#include <bits/stdc++.h>
using namespace std;
long long T[100100];
long long MI[100100];
int main() {
  long long N;
  while (cin >> N) {
    for (int i = 0; i < N; i++) cin >> T[i];
    long long minn = 0;
    for (int i = N - 1; i >= 0; i--) {
      minn--;
      minn = max(T[i] + 1, minn);
      MI[i] = minn;
    }
    for (int i = 1; i < N; i++) {
      MI[i] = max(MI[i], MI[i - 1]);
    }
    long long marks = 0;
    long long total = 0;
    for (int i = 0; i < N; i++) {
      total += MI[i] - T[i] - 1;
    }
    cout << total << endl;
  }
}
