from heapq import heapify, heappushpop

N, *a = list(map(int, open(0).read().split()))



hq1 = a[:N]

hq2 = [-ai for ai in a[-N:]]



heapify(hq1)

heapify(hq2)



sum1 = [sum(hq1)]

sum2 = [sum(hq2)]

for k in range(N, 2 * N):

    sum1.append(sum1[-1] + a[k] - heappushpop(hq1, a[k]))

    sum2.append(sum2[-1] - a[-k - 1] - heappushpop(hq2, -a[-k - 1]))



print((max(list(map(sum, list(zip(sum1, sum2[::-1])))))))
from heapq import heapify, heappushpop

N, *A = list(map(int, open(0).read().split()))

def f(L):

    q = L[:N]

    heapify(q)

    s = sum(q)

    yield s

    for e in L[N:2 * N]:

        s += e - heappushpop(q, e)

        yield s

print((max(list(map(sum, list(zip(f(A), list(f([-a for a in A[::-1]]))[::-1])))))))
from heapq import heapify, heappushpop

N, *a = list(map(int, open(0).read().split()))
hq1 = a[:N]
hq2 = [-ai for ai in a[-N:]]
heapify(hq1)
heapify(hq2)
sum1 = [sum(hq1)]
sum2 = [sum(hq2)]
for k in range(N, 2 * N):
    sum1.append(sum1[-1] + a[k] - heappushpop(hq1, a[k]))
    sum2.append(sum2[-1] - a[-k - 1] - heappushpop(hq2, -a[-k - 1]))
print((max(list(map(sum, list(zip(sum1, sum2[::-1])))))))

from heapq import heapify, heappushpop

N, *A = list(map(int, open(0).read().split()))


def f(L):
    q = L[:N]
    heapify(q)
    s = sum(q)
    yield s
    for e in L[N : 2 * N]:
        s += e - heappushpop(q, e)
        yield s


print((max(list(map(sum, list(zip(f(A), list(f([-a for a in A[::-1]]))[::-1])))))))

-N, *a = list(map(int, open(0).read().split())) -hq1 = a[:N] -hq2 = [-ai for ai in a[-N:]] -heapify(hq1) -heapify(hq2) -sum1 = [sum(hq1)] -sum2 = [sum(hq2)] -for k in range(N, 2 * N): -    sum1.append(sum1[-1] + a[k] - heappushpop(hq1, a[k])) -    sum2.append(sum2[-1] - a[-k - 1] - heappushpop(hq2, -a[-k - 1])) -print((max(list(map(sum, list(zip(sum1, sum2[::-1]))))))) +N, *A = list(map(int, open(0).read().split())) + + +def f(L): +    q = L[:N] +    heapify(q) +    s = sum(q) +    yield s +    for e in L[N : 2 * N]: +        s += e - heappushpop(q, e) +        yield s + + +print((max(list(map(sum, list(zip(f(A), list(f([-a for a in A[::-1]]))[::-1])))))))