import heapq



N = int(eval(input()))

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



# 準備

left, right = A[:N], A[-N:]



right = list([-x for x in right])

left_sum, right_sum = [sum(left)], [-sum(right)]

heapq.heapify(left)

heapq.heapify(right)



# left処理

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

    heapq.heappush(left, A[i])

    low = heapq.heappop(left)

    left_sum.append(left_sum[-1] + A[i] - low)



# right処理

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

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

    high = -heapq.heappop(right)

    right_sum.append(right_sum[-1] + A[i] - high)



# rightを逆順にしてleftの挙動と合わせる

right_sum = right_sum[::-1]



ans = max([l-r for l, r in zip(left_sum, right_sum)])

print(ans)

import heapq

N = int(eval(input()))

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



Left, Right = A[:N], list([-a for a in A[-N:]])

heapq.heapify(Left)

heapq.heapify(Right)

Left_SUM, Right_SUM = [sum(Left)], [-sum(Right)]



M = A[N:2*N]

# 左側

for k in range(N):

    lo = heapq.heappushpop(Left, M[k])

    Left_SUM.append(Left_SUM[-1] + M[k] - lo)



# 右側

for k in reversed(list(range(N))):

    hi = -heapq.heappushpop(Right, -M[k])

    Right_SUM.append(Right_SUM[-1] + M[k] - hi)



# 最大値を計算

ans = max([l - r for l, r in zip(Left_SUM, Right_SUM[::-1])])

print(ans)

import heapq

N = int(eval(input()))
A = list(map(int, input().split()))
# 準備
left, right = A[:N], A[-N:]
right = list([-x for x in right])
left_sum, right_sum = [sum(left)], [-sum(right)]
heapq.heapify(left)
heapq.heapify(right)
# left処理
for i in range(N, 2 * N):
    heapq.heappush(left, A[i])
    low = heapq.heappop(left)
    left_sum.append(left_sum[-1] + A[i] - low)
# right処理
for i in range(2 * N - 1, N - 1, -1):
    heapq.heappush(right, -A[i])
    high = -heapq.heappop(right)
    right_sum.append(right_sum[-1] + A[i] - high)
# rightを逆順にしてleftの挙動と合わせる
right_sum = right_sum[::-1]
ans = max([l - r for l, r in zip(left_sum, right_sum)])
print(ans)

import heapq

N = int(eval(input()))
A = list(map(int, input().split()))
Left, Right = A[:N], list([-a for a in A[-N:]])
heapq.heapify(Left)
heapq.heapify(Right)
Left_SUM, Right_SUM = [sum(Left)], [-sum(Right)]
M = A[N : 2 * N]
# 左側
for k in range(N):
    lo = heapq.heappushpop(Left, M[k])
    Left_SUM.append(Left_SUM[-1] + M[k] - lo)
# 右側
for k in reversed(list(range(N))):
    hi = -heapq.heappushpop(Right, -M[k])
    Right_SUM.append(Right_SUM[-1] + M[k] - hi)
# 最大値を計算
ans = max([l - r for l, r in zip(Left_SUM, Right_SUM[::-1])])
print(ans)

-# 準備 -left, right = A[:N], A[-N:] -right = list([-x for x in right]) -left_sum, right_sum = [sum(left)], [-sum(right)] -heapq.heapify(left) -heapq.heapify(right) -# left処理 -for i in range(N, 2 * N): -    heapq.heappush(left, A[i]) -    low = heapq.heappop(left) -    left_sum.append(left_sum[-1] + A[i] - low) -# right処理 -for i in range(2 * N - 1, N - 1, -1): -    heapq.heappush(right, -A[i]) -    high = -heapq.heappop(right) -    right_sum.append(right_sum[-1] + A[i] - high) -# rightを逆順にしてleftの挙動と合わせる -right_sum = right_sum[::-1] -ans = max([l - r for l, r in zip(left_sum, right_sum)]) +Left, Right = A[:N], list([-a for a in A[-N:]]) +heapq.heapify(Left) +heapq.heapify(Right) +Left_SUM, Right_SUM = [sum(Left)], [-sum(Right)] +M = A[N : 2 * N] +# 左側 +for k in range(N): +    lo = heapq.heappushpop(Left, M[k]) +    Left_SUM.append(Left_SUM[-1] + M[k] - lo) +# 右側 +for k in reversed(list(range(N))): +    hi = -heapq.heappushpop(Right, -M[k]) +    Right_SUM.append(Right_SUM[-1] + M[k] - hi) +# 最大値を計算 +ans = max([l - r for l, r in zip(Left_SUM, Right_SUM[::-1])])