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)
ans = 0
cnt = 0
xx = [0]*n
yy = [0]*n
for pt, xyarr in desc:
  for x,y in xyarr:
    if xx[x] == 0 and yy[y] == 0:
      ans += pt
      cnt += 1
      xx[x] = 1
      yy[y] = 1
      if cnt >= n: break
  if cnt >= n: break
print(ans)