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