Buggy python submission (verdict: Runtime Error):
from operator import itemgetter, attrgetter
#input
n = int(input())
H = []
for i in range(n):
    a, b = map(int, input().split())
    H.append([i, a, b])

C = sorted(H, key = itemgetter(1, 2), reverse = True)
A = sorted(H, key = itemgetter(2, 1), reverse = True)
 
ans_c = 0
ans_a = 0
turn = 0
 
while H != []:
    C = sorted(H, key = itemgetter(1, 2), reverse = True)
    A = sorted(H, key = itemgetter(2, 1), reverse = True)
    if turn % 2 == 0: #chokudai 
        if C[0][1] - A[0][1] >= A[0][2] - C[0][2]:
            chokudai = C.pop(0)
        else:
            chokudai = A.pop(0)
        ans_c += chokudai[1]
        H.pop(chokudai[0])
    else: #aoki
        if A[0][2] - C[0][2] >= C[0][1] - A[0][1]:
            aoki = A.pop(0)
        else:
            aoki = C.pop(0)
        ans_a += aoki[2]
        H.pop(aoki[0])
    turn += 1
 
print(ans_c - ans_a)


Fixed submission:
#input
n = int(input())
H = []
for _ in range(n):
    a, b = map(int, input().split())
    H.append([a + b, a, b])

H = sorted(H, reverse = True)
sum_c = 0
sum_a = 0

for i in range(n):
    if i % 2 == 0:
        sum_c += H[i][1]
    else:
        sum_a += H[i][2]

ans = sum_c - sum_a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter, attrgetter
#input
n = int(input())
H = [list(map(int, input().split())) for _ in range(n)]
C = sorted(H, key = itemgetter(0), reverse = True)
A = sorted(H, key = itemgetter(1), reverse = True)

ans_c = 0
ans_a = 0
turn = 0

while C != [] and A != []:
    if turn % 2 == 0: #chokudai 
        if C[0][0] - A[0][0] >= A[0][1] - C[0][1]:
            chokudai = C.pop(0)
            ans_c += chokudai[0]
            A = sorted(C, key = itemgetter(1), reverse = True)
        else:
            chokudai = A.pop(0)
            ans_c += chokudai[0]
            C = sorted(A, key = itemgetter(0), reverse = True)
    else: #aoki
        if A[0][1] - C[0][1] >= C[0][0] - A[0][0]:
            aoki = A.pop(0)
            ans_a += aoki[1]
            C = sorted(A, key = itemgetter(0), reverse = True)
        else:
            aoki = C.pop(0)
            ans_a += aoki[1]
            A = sorted(C, key = itemgetter(1), reverse = True)
    turn += 1

print(ans_c - ans_a)


Fixed submission:
#input
n = int(input())
H = []
for _ in range(n):
    a, b = map(int, input().split())
    H.append([a + b, a, b])

H = sorted(H, reverse = True)
sum_c = 0
sum_a = 0

for i in range(n):
    if i % 2 == 0:
        sum_c += H[i][1]
    else:
        sum_a += H[i][2]

ans = sum_c - sum_a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter, attrgetter
#input
n = int(input())
H = [list(map(int, input().split())) for _ in range(n)]
C = sorted(H, key = itemgetter(0), reverse = True)
A = sorted(H, key = itemgetter(1), reverse = True)

ans_c = 0
ans_a = 0
turn = 0

while C != [] and A != []:
    if turn % 2 == 0: #chokudai 
        if C[0][0] - A[0][0] >= A[0][1] - C[0][1]:
            chokudai = C.pop(0)
            ans_c += chokudai[0]
            A = sorted(C, key = itemgetter(1), reverse = True)
        else:
            chokudai = A.pop(0)
            ans_c += chokudai[0]
            C = sorted(A, key = itemgetter(0), reverse = True)
    else: #aoki
        if A[0][1] - C[0][1] >= C[0][0] - A[0][0]:
            aoki = A.pop(0)
            ans_a += aoki[1]
            C = sorted(A, key = itemgetter(1), reverse = True)
        else:
            aoki = C.pop(0)
            ans_a += aoki[1]
            A = sorted(C, key = itemgetter(1), reverse = True)
    turn += 1

print(ans_c - ans_a)


Fixed submission:
#input
n = int(input())
H = []
for _ in range(n):
    a, b = map(int, input().split())
    H.append([a + b, a, b])

H = sorted(H, reverse = True)
sum_c = 0
sum_a = 0

