N = int(input())
A = list(map(int, input().split()))
used = [False] * N
fixed = [False] * N
ans = 0
for _ in range(N):
    h = (-float('inf'), -1, -1)
    for i in range(N):
        if used[i]:
            continue
        valj = max([(A[i] * (abs(i-j)), j)
                    for j in range(N) if not fixed[j]])
        val, j = valj
        h = (val, i, j) if val > h[0] else h
    val, index, j = h
    ans += val
    used[index] = True
    fixed[j] = True
    # print(val, index, used)
print(ans)
