#include <bits/stdc++.h>
using namespace std;
long long a[200100];
int main() {
  long long n, ans = 0, l = 1000000000000;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] < l) {
      ans += a[i];
      l = a[i];
    } else {
      long long b = max(0ll, l - 1);
      ans += b;
      l = b;
    }
  }
  cout << ans << endl;
  return 0;
}
