#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    long long n;
    cin >> n;
    long long i;
    long long arr[n];
    for (i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long temp = 1000000007;
    long long sum = 0;
    for (i = n - 1; i >= 0; i--) {
      if (arr[i] >= temp) {
        if (temp == 0) {
          temp = 0;
          break;
        }
        sum += temp - 1;
        temp--;
      } else {
        sum += arr[i];
        temp = arr[i];
      }
    }
    cout << sum << endl;
  }
  return 0;
}
