import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))
"""
lst2 = [[0]*n for _ in range(n)]

for i in range(n): #座標
    for j in range(n): #もの
        lst2[i][j] = abs(i-j)*lst1[j]"""

unused = [1]*n
l = 0
r = n-1
g = 0
ans = 0
while g < n:
    res = -10**9
    idx = None
    if g%2==0:
        for i in range(n):
            if unused[i] and abs(l-i)*lst1[i] >= res:
                if abs(l-i)*lst1[i] == res: #その値が小さい方優先
                    if lst1[i] < lst1[idx]:
                        idx = i
                else:
                    idx = i
                    res = abs(l-i)*lst1[i]
        unused[idx] = 0
        ans += res

        l += 1
    else:
        for i in range(n):
            if unused[i] and abs(r-i)*lst1[i] >= res:
                if abs(l-i)*lst1[i] == res:
                    if lst1[i] < lst1[idx]:
                        idx = i
                else:
                    idx = i
                    res = abs(r-i)*lst1[i]
        unused[idx] = 0
        ans += res

        r -= 1
    
    g += 1
unused = [1]*n
l = 0
r = n-1
g = 0
ans2 = 0
while g < n:
    res = -10**9
    idx = None
    if g%2==1:
        for i in range(n):
            if unused[i] and abs(l-i)*lst1[i] >= res:
                if abs(l-i)*lst1[i] == res: #その値が小さい方優先
                    if lst1[i] < lst1[idx]:
                        idx = i
                else:
                    idx = i
                    res = abs(l-i)*lst1[i]
        unused[idx] = 0
        ans2 += res

        l += 1
    else:
        for i in range(n):
            if unused[i] and abs(r-i)*lst1[i] >= res:
                if abs(l-i)*lst1[i] == res:
                    if lst1[i] < lst1[idx]:
                        idx = i
                else:
                    idx = i
                    res = abs(r-i)*lst1[i]
        unused[idx] = 0
        ans2 += res

        r -= 1
    
    g += 1
print(max(ans,ans2))