Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
D.sort(reverse=True)

A=0
B=0
while D!=[]:
  A+=D[0][0]
  D.pop(0)
  if D==[]:
    break
  tmp=max(D, key=lambda x:x[1])
  B+=tmp[1]
  D.remove(tmp)
  
print(A-B)

Fixed submission:
N = int(input())
D=[]
b=0
for _ in range(N):
  A,B=map(int, input().split())
  D.append([A,B,A+B])
  b+=B
D.sort(reverse=True, key=lambda x:x[2])

ans=0
while D!=[]:
  ans+=D[0][2]
  D.pop(0)
  if D!=[]:
    D.pop(0)
  
print(ans-b)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
D.sort(reverse=True)

A=0
B=0
for i in range(N):
  if i%2==0:
    A+=D[0][0]
    D.pop(0)
  else:
    tmp=max(D, key=lambda x:x[1])
    B+=tmp[1]
    D.remove(tmp)
  
print(A-B)

Fixed submission:
N = int(input())
D=[]
b=0
for _ in range(N):
  A,B=map(int, input().split())
  D.append([A,B,A+B])
  b+=B
D.sort(reverse=True, key=lambda x:x[2])

ans=0
while D!=[]:
  ans+=D[0][2]
  D.pop(0)
  if D!=[]:
    D.pop(0)
  
print(ans-b)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
A=0
B=0
for i in range(N):
  if i%2==0:
    D.sort(reverse=True)
    A+=D[0][0]
    D.pop(0)
  else:
    D.sort(reverse=True, key=lambda x:x[1])
    B+=D[0][1]
    D.pop(0)
  
print(A-B)

Fixed submission:
N = int(input())
D=[]
b=0
for _ in range(N):
  A,B=map(int, input().split())
  D.append([A,B,A+B])
  b+=B
D.sort(reverse=True, key=lambda x:x[2])

ans=0
while D!=[]:
  ans+=D[0][2]
  D.pop(0)
  if D!=[]:
    D.pop(0)
  
print(ans-b)

Buggy python submission (verdict: Time Limit Exceeded):
def res(D, p):
    if len(D)==1:
      return D[0][p] if p==0 else -D[0][p]
    else:
      m=max(D, key=lambda x:x[p])
      tmp=[d for d in D if d[p]==m[p]]
      t=max(tmp, key=lambda x:x[abs(p-1)])
      D.remove(t)
      return res(D, abs(p-1)) + (t[p] if p==0 else -t[p])
      
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
  
print(res(D, 0))



Fixed submission:
N = int(input())
D=[]
b=0
for _ in range(N):
  A,B=map(int, input().split())
  D.append([A,B,A+B])
  b+=B
D.sort(reverse=True, key=lambda x:x[2])

ans=0
while D!=[]:
  ans+=D[0][2]
  D.pop(0)
  if D!=[]:
    D.pop(0)
  
print(ans-b)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]

A=0
B=0
for i in range(N):
  if i%2==0:
    m=max(D, key=lambda x:x[0])
    tmp=[d for d in D if d[0]==m[0]]
    t=max(tmp, key=lambda x:x[1])
    A+=t[0]
    D.remove(t)
  else:
    m=max(D, key=lambda x:x[1])
    tmp=[d for d in D if d[1]==m[1]]
    t=max(tmp, key=lambda x:x[0])
    B+=t[1]
    D.remove(t)
  
print(A-B)

Fixed submission:
N = int(input())
D=[]
b=0
for _ in range(N):
  A,B=map(int, input().split())
  D.append([A,B,A+B])
  b+=B
D.sort(reverse=True, key=lambda x:x[2])

ans=0
while D!=[]:
  ans+=D[0][2]
  D.pop(0)
  if D!=[]:
    D.pop(0)
  
print(ans-b)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]

A=0
B=0
for i in range(N):
  if i%2==0:
    D.sort(reverse=True, key=lambda x:x[0])
    tmp=[d for d in D if d[0]==D[0][0]]
    tmp.sort(reverse=True, key=lambda x:x[1])
    A+=tmp[0][0]
    D.remove(tmp[0])
  else:
    D.sort(reverse=True, key=lambda x:x[1])
    tmp=[d for d in D if d[1]==D[0][1]]
    tmp.sort(reverse=True, key=lambda x:x[0])
    B+=tmp[0][1]
    D.remove(tmp[0])
  
print(A-B)

Fixed submission:
N = int(input())
D=[]
b=0
for _ in range(N):
  A,B=map(int, input().split())
  D.append([A,B,A+B])
  b+=B
D.sort(reverse=True, key=lambda x:x[2])

ans=0
while D!=[]:
  ans+=D[0][2]
  D.pop(0)
  if D!=[]:
    D.pop(0)
  
print(ans-b)