https://www.acmicpc.net/problem/2847
using System;
class Program
{
static void Main() {
string s=Console.ReadLine();
int n=int.Parse(s);
int[] arr=new int[n];
int count=0;
for(int i=0;i<n;i++){
string s1=Console.ReadLine();
arr[i]=int.Parse(s1);
}
for(int i=n-1;i>0;i--){
if(arr[i]<=arr[i-1]){
count+=arr[i-1]-arr[i]+1;
arr[i-1]=arr[i]-1;
}
}
Console.Write(count);
}
}