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
import bisect
import operator

class Point(tuple):
    def __new__(self, a, b):
        return tuple.__new__(self, (a, b))
    def __add__(self, x):
        if type(x) != type(self): x = Point(x, 1)
        return Point(self[0] * x[1] + self[1] * x[0], self[1] * x[1])
    def __sub__(self, x):
        if type(x) != type(self): x = Point(x, 1)
        return Point(self[0] * x[1] - self[1] * x[0], self[1] * x[1])
    def __neg__(self):
        return Point(-self[0], self[1])
    def __mul__(self, x):
        if type(x) != type(self): x = Point(x, 1)
        return Point(x[0] * self[0], x[1] * self[1])
    def __rmul__(self, k):
        return self.__mul__(k)
    def __eq__(self, x):
        if type(x) != type(self): x = Point(x, 1)
        return self[0] * x[1] == self[1] * x[0]
    def __le__(self, x):
        if type(x) != type(self): x = Point(x, 1)
        return self[0] * x[1] <= self[1] * x[0]
    def __ge__(self, x):
        if type(x) != type(self): x = Point(x, 1)
        return self[0] * x[1] >= self[1] * x[0]
    def __ne__(self, x): return not self.__eq__(x)
    def __gt__(self, x): return not self.__le__(x)
    def __lt__(self, x): return not self.__ge__(x)

class LinearFunction(tuple):
    def __new__(self, a, b):
        return tuple.__new__(self, (a, b))
    def __add__(self, f):
        return LinearFunction(self[0] + f[0], self[1] + f[1])
    def __sub__(self, f):
        return LinearFunction(self[0] - f[0], self[1] - f[1])
    def __neg__(self):
        return LinearFunction(-self[0], -self[1])
    def __mul__(self, k):
        return LinearFunction(k * self[0], k * self[1])
    def __rmul__(self, k):
        return self.__mul__(k)
    def __call__(self, x):
        return self[0] * x + self[1]
    def __and__(self, f):
        return Point(self[1] -f[1], f[0] - self[0])


class ConvexHull():
    def __init__(self, L):
        self.stack, self.points = [], []
        for f in sorted(L):
            while len(self.stack) > 1 and f(self.points[-1]) >= self.stack[-1](self.points[-1]):
                self.stack.pop()
                self.points.pop()
            if self.stack:
                x = self.stack[-1] & f
                self.stack.append(f)
                self.points.append(x)
            else:
                self.stack.append(f)
    def __call__(self, x):
        i = bisect.bisect(self.points, x)
        return self.stack[i](x)

from itertools import accumulate

def solve():
    n = int(input())
    A = [int(x) for x in input().split()]
    S = list(accumulate(A))
    C = ConvexHull(LinearFunction(l, -S[l]) for l in range(n))
    return max(C(A[r]) + S[r] - r*A[r] for r in range(n)) + sum((r+1)*A[r] for r in range(n))

print(solve())
