import heapq

n = int(input())
alist = list(map(int,input().split()))

def calc_hapiness(x,y,a):
    return abs(x-y)*a

q = []
for i in range(n):
    for j in range(n):
        heapq.heappush(q,(-calc_hapiness(i,j,alist[i]),i,j))

used_a = [0]*(n+1)
used_new = [0]*(n+1)
cost  = 0
while used_new.count(1) != n:
    a = heapq.heappop(q)
    if used_a[a[1]] == 0 and used_new[a[2]] == 0:
        cost += a[0]
        used_a[a[1]] = 1
        used_new[a[2]] = 1

print(-cost)
