4. Determine all functions $f: \mathbb{R} \rightarrow \mathbb{R}$ such that for all $x, y \in \mathbb{R}$,

$$
f(x f(x)+f(y))=(f(x))^{2}+y
$$

(Bulgaria)
4. The right-hand side of the given equation (*) can take all real values, so the function $f$ is "onto". This means there exists $c$ such that $f(c)=0$. Substituting $x=c$ in (*) gives $f(f(y))=y$. Now, by substituting $f(x)$ for $x$ in (*), we get $f(x f(x)+f(y))=x^{2}+y$, which together with (*) yields $f(x)^{2}=x^{2}$ for all $x$.

Assume there exist $a$ and $b (ab \neq 0)$ such that $f(a)=-a$ and $f(b)=b$. Substituting $(x, y)=(a, b)$ into (*) gives $f\left(-a^{2}+b\right)=a^{2}+b$, which is impossible if $a, b \neq 0$. Therefore, the only possible functions are $f(x) \equiv x$ and $f(x) \equiv -x$, and they are indeed solutions.