n = int(eval(input()))

as_ =  list(map(int, input().split()))



l = [0]*n

m = [0]*n

r = [0]*n

for i in range(n):

  l[i] = as_[i]

  m[i] = as_[n+i]

  r[i] = (-1)*as_[2*n+i]



import heapq

heapq.heapify(l)

heapq.heapify(r)



l_maxs = [0]*(n+1)

r_mins = [0]*(n+1)



sl = sum(l)

sr = sum(r)



for i in range(n+1):

  if i != 0:

    j = i-1

    heapq.heappush(l, m[j])

    a = heapq.heappop(l)

    sl += m[j] -a

    

    k = -i

    heapq.heappush(r, m[k]*(-1))

    b = heapq.heappop(r)

    sr += m[k]*(-1) - b

    

  l_maxs[i] = sl

  r_mins[i] = sr



#print(l_maxs)

#print(r_mins)



print((max([l_maxs[i] + r_mins[n-i] for i in range(n+1)])))
n = int(eval(input()))

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



L = A[0:n]

R = A[2*n:3*n]

import heapq

sl = sum(L)

heapq.heapify(L)

sls = [0]*(n+1)

sls[0] = sl

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

    heapq.heappush(L, A[i])

    x = heapq.heappop(L)

    sl += A[i]-x

    sls[i-n+1] = sl

#print(sls)



sr = sum(R)

R = [-c for c in R]

heapq.heapify(R)

srs = [0]*(n+1)

srs[-1] = sr

for i in reversed(list(range(n, 2*n))):

    heapq.heappush(R, -A[i])

    x = -heapq.heappop(R)

    sr += A[i]-x

    srs[i-n] = sr

#print(srs)

ans = - 10**18

for i in range(n+1):

    ans = max(ans, sls[i]-srs[i])

print(ans)
n = int(eval(input()))
as_ = list(map(int, input().split()))
l = [0] * n
m = [0] * n
r = [0] * n
for i in range(n):
    l[i] = as_[i]
    m[i] = as_[n + i]
    r[i] = (-1) * as_[2 * n + i]
import heapq

heapq.heapify(l)
heapq.heapify(r)
l_maxs = [0] * (n + 1)
r_mins = [0] * (n + 1)
sl = sum(l)
sr = sum(r)
for i in range(n + 1):
    if i != 0:
        j = i - 1
        heapq.heappush(l, m[j])
        a = heapq.heappop(l)
        sl += m[j] - a
        k = -i
        heapq.heappush(r, m[k] * (-1))
        b = heapq.heappop(r)
        sr += m[k] * (-1) - b
    l_maxs[i] = sl
    r_mins[i] = sr
# print(l_maxs)
# print(r_mins)
print((max([l_maxs[i] + r_mins[n - i] for i in range(n + 1)])))

n = int(eval(input()))
A = list(map(int, input().split()))
L = A[0:n]
R = A[2 * n : 3 * n]
import heapq

sl = sum(L)
heapq.heapify(L)
sls = [0] * (n + 1)
sls[0] = sl
for i in range(n, 2 * n):
    heapq.heappush(L, A[i])
    x = heapq.heappop(L)
    sl += A[i] - x
    sls[i - n + 1] = sl
# print(sls)
sr = sum(R)
R = [-c for c in R]
heapq.heapify(R)
srs = [0] * (n + 1)
srs[-1] = sr
for i in reversed(list(range(n, 2 * n))):
    heapq.heappush(R, -A[i])
    x = -heapq.heappop(R)
    sr += A[i] - x
    srs[i - n] = sr
# print(srs)
ans = -(10**18)
for i in range(n + 1):
    ans = max(ans, sls[i] - srs[i])
print(ans)

-as_ = list(map(int, input().split())) -l = [0] * n -m = [0] * n -r = [0] * n -for i in range(n): -    l[i] = as_[i] -    m[i] = as_[n + i] -    r[i] = (-1) * as_[2 * n + i] +A = list(map(int, input().split())) +L = A[0:n] +R = A[2 * n : 3 * n] -heapq.heapify(l) -heapq.heapify(r) -l_maxs = [0] * (n + 1) -r_mins = [0] * (n + 1) -sl = sum(l) -sr = sum(r) +sl = sum(L) +heapq.heapify(L) +sls = [0] * (n + 1) +sls[0] = sl +for i in range(n, 2 * n): +    heapq.heappush(L, A[i]) +    x = heapq.heappop(L) +    sl += A[i] - x +    sls[i - n + 1] = sl +# print(sls) +sr = sum(R) +R = [-c for c in R] +heapq.heapify(R) +srs = [0] * (n + 1) +srs[-1] = sr +for i in reversed(list(range(n, 2 * n))): +    heapq.heappush(R, -A[i]) +    x = -heapq.heappop(R) +    sr += A[i] - x +    srs[i - n] = sr +# print(srs) +ans = -(10**18) -    if i != 0: -        j = i - 1 -        heapq.heappush(l, m[j]) -        a = heapq.heappop(l) -        sl += m[j] - a -        k = -i -        heapq.heappush(r, m[k] * (-1)) -        b = heapq.heappop(r) -        sr += m[k] * (-1) - b -    l_maxs[i] = sl -    r_mins[i] = sr -# print(l_maxs) -# print(r_mins) -print((max([l_maxs[i] + r_mins[n - i] for i in range(n + 1)]))) +    ans = max(ans, sls[i] - srs[i]) +print(ans)