#include <bits/stdc++.h>
using namespace std;
struct compare {
  bool operator()(const pair<long long int, long long int> &l,
                  const pair<long long int, long long int> &r) {
    if (l.first == r.first) return l.second > r.second;
    return l.first > r.first;
  }
};
priority_queue<pair<long long int, long long int>,
               vector<pair<long long int, long long int> >, compare>
    pq;
long long int min(long long int a, long long int b) { return a <= b ? a : b; }
long long int max(long long int a, long long int b) { return a >= b ? a : b; }
long long int abso(long long int n) { return n >= 0 ? n : -n; }
int main(int argc, char const *argv[]) {
  int n;
  vector<long long int> V;
  long long int ans = 0;
  cin >> n;
  V.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> V[i];
  }
  long long int last = 10000000000;
  for (int i = n - 1; i >= 0; i--) {
    if (V[i] < last) {
      ans += V[i];
      last = V[i];
    } else {
      ans += max(0, min(last - 1, V[i] - 1));
      last = max(0, min(last - 1, V[i] - 1));
    }
  }
  cout << ans << "\n";
}
