18.8. (CSSR, 83). For given numbers $n \in \mathbf{N}$ and $a \in[0 ; n]$, find the maximum value of the expression

$$
\left|\sum_{i=1}^{n} \sin 2 x_{i}\right| \text { given }
$$

the condition that

$$
\sum_{i=1}^{n} \sin ^{2} x_{i}=a
$$
18.8. We have

$$
a=\sum_{i=1}^{n} \sin ^{2} x_{i}=\sum_{i=1}^{n}\left(1-\cos 2 x_{i}\right) / 2
$$

i.e.

$$
\sum_{i=1}^{n} \cos 2 x_{i}=n-2 a
$$

Next, consider the vectors on the plane

$$
\left(\cos 2 x_{i} ; \quad \sin 2 x_{i}\right)
$$

of unit length. Their sum has a length not greater than $n$, and thus the inequality is satisfied

$$
\begin{aligned}
\left|\sum_{i=1}^{n} \sin 2 x_{i}\right|<\sqrt{n^{2}-\left(\sum_{i=1}^{n} \cos 2 x_{i}\right)^{2}} & = \\
& =\sqrt{n^{2}-(n-2 a)^{2}}=2 \sqrt{a(n-a)}
\end{aligned}
$$

in which equality is achieved when

$$
x_{1}=x_{2}=\ldots=x_{n}=\arcsin \sqrt{a / n}
$$

Thus, the maximum value is $2 \sqrt{a(n-a)}$.