import sys
input = sys.stdin.buffer.readline
from operator import itemgetter
sys.setrecursionlimit(10**7)

def main():
    N = int(input())
    a = list(map(int,input().split()))
    active = []
    
    for i in range(N):
        active.append((a[i],i))
        
    active.sort(key=itemgetter(0),reverse=True)
    
    def point(x,y,ind):
        if ind == N:
            return 0
        else:
            ret1 = point(x+1,y,ind+1)+active[ind][0]*(abs(active[ind][1]-x))
            ret2 = point(x,y-1,ind+1)+active[ind][0]*(abs(active[ind][1]-y))
            ret = max(ret1,ret2)
            return ret
    
    print(point(0,N-1,0))

if __name__ == "__main__":
    main()
