#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int maxn = 4e5 + 5;

int n;
int a[maxn];

int main() {
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++) scanf("%d",&a[i]);

	priority_queue<int> heap;
	ll sum = 0, aoki = 0;
	for(int i=1;i<=n;i++) {
		heap.push(-a[n-i+1]);
		heap.push(-a[n+i]);
		sum += a[n-i+1] + a[n+i];
		aoki += -heap.top(); heap.pop();
	}
	printf("%lld",sum - aoki);
}
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N; cin>>N;
	vll v1(N),v2(N);
	rep(i,2*N){
		ll v; cin>>v;
		if (i<N) v1[i]=v;
		else v2[i-N]=v;
	}
	reverse(all(v1));
	ll ans=0;
	multiset<ll> ms;
	rep(i,N){
		ll mx = max(v1[i],v2[i]);
		ll mn = min(v1[i],v2[i]);
		ans+=mx;
		ms.ins(mx);
		if (!ms.empty() && *ms.begin()<mn){
			auto itr = ms.begin();
			ans+=mn-*itr;
			ms.ins(mn);
			ms.erase(itr);
		}
	}
	cout<<ans<<"\n";
    return 0;
}
