#include <bits/stdc++.h>
const int maxn = 1e5 + 5;
using namespace std;
long long arr[2 * maxn];
int main() {
  long long n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) scanf("%lld", &arr[i]);
  sum += arr[n];
  for (int i = n - 1; i >= 1; i--) {
    if (arr[i] >= arr[i + 1]) {
      sum += max((long long)0, arr[i + 1] - 1);
      arr[i] = max((long long)0, arr[i + 1] - 1);
    } else {
      sum += arr[i];
    }
  }
  cout << sum << endl;
  return 0;
}
