qyliang/CodeNanoFix huggingface dataset:
Buggy code:
# coding: utf-8
n = int(input())
ll = []
d = {}
in_k = []
for i in range(n):
    s, p = map(str, input().split())
    if not s in d:
        d[s] = [[int(p), i+1]]
    else:
        d[s].append([int(p), i+1])
    if not s in in_k:
        in_k.append(s)
tmp = 1
num = 1
keys = sorted(d.keys())
for k in keys:
    d[k].sort(key=lambda x: x[0], reverse=True)
    for i in range(len(d[k])):
        d[k][i].append(num)
        num += 1
    d[k].sort(key=lambda x: x[1])
for k in d.keys():
    for j in range(len(d[k])):
        ll.append(d[k][j][1:])
ll.sort(key=lambda x: x[0])
for l in ll:
        print(l[1])

Fixed code:
# coding: utf-8
n = int(input())
ll = []
d = {}
in_k = []
for i in range(n):
    s, p = map(str, input().split())
    if not s in d:
        d[s] = [[int(p), i+1]]
    else:
        d[s].append([int(p), i+1])
    if not s in in_k:
        in_k.append(s)
tmp = 1
num = 1
keys = sorted(d.keys())
for k in keys:
    d[k].sort(key=lambda x: x[0], reverse=True)
    for i in range(len(d[k])):
        d[k][i].append(num)
        num += 1
    d[k].sort(key=lambda x: x[1])
for k in d.keys():
    for j in range(len(d[k])):
        ll.append(d[k][j][1:])
ll.sort(key=lambda x: x[1])
for l in ll:
        print(l[0])
Buggy code:
n=int(input())
s=[]

for i in range(n):
  a,b=map(str,input().split())
  s.append([a,b,i+1])
  
#s.sort(key=lambda x:(x[0],x[1]))
print(s)

for i in range(n):
  print(s[i][2])

Fixed code:
n=int(input())
s=[]

for i in range(n):
  a,b=map(str,input().split())
  b=int(b)
  s.append([a,100-b,i+1])
  
s.sort(key=lambda x:(x[0],x[1]))
#print(s)

for i in range(n):
  print(s[i][2])
Buggy code:
N=int(input())
L=[list(input().split())+[i+1] for i in range(N)]
L.sort(key=lambda x: x[1],reverse=True)
L.sort(key=lambda x: x[0])
for l in L:
  print(l[2])

Fixed code:
N=int(input())
L=[list(input().split())+[i+1] for i in range(N)]
L=[[l[0],int(l[1]),l[2]] for l in L]
L.sort(key=lambda x: x[1],reverse=True)
L.sort(key=lambda x: x[0])
for l in L:
  print(l[2])
Buggy code:
n = int(input())
l = [input().split()+[i] for i in range(n)]

l = sorted(l, key=lambda x : x[1], reverse=True)
l = sorted(l, key=lambda x : x[0])
for i in range(n):
    print(l[i][2])

Fixed code:
n = int(input())
l = [input().split()+[i+1] for i in range(n)]
for i in range(n):
    l[i][1] = int(l[i][1])
l = sorted(l, key=lambda x : x[1], reverse=True)
l = sorted(l, key=lambda x : x[0])
for i in range(n):
    print(l[i][2])
Buggy code:
def main():
    n = int(input())
    inlis = []
    namelis = []
    for i in range(n):
        a, b = map(str, input().split())
        b = int(b)
        inlis.append([a,b])
        namelis.append(a)
    namelis.sort()    
    inlis_so = sorted(inlis)
    anslis = []
    for num in inlis:
        #print(num, num[0], inlis_so, inlis_so.count(num[0]))
        kazu = namelis.count(num[0])
        if kazu == 1:
            anslis.append(inlis_so.index(num))
        else:
            kijun = namelis.index(num[0])+1
            kouho = list(filter(lambda word:True if word[0] == num[0] else False,inlis))
            kouho_so = sorted(kouho, key = lambda x:x[0], reverse = True)
            suujibun = kouho_so.index(num)
            anslis.append(kijun + suujibun)
    for i in range(1, n+1):
        print(anslis.index(i)+1)

    

        
    
