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

bool empty(vector <ll> v) {
    if (v.size() == 0) 
        return true;
    return false;
}

int main() {
    ll n, res = 0, max = 0;
    cin >> n;
    
    vector <ll> v, dist;
    vector <pair <ll, ll>> vec;
    dist.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> dist[i];
        if (dist[i] > max)
            max = dist[i];
    }

    v.resize(max, 0); 
    for (auto i : dist) 
        v[i - 1]++;

    for (ll i = 0; i < max; i++) 
        if (v[i] != 0) 
            vec.push_back(make_pair(i + 1, v[i]));

    while (!empty(vec)) {
        res += vec[vec.size() - 1].first * vec[vec.size() - 1].second;
        for (ll i = 0; i < vec.size(); i++) {
            vec[i].first -= vec[vec.size() - 1].second;
            if (vec[i].first <= 0) 
                vec.erase(vec.begin() + i);
        }
        vec.erase(vec.end() - 1);
    } 
    cout << res; 
}