import sys
import itertools
import heapq
import numpy as np
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()

ans=0
l_infant=[[0]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        l_infant[i][j]=A[i]*abs(j-i)

a_infant=np.array(l_infant)

for i in range(N):
        idx = np.unravel_index(np.argmax(a_infant), a_infant.shape)
        ans += a_infant[idx[0]][idx[1]] 
        a_infant=np.delete(a_infant,idx[0],0)
        a_infant=np.delete(a_infant,idx[1],1)

print(ans)