#ここまでテンプレ
from sys import stdin
from sys import setrecursionlimit

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))

ma = 0

#i人分ずらす
for i in range(n):
    #j番目の人に対する操作
    point = 0
    for j in range(n):
        iti = min(i,abs(j-(j+i)%n))
        point += a[j]*iti
    ma = max(ma,point)
    
print(ma)