import sys
from math import pi
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    left = 0
    right = N-1
    ans = 0
    used = [False]*N
    while right - left >0:
        l_max = -1
        l_index = 0
        r_max = -1
        r_index = 0
        for i in range(N):
            if used[i] == False:
                l = A[i] * abs(left-i)
                r = A[i] * abs(right - i)
                if l_max<l:
                    l_index = i
                    l_max = l
                if r_max<r:
                    r_index = i
                    r_max = r
        if l_index == r_index:
            if l_max>=r_max:
                ans += l_max
                used[l_index]=True
                left += 1
            else:
                ans += r_max
                used[r_index]=True
                right -= 1
        else:
            ans += l_max + r_max
            used[r_index]=True
            used[l_index]=True
            left += 1
            right -= 1
    print(ans)


if __name__ == '__main__':
    main()