#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout.setf(ios_base::fixed, ios_base::floatfield);
  int n;
  cin >> n;
  int64_t a[200000];
  for (int i = 0; i < n; i++) cin >> a[i];
  int64_t prev = INT32_MAX;
  int64_t ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    prev = min(a[i], prev - 1);
    ans += prev;
    if (prev <= 0) break;
  }
  cout << ans << endl;
  return 0;
}
