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

int main() {
    int n;
    cin >> n;
    vector<ll> v(2 * n, 0);
    rep(i, 2 * n) {
        cin >> v[i];
    }
    ll sum = 0, aoki = 0;
    rep(i, 2 * n) sum += v[i];
    priority_queue<ll, vector<ll>, greater<ll>> que;
    for(int i = n - 1; i >= 0; i--) {
        que.push(v[i]);
        que.push(v[2 * n - 1 - i]);
        aoki += que.top();
        que.pop();
    }
    cout << sum - aoki << endl;
    return 0;
}

#pragma region Macros
#include <bits/stdc++.h>
#if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG)
#include <atcoder/all>
#endif
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>using vec = vector<T>;
template<class T, class U>using umap = unordered_map<T, U>;
using ll = long long;
using P = pair<ll, ll>;
using vl = vec<ll>;
#define fi first
#define se second
#define el endl
constexpr ll INF = numeric_limits<ll>::max()/2-1;
#pragma endregion

#pragma region IOMacros
template<class T>
istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;}
template<class T>
ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;}

#define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__);
void __i() {}
template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);}

void O() {cout << el;}
template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);}
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    I(ll, N);
    priority_queue<ll> q;
    unordered_set<ll> mp;
    ll mn = INF;
    REP(i, N){
        I(ll, a);
        if(mp.find(a) == mp.end()){
            chmin(mn, a);
            q.push(a);
            mp.insert(a);
        }
    }
    while(q.size() > 1){
        auto a = q.top(); q.pop();
        a -= mn;
        if (mp.find(a) == mp.end()){
            chmin(mn, a);
            q.push(a);
            mp.insert(a);
        }
    }
    cout << q.top() << el;
}
