answer:
f(X) = g(X, 0, 0); g(X, Y, Z) = Y < X ? g(X, Y+1, Z+2*Y+1) : Z
f(X) = g(X, 0, 0);
g(X, Y, Z) = Y < X ? g(X, Y+1, Z+2*Y+1) : Z