#include <bits/stdc++.h>
using namespace std;
using ii = pair<long long, long long>;
vector<ii> dirs = {
    {1, 0},  {0, 1},   {-1, 0}, {0, -1}, {1, 1},
    {-1, 1}, {-1, -1}, {1, -1}, {0, 0},
};
template <class T>
inline bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
ostream& operator<<(ostream& s, vector<T>& d) {
  for (long long i = 0, max_i = (d.size()); i < max_i; i++)
    s << d[i] << (i == d.size() - 1 ? "" : " ");
  return s;
}
template <class T>
ostream& operator<<(ostream& s, vector<vector<T>>& d) {
  for (long long i = 0, max_i = (d.size()); i < max_i; i++)
    s << d[i] << (i == d.size() - 1 ? "" : "\n");
  return s;
}
template <class T, class S>
ostream& operator<<(ostream& s, pair<T, S>& p) {
  s << "{" << p.first << ", " << p.second << "}";
  return s;
}
template <class T, class S>
ostream& operator<<(ostream& s, map<T, S> m) {
  for (auto it = m.begin(); it != m.end(); it++) {
    s << *it << (next(it) == m.end() ? "" : "\n");
  }
  return s;
}
void dump_func() { cerr << "\n"; }
template <class Head, class... Tail>
void dump_func(Head&& h, Tail&&... t) {
  cerr << h << (sizeof...(Tail) == 0 ? "" : ", "),
      dump_func(forward<Tail>(t)...);
}
struct Fast {
  Fast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr long long MOD = 1000000007;
signed main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0, max_i = (n); i < max_i; i++) cin >> a[i];
  long long prev = a[n - 1];
  long long ans = prev;
  for (long long i = n - 2; i >= 0; i--) {
    ;
    prev = min(a[i], prev - 1);
    if (prev <= 0) break;
    ans += prev;
  }
  cout << ans << "\n";
}
