from heapq import*;n,*a=list(map(int,open(0).read().split()));b,h,c,p=a[:n],heappushpop,[-i for i in a[n:][::-1]],heapify;s,d=sum(b),c[:n];t=sum(d);p(b);p(d);r,l=[s],[t]

for i in range(n,n*2):s+=a[i]-h(b,a[i]);t+=c[i]-h(d,c[i]);r+=[s];l+=[t]

print((max(list(map(sum,list(zip(r,l[::-1])))))))
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])))))))
from heapq import *

n, *a = list(map(int, open(0).read().split()))
b, h, c, p = a[:n], heappushpop, [-i for i in a[n:][::-1]], heapify
s, d = sum(b), c[:n]
t = sum(d)
p(b)
p(d)
r, l = [s], [t]
for i in range(n, n * 2):
    s += a[i] - h(b, a[i])
    t += c[i] - h(d, c[i])
    r += [s]
    l += [t]
print((max(list(map(sum, list(zip(r, l[::-1])))))))

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(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 + + -b, h, c, p = a[:n], heappushpop, [-i for i in a[n:][::-1]], heapify -s, d = sum(b), c[:n] -t = sum(d) -p(b) -p(d) -r, l = [s], [t] -for i in range(n, n * 2): -    s += a[i] - h(b, a[i]) -    t += c[i] - h(d, c[i]) -    r += [s] -    l += [t] -print((max(list(map(sum, list(zip(r, l[::-1]))))))) +print((max(list(map(sum, list(zip(f(a), list(f([-e for e in a[::-1]]))[::-1])))))))