#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  cout << endl;
  long long arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long sum = 0;
  ;
  for (int i = n - 2; i >= 0; i--) {
    if (arr[i] >= arr[i + 1]) {
      if (arr[i + 1] == 1 || arr[i + 1] == 0)
        arr[i] = 0;
      else
        arr[i] = arr[i + 1] - 1;
    }
  }
  for (int i = 0; i < n; i++) {
    sum = sum + arr[i];
  }
  cout << sum;
}
