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