Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    DP = [[0] * (M + 1) for _ in range(N + 1)]

    for i in range(N):
        DP[i + 1][0] = DP[i][0] + A[i]
        if DP[i + 1][0] > K:
            DP[i + 1][0] = 0
            break
    for j in range(M):
        DP[0][j + 1] = DP[0][j] + B[j]
        if DP[0][j + 1] > K:
            DP[0][j + 1] = 0
            break

    for i in range(N):
        if DP[i + 1][0] == 0: break
        for j in range(M):
            if DP[i + 1][j] == 0: break
            DP[i + 1][j + 1] = DP[i + 1][j] + B[j]
            if DP[i + 1][j + 1] > K:
                DP[i + 1][j + 1] = 0
                break

    ans = 0
    for i in range(N + 1):
        MX = max(DP[i])
        if MX == 0: break
        j = DP[i].index(MX)
        ans = max(ans, i + j)

    print(ans)


if __name__ == '__main__':
    main()

exit()


Fixed submission:
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    SUMA = [0]
    for a in A:
        if SUMA[-1] + a > K: break
        SUMA.append(SUMA[-1] + a)
    SUMB = [0]
    for b in B:
        if SUMB[-1] + b > K: break
        SUMB.append(SUMB[-1] + b)

    if len(SUMA) == 1:
        ans = len(SUMB) - 1
    elif len(SUMB) == 1:
        ans = len(SUMA) - 1
    else:
        ans = 0
        i = len(SUMA)
        j = 1
        while i:
            i -= 1
            while SUMA[i] + SUMB[j] <= K:
                j += 1
                if j == len(SUMB): break
            j -= 1
            ans = max(ans, i + j)

    print(ans)


if __name__ == '__main__':
    main()

exit()
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

L = 0
U = len(S)

while U - L > 1:
    M = (U + L) // 2

    OK = False
    for i in range(2):
        A = i
        B = M
        if A % 2 != B % 2: B -= 1

        NG = False
        for s in S:
            if s == '0':
                A -= 1
                B -= 1
            elif s == '1':
                A += 1
                B += 1
            else:
                A -= 1
                B += 1

            if A < 0: A += 2
            if B > M: B -= 2
            if A > B:
                NG = True
                break

        if not NG:
            OK = True
            break

    if OK:
        U = M
    else:
        L = M

print(U)


Fixed submission:
S = input()

L = 0
U = len(S)

while U - L > 1:
    M = (U + L) // 2

    OK = False
    for i in range(2):
        A = i
        B = M
        if A % 2 != B % 2: B -= 1

        NG = False
        for s in S:
            if s == '0':
                A -= 1
                B -= 1
            elif s == '1':
                A += 1
                B += 1
            else:
                A -= 1
                B += 1

            if A < 0: A += 2
            if B > M: B -= 2
            if A > B:
                NG = True
                break

        if not NG:
            OK = True
            break

    if OK:
        U = M
    else:
        L = M

print(U)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 1
for i in range(N):
    ans *= A[i]
    if ans == 0: break

if ans > 10**18:
    ans = -1

print(ans)


Fixed submission:
N = int(input())
A = tuple(map(int, input().split()))

if 0 in A:
    ans = 0
else:
    ans = 1
    for i in A:
        ans *= i
        if ans > 10**18:
            ans = -1
            break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int,input().split())
A = list(map(int,input().split()))

MOD = 998244353

dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S + 1):
        dp[i + 1][j] += 2 * dp[i][j]
        #dp[i + 1][j] %= MOD
        if j + A[i] <= S:
            dp[i + 1][j + A[i]] += dp[i][j]
            #dp[i + 1][j + A[i]] %= MOD

print(dp[N][S] % MOD)


Fixed submission:
N, S = map(int,input().split())
A = list(map(int,input().split()))

MOD = 998244353

dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S + 1):
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= MOD
        if j + A[i] <= S:
            dp[i + 1][j + A[i]] += dp[i][j]
            dp[i + 1][j + A[i]] %= MOD

print(dp[N][S])

Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int,input().split())
A = list(map(int,input().split()))

MOD = 998244353

dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S + 1):
        dp[i + 1][j] += 2 * dp[i][j]
        #dp[i + 1][j] %= MOD
        if j + A[i] <= S:
            dp[i + 1][j + A[i]] += dp[i][j]
            #dp[i + 1][j + A[i]] %= MOD

print(dp[N][S] % MOD)


Fixed submission:
N, S = map(int,input().split())
A = list(map(int,input().split()))

MOD = 998244353

dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S + 1):
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= MOD
        if j + A[i] <= S:
            dp[i + 1][j + A[i]] += dp[i][j]
            dp[i + 1][j + A[i]] %= MOD

print(dp[N][S])

Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int,input().split())
A = list(map(int,input().split()))

MOD = 998244353

dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S + 1):
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= MOD
        if j + A[i] <= S:
            dp[i + 1][j + A[i]] += dp[i][j]
            dp[i + 1][j + A[i]] %= MOD

print(dp[N][S])


Fixed submission:
N, S = map(int,input().split())
A = list(map(int,input().split()))

MOD = 998244353

dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S + 1):
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= MOD
        if j + A[i] <= S:
            dp[i + 1][j + A[i]] += dp[i][j]
            dp[i + 1][j + A[i]] %= MOD

print(dp[N][S])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from functools import lru_cache

sys.setrecursionlimit(10**6)


def main():
    T = int(input())
    TESTCASEs = [list(map(int, input().split())) for _ in range(T)]


    def calc_cost(N, A, B, C, D):


        #@lru_cache(maxsize=None)
        def calc(N):
            if N == 0:
                return 0
            if N == 1:
                return D

            cost = N * D
            
            for T, Tcost in ((2, A), (3, B), (5, C)):
                div, mod = divmod(N, T)

                cost = min(cost, calc(div) + Tcost + mod * D)
                if mod:
                    cost = min(cost, calc(div + 1) + Tcost + (T - mod) * D)

            return cost


        return calc(N)


    for TESTCASE in TESTCASEs:
        total_cost = calc_cost(*TESTCASE)
        print(total_cost)


if __name__ == '__main__':
    main()

sys.exit()


Fixed submission:
import sys
from functools import lru_cache

sys.setrecursionlimit(10**6)


def main():
    T = int(input())
    TESTCASEs = [list(map(int, input().split())) for _ in range(T)]


    def calc_cost(N, A, B, C, D):


        @lru_cache(maxsize=None)
        def calc(N):
            if N == 0:
                return 0
            if N == 1:
                return D

            cost = N * D
            
            for T, Tcost in ((2, A), (3, B), (5, C)):
                div, mod = divmod(N, T)

                cost = min(cost, calc(div) + Tcost + mod * D)
                if mod:
                    cost = min(cost, calc(div + 1) + Tcost + (T - mod) * D)

            return cost


        return calc(N)


    for TESTCASE in TESTCASEs:
        total_cost = calc_cost(*TESTCASE)
        print(total_cost)


if __name__ == '__main__':
    main()

sys.exit()
Buggy python submission (verdict: Runtime Error):
#168 - F
import sys
import numpy as np
#from numba import njit


N, M = map(int, sys.stdin.buffer.readline().split())
LineData = np.int64(sys.stdin.buffer.read().split())

INF = 10**9 + 1

LineData = LineData.reshape(-1, 3)
A, B, C = LineData[:N].T
D, E, F = LineData[N:].T
#X = np.unique(np.concatenate([D, [-INF, 0, INF]]))
#Y = np.unique(np.concatenate([C, [-INF, 0, INF]]))
X = np.unique(np.concatenate([D, [-INF, INF]]))
Y = np.unique(np.concatenate([C, [-INF, INF]]))
A = np.searchsorted(X, A)
B = np.searchsorted(X, B, 'right') - 1
C = np.searchsorted(Y, C)
D = np.searchsorted(X, D)
E = np.searchsorted(Y, E)
F = np.searchsorted(Y, F, 'right') - 1

x = np.searchsorted(X, 0, 'right') - 1
y = np.searchsorted(Y, 0, 'right') - 1

DX = X[1:] - X[:-1]
DY = Y[1:] - Y[:-1]

A = A.tolist()
B = B.tolist()
C = C.tolist()
D = D.tolist()
E = E.tolist()
F = F.tolist()
X = X.tolist()
Y = Y.tolist()
DX = DX.tolist()
DY = DY.tolist()

LenX = len(X)
LenY = len(Y)

visit = [[False] * LenY for _ in range(LenX)]
visit[x][y] = True
area = 0
queue = [(x, y)]

LineX = [[False] * LenY for _ in range(LenX)]
LineY = [[False] * LenY for _ in range(LenX)]

#for x1, x2, y in zip(A, B, C):
#    for x in range(x1, x2):
#        LineY[x][y] = True
for i in range(len(A)):
    y = C[i]
    for x in range(A[i], B[i]):
        LineY[x][y] = True

#for x, y1, y2 in zip(D, E, F):
#    for y in range(y1, y2):
#        LineX[x][y] = True
for i in range(len(D)):
    x = D[i]
    for y in range(E[i], F[i]):
        LineX[x][y] = True

