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