def f(a):

	q=a[:n];s=sum(q);heapify(q);yield s

	for e in a[n:2*n]:s+=e-heappushpop(q,e);yield s

from heapq import*;n,*a=list(map(int,open(0).read().split()));print((max(list(map(sum,list(zip(f(a),list(f([-e for e in a[::-1]]))[::-1])))))))
def f(l,a):

	q=a[:n];s=sum(q);heapify(q);l+=[s]

	for e in a[n:2*n]:s+=e-heappushpop(q,e);l+=[s]

from heapq import*;n,*a=list(map(int,open(0).read().split()));l=[];f(l,a);f(l,[-i for i in a[::-1]]);m=len(l)//2;print((max(l[i]+l[-i-1]for i in range(m))))
def f(a):
    q = a[:n]
    s = sum(q)
    heapify(q)
    yield s
    for e in a[n : 2 * n]:
        s += e - heappushpop(q, e)
        yield s


from heapq import *

n, *a = list(map(int, open(0).read().split()))
print((max(list(map(sum, list(zip(f(a), list(f([-e for e in a[::-1]]))[::-1])))))))

def f(l, a):
    q = a[:n]
    s = sum(q)
    heapify(q)
    l += [s]
    for e in a[n : 2 * n]:
        s += e - heappushpop(q, e)
        l += [s]


from heapq import *

n, *a = list(map(int, open(0).read().split()))
l = []
f(l, a)
f(l, [-i for i in a[::-1]])
m = len(l) // 2
print((max(l[i] + l[-i - 1] for i in range(m))))

-def f(a): +def f(l, a): -    yield s +    l += [s] -        yield s +        l += [s] -print((max(list(map(sum, list(zip(f(a), list(f([-e for e in a[::-1]]))[::-1]))))))) +l = [] +f(l, a) +f(l, [-i for i in a[::-1]]) +m = len(l) // 2 +print((max(l[i] + l[-i - 1] for i in range(m))))