https://www.acmicpc.net/problem/2847
#include<iostream>
using namespace std;
int n;
const int MAX = 100;
int arr[MAX];
int solution(){
int answer = 0;
int post = arr[n-1];
for(int i=n-2;i>=0;i--){
if(post <= arr[i]){
answer += arr[i]-post+1;
post--;
}else{
post = arr[i];
}
}
return answer;
}
#include<cstdio>
int n,a[100],r;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", a+i);
for (int i = n-1; i; i--) if (a[i-1] >= a[i]) r+=a[i-1]-a[i]+1,a[i-1] = a[i] - 1;
printf("%d", r);
return 0;
}