#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], x[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  x[n - 1] = n - 1 - a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    x[i] = min(x[i + 1], i - a[i]);
  }
  for (int i = 1; i < n; i++) {
    x[i] = min(x[i - 1] + 1, x[i]);
  }
  long long res = 0;
  for (int i = 0; i < n; i++) {
    res = res + (long long)(i - a[i] - x[i]);
  }
  cout << res << "\n";
  return 0;
}
