4. The numbers $x$ and $y$ are such that the equations $\sin y + \sin x + \cos 3x = 0$ and $\sin 2y - \sin 2x = \cos 4x + \cos 2x$ are satisfied. What is the greatest value that the sum $\cos y + \cos x$ can take?
Answer: $1+\sin \frac{3 \pi}{8}=1+\frac{\sqrt{2+\sqrt{2}}}{2}$.

Solution. Transform the second equality:

$$
\sin 2 y=2 \sin x \cos x+2 \cos 3 x \cos x \Leftrightarrow \sin 2 y=2 \cos x(\sin x+\cos 3 x) \text {. }
$$

Substituting $-\sin y$ for $\sin x+\cos 3 x$, we get $\sin 2 y=-2 \cos x \sin y, 2 \sin y \cos y+2 \cos x \sin y=0, \sin y(\cos y+\cos x)=0$, from which there are two possibilities.

1) $\cos x+\cos y=0$, i.e., the desired expression turns to zero.
2) $\sin y=0$. Then $y=\pi n, n \in \mathbb{Z}$, and from the first equation we get that

$\sin x+\cos 3 x=0 \Leftrightarrow \cos 3 x=\cos \left(x+\frac{\pi}{2}\right) \Leftrightarrow\left[\begin{array}{l}3 x=x+\frac{\pi}{2}+2 \pi k, \\ 3 x=-x-\frac{\pi}{2}+2 \pi k, k \in \mathbb{Z}\end{array} \Leftrightarrow\left[\begin{array}{l}x=\frac{\pi}{4}+\pi k, \\ x=-\frac{\pi}{8}+\frac{\pi k}{2}, k \in \mathbb{Z} .\end{array}\right.\right.$

Then the maximum value of the sum $\cos y+\cos x$ is achieved when $y=2 \pi n, n \in \mathbb{Z}$ and $x=$ $\frac{3 \pi}{8}+2 \pi k, k \in \mathbb{Z}$, and it is equal to $1+\sin \frac{3 \pi}{8}$.

To compute $\sin \frac{3 \pi}{8}$, we apply the cosine double-angle formula: $\cos \frac{3 \pi}{4}=1-2 \sin ^{2} \frac{3 \pi}{8}$, from which $\sin \frac{3 \pi}{8}=\sqrt{\frac{1-\cos \frac{3 \pi}{4}}{2}}=\frac{\sqrt{2+\sqrt{2}}}{2}$.

Thus, under the given conditions, $\max (\cos x+\sin y)=1+\frac{\sqrt{2+\sqrt{2}}}{2}$.