Buggy python submission (verdict: Time Limit Exceeded):
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((abs(tmp[0] - tmp[1]), tmp[0], tmp[1]))

dishes = sorted(dishes, key=lambda x: x[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    tmp_point = -1
    dish = None
    for tmp_dish in dishes:
        if dish is None:
            dish = tmp_dish
        elif tmp_point > dish[0]:
            break
        else:
            if dish[player + 1] > tmp_dish[player + 1] and tmp_dish[player + 1] - tmp_dish[int(not player) + 1] >= 0:
                dish = tmp_dish
            else:
                pass
    dishes.remove(dish)
    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])

Fixed submission:
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((abs(tmp[0] + tmp[1]), tmp[0], tmp[1]))

dishes = sorted(dishes, key=lambda x: x[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    dish = dishes.pop(0)
    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])

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

n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((tmp[0] - tmp[1], tmp[1] - tmp[0], tmp[0], tmp[1]))

dishes = [sorted(dishes, key=itemgetter(0, 2), reverse=True), sorted(dishes, key=itemgetter(0, 3), reverse=True)]

# print(dishes[0])
# print(dishes[1])

point = [0, 0]
player = 0
while len(dishes[0]) > 0:
    dish = dishes[player].pop(0)
    # if player == 0:
    #     dish = dishes.pop(0)
    # else:
    #     dish = dishes.pop(len(dishes) - 1)

    dishes[int(not player)].remove(dish)
    # print(dish)
    point[player] += dish[player + 2]
    player = int(not player)
    # print(point)
print(point[0] - point[1])


Fixed submission:
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((abs(tmp[0] + tmp[1]), tmp[0], tmp[1]))

dishes = sorted(dishes, key=lambda x: x[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    dish = dishes.pop(0)
    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])

Buggy python submission (verdict: Runtime Error):
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((tmp[0] - tmp[1], tmp[0], tmp[1]))

sorted(dishes, key=lambda v: v[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes[0]) > 0:
    if player == 0:
        dish = dishes.pop(0)
    else:
        dish = dishes.pop(len(dishes) - 1)

    # remove dish
    dishes.remove(dish)

    point[player] += dish[player + 2]
    player = int(not player)
print(point[0] - point[1])


Fixed submission:
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((abs(tmp[0] + tmp[1]), tmp[0], tmp[1]))

dishes = sorted(dishes, key=lambda x: x[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    dish = dishes.pop(0)
    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])

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

n = input()
dishes = [[], []]
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    # dish.append((tmp[0] - tmp[1], tmp[1] - tmp[0], tmp[0], tmp[1], i))
    dish = (tmp[0] - tmp[1], tmp[1] - tmp[0], tmp[0], tmp[1], i)
    dishes[0].append(dish)
    dishes[1].append(dish)

sorted(dishes[0], key=lambda v: v[0], reverse=True)
sorted(dishes[1], key=lambda v: v[1], reverse=True)

point = [0, 0]
player = 0
while len(dishes[0]) > 0:
    dish = dishes[player].pop(0)

    # remove dish
    dishes[int(not player)].remove(dish)

    point[player] += dish[player + 2]
    player = int(not player)
print(point[0] - point[1])


Fixed submission:
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((abs(tmp[0] + tmp[1]), tmp[0], tmp[1]))

dishes = sorted(dishes, key=lambda x: x[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    dish = dishes.pop(0)
    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])

Buggy python submission (verdict: Time Limit Exceeded):
n = input()
dishes = [[], []]
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    # dish.append((tmp[0] - tmp[1], tmp[1] - tmp[0], tmp[0], tmp[1], i))
    dishes[0].append((tmp[0] - tmp[1], tmp[1] - tmp[0], tmp[0], tmp[1], i))
    dishes[1].append((tmp[0] - tmp[1], tmp[1] - tmp[0], tmp[0], tmp[1], i))

# dishes = [copy.deepcopy(dish), copy.deepcopy(dish)]
sorted(dishes[0], key=lambda v: v[0], reverse=True)
sorted(dishes[1], key=lambda v: v[1], reverse=True)

point = [0, 0]
player = 0
while len(dishes[0]) > 0:
    dish = dishes[player].pop(0)

    # remove dish
    dishes[int(not player)].remove(dish)

    point[player] += dish[player + 2]
    player = int(not player)
print(point[0] - point[1])


Fixed submission:
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((abs(tmp[0] + tmp[1]), tmp[0], tmp[1]))

dishes = sorted(dishes, key=lambda x: x[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    dish = dishes.pop(0)
    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])

Buggy python submission (verdict: Time Limit Exceeded):
def ex():
    n = input()
    dish = []
    for i in range(int(n)):
        tmp = [int(each) for each in input().split()]
        dish.append((tmp[0] - tmp[1], tmp[1] - tmp[0], tmp[0], tmp[1]))

    point = [0, 0]

    player = 0
    while len(dish) > 0:
        # print('player', player)
        sorted(dish, key=lambda v: v[player], reverse=True)
        # print(dish[0])
        point[player] += dish.pop(0)[player + 2]
        player = int(not player)
        # print('point', point)

    print(point[0] - point[1])


ex()


Fixed submission:
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((abs(tmp[0] + tmp[1]), tmp[0], tmp[1]))

dishes = sorted(dishes, key=lambda x: x[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    dish = dishes.pop(0)
    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])

Buggy python submission (verdict: Runtime Error):
n = input()
dish = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dish.append((tmp[0] - tmp[1], tmp[1] - tmp[0], tmp[0], tmp[1]))

point = [0, 0]

player = 0
while len(dish) > 0:
    # print(player.__str__(), player)

    sorted(dish, key=lambda v: dish[player], reverse=True)
    # print(dish[0])
    point[player] += dish.pop(0)[player + 2]
    player = int(not player)
    # print('point', point)

print(point[0] - point[1])


Fixed submission:
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((abs(tmp[0] + tmp[1]), tmp[0], tmp[1]))

dishes = sorted(dishes, key=lambda x: x[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    dish = dishes.pop(0)
    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])

Buggy python submission (verdict: Runtime Error):
n = input()
dish = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dish.append((tmp[0] - tmp[1], tmp[1] - tmp[0], tmp[0], tmp[1]))

point = [0, 0]

player = 0
while len(dish) > 0:

    sorted(dish, key=lambda v: dish[player], reverse=True)
    point[player] = dish.pop(0)[player + 2]
    player = int(not player)


print(point[0] - point[1])

Fixed submission:
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((abs(tmp[0] + tmp[1]), tmp[0], tmp[1]))

dishes = sorted(dishes, key=lambda x: x[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    dish = dishes.pop(0)
    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])

Buggy python submission (verdict: Runtime Error):
n = input()
dish = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dish.append((tmp[0] - tmp[1], tmp[1] - tmp[0]))

point = [0, 0]

player = 0
while len(dish) > 0:

    sorted(dish, key=lambda v: dish[player], reverse=True)
    point[player] += point[player]
    player = int(not player)
print(point[0] - point[1])

Fixed submission:
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((abs(tmp[0] + tmp[1]), tmp[0], tmp[1]))

dishes = sorted(dishes, key=lambda x: x[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    dish = dishes.pop(0)
    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])