import math
import sys

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

def main():
    tol = 1.0e-12
    n, nmax = 0, 50
    x, y = 0.0, 1.0

    print("Enter x:")
    x=float(input())
    print("Enter y:")
    y=float(input())

    if abs(x-y) < tol:
        print(f"Bad initial guesses, |x-y| < {tol:.4e}")
        sys.exit(0)
        
    fx, fy = f(x), f(y)

    if abs(fx-fy) < tol:
        print(f"Bad initial guesses, |fx-fy| < {tol:.4e}")
        sys.exit(0)

    while n <= nmax and abs(fx) > tol:
        z = x
        x = x-fx*(x-y)/(fx-fy)
        y = z
        fy = fx
        fx = f(x)
        n += 1

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

if __name__ == "__main__":
    main()
