#include <bits/stdc++.h>
using namespace std;
int main() {
  stack<long long int> aa;
  long long int n, temp, ans = 0, maxn = 1000000010;
  scanf("%lld", &n);
  while (n--) {
    scanf("%lld", &temp);
    aa.push(temp);
  }
  while (!aa.empty()) {
    temp = aa.top();
    if (temp < maxn) {
      ans += temp;
      maxn = temp;
    } else if (temp >= maxn && maxn != 0) {
      ans += maxn - 1;
      maxn = maxn - 1;
    }
    aa.pop();
  }
  cout << ans << endl;
  return 0;
}
