#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, i;
  long long a, b;
  cin >> n;
  i = a = 0, b = 1000000001;
  int arr[n];
  while (i < n) {
    cin >> arr[i];
    i++;
  }
  i = n - 1;
  while (i >= 0) {
    if (arr[i] < b) {
      a += arr[i];
      b = arr[i];
      if (b == 1) break;
    } else if (arr[i] >= b) {
      b--;
      a += b;
      if (b == 1) break;
    }
    i--;
  }
  cout << a << endl;
  return 0;
}
