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

long a[100007],balls;
long workingNumber, lastNumber, indexMinus, prise;

int main() {
    cin>>balls;
    for(int i=1;i<=balls;i++) cin>>a[i];

    for(long i=balls;i>=1;i--){
        //cout<<a[i]<<" ";
        lastNumber=a[i];
        if(a[i]!=a[balls]){
            if(a[i]!=workingNumber) a[i]-=indexMinus;
            else a[i]=a[i+1];
            if(a[i]<=0) continue;
        }
        workingNumber=lastNumber;
        //cout<<a[i]<<" ";
        prise+=a[i];
        indexMinus++;
        //cout<<prise<<endl;
    }
    cout<<endl;
    cout<<prise<<endl;
    return 0;
}
