#include <bits/stdc++.h>

using namespace std;

typedef int int2;
#define int long long
#define pi pair<int, int>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
const int inf = 1e18;
const int B = 450;

int t;


int2 main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(2 * n);
    for (int i = 0; i < 2 * n; i++) {
        cin >> a[i];
    }
    map<int, vector<int>> locs;
    vector<pi> pairs;
    for (int i = n - 1; i >= 0; i--) {
        int e1 = a[i];
        int e2 = a[2 * n - 1 - i];
        pairs.eb(min(e1, e2), max(e1, e2));
    }
    int ans = 0;
    multiset<int> cur;
    for (int i = 0; i < n; i++) {
        int mn = pairs[i].f;
        int mx = pairs[i].s;
        ans += mx;
        if (!cur.empty() and *(cur.begin()) < mn) {
            ans += (mn - (*cur.begin()));
            cur.erase(cur.begin());
            cur.insert(mn);
        }
        cur.insert(mx);
    }
    cout << ans << "\n";
} 
#include <bits/stdc++.h>
#define int long long int
#include <time.h>
using namespace std;
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector <int> v1;
    vector <int> v2;
    for(int i = 1;i<= n;i++){
        int z;
        cin>>z;
        v1.push_back(z);
    }
    reverse(v1.begin() , v1.end() );
    for(int i = 1;i<= n;i++){
        int z;
        cin>>z;
        v2.push_back(z);
    }
    priority_queue <int> q;
    for(int i = 0;i<n;i++){
        q.push(-v1[i] );
        q.push(-v2[i]);
        q.pop();
    }
    int ans = 0;
    while(q.size()){
        ans+= -q.top();
        q.pop();
    }
    cout<<ans;
}
