#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll,ll>;

ll solve_sub(ll N, vector<ll>& V) {
    priority_queue<pii> q;
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        int i2 = 2*N-1-i;
        q.push(pii(V[i],i));
        q.push(pii(V[i2],i2));
        ans += q.top().first;
        q.pop();
    }
    return ans;
}

ll solve_sub_0(ll N, vector<ll>& V) {
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        int i1 = N-1-i, i2 = N+i;
        ans += max(V[i1],V[i2]);
    }
    return ans;
}

ll solve() {
    ll N;
    cin >> N;
    vector<ll> V(2*N);
    for ( int i = 0; i < 2*N; i++ ) cin >> V[i];
    ll ans = solve_sub(N, V);
    return ans;
}

auto solve_small_1(ll N, vector<ll>& V) {
    ll ans = 0;
    vector<ll> ans_v;
    vector<ll> used(2*N);
    auto dfs = [&](auto self, int d, ll s) -> void {
        if ( d == N ) {
            ans = max(ans, s);
            return;
        }
        int h0, h1, c = 0;
        for ( int i = 0; i < 2*N; i++ ) {
            if ( used[i] == 0 ) {
                c++;
                if ( c <= N-d ) {
                    h0 = i;
                } else {
                    h1 = i;
                    break;
                }
            }
        }
        for ( int i = 0; i < 2*N; i++ ) {
            if ( used[i] > 0 ) continue;
            int i1 = i;
            int i2 = i < h1 ? h1 : h0;
            used[i1] = 1;
            used[i2] = 1;
            ans_v.push_back(i1);
            self(self, d+1, s+V[i1]);
            ans_v.pop_back();
            used[i1] = 0;
            used[i2] = 0;
        }
    };
    dfs(dfs,0,0LL);
    return ans;
}
struct Data {
    int id;
    ll N;
    vector<ll> V;
};
void test() {
    mt19937_64 mt64(0);
    uniform_int_distribution<ll> rnd_n(3, 4);
    uniform_int_distribution<ll> rnd_v(0, 9);

    int id = 0;
    vector<Data> ts;
    ts.push_back({++id,4,{3,2,8,6,7,6,1,6}});
    ts.push_back({++id,3,{1,2,3,4,5,6}});
    ts.push_back({++id,4,{1,4,5,8,7,6,3,2}});
    for ( int i = 0; i < 100; i++ ) {
        int n = rnd_n(mt64);
        vector<ll> a;
        for ( int j = 0; j < 2*n; j++ ) {
            a.push_back(rnd_v(mt64));
        }
        ts.push_back({++id,n,a});
    }
    
    for ( Data& t : ts ) {
        auto ans0 = solve_sub(t.N,t.V);
        auto ans1 = solve_small_1(t.N,t.V);
        if ( ans0 != ans1 ) {
            cout << t.id << " " << ans0 << " " << ans1 << "\n";
        }
    }
    cout << "end" << "\n";
}

int main() {
    // test();

    auto ans = solve();
    cout << ans << "\n";
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  vector<lint> V1(N), V2(N);
  IREP(i, N) cin >> V1[i];
  REP(i, N) cin >> V2[i];
  multiset<lint> st;
  REP(i, N) {
    if(st.size() > 0 && *st.begin() < min(V1[i], V2[i])) {
      st.erase(st.begin());
      st.insert(V1[i]);
      st.insert(V2[i]);
    } else {
      st.insert(max(V1[i], V2[i]));
    }
  }
  lint ans = 0;
  for(lint x : st) ans += x;
  cout << ans << endl;
}