#include <bits/stdc++.h>
using namespace std;
int n, k[100005], a[100005];
long long sumk, suma;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k[i]);
    sumk += (long long)k[i];
  }
  a[1] = 1;
  for (int i = 2; i <= n; i++) {
    a[i] = max(a[i - 1], k[i] + 1);
  }
  for (int i = n - 1; i >= 1; i--) {
    a[i] = max(a[i], a[i + 1] - 1);
  }
  for (int i = 1; i <= n; i++) suma += (long long)a[i];
  printf("%I64d\n", suma - sumk - (long long)n);
  return 0;
}
