#include <bits/stdc++.h>
using namespace std;
vector<long long> subr(vector<long long> v) {
  long long n = v.size();
  vector<long long> res(n + 1, 0);
  long long i = 0;
  while (i < n) {
    if (v[i] == 0) {
      i++;
      continue;
    }
    long long j = i;
    while (j < n and v[j] == 1) {
      j++;
    }
    for (int k = 1; k <= j - i; k++) {
      res[k] += j - i - k + 1;
    }
    i = j;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n;
  cin >> n;
  long long arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long val = arr[n - 1];
  long long sum = arr[n - 1];
  for (int i = n - 1 - 1; i >= 0; i--) {
    val = min(val - 1, arr[i]);
    if (val < 0) val = 0;
    sum += val;
  }
  cout << sum;
  return 0;
}
