#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int sum = a[n - 1];
  long long int prev = a[n - 1];
  for (long long int i = n - 2; i >= 0; i--) {
    prev = min(a[i], max(0ll, prev - 1));
    sum += prev;
  }
  cout << sum;
}
