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