Functional equation : $ f(1)^3 + f(2)^3 + \ldots + f(n)^3 = (f(1) + f(2) + \ldots + f(n))^2$ Find all function $f:\mathbb{N}\rightarrow\mathbb{N}\cup\{0\}$ satisfying
$$ f(1)^3 + f(2)^3 + \ldots + f(n)^3 = (f(1) + f(2) + \ldots + f(n))^2$$
$\forall n \in \mathbb{N}$.
Thank you,  Batominovski and Guy Fabrice..
Is my understanding correct ? Please let me know if there is any mistake.
Substitute $n=1$, $f(1)^3 =f(1)^2$, so $f(1)=0$ or $1$
$f(1)=0$ : substitute $n=2$, $f(2)^3 =f(2)^2$, so $f(2)=0$ or $1$
If $f(2) = 0$, let $l$ be the maximal value such that $f(l) =0$.
so $ f(1)^3 + f(2)^3 + \ldots + f(l+1)^3 = (f(1) + f(2) + \ldots + f(l+1))^2$
then $f(l+1)^3=(f(l+1))^2$ so $f(l+1) = 1$
If $f(2) = 1$, then $0+1+f(3)^3=(f(1)+f(2)+f(3))^2$ , so $f(3) = 0$ or $2$
Since  $ f(1)^3 + f(2)^3 + \ldots + f(n)^3 = (f(1) + f(2) + \ldots + f(n))^2$
and $ f(1)^3 + f(2)^3 + \ldots + f(n+1)^3 = (f(1) + f(2) + \ldots + f(n+1))^2$
so $f(n+1)^3 = 2(f(1)+f(2)+\ldots+f(n))f(n+1)+f(n+1))^2$
so $f(n+1)^2-f(n+1)=2(f(1)+f(2)+\ldots+f(n))$ 
i.e., if $f(n) \not= 0$, then $f(n)=n, \forall n \in \mathbb{N}$
so if $f(x)=0, \forall x \in \mathbb{N}$ then $f(n) = 0, \;\forall n \in \mathbb{N}$ 
If $f(x)$ be the value such that Max$\{f(1), f(2), \ldots ,f(x)\}=k$ then $f(x+1) = k+1$ or $0$ ---[1]
By induction, let $P(n)$ denotes [1]
Basic step , it's obvious that if $f(1) = 0$, then $f(l_i)=1$, $1\leq l_i\leq x$
so $1+f(l_i+1)^3 = (f(l_i+1) +1)^2$ so $f(l_i+1)=2$ or $0$
Inductive step, suppose that $P(k)$ is true. 
$1^3+2^3+\ldots+k^3+f(x+1)^3=(1+2+\ldots+k+f(x+1))^2$, 
so $f(x+1)=k+1$ or $0$, so $P(n)$ is true.
The sequence of $f$ is $\underbrace{0\ldots0}_{\text{$k_1$}}1\underbrace{0\ldots0}_{\text{$k_2$}}2\ldots$, where $k_1, k_2, \ldots \in \mathbb{N}$
Answer check : 
$ f(1)^3 + f(2)^3 + \ldots + f(n)^3 = 1^3+2^3+\ldots+m^3=\left(\frac{m(m+1)}{2}\right)^2=(f(1) + f(2) + \ldots + f(n))^2$
$\blacksquare$

Hint: Prove by induction on $n$ that, if $f(n)\neq 0$, then
(1) we have $f(n)=M_n+1$, where $M_n:=\max\big\{f(1),f(2),\ldots,f(n-1)\big\}$ for $n>1$, and $M_1:=0$;
(2) for $n>1$, each the numbers $1,2,\ldots,M_n$ appears only once among $f(1),f(2),\ldots,f(n-1)$ in an increasing order (i.e., $i$ appears before $i+1$).
Both statements should be proven simultaneously (i.e., not with separate inductive proofs).
