import math
import sys

def f(x):
    return (3 * x - 2) * (x ** 2 + 1)

def main():
    tol = 1.0e-12
    n, nmax = 0, 100
    a, b = 0.0, 1.0

    print("Enter left endpoint:")
    a=float(input())
    print("Enter right endpoint:")
    b=float(input())
    fa, fb = f(a), f(b)

    if fa * fb >= 0:
        print("Bad search interval")
        sys.exit(0)

    x = (a + b) / 2
    fx = f(x)
    d = (b - a) / 2

    while n <= nmax and abs(fx) > tol and d > tol:
        if fa * fx < 0:
            b = x
            fb = fx
        else:
            a = x
            fa = fx
        x = (a + b) / 2
        fx = f(x)
        n += 1
        d /= 2

    print(f"{n:5d} {x:.16e} {fx:.4e} {d:.4e}")

if __name__ == "__main__":
    main()
