#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define DBG(a) cout<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 998244353;
long double pi = acosl(-1);
const ll infl = 1e17+100;
const int inf = 1e9+100;
const int nmax = 1e6+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;


multiset<int>nibo;
vector<int>v1, v2;


int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int n;
    cin>>n;
    v1.resize(n), v2.resize(n);
    for(int &x : v1) cin>>x;
    for(int &x : v2) cin>>x;
    reverse(v2.begin(), v2.end());

    ll ans = 0;
    for(int i=0; i<n; i++){
        int x1 = v1.back(), x2 = v2.back();
        v1.pop_back(), v2.pop_back();
        if(x1>x2) swap(x1,x2);
        if(i==0){
            nibo.insert(x2);
        }
        else{
            auto it = nibo.begin();
            if( *it < x1){
                nibo.erase(it);
                nibo.insert(x2);
                nibo.insert(x1);
            }
            else {
                nibo.insert(x2);
            }
        }
//        for(int x : nibo) cout<<x<<" ";
//        cout<<"aa "<<endl;
    }
    for(int x : nibo) ans += x;
    cout<<ans<<endl;
}
/*
*/

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MOD = 1000000007;
template <class T>
struct fenwick_tree {
	vector<T> x;
	fenwick_tree(int n) : x(n, 0) {}
	T sum(int i, int j) {
		if (i == 0) {
			T S = 0;
			for (j; j >= 0; j = (j & (j + 1)) - 1) S += x[j];
			return S;
		} else
			return sum(0, j) - sum(0, i - 1);
	}
	void add(int k, T a) {
		for (; k < x.size(); k |= k + 1) x[k] += a;
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(2 * N);
	int res = 0;
	for (int i = 0; i < 2 * N; i++) {
		cin >> A[i];
	}
	vector<int> B;
	for (int i = 0; i < N; i++) {
		B.push_back(min(A[N - 1 - i], A[i + N]));
		B.push_back(max(A[N - 1 - i], A[i + N]));
	}

	int sum = 0;
	priority_queue<int> pq;
	for (int i = 1; i < 2 * N; i++) {
		if (i % 2 == 0) {
			int a = -pq.top();
			if (a < B[i]) {
				res += B[i] - a;
				pq.pop();
				pq.push(-B[i]);
			}
		} else {
			res += B[i];
			pq.push(-B[i]);
		}
	}
	// fenwick_tree<int> ft(2 * N);
	// for (int i = 0; i < 3 * N; i++) {
	// 	ft.add(i, 1);
	// }
	// vector<pair<int, int> > vp;
	// for (int i = 0; i < 2 * N; i++) {
	// 	vp.emplace_back(B[i], i);
	// }
	// sort(B.rbegin(), B.rend());
	// for (int i = 0; i < 2 * N; i++) {
	// 	//cerr << vp[i].first << " " << vp[i].second << endl;
	// 	int p = vp[i].second;
	// 	if (ft.sum(0, p) - 2 >= 0) {
	// 		ft.add(p, -2);
	// 		res += vp[i].first;
	// 	}
	// }
	cout << res << endl;
}