Find all functions $f: \mathbb{Q} \rightarrow \mathbb{Q}$ such that the equation

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

holds for all rational numbers $x$ and $y$.
Here, $\mathbb{Q}$ denotes the set of rational numbers.
(Slovakia, Patrik Bak)

Answer: $f(x)=x$ and $f(x)=-x$.
Denote the equation from the statement by (1). Let $x f(x)=A$ and $x^{2}=B$. The equation (1) is of the form

$$
f(A+y)=f(y)+B
$$

Also, if we put $y \rightarrow -A+y$, we have $f(A-A+y)=f(-A+y)+B$. Therefore

$$
f(-A+y)=f(y)-B
$$

We can easily show that for any integer $n$ we even have

$$
f(n A+y)=f(y)+n B
$$

Indeed, it's trivially true for $n=0$ and if this holds true for some integer $n$, then

$$
f((n+1) A+y)=f(A+y+n A)=f(n y+A)+B=f(y)+n B+B=f(y)+(n+1) B
$$

and

$$
f((n-1) A+y)=f(-A+n A+y)=f(n A+y)-B=f(y)+n B-B=f(y)+(n-1) B.
$$

So, equation (2) follows from the induction on $n$.
Now we can say that for any integer $k$ it holds

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

If $y$ is given, then $f(y)+n x^{2}$ can be any rational number, since $n x^{2}$ can be any rational number. If it is supposed to be $\frac{p}{q}$, where $q \neq 0$, then we may take $n=p q$, and $x=\frac{1}{q}$. Therefore $f$ is surjective on $\mathbb{Q}$. So there's a rational number $c$ such that $f(c)=0$. By putting $x=c$ into (1) we immediately get $c=0$, i.e. $f(0)=0$. Therefore, $f(x)=0$ if and only if $x=0$.

For any integer $n$ and for any rational $x, y$ it holds

$$
f\left(n^{2} x f(x)+y\right)=f(y)+n^{2} x^{2}=f(y)+(n x)^{2}=f(n x f(n x)+y)
$$

After taking $y=-n x f(n x)$ in (4), the right-hand side becomes 0, therefore

$$
n^{2} x f(x)-n x f(n x)=0
$$

This simplifies into $n f(x)=f(n x)$ for $x \neq 0$, but it also holds for $x=0$. Therefore, for any rational number $x=\frac{p}{q}$ we have,

$$
f(x)=f\left(\frac{p}{q}\right)=f\left(p \cdot \frac{1}{q}\right)=p \cdot f\left(\frac{1}{p}\right)=p \cdot \frac{f\left(q \cdot \frac{1}{q}\right)}{q}=\frac{p}{q} \cdot f(1)=x f(1)
$$

So, we have $f(x)=k x$, for some rational number $k$. Let's put this answer in (1) and we get $k(x k x+y)=k y+x^{2}$, thus $k^{2}=1$. Therefore $f(x)=x$ and $f(x)=-x$ are solutions.