#include <bits/stdc++.h>
using namespace std;
int dx[] = {+1, -1, +0, +0};
int dy[] = {+0, +0, +1, -1};
int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int hr[] = {-2, -2, -1, +1, +2, +2, -1, +1};
int hc[] = {+1, -1, +2, +2, -1, +1, -2, -2};
const int MAXN = (int)1e5 + 9;
const int N = 100000;
int main() {
  long long i, j, k, l, m, n, p, q, r, tc, t;
  cin >> n;
  long long ara[n + 9];
  for (i = 1; i <= n; i++) cin >> ara[i];
  long long sum = ara[n];
  r = ara[n];
  for (i = n - 1; i >= 1; i--) {
    if (r == 1) break;
    if (ara[i] >= r) {
      sum += r - 1;
      r = r - 1;
    } else if (ara[i] < r) {
      sum += ara[i];
      r = ara[i];
    }
  }
  cout << sum << endl;
  return 0;
}
