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