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