#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
 
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  int n;
  cin >> n;
  vector<int> v(2*n);
  for(int i = 0; i < 2*n; ++i){
    cin >> v[i]; 
  }
  multiset<int> s;
  int l = 0;
  int r = 2*n -1;
  i64  ans = 0;
  while(l<r){
    s.insert(v[l]);
    s.insert(v[r]);
    auto it = prev(s.end());
    ans += *it;
    s.erase(it);
    l += 1;
    r -= 1;
  }
  cout << ans << endl;
  return 0;
}
#include <bits/stdc++.h>

const int N = 200000;

int v[2*N + 5], n;

int main() {
	scanf("%d", &n); for(int i=1;i<=(n<<1);i++) scanf("%d", &v[i]);
	
	long long sum = 0;
	std::priority_queue<int>que;
	for(int i=n;i>=1;i--) {
		que.push(v[n - i + 1]), que.push(v[n + i]);
		sum += que.top(), que.pop();
	}
	printf("%lld\n", sum);
}