n = int(input())
A = list(map(int, input().split()))
dc = dict()
for i in range(n):
  for j in range(n):
    pt = A[i] * abs(i-j)
    if dc.get(pt) == None:
      dc[pt] = [(i,j)]
    else:
      dc[pt].append((i,j))
desc = sorted(dc.items(), key=lambda x: x[0], reverse=True)
import numpy as np
ans = 0
table = np.zeros((n,n))
for pt, xyarr in desc:
  for x,y in xyarr:
    if table[x,y] == 0:
      ans += pt
      table[x,:] = 1
      table[:,y] = 1
print(ans)