Let $L\ge 2$ be an integer, $a_0=10$, $a_L=2$, and $a_1,...,a_{L-1}\ge 2$ be integers summing to $36$. Maximize $\sum_{i=0}^{L-1}a_ia_{i+1}$ over $L$ and $a_1,...,a_{L-1}$.
I think the maximum is $556$ achieved at $L=3$ and $(a_1,a_2)=(22,14)$. It’s easy to show if $L\le 3$. For $L>3$, I tried to increase the sum by using $a_1,...,a_{L-3},a_{L-2}+a_{L-1}$ instead of $a_1,...,a_{L-1}$, but it doesn’t work for arbitrary $a_1,...,a_{L-1}$, so I tried to first increase the sum by swapping $a_i$ with $a_j$ when they were out of order in some sense, like the proof of the rearrangement inequality, but I couldn’t figure out how. Maybe there is a way using calculus.
Here's a solution with calculus. This confirms that indeed the maximum is achieved, as stated by the author, for $L=3$ and $(a_1,a_2)=(22,14)$. However, I'd be grateful for explanations from MSE readers (see text below and case 3) where I do not understand some results.
First note that, as $a_1,...,a_{L-1}\ge 2$ and $\sum_{i=1}^{L-1}a_i = 36$, we need to consider only $L\le 19$.
First, relax the condition $a_i \ge2$. Then, enforce the sum condition with Lagrange parameter $\lambda$. The function which needs to be maximized is then
$$ S = \sum_{i=0}^{L-1}a_ia_{i+1} - \lambda(-36 + \sum_{i=1}^{L-1}a_i) \\ = 10 a_1 + 2 a_{L-1} + \sum_{i=1}^{L-2}a_ia_{i+1} - \lambda(-36 + \sum_{i=1}^{L-1}a_i) \\ $$ Maximization goes by taking partial derivatives which gives $$ \frac{\partial S}{\partial a_j} = a_{j-1} + a_{j+1} - \lambda = 0 \quad \forall j=2\cdots L-2\\ \frac{\partial S}{\partial a_1} = 10 + a_2 - \lambda = 0\\ \frac{\partial S}{\partial a_{L-1}} = 2 + a_{L-2} - \lambda = 0 $$
The third equation can only be enforced for $L\ne4$ because otherwise it contradicts the second equation.
For $L \ne 4$, the sum of all these equations gives $2 \sum_{i=1}^{L-1}a_i - (a_1 + a_{L-1}) + 12= (L-1)\lambda$ or, plugging in the sum condition, $84 - (a_1 + a_{L-1})= (L-1)\lambda$. Now let us inspect the partial derivatives above. Start with unknown $a_1$ and $\lambda$. Then we get the following equations, which can be used up to $a_j$ with $j = L-1$: $$ a_2 = \lambda -10\\ a_3 = \lambda -a_1\\ a_4 = \lambda -a_2 = 10\\ a_5 = \lambda -a_3 = a_1\\ a_6 = \lambda -a_4 = \lambda -10\\ a_7 = \lambda -a_5 = \lambda -a_1 $$
It is indeed very strange to see that $a_4=10$ which will come in action for $L \ge 5$. As we shall see in case 3 (below), this produces errors which I cannot explain.
Since the recursion length is two, and since the last two values repeat the first two, we see that in general, $a_k = a_{k \, \text{mod}\, 4}$, so we need only consider 4 cases.
Case 1: $L-1 =2 + 4 n$. Then $a_{L-1} = a_2 = \lambda-10$ and we have $84 - (a_1 + a_{L-1}) = 84 - (a_1 +\lambda-10) = (L-1)\lambda$ or $ 94 - a_1 = L \lambda = (3 + 4n) \lambda$ . Further, we have $36 = \sum_{i=1}^{L-1}a_i = a_1 + a_2 + n\cdot(2 \lambda) = -10 + a_1 + (2n +1)\lambda$ or $ 46 - a_1 = (1 + 2n) \lambda$ . Combining the two equations gives $$ \lambda = \frac{24}{1+n}\\ a_1 = -2 +\frac{24}{1+n} $$
For $n=0 \; (L=3)$ we get $a_1 = 22$ and $a_2 = \lambda -10 = 14$ which is the result that the question text already stated.
For $n=1 \; (L=7)$ we get $\lambda = 12$ and $a_1 = 10$ which gives the $a$-sequence (starting with $a_0$) $10, 10, 2,2,10, 10,2, 2$ and hence $\sum_{i=0}^{6}a_ia_{i+1} = 100 + 20+4+20+100+20+4 = 268$.
For $n=2 \; (L=11)$ we get $\lambda = 8$ and $a_1 = 6$, $a_2 = -2$ so this does not allow unrestricted optimization any more.
Case 2: $L-1 =3 + 4 n$. Then $a_{L-1} = a_3 = \lambda-a_1$ and we have $36 = \sum_{i=1}^{L-1}a_i = a_1 + a_2 + a_3 + n\cdot(2 \lambda) = -10 + (2n +2)\lambda$ or $ 23 = (n +1)\lambda$. The parameter $a_1$ remains arbitrary.
For $n=0$ $(L =4)$, we have $\lambda = 23$ and hence $a_2 = 13, a_3 = 23 - a_1$. So $S = a_0 a_1 +a_1 a_2 +a_2 a_3 +a_3 a_4 = 23 a_1 + 13 (23 - a_1) + 2 (23 - a_1) = 8 a_1 + 345$. So $S$ rises with $a_1$ and the limiting factor is $a_3 = 23 - a_1 \ge 2$ which allows $a_1 = 21$, giving $S=513$ .
For $n=1$ $(L =8)$, we have $\lambda = 11.5$ and hence $a_2 = 1.5$ which doesn't fit. Let $\lambda = 12$ and we have $a_2 = 2, a_3 = 12 - a_1$. So $S = a_0 a_1 +a_1 a_2 +a_2 a_3 +a_3 a_4 = 12 a_1 + 2 (12 - a_1) + 2 (12 - a_1) = 8 a_1 + 48$. So $S$ rises with $a_1$ and the limiting factor is $a_3 = 12 - a_1 \ge 2$ which allows $a_1 = 10$, giving $S=128$ .
Case 3: $L-1 =4 + 4 n$. Then $a_{L-1} = a_4 = 10$ and we have $84 - (a_1 + a_{L-1}) = 84 - (a_1 +10) = (L-1)\lambda$ or $ 74 - a_1 = (L-1) \lambda = (4+ 4n) \lambda$ . Further, we have $36 = \sum_{i=1}^{L-1}a_i = a_1 + a_2 + a_3 + a_4 + n\cdot(2 \lambda) = (2n +2)\lambda$ or $18 = (1 + n) \lambda$ . Combining the two equations gives $$ \lambda = \frac{18}{1+n}\\ a_1 = 2 $$
For $n=0 \; (L=5)$ we get $a_1 = 2$ and $\lambda = 18$ which gives the $a$-sequence (starting with $a_0$) $10, 2, 8, 16, 10,2$ and hence $\sum_{i=0}^{4}a_ia_{i+1} = 20 + 16 + 128 + 160 + 20 = 344$. However, by numerical evaluation, the sequence $a_1=20,a_2=12,a_3=2,a_4=2$ gives $S=472$ and I do not see how this comes about so I'll stop here. I'd be grateful for some explanation.
As already noted by the author, it is unlikely that increasing $L$ will lead to higher values of $S$, given that with $a_i \ge 2$ an increasing portion of the sum (36) must be held back for ever more values $a_i$, which will not allow products of high numbers.