from heapq import heappush, heappop

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

F = []

fs = 0

S = []

ss = 0

P = []

state = [0]*(3*N)

for i in range(N):

  heappush(F,A[i])

  fs += A[i]

for i in range(N,3*N):

  heappush(S,(-A[i],i))

  ss += A[i]

  state[i] = 1

for i in range(N):

  m,j = heappop(S)

  state[j] = 2

  ss += m

  heappush(P,(-m,j))

ans = fs-ss

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

  n = heappop(F)

  fs = fs-n+A[i]

  heappush(F,A[i])

  if state[i]==1:

    while state[P[0][1]]==0:

      heappop(P)

    p,j = heappop(P)

    ss += -A[i]+p

    state[j] = 1

  state[i] = 0

  ans = max(ans,fs-ss)

print(ans)
from heapq import heappush, heappop

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

F = []

fs = 0

ss = 0

P = []

state = [0]*(3*N)

for i in range(N):

  heappush(F,A[i])

  fs += A[i]

ls = sorted(list(range(N,3*N)),key=lambda x:A[x])

for i in range(N):

  state[ls[i]] = 1

  ss += A[ls[i]]

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

  state[ls[i]] = 2

  heappush(P,(A[ls[i]],ls[i]))

ans = fs-ss

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

  n = heappop(F)

  fs = fs-n+A[i]

  heappush(F,A[i])

  if state[i]==1:

    while state[P[0][1]]==0:

      heappop(P)

    p,j = heappop(P)

    ss += -A[i]+p

    state[j] = 1

  state[i] = 0

  ans = max(ans,fs-ss)

print(ans)
from heapq import heappush, heappop

N, *A = list(map(int, open(0).read().split()))
F = []
fs = 0
S = []
ss = 0
P = []
state = [0] * (3 * N)
for i in range(N):
    heappush(F, A[i])
    fs += A[i]
for i in range(N, 3 * N):
    heappush(S, (-A[i], i))
    ss += A[i]
    state[i] = 1
for i in range(N):
    m, j = heappop(S)
    state[j] = 2
    ss += m
    heappush(P, (-m, j))
ans = fs - ss
for i in range(N, 2 * N):
    n = heappop(F)
    fs = fs - n + A[i]
    heappush(F, A[i])
    if state[i] == 1:
        while state[P[0][1]] == 0:
            heappop(P)
        p, j = heappop(P)
        ss += -A[i] + p
        state[j] = 1
    state[i] = 0
    ans = max(ans, fs - ss)
print(ans)

from heapq import heappush, heappop

N, *A = list(map(int, open(0).read().split()))
F = []
fs = 0
ss = 0
P = []
state = [0] * (3 * N)
for i in range(N):
    heappush(F, A[i])
    fs += A[i]
ls = sorted(list(range(N, 3 * N)), key=lambda x: A[x])
for i in range(N):
    state[ls[i]] = 1
    ss += A[ls[i]]
for i in range(N, 2 * N):
    state[ls[i]] = 2
    heappush(P, (A[ls[i]], ls[i]))
ans = fs - ss
for i in range(N, 2 * N):
    n = heappop(F)
    fs = fs - n + A[i]
    heappush(F, A[i])
    if state[i] == 1:
        while state[P[0][1]] == 0:
            heappop(P)
        p, j = heappop(P)
        ss += -A[i] + p
        state[j] = 1
    state[i] = 0
    ans = max(ans, fs - ss)
print(ans)

-S = [] -for i in range(N, 3 * N): -    heappush(S, (-A[i], i)) -    ss += A[i] -    state[i] = 1 +ls = sorted(list(range(N, 3 * N)), key=lambda x: A[x]) -    m, j = heappop(S) -    state[j] = 2 -    ss += m -    heappush(P, (-m, j)) +    state[ls[i]] = 1 +    ss += A[ls[i]] +for i in range(N, 2 * N): +    state[ls[i]] = 2 +    heappush(P, (A[ls[i]], ls[i]))