21. How to draw $n$ rays starting from one point on a plane so that the sum of all possible pairwise angles between these rays is the greatest possible? (Here, the angle between two rays is understood to be no more than $180^{\circ}$.) What is this greatest possible value of the sum of the angles?
21. Let $l_{1}, l_{2}, \ldots, l_{n}$ be some $n$ rays emanating from a point $O$. If rays $l_{1}$ and $l_{2}$ are directed in opposite directions, then $\angle\left(l_{1}, l_{2}\right)=180^{\circ}$ and for any third ray $l_{3}$, the sum $\angle\left(l_{1}, l_{3}\right)+\angle\left(l_{2}, l_{3}\right)=180^{\circ}$ (regardless of the position of $l_{3}$). Now, let's exclude all pairs of oppositely directed rays from our system; let $l_{1}, l_{2}, \ldots, l_{m}$ (where $m \leqslant n$) be the remaining rays. Fix the rays $l_{s}, \ldots, l_{m}$, and rotate the ray $l_{1}$; consider the sum

$$
L=\angle\left(l_{1}, l_{2}\right)+\angle\left(l_{1}, l_{3}\right)+\ldots+\angle\left(l_{1}, l_{m}\right)
$$

and determine how the sum $L$ will change when the ray $l_{1}$ is rotated by some small angle $\varphi$ to the position $l_{1}^{\prime}$, i.e., compare $L$ with the sum $L^{\prime}$ obtained from $L$ by replacing the ray $l_{1}$ with the ray $l_{1}^{\prime}$. It is not difficult to see that the sum $L$ can decrease when the ray $l_{1}$ is rotated slightly around $O$ in one direction, as well as when it is rotated in the opposite direction, only if at the initial moment the ray $l_{1}$ was opposite to one of the rays $l_{2}, \ldots, l_{m}$ (and thus, upon rotating $l_{1}$ in any direction, the angle between $l_{1}$ and this ray decreases); however, this is impossible since we have already removed all pairs of mutually opposite rays. Therefore, when the ray $l_{1}$ is rotated by a small angle $\varphi$ in some direction, the sum $L$ will not decrease. In this case, two scenarios may occur: either $L$ remains constant for all positions of the ray $l_{1}$ - and then we will direct $l_{1}$ opposite to $l_{2}$ and then discard both these rays; or, upon rotating $l_{1}$ in the considered direction, $L$ first increases, and upon passing the ray $l_{1}$ through some position $l_{1}^{0}$, it begins to decrease (if the sum $L$ is not constant, it cannot always increase, since upon rotating $l_{1}$ by $360^{\circ}$, the sum $L$ returns to its previous value). However, $L$ can begin to decrease only when the ray $l_{1}$ passes through the position $l_{1}^{0}$ if the angle between $l_{1}$ and one of the rays $l_{2}, \ldots, l_{m}$ first increases and then, upon passing through $l_{1}^{0}$, begins to decrease, i.e., if $l_{1}^{0}$ is opposite to one of the rays $l_{2}, \ldots, l_{m}$. In this case, we will rotate the ray $l_{1}$ to the position $l_{1}^{0}$ and then discard $l_{1}^{0}$ along with the ray opposite to it; in this process, the total number of rays decreases by two.

Continuing to act in this manner, we can reach a state where either a single ray remains or no rays remain. Thus, without reducing the sum of pairwise angles between the rays, an arbitrary system of $n$ rays can be replaced by a set of $k$ pairs of oppositely directed rays (if $n=2 k$ is even) or a set of $k$ pairs of oppositely directed rays and one additional ray (if $n=2 k+1$ is odd). In the latter two cases, the sum of all possible pairwise angles between the rays is respectively

$$
k^{2} \cdot 180^{\circ} \quad \text{or} \quad\left(k^{2}+k\right) \cdot 180^{\circ} ;
$$

it does not depend on the arrangement of the rays (such that the conditions formulated above are satisfied) and is the greatest of all possible.