import heapq

N = int(eval(input()))

*A, = list(map(int,input().split()))

q = []

for a in A[:N]:

    heapq.heappush(q,a)

S1 = [sum(q)]

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

    if a>q[0]:

        S1.append(S1[-1] + a - q[0])

        heapq.heapreplace(q,a)

    else:

        S1.append(S1[-1])

q = []

for a in A[2*N:]:

    heapq.heappush(q,-a)

S2 = [sum(q)]

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

    if a<-q[0]:

        S2.append(S2[-1] - a - q[0])

        heapq.heapreplace(q,-a)

    else:

        S2.append(S2[-1])

S2 = S2[::-1]

print((max(list(map(sum,list(zip(S1,S2)))))))
N = int(eval(input()))

*A, = list(map(int,input().split()))



from heapq import *



B1 = []

hpu = heappush

hpp = heappushpop

for a in A[:N]:

    hpu(B1,a)

S1 = [sum(B1)]

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

    S1.append(S1[-1]+ a - hpp(B1,a))

B2 = []

for a in A[2*N:]:

    hpu(B2,-a)

S2 = [-sum(B2)]

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

    S2.append(S2[-1] + a + hpp(B2,-a))



print((max(S1[i]-S2[-i-1] for i in range(N+1))))
import heapq

N = int(eval(input()))
(*A,) = list(map(int, input().split()))
q = []
for a in A[:N]:
    heapq.heappush(q, a)
S1 = [sum(q)]
for a in A[N : N * 2]:
    if a > q[0]:
        S1.append(S1[-1] + a - q[0])
        heapq.heapreplace(q, a)
    else:
        S1.append(S1[-1])
q = []
for a in A[2 * N :]:
    heapq.heappush(q, -a)
S2 = [sum(q)]
for a in A[N : N * 2][::-1]:
    if a < -q[0]:
        S2.append(S2[-1] - a - q[0])
        heapq.heapreplace(q, -a)
    else:
        S2.append(S2[-1])
S2 = S2[::-1]
print((max(list(map(sum, list(zip(S1, S2)))))))

N = int(eval(input()))
(*A,) = list(map(int, input().split()))
from heapq import *

B1 = []
hpu = heappush
hpp = heappushpop
for a in A[:N]:
    hpu(B1, a)
S1 = [sum(B1)]
for a in A[N : 2 * N]:
    S1.append(S1[-1] + a - hpp(B1, a))
B2 = []
for a in A[2 * N :]:
    hpu(B2, -a)
S2 = [-sum(B2)]
for a in A[N : 2 * N][::-1]:
    S2.append(S2[-1] + a + hpp(B2, -a))
print((max(S1[i] - S2[-i - 1] for i in range(N + 1))))

-import heapq - -q = [] +from heapq import * + +B1 = [] +hpu = heappush +hpp = heappushpop -    heapq.heappush(q, a) -S1 = [sum(q)] -for a in A[N : N * 2]: -    if a > q[0]: -        S1.append(S1[-1] + a - q[0]) -        heapq.heapreplace(q, a) -    else: -        S1.append(S1[-1]) -q = [] +    hpu(B1, a) +S1 = [sum(B1)] +for a in A[N : 2 * N]: +    S1.append(S1[-1] + a - hpp(B1, a)) +B2 = [] -    heapq.heappush(q, -a) -S2 = [sum(q)] -for a in A[N : N * 2][::-1]: -    if a < -q[0]: -        S2.append(S2[-1] - a - q[0]) -        heapq.heapreplace(q, -a) -    else: -        S2.append(S2[-1]) -S2 = S2[::-1] -print((max(list(map(sum, list(zip(S1, S2))))))) +    hpu(B2, -a) +S2 = [-sum(B2)] +for a in A[N : 2 * N][::-1]: +    S2.append(S2[-1] + a + hpp(B2, -a)) +print((max(S1[i] - S2[-i - 1] for i in range(N + 1))))