n = int(input())
a=list(map(int,input().split()))
s=a[-1]
b=a[-1]
k=1
for i in range(n-1,0,-1):
  if a[i]==b:
    s+=a[i]
    k+=1
  elif a[i]>b:
    a[i]=b
    s+=b
    k+=1
  else:
    b=a[i]-k
    k+=1 
print (s)
