#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) scanf("%d", a + i);
    int minn = 0x3f3f3f3f;
    long long ans = 0;
    for (int i = n - 1; i >= 0; i--) {
      minn = min(a[i], minn - 1);
      minn = max(0, minn);
      ans += minn;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
