n=int(input())
a=list(map(int,input().split(" ")))
d={}
lis=[]
sum=0
for i in range(len(a)):
    d[i+1]=a[i]
for t in sorted(d.items(),key=lambda x:(x[1],x[0]),reverse=True):
    lis.append(t)
start=1
for l in lis :
    if l[0]-start>n-l[0]:
        sum+=(l[0]-start)*l[1]
        start+=1
    else:
        sum+=(n-l[0])*l[1]
        n-=1


print(sum+1)
