#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;
long long a[N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%lld", a + i);
    long long ans = 0, cut = numeric_limits<long long>::max();
    for (int i = n - 1; i >= 0; i--) {
        cut = min(cut - 1, a[i]);
        if (cut <= 0) break;
        ans += cut;
    }
    printf("%lld", ans);
    return 0;
}