https://www.acmicpc.net/problem/2847
n=int(input()) arr=[0]*n count=0 for i in range(n): arr[i]=int(input()) for i in range(n-1,0,-1): if arr[i]<=arr[i-1]: count+=arr[i-1]-arr[i]+1 arr[i-1]=arr[i]-1 print(count)