#include <bits/stdc++.h>
using namespace std;
int input() {
  int res = 0;
  char c = ' ';
  while (c < '0') c = getchar();
  while (c >= '0') res = res * 10 + (c - '0'), c = getchar();
  return res;
}
const int N = 1e5 + 1;
long long a[N], ev[N], C[N];
int main() {
  int n = input();
  for (int i = 0; i < n; ++i) {
    a[i] = input();
    ev[i] = a[i] - i;
  }
  ev[n] = -1e9;
  for (int i = n - 1; i >= 0; --i) ev[i] = max(ev[i], ev[i + 1]);
  long long cur = 0, ans = 0;
  for (int i = 0; i < n; ++i) {
    long long res = ev[i] + i;
    cur = max(cur, C[i] = max(cur, res));
    ans += cur - a[i];
  }
  cout << ans;
}
