Codeforces Round 344 (Div. 2)
E
Product Sum
Codeforces
2600
原题
← D→
翻译中…

Blake is the boss of Kris, however, this doesn't spoil their friendship. They often gather at the bar to talk about intriguing problems about maximising some values. This time the problem is really special.

翻译中…

You are given an array $*a*$ of length $*n*$. The characteristic of this array is the value image — the sum of the products of the values $*a*_{*i*}$ by $*i*$. One may perform the following operation exactly once: pick some element of the array and move to any position. In particular, it's allowed to move the element to the beginning or to the end of the array. Also, it's allowed to put it back to the initial position. The goal is to get the array with the maximum possible value of characteristic.

翻译中…

image

翻译中…

Input

翻译中…

The first line of the input contains a single integer $*n*$ ($2 ≤ *n* ≤ 200 000$) — the size of the array $*a*$.

翻译中…

The second line contains $*n*$ integers $*a*_{*i*}$ ($1 ≤ *i* ≤ *n*$, $|*a*_{*i*}| ≤ 1 000 000$) — the elements of the array $*a*$.

翻译中…

Output

翻译中…

Print a single integer — the maximum possible value of characteristic of $*a*$ that can be obtained by performing no more than one move.

翻译中…

Note

翻译中…

In the first sample, one may pick the first element and place it before the third (before $5$). Thus, the answer will be $3·1 + 2·2 + 4·3 + 5·4 = 39$.

翻译中…

In the second sample, one may pick the fifth element of the array and place it before the third. The answer will be $1·1 + 1·2 + 1·3 + 2·4 + 7·5 = 49$.

翻译中…

样例

Input #1
4
4 3 2 5
Output #1
39
InputCopy OutputCopy
Input #2
5
1 1 2 7 1
Output #2
49
InputCopy OutputCopy
Input #3
3
1 1 2
Output #3
9
InputCopy OutputCopy
题目信息
题号
631E
时间限制
1 s
内存限制
256 MB
标签
数据结构
动态规划
计算几何

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。