#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long arr[n];
  for (int i = n - 1; i >= 0; i--) scanf("%lld", &arr[i]);
  long long ans = arr[0], last = arr[0];
  for (int i = 1; i < n && last > 0; i++) {
    last = min(arr[i], last - 1);
    ans += last;
  }
  cout << ans;
}
