#include <bits/stdc++.h>
using namespace std;
long long n;
long long x[100105];
long long lt[100105];
long long rt[100105];
int main() {
  scanf("%I64d", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%I64d", x + i);
    lt[i] = x[i];
    rt[i] = x[i];
  }
  for (long long i = 1, j = n; i < n && j > 1; i++, j--) {
    if (lt[i] >= lt[i + 1]) {
      lt[i + 1] = lt[i] + 1;
    }
    if (rt[j] >= rt[j - 1]) {
      rt[j - 1] = rt[j] + 1;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += min(lt[i], rt[i]) - x[i];
    x[i] = min(lt[i], rt[i]);
  }
  for (long long i = 1; i <= n; i++) {
    if (x[i] == x[i - 1]) ans++;
  }
  printf("%I64d\n", ans);
  return 0;
}
