#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long s[n];
  for (long long c = 0; c < n; c++) cin >> s[c];
  long long sum = 0;
  long long nextAllowedNum = 10000000000000 + 33;
  for (long long c = n - 1; c >= 0; c--) {
    if (nextAllowedNum <= 0) break;
    long long takeval = 0;
    takeval = s[c] <= nextAllowedNum ? s[c] : nextAllowedNum;
    nextAllowedNum = takeval - 1;
    sum += takeval;
  }
  cout << sum << endl;
  return 0;
}
