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