#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, a[maxn], b[maxn], c[maxn], num, res, cnt;
long long ans;
stack<int> s;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (s.empty()) {
      s.push(i);
      continue;
    }
    while ((!s.empty()) && (s.top() - a[s.top()] >= i - a[i])) s.pop();
    s.push(i);
  }
  while (!s.empty()) {
    b[++cnt] = s.top();
    c[cnt] = b[cnt] - a[b[cnt]] - 1;
    s.pop();
  }
  res = cnt;
  for (int i = 1; i <= n; i++) {
    if (res > 1 && i > b[res]) res--;
    if (i - num > c[res]) num++;
    ans = ans + (num - a[i] - 1);
  }
  cout << ans;
  return 0;
}
