#include <bits/stdc++.h>
using LL = long long;
using LD = long double;
const int mod = 1e9 + 7;
using namespace std;
LL arr[502][502];
LL trns[502][502];
void Transpose(LL n, LL m) {
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) trns[j][i] = arr[i][j];
}
int main() {
  LL n;
  cin >> n;
  LL x;
  vector<int> vec1, vec2;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    vec1.push_back(x);
    vec2.push_back(x);
  }
  reverse(vec2.begin(), vec2.end());
  LL sum2 = vec2[0];
  for (int i = 1; i < n; ++i) {
    if (vec2[i] >= vec2[i - 1] && vec2[i - 1] != 0) vec2[i] = (vec2[i - 1] - 1);
    if (vec2[i] >= vec2[i - 1] && vec2[i - 1] == 0) vec2[i] = 0;
    sum2 += vec2[i];
  }
  cout << sum2 << endl;
}
LL primeFact(int n) {
  set<int> st;
  for (int i = 3; i <= n; i += 2) {
    while (n % 2 == 0) {
      st.insert(2);
      n /= 2;
    }
  }
  for (int i = 3; i <= n; i += 2) {
    while (n % i == 0) {
      st.insert(i);
      n /= i;
    }
  }
  if (n > 1) st.insert(n);
  return st.size();
}
LL GCD(LL a, LL b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
LL cntr = 0;
LL GCDcntr(LL a, LL b) {
  if (b == 0) return cntr;
  cntr += (a / b);
  return GCDcntr(b, a % b);
}
LL* MaximumAlgorithm(LL arr[], LL n) {
  LL maxi = 0;
  LL* mx = new LL[n];
  for (LL i = 0; i < n; ++i) {
    for (LL j = 0; j <= i; ++j) {
      if (maxi <= arr[j]) maxi = arr[j];
    }
    mx[i] = maxi;
  }
  return mx;
}
