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