import sys

# If available, use C implementation

try:

    from _heapq import heapify, heappushpop

except ImportError:

    from heapq import heapify, heappushpop

try:

    from _heapq import _heapreplace_max

except ImportError:

    pass

try:

    from _heapq import _heapify_max as heapify_max

except ImportError:

    from heapq import _heapify_max as heapify_max

try:

    from _heapq import _siftup_max

except ImportError:

    from heapq import _siftup_max





def heappushpop_max(heap, item):

    if heap and heap[0] > item:

        item, heap[0] = heap[0], item

        _siftup_max(heap, 0)

    return item





fin = sys.stdin.readline

N = int(fin())

a_list = [int(elem) for elem in fin().split()]



left_pq = a_list[:N]

right_pq = a_list[2 * N:]

heapify(left_pq)

heapify_max(right_pq)



left_sum = [sum(left_pq)]

right_sum = [sum(right_pq)]

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

    left_item = a_list[k]

    right_item = a_list[-k - 1]

    left_sum.append(left_sum[-1] - heappushpop(left_pq, left_item) + left_item)

    right_sum.append(right_sum[-1] - heappushpop_max(right_pq, right_item) + right_item)



max_sum = max(list(map(sum, list(zip(left_sum, [-item for item in right_sum[::-1]])))))

print(max_sum)

import sys

from heapq import heapify, heappushpop





fin = sys.stdin.readline

N = int(fin())

a_list = [int(elem) for elem in fin().split()]



left_pq = a_list[:N]

right_pq = [-item for item in a_list[2 * N:]]

heapify(left_pq)

heapify(right_pq)



left_sum = [sum(left_pq)]

right_sum = [sum(right_pq)]

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

    left_item = a_list[k]

    right_item = a_list[-k - 1]

    left_sum.append(left_sum[-1] - heappushpop(left_pq, left_item) + left_item)

    right_sum.append(right_sum[-1] - heappushpop(right_pq, -right_item) - right_item)



max_sum = max(list(map(sum, list(zip(left_sum, right_sum[::-1])))))

print(max_sum)

import sys

# If available, use C implementation
try:
    from _heapq import heapify, heappushpop
except ImportError:
    from heapq import heapify, heappushpop
try:
    from _heapq import _heapreplace_max
except ImportError:
    pass
try:
    from _heapq import _heapify_max as heapify_max
except ImportError:
    from heapq import _heapify_max as heapify_max
try:
    from _heapq import _siftup_max
except ImportError:
    from heapq import _siftup_max


def heappushpop_max(heap, item):
    if heap and heap[0] > item:
        item, heap[0] = heap[0], item
        _siftup_max(heap, 0)
    return item


fin = sys.stdin.readline
N = int(fin())
a_list = [int(elem) for elem in fin().split()]
left_pq = a_list[:N]
right_pq = a_list[2 * N :]
heapify(left_pq)
heapify_max(right_pq)
left_sum = [sum(left_pq)]
right_sum = [sum(right_pq)]
for k in range(N, 2 * N):
    left_item = a_list[k]
    right_item = a_list[-k - 1]
    left_sum.append(left_sum[-1] - heappushpop(left_pq, left_item) + left_item)
    right_sum.append(right_sum[-1] - heappushpop_max(right_pq, right_item) + right_item)
max_sum = max(list(map(sum, list(zip(left_sum, [-item for item in right_sum[::-1]])))))
print(max_sum)

import sys
from heapq import heapify, heappushpop

fin = sys.stdin.readline
N = int(fin())
a_list = [int(elem) for elem in fin().split()]
left_pq = a_list[:N]
right_pq = [-item for item in a_list[2 * N :]]
heapify(left_pq)
heapify(right_pq)
left_sum = [sum(left_pq)]
right_sum = [sum(right_pq)]
for k in range(N, 2 * N):
    left_item = a_list[k]
    right_item = a_list[-k - 1]
    left_sum.append(left_sum[-1] - heappushpop(left_pq, left_item) + left_item)
    right_sum.append(right_sum[-1] - heappushpop(right_pq, -right_item) - right_item)
max_sum = max(list(map(sum, list(zip(left_sum, right_sum[::-1])))))
print(max_sum)

- -# If available, use C implementation -try: -    from _heapq import heapify, heappushpop -except ImportError: -    from heapq import heapify, heappushpop -try: -    from _heapq import _heapreplace_max -except ImportError: -    pass -try: -    from _heapq import _heapify_max as heapify_max -except ImportError: -    from heapq import _heapify_max as heapify_max -try: -    from _heapq import _siftup_max -except ImportError: -    from heapq import _siftup_max - - -def heappushpop_max(heap, item): -    if heap and heap[0] > item: -        item, heap[0] = heap[0], item -        _siftup_max(heap, 0) -    return item - +from heapq import heapify, heappushpop -right_pq = a_list[2 * N :] +right_pq = [-item for item in a_list[2 * N :]] -heapify_max(right_pq) +heapify(right_pq) -    right_sum.append(right_sum[-1] - heappushpop_max(right_pq, right_item) + right_item) -max_sum = max(list(map(sum, list(zip(left_sum, [-item for item in right_sum[::-1]]))))) +    right_sum.append(right_sum[-1] - heappushpop(right_pq, -right_item) - right_item) +max_sum = max(list(map(sum, list(zip(left_sum, right_sum[::-1])))))