4. Given various polynomials $f(x)$ and $g(x)$ of degree 3. It turns out that the polynomials $f(f(x))$ and $(g(x))^{3}$ are equal, as well as the polynomials $f(g(x))$ and $(f(x))^{3}$. Additionally, $f(0)=1$. Find all such pairs of polynomials $f, g$.
Answer: $f(x)=-x^{2}+3 x^{2}-3 x+1=(1-x)^{3}, g(x)=(x-1)^{3}+1$. (In the 2nd variant: $f(x)=-2-(x+2)^{3}$, $\left.g(x)=(x+2)^{3}.\right)$

Let $f(x)=a x^{3}+b x^{2}+c x+1$. By the condition, $a f^{3}(x)+b f^{2}(x)+c f(x)+1=g^{3}(x) u a g^{3}(x)+b g^{2}(x)+c g(x)+1=$ $f^{3}(x)$. Subtract the second equality from the first: $(a+1)\left(f^{3}(x)-g^{3}(x)\right)+b\left(f^{2}(x)-g^{2}(x)\right)+c(f(x)-g(x))=0$. This expression can easily be factored into two factors, and since one of them $f(x)-g(x)$ is a non-zero polynomial, the second factor must be zero: $(a+1)\left(f^{2}(x)+f(x) g(x)+g^{2}(x)\right)+b(f(x)+g(x))+c=0$.

Note that $f^{2}(x)+f(x) g(x)+g^{2}(x)$ is a polynomial of degree 6 (its coefficient at $x^{6}$ is $a^{2}+a a_{1}^{2}+a_{1}^{2} \neq 0$, where $a_{1}$ is the leading coefficient of $g(x)$). Therefore, $a+1$ must be equal to 0. Thus, $a=-1$, and in this case $b(f(x)+g(x))=-c$. This is possible in two cases:

1) $b=c=0$. Then $-f^{3}(x)+1=g^{3}(x)$, i.e., $f^{3}(x)+g^{3}(x)=1$. But the polynomial on the left side is the product $(f+g)\left(f^{2}-f g+g^{2}\right)$, and the second bracket is a polynomial of degree 6 (as discussed above). Therefore, this cannot happen.
2) $f(x)+g(x)=-c / b$ is a constant polynomial. Denote $-c / b=T, g(x)=T-f(x)$. Substituting this into the first condition, we get $-f^{3}(x)+b f^{2}(x)+c f(x)+1=(T-f(x))^{3}=-f^{3}(x)+3 T f^{2}(x)-3 T^{2} f(x)+T^{3}$. From this, it follows that $b=3 T, c=-3 T^{2}, 1=T^{3}$, i.e., $f(x)=-x^{2}+3 x^{2}-3 x+1=(1-x)^{3}, g(x)=1-(1-x)^{3}=$ $(x-1)^{3}+1$.