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

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;
 
#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define MP make_pair

void solve(int test)
{
    int n;
    cin >> n;
    int i;
    VInt a(n), b(n);
    FOR(i, 0, n) cin >> a[i];
    FOR(i, 0, n) cin >> b[i];
    reverse(ALL(a));
    
    priority_queue<int> q;
    FOR(i, 0, n)
    {
        q.push(-a[i]);
        q.push(-b[i]);
        q.pop();
    }

    Int res = 0;
    FOR(i, 0, n)
    {
        res -= q.top();
        q.pop();
    }
    cout << res << endl;
}

int main()
{
    int T = 1, t;
    //cin >> T;
    FOR(t, 0, T) 
    {
        //cerr << "Solving " << t << "/" << T << endl;
        solve(t);
    }
    return 0;
}

// I've done my sentence but committed no crime
#pragma GCC optimize("Ofast")
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define mod (int)(1e9+7)
#define mod2 998244353
#define flush fflush(stdout);
#define PI 3.1415926535897932384626433832795

void solve() {
    int n; cin>>n;
    int ans=0;
    for(int i=1;i<n;i++){
        if(i>0&&(n-i)>0)ans++;
    }
    cout<<ans<<'\n';
}

int32_t main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}