#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#ifndef LOCAL
#define cerr if(0)cerr
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using pii = pair<int, int>;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin>>n;
	vector<int> a(2*n); for(int& i: a) cin>>i;
	ll ans = 0;
	for(int i: a) ans += i;
	priority_queue<int> pq;
	for(int i=0; i<n; ++i) {
		pq.push(-(a[n-i-1]));
		pq.push(-(a[n+i]));

		ans += pq.top();
		pq.pop();
	}
	cout<<ans<<'\n';
}


/**
*    author:  shu8Cream
*    created: 19.12.2020 21:08:37
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using Graph = vvi;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    int j=0;
    for(int i=n-1; i>0; i-=2){
        ans+=abs(a[j]-a[n-1-j])*i;
        j++;
    }
    cout << ans << endl;
}