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