#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  long long mx = v[n - 1];
  long long res = mx;
  for (long long i = n - 2; i >= 0; i--) {
    res += max(0ll, min(v[i], mx - 1));
    mx = min(v[i], mx - 1);
  }
  cout << res;
  return 0;
}
