#include <bits/stdc++.h>
//author: @van4o_0
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef long double ld;

typedef pair<int, int> p_ii;
typedef pair<int, ll> p_il;
typedef pair <ll, ll> p_ll;

typedef map<int, int> dict_ii;
typedef map <ll, ll> dict_ll;
typedef map<int, string> dict_is;

typedef vector<int> vi;
typedef vector <vi> vvi;
typedef vector <ll> vl;
typedef vector <vl> vvl;
typedef vector<bool> vb;
typedef vector <vb> vvb;
typedef vector<char> vc;
typedef vector <vc> vvc;

//define all(x) (x).begin(), (x).end()
//define sort(x) sort(all(x))

template<typename T>
istream &operator>>(istream &input, vector <T> &arr) {
    for (auto &e: arr) input >> e;
    return input;
}

template<typename T>
//print vector, default sep=" "
ostream &operator<<(ostream &print, vector <T> &arr_out) {
    string sep = " ";
    for (auto x: arr_out) print << x << sep;
    return print;
}

//define r(i, a, b) for (int i = a; i < (b); ++i)
//define range(i, b) for (int i = 0; i < (b); ++i)

void solve() {
    int n;cin >> n;
    vi a(n); cin >> a;

    ll rez = a[n-1] * n;
    int i = n-a[n-1]-1;

    int last = n-2;
    while (true){
        if(i<0 or last<0) break;

        rez += a[last]*i;
        last --;
        i -= a[last]+1;
    }

    cout << rez << endl;

}


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int tt = 1;
    // cin>>tt;
    while (tt--) solve();
    return 0;
}