Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
L=[]
S=[]
for i in range(N):
    x = input()
    l=[y for y in x]
    L.append(l)
for i in range(M):
    x = input()
    s=[y for y in x]
    S.append(s)
flag = 0
sum = 0
for i in range(N):
    for j in range(N):
        for k in range(M):
            for l in range(M):
                if i+k < N and j+l < N:
                    if L[i+k][j+l] == S[k][l]:
                        sum += 1
                        if sum == M * M:
                            flag = 1
                    else:
                        sum = 0
if flag == 0:
    print("No")
else:
    print("Yes")


Fixed submission:
table=[2,3,4,5,6,7,8,9,10,11,12,13,1]
a,b=map(int,input().split())
if a == b :
    print("Draw")
elif table.index(a) < table.index(b):
    print("Bob")
elif table.index(a) > table.index(b):
    print("Alice")

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
L=[]
S=[]
for i in range(N):
    x = input()
    l=[y for y in x]
    L.append(l)
for i in range(M):
    x = input()
    s=[y for y in x]
    S.append(s)
flag = 0
sum = 0
for i in range(N):
    for j in range(N):
        for k in range(M):
            for l in range(M):
                if i+k < N and j+l < N:
                    if L[i+k][j+l] == S[k][l]:
                        sum += 1
                        if sum == M * M:
                            flag = 1
                    else:
                        sum = 0
if flag == 0:
    print("No")
else:
    print("Yes")

Fixed submission:
table=[2,3,4,5,6,7,8,9,10,11,12,13,1]
a,b=map(int,input().split())
if a == b :
    print("Draw")
elif table.index(a) < table.index(b):
    print("Bob")
elif table.index(a) > table.index(b):
    print("Alice")

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
L=[]
S=[]
for i in range(N):
    x = input()
    l=[y for y in x]
    L.append(l)
for i in range(M):
    x = input()
    s=[y for y in x]
    S.append(s)
flag = 0
sum = 0
for i in range(N):
    for j in range(N):
        for k in range(M):
            for l in range(M):
                if i+k < N and j+l < N:
                    if L[i+k][j+l] == S[k][l]:
                        sum += 1
                        if sum == M * M:
                            flag = 1
                    else:
                        sum = 0
if flag == 0:
    print("No")
else:
    print("Yes")
remote@deb465:~/pyt

Fixed submission:
table=[2,3,4,5,6,7,8,9,10,11,12,13,1]
a,b=map(int,input().split())
if a == b :
    print("Draw")
elif table.index(a) < table.index(b):
    print("Bob")
elif table.index(a) > table.index(b):
    print("Alice")
Buggy python submission (verdict: Runtime Error):
const = 10 ** 9 + 7
N = int(input())
TABLE = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]T = []
ans = 1
for x in TABLE:
    L = []
    for i in range(1,N + 1):
        count = 0
        while i % x == 0:
            i /= x
            count += 1
        L.append(count)
    T.append(sum(L)+1)
#print(T)
for x in T:
    ans *= x
print(ans % const)

Fixed submission:
const = 10 ** 9 + 7
N = int(input())
TABLE = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997]
T = []
ans = 1
for x in TABLE:
    L = []
    for i in range(1,N + 1):
        count = 0
        while i % x == 0:
            i /= x
            count += 1
        L.append(count)
    T.append(sum(L)+1)
#print(T)
for x in T:
    ans *= x
print(ans % const)
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(input())
    ans = []

    for i in range(N, 0, -1):
        sm = 0
        elems = []
        for k in range(i, 0, -1):
            if sm + k <= N:
                sm += k
                elems.append(k)
                if sm == N:
                    ans = elems
    print(*ans,sep='\n')

if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    N = int(input())
    ans = []

    left = 0
    right = N + 1
    while right - left > 1:
        mid = (left + right) // 2
        success, elems = calcElements(mid, N)
        if success:
            ans = elems
            right = mid
        else:
            left = mid
    print(*ans,sep='\n')

def calcElements(max_value, N):
    sm = 0
    elems = []
    for k in range(max_value, 0, -1):
        if sm + k <= N:
            sm += k
            elems.append(k)
            if sm == N:
                return (True, elems)
    
    return (False, elems)

if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(input())
    ans = []

    for i in range(N, 0, -1):
        sm = 0
        elems = []
        for k in range(i, 0, -1):
            if sm + k <= N:
                sm += k
                elems.append(k)
                if sm == N:
                    ans = elems
    print(*ans,sep='\n')

if __name__ == '__main__':
    solve()