if __name__ == "__main__":
    main()


Fixed code:
def main():
    n = int(input())
    inlis = []
    namelis = []
    for i in range(n):
        a, b = map(str, input().split())
        b = int(b)
        inlis.append([a,b])
        namelis.append(a)
    namelis.sort()    
    inlis_so = sorted(inlis)
    anslis = []
    for num in inlis:
        #print(num, num[0], inlis_so, inlis_so.count(num[0]))
        kazu = namelis.count(num[0])
        if kazu == 1:
            anslis.append(inlis_so.index(num)+1)
        else:
            kijun = namelis.index(num[0]) + 1
            kouho = list(filter(lambda word:True if word[0] == num[0] else False,inlis))
            kouho_so = sorted(kouho, key = lambda x:x[1], reverse = True)
            suujibun = kouho_so.index(num)
            anslis.append(kijun + suujibun)
    for i in range(1, n+1):
        #print(anslis)
        print(anslis.index(i)+1)

    

        
    
if __name__ == "__main__":
    main()
Buggy code:
n = [(input().split()) for _ in range(int(input()))]
m = sorted(sorted(n,key=lambda x:x[1], reverse=True),key=lambda x:x[0])
print('\n'.join([str(n.index(li)+1) for li in m]))

Fixed code:
n = [(input().split()) for _ in range(int(input()))]
m = sorted(sorted(n,key=lambda x:int(x[1]), reverse=True),key=lambda x:x[0])
print('\n'.join([str(n.index(li)+1) for li in m]))
Buggy code:
N=int(input())

name=[input().split() for i in range(N)]
score=[]

#print(name)

name2=sorted(name,key=lambda x:(x[0],-int(x[1])))
#name=sorted(name,key=lambda x:x[1], reverse=True)
#print(name2)

for i in range(N):
    for j,city in enumerate(name2):
        if name[i]==city:
            print(j+1)

Fixed code:
N=int(input())

name=[input().split() for i in range(N)]
score=[]

#print(name)

name2=sorted(name,key=lambda x:(x[0],-int(x[1])))
#name=sorted(name,key=lambda x:x[1], reverse=True)
#print(name2)

for i in range(N):
    for j,city in enumerate(name):
        if name2[i]==city:
            print(j+1)
Buggy code:
n = int(input())

SP = []

for i in range(n):
  s, p = [s for s in input().split()]
  p = int(p)
  SP.append(s, p, i +1)
  
SP.sort(key = lambda x: x[1], reverse = True)
SP.sort(key = lambda x: x[0])

print(SP[2])


Fixed code:
N = int(input())

SP = []

for i in range(N):
    s, p = input().split()
    SP.append([s, int(p), i])

SP.sort(key=lambda x:x[1], reverse=True)
SP.sort(key=lambda x:x[0])

for i in range(N):
    print(SP[i][2]+1)
Buggy code:
n=int(input())

lista=[]

for i in range(n): 
	s,p = map(str,input().split())
	lista.append([s,p,i+1])
	
	
#print(lista)
	
lista.sort(key=lambda x:x[1])
#print(lista)

lista.sort(key=lambda x:x[0])
#print(lista)

ans=0
list_ans=[]
for i in range(n):
	ans=lista[i][2]
	list_ans.append(ans)
print(list_ans)
	

Fixed code:
n=int(input())

lista=[]

for i in range(n): 
	s,p = map(str,input().split())
	p=int(p)
	lista.append([s,p,i+1])
	
	
#print(lista)
	
lista.sort(key=lambda x:-x[1])
#print(lista)

lista.sort(key=lambda x:x[0])
#print(lista)

ans=0
list_ans=[]
for i in range(n):
	ans=lista[i][2]
	list_ans.append(ans)

for i in range(n):
	print(list_ans[i])
Buggy code:
n = int(input())

li = []
for i in range(n):
    li.append(list(map(str, input().split())))
    li[i].append(i+1)

