#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  long long ans = a[n - 1], last = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    last = max(0LL, min(last - 1, a[i]));
    ans += last;
  }
  cout << ans << '\n';
  return 0;
}