Fixed submission:
def solve():
    N = int(input())
    ans = []

    left = 0
    right = N + 1
    while right - left > 1:
        mid = (left + right) // 2
        success, elems = calcElements(mid, N)
        if success:
            ans = elems
            right = mid
        else:
            left = mid
    print(*ans,sep='\n')

def calcElements(max_value, N):
    sm = 0
    elems = []
    for k in range(max_value, 0, -1):
        if sm + k <= N:
            sm += k
            elems.append(k)
            if sm == N:
                return (True, elems)
    
    return (False, elems)

if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Runtime Error):
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            #ここで起点(左上)nowx, nowy として　 9マスに着目する
            name = str(nowx) + ' '  +str(nowy)
            if name in cand : cand[name] += 1
            else: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    ans[x] += 1
    tmp -= 1
ans[0] = tmp
for x in ans:
    print(x)


Fixed submission:
a = int(input())
b = int(input())
c = int(input())

print((a+b)*c//2)
Buggy python submission (verdict: Runtime Error):
N  = int(input())

print((1+N)(N)//2)

Fixed submission:
N  = int(input())
ans = 0
for i in range(N+1):
  ans += i
print(ans)

Buggy python submission (verdict: Runtime Error):
N  = input()
ans = 0
for i in range(N+1):
  ans += i
print(ans)

Fixed submission:
N  = int(input())
ans = 0
for i in range(N+1):
  ans += i
print(ans)
Buggy python submission (verdict: Runtime Error):
S = list(input())
ans = []

for i in range(len(S)):
    if S[i] == 'B':
        if i == 0:
            pass
        else:
            del ans[-1]
        
    else:
        ans.append(S[i])

for x in ans:
    print(x,end='')
print()



Fixed submission:
S = list(input())
i = 0
while 'B' in S:
    if S[i] == 'B':
        if i == 0:
            del S[0]
            i = 0
            continue
        else:
            del S[i-1]
            del S[i-1]
            i = 0
            continue
    i += 1
for x in S:
    print(x, end='')
print()
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,inptu().split()))
ave = sum(L) / len(L)
if ave * 10 % 10 >= 5:
  ave = int(ave) + 1
else:
  ave = int(ave)
ans = 0
for x in L:
  ans += (x - ave) **2
print(ans)

Fixed submission:
N = int(input())
ans = 10**10
L = list(map(int,input().split()))
for i in range(-101,101): 
  tmp = 0
  for x in L:
    tmp += (i - x) ** 2
  ans = min(ans,tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
L = list(map(int,input().split()))
for i in range(N,100000):
    flag = 0
    for x in str(i):
        if int(x) in L:
            flag = 1
    if flag == 0:
        print(i)
        exit()

Fixed submission:
L=list(map(int,input().split()))
table=[5,5,7]
L=sorted(L)
if table == L:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
L=list(map(int,input().split()))
table=[5,5,7]
L=soretd(L)
if table == L:
  print("YES")
else:
  print("NO")


Fixed submission:
L=list(map(int,input().split()))
table=[5,5,7]
L=sorted(L)
if table == L:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
L=map(int,input().split())
table=[5,5,7]
L=soretd(L)
if table == L:
  print("YES")
else:
  print("NO")


Fixed submission:
L=list(map(int,input().split()))
table=[5,5,7]
L=sorted(L)
if table == L:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
L=amp(int,input().split())
table=[5,5,7]
L=soretd(L)
if table == L:
  print("YES")
else:
  print("NO")

Fixed submission:
L=list(map(int,input().split()))
table=[5,5,7]
L=sorted(L)
if table == L:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
import numpy as np
print(char(ord(input()[0])+1))

Fixed submission:
print(chr(ord(input()[0])+1))
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,input().split())
PS = (input().split() for _ in range(N))

ac = [False] * N
wa_cnt = [0] * N
penal = 0
for P,S in PS:
    p = int(P)-1
    if ac[p]:
        pass
    elif S == b'WA':
        wa_cnt[p] += 1
    else:
        ac[p] = True
        penal += wa_cnt[p]

ac = sum(ac)
print(ac, penal)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
PS = (line.split() for line in readlines())

ac = [False] * N
wa_cnt = [0] * N
penal = 0
for P,S in PS:
    p = int(P)-1
    if ac[p]:
        pass
    elif S == b'WA':
        wa_cnt[p] += 1
    else:
        ac[p] = True
        penal += wa_cnt[p]

