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

int main(){
  long long N;
  cin >> N;
  vector<long long> L(N),R(N);
  for(int i=0;i<N;i++) cin >> L[i];
  for(int i=N-1;i>=0;i--) cin >> R[i];
  
  long long ans = 0;
  vector<long long> V1(N),V2(N);
  for(int i=0;i<N;i++){
    V1[i] = max(L[i],R[i]);
    V2[i] = min(L[i],R[i]);
    ans += V1[i];
  }
  
  priority_queue<long long> P;
  P.push(V2[0]);
  for(int i=1;i<N;i++){
    long long x = P.top();
    if(V1[i]<x){
      ans += x - V1[i];
      P.pop();
      P.push(V1[i]);
    }
    P.push(V2[i]);
  }
  
  cout << ans << endl;
  return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;

int main() {
	long long N; cin >> N;
	vector<long long> V(2 * N);
	for (int i = 0; i < 2 * N; i++) cin >> V[i];

	multiset<long long> Set;
	long long sum = 0;
	for (int i = 0; i < N; i++) {
		Set.insert(V[N - i - 1]);
		Set.insert(V[N + i]);
		long long a = *Set.begin();
		Set.erase(Set.begin());
		sum += a;
	}

	long long sum_ = 0;
	for (int i = 0; i < 2 * N; i++) sum_ += V[i];

	cout << sum_ - sum << endl;
}