#include <bits/stdc++.h>
#define MAXN (int)5005
#define pii pair<ll,ll>
#define fi first
#define se second
using namespace std;
typedef long long ll;
ll n,m,a[MAXN],b[MAXN],r=0;
vector<ll>r1,r2;
ll f(ll rr, ll m){
    for(int i=0;i<m;i++){
        //cout<<"A"<<rr<<' '<<(r1.size()-i)*r1[i]-(r2.size()+i)*r1[i]<<' ';
        rr-=((ll)r1.size()-i)*r1[i]-((ll)r2.size()+i)*r1[i];
        //cout<<rr<<'\n';
    }
    return rr;
}
void solve(){
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    for(int i=1;i<=n;i++){
       // cout<<abs(a[i]-b[i])<<'\n';
        if(a[i]<b[i]){
            r1.push_back(b[i]-a[i]);
        }else{
            r2.push_back(a[i]-b[i]);
        }
        r+=abs(a[i]-b[i]);
    }
    //cout<<r<<'\n';
    //cerr<<r<<'\n';
    int m=(r1.size()+r2.size())/2;
    sort(r1.begin(),r1.end());
    sort(r2.begin(),r2.end());
    if(r1.size()<r2.size()){
        swap(r1,r2);
    }
    if(r1.size()==r2.size()){
            return;
    }
    r=f(r,m);
    //cout<<r<<'\n';
}
long long Konflikt(int N,int M,int *A,int *B){
    n=N;
    m=M;
    for(int i=1;i<=n;i++){
        a[i]=A[i];
        b[i]=B[i];
    }
    solve();
    return r;
}