from collections import deque

from heapq import heapify, heappop as pop, heappush as push



N = int(eval(input()))

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



l = a[:N]

m = deque(a[N:N*2])

r = [x * -1 for x in a[N*2:]] # 中身は負



heapify(l)

heapify(r)



ll = [sum(l)]

for em in m:

    l_min = pop(l)

    if l_min < em:

        ll.append(ll[-1] - l_min + em)

        push(l, em)

    else:

        ll.append(ll[-1])

        push(l, l_min)



rr = [sum(r)] # 中身は負

for em in reversed(m):

    r_max = pop(r) * -1

    if r_max > em:

        rr.append(rr[-1] + r_max - em)

        push(r, em * -1)

    else:

        rr.append(rr[-1])

        push(r, r_max * -1)



print((max(a + b for a, b in zip(ll, reversed(rr)))))
from heapq import heapify, heappop as pop, heappush as push



N = int(eval(input()))

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



l = a[:N]

m = a[N:N*2]

r = [x * -1 for x in a[N*2:]] # 中身は負



heapify(l)

heapify(r)



ll = [sum(l)]

for em in m:

    l_min = pop(l)

    if l_min < em:

        ll.append(ll[-1] - l_min + em)

        push(l, em)

    else:

        ll.append(ll[-1])

        push(l, l_min)



rr = [sum(r)] # 中身は負

for em in reversed(m):

    r_max = pop(r) * -1

    if r_max > em:

        rr.append(rr[-1] + r_max - em)

        push(r, em * -1)

    else:

        rr.append(rr[-1])

        push(r, r_max * -1)



print((max(a + b for a, b in zip(ll, reversed(rr)))))

from collections import deque
from heapq import heapify, heappop as pop, heappush as push

N = int(eval(input()))
a = list(map(int, input().split()))
l = a[:N]
m = deque(a[N : N * 2])
r = [x * -1 for x in a[N * 2 :]]  # 中身は負
heapify(l)
heapify(r)
ll = [sum(l)]
for em in m:
    l_min = pop(l)
    if l_min < em:
        ll.append(ll[-1] - l_min + em)
        push(l, em)
    else:
        ll.append(ll[-1])
        push(l, l_min)
rr = [sum(r)]  # 中身は負
for em in reversed(m):
    r_max = pop(r) * -1
    if r_max > em:
        rr.append(rr[-1] + r_max - em)
        push(r, em * -1)
    else:
        rr.append(rr[-1])
        push(r, r_max * -1)
print((max(a + b for a, b in zip(ll, reversed(rr)))))

from heapq import heapify, heappop as pop, heappush as push

N = int(eval(input()))
a = list(map(int, input().split()))
l = a[:N]
m = a[N : N * 2]
r = [x * -1 for x in a[N * 2 :]]  # 中身は負
heapify(l)
heapify(r)
ll = [sum(l)]
for em in m:
    l_min = pop(l)
    if l_min < em:
        ll.append(ll[-1] - l_min + em)
        push(l, em)
    else:
        ll.append(ll[-1])
        push(l, l_min)
rr = [sum(r)]  # 中身は負
for em in reversed(m):
    r_max = pop(r) * -1
    if r_max > em:
        rr.append(rr[-1] + r_max - em)
        push(r, em * -1)
    else:
        rr.append(rr[-1])
        push(r, r_max * -1)
print((max(a + b for a, b in zip(ll, reversed(rr)))))

-from collections import deque -m = deque(a[N : N * 2]) +m = a[N : N * 2]