li.sort( key = lambda li : (li[0], -int(li[1])))
print(li)


Fixed code:
n = int(input())

li = []
for i in range(n):
    li.append(list(map(str, input().split())))
    li[i].append(i+1)

li.sort( key = lambda li : (li[0], -int(li[1])))
for i in li:
    print(i[2])
Buggy code:
#n, x = map(int,input().split())
n = int(input())
ls = [["",[[]]]]
for i in range(n):
  s, p = input().split()
  p = int(p)
  for j in ls:
    if s == j[0]:
      j[1].append([i+1,p])
      break
    elif j == ls[-1]:
      ls.append([s,[[i+1,p]]])
      break
#ls = list(map(int,input().split()))
#s = input()
ls.remove(ls[0])
print(ls)
ls.sort()
for i in ls:
  i[1].sort(key=lambda x: x[1],reverse=True)
  for j in i[1]:
    print(j[0])


Fixed code:
#n, x = map(int,input().split())
n = int(input())
ls = [["",[[]]]]
for i in range(n):
  s, p = input().split()
  for j in ls:
    if s == j[0]:
      j[1].append([i+1,int(p)])
      break
    elif j == ls[-1]:
      ls.append([s,[[i+1,int(p)]]])
      break
#ls = list(map(int,input().split()))
#s = input()
ls.remove(ls[0])
ls.sort()
for i in ls:
  i[1].sort(key=lambda x: x[1],reverse=True)
  for j in i[1]:
    print(j[0])
Buggy code:
n = int(input())

a = []

for i in range(n):
  	# input as str
	s, p = input().split()
    # p -> integer
	p = int(score)
    # create list
	a.append((s, p, i+1))

# sort
a.sort(key=lambda x:x[1], reverse=True)

# sort
a.sort(key=lambda x:x[0])

# output
for i in range(n):
	print(a[i][2])

Fixed code:
n = int(input())

a = []

for i in range(n):
  	# input as str
	s, p = input().split()
    # p -> integer
	p = int(p)
    # create list
	a.append((s, p, i+1))

# sort
a.sort(key=lambda x:x[1], reverse=True)

# sort
a.sort(key=lambda x:x[0])

# output
for i in range(n):
	print(a[i][2])
Buggy code:
n = int(input())
sp = [input().split() for _ in range(n)]
sp_s = sorted(sp, key=lambda x:(x[0], -int(x[1])))
for i in sp:
    print(sp_s.index(i)+1)

Fixed code:
n = int(input())
sp = [input().split() for _ in range(n)]
sp_s = sorted(sp, key=lambda x:(x[0], -int(x[1])))
for i in sp_s:
    print(sp.index(i)+1)
Buggy code:
n=int(input())
s,p=int(input().split())
li=[]
for i in range(0,n):
  li.append((i+1,s[i],p[i]))

new_li=sorted(li,key=lambda x:x[1])

new2_li=sorted(new_li,key=lambda x:x[2] reverse=True)

for j in range(0,n):
  print(new2_li[j][0])


Fixed code:
n=int(input())

li=[]

for i in range(0,n):
  s,p=input().split()
  p=int(p)
  li.append((i+1,s,p))


new_li=sorted(li,key=lambda x:x[2] , reverse=True)
new2_li=sorted(new_li,key=lambda x:x[1])


for j in range(0,n):
  print(new2_li[j][0])
Buggy code:
# -*- coding: utf-8 -*-

N = int(input())
di = []
tmp =[]

for i in range(N):
    si, pi = input().split()
    pi = int(pi) * (-1)
    tmp = [si, pi, i]
    di.append(tmp)


di = sorted(di, key=lambda x: (x[0], x[1]))    

print(di)

for i in range(N):
    print(di[i][2]+1)






Fixed code:
# -*- coding: utf-8 -*-

N = int(input())
di = []
tmp =[]

for i in range(N):
    si, pi = input().split()
    pi = int(pi) * (-1)
    tmp = [si, pi, i]
    di.append(tmp)
