#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  for (long long i = n - 1; i > 0; i--) {
    if (a[i - 1] >= a[i]) a[i - 1] = max(0LL, a[i] - 1);
  }
  long long an = 0;
  for (long long int i = 0; i < n; i++) an += a[i];
  cout << an;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long TESTS = 1;
  while (TESTS--) {
    solve();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    ;
  }
  return 0;
}
