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

#define ll long long
const int maxn = 4e5 + 5;

int n;
int a[maxn];

int main() {
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++) scanf("%d",&a[i]);

	priority_queue<int> heap;
	ll sum = 0, aoki = 0;
	for(int i=1;i<=n;i++) {
		heap.push(-a[n-i+1]);
		heap.push(-a[n+i]);
		sum += a[n-i+1] + a[n+i];
		aoki += -heap.top(); heap.pop();
	}
	printf("%lld",sum - aoki);
}
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    string s;
    int k;
    cin>>s>>k;
    for(int aaa=0;aaa<k;aaa++){
        string a = s;
        string b = s;
        sort(all(a));
        sort(all(b));
        reverse(all(b));
        int x = 0;
        int n = a.size();
        for(int i=0;i<n;i++){
            x *= 10;
            x += b[i]-a[i];
        }
        s = to_string(x);
    }
    cout << s << endl;
}