import heapq

n = int(eval(input()))

a = [int(i) for i in input().split()]

k = 0

a_front = []

a_center = []

a_back = []

front_sum = 0

back_sum = 0



for i in a:

    k += 1

    if k <= n:

        a_front += [i]

        front_sum += i

    elif k <= 2 * n:

        a_center += [i]

    else:

        a_back += [-i]

        back_sum += i



heapq.heapify(a_front)

heapq.heapify(a_back)



front_sums = [front_sum]

back_sums = [back_sum]



for i in range(n):

        front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i])

        front_sums += [front_sum]

        back_sum += a_center[-i-1] + heapq.heappushpop(a_back, -a_center[-i-1])

        back_sums += [back_sum]



print((max([front_sums[i] - back_sums[-i-1] for i in range(n+1)])))

#print(front_sums, back_sums)

import heapq



def calc(front_sum, back_sum):

    heapq.heapify(a_front)

    heapq.heapify(a_back)

    front_sums = [front_sum]

    back_sums = [back_sum]

    for i in range(n):

        front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i])

        front_sums += [front_sum]

        back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1])

        back_sums += [back_sum]

    return max([front_sums[i] - back_sums[-i-1] for i in range(n+1)])







if __name__ == "__main__":

    n = int(eval(input()))

    a = [int(i) for i in input().split()]

    k = 0

    a_front = []

    a_center = []

    a_back = []

    front_sum = 0

    back_sum = 0



    for i in a:

        k += 1

        if k <= n:

            a_front += [i]

            front_sum += i

        elif k <= 2 * n:

            a_center += [i]

        else:

            a_back += [-i]

            back_sum += i



    print((calc(front_sum, back_sum)))



import heapq

n = int(eval(input()))
a = [int(i) for i in input().split()]
k = 0
a_front = []
a_center = []
a_back = []
front_sum = 0
back_sum = 0
for i in a:
    k += 1
    if k <= n:
        a_front += [i]
        front_sum += i
    elif k <= 2 * n:
        a_center += [i]
    else:
        a_back += [-i]
        back_sum += i
heapq.heapify(a_front)
heapq.heapify(a_back)
front_sums = [front_sum]
back_sums = [back_sum]
for i in range(n):
    front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i])
    front_sums += [front_sum]
    back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1])
    back_sums += [back_sum]
print((max([front_sums[i] - back_sums[-i - 1] for i in range(n + 1)])))
# print(front_sums, back_sums)

import heapq


def calc(front_sum, back_sum):
    heapq.heapify(a_front)
    heapq.heapify(a_back)
    front_sums = [front_sum]
    back_sums = [back_sum]
    for i in range(n):
        front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i])
        front_sums += [front_sum]
        back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1])
        back_sums += [back_sum]
    return max([front_sums[i] - back_sums[-i - 1] for i in range(n + 1)])


if __name__ == "__main__":
    n = int(eval(input()))
    a = [int(i) for i in input().split()]
    k = 0
    a_front = []
    a_center = []
    a_back = []
    front_sum = 0
    back_sum = 0
    for i in a:
        k += 1
        if k <= n:
            a_front += [i]
            front_sum += i
        elif k <= 2 * n:
            a_center += [i]
        else:
            a_back += [-i]
            back_sum += i
    print((calc(front_sum, back_sum)))

-n = int(eval(input())) -a = [int(i) for i in input().split()] -k = 0 -a_front = [] -a_center = [] -a_back = [] -front_sum = 0 -back_sum = 0 -for i in a: -    k += 1 -    if k <= n: -        a_front += [i] -        front_sum += i -    elif k <= 2 * n: -        a_center += [i] -    else: -        a_back += [-i] -        back_sum += i -heapq.heapify(a_front) -heapq.heapify(a_back) -front_sums = [front_sum] -back_sums = [back_sum] -for i in range(n): -    front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i]) -    front_sums += [front_sum] -    back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1]) -    back_sums += [back_sum] -print((max([front_sums[i] - back_sums[-i - 1] for i in range(n + 1)]))) -# print(front_sums, back_sums) + +def calc(front_sum, back_sum): +    heapq.heapify(a_front) +    heapq.heapify(a_back) +    front_sums = [front_sum] +    back_sums = [back_sum] +    for i in range(n): +        front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i]) +        front_sums += [front_sum] +        back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1]) +        back_sums += [back_sum] +    return max([front_sums[i] - back_sums[-i - 1] for i in range(n + 1)]) + + +if __name__ == "__main__": +    n = int(eval(input())) +    a = [int(i) for i in input().split()] +    k = 0 +    a_front = [] +    a_center = [] +    a_back = [] +    front_sum = 0 +    back_sum = 0 +    for i in a: +        k += 1 +        if k <= n: +            a_front += [i] +            front_sum += i +        elif k <= 2 * n: +            a_center += [i] +        else: +            a_back += [-i] +            back_sum += i +    print((calc(front_sum, back_sum)))