#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
int s[maxn];
int main() {
  int n;
  while (cin >> n) {
    long long t, sum = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &s[i]);
    }
    t = s[n];
    sum += s[n];
    for (int i = n - 1; i >= 1; i--) {
      if (s[i] >= t - 1)
        t -= 1;
      else
        t = s[i];
      if (t == 0) break;
      sum += t;
    }
    cout << sum << endl;
  }
  return 0;
}
