Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    maxv = max(n)
    winner = n.index(maxv)
    print(winner, maxv)

Fixed submission:
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0 and a == winner:
        maxv = max(n)
        winner = n.index(maxv)
    elif n[a] > maxv:
            maxv, winner = n[a], a
    elif n[a] == maxv:
            winner = min(winner, a)
    print(winner, maxv)

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0:
        maxv, winner = max(n), n.index(maxv)
    else:
        if n[a] > maxv:
            maxv, winner = n[a], a
        elif n[a] == maxv:
            winner = n.index(maxv)
    print(winner, maxv)

Fixed submission:
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0 and a == winner:
        maxv = max(n)
        winner = n.index(maxv)
    elif n[a] > maxv:
            maxv, winner = n[a], a
    elif n[a] == maxv:
            winner = min(winner, a)
    print(winner, maxv)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0:
        maxv = max(n)
        winner = n.index(maxv)
    else:
        if n[a] > maxv:
            maxv, winner = n[a], a
        elif n[a] == maxv:
            winner = n.index(maxv)
    print(winner, maxv)

Fixed submission:
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0 and a == winner:
        maxv = max(n)
        winner = n.index(maxv)
    elif n[a] > maxv:
            maxv, winner = n[a], a
    elif n[a] == maxv:
            winner = min(winner, a)
    print(winner, maxv)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0:
        maxv = max(n)
        winner = n.index(maxv)
    else:
        if n[a] > maxv:
            maxv, winner = n[a], a
        elif n[a] == maxv:
            winner = n.index(maxv)
    print(winner, maxv)

Fixed submission:
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0 and a == winner:
        maxv = max(n)
        winner = n.index(maxv)
    elif n[a] > maxv:
            maxv, winner = n[a], a
    elif n[a] == maxv:
            winner = min(winner, a)
    print(winner, maxv)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0:
        maxv = max(n)
        winner = n.index(maxv)
    elif n[a] > maxv:
            maxv, winner = n[a], a
    elif n[a] == maxv:
            winner = n.index(maxv)
    print(winner, maxv)

Fixed submission:
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0 and a == winner:
        maxv = max(n)
        winner = n.index(maxv)
    elif n[a] > maxv:
            maxv, winner = n[a], a
    elif n[a] == maxv:
            winner = min(winner, a)
    print(winner, maxv)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0:
        maxv = max(n)
        winner = n.index(maxv)
    elif n[a] > maxv:
            maxv, winner = n[a], a
    elif n[a] == maxv:
            winner = min(winner, a)
    print(winner, maxv)

Fixed submission:
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0 and a == winner:
        maxv = max(n)
        winner = n.index(maxv)
    elif n[a] > maxv:
            maxv, winner = n[a], a
    elif n[a] == maxv:
            winner = min(winner, a)
    print(winner, maxv)