import sys

from heapq import heapify, heappush, heappop

from itertools import accumulate



inf = 1<<100



def solve():

    N = int(eval(input()))

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

    ps = [0] + list(accumulate(a))



    psmin = [0] * (N + 1)

    minhp = a[:N]

    heapify(minhp)



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

        heappush(minhp, a[N - 1 + i])

        x = heappop(minhp)

        psmin[i] = psmin[i - 1] + x



    psmax = [0] * (N + 1)

    maxhp = [-ai for ai in a[2*N:]]

    heapify(maxhp)



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

        heappush(maxhp, -a[2*N - i])

        x = -heappop(maxhp)

        psmax[i] = psmax[i - 1] + x



    # print(psmin)

    # print(psmax)



    ans = -inf



    for i in range(0, N + 1):

        # print(ps[N + i], psmin[i], ps[3*N] - ps[N + i], psmax[N - i])

        v = (ps[N + i] - psmin[i]) - (ps[3*N] - ps[N + i] - psmax[N - i])

        ans = max(ans, v)



    print(ans)

    pass



if __name__ == '__main__':

    solve()
import sys

from heapq import heapify, heappush, heappop



inf = 1<<60



def solve():

    n = int(eval(input()))

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



    ps = [sum(a[:n])]

    minhp = a[:n]

    heapify(minhp)



    for i in range(n):

        heappush(minhp, a[n + i])

        x = heappop(minhp)

        ps.append(ps[-1] + a[n + i] - x)



    ss = [sum(a[2*n:])]

    maxhp = [-ai for ai in a[2*n:]]

    heapify(maxhp)



    for i in range(n):

        heappush(maxhp, -a[2*n - 1 - i])

        x = -heappop(maxhp)

        ss.append(ss[-1] + a[2*n - 1 - i] - x)



    ans = -inf



    for i in range(n + 1):

        ans = max(ans, ps[i] - ss[n - i])



    print(ans)



if __name__ == '__main__':  

    solve()
import sys
from heapq import heapify, heappush, heappop
from itertools import accumulate

inf = 1 << 100


def solve():
    N = int(eval(input()))
    a = [int(i) for i in input().split()]
    ps = [0] + list(accumulate(a))
    psmin = [0] * (N + 1)
    minhp = a[:N]
    heapify(minhp)
    for i in range(1, N + 1):
        heappush(minhp, a[N - 1 + i])
        x = heappop(minhp)
        psmin[i] = psmin[i - 1] + x
    psmax = [0] * (N + 1)
    maxhp = [-ai for ai in a[2 * N :]]
    heapify(maxhp)
    for i in range(1, N + 1):
        heappush(maxhp, -a[2 * N - i])
        x = -heappop(maxhp)
        psmax[i] = psmax[i - 1] + x
    # print(psmin)
    # print(psmax)
    ans = -inf
    for i in range(0, N + 1):
        # print(ps[N + i], psmin[i], ps[3*N] - ps[N + i], psmax[N - i])
        v = (ps[N + i] - psmin[i]) - (ps[3 * N] - ps[N + i] - psmax[N - i])
        ans = max(ans, v)
    print(ans)
    pass


if __name__ == "__main__":
    solve()

import sys
from heapq import heapify, heappush, heappop

inf = 1 << 60


def solve():
    n = int(eval(input()))
    a = [int(i) for i in input().split()]
    ps = [sum(a[:n])]
    minhp = a[:n]
    heapify(minhp)
    for i in range(n):
        heappush(minhp, a[n + i])
        x = heappop(minhp)
        ps.append(ps[-1] + a[n + i] - x)
    ss = [sum(a[2 * n :])]
    maxhp = [-ai for ai in a[2 * n :]]
    heapify(maxhp)
    for i in range(n):
        heappush(maxhp, -a[2 * n - 1 - i])
        x = -heappop(maxhp)
        ss.append(ss[-1] + a[2 * n - 1 - i] - x)
    ans = -inf
    for i in range(n + 1):
        ans = max(ans, ps[i] - ss[n - i])
    print(ans)


if __name__ == "__main__":
    solve()

-from itertools import accumulate -inf = 1 << 100 +inf = 1 << 60 -    N = int(eval(input())) +    n = int(eval(input())) -    ps = [0] + list(accumulate(a)) -    psmin = [0] * (N + 1) -    minhp = a[:N] +    ps = [sum(a[:n])] +    minhp = a[:n] -    for i in range(1, N + 1): -        heappush(minhp, a[N - 1 + i]) +    for i in range(n): +        heappush(minhp, a[n + i]) -        psmin[i] = psmin[i - 1] + x -    psmax = [0] * (N + 1) -    maxhp = [-ai for ai in a[2 * N :]] +        ps.append(ps[-1] + a[n + i] - x) +    ss = [sum(a[2 * n :])] +    maxhp = [-ai for ai in a[2 * n :]] -    for i in range(1, N + 1): -        heappush(maxhp, -a[2 * N - i]) +    for i in range(n): +        heappush(maxhp, -a[2 * n - 1 - i]) -        psmax[i] = psmax[i - 1] + x -    # print(psmin) -    # print(psmax) +        ss.append(ss[-1] + a[2 * n - 1 - i] - x) -    for i in range(0, N + 1): -        # print(ps[N + i], psmin[i], ps[3*N] - ps[N + i], psmax[N - i]) -        v = (ps[N + i] - psmin[i]) - (ps[3 * N] - ps[N + i] - psmax[N - i]) -        ans = max(ans, v) +    for i in range(n + 1): +        ans = max(ans, ps[i] - ss[n - i]) -    pass