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