LenX -= 1
LenY -= 1

while queue:
    x, y = queue.pop()
    
    if x == 0 or x == LenX or y == 0 or y == LenY:
        area = 0
        break
    
    area += DX[x] * DY[y]
    
    x1 = x - 1
    if not LineX[x][y] and not visit[x1][y]:
        visit[x1][y] = True
        queue.append((x1, y))
    y1 = y - 1
    if not LineY[x][y] and not visit[x][y1]:
        visit[x][y1] = True
        queue.append((x, y1))
    x1 = x + 1
    if not LineX[x1][y] and not visit[x1][y]:
        visit[x1][y] = True
        queue.append((x1, y))
    y1 = y + 1
    if not LineY[x][y1] and not visit[x][y1]:
        visit[x][y1] = True
        queue.append((x, y1))

if area == 0:
    print("INF")
else:
    print(area)


Fixed submission:
import sys
import os

n = input()
n = n[-1]

if n == "2" or n == "4" or n == "5" or n == "7" or n == "9":
    print("hon")
elif n == "0" or n == "1" or n == "6" or n == "8":
    print("pon")
elif n == "3":
    print("bon")

sys.exit()

Buggy python submission (verdict: Runtime Error):
import sys
import os

n = sys.argv[1]
n = n[-1]

if n == "2" or n == "4" or n == "5" or n == "7" or n == "9":
    print("hon")
elif n == "0" or n == "1" or n == "6" or n == "8":
    print("pon")
elif n == "3":
    print("bon")

sys.exit()


Fixed submission:
import sys
import os

n = input()
n = n[-1]

if n == "2" or n == "4" or n == "5" or n == "7" or n == "9":
    print("hon")
elif n == "0" or n == "1" or n == "6" or n == "8":
    print("pon")
elif n == "3":
    print("bon")

sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        if j + wv[i][0] <= W:
            dp[i + 1][j + wv[i][0]] = max(dp[i][j] + wv[i][1], dp[i][j + wv[i][0]])
        
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

print(dp[N][W])


Fixed submission:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        if j + wv[i][0] <= W:
            dp[i + 1][j + wv[i][0]] = max(dp[i][j] + wv[i][1], dp[i][j + wv[i][0]])
        
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    t = input()

    len_s = len(s)
    len_t = len(t)

    DP = [[0] * (len_t + 1) for _ in range(len_s + 1)]

    for i in range(len_s):
        for j in range(len_t):
            if s[i] == t[j]:
                DP[i + 1][j + 1] = DP[i][j] + 1
            else:
                DP[i + 1][j + 1] = max(DP[i + 1][j], DP[i][j + 1])

    ans = ""
    i = len_s
    j = len_t
    while DP[i][j]:
        if s[i - 1] == t[j - 1]:
            ans += s[i - 1]
            i -= 1
            j -= 1
        else:
            if DP[i - 1][j] > DP[i][j -1]:
                i -= 1
            else:
                j -= 1

    print(ans[::-1])


if __name__ == '__main__':
    main()

exit()

Fixed submission:
def main():
    s = input()
    t = input()

    len_s = len(s)
    len_t = len(t)

    DP = [[0] * (len_t + 1) for _ in range(len_s + 1)]

    for i in range(len_s):
        for j in range(len_t):
            if s[i] == t[j]:
                DP[i + 1][j + 1] = DP[i][j] + 1
            else:
                DP[i + 1][j + 1] = max(DP[i + 1][j], DP[i][j + 1])

    ans = ""
    i = len_s
    j = len_t
    while DP[i][j]:
        if s[i - 1] == t[j - 1]:
            ans += s[i - 1]
            i -= 1
            j -= 1
        else:
            if DP[i - 1][j] > DP[i][j -1]:
                i -= 1
            else:
                j -= 1

    print(ans[::-1])


if __name__ == '__main__':
    main()

exit()
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
array=input().split(" ")
sum=1
for i in range(N):
  sum=sum*int(array[i])
if sum>1000000000000000000:
	sum=-1
    

print(sum)

Fixed submission:
N=int(input())
array=input().split(" ")
sum=1
for j in range(N):
  if array[j]=="0":
    sum=0
if sum!=0:
  for i in range(N):
    sum=sum*int(array[i])
    if sum>1000000000000000000:
        sum=-1
        break
    else:
      continue
    break
print(sum)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print(0)
else:
    result = 0
    for i in range(len(factorization(N))):
        tempnumber = factorization(N)[i][1]
        plusnumber = 1
        while tempnumber > 0:
            tempnumber -= plusnumber
            result += 1
            plusnumber += 1
    print(result)

