import sys
n = int(sys.stdin.readline().strip())
A = map(int, sys.stdin.readline().split())
A = list(A)
Mhappy = -1
for mv in range(1, n):
    happy = 0
    for i, a in enumerate(A):
        happy += a * abs( (i+mv) % n - i)
    #print(mv, happy)
    Mhappy = max(happy, Mhappy)
print(Mhappy)
