#include <bits/stdc++.h>
using namespace std;
int n, a[200005];
long long ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = n - 1; i >= 1; i--)
    if (a[i] >= a[i + 1]) a[i] = max(0, a[i + 1] - 1);
  for (int i = 1; i <= n; i++) ans += (long long)a[i];
  cout << ans << endl;
}
