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

from heapq import heappush,heappushpop,heapify



n = int(eval(input()))

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



q = []

s = 0

for i in range(n):

    heappush(q, a[i])

    s += a[i]

left = [s]

for k in range(n):

    x = heappushpop(q, a[n+k])

    s = s - x + a[n+k]

    left.append(s)



q = []

s = 0

for i in range(n):

    heappush(q, -1*a[3*n-1-i])

    s += a[3*n-1-i]

right = [0 for _ in range(n+1)]

right[n] = s

for k in range(n):

    x = heappushpop(q, -1*a[2*n-1-k])

    s = s - (-1*x) + a[2*n-1-k]

    right[n-1-k] = s



m = None

for k in range(n+1):

    if m is None:

        m = left[k] - right[k]

    else:

        m = max(m, left[k]-right[k])



print(m)

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

import heapq



n = int(eval(input()))

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

q = al[:n]

heapq.heapify(q)



s = sum(al[:n])

ll = [s]

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

    a = al[i]

    s += a

    a = heapq.heappushpop(q, a)

    s -= a

    ll.append(s)



s = 0

q = []

heapq.heapify(q)

for i in range(2*n, 3*n):

    s -= al[i]

    heapq.heappush(q, -al[i])



rl = [-s]

for i in range(2*n-1,n-1,-1):

    a = al[i]

    s += -a

    a = heapq.heappushpop(q, -a)

    s -= a

    rl.append(-s)

rl.reverse()



res = ll[0]-rl[0]

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

    res = max(res, ll[i]-rl[i])



print(res)

# -*- coding: utf-8 -*-
from heapq import heappush, heappushpop, heapify

n = int(eval(input()))
a = [int(x) for x in input().split()]
q = []
s = 0
for i in range(n):
    heappush(q, a[i])
    s += a[i]
left = [s]
for k in range(n):
    x = heappushpop(q, a[n + k])
    s = s - x + a[n + k]
    left.append(s)
q = []
s = 0
for i in range(n):
    heappush(q, -1 * a[3 * n - 1 - i])
    s += a[3 * n - 1 - i]
right = [0 for _ in range(n + 1)]
right[n] = s
for k in range(n):
    x = heappushpop(q, -1 * a[2 * n - 1 - k])
    s = s - (-1 * x) + a[2 * n - 1 - k]
    right[n - 1 - k] = s
m = None
for k in range(n + 1):
    if m is None:
        m = left[k] - right[k]
    else:
        m = max(m, left[k] - right[k])
print(m)

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

n = int(eval(input()))
al = list(map(int, input().split()))
q = al[:n]
heapq.heapify(q)
s = sum(al[:n])
ll = [s]
for i in range(n, 2 * n):
    a = al[i]
    s += a
    a = heapq.heappushpop(q, a)
    s -= a
    ll.append(s)
s = 0
q = []
heapq.heapify(q)
for i in range(2 * n, 3 * n):
    s -= al[i]
    heapq.heappush(q, -al[i])
rl = [-s]
for i in range(2 * n - 1, n - 1, -1):
    a = al[i]
    s += -a
    a = heapq.heappushpop(q, -a)
    s -= a
    rl.append(-s)
rl.reverse()
res = ll[0] - rl[0]
for i in range(1, n + 1):
    res = max(res, ll[i] - rl[i])
print(res)

-from heapq import heappush, heappushpop, heapify +import heapq -a = [int(x) for x in input().split()] +al = list(map(int, input().split())) +q = al[:n] +heapq.heapify(q) +s = sum(al[:n]) +ll = [s] +for i in range(n, 2 * n): +    a = al[i] +    s += a +    a = heapq.heappushpop(q, a) +    s -= a +    ll.append(s) +s = 0 -s = 0 -for i in range(n): -    heappush(q, a[i]) -    s += a[i] -left = [s] -for k in range(n): -    x = heappushpop(q, a[n + k]) -    s = s - x + a[n + k] -    left.append(s) -q = [] -s = 0 -for i in range(n): -    heappush(q, -1 * a[3 * n - 1 - i]) -    s += a[3 * n - 1 - i] -right = [0 for _ in range(n + 1)] -right[n] = s -for k in range(n): -    x = heappushpop(q, -1 * a[2 * n - 1 - k]) -    s = s - (-1 * x) + a[2 * n - 1 - k] -    right[n - 1 - k] = s -m = None -for k in range(n + 1): -    if m is None: -        m = left[k] - right[k] -    else: -        m = max(m, left[k] - right[k]) -print(m) +heapq.heapify(q) +for i in range(2 * n, 3 * n): +    s -= al[i] +    heapq.heappush(q, -al[i]) +rl = [-s] +for i in range(2 * n - 1, n - 1, -1): +    a = al[i] +    s += -a +    a = heapq.heappushpop(q, -a) +    s -= a +    rl.append(-s) +rl.reverse() +res = ll[0] - rl[0] +for i in range(1, n + 1): +    res = max(res, ll[i] - rl[i]) +print(res)