#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long ans = 0;
  long long pos = LLONG_MAX;
  for (long long i = n - 1; i >= 0; i--) {
    pos = max(min(pos - 1, a[i]), 0LL);
    ans += pos;
  }
  cout << ans;
  return 0;
}