di = sorted(di, key=lambda x: (x[0], x[1]))    

for i in range(N):
    print(di[i][2]+1)
Buggy code:
from operator import itemgetter
N = int(input())
guide = []
for i in range(N):
  lst = input().split(' ')
  guide.append([i+1,lst[0],int(lst[1])])
guide = sorted(guide, key=itemgetter(2),reverse=True)
guide = sorted(guide, key=itemgetter(1))

print(guide)


Fixed code:
from operator import itemgetter
N = int(input())
guide = []
for i in range(N):
  lst = input().split(' ')
  guide.append([i+1,lst[0],int(lst[1])])
guide = sorted(guide, key=itemgetter(2),reverse=True)
guide = sorted(guide, key=itemgetter(1))
for i in range(N):
  print(guide[i][0])
Buggy code:
N = int(input())
re = []
for i in range(N):
    re.append(list(input().split()) + [i+1])
for i in range(N):
    re[i][1] = int(re[i][1])
re = sorted(re, key = lambda x: x[1], reverse = True)
re = sorted(re, key = lambda x: x[0])
print(re)
for i in range(N):
    print(re[i][2])


Fixed code:
N = int(input())
re = []
for i in range(N):
    re.append(list(input().split()) + [i+1])
for i in range(N):
    re[i][1] = int(re[i][1])
re = sorted(re, key = lambda x: x[1], reverse = True)
re = sorted(re, key = lambda x: x[0])

for i in range(N):
    print(re[i][2])
Buggy code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    SP = [input().split() for _ in range(N)]

    SP = enumerate(SP)
    SP = sorted(SP, key=lambda x: (x[1][1], -x[1][0]))
    for i in SP:
        print(i[0])    

if __name__ == '__main__':
    resolve()


Fixed code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    SP = [input().split() for _ in range(N)]

    SP = enumerate(SP)
    SP = sorted(SP, key=lambda x: (x[1][0], -int(x[1][1])))
    for i in SP:
        print(i[0]+1)    

if __name__ == '__main__':
    resolve()
Buggy code:
a = int(input())
c = list()
for b in range(a):
  z, zz = input().split()
  c.append([z,int(zz)]) 

l = list()
tmp = sorted(c, key=lambda x:x[1], reverse=True)
x = sorted(tmp, key=lambda x:x[0])
for a in x:
  for y in c:
    if (a == y):
      l.append(c.index(a)+1)
print(l)

Fixed code:
a = int(input())
c = list()
for b in range(a):
  z, zz = input().split()
  c.append([z,int(zz)]) 

l = list()
tmp = sorted(c, key=lambda x:x[1], reverse=True)
x = sorted(tmp, key=lambda x:x[0])
for a in x:
  for y in c:
    if (a == y):
      l.append(c.index(a)+1)
[print(i) for i in l]
Buggy code:
n = int(input())
lst = [list(input().split())+[i+1] for i in range(n)]

#print(lst)

lst = sorted(lst, key= lambda x:(x[0],-int(x[1])))
print(lst)
for i in range(n):
   print(lst[i][2])


Fixed code:
n = int(input())
lst = [list(input().split())+[i+1] for i in range(n)]


lst = sorted(lst, key= lambda x:(x[0],-int(x[1])))

for i in range(n):
   print(lst[i][2])
Buggy code:
N=int(input())
listA=[]
for i in range(N):
    lis=input().split()
    listA.append([lis[0],int(lis[1]),i])
sort=sorted(listA,key=lambda x:(x[0],-x[1]))
for i in range(N):
    sort[i].append(i+1)
sort=sorted(sort,key=lambda x:x[2])
for disp in sort:
    print(disp[3])

Fixed code:
N=int(input())
listA=[]
for i in range(N):
    lis=input().split()
    listA.append([lis[0],int(lis[1]),i])
sort=sorted(listA,key=lambda x:(x[0],-x[1]))
for i in range(N):
    sort[i].append(i+1)
for disp in sort:
    print(disp[2]+1)
