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