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

N = int(input())
finish = [False] * N
As, Bs = [], []
for i in range(N):
    a,b = map(int, input().split())
    # As.append((a,b,i))
    # Bs.append((b,a,i))
    heapq.heappush(As,(a,b,i))
    heapq.heappush(Bs,(b,a,i))

# cnt = 0
# As.sort(reverse=True)
# Bs.sort(reverse=True)




cnt = 0
p_a = 0
p_b = 0
while sum(finish)<N:
    # 高橋くんのターン
    while True:
        a,_,i = heapq.heappop(As)
        # a,_,i = As.pop()
        if not finish[i]:
            p_a += a
            finish[i] = True
            cnt += 1
            break
    # 青木
    while True and cnt < N:
        # b,_,i = Bs.pop()
        b,_,i = heapq.heappop(Bs)
        
        if not finish[i]:
            p_b += b
            finish[i] = True
            cnt += 1
            break
    # print(cnt,p_a,p_b)

print(p_a-p_b)


Fixed submission:
N = int(input())
ABs = []
sum_B = 0
for i in range(N):
    a,b = map(int, input().split())
    ABs.append(a+b)
    sum_B += b 
ABs.sort(reverse=True)
ans = sum(ABs[::2])-sum_B
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

N = int(input())
finish = [False] * N
As, Bs = [], []
A_,B_ = [],[]
for i in range(N):
    a,b = map(int, input().split())
    As.append((a,b,i))
    Bs.append((b,a,i))

cnt = 0
As.sort(reverse=True)
Bs.sort(reverse=True)

p_a = 0
p_b = 0
while sum(finish)<N:
    # 高橋くんのターン
    while True:
        a,_,i = As.pop()
        if not finish[i]:
            p_a += a
            finish[i] = True
            cnt += 1
            break
    # 青木
    while True and cnt < N:
        b,_,i = Bs.pop()
        if not finish[i]:
            p_b += b
            finish[i] = True
            cnt += 1
            break
    # print(cnt,p_a,p_b)

print(p_a-p_b)


Fixed submission:
N = int(input())
ABs = []
sum_B = 0
for i in range(N):
    a,b = map(int, input().split())
    ABs.append(a+b)
    sum_B += b 
ABs.sort(reverse=True)
ans = sum(ABs[::2])-sum_B
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
finish = [False] * N
As, Bs = [], []
A_,B_ = [],[]
for i in range(N):
    a,b = map(int, input().split())
    As.append((a*10**10+b,i))
    Bs.append((b*10**10+a,i))
    A_.append(a)
    B_.append(b)
from operator import itemgetter
cnt = 0
As.sort(reverse=True)
Bs.sort(reverse=True)

p_a = 0
p_b = 0
while sum(finish)<N:
    # 高橋くんのターン
    while True:
        a,i = As.pop()
        if not finish[i]:
            p_a += (a-B_[i])//10**10
            finish[i] = True
            cnt += 1
            break
    # 青木
    while True and cnt < N:
        b,i = Bs.pop()
        if not finish[i]:
            p_b += (b-A_[i])//10**10
            finish[i] = True
            cnt += 1
            break
    # print(cnt,p_a,p_b)

print(p_a-p_b)


Fixed submission:
N = int(input())
ABs = []
sum_B = 0
for i in range(N):
    a,b = map(int, input().split())
    ABs.append(a+b)
    sum_B += b 
ABs.sort(reverse=True)
ans = sum(ABs[::2])-sum_B
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
finish = [False] * N
As, Bs = [], []
for i in range(N):
    a,b = map(int, input().split())
    As.append((a,b,i))
    Bs.append((b,a,i))
from operator import itemgetter
cnt = 0
As = sorted(As, key=itemgetter(0,1),reverse=True)
Bs = sorted(Bs, key=itemgetter(0,1),reverse=True)

p_a = 0
p_b = 0
while sum(finish)<N:
    # 高橋くんのターン
    while True:
        a,_,i = As.pop()
        if not finish[i]:
            p_a += a
            finish[i] = True
            cnt += 1
            break
    # 青木
    while True and cnt < N:
        b,_,i = Bs.pop()
        if not finish[i]:
            p_b += b
            finish[i] = True
            cnt += 1
            break
    # print(cnt,p_a,p_b)

print(p_a-p_b)


Fixed submission:
N = int(input())
ABs = []
sum_B = 0
for i in range(N):
    a,b = map(int, input().split())
    ABs.append(a+b)
    sum_B += b 
ABs.sort(reverse=True)
ans = sum(ABs[::2])-sum_B
print(ans)