#include <bits/stdc++.h>
using namespace std;
int minim(long long a, long long b) {
  if (a < b) return a;
  return b;
}
long x[200001];
int main() {
  long long n, ch, l, mn;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> x[i];
  l = x[n] - 1;
  ch = x[n];
  int i = n - 1;
  mn = l;
  while (i >= 1 && mn != 0) {
    mn = minim(x[i], l);
    if (mn == 0)
      l = mn;
    else
      l = mn - 1;
    ch += mn;
    i--;
  }
  cout << ch << endl;
  return 0;
}
