#include <bits/stdc++.h>
using namespace std;
int n;
long long a[200010];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  long long ans = 0, cnt = 1e18;
  for (int i = n; i >= 1; --i) {
    cnt = min(a[i], cnt - 1);
    ans += max((long long)0, cnt);
  }
  cout << ans << endl;
  return 0;
}
