#include <bits/stdc++.h>
using namespace std;
void nop() {}
constexpr long long MOD = 1e9 + 7;
constexpr int INF = 2e9;
constexpr long long INFL = 8e18;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &ai : a) cin >> ai;
  reverse(a.begin(), a.end());
  long long ans = 0;
  int prevai = INF;
  for (int ai : a) {
    int cans = min(ai, max(0, prevai - 1));
    ans += cans;
    prevai = cans;
  }
  cout << ans << endl;
  return 0;
}
