from heapq import heapify, heappop, heappush



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



Q = A[:N]

heapify(Q)



R = [sum(Q)]

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

    heappush(Q, A[k])

    m = heappop(Q)

    R.append(R[-1] + A[k] - m)



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

heapify(Q)



B = [sum(Q)]

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

    heappush(Q, -A[k])

    m = heappop(Q)

    B.append(B[-1] - A[k] - m)



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, heappop, heappush

N, *A = list(map(int, open(0).read().split()))
Q = A[:N]
heapify(Q)
R = [sum(Q)]
for k in range(N, 2 * N):
    heappush(Q, A[k])
    m = heappop(Q)
    R.append(R[-1] + A[k] - m)
Q = [-a for a in A[2 * N :]]
heapify(Q)
B = [sum(Q)]
for k in reversed(list(range(N, 2 * N))):
    heappush(Q, -A[k])
    m = heappop(Q)
    B.append(B[-1] - A[k] - m)
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)))))

-for k in range(N, 2 * N): -    heappush(Q, A[k]) -    m = heappop(Q) -    R.append(R[-1] + A[k] - m) +for a in A[N : 2 * N]: +    heappush(Q, a) +    R.append(R[-1] + a - heappop(Q)) -for k in reversed(list(range(N, 2 * N))): -    heappush(Q, -A[k]) -    m = heappop(Q) -    B.append(B[-1] - A[k] - m) +for a in reversed(A[N : 2 * N]): +    heappush(Q, -a) +    B.append(B[-1] - a - heappop(Q))