#include <iostream>
#include <bits/stdc++.h>
#include <vector>

using namespace std;

int main()
{
    int n,summ,k,step;
    vector <int> a;
    cin >> n;
    a.resize(n);
    summ=0;
    k=0;
    step=1;
    for (int i=1; i<=n; ++i)
    {
        cin >> a[i];
    }
    for (int i=n; i>0; --i)
    {
        if (a[i]==a[i+1])
        {
            if (a[i]-k+step<=0)
                break;
            summ=summ+a[i]-k+step;
            ++step;
        }
        else
        {
            if (a[i]-k<=0)
                break;
            summ=summ+a[i]-k;
            step=1;
        }
        ++k;
    }
    cout << summ;
    return 0;
}