#include <bits/stdc++.h>
using namespace std;
bool taketests = false;
long long n, m, k;
string str = "";
long long binary(long long* arr, long long size, long long val) {
  long long low = 0;
  long long high = size - 1;
  while (low <= high) {
    long long mid = (high + low) / 2;
    if (low == high) {
      if (arr[low] <= val) {
        return low;
      } else {
        return low - 1;
      }
    }
    if (arr[mid] == val) {
      return mid;
    } else if (arr[mid] < val) {
      low = mid + 1;
    } else {
      high = mid;
    }
  }
  return 0;
}
void run() {
  cin >> n;
  long long marks[n];
  for (long long int i = 0; i < n; i++) {
    cin >> marks[i];
  }
  long long skipped[n];
  long long currmin = n;
  for (int i = n - 1; i >= 0; i--) {
    skipped[i] = min(currmin, i - marks[i]);
    currmin = skipped[i];
  }
  for (int i = 1; i < n; i++) {
    if (skipped[i] - skipped[i - 1] >= 1) {
      skipped[i] = skipped[i - 1] + 1;
    } else {
      skipped[i] = skipped[i - 1];
    }
  }
  long long count = 0;
  long long nummarks = 1;
  for (int i = 1; i < n; i++) {
    count += (nummarks - marks[i]);
    if (skipped[i] <= skipped[i - 1]) {
      nummarks++;
    } else {
      count--;
    }
  }
  cout << setprecision(30) << count << endl;
  return;
  ;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int tests = 1;
  if (taketests) cin >> tests;
  for (int i = 0; i < tests; i++) {
    run();
  }
  return 0;
}
