N, *A = map(int, open(0).read().split())

dp = [[0] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        dp[i][j] = A[i] * abs(i - j)

ms = [max(dp[i]) for i in range(N)]
filled = [False] * N
ans = 0
for i, _ in sorted(enumerate(ms), key=lambda x: -x[1]):
    for j, v in sorted(enumerate(dp[i]), key=lambda x: -x[1]):
        if filled[j]:
            continue
            
        filled[j] = True
        ans += v
        break
        
print(ans)