for i in range(n):
    if i % 2 == 0:
        sum_c += H[i][1]
    else:
        sum_a += H[i][2]

ans = sum_c - sum_a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter, attrgetter
#input
n = int(input())
H = [list(map(int, input().split())) for _ in range(n)]
C = sorted(H, key = itemgetter(0, 1), reverse = True)
A = sorted(H, key = itemgetter(1, 0), reverse = True)

ans_c = 0
ans_a = 0
turn = 0

while C != [] and A != []:
    if turn % 2 == 0: #chokudai 
        if C[0][0] - A[0][0] >= A[0][1] - C[0][1]:
            chokudai = C.pop(0)
            ans_c += chokudai[0]
            A = sorted(C, key = itemgetter(1, 0), reverse = True)
        else:
            chokudai = A.pop(0)
            ans_c += chokudai[0]
            C = sorted(A, key = itemgetter(0, 1), reverse = True)
    else: #aoki
        if A[0][1] - C[0][1] >= C[0][0] - A[0][0]:
            aoki = A.pop(0)
            ans_a += aoki[1]
            C = sorted(A, key = itemgetter(0, 1), reverse = True)
        else:
            aoki = C.pop(0)
            ans_a = aoki[1]
            A = sorted(C, key = itemgetter(1, 0), reverse = True)
    turn += 1

print(ans_c - ans_a)


Fixed submission:
#input
n = int(input())
H = []
for _ in range(n):
    a, b = map(int, input().split())
    H.append([a + b, a, b])

H = sorted(H, reverse = True)
sum_c = 0
sum_a = 0

for i in range(n):
    if i % 2 == 0:
        sum_c += H[i][1]
    else:
        sum_a += H[i][2]

ans = sum_c - sum_a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter, attrgetter
#input
n = int(input())
H = [list(map(int, input().split())) for _ in range(n)]
C = sorted(H, key = itemgetter(0, 1), reverse = True)
A = sorted(H, key = itemgetter(1, 0), reverse = True)

ans_c = 0
ans_a = 0
turn = 0

while H != []:
    C = sorted(H, key = itemgetter(0, 1), reverse = True)
    A = sorted(H, key = itemgetter(1, 0), reverse = True)
    if turn % 2 == 0: #chokudai 
        if C[0][0] - A[0][0] >= A[0][1] - C[0][1]:
            chokudai = C.pop(0)
        else:
            chokudai = A.pop(0)
        ans_c += chokudai[0]
        H.remove(chokudai)
    else: #aoki
        if A[0][1] - C[0][1] >= C[0][0] - A[0][0]:
            aoki = A.pop(0)
        else:
            aoki = C.pop(0)
        ans_a += aoki[1]
        H.remove(aoki)
    turn += 1

print(ans_c - ans_a)


Fixed submission:
#input
n = int(input())
H = []
for _ in range(n):
    a, b = map(int, input().split())
    H.append([a + b, a, b])

H = sorted(H, reverse = True)
sum_c = 0
sum_a = 0

for i in range(n):
    if i % 2 == 0:
        sum_c += H[i][1]
    else:
        sum_a += H[i][2]

ans = sum_c - sum_a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter, attrgetter
#input
n = int(input())
H = [list(map(int, input().split())) for _ in range(n)]
C = sorted(H, key = itemgetter(0, 1), reverse = True)
A = sorted(H, key = itemgetter(1, 0), reverse = True)

ans_c = 0
ans_a = 0

while C != []:
    if C[0][0] - A[0][0] >= A[0][1] - C[0][1]:
        chokudai = C.pop(0)
        ans_c += chokudai[0]
        A.remove(chokudai)
    else:
        chokudai = A.pop(0)
        ans_c += chokudai[0]
        C.remove(chokudai)
    if C == []:
        print(ans_c - ans_a)
        exit()
    if A[0][1] - C[0][1] >= C[0][0] - A[0][0]:
        aoki = A.pop(0)
        ans_a += aoki[1]
        C.remove(aoki)
    else:
        aoki = C.pop(0)
        ans_a += aoki[1]
        A.remove(aoki)
    if C == []:
        print(ans_c - ans_a)
        exit()

Fixed submission:
#input
n = int(input())
H = []
for _ in range(n):
    a, b = map(int, input().split())
    H.append([a + b, a, b])

H = sorted(H, reverse = True)
sum_c = 0
sum_a = 0

for i in range(n):
    if i % 2 == 0:
        sum_c += H[i][1]
    else:
        sum_a += H[i][2]

ans = sum_c - sum_a
print(ans)