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

int main() {
    long long ans = 0, kol = 1, p = 0, x, n;

    cin >> n;
    while (n--) {
        cin >> x;
        if (x == p)
            kol++;
        else {
            ans += max(0LL, p - n - 1) * 1LL * kol;
            kol = 1;
            p = x;
        }
    }
    ans += max(0LL, p - n - 1) * 1LL * kol;
    cout << ans;
}