ac = sum(ac)
print(ac, penal)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    points = [[0 for _ in range(w)] for _ in range(h)]

    for i in range(h):
        left = 0
        for j in range(w):
            if field[i][j] == '#':
                for k in range(left, j):
                    points[i][k] += j-left
                left = j+1
                continue
        for k in range(left, w):
            points[i][k] += w-left

    #print("\n".join(str(point) for point in points))
    for j in range(w):
        up = 0
        for i in range(h):
            if field[i][j] == '#':
                for k in range(up, i):
                    points[k][j] += i-up
                up = i+1
                continue
        for k in range(up, h):
            points[k][j] += h-up

    psoudo_ans = max(max(line) for line in points)
    print(max(0, psoudo_ans-1))
    #print("\n".join(str(point) for point in points))


main()

Fixed submission:
def main():
    h, w = map(int, input().split())

    field = [input() for _ in range(h)]

    points = [[0 for _ in range(w)] for _ in range(h)]

    for i in range(h):
        left = 0
        for j in range(w):
            if field[i][j] == '#':
                for k in range(left, j):
                    points[i][k] += j-left
                left = j+1
                continue
        for k in range(left, w):
            points[i][k] += w-left

    #print("\n".join(str(point) for point in points))
    for j in range(w):
        up = 0
        for i in range(h):
            if field[i][j] == '#':
                for k in range(up, i):
                    points[k][j] += i-up
                up = i+1
                continue
        for k in range(up, h):
            points[k][j] += h-up

    psoudo_ans = max(max(line) for line in points)
    print(max(0, psoudo_ans-1))
    #print("\n".join(str(point) for point in points))


main()
Buggy python submission (verdict: Runtime Error):
def main():
    m, k = map(int, input().split())
    maximum = 2 ** m - 1

    if k==0:
        print(" ".join(map(str, range(0, maximum+1))), end=" ")
        print(" ".join(map(str, range(maximum, -1, -1))))
        return

    if m==1:
        print(-1)
        return

    if maximum < k:
        print(-1)
        return

    other_than_k = [i for i in range(1, maximum+1) if i!=k]
    print(" ".join(map(str, other_than_k[2:])), end=" ")
    print(other_than_k[0], k, other_than_k[0], other_than_k[1], k, other_than_k[1], end=" ")
    print(" ".join(reversed(map(str, other_than_k[2:]))))

main()

Fixed submission:
def main():
    m, k = map(int, input().split())
    maximum = 2 ** m - 1

    if k==0:
        print(" ".join(map(str, range(0, maximum+1))), end=" ")
        print(" ".join(map(str, range(maximum, -1, -1))))
        return

    if m==1:
        print(-1)
        return

    if maximum < k:
        print(-1)
        return

    others = [i for i in range(1, maximum+1) if i!=k]
    print(0, k, 0, end=" ")
    print(" ".join(map(str, others)), k, " ".join(map(str, reversed(others))))


main()
Buggy python submission (verdict: Runtime Error):
import string

n, q = map(int, input().split())
s = input()
tds = list(tuple(input().split()) for _ in range(q))

left = 0
right = n-1

for t, d in reversed(tds):
    if d=="L":
        if t==s[left]:
            left += 1
    if d=="R":
        if t==s[right]:
            right -= 1

print(right - left + 1)


Fixed submission:
n, q = map(int, input().split())
s = input()
tds = list(tuple(input().split()) for _ in range(q))

left = 0
right = n-1

for t, d in reversed(tds):
    if d=="L":
        if t==s[left]:
            left = left+1
            if left > n-1:
                right = 0
                left = n-1
                break
        if right < n-1 and t==s[right+1]:
            right = min(right+1, n-1)

    if d=="R":
        if t==s[right]:
            right = right-1
            if 0 > right:
                right = 0
                left = n-1
                break
        if left > 0 and t==s[left-1]:
            left = max(left-1, 0)

print(max(right - left + 1, 0))
Buggy python submission (verdict: Runtime Error):
n = int(input())
xys = [tuple(map(int, input().split())) for _ in range(n-1)]

neighbors = [[] for _ in range(n)]

for x, y in xys:
    neighbors[x-1].append(y-1)
    neighbors[y-1].append(x-1)

froms = [-1 for _ in range(n)]

froms[0] = -2

def f(x):
    for y in neighbors[x]:
        if froms[y]==-1 :
            froms[y] = x
            f(y)

f(0)

path = [n-1]
while path[-1]!=0:
    if froms[path[-1]]==-1:
        break
    path.append(froms[path[-1]])
path.reverse()

