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