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