from heapq import heapify,heappush, heappop



N=eval(input())

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



q=A[:N]

heapify(q)

q_sum=sum(q)



B=[ float("-inf") for i in range(3*N)]

B[N-1]=q_sum



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

	x=A[i]

	if x>q[0]:

		tmp=heappop(q)

		q_sum-=tmp

		q_sum+=x

		heappush(q,x)

	B[i]=q_sum



q=[x*-1 for x in A[2*N:]]

heapify(q)



q_sum=sum(q)*-1

B[2*N-1]-=q_sum



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

	x=A[i]*-1

	if q[0]<x:

		tmp=heappop(q)

		q_sum-=tmp*-1

		q_sum+=x*-1

		heappush(q,x)

	B[i-1]-=q_sum



print(max(B))
from heapq import heapify,heappush, heappop



N=eval(input())

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



hq1=A[:N]

heapify(hq1)

sum1=sum(hq1)





T1=[]

T1.append(sum1)



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

	x=A[i]

	if hq1[0]<x:

		u=heappop(hq1)

		heappush(hq1,x)

		sum1+=(x-u)

	T1.append(sum1)





hq2=[x*-1 for x in A[2*N:]]

sum2=-1*sum(hq2)

heapify(hq2)







T2=[]

T2.append(sum2)



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

	x=A[i]

	if x*-1 > hq2[0]<x:

			u=heappop(hq2)

			heappush(hq2,x*-1)

			sum2+=u+x



	T2.append(sum2)





T2.reverse()





ans=float("-inf")

for x, y in zip(T1, T2):

	ans=max(ans , x-y)

print(ans)

from heapq import heapify, heappush, heappop

N = eval(input())
A = list(map(int, input().split()))
q = A[:N]
heapify(q)
q_sum = sum(q)
B = [float("-inf") for i in range(3 * N)]
B[N - 1] = q_sum
for i in range(N, 2 * N):
    x = A[i]
    if x > q[0]:
        tmp = heappop(q)
        q_sum -= tmp
        q_sum += x
        heappush(q, x)
    B[i] = q_sum
q = [x * -1 for x in A[2 * N :]]
heapify(q)
q_sum = sum(q) * -1
B[2 * N - 1] -= q_sum
for i in range(2 * N - 1, N - 1, -1):
    x = A[i] * -1
    if q[0] < x:
        tmp = heappop(q)
        q_sum -= tmp * -1
        q_sum += x * -1
        heappush(q, x)
    B[i - 1] -= q_sum
print(max(B))

from heapq import heapify, heappush, heappop

N = eval(input())
A = list(map(int, input().split()))
hq1 = A[:N]
heapify(hq1)
sum1 = sum(hq1)
T1 = []
T1.append(sum1)
for i in range(N, 2 * N):
    x = A[i]
    if hq1[0] < x:
        u = heappop(hq1)
        heappush(hq1, x)
        sum1 += x - u
    T1.append(sum1)
hq2 = [x * -1 for x in A[2 * N :]]
sum2 = -1 * sum(hq2)
heapify(hq2)
T2 = []
T2.append(sum2)
for i in range(2 * N - 1, N - 1, -1):
    x = A[i]
    if x * -1 > hq2[0] < x:
        u = heappop(hq2)
        heappush(hq2, x * -1)
        sum2 += u + x
    T2.append(sum2)
T2.reverse()
ans = float("-inf")
for x, y in zip(T1, T2):
    ans = max(ans, x - y)
print(ans)

-q = A[:N] -heapify(q) -q_sum = sum(q) -B = [float("-inf") for i in range(3 * N)] -B[N - 1] = q_sum +hq1 = A[:N] +heapify(hq1) +sum1 = sum(hq1) +T1 = [] +T1.append(sum1) -    if x > q[0]: -        tmp = heappop(q) -        q_sum -= tmp -        q_sum += x -        heappush(q, x) -    B[i] = q_sum -q = [x * -1 for x in A[2 * N :]] -heapify(q) -q_sum = sum(q) * -1 -B[2 * N - 1] -= q_sum +    if hq1[0] < x: +        u = heappop(hq1) +        heappush(hq1, x) +        sum1 += x - u +    T1.append(sum1) +hq2 = [x * -1 for x in A[2 * N :]] +sum2 = -1 * sum(hq2) +heapify(hq2) +T2 = [] +T2.append(sum2) -    x = A[i] * -1 -    if q[0] < x: -        tmp = heappop(q) -        q_sum -= tmp * -1 -        q_sum += x * -1 -        heappush(q, x) -    B[i - 1] -= q_sum -print(max(B)) +    x = A[i] +    if x * -1 > hq2[0] < x: +        u = heappop(hq2) +        heappush(hq2, x * -1) +        sum2 += u + x +    T2.append(sum2) +T2.reverse() +ans = float("-inf") +for x, y in zip(T1, T2): +    ans = max(ans, x - y) +print(ans)