004. Multiplying Adjacent Elements in a Permutation

Given a permutation (a1,a2,⋯ ,an)(a_1, a_2, \cdots, a_n) of {1,2,⋯ ,n}\{ 1, 2, \cdots, n \}, maximize a1a2+a2a3+⋯+an−1an+ana1a_1 a_2 + a_2 a_3 + \cdots + a_{n-1} a_n + a_n a_1.


Let Mn=max⁡(a1a2+a2a3+⋯+an−1an+ana1)M_n = \max (a_1 a_2 + a_2 a_3 + \cdots + a_{n-1} a_n + a_n a_1). Note that MnM_n of a permutation is always the same as the ones of its cyclic permutations. Observe the amount of change updating {1,2,⋯ ,n−1}\{ 1, 2, \cdots, n - 1 \} to {1,2,⋯ ,n}\{ 1, 2, \cdots, n \}. When nn is inserted between aka_k and ak+1a_{k + 1}, the amount of change is nak+nak+1−akak+1=nak+nak+1−akak+1+n2−n2=n2−{n2−n(ak+ak+1)+akak+1}=n2−(n−ak)(n−ak+1)≤n2−{n−(n−1)}{n−(n−2)}=n2−2\begin{aligned} n a_k + n a_{k + 1} - a_k a_{k + 1} &= n a_k + n a_{k + 1} - a_k a_{k + 1} + n^2 - n^2 \\ &= n^2 - \{ n^2 - n (a_k + a_{k + 1}) + a_k a_{k + 1} \} \\ &= n^2 - (n - a_k) (n - a_{k + 1}) \\ &\leq n^2 - \{n - (n - 1)\} \{n - (n - 2)\} = n^2 - 2 \end{aligned}

where 1≤k≤n−11 \leq k \leq n - 1. Although k+1k + 1 must be 11 when k=n−1k = n - 1, the above inequality is always valid since the permutation can be cyclic keeping Mn−1M_{n - 1}. So, the maximum amount of change is n2−2n^2 - 2, which means Mn−Mn−1=n2−2M_n - M_{n - 1} = n^2 - 2. Also, this only happens when nn is inserted between n−1n - 1 and n−2n - 2 in a situation where n−1n - 1 and n−2n - 2 are adjacent. From M2=a1a2+a2a1=4M_2 = a_1 a_2 + a_2 a_1 = 4, M3=M2+32−2M4=M3+42−2⋮Mn=Mn−1+n2−2  ⟹  Mn=M2+(32−2)+(42−2)+⋯+(n2−2)=4+(12+22+⋯+n2)−(12+22)−2(n−2)=(12+22+⋯+n2)−2n+3=n(n+1)(2n+1)6−2n+3(n≥2)\begin{aligned} M_3 &= M_2 + 3^2 - 2 \\ M_4 &= M_3 + 4^2 - 2 \\ &\qquad \vdots \\ M_n &= M_{n - 1} + n^2 - 2 \\\\ \implies M_n &= M_2 + (3^2 - 2) + (4^2 - 2) + \cdots + (n^2 - 2) \\ &= 4 + (1^2 + 2^2 + \cdots + n^2) - (1^2 + 2^2) - 2(n - 2) \\ &= (1^2 + 2^2 + \cdots + n^2) -2n + 3 \\ &= \frac{n(n + 1)(2n + 1)}{6} - 2n + 3 \qquad (n \geq 2) \end{aligned}

Enumerating MnM_n starting from n=3n = 3, M3⟸1,3,2M4⟸1,3,4,2M5⟸1,3,5,4,2⋮Mn={1,3,⋯ ,n−3,n−1,n,n−2,⋯ ,4,2(n is even)1,3,⋯ ,n−2,n,n−1,n−3,⋯ ,4,2(n is odd)\begin{aligned} M_3 &\Longleftarrow 1, 3, 2 \\ M_4 &\Longleftarrow 1, 3, 4, 2 \\ M_5 &\Longleftarrow 1, 3, 5, 4, 2 \\ &\qquad \vdots \\ M_n &= \begin{cases} 1, 3, \cdots, n - 3, n - 1, n, n - 2, \cdots, 4, 2 \qquad (n \text{ is even}) \\\\ 1, 3, \cdots, n - 2, n, n - 1, n - 3, \cdots, 4, 2 \qquad (n \text{ is odd}) \end{cases} \end{aligned}


© 2026. All rights reserved.