#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int Arr[N], Brr[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> Arr[i];
  int Cur = 0;
  for (int i = n; i >= 1; i--) {
    Cur = max(0, Cur - 1);
    Cur = max(Cur, Arr[i] + 1);
    Brr[i] = Cur;
  }
  long long int Sum = 0;
  for (int i = 1; i <= n; i++) {
    Cur = max(Cur, Brr[i]);
    Sum += Cur;
  }
  for (int i = 1; i <= n; i++) Sum -= (Arr[i] + 1);
  cout << Sum << "\n";
  return 0;
}