Buggy code:
N=int(input())
d=[input().split() for i in range(N)]
name=[]
for i in range(N):
    d[i].append(i+1)
    name.append(d[i][0])
Name=list(set(name))
Name.sort()
d.sort()
for i in range(len(Name)):
    li=[]
    for j in range(N):
        if Name[i]==d[j][0]:
            li.append([d[j][1],d[j][2]])
    li.sort()
    Li=li[::-1]
    for j in range(len(li)):
        print(Li[j][1])

Fixed code:
N=int(input())
d=[input().split() for i in range(N)]
name=[]
for i in range(N):
    d[i].append(i+1)
    d[i][1]=int(d[i][1])
    name.append(d[i][0])
Name=list(set(name))
Name.sort()
d.sort()
for i in range(len(Name)):
    li=[]
    for j in range(N):
        if Name[i]==d[j][0]:
            li.append([d[j][1],d[j][2]])
        else:
            continue
    li.sort()
    Li=li[::-1]
    for k in range(len(li)):
        print(Li[k][1])
Buggy code:
my_list = []
for i in range(1,N+1):
    l = list((input().split()))
    l.append(i)
    my_list.append(l)

my_list2 = sorted(my_list, key=lambda x:(x[0],-int(x[1])))
for i in my_list2:
  print(i[2])



Fixed code:
N = int(input())
my_list = []
for i in range(1,N+1):
    l = list((input().split()))
    l.append(i)
    my_list.append(l)
 
my_list2 = sorted(my_list, key=lambda x:(x[0],-int(x[1])))
for i in my_list2:
  print(i[2])
Buggy code:
n = int(input())
dct=[]
for i in range(n):
  d = input().split()
  name = d[0]
  score = int(d[1])
  dct.append([name,score,i+1])

dct.sort()
for i in range(n):
  print(dct[i][2])

Fixed code:
n = int(input())
dct=[]
for i in range(n):
  d = input().split()
  name = d[0]
  score = int(d[1])
  dct.append([name,-score,i+1])

dct.sort()
for i in range(n):
  print(dct[i][2])
Buggy code:
N = int(input())
R = [input().split() + [i+1] for i in range(N)]
print(R)
R.sort(key=lambda x: -int(x[1]))
R.sort(key=lambda x: x[0])
[print(n) for _, _, n in R]

Fixed code:
N = int(input())
R = [input().split() + [i+1] for i in range(N)]
# print(R)
R.sort(key=lambda x: -int(x[1]))
R.sort(key=lambda x: x[0])
[print(n) for _, _, n in R]
Buggy code:
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

def main():
    N = II()
    li = []
    for i in range(N):
        S, P = LS()
        li.append([S, int(P), i])

    li = sorted(li, key= lambda x: (x[0], -x[1]))
    print(li)
    for j in li:
        print(j[2]+1)

main()

Fixed code:
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

def main():
    N = II()
    li = []
    for i in range(N):
        S, P = LS()
        li.append([S, int(P), i])

    li = sorted(li, key= lambda x: (x[0], -x[1]))
    for j in li:
        print(j[2]+1)

main()
Buggy code:

N = int(input())
l=list()#empty list

for i in range(1,N+1):
    tempS,tempP = input().split()
    l.append([tempS,-int(tempP),i])

sortedList = sorted(l,key=lambda item:(item[0],item[1]))

print(sortedList)
for i in range(1,N+1):
    print(sortedList[i-1][2])


Fixed code:
N = int(input())
l=list()#empty list

for i in range(1,N+1):
    tempS,tempP = input().split()
    l.append([tempS,-int(tempP),i])

sortedList = sorted(l,key=lambda item:(item[0],item[1]))

for i in range(1,N+1):
    print(sortedList[i-1][2])
Buggy code:
n=int(input())
hoge=[]
for i in range(n):
  a,b=map(str,input().split())
  hoge.append([a,b,i+1])
hoge=sorted(hoge,key=lambda x:(x[1]),reverse=True)
hoge=sorted(hoge,key=lambda x:(x[0]),reverse=False)

