#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  reverse(arr, arr + n);
  long long countt = 0;
  for (int i = 0; i < n - 1; i++) {
    if (arr[i + 1] < arr[i]) {
      countt += arr[i];
    } else if (arr[i + 1] >= arr[i]) {
      countt += arr[i];
      if (arr[i] - 1 >= 0) {
        arr[i + 1] = arr[i] - 1;
      } else {
        arr[i + 1] = 0;
      }
    }
  }
  if (arr[n - 1] > 0) {
    countt += arr[n - 1];
  } else {
    countt += 0;
  }
  cout << countt << '\n';
}
