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