#include <bits/stdc++.h>
using namespace std;
int n, a[550000];
long long tot = 0;
int getin() {
  int ans = 0;
  bool f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 0;
    c = getchar();
  }
  while (isdigit(c)) {
    ans = ans * 10 + c - '0';
    c = getchar();
  }
  if (f) return ans;
  return -ans;
}
int main() {
  n = getin();
  for (int i = 1; i <= n; i++) {
    a[i] = getin();
  }
  int maxx = a[n];
  tot = a[n];
  for (int i = n - 1; i >= 1; i--) {
    if (a[i] >= maxx)
      tot += max(--maxx, 0);
    else
      tot += a[i], maxx = a[i];
  }
  cout << tot;
  return 0;
}
