Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = list(map(int, input().split()))
L = sorted(A[:2*N])
sumL = sum(L[N:])
R = sorted(A[N:])
sumR = sum(R[:N])
AL = [sumL]
p = N
BL = [True] * (2*N)
for a in reversed(A[N:2*N]):  # sumLはだんだん減る
    ind = bisect.bisect_left(L, a)
    while BL[ind] == False:
        ind += 1
    if ind >= p:
        sumL -= L[ind]
        p -= 1
        while BL[p] == False:
            p -= 1
        sumL += L[p]
    AL.append(sumL)
    BL[ind] = False
AR = [sumR]
p = N-1
BR = [True] * (2*N)
for a in A[N:2*N]:  # sumRはだんだん増える
    ind = bisect.bisect_left(R, a)
    while BR[ind] == False:
        ind += 1
    if ind <= p:
        sumR -= R[ind]
        p += 1
        while BR[p] == False:
            p += 1
        sumR += R[p]
    AR.append(sumR)
    BR[ind] = False
AL.reverse()
C = [AL[i] - AR[i] for i in range(N+1)]
print(max(C))


Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
L = sorted(A[:2*N])
sumL = sum(L[N:])
R = sorted(A[N:])
sumR = sum(R[:N])
AL = [sumL]
p = N
BL = [False] * (2*N)
for a in reversed(A[N:2*N]):  # sumLはだんだん減る
    ind = bisect.bisect_left(L, a)
    if BL[ind] != False:
        BL[ind] += 1
        ind += BL[ind] - 1
    if ind >= p:
        sumL -= L[ind]
        p -= 1
        while BL[p] != False:
            p -= 1
        sumL += L[p]
    AL.append(sumL)
    BL[ind] = 1
AR = [sumR]
p = N-1
BR = [False] * (2*N)
for a in A[N:2*N]:  # sumRはだんだん増える
    ind = bisect.bisect_left(R, a)
    if BR[ind] != False:
        BR[ind] += 1
        ind += BR[ind] - 1
    if ind <= p:
        sumR -= R[ind]
        p += 1
        while BR[p] != False:
            p += 1
        sumR += R[p]
    AR.append(sumR)
    BR[ind] = 1
AL.reverse()
C = [AL[i] - AR[i] for i in range(N+1)]
print(max(C))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = list(map(int, input().split()))
L = sorted(A[:2*N])
sumL = sum(L[N:])
R = sorted(A[N:])
sumR = sum(R[:N])
AL = [sumL]
p = N
BL = [True] * (2*N)
for a in reversed(A[N:2*N]):  # sumLはだんだん減る
    ind = bisect.bisect_left(L, a)
    while BL[ind] == False:
        ind += 1
    if ind >= p:
        sumL -= L[ind]
        p -= 1
        while BL[p] == False:
            p -= 1
        sumL += L[p]
    AL.append(sumL)
    BL[ind] = False
AR = [sumR]
p = N-1
BR = [True] * (2*N)
for a in A[N:2*N]:  # sumRはだんだん増える
    ind = bisect.bisect_left(R, a)
    while BR[ind] == False:
        ind += 1
    if ind <= p:
        sumR -= R[ind]
        p += 1
        while BR[p] == False:
            p += 1
        sumR += R[p]
    AR.append(sumR)
    BR[ind] = False
AL.reverse()
C = [AL[i] - AR[i] for i in range(N+1)]
print(max(C))


Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
L = sorted(A[:2*N])
sumL = sum(L[N:])
R = sorted(A[N:])
sumR = sum(R[:N])
AL = [sumL]
p = N
BL = [False] * (2*N)
for a in reversed(A[N:2*N]):  # sumLはだんだん減る
    ind = bisect.bisect_left(L, a)
    if BL[ind] != False:
        BL[ind] += 1
        ind += BL[ind] - 1
    if ind >= p:
        sumL -= L[ind]
        p -= 1
        while BL[p] != False:
            p -= 1
        sumL += L[p]
    AL.append(sumL)
    BL[ind] = 1
AR = [sumR]
p = N-1
BR = [False] * (2*N)
for a in A[N:2*N]:  # sumRはだんだん増える
    ind = bisect.bisect_left(R, a)
    if BR[ind] != False:
        BR[ind] += 1
        ind += BR[ind] - 1
    if ind <= p:
        sumR -= R[ind]
        p += 1
        while BR[p] != False:
            p += 1
        sumR += R[p]
    AR.append(sumR)
    BR[ind] = 1
