import sys,math,copy,queue,itertools,bisect
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

N = NI()
A = LI()

ure = 0
top = 0
bot = N-1
for k in range(N):
    max_u = 0
    max_i = -1
    max_tb = -1
    for i in range(N):
        u1 = abs(top-i) * A[i]
        u2 = abs(bot-i) * A[i]
        if u1 > u2:
            if u1 > max_u:
                max_u = u1
                max_i = i
                max_tb = 1
        else:
            if u2 > max_u:
                max_u = u2
                max_i = i
                max_tb = 2
    ure += max_u
    A[max_i] = 0
    if max_tb == 1:
        top += 1
    else:
        bot -= 1
print (ure)
