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