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