Fixed submission:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
N = int(input())
if N == 1:
    print(0)
else:
    result = 0
    for i in range(len(factorization(N))):
        tempnumber = factorization(N)[i][1]
        plusnumber = 1
        while tempnumber > 0:
            result += 1
            plusnumber += 1
            tempnumber -= plusnumber
    print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int,input().split()))
result = 0
nowmin = P[0]
for i in range(N):
    if P[i]>nowmin:
        pass 
    else:
        if P[i] == min(P[:i+1]):
            result += 1
            nowmin == P[i]
print(result)

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
result = 0
nowmin = N
for i in range(N):
    if P[i]>nowmin:
        pass 
    else:
        result += 1
        nowmin = P[i]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int,input().split()))
result = 0
for i in range(N):
    if P[i] == min(P[:i+1]):
        result += 1
print(result)

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
result = 0
nowmin = N
for i in range(N):
    if P[i]>nowmin:
        pass 
    else:
        result += 1
        nowmin = P[i]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int,input().split()))
result = 0
for i in range(N):
    miss = 0
    for j in range(i+1):
        if P[i]>P[i-j]:
            miss = 1
            break
    if miss == 0:
        result+=1
print(result)

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
result = 0
nowmin = N
for i in range(N):
    if P[i]>nowmin:
        pass 
    else:
        result += 1
        nowmin = P[i]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int,input().split()))
result = 0
for i in range(N):
    number = P[i]
    miss = 0
    for j in range(i):
        if P[i]>P[j]:
            miss = 1
            break
    if miss == 0:
        result+=1
print(result)

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
result = 0
nowmin = N
for i in range(N):
    if P[i]>nowmin:
        pass 
    else:
        result += 1
        nowmin = P[i]
print(result)
Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())
def okasi(x, y):
    return (x * y) // math.gcd(x, y)

print(okasi(A,B))

Fixed submission:
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a

A, B = map(int, input().split())
def okasi(x, y):
    return (x * y) // gcd(x, y)

print(okasi(A,B))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
number = list(map(int,input().split()))
if not 1 in number:
    print(-1)
else:
    for i in range(N):
        now = i+1
        if now in number:
            #number.index(now)が左から数えたときのnowのindex番号
            number[:number.index(now)+1]=[]
            if i == N-1:
                count=0

        else:
            count = N-i
            break
    print(count)

Fixed submission:
N = int(input())
number = list(map(int,input().split()))
count = 0
if not 1 in number:
    print(-1)
