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