blacks_l = path[:(len(path)+1)//2]
blacks = set(blacks_l)
whites = set(path[(len(path)+1)//2:])

def fennec(x):
    for y in neighbors[x]:
        if not y in blacks and not y in whites:
            blacks.add(y)
            fennec(y)

for b in blacks_l:
    fennec(b)

if len(blacks) > n-len(blacks):
    print('Fennec')
else:
    print('Snuke')

Fixed submission:
import sys

sys.setrecursionlimit(100000000)

n = int(input())
xys = [tuple(map(int, input().split())) for _ in range(n-1)]

neighbors = [[] for _ in range(n)]

for x, y in xys:
    neighbors[x-1].append(y-1)
    neighbors[y-1].append(x-1)

froms = [-1 for _ in range(n)]

froms[0] = -2

def f(x):
    for y in neighbors[x]:
        if froms[y]==-1 :
            froms[y] = x
            f(y)

f(0)

path = [n-1]
while path[-1]!=0:
    if froms[path[-1]]==-1:
        break
    path.append(froms[path[-1]])
path.reverse()

blacks_l = path[:(len(path)+1)//2]
blacks = set(blacks_l)
whites = set(path[(len(path)+1)//2:])

def fennec(x):
    for y in neighbors[x]:
        if not y in blacks and not y in whites:
            blacks.add(y)
            fennec(y)

for b in blacks_l:
    fennec(b)

if len(blacks) > n-len(blacks):
    print('Fennec')
else:
    print('Snuke')
Buggy python submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, size):
        self.parents = list(range(size))

    def find(self, i):
        ret = i
        path = []
        while self.parents[ret]!=ret:
            path.append(ret)
            ret = self.parents[ret]
        for p in path:
            self.parents[p] = ret
        return ret

    def union(self, i, j):
        self.parents[self.find(i)] = j

n = int(input())
xys = [(*map(int, input().split()), i) for i in range(n)]

sortx = sorted(xys, key=lambda xy: xy[0])
roadsx = [(sortx[i][0]-sortx[i-1][0], sortx[i][2], sortx[i-1][2]) for i in range(1, n)]
sorty = sorted(xys, key=lambda xy: xy[1])
roadsy = [(sorty[i][1]-sorty[i-1][1], sorty[i][2], sorty[i-1][2]) for i in range(1, n)]
roads = roadsx + roadsy
roads.sort(key=lambda x:x[0])

ctr = 1
ans = 0
uf = UnionFind(n)
for road in roads:
    if ctr >= n:
        break
    cost, i1, i2 = road
    if uf.find(i1) != uf.find(i2):
        ans += cost
        ctr += 1
        uf.union(i1, i2)

print(ans)

Fixed submission:
class UnionFind:
    def __init__(self, size):
        self.parents = list(range(size))

    def find(self, i):
        ret = i
        path = []
        while self.parents[ret]!=ret:
            path.append(ret)
            ret = self.parents[ret]
        for p in path:
            self.parents[p] = ret
        return ret

    def union(self, i, j):
        self.parents[self.find(i)] = j

n = int(input())
xys = [(tuple(map(int, input().split())), i) for i in range(n)]

sortx = sorted(xys, key=lambda xy: xy[0][0])
roadsx = [(sortx[i][0][0]-sortx[i-1][0][0], sortx[i][1], sortx[i-1][1]) for i in range(1, n)]
sorty = sorted(xys, key=lambda xy: xy[0][1])
roadsy = [(sorty[i][0][1]-sorty[i-1][0][1], sorty[i][1], sorty[i-1][1]) for i in range(1, n)]
roads = roadsx + roadsy
roads.sort(key=lambda x:x[0])

ctr = 1
ans = 0
uf = UnionFind(n)
for road in roads:
    if ctr >= n:
        break
    cost, i1, i2 = road
    if uf.find(i1) != uf.find(i2):
        ans += cost
        ctr += 1
        uf.union(i1, i2)

print(ans)
Buggy python submission (verdict: Runtime Error):
import math

n, a, b = map(int, input().split())
hs = list(map(int, (input() for _ in range(n))))

m = sum(hs) // (a + (n-1)*b) - 10
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b) / (a-b))) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)

Fixed submission:
n = int(input())
ss = list(map(int, (input() for _ in range(n))))

full = sum(ss)
non0s = list(s for s in ss if s%10!=0)

if full%10!=0:
    print(full)
else:
    if len(non0s)==0:
        print(0)
    else:
        print(full - min(non0s))

Buggy python submission (verdict: Runtime Error):
import heapq
from collections import Counter
import math

n, a, b = map(int, input().split())
hs = map(int, (input() for _ in range(n)))
counter = [[-x, c] for x, c in Counter(hs).items()]

cum = 0
p = 0

heapq.heapify(counter)

def f(m, c, a, b):
    ans = 0
    ans += math.floor(m / (a + b*(c-1))) * c
    m -= math.floor(m / (a + b*(c-1))) * (a + b*(c-1))
    ans += min(math.ceil(m / b), math.ceil(m / (a + b*(c-1)))*c)
    return ans

while(True):
    x, y = heapq.heappop(counter)
    if len(counter) == 0:
        print(p + f(-x-cum, y, a, b))
        break
    v, _ = counter[0]
    if x==v:
        counter[0][1] += y
        continue
    m = math.ceil((v-x) / (a-b))
    if (-x) - (m*a + m*(y-1)*b + cum) <= 0 and (-v) - m*y*b <=0:
        print(p + f(-x-cum, y, a, b))
        break
    p += m*y
    cum += b*m*y
    heapq.heappush(counter, [x + m*(a-b), y])

Fixed submission:
n = int(input())
ss = list(map(int, (input() for _ in range(n))))

full = sum(ss)
non0s = list(s for s in ss if s%10!=0)

if full%10!=0:
    print(full)
else:
    if len(non0s)==0:
        print(0)
    else:
        print(full - min(non0s))
Buggy python submission (verdict: Time Limit Exceeded):
import math

n, a, b = map(int, input().split())
hs = list(map(int, (input() for _ in range(n))))

m = sum(hs) // (a + (n-1)*b)-10
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b) / (a-b))) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)


