#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;
void solve(){
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    vector<int>r1,r2;
    int r=0;
    for(int i=1;i<=n;i++){
        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]);
    }
    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);
    }
    for(int i=0;i<m;i++){
        r-=(r1.size()-i)*r1[i]+(r2.size()+i)*r1[i];
    }
    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;
}