#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int64_t n;
  cin >> n;
  int64_t a[n], sum = 0;
  for (int64_t i = 0; i < n; i++) cin >> a[i];
  for (int64_t i = n - 1; i > 0; i--)
    if (a[i] <= a[i - 1]) a[i - 1] = (0 > a[i] - 1) ? 0 : a[i] - 1;
  for (int64_t i = 0; i < n; i++) sum += a[i];
  cout << sum;
  return 0;
}
