OI IX - izo

// https://szkopul.edu.pl/problemset/problem/C-avIJ9h36gThNQUOeaYwAD9/site/?key=submissions

#include <bits/stdc++.h>

// #define GARY_DBG
#define GARY_LIB

constexpr int sizik = 1000 * 1001;

#define ar std::array

typedef std::vector<std::vector<int>> _kra;

constexpr int INF = INT32_MAX, NINF = INT32_MIN;

void solve() {
    int n;
    std::cin >> n;

    int ans = 0;
    std::vector<int> v(n);
    for (auto& a : v) {
        std::cin >> a;
        ans += a;
    }
    std::sort(v.begin(), v.end());

    std::deque<int> d;
    for (const auto& a : v) {
        d.push_back(a);
    }

    while (!d.empty()) {
        if ((int)d.size() <= 1) break;
        ans += d.back() - d.front();
        d.pop_back();
        d.pop_front();
    }

    std::cout << ans << '\n';
}

int32_t main() {
#ifndef GARY_DBG
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
#endif

    int t = 1;
    // std::cin >> t;

    for (; t > 0; t--) {
        solve();
    }

    return 0;
}