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 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/2e111bb14e07b268a6efbbdc554cdbef6e466ad0.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the sum of the products of the values *a*<sub class="lower-index">*i*</sub> 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.
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*<sub class="lower-index">*i*</sub> (1 ≤ *i* ≤ *n*, |*a*<sub class="lower-index">*i*</sub>| ≤ 1 000 000) — the elements of the array *a*.
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.
4
4 3 2 5
39
5
1 1 2 7 1
49
3
1 1 2
9
5
1 2 3 4 5
55
5
-1 -2 -3 -4 -5
-45
4
0 0 0 0
0
7
0 0 0 -1 0 0 0
-1
2
1000000 -1000000
1000000
2
1 1
3
2
-1 -1
-3
2
-1000000 1000000
1000000
2
0 0
0
4
2 1 3 4
30
5
1 2 5 4 5
62
4
2 3 4 1
30
4
4 1 2 3
30
6
5 7 11 83 14 999
6517
4
87 213 141 1
1378
from sys import stdin, stdout

def calculate(m0,c0,m1,c1):
    return (c0-c1)/(m1-m0)

n = int(stdin.readline())

A = [int(x) for x in stdin.readline().split()]
sigma = [0]
for i in range(n-1):
    sigma.append(sigma[-1]+A[i])
running_sum = sum([A[i]*(i+1) for i in range(n)])

answer = 0
line_stack = [(0,0)]
segment_lefts = [-1000000]
pointer = 0

for i in range(1,n-1):
    answer = max(answer, line_stack[pointer][0]*A[i]+line_stack[pointer][1]-A[i]*i+sigma[i])
    while len(line_stack) > 0 and calculate(line_stack[-1][0], line_stack[-1][1], i, -sigma[i]) <= segment_lefts[-1]:
        line_stack.pop()
        segment_lefts.pop()
    if len(line_stack) == 0:
        segment_lefts.append(-1000000)
    else:
        segment_lefts.append(calculate(line_stack[-1][0], line_stack[-1][1], i, -sigma[i]))
    line_stack.append((i, -sigma[i]))

    lower = 0
    upper = len(line_stack)
    while upper - lower > 1:
        candidate = (upper + lower)//2
        if segment_lefts[candidate] > A[i+1]:
            upper = candidate
        else:
            lower = candidate
    pointer = lower

answer = max(answer, line_stack[pointer][0]*A[n-1]+line_stack[pointer][1]-A[n-1]*(n-1)+sigma[n-1])

sigma = [0]
for i in range(n-1,0,-1):
    sigma.append(sigma[-1]+A[i])

line_stack = [(-(n-1),0)]
segment_lefts = [-1000000]
pointer = 0

for i in range(n-2,0,-1):
    answer = max(answer, line_stack[pointer][0]*(-A[i])+line_stack[pointer][1]-A[i]*i-sigma[n-1-i])
    while len(line_stack) > 0 and calculate(line_stack[-1][0], line_stack[-1][1], -i, sigma[n-1-i]) <= segment_lefts[-1]:
        line_stack.pop()
        segment_lefts.pop()
    if len(line_stack) == 0:
        segment_lefts.append(-1000000)
    else:
        segment_lefts.append(calculate(line_stack[-1][0], line_stack[-1][1], -i, sigma[n-1-i]))
    line_stack.append((-i, sigma[n-1-i]))

    lower = 0
    upper = len(line_stack)
    while upper - lower > 1:
        candidate = (upper + lower)//2
        if segment_lefts[candidate] > -A[i-1]:
            upper = candidate
        else:
            lower = candidate
    pointer = lower

answer = max(answer, line_stack[pointer][0]*(-A[0])+line_stack[pointer][1]-sigma[n-1])

true_answer = answer + running_sum
stdout.write('{}\n'.format(true_answer))