for i in range(n):
  print(hoge[i][2])

Fixed code:
n=int(input())
hoge=[]
for i in range(n):
  a,b=map(str,input().split())
  c=int(b)
  hoge.append([a,c,i+1])
hoge=sorted(hoge,key=lambda x:(x[1]),reverse=True)
hoge=sorted(hoge,key=lambda x:(x[0]),reverse=False)
for i in range(n):
  print(hoge[i][2])
Buggy code:
n = int(input())
x = [list(input().split(""))for i in range(n)]

for i in range(n):
    x[i][1] = int(x[i][1])

test2 = sorted(x,key = lambda k :(k[0],-k[1]))

for i in range(n):
    print(x.index(test2[i])+1)

Fixed code:
n = int(input())
 
 
x = [list(input().split(" ")) for i in range(n)]
 
for i in range(n):
    x[i][1] = int(x[i][1])
 
test2 = sorted(x, key = lambda k:(k[0],-k[1]))
 
for i in range(n):
    print(x.index(test2[i]) + 1)
Buggy code:
n=int(input())
sp=[[0 for i in range(3)]for i in range(n)]
for i in range(n):
  sp[i][0],sp[i][1]=input().split()
  sp[i][1]=int(sp[i][1])
  sp[i][2]=i+1
print(sp)
sp=sorted(sp,key=lambda x:(x[0],-x[1]))
print(sp)
for i in range(n):
    print(sp[i][2])

Fixed code:
n=int(input())
sp=[[0 for i in range(3)]for i in range(n)]
for i in range(n):
  sp[i][0],sp[i][1]=input().split()
  sp[i][1]=int(sp[i][1])
  sp[i][2]=i+1
sp=sorted(sp,key=lambda x:(x[0],-x[1]))
for i in range(n):
    print(sp[i][2])
Buggy code:
import copy
n = int(input())
r = []
for _ in range(n):
    city, x = input().split()
    x = int(x)
    r.append((city, x))

d = copy.deepcopy(r)
d = sorted(d, key=lambda x: -x[1])
d = sorted(d, key=lambda x: x[0])

print(d)
for k in d:
    print(r.index(k) + 1)


Fixed code:
import copy
n = int(input())
r = []
for _ in range(n):
    city, x = input().split()
    x = int(x)
    r.append((city, x))

d = copy.deepcopy(r)
d = sorted(d, key=lambda x: -x[1])
d = sorted(d, key=lambda x: x[0])

for k in d:
    print(r.index(k) + 1)
Buggy code:
from sys import stdin
from collections import defaultdict

N = int(input())
lines = stdin.readlines()

dic = defaultdict(dict)

for i, line in enumerate(lines):
    line = line.strip().split()
    if i==0:
        tuple1 = ([i+1, line[0], int(line[1])],)
    else:
        tuple1 = tuple1 + ([i+1, line[0], int(line[1])],)


#print(tuple1)

tuple1 = sorted(tuple1, key = lambda x:x[2], reverse=True)
result = sorted(tuple1, key = lambda x:x[1])
print(result)

Fixed code:
from sys import stdin
from collections import defaultdict

N = int(input())
lines = stdin.readlines()

dic = defaultdict(dict)

for i, line in enumerate(lines):
    line = line.strip().split()
    if i==0:
        tuple1 = ([i+1, line[0], int(line[1])],)
    else:
        tuple1 = tuple1 + ([i+1, line[0], int(line[1])],)


#print(tuple1)

tuple1 = sorted(tuple1, key = lambda x:x[2], reverse=True)
result = sorted(tuple1, key = lambda x:x[1])
for i in range(0,N):
    print(result[i][0])
Buggy code:
N = int(input())

names = []
points = []
ans = []

for i in range(N):
    name, point = str(input()).split(" ")
    ans.append(1)
    names.append(name)
    points.append(point)
    if i == 0:
        continue
    if i == 1:
        if name < names[0]:
            ans[0] += 1
        elif name == names[0] and point > points[0]:
            ans[0] += 1
        else:
            ans[1] += 1
        continue
    for j in range(len(ans) - 1):
        if name < names[j]:
            ans[j] += 1
        elif name == names[j] and point > points[j]:
            ans[j] += 1
        else:
            ans[i] += 1

