n=int(input())
s=input().split()
for i in range(n):s[i]=int(s[i])
maxold=max(s)
indexold=s.index(maxold)
k=n-indexold
maxall=maxold-k
money=maxold*k
kk=k
maxnew=0
indexnew=0
while maxall>0:
    ss=s[:indexold:]
    if max(ss)>=kk:
        maxnew=max(ss)
        indexnew=s.index(maxnew)
        maxold=maxnew
        k=indexold-indexnew
        money+=(maxold-k)*k
        kk+=k
        indexold=indexnew
    maxall=maxold-kk
print(money)