#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXNUM = 1000000000;
const int MaxSize = 1e5*3;
ll A[211000];
ll p[211000];
struct node {
    int x,y;
};
node point[MaxSize];
bool cmp(node a,node b) {
    if(a.x!=b.x) return a.x<b.x;
    return a.y<b.y;
}
vector<int>vec[MaxSize];


int main() {
    ll ans = 0;
    int n; scanf("%d",&n);
//    for(int i=1;i<=n;i++) scanf("%d",&A[i]);
//    for(int i=1;i<=n;i++) {
//        for(int j=1+i;j<=n;j++) {
//            ans += abs(A[i]-A[j]);
//        }
//    }
    for(int i=1;i<=n;i++) scanf("%lld",&A[i]);
    sort(A+1,A+n+1);
    p[1]=0;
    for(int i=2;i<=n;i++) {
        p[i] = (i-1)*(A[i]-A[i-1])+p[i-1];
    }
    for(int i=1;i<=n;i++) ans += p[i];
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

int main(){
    int N; cin >> N;

    vector<ll> A(2*N);
    rep(i, 2*N) cin >> A[i];

    vector<ll> B(2*N);
    rep(i, N){
        B[2*i] = A[N-1-i], B[2*i+1] = A[N+i];
    }

    priority_queue<ll, vector<ll>, greater<ll>> que;
    ll S = accumulate(all(A), 0LL);

    rep(i, N){
        que.emplace(B[2*i]), que.emplace(B[2*i+1]);
        S -= que.top(); que.pop();
    }

    cout << S << '\n';
}