#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[1000000];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int cur = a[n - 1];
  long long total = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    cur = min(cur - 1, a[i]);
    cur = max(0, cur);
    total += cur;
  }
  cout << total;
  return 0;
}
