#include <bits/stdc++.h>
using namespace std;
int m[100001], t[100001];
int main() {
  int64_t n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> m[i];
  int now = 0;
  for (int i = n - 1; i >= 0; i--) {
    now = (now - 1 < 0) ? 0 : now - 1;
    now = max(now, m[i] + 1);
    t[i] = now;
  }
  now = 0;
  for (int i = 0; i < n; i++) {
    now = max(now, t[i]);
    ans += now - m[i] - 1;
  }
  cout << ans << endl;
  return 0;
}
