#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll a[100001];
vector < pair <ll, ll> > ob;
vector < pair <ll, ll> > v;
vector < pair <ll, ll> > use;

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

    ll N;

    cin >> N;

    for (ll i = 0; i < N; i++)
    {
        cin >> a[i];
    }

    sort(a, a + N);

    ll br = 1;

    for (ll i = 0; i < N - 1; i++)
    {
        if (a[i] == a[i + 1])
        {
            br++;
        }
        else
        {
            v.push_back({a[i], br});
            ob.push_back({a[i], br});
            use.push_back({a[i], 0});

            br = 1;
        }
    }

    if (br >= 1)
    {
        v.push_back({a[N - 1], br});
        ob.push_back({a[N - 1], br});
        use.push_back({a[N - 1], 0});
        br = 1;
    }

    ll ans = 0;
    bool f = 1;

    while (f)
    {
        use[0].second += min(v[0].second, v[1].second);
        f = 0;

        for (ll i = 0; i < v.size() - 1; i++)
        {
            ll del = min(v[i].second, v[i + 1].second);

            if (ob[i + 1].second - use[i + 1].second >= del)
            {
                f = 1;
            }
            else
            {
                continue;
            }

            v[i].second -= del;

            use[i + 1].second += del;
        }

        for (ll i = 0; i < v.size(); i++)
        {
            if (v[i].second == 0)
            {
                v.erase(v.begin() + i, v.begin() + i + 1);
                use.erase(use.begin() + i, use.begin() + i + 1);
                i--;
            }
        }
    }

    for (ll i = 0; i < v.size(); i++)
    {
        ans += v[i].first * v[i].second;
    }

    cout << ans << endl;

    return 0;
}
