n=int(input())
s=list(map(int, input().split()))
p={}
for i in range(n):
    p[i+1]=s[i]
a=0
b=[0]
c=0
e=0
f=0
g=[]
h=n
l=1
m=0
for j in range(1,n+1):
    c=0
    f=0
    for i in range(1,n+1):

        d=0
        if not(i in g):


            d=max((h-i),i-l)
            # print(c,d,h,i,j,l)
            if c<p[i]*d:
                c=p[i]*d
                f=i

            elif c==p[i]*d and d>e:
                e=d
                c=p[i]*d
                f=i

    if (h-f)>(f-l):
        h-=1
    else:
        l+=1
    g.append(f)
    m+=c
print(m)
