#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = a.back();
  for (int i = n - 2; i >= 0; i--) {
    if (a[i] >= a[i + 1] - 1) {
      a[i] = a[i + 1] - 1;
    }
    ans += 1LL * a[i];
    if (a[i] == 0) {
      break;
    }
  }
  cout << ans << endl;
}