else:
    nownumber = 1
    nowindex = 0
    for i in range(N):
        if number[i]  == nownumber:
            count += 1
            nownumber += 1
        else:
            pass
    print(N-count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
number = list(map(int,input().split()))
count = 0
if not 1 in number:
    print(-1)
else:
    for i in range(N):
        now = i+1
        if now in number:
            indexnumber = number.index(now)
            #number.index(now)が左から数えたときのnowのindex番号
            count += indexnumber
            number[:indexnumber+1]=[]

        else:
            count += len(number)
            break
    print(count)

Fixed submission:
N = int(input())
number = list(map(int,input().split()))
count = 0
if not 1 in number:
    print(-1)
else:
    nownumber = 1
    nowindex = 0
    for i in range(N):
        if number[i]  == nownumber:
            count += 1
            nownumber += 1
        else:
            pass
    print(N-count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
number = list(map(int,input().split()))
count = 0
if not 1 in number:
    print(-1)
else:
    for i in range(N):
        now = i+1
        if now in number:
            #number.index(now)が左から数えたときのnowのindex番号
            count += number.index(now)
            number[:number.index(now)+1]=[]

        else:
            count += len(number)
            break
    print(count)

Fixed submission:
N = int(input())
number = list(map(int,input().split()))
count = 0
if not 1 in number:
    print(-1)
else:
    nownumber = 1
    nowindex = 0
    for i in range(N):
        if number[i]  == nownumber:
            count += 1
            nownumber += 1
        else:
            pass
    print(N-count)
Buggy python submission (verdict: Time Limit Exceeded):
number = int(input())
heights = list(map(int, input().split()))
plusminus=[]
answerlist = [0]
for i in range(number-1):
    if heights[i]>=heights[i+1]:
        plusminus.append(1)
    else:
        plusminus.append(0)
for j in range(number-1):
    if heights[j] == 0:
        pass
    else:
        q = 0
        for k in range(number-1-j):
            if plusminus[j+k]==1:
                q += 1
            else:
                break
        answerlist.append(q)
                
print(max(answerlist))

Fixed submission:
number = int(input())
heights = list(map(int, input().split()))
plusminus=[]
answerlist = [0]
q = 0
for i in range(number-1):
    if i != number-2 and heights[i]>=heights[i+1]:
        q += 1
    elif i == number-2 and heights[i]>=heights[i+1]:
        q += 1
        answerlist.append(q)
    else:
        answerlist.append(q)
        q = 0
print(max(answerlist))

Buggy python submission (verdict: Time Limit Exceeded):
number = int(input())
heights = list(map(int, input().split()))
timeslist = []
for i in range(number):
    times = number-i-1
    q = 0
    for j in range(times):
        if heights[i+j] >= heights[i+j+1]:
            q+=1
        else:
            break
    timeslist.append(q)
print(max(timeslist))

Fixed submission:
number = int(input())
heights = list(map(int, input().split()))
plusminus=[]
answerlist = [0]
q = 0
for i in range(number-1):
    if i != number-2 and heights[i]>=heights[i+1]:
        q += 1
    elif i == number-2 and heights[i]>=heights[i+1]:
        q += 1
        answerlist.append(q)
    else:
        answerlist.append(q)
        q = 0
print(max(answerlist))
Buggy python submission (verdict: Runtime Error):
l,m = map(int,input().split())
lis =[]
lis2=[]
for i in range(l):
  lis.append(m+i)
  lis2.append(abs(m+i))

lis.pop(lis2.index(min(lis2)))
print(sum(lis)
  

Fixed submission:
l,m = map(int,input().split())
lis =[]
lis2=[]
for i in range(l):
  lis.append(m+i)
  lis2.append(abs(m+i))

lis.pop(lis2.index(min(lis2)))
print(sum(lis))

Buggy python submission (verdict: Runtime Error):
l,m = map(int,input().split())
lis =[]
lis2=[]
for i in range(l):
  lis.append(m+i-1)
  lis2.append(abs(m+i-1))

lis.pop(list_name.index(min(lis2)))
print(sum(lis)
  

Fixed submission:
l,m = map(int,input().split())
lis =[]
lis2=[]
for i in range(l):
  lis.append(m+i)
  lis2.append(abs(m+i))

lis.pop(lis2.index(min(lis2)))
print(sum(lis))
Buggy python submission (verdict: Runtime Error):
i,j =map(int,input())
if i>=10:
  print(10)
else:
  print(0)

Fixed submission:
X, Y = map(int, input().split())
if X >= Y:
  print(10)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
A, P = input().split()
P += A*3
print(P//2)

Fixed submission:
A, P = map(int,input().split())
P += A*3
print(P//2)
Buggy python submission (verdict: Runtime Error):
P = int(input())
res= []
for i in range(P):
  a, b = input().split(' ')
  res.append((a,b,i+1))
res2 = sorted(res, key = lambda x:x[1], reverse = True)
res3 = sorted(res2, key = lambda x:x[0])
for j in range(P):
  print(res3[2])

Fixed submission:
P = int(input())
res= []
for i in range(P):
  a, b = input().split()
  res.append((a,int(b)))
res2 = sorted(res, key = lambda x:x[1], reverse = True)
res3 = sorted(res2, key = lambda x:x[0])
for j in range(P):
  print(str(res.index(res3[j])+1))

Buggy python submission (verdict: Runtime Error):
P = int(input())
res= []
for i in range(P):
    a, b = input().split()
    res.append((a,b))
    print(res)
res2 = sorted(res, key = lambda x:(x[0],x[1]))
for i in range(P):
    print(int(index(res2[i])+1)

Fixed submission:
P = int(input())
res= []
for i in range(P):
  a, b = input().split()
  res.append((a,int(b)))
res2 = sorted(res, key = lambda x:x[1], reverse = True)
res3 = sorted(res2, key = lambda x:x[0])
for j in range(P):
  print(str(res.index(res3[j])+1))
Buggy python submission (verdict: Runtime Error):
N = input()
remainder = N % 1000
print(remainder)

Fixed submission:
N = int(input())
if N%1000 == 0:
	print(0)
else:
	print(1000 - N%1000)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split(" "))
trickSum = 0
result = list()
while True :
    d = input()
    if d == "":
        break
    result = result + (list(map(int, input().split(" "))))
print(N - len(set(result)))

Fixed submission:
N,K = map(int,input().split(" "))
trickSum = 0
result = list()
for i in range(K):
    d = input()
    result = result + (list(map(int, input().split(" "))))
print(N - len(set(result)))