#include <bits/stdc++.h>
using namespace std;
void printa(int a[], int n) {
  cout << "[";
  for (int i = 0; i < n; ++i) cout << a[i] << " ";
  cout << "]" << endl;
}
template <typename T>
void printv(vector<T> v, int n) {
  cout << "[";
  for (int i = 0; i < n && i < v.size(); ++i) cout << v[i] << " ";
  cout << "]" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, arr[200000];
  long long int ans;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  ans = 0;
  for (int i = n - 1; i > 0; --i) {
    if (arr[i] > 0) {
      if (arr[i] <= arr[i - 1]) arr[i - 1] = arr[i] - 1;
    } else {
      arr[i - 1] = 0;
    }
    ans += arr[i];
  }
  ans += arr[0];
  cout << ans << endl;
  return 0;
}
