#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int a[maxn], t[maxn];
int n;
long long ans = 0;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int cur = 0;
  for (int i = n - 1; i >= 0; --i) {
    cur--;
    cur = max(cur, a[i] + 1);
    t[i] = cur;
  }
  cur = 0;
  for (int i = 0; i < n; ++i) {
    cur = max(cur, t[i]);
    ans += (cur - a[i] - 1);
  }
  printf("%lld\n", ans);
  return 0;
}