for i in range(N):
    print(ans.index(min(ans)) + 1)
    ans[ans.index(min(ans))] = 101


Fixed code:
N = int(input())

names = []
points = []
ans = []

for i in range(N):
    name, point = str(input()).split(" ")
    point = int(point)
    ans.append(1)
    names.append(name)
    points.append(int(point))
    if i == 0:
        continue
    if i == 1:
        if name < names[0]:
            ans[0] += 1
        elif name == names[0] and point > points[0]:
            ans[0] += 1
        else:
            ans[1] += 1
        continue
    for j in range(len(ans) - 1):
        if name < names[j]:
            ans[j] += 1
        elif name == names[j] and point > points[j]:
            ans[j] += 1
        else:
            ans[i] += 1

for i in range(N):
    print(ans.index(min(ans)) + 1)
    ans[ans.index(min(ans))] = 101
Buggy code:
n = int(input())

data = dict()

for i in range(1, n + 1):
  city, score = input().split()
  data[city] = [int(score), i]

for key in sorted(data.keys()):
  for _, num in sorted(data[key], key=lambda x: -x[0]):
    print(num)

Fixed code:
n = int(input())

data = dict()

for i in range(1, n + 1):
    city, score = input().split()
    if city not in data:
        data[city] = []
    data[city].append([int(score), i])

for key in sorted(data.keys()):
    for _, num in sorted(data[key], key=lambda x: -x[0]):
        print(num)
Buggy code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#n=int(input())
#import fractions
#S=input()
#import math
#lis=list(map(int,input().split()))

n=int(input())
sp={}
for i in range(n):
    li=input().split()
    li.append(i+1)
    if li[0] not in sp:
        sp[li[0]]=[li]
    else:
        sp[li[0]].append(li)
        sp[li[0]].sort(reverse=True)
items_sorted = sorted(sp.items())
print(items_sorted)
for i in range(n):
    for j in range(len(items_sorted[i])):
        print(items_sorted[i][j+1][2])


Fixed code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#n=int(input())
#import fractions
#S=input()
#import math
#lis=list(map(int,input().split()))

n=int(input())
sp={}
for i in range(n):
    li=input().split()
    li.append(i+1)
    li[1]=int(li[1])
    if li[0] not in sp:
        sp[li[0]]=[li]
    else:
        sp[li[0]].append(li)
        sp[li[0]].sort(reverse=True)
items_sorted = sorted(sp.items())
#print(items_sorted)
for i in range(len(items_sorted)):
    for j in range(len(items_sorted[i][1])):
        print(items_sorted[i][1][j][2])
Buggy code:
n = int(input())
res_list = []
for i in range(n):
    a,b=input().split()
    res_list.append((a,int(b)))
psorted_res_list = sorted(res_list, key=lambda x: x[1], reverse=True)
sorted_res_list = sorted(psorted_res_list, key=lambda x: x[0])
for i in range(n):
    print(sorted_res_list.index(res_list[i]) + 1)

Fixed code:
n = int(input())
res_list = []
for i in range(n):
    a,b=input().split()
    res_list.append((a,int(b)))
psorted_res_list = sorted(res_list, key=lambda x: x[1], reverse=True)
sorted_res_list = sorted(psorted_res_list, key=lambda x: x[0])
for i in range(n):
    print(res_list.index(sorted_res_list[i]) + 1)
Buggy code:
n = int(input())
l = []
for i in range(n):
    x, y = input().split()
    l.append([i, x, int(y)])
l = sorted(l, key=lambda x:(x[1], x[2]))
for i in l:
    print(i[0])

Fixed code:
n = int(input())
l = []
for i in range(n):
    x, y = input().split()
    l.append([i+1, x, -int(y)])
l = sorted(l, key=lambda x:(x[1],x[2]))

for i in l:
    print(i[0])