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