#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int *a;
  int i, ct;
  int sum = 0;
  cin >> n;
  a = new int[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 1; i < n; i++) {
    ct = 0;
    a[i] = a[i] + ct;
    while (a[i] < a[i - 1]) {
      ct++;
      a[i] = a[i] + ct;
    }
    sum += ct;
  }
  cout << sum;
  return 0;
}
