#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int N = 1e5 + 5;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  vector<long long int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  long long int ans = 0, prev = LLONG_MAX;
  for (int i = n - 1; i >= 0; i--) {
    if (prev > a[i]) {
      ans += a[i];
      prev = a[i];
    } else if (prev <= a[i] && prev != 0) {
      ans += prev - 1;
      prev -= 1;
    } else if (prev == 1)
      break;
  }
  cout << ans << "\n";
}
