from heapq import heapify, heappop, heappush



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



Q = A[:N]

heapify(Q)



R = [sum(Q)]

for a in A[N:2 * N]:

    heappush(Q, a)

    R.append(R[-1] + a - heappop(Q))



Q = [-a for a in A[2 * N:]]

heapify(Q)



B = [sum(Q)]

for a in reversed(A[N:2 * N]):

    heappush(Q, -a)

    B.append(B[-1] - a - heappop(Q))



print((max(r + b for r, b in zip(R, reversed(B)))))

from heapq import heapify, heappushpop



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



Q = A[:N]

heapify(Q)



R = [sum(Q)]

for a in A[N:2 * N]:

    R.append(R[-1] + a - heappushpop(Q, a))



Q = [-a for a in A[2 * N:]]

heapify(Q)



B = [sum(Q)]

for a in reversed(A[N:2 * N]):

    B.append(B[-1] - a - heappushpop(Q, -a))



print((max(r + b for r, b in zip(R, reversed(B)))))

from heapq import heapify, heappop, heappush

N, *A = list(map(int, open(0).read().split()))
Q = A[:N]
heapify(Q)
R = [sum(Q)]
for a in A[N : 2 * N]:
    heappush(Q, a)
    R.append(R[-1] + a - heappop(Q))
Q = [-a for a in A[2 * N :]]
heapify(Q)
B = [sum(Q)]
for a in reversed(A[N : 2 * N]):
    heappush(Q, -a)
    B.append(B[-1] - a - heappop(Q))
print((max(r + b for r, b in zip(R, reversed(B)))))

from heapq import heapify, heappushpop

N, *A = list(map(int, open(0).read().split()))
Q = A[:N]
heapify(Q)
R = [sum(Q)]
for a in A[N : 2 * N]:
    R.append(R[-1] + a - heappushpop(Q, a))
Q = [-a for a in A[2 * N :]]
heapify(Q)
B = [sum(Q)]
for a in reversed(A[N : 2 * N]):
    B.append(B[-1] - a - heappushpop(Q, -a))
print((max(r + b for r, b in zip(R, reversed(B)))))

-from heapq import heapify, heappop, heappush +from heapq import heapify, heappushpop -    heappush(Q, a) -    R.append(R[-1] + a - heappop(Q)) +    R.append(R[-1] + a - heappushpop(Q, a)) -    heappush(Q, -a) -    B.append(B[-1] - a - heappop(Q)) +    B.append(B[-1] - a - heappushpop(Q, -a))