# coding: utf-8

# Your code here!

n = int(eval(input()))

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



from heapq import *



pq1 = a[:n]

heapify(pq1)

s = sum(pq1)

score1 = [s]

for i in range(n):

    c=heappushpop(pq1, a[n+i])

    s += a[n+i] - c

    score1.append(s)



pq2 = [-i for i in a[2*n:]]

heapify(pq2)

s = sum(pq2)

score2 = [s]

for i in range(1,n+1):

    c=heappushpop(pq2, -a[2*n-i])

    s += -a[2*n-i] - c

    score2.append(s)



#print(score1)

#print(score2)

ans = -10**17

for i,j in zip(score1,reversed(score2)):

    ans = max(ans, i+j)



print(ans)

    

# coding: utf-8

# Your code here!

import sys

read = sys.stdin.read

readline = sys.stdin.readline



n,*a = list(map(int,read().split()))



from heapq import *



def get(q,a):

    v = sum(q)

    res = [v]

    for i in a[n:2*n]:

        x = heappushpop(q,i)

        v += i-x

        res.append(v)

    return res



q = a[:n]

heapify(q)

res1 = get(q,a)



a = [-i for i in a[::-1]]

q = a[:n]

heapify(q)

res2 = get(q,a)



#print(res1)

#print(res2)



print((max(i+j for i,j in zip(res1,res2[::-1]))))















# coding: utf-8
# Your code here!
n = int(eval(input()))
a = [int(i) for i in input().split()]
from heapq import *

pq1 = a[:n]
heapify(pq1)
s = sum(pq1)
score1 = [s]
for i in range(n):
    c = heappushpop(pq1, a[n + i])
    s += a[n + i] - c
    score1.append(s)
pq2 = [-i for i in a[2 * n :]]
heapify(pq2)
s = sum(pq2)
score2 = [s]
for i in range(1, n + 1):
    c = heappushpop(pq2, -a[2 * n - i])
    s += -a[2 * n - i] - c
    score2.append(s)
# print(score1)
# print(score2)
ans = -(10**17)
for i, j in zip(score1, reversed(score2)):
    ans = max(ans, i + j)
print(ans)

# coding: utf-8
# Your code here!
import sys

read = sys.stdin.read
readline = sys.stdin.readline
n, *a = list(map(int, read().split()))
from heapq import *


def get(q, a):
    v = sum(q)
    res = [v]
    for i in a[n : 2 * n]:
        x = heappushpop(q, i)
        v += i - x
        res.append(v)
    return res


q = a[:n]
heapify(q)
res1 = get(q, a)
a = [-i for i in a[::-1]]
q = a[:n]
heapify(q)
res2 = get(q, a)
# print(res1)
# print(res2)
print((max(i + j for i, j in zip(res1, res2[::-1]))))

-n = int(eval(input())) -a = [int(i) for i in input().split()] +import sys + +read = sys.stdin.read +readline = sys.stdin.readline +n, *a = list(map(int, read().split())) -pq1 = a[:n] -heapify(pq1) -s = sum(pq1) -score1 = [s] -for i in range(n): -    c = heappushpop(pq1, a[n + i]) -    s += a[n + i] - c -    score1.append(s) -pq2 = [-i for i in a[2 * n :]] -heapify(pq2) -s = sum(pq2) -score2 = [s] -for i in range(1, n + 1): -    c = heappushpop(pq2, -a[2 * n - i]) -    s += -a[2 * n - i] - c -    score2.append(s) -# print(score1) -# print(score2) -ans = -(10**17) -for i, j in zip(score1, reversed(score2)): -    ans = max(ans, i + j) -print(ans) + +def get(q, a): +    v = sum(q) +    res = [v] +    for i in a[n : 2 * n]: +        x = heappushpop(q, i) +        v += i - x +        res.append(v) +    return res + + +q = a[:n] +heapify(q) +res1 = get(q, a) +a = [-i for i in a[::-1]] +q = a[:n] +heapify(q) +res2 = get(q, a) +# print(res1) +# print(res2) +print((max(i + j for i, j in zip(res1, res2[::-1]))))