#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long sum = 0;
  int cur = 1e9 + 1;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] >= cur) {
      sum = sum + max(0, (cur - 1));
      cur--;
    } else {
      sum = sum + a[i];
      cur = a[i];
    }
  }
  cout << sum << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
