Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    a = []
    b = []
    for _ in range(N):
        ai, bi = map(int, input().split())
        a.append(ai)
        b.append(bi)
    ans = 0
    s = 1
    while True:
        if sum(a) == 0:
            print(ans)
            exit()
        ma = a.pop()
        ans += ma * s
        b.pop()
        t = a
        a = b
        b = t
        s *= -1


main()


Fixed submission:
def main():
    N = int(input())
    ab = [[int(i) for i in input().split()] for _ in range(N)]
    ab = sorted(ab, key=lambda x: x[0] + x[1], reverse=True)
    ans = 0
    for i in range(N):
        if i % 2 == 0:
            ans += ab[i][0]
        else:
            ans -= ab[i][1]
    print(ans)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    a = []
    b = []
    for _ in range(N):
        ai, bi = map(int, input().split())
        a.append(ai)
        b.append(bi)
    ans = 0
    s = 1
    while True:
        if sum(a) == 0:
            print(ans)
            exit()
        ma = max(a)
        mb = max(b)
        ans += ma * s
        if ma >= mb:
            i = a.index(ma)
        else:
            i = b.index(mb)
        a[i] = 0
        b[i] = 0
        t = a
        a = b
        b = t
        s *= -1


main()


Fixed submission:
def main():
    N = int(input())
    ab = [[int(i) for i in input().split()] for _ in range(N)]
    ab = sorted(ab, key=lambda x: x[0] + x[1], reverse=True)
    ans = 0
    for i in range(N):
        if i % 2 == 0:
            ans += ab[i][0]
        else:
            ans -= ab[i][1]
    print(ans)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    a = []
    b = []
    for _ in range(N):
        ai, bi = map(int, input().split())
        a.append(ai)
        b.append(bi)
    ans = 0
    s = 1
    while True:
        if len(a) == 0:
            print(ans)
            exit()
        ma = max(a)
        mb = max(b)
        ans += ma * s
        if ma >= mb:
            i = a.index(ma)
        else:
            i = b.index(mb)
        a.pop(i)
        b.pop(i)
        ta = a
        a = b
        b = ta
        s *= -1


main()


Fixed submission:
def main():
    N = int(input())
    ab = [[int(i) for i in input().split()] for _ in range(N)]
    ab = sorted(ab, key=lambda x: x[0] + x[1], reverse=True)
    ans = 0
    for i in range(N):
        if i % 2 == 0:
            ans += ab[i][0]
        else:
            ans -= ab[i][1]
    print(ans)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def f(a, b, ans, s):
    if len(a) == 0:
        print(ans)
        exit()
    if max(a) >= max(b):
        i = a.index(max(a))
        ans += a[i] * s
        a.pop(i)
        b.pop(i)
    else:
        i = b.index(max(b))
        ans += a[i] * s
        a.pop(i)
        b.pop(i)
    f(b, a, ans, (-1) * s)


def main():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    f(A, B, 0, 1)


main()


Fixed submission:
def main():
    N = int(input())
    ab = [[int(i) for i in input().split()] for _ in range(N)]
    ab = sorted(ab, key=lambda x: x[0] + x[1], reverse=True)
    ans = 0
    for i in range(N):
        if i % 2 == 0:
            ans += ab[i][0]
        else:
            ans -= ab[i][1]
    print(ans)


main()