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

int n, buf, cost = 0;
vector<int> balls;

void grab(){
    int buf = balls[0], k = 0;
    bool p = true;
    int i = balls.size()-1;
    while (i > 0 && p){
        if (balls[i]!=balls[i-1]) p =false;
        cost += balls[i];
        balls.erase(balls.end()-1);
        k++;
        i--;
    }
    for (int i = 0; i < balls.size(); i++) {
        if (balls[i]-k>=0) balls[i]-=k;
        else { 
            balls.erase(balls.begin()+i);
            i--;
        }
    }
}

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

	
	cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> buf;
        balls.push_back(buf);
    }
    while (balls.size() > 0) grab();
    cout << cost;
}