Fixed submission:
import math

n, a, b = map(int, input().split())
hs = list(map(int, (input() for _ in range(n))))

m = sum(hs) // (a + (n-1)*b) - 10
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b) / (a-b))) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)

Buggy python submission (verdict: Time Limit Exceeded):
import math

n, a, b = map(int, input().split())
hs = list(map(int, (input() for _ in range(n))))

m = 0
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b) / (a-b))) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)

Fixed submission:
import math

n, a, b = map(int, input().split())
hs = list(map(int, (input() for _ in range(n))))

m = sum(hs) // (a + (n-1)*b) - 10
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b) / (a-b))) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)
Buggy python submission (verdict: Runtime Error):
import heapq
n = int(input())
xs = list(map(int, input().split()))
head = heapq.heapify(xs[:n])
body = xs[n:2*n]
body_and_tail = sorted(xs[n:])
sum_tail = sum(body_and_tail_list[:n])
unused_tail = heapq.heapify(body_and_tail[-n:])
ans = -1000000000000000000000
temp = sum(head) - sum_tail
for b in body:
    heapq.push(head, b)
    temp = temp - heapq.pop(head) - heapq.pop(unused_tail) + 2*b
    ans = max(ans, temp)
print(ans)

Fixed submission:
import heapq
n = int(input())
xs = list(map(int, input().split()))
head = [(x, x) for x in xs[:n]]
heapq.heapify(head)
body = xs[n:-n]
tail = [(-x, x) for x in xs[-n:]]
heapq.heapify(tail)

def f(heap, body, sign, initial):
    answer = [initial]
    acc = initial
    for b in body:
        heapq.heappush(heap, (sign*b, b))
        _, x = heapq.heappop(heap)
        acc = acc + b - x
        answer.append(acc)
    return answer
 
print(max(x - y for x, y in zip(
    f(head, body, 1, sum(xs[:n])),
    f(tail, body[::-1], -1, sum(xs[-n:]))[::-1])))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
xs = list(map(int, input().split()))
ans = -100000000000000000000000000000000000000
for i in range(n+1):
    head = sorted(xs[:n+i])
    tail = sorted(xs[n+i:])
    ans = max(ans, sum(head[-n:])-sum(tail[:n]))
print(ans)

Fixed submission:
import heapq
n = int(input())
xs = list(map(int, input().split()))
head = [(x, x) for x in xs[:n]]
heapq.heapify(head)
body = xs[n:-n]
tail = [(-x, x) for x in xs[-n:]]
heapq.heapify(tail)

def f(heap, body, sign, initial):
    answer = [initial]
    acc = initial
    for b in body:
        heapq.heappush(heap, (sign*b, b))
        _, x = heapq.heappop(heap)
        acc = acc + b - x
        answer.append(acc)
    return answer
 
print(max(x - y for x, y in zip(
    f(head, body, 1, sum(xs[:n])),
    f(tail, body[::-1], -1, sum(xs[-n:]))[::-1])))