#include <bits/stdc++.h>
using namespace std;

int main() {
    unsigned long long n, res, c, d;
    vector <long long> v;
    cin >> n;
    v.resize(n);
    for (long long i = 0; i < n; i++) {
        cin >> v[i];
    }
    res = v[v.size()-1];
    c = 1;
    d = 0;
    for (long long i = n - 2; i >= 0; i--) {
        if (v[i] != v[i+1]) {
            if (v[i] >= c)
            res += v[i] - c;
            d = 0;
        }
        else { 
            d++;
            res += v[i] - c + d;
        }
        c++;
    }
    cout << res;
}
