Maximizing $\sum_{i=1}^{10} \cos(3x_i)$, for real $x_i$ such that $\sum_{i=1}^{10} \cos(x_i)=0$ 
Determine the greatest possible value of $\sum_{i=1}^{10} \cos(3x_i)$ for real $x_1,x_2,\cdots,x_{10}$, where  $\sum_{i=1}^{10} \cos(x_i)=0$.

My approach was to somehow get a equation solely in terms of one of the $\cos x_i$ and then differentiating and getting the maximum according to the range of cos which is $[-1,1]$. For achieving this, I first inductively proved that
$$a^3+b^3 +c^3 +\cdots+n^3= 3\cdot(\text{sum of product of terms taking three at a time})$$ but that just makes the expression to be that we need to maximize the value of
$$12\cdot(\text{sum of product of terms taking three at a time})$$ But now how do we get an equation in just one variable?
 A: We apply Lagrange multipliers.
Let $f(x_1,\ldots, x_{10})=\sum_{i=1}^{10} \cos 3x_i$ be the objective function and $g(x_1,\ldots, x_{10})=\sum_{i=1}^{10} \cos x_i=0$ be the constraint.
For each $1\leq i\leq 10$, we have by the triple angle formula,
$\lambda \sin x_i = 3(3\sin x_i - 4\sin^3 x_i)$
which gives
$\sin x_i = 0$ or $\lambda-9=-12\sin^2 x_i$.
If $\sin x_i = 0$ then the corresponding $\cos 3x_i$ is maximized when $\cos x_i = 1$.
If $\sin x_i \neq 0$ then all remaining $\sin^2 x_i$ must be identical. Then all remaining $\cos^2 x_i$ are also identical. Let $\mu=|\cos x_i|$. Then $0\leq \mu\leq 1$.
Let $q$ be the number of indices with $\cos x_i = -\mu$, let $n$ be the number of indices with $\cos x_i = \mu$, and $m$ be the number of indices with $\cos x_i=1$.
Then necessarily, $q+n+m=10$ and the constraint becomes
$$
m+(n-q)\mu=0.
$$
The objective function becomes
$$
\begin{align}
m+ & n(4\mu^3-3\mu) + q(4(-\mu)^3 - 3(-\mu)) \\ 
&= m+ 4(n-q) \mu^3 - 3(n-q)\mu\\
&=4m+4(n-q)\mu \mu^2\\
&=4m(1-\mu^2)\\
&=4m\left( 1-\frac{m^2}{(q-n)^2}\right).\end{align}
$$
This is maximized with $q=7$, $n=0$, $m=3$. When this happens, we have $7$ of $x_1, \ldots, x_{10}$ satisfying $\cos x_i= -\frac 37$ and the other $3$ of them have $\cos x_i=1$. The maximum is
$$
12\left(1-\frac{9}{49}\right)=\frac{480}{49}\approx 9.7959.
$$
