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