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