#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int a[200001];
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  long long buy = a[n - 1];
  int pre = a[n - 1];
  for (i = n - 2; i >= 0; i--) {
    if (a[i] >= pre - 1) {
      if (pre - 1 == 0)
        break;
      else
        buy += pre - 1;
      pre--;
    } else {
      buy += a[i];
      pre = a[i];
    }
  }
  printf("%lld\n", buy);
  return 0;
}
