#include <bits/stdc++.h>
using namespace std;
int num[200005];
int main() {
  long long n, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  int last = 1e9 + 5;
  for (int i = n - 1; i >= 0; i--) {
    int add = max(0, min(last - 1, num[i]));
    sum += add;
    last = add;
  }
  cout << sum;
}
