def calc(a,k):
    b = a.copy()
    ret = 0
    if k == 0:
        b.sort()
    elif k == n:
        b.sort(reverse=True)
    else:
        c = b[:k]
        d = b[k:]
        c.sort
        d.sort(reverse=True)
        b = d+c
    #print(b)
    for i in range(n):
        ret += b[i][0] * abs(b[i][1] - i)
    #print(k,ret)
    return ret

n = int(input())
a = [[int(num),-1] for num in input().split()]

for i in range(n):
    a[i][1] = i
    
ans = 0
for k in range(n+1):
    ans = max(ans,calc(a,k))
    
print(ans)