#include <bits/stdc++.h>
using namespace std;
long long int calc(int i, vector<int> &v) {
  long long int sum = v[i];
  int cnt = v[i];
  for (int j = i - 1; j >= 0; j -= 1) {
    if (cnt > 0) cnt--;
    cnt = min(cnt, v[j]);
    sum += cnt;
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i += 1) cin >> v[i];
  int m = v[n - 1];
  long long int sum = 0;
  sum = max(sum, calc(n - 1, v));
  cout << sum;
  return 0;
}
