#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N], humidai[N], Ah[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    humidai[i] = 0;
    Ah[i] = A[i] + humidai[i];
  }
  int sum = 0;
  for (int i = 1; i < N; i++) {
    for (int j = 0; Ah[i] < Ah[i - 1]; j++) {
      humidai[i] += j;
      Ah[i] = A[i] + humidai[i];
    }
    sum += humidai[i];
  }
  cout << sum << endl;
}
