#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const long long maxnodes = 1005;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> v(n);
  map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
  }
  long long ans = v[n - 1];
  for (long long i = n - 2; i >= 0; i--) {
    if (v[i] < v[i + 1])
      ans += v[i];
    else {
      ans += max((long long)0, v[i + 1] - 1);
      v[i] = max((long long)0, v[i + 1] - 1);
    }
  }
  cout << ans;
  return 0;
}
