#include <bits/stdc++.h>
using namespace std;
const int LIMIT = 2e5 + 5;
int n, a[LIMIT], prevC = 1e9 + 1;
long long r;
int main() {
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = n - 1; i >= 0; i--) {
    prevC = min(a[i], prevC - 1);
    if (prevC == 0) {
      break;
    }
    r += prevC;
  }
  printf("%lld\n", r);
  return 0;
}
