#include <bits/stdc++.h>
using namespace std;
int n, a[200000], i;
long long s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  s = a[n - 1];
  for (i = n - 2; i >= 0; i--) {
    a[i] = max(0, min(a[i], a[i + 1] - 1));
    s += a[i];
  }
  cout << s;
}
