#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n];
  int t[n];
  int i, cur;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = n - 1; i >= 0; --i) {
    cur = max(0, cur - 1);
    cur = max(cur, a[i] + 1);
    t[i] = cur;
  }
  long long ans = 0;
  for (i = 0, cur = 0; i < n; ++i) {
    cur = max(cur, t[i]);
    ans += cur;
  }
  for (i = 0; i < n; ++i) ans -= (a[i] + 1);
  printf("%lld\n", ans);
  return 0;
}
