#include <iostream>
#include <vector>
#include <numeric>
#include <set>

int main()
{
  int N;
  std::cin >> N;
  std::vector<long long> vs(2 * N);
  for (auto& v : vs) { std::cin >> v; }

  std::multiset<long long> pool;
  long long aoki = 0;
  for (int i = 0; i < N; i++)
  {
    pool.insert(vs[N - 1-i]);
    pool.insert(vs[N+i]);
    aoki += *pool.begin();
    pool.erase(pool.begin());
  }

  long long sum = std::accumulate(vs.begin(), vs.end(), 0LL);

  std::cout << sum - aoki << std::endl;
  return 0;
}

#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
typedef long long ll;
cs int N = 4e5 + 5; 
int n, a[N], p[N], c[N];
ll ans; 
#define mid ((l + r) >> 1)
cs int M = N << 2; 
int mn[M], ta[M];
void up(int x) {
	mn[x] = min(mn[x << 1], mn[x << 1 | 1]) + ta[x];
}
void build(int x, int l, int r) {
	if(l == r) {
		mn[x] = l;
		return;
	}
	build(x << 1, l, mid);
	build(x << 1 | 1, mid + 1, r);
	up(x);
}
void mdf(int x, int l, int r, int L, int R) {
	if(L <= l && r <= R) 
		return mn[x] --, ta[x] --, void();
	if(L <= mid) mdf(x << 1, l, mid, L, R);
	if(R > mid) mdf(x << 1 | 1, mid + 1, r, L, R); 
	up(x);
}
int qry(int x, int l, int r, int L, int R) {
	if(L <= l && r <= R) 
		return mn[x];
	int ans = 1e9;
	if(L <= mid) ans = min(ans, qry(x << 1, l, mid, L, R));
	if(R > mid) ans = min(ans, qry(x << 1 | 1, mid + 1, r, L, R));
	return ans + ta[x];
}
#undef mid

void ins(int x, int c) {
	int z = qry(1, 1, n, x, n);
	if(z) {
		ans += c;
		mdf(1, 1, n, x, n);
	}
}
int main() {
	#ifdef FSYo
	freopen("1.in", "r", stdin);
	#endif
	cin >> n; 
	for(int i = 1; i <= n + n; i++)
		scanf("%d", &a[i]), p[i] = i;
	sort(p + 1, p + n + n + 1, 
	[](cs int &i, cs int &j) {
		return a[i] > a[j];
	});
	build(1, 1, n);
	for(int i = 1; i <= n + n; i++) {
		int x = p[i];
		if(x <= n) {
			ins(n - x + 1, a[x]);
		}
		else {
			ins(x - n, a[x]);
		}
	}
	cout << ans; 
	return 0; 
}