#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = long long;
using ld = long double;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &i : a) {
    cin >> i;
  }
  ll res = a[n - 1];
  int prev = a[n - 1] - 1;
  for (int i = n - 2; i >= 0; --i) {
    int x = min(prev, a[i]);
    prev = x - 1 < 0 ? 0 : x - 1;
    res += x;
  }
  cout << res << '\n';
}
