Simplify the expression

$$
K=x^{n}+x^{n-1}+2 x^{n-2}+2 x^{n-3}+3 x^{n-4}+\ldots+3 x^{4}+2 x^{3}+2 x^{2}+x+1
$$

where, moving from both left and right towards the center, after two equal coefficients, a coefficient that is 1 greater follows.
The number of terms in $K$ is $n+1$, among which 4 terms have equal coefficients: 1, $2, \ldots$, thus in the middle, there is 1 more term with equal coefficients than the remainder when $n$ is divided by 4. Let $n=4 p+q$, where $0 \leq q<4$, then the number of middle terms is $q+1$, that is, 1, 2, 3, or 4, and their coefficient is $p+1$.

$K$ can be decomposed into the sum of $p+1$ geometric sequences, each with a common ratio of $x$, the (right-counted) first term being $1, x^{2}, x^{4}, \ldots, x^{2 p}$, the number of terms decreases by 4, that is, $n+1, n-3, n-7, \ldots, q+5$, finally in the last one $n+1-4 p=q+1$, and the sum of each sequence is written in closed form (assuming $x \neq 1$):

\[
\begin{aligned}
K & =\left(x^{n}+x^{n-1}+x^{n-2}+\ldots+x^{2}+x+1\right)+ \\
& +\left(x^{n-2}+x^{n-3}+x^{n-4}+\ldots+x^{4}+x^{3}+x^{2}\right)+\ldots+ \\
& +\left(x^{n-2 p}+\ldots+x^{2 p}\right)= \\
& =\frac{x^{n+1}-1}{x-1}+x^{2} \cdot \frac{x^{n-3}-1}{x-1}+\ldots+x^{2 p} \cdot \frac{x^{n-4 p+1}-1}{x-1}
\end{aligned}
\]

By multiplying and combining the first terms of the numerators:

\[
(x-1) \cdot K=\left(x^{n+1}+x^{n-1}+\ldots+x^{n-2 p+1}\right)-\left(1+x^{2}+\ldots+x^{2 p}\right) .
\]

From the first sum, the last term is factored out, leaving the terms of the second parenthesis in reverse order, forming a geometric sequence with a common ratio of $x^{2}$, thus

\[
\begin{aligned}
(x-1) \cdot K & =\left(x^{n-2 p+1}-1\right)\left(1+x^{2}+\ldots+x^{2 p}\right)= \\
& =\frac{\left(x^{n-2 p+1}-1\right)\left(x^{2 p+2}-1\right)}{x^{2}-1}
\end{aligned}
\]

provided that $x^{2} \neq 1$. Therefore, considering $2 p=(n-q) / 2$,

\[
K=\frac{\left(x^{\frac{n-q}{2}+2}-1\right)\left(x^{\frac{n+q}{2}+1}-1\right)}{(x-1)\left(x^{2}-1\right)}
\]

In the excluded case $x=1$, $K$ can be decomposed into four identical arithmetic sequences, each with $p$ terms, and in the middle, there are still $q+1$ terms, each being $p+1$, thus

\[
\begin{aligned}
K & =4(1+2+\ldots+p)+(q+1)(p+1)=(p+1)(2 p+q+1)= \\
& =\frac{1}{8}(n-q+4)(n+q+2)
\end{aligned}
\]

In the case $x=-1$, the terms of $K$ have alternating signs, so the sum of 4 terms with the same coefficient is 0, and only the $p+1$ terms with absolute values need to be considered. For odd $n$, there are either no such terms or two, and since they are adjacent, $K=0$. For even $n$, that is, $q=0$ and 2, $K=p+1=(n-q+4) / 4$, because the positive terms are in the majority, moving from the right towards the center, the first term with a larger coefficient is even.

Lempert László (Budapest, Radnóti M. Gymnasium II. o. t.)

Remark. Our result is valid for $x=0$ as well, and the formula for the sum of a geometric sequence is also valid for $q=0$.