import itertools
N = int(input())
A = [0] + [int(_) for _ in input().split()]
list = [i+1 for i in range(N)]
comb = itertools.permutations(list, 2)
happy = []
for c in comb:
    happy.append([A[c[0]] * abs(c[0] - c[1]), c])
happy.sort(reverse=True)
fixed = [False for i in range(N+1)]
seated = [False for i in range(N+1)]
ans = 0
for h in happy:
    if not fixed[h[1][0]] and not seated[h[1][1]]:
        ans += h[0]
        fixed[h[1][0]] = True
        seated[h[1][1]] = True

print(ans)
