# -*- coding: utf-8 -*-



import heapq





class MaxHeap:

    def __init__(self, li):

        self.heap = [-e for e in li]

        heapq.heapify(self.heap)



    def push(self, val):

        heapq.heappush(self.heap, -val)



    def pop(self):

        return -heapq.heappop(self.heap)





n = int(eval(input()))

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



fh_sum = 0

fh = []

sh_sum = 0

sh = MaxHeap([])

for i in range(n):

    heapq.heappush(fh, a[i])

    fh_sum += a[i]

    sh.push(a[-(i+1)])

    sh_sum += a[-(i+1)]



fh_sums = [fh_sum]

sh_sums = [sh_sum]

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

    fh_sum += a[k]

    heapq.heappush(fh, a[k])

    fh_sum -= heapq.heappop(fh)

    fh_sums.append(fh_sum)

    sh_sum += a[-(k+1)]

    sh.push(a[-(k+1)])

    sh_sum -= sh.pop()

    sh_sums.append(sh_sum)



sh_sums = sh_sums[::-1]



ans = -float("inf")

for fh_sum, sh_sum in zip(fh_sums, sh_sums):

    score = fh_sum - sh_sum

    ans = max(ans, score)



print(ans)

from heapq import heapify, heappop, heappush





class MaxHeap:

    def __init__(self, li):

        self.hp = []

        for e in li:

            heappush(self.hp, -e)



    def push(self, x):

        heappush(self.hp, -x)



    def pop(self):

        ret = heappop(self.hp)

        ret *= -1

        return ret



    def seak(self):

        return -self.hp[0]



    def sum(self):

        return -sum(self.hp)





n = int(eval(input()))

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



f = a[:n]

s = a[n:2*n]

t = a[2*n:]



heapify(f)

t = MaxHeap(t)



f_sm = sum(f)

f_sm_li = [f_sm]

for e in s:

    heappush(f, e)

    f_sm += e

    pp = heappop(f)

    f_sm -= pp

    f_sm_li.append(f_sm)



t_sm = t.sum()

t_sm_li = [t_sm]

for e in s[::-1]:

    t.push(e)

    t_sm += e

    pp = t.pop()

    t_sm -= pp

    t_sm_li.append(t_sm)



t_sm_li = t_sm_li[::-1]

ans = -float("inf")

for ef, et in zip(f_sm_li, t_sm_li):

    ans = max(ans, ef - et)



print(ans)

# -*- coding: utf-8 -*-
import heapq


class MaxHeap:
    def __init__(self, li):
        self.heap = [-e for e in li]
        heapq.heapify(self.heap)

    def push(self, val):
        heapq.heappush(self.heap, -val)

    def pop(self):
        return -heapq.heappop(self.heap)


n = int(eval(input()))
a = list(map(int, input().split()))
fh_sum = 0
fh = []
sh_sum = 0
sh = MaxHeap([])
for i in range(n):
    heapq.heappush(fh, a[i])
    fh_sum += a[i]
    sh.push(a[-(i + 1)])
    sh_sum += a[-(i + 1)]
fh_sums = [fh_sum]
sh_sums = [sh_sum]
for k in range(n, 2 * n):
    fh_sum += a[k]
    heapq.heappush(fh, a[k])
    fh_sum -= heapq.heappop(fh)
    fh_sums.append(fh_sum)
    sh_sum += a[-(k + 1)]
    sh.push(a[-(k + 1)])
    sh_sum -= sh.pop()
    sh_sums.append(sh_sum)
sh_sums = sh_sums[::-1]
ans = -float("inf")
for fh_sum, sh_sum in zip(fh_sums, sh_sums):
    score = fh_sum - sh_sum
    ans = max(ans, score)
print(ans)

from heapq import heapify, heappop, heappush


class MaxHeap:
    def __init__(self, li):
        self.hp = []
        for e in li:
            heappush(self.hp, -e)

    def push(self, x):
        heappush(self.hp, -x)

    def pop(self):
        ret = heappop(self.hp)
        ret *= -1
        return ret

    def seak(self):
        return -self.hp[0]

    def sum(self):
        return -sum(self.hp)


n = int(eval(input()))
a = list(map(int, input().split()))
f = a[:n]
s = a[n : 2 * n]
t = a[2 * n :]
heapify(f)
t = MaxHeap(t)
f_sm = sum(f)
f_sm_li = [f_sm]
for e in s:
    heappush(f, e)
    f_sm += e
    pp = heappop(f)
    f_sm -= pp
    f_sm_li.append(f_sm)
t_sm = t.sum()
t_sm_li = [t_sm]
for e in s[::-1]:
    t.push(e)
    t_sm += e
    pp = t.pop()
    t_sm -= pp
    t_sm_li.append(t_sm)
t_sm_li = t_sm_li[::-1]
ans = -float("inf")
for ef, et in zip(f_sm_li, t_sm_li):
    ans = max(ans, ef - et)
print(ans)

-# -*- coding: utf-8 -*- -import heapq +from heapq import heapify, heappop, heappush -        self.heap = [-e for e in li] -        heapq.heapify(self.heap) +        self.hp = [] +        for e in li: +            heappush(self.hp, -e) -    def push(self, val): -        heapq.heappush(self.heap, -val) +    def push(self, x): +        heappush(self.hp, -x) -        return -heapq.heappop(self.heap) +        ret = heappop(self.hp) +        ret *= -1 +        return ret + +    def seak(self): +        return -self.hp[0] + +    def sum(self): +        return -sum(self.hp) -fh_sum = 0 -fh = [] -sh_sum = 0 -sh = MaxHeap([]) -for i in range(n): -    heapq.heappush(fh, a[i]) -    fh_sum += a[i] -    sh.push(a[-(i + 1)]) -    sh_sum += a[-(i + 1)] -fh_sums = [fh_sum] -sh_sums = [sh_sum] -for k in range(n, 2 * n): -    fh_sum += a[k] -    heapq.heappush(fh, a[k]) -    fh_sum -= heapq.heappop(fh) -    fh_sums.append(fh_sum) -    sh_sum += a[-(k + 1)] -    sh.push(a[-(k + 1)]) -    sh_sum -= sh.pop() -    sh_sums.append(sh_sum) -sh_sums = sh_sums[::-1] +f = a[:n] +s = a[n : 2 * n] +t = a[2 * n :] +heapify(f) +t = MaxHeap(t) +f_sm = sum(f) +f_sm_li = [f_sm] +for e in s: +    heappush(f, e) +    f_sm += e +    pp = heappop(f) +    f_sm -= pp +    f_sm_li.append(f_sm) +t_sm = t.sum() +t_sm_li = [t_sm] +for e in s[::-1]: +    t.push(e) +    t_sm += e +    pp = t.pop() +    t_sm -= pp +    t_sm_li.append(t_sm) +t_sm_li = t_sm_li[::-1] -for fh_sum, sh_sum in zip(fh_sums, sh_sums): -    score = fh_sum - sh_sum -    ans = max(ans, score) +for ef, et in zip(f_sm_li, t_sm_li): +    ans = max(ans, ef - et)