import sys
n =int(sys.stdin.readline())
l = list(map(int,sys.stdin.readline().split()))
dp = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
    for j in range(n):
        dp[i][j] = l[j]*abs(i-j)
idone = {}
jdone = {}
got = 0
ans = 0
while got<n:
    local = 0
    for i in range(n):
        for j in range(n):
            if i not in idone and j not in jdone:
                if local<dp[i][j]:
                    ido = i
                    jdo = j
                    local = dp[i][j]
    idone[ido] = 1
    jdone[jdo] = 1
    ans += local
    got += 1
sys.stdout.write((str(ans)+'\n'))