#include <bits/stdc++.h>
int main() {
  long long int types[1000000], n;
  scanf("%lld", &n);
  for (long long int i = 0; i < n; i++) scanf("%lld", &types[i]);
  long long int t;
  long long int max = types[n - 1];
  for (long long int i = n - 2; i >= 0; i--) {
    t = ((types[i]) < (types[i + 1] - 1) ? (types[i]) : (types[i + 1] - 1));
    types[i] = (t >= 0) ? t : 0;
    max += types[i];
  }
  printf("%lld", max);
  return 0;
}
