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