#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  int *a = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int count = a[n - 1];
  long long int max = a[n - 1] - 1;
  for (int i = n - 2; i >= 0; i--) {
    if (max > 0) {
      if (a[i] >= max) {
        count += max;
        max -= 1;
      } else {
        count += a[i];
        max = a[i] - 1;
      }
    }
  }
  cout << count << endl;
  return 0;
}
