N = int(input())
A = list(map(int, input().split()))

candidates = list(range(N))
order = [0] * N
order[::2] = candidates[N // 2:][::-1]
order[1::2] = candidates[:N // 2]
ans = 0
for i in order:
    max_h = -1
    max_j = 0
    for j in candidates:
        h = A[j] * abs(i - j)
        if h > max_h:
            max_j = j
            max_h = h
    ans += max_h
    candidates.remove(max_j)
print(ans)