#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, ans;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  ans = 0;
  long long c = 0;
  long long min_h = INT_MAX;
  for (long long i = n - 1; i >= 0; i--) {
    v[i] = max(min(min_h, v[i]), c);
    ans += v[i];
    min_h = v[i] - 1;
  }
  cout << ans;
}
