#P7812. Maximized Permutation Weight
Maximized Permutation Weight
Maximized Permutation Weight
Given an array \(a\) of length \(n\), and a permutation \(p\) of \(\{1,2,\dots,n\}\), define the weight of \(p\) as
\[ W(p)=\sum_{i=1}^{n} p_i\,a_{p_{i-1}}\,a_{p_i}\,a_{p_{i+1}}, \quad\text{with } p_0=p_n \text{ and } p_{n+1}=p_1. \]Your task is to construct a permutation with a weight as large as possible.
inputFormat
The input begins with an integer \(n\) on the first line representing the length of the sequence. The second line contains \(n\) integers \(a_1,a_2,\dots,a_n\), representing the elements of the sequence.
outputFormat
Output a permutation consisting of \(n\) integers \(p_1,p_2,\dots,p_n\) that you believe gives a high (ideally maximum) weight according to the formula. The numbers should be separated by spaces.
sample
3
1 2 3
1 2 3