#include <bits/stdc++.h>
using namespace std;
int a[200006];
int n;
int main() {
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  int lim = 1e9 + 7;
  for (int i = n; i >= 1; i--) {
    if (a[i] < lim) {
      ans += a[i];
      lim = a[i];
    } else {
      ans += max(0, lim - 1);
      lim = max(0, lim - 1);
    }
  }
  cout << ans;
  return 0;
}
