Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n=int(input())
a=list(map(int,input().split()))
ans=[0 for i in range(n+1)]
ans[0]=sum(a[:n])
b=a[:n]
heapq.heapify(b)
for i in range(n):
  c=heapq.heappop(b)
  if c>a[n+i]:
    heapq.heappush(b,c)
    ans[i+1]=sum(b)
  else:
    heapq.heappush(b,a[n+i])
    ans[i+1]=sum(b)
b=a[2*n:]
for i in range(n):
  b[i]=-b[i]
heapq.heapify(b)
ans[n]+=sum(b)
for i in range(n-1,-1,-1):
  c=heapq.heappop(b)
  if c>-a[n+i]:
    heapq.heappush(b,c)
    ans[i]+=sum(b)
  else:
    heapq.heappush(b,-a[n+i])
    ans[i]+=sum(b)
print(max(ans))

Fixed submission:
import heapq
n=int(input())
a=list(map(int,input().split()))
ans=[0 for i in range(n+1)]
ans[0]=sum(a[:n])
b=a[:n]
heapq.heapify(b)
sb=sum(b)
for i in range(n):
  sb+=a[n+i]
  c=heapq.heappushpop(b,a[n+i])
  sb-=c
  ans[i+1]=sb
b=a[2*n:]
for i in range(n):
  b[i]=-b[i]
heapq.heapify(b)
ans[n]+=sum(b)
sb=sum(b)
for i in range(n-1,-1,-1):
  sb-=a[n+i]
  c=heapq.heappushpop(b,-a[n+i])
  sb-=c
  ans[i]+=sb
print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))
ans=0
for i in range(n+1):
  m=0
  b1=np.sort(a[:n+i])[i:]
  b2=np.sort(a[n+i:])[:n]
  m=np.sum(b1)-np.sum(b2)
  if ans<m or i==0:
    ans=m
print(ans)

Fixed submission:
import heapq
n=int(input())
a=list(map(int,input().split()))
ans=[0 for i in range(n+1)]
ans[0]=sum(a[:n])
b=a[:n]
heapq.heapify(b)
sb=sum(b)
for i in range(n):
  sb+=a[n+i]
  c=heapq.heappushpop(b,a[n+i])
  sb-=c
  ans[i+1]=sb
b=a[2*n:]
for i in range(n):
  b[i]=-b[i]
heapq.heapify(b)
ans[n]+=sum(b)
sb=sum(b)
for i in range(n-1,-1,-1):
  sb-=a[n+i]
  c=heapq.heappushpop(b,-a[n+i])
  sb-=c
  ans[i]+=sb
print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n+1):
  m=0
  b1=sorted(a[:n+i])[i:]
  b2=sorted(a[n+i:])[:n]
  m=sum(b1)-sum(b2)
  if ans<m or i==0:
    ans=m
print(ans)

Fixed submission:
import heapq
n=int(input())
a=list(map(int,input().split()))
ans=[0 for i in range(n+1)]
ans[0]=sum(a[:n])
b=a[:n]
heapq.heapify(b)
sb=sum(b)
for i in range(n):
  sb+=a[n+i]
  c=heapq.heappushpop(b,a[n+i])
  sb-=c
  ans[i+1]=sb
b=a[2*n:]
for i in range(n):
  b[i]=-b[i]
heapq.heapify(b)
ans[n]+=sum(b)
sb=sum(b)
for i in range(n-1,-1,-1):
  sb-=a[n+i]
  c=heapq.heappushpop(b,-a[n+i])
  sb-=c
  ans[i]+=sb
print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n+1):
  m=0
  b1=a[:n+i]
  b2=a[n+i:]
  heapq.heapify(b1)
  heapq.heapify(b2)
  for j in range(i):
    b=heapq.heappop(b1)
  for j in range(n):
    b=heapq.heappop(b2)
    m-=b
  m+=sum(b1)
  if ans<m or i==0:
    ans=m
print(ans)

Fixed submission:
import heapq
n=int(input())
a=list(map(int,input().split()))
ans=[0 for i in range(n+1)]
ans[0]=sum(a[:n])
b=a[:n]
heapq.heapify(b)
sb=sum(b)
for i in range(n):
  sb+=a[n+i]
  c=heapq.heappushpop(b,a[n+i])
  sb-=c
  ans[i+1]=sb
b=a[2*n:]
for i in range(n):
  b[i]=-b[i]
heapq.heapify(b)
ans[n]+=sum(b)
sb=sum(b)
for i in range(n-1,-1,-1):
  sb-=a[n+i]
  c=heapq.heappushpop(b,-a[n+i])
  sb-=c
  ans[i]+=sb
print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n+1):
  m=0
  b1=a[:n+i]
  b2=a[n+i:]
  for j in range(len(b1)):
    b1[j]=-b1[j]
  heapq.heapify(b1)
  heapq.heapify(b2)
  for j in range(n):
    b=-heapq.heappop(b1)
    m+=b
    b=heapq.heappop(b2)
    m-=b
  if ans<m or i==0:
    ans=m
print(ans)

Fixed submission:
import heapq
n=int(input())
a=list(map(int,input().split()))
ans=[0 for i in range(n+1)]
ans[0]=sum(a[:n])
b=a[:n]
heapq.heapify(b)
sb=sum(b)
for i in range(n):
  sb+=a[n+i]
  c=heapq.heappushpop(b,a[n+i])
  sb-=c
  ans[i+1]=sb
b=a[2*n:]
for i in range(n):
  b[i]=-b[i]
heapq.heapify(b)
ans[n]+=sum(b)
sb=sum(b)
for i in range(n-1,-1,-1):
  sb-=a[n+i]
  c=heapq.heappushpop(b,-a[n+i])
  sb-=c
  ans[i]+=sb
print(max(ans))