import random
import time
def LI():return list(map(int,input().split()))
start=time.time()
n=int(input()) # 2000 O(nn?),O(nlogn)
l=[i for i in range(n)]
a=LI()
ans=0
while True:
    if time.time()-start>1.85:
        print(ans)
        exit()
    random.shuffle(l)
    tmp=0
    for i,(j,k) in enumerate(zip(a,l)):
        tmp+=j*abs(i-k)
    ans=max(ans,tmp)