#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int *a = new int[n];
  long long ans = 0;
  int d = 0;
  int *q = new int[n];
  int *w = new int[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    q[i] = i - a[i];
  }
  w[n - 1] = q[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    w[i] = min(q[i], w[i + 1]);
  }
  for (int i = 1; i < n; ++i) {
    d = min(d + 1, w[i]);
    ans += i - d - a[i];
  }
  cout << ans;
  return 0;
}
