import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
long binarySearch(long min, long max, bool delegate(long) f){
	if(!f(min)) return min - 1; if(f(max)) return max;
	long mid; while(max - min > 1){ mid = min + (max - min) / 2; if(f(mid)) min = mid; else max = mid; } return min;
	}

void main(){
	int n = read.to!int;
	long[] as = readln.split.map!(to!long).array;
	
	long[] sums1;
	{
		long[] q = as[0 .. n];
		q.sort!"a > b"();
		long[] sums = [q.reduce!"a + b"()];
		foreach(int i; n .. (n + n)){
			if(q[$ - 1] < as[i]){
				sums ~= sums[$ - 1] + (as[i] - q[$ - 1]);
				int j = cast(int)binarySearch(0, n - 1, x => q[cast(int)x] > as[i]) + 1;
				q = q[0 .. j] ~ as[i] ~ q[j .. $ - 1];
				}
			else sums ~= sums[$ - 1];
			}
		sums1 = sums;
		}
	
	debug sums1.writeln;
	
	long[] sums2;
	{
		long[] q = as[n * 2 .. $];
		q.sort!"a < b"();
		long[] sums = [q.reduce!"a + b"()];
		foreach_reverse(int i; n .. (n + n)){
			if(q[$ - 1] > as[i]){
				sums ~= sums[$ - 1] - (q[$ - 1] - as[i]);
				int j = cast(int)binarySearch(0, n - 1, x => q[cast(int)x] < as[i]) + 1;
				q = q[0 .. j] ~ as[i] ~ q[j .. $ - 1];
				}
			else sums ~= sums[$ - 1];
			}
		sums2 = sums;
		}
	
	debug sums2.writeln;
	
	long ans = long.min;
	foreach(int i; 0 .. n){
		if(sums1[i] - sums2[n - i] > ans) ans = sums1[i] - sums2[n - i];
		}
	
	ans.writeln;
	
	}