import numpy as np
N = int(input())
B = [[] for _ in range(N)]
for i, A in enumerate(input().split()):
    for j in range(N):
        B[j].append(int(A)*abs(i-j))
# print(B)
S = 0
while B != []:
    for i in range(len(B)):
        n = np.argmax(B[i])
        if np.argmax(np.array(B).T.tolist()[n]) == i:
            S += B[i][n]
            for j in range(len(B)):
                del B[j][n]
            del B[i]
print(S)
