import sys
import math
from collections import deque
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()

start = [False]*(N+1)
visited = [False]*(N+1)

heappop = heapq.heappop
heappush = heapq.heappush
d = []

for i in range(N):
  for j in range(N):
    heappush(d, (-a[i]*abs(i-j), i, j)) # (score, st, ed)

ans = 0
while d:
  num,st,ed = heappop(d)
  if start[st] == False and visited[ed] == False:
    ans += num
    start[st] = True
    visited[ed] = True
print(-ans)