AL.reverse()
C = [AL[i] - AR[i] for i in range(N+1)]
print(max(C))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = list(map(int, input().split()))
L = sorted(A[:2*N])
sumL = sum(L[N:])
R = sorted(A[N:])
sumR = sum(R[:N])
AL = [sumL]
p = N
BL = [True] * (2*N)
for a in reversed(A[N:2*N]):  # sumLはだんだん減る
    ind = bisect.bisect_left(L, a)
    while BL[ind] == False:
        ind += 1
    if ind >= p:
        sumL -= L[ind]
        p -= 1
        while BL[p] == False:
            p -= 1
        sumL += L[p]
    AL.append(sumL)
    BL[ind] = False
AR = [sumR]
p = N-1
BR = [True] * (2*N)
for a in A[N:2*N]:  # sumRはだんだん増える
    ind = bisect.bisect_left(R, a)
    while BR[ind] == False:
        ind += 1
    if ind <= p:
        sumR -= R[ind]
        p += 1
        while BR[p] == False:
            p += 1
        sumR += R[p]
    AR.append(sumR)
    BR[ind] = False
AL.reverse()
C = [AL[i] - AR[i] for i in range(N+1)]
print(max(C))


Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
L = sorted(A[:2*N])
sumL = sum(L[N:])
R = sorted(A[N:])
sumR = sum(R[:N])
AL = [sumL]
p = N
BL = [False] * (2*N)
for a in reversed(A[N:2*N]):  # sumLはだんだん減る
    ind = bisect.bisect_left(L, a)
    if BL[ind] != False:
        BL[ind] += 1
        ind += BL[ind] - 1
    if ind >= p:
        sumL -= L[ind]
        p -= 1
        while BL[p] != False:
            p -= 1
        sumL += L[p]
    AL.append(sumL)
    BL[ind] = 1
AR = [sumR]
p = N-1
BR = [False] * (2*N)
for a in A[N:2*N]:  # sumRはだんだん増える
    ind = bisect.bisect_left(R, a)
    if BR[ind] != False:
        BR[ind] += 1
        ind += BR[ind] - 1
    if ind <= p:
        sumR -= R[ind]
        p += 1
        while BR[p] != False:
            p += 1
        sumR += R[p]
    AR.append(sumR)
    BR[ind] = 1
AL.reverse()
C = [AL[i] - AR[i] for i in range(N+1)]
print(max(C))

Buggy python submission (verdict: Runtime Error):
import bisect
N = int(input())
A = list(map(int, input().split()))

L = sorted(A[:2*N])
sumL = sum(L[N:])
R = sorted(A[N:])
sumR = sum(R[:N])

AL = [sumL]
p = N
for a in reversed(A[N:2*N]):  # sumLはだんだん減る
    ind = bisect.bisect_left(L, a)
    if ind >= p:
        sumL -= L[ind]
        p -= 1
        while L[p] == False:
            p -= 1
        sumL += L[p]
    AL.append(sumL)
    L[ind] = False
AR = [sumR]
p = N-1
for a in A[N:2*N]:  # sumRはだんだん増える
    ind = bisect.bisect_left(R, a)
    if ind <= p:
        sumR -= R[ind]
        p += 1
        while R[p] == False:
            p += 1
        sumR += R[p]
    AR.append(sumR)
    R[ind] = False
AL.reverse()
C = [AL[i] - AR[i] for i in range(N+1)]
print(max(C))


Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
L = sorted(A[:2*N])
sumL = sum(L[N:])
R = sorted(A[N:])
sumR = sum(R[:N])
AL = [sumL]
p = N
BL = [False] * (2*N)
for a in reversed(A[N:2*N]):  # sumLはだんだん減る
    ind = bisect.bisect_left(L, a)
    if BL[ind] != False:
        BL[ind] += 1
        ind += BL[ind] - 1
    if ind >= p:
        sumL -= L[ind]
        p -= 1
        while BL[p] != False:
            p -= 1
        sumL += L[p]
    AL.append(sumL)
    BL[ind] = 1
AR = [sumR]
p = N-1
BR = [False] * (2*N)
for a in A[N:2*N]:  # sumRはだんだん増える
    ind = bisect.bisect_left(R, a)
    if BR[ind] != False:
        BR[ind] += 1
        ind += BR[ind] - 1
    if ind <= p:
        sumR -= R[ind]
        p += 1
        while BR[p] != False:
            p += 1
        sumR += R[p]
    AR.append(sumR)
    BR[ind] = 1
AL.reverse()
C = [AL[i] - AR[i] for i in range(N+1)]
print(max(C))