#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, i;
  cin >> n;
  long long arr[n];
  for (i = 0; i < n; i++) cin >> arr[i];
  long long sum = 0;
  for (i = n - 1; i > 0; i--) {
    if (arr[i] > arr[i - 1]) {
      sum = sum + arr[i];
    } else {
      arr[i - 1] = arr[i] - 1;
      if (arr[i - 1] < 0) arr[i - 1] = 0;
      sum = sum + arr[i];
    }
  }
  sum = sum + arr[0];
  cout << sum;
}
