#include <bits/stdc++.h>
using namespace std;
struct debugger {
  static void call(const char* it) {}
  template <typename T, typename... valT>
  static void call(const char* it, T val, valT... rest) {
    string var = "";
    for (; *it && *it != ','; it++)
      if (*it != ' ') var += *it;
    cerr << var << '=' << val << " ";
    call(++it, rest...);
  }
};
int main() {
  int n;
  cin >> n;
  long long res = 0;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  res = v[n - 1];
  long long can = res - 1;
  for (int i = n - 2; n >= 0; i--) {
    if (i < 0) break;
    if (can == 0)
      break;
    else if (can >= v[i]) {
      res += v[i];
      can = (v[i] - 1);
      if (can == 1 and v[i] == 1) break;
    } else if (can < v[i]) {
      res += can;
      can--;
    }
  }
  cout << res << endl;
}
