#include <bits/stdc++.h>
using namespace std;
long long INF = 1 << 28;
const double pi = acos(-1.0);
int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};
int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
int knight[8][2] = {1, 2, 1, -2, 2, 1, 2, -1, -1, 2, -1, -2, -2, 1, -2, -1};
const long double EPS = 1e-7;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool cmp(int a, int b) { return a < b; }
int on(int mask, int st) { return mask | (1 << st); }
int off(int mask, int st) { return mask & (~(1 << st)); }
bool check(int mask, int st) { return mask & (1 << st); }
long long inf = 1e18;
long long mod = 1e9 + 7;
long long arr[300000];
int main() {
  string s;
  long long ans = 0;
  int n, x;
  long long m, y;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
  }
  long long last = INT_MAX;
  for (int i = n - 1; i >= 0; i--) {
    if (arr[i] >= last) {
      ans += (last - 1);
      last = last - 1;
    } else {
      ans += arr[i];
      last = arr[i];
    }
    if (last == 1) break;
  }
  cout << ans << endl;
  return 0;
}
