#include <bits/stdc++.h>
using namespace std;
map<int, unordered_set<int>> gr;
map<int, unordered_set<int>> res;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
  }
  long long res = v[n - 1];
  long long curr = v[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    if (curr <= 0) break;
    if (v[i] == curr) {
      res += v[i] - 1;
      curr = v[i] - 1;
    } else if (v[i] < curr) {
      res += v[i];
      curr = v[i];
    } else {
      res += curr - 1;
      curr--;
    }
  }
  cout << res << endl;
  return 0;
}
