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

#define int long long
#define endl '\n'
#define inf 2000000000000000000
#define random (rand()^(rand()<<15))

using namespace std;
constexpr int mod=1000000007;
constexpr int MOD=998244353;

void solve()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int res=a[n-1],q=1,x=0;
    for(int i=n-2;i>=0;i--)
    {
        if(a[i]!=a[i+1])
        {
            x=q;
        }
        res+=max((a[i]-x),0ll);
//        cout<<a[i]<<" "<<x<<endl;
        q++;
    }
    cout<<res<<endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t=1;
//    cin>>t;
    for(int _=1;_<=t;_++)
    {
        solve();
    }
}
