#include <bits/stdc++.h>
using namespace std;
long long to_Integer(string x) {
  long long xx = 0;
  int len = x.length();
  long long o = 1;
  for (int i = len - 1; i >= 0; --i, o *= 10) {
    long long s = x[i] - '0';
    xx += (x[i] - '0') * o;
  }
  return xx;
}
bool isPrime(long long n) {
  if (n < 2) return false;
  if (n < 4) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long gcd(long long a, long long b) {
  return b == 0 ? (a < 0 ? -a : a) : gcd(b, a % b);
}
int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  long long x[n], sum = 0, l = 0;
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  sum += x[n - 1];
  l = x[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    if (x[i] < l) {
      sum += x[i];
      l = x[i];
    } else {
      if (l - 1 >= 0) {
        sum += l - 1;
        l--;
      }
    }
  }
  cout << sum << endl;
  return 0;
}
