#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ll n, r = 0;
    cin >> n;
    
    vector <ll> a(n);
    
    for (ll i = 0; i < n; ++i) 
        cin >> a[i];
        
    reverse(a.begin(), a.end()); 
    ll sum = a[0];
    
    for (ll i = 1; i < n; ++i) {
        if (a[i] != a[i - 1]) r = i;
        
        if (a[i] - r < 1) break;
        sum += a[i] - r;
    }
    cout << sum;

    return 0;
}