qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import collections as cl

N=int(input())

L = cl.deque()

for i in range(N):
  S,P_ = input().split()
  P = int(P_)
  
  flg = False
  for j in range(len(L)):
    if L[j][0]>S or (L[j][0]==S and L[j][1]>P):
      L.insert(j,(S,P,i))
      flg = True
  if flg==False:
    L.append(j,(S,P,i))
    
I = [0]*N
for i in range(N):
  I[L[i][2]] = i+1

for i in range(N):
  print(I[i])
      




Fixed code:
import collections as cl

N=int(input())

L = []

for i in range(N):
  S,P_ = input().split()
  P = int(P_)
  
  flg = False
  for j in range(len(L)):
    if L[j][0]>S or (L[j][0]==S and L[j][1]<P):
      L.insert(j,(S,P,i))
      flg = True
      break
  if flg==False:
    L.append((S,P,i))
        
#I = [0]*N
for i in range(N):
  print(L[i][2]+1)
#  I[L[i][2]] = i+1
Buggy code:
from collections import defaultdict
n = int(input())
l1, l2 = [], []
l3 = []
d = defaultdict(dict)

for i in range(n):
    s,  p = (x for x in input().split())
    p = int(p)
    d[s][i] = p

s_sorted = sorted(d.items(), key=lambda x:x[0])

for i in s_sorted :
    s = sorted(i[1].values(), reverse = True)
    l3.append(s)


for i in range(len(s_sorted)) :
    for k, v in sorted(s_sorted[i][1].items(), key=lambda x: -x[1]) :
        print(v)

Fixed code:
from collections import defaultdict
n = int(input())
l1, l2 = [], []
l3 = []
d = defaultdict(dict)

for i in range(n):
    s,  p = (x for x in input().split())
    p = int(p)
    d[s][i] = p

s_sorted = sorted(d.items(), key=lambda x:x[0])

for i in s_sorted :
    s = sorted(i[1].values(), reverse = True)
    l3.append(s)


for i in range(len(s_sorted)) :
    for k, v in sorted(s_sorted[i][1].items(), key=lambda x: -x[1]) :
        print(k + 1)
Buggy code:
N = int(input())
A = []
for i in range(N) :
    S, P = input().split()
    A.append([S])
    A[i].append(100-int(P))
new_A_list = sorted(A)
for i in range(N) :
    print(new_A_list.index(A[i])+1)

Fixed code:
N = int(input())
A = []
for i in range(N) :
    S, P = input().split()
    A.append([S])
    A[i].append(100-int(P))
new_A_list = sorted(A)
for i in range(N) :
    print(A.index(new_A_list[i])+1)
Buggy code:
N = int(input())
book= []
for i in range(N):
    a = input().split()
    city = a[0]
    score = (100-int(a[1]))
    book.append((city, score))
b=sorted(book)
print(book)
print(b)

for i in b:
    ans =  1
    for j in book:
        if i == j:
            print(ans)
        else:
            ans += 1

Fixed code:
N = int(input())
book= []
for i in range(N):
    a = input().split()
    city = a[0]
    score = (100-int(a[1]))
    book.append((city, score))
b=sorted(book)

for i in b:
    ans =  1
    for j in book:
        if i == j:
            print(ans)
        else:
            ans += 1
Buggy code:
n = int(input())
lst = []
for i in range(n):
  s, p = input().split()
  p = int(p)
  lst.append((s, p, i+1))
lst_sorted = sorted(lst, key:lambda x: (x[0], -x[1]))
for _, _, num in lst_sorted:
  print(num)

Fixed code:
n = int(input())
lst = []
for i in range(n):
  s, p = input().split()
  p = int(p)
  lst.append((s, p, i+1))
lst_sorted = sorted(lst, key=lambda x: (x[0], -x[1], x[2]))
for _, _, num in lst_sorted:
  print(num)
Buggy code:
n = int(input())
r=[]
for i in range(n):
    s,p=input().split()
    r.append((s,int(p),i))

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

Fixed code:
n = int(input())
r=[]
for i in range(n):
    s,p=input().split()
    r.append((s,int(p),i))

l = sorted(r,key=lambda x:(x[0],-x[1]))

for i in range(n):
    print(l[i][2]+1)
Buggy code:
n=int(input())
res=[]
city=[]
for i in range(n):
    s,p=map(str,input().split())
    p=int(p)
    res.append([s,p,i+1])
R=sorted(res,key=lambda x : x[1],reverse=True)
Res=sorted(R,key=lambda x : x[0])
print(Res)
for j in Res:
    print(j[2])

Fixed code:
n=int(input())
res=[]
city=[]
for i in range(n):
    s,p=map(str,input().split())
    p=int(p)
    res.append([s,p,i+1])
R=sorted(res,key=lambda x : x[1],reverse=True)
Res=sorted(R,key=lambda x : x[0])

for j in Res:
    print(j[2])
Buggy code:
n = int(input())
sp = [[0, 0, 0] for i in range(n)]
for i in range(n):
  sp[i][0], sp[i][1] = list(map(str, input().split()))
  sp[i][1] = int(sp[i][1])
  sp[i][2] = i+1
sp.sort()
print(sp)

c=1
for i in range(n-1):
  if sp[i][0] == sp[i+1][0]:
    c+=1
    i+=1
  else:
    for j in range(c):
      print(sp[i-j][2])
    c=1
for j in range(c):
  print(sp[n-1-j][2])

Fixed code:
n = int(input())
sp = [[0, 0, 0] for i in range(n)]
for i in range(n):
  sp[i][0], sp[i][1] = list(map(str, input().split()))
  sp[i][1] = int(sp[i][1])
  sp[i][2] = i+1
sp.sort()

c=1
for i in range(n-1):
  if sp[i][0] == sp[i+1][0]:
    c+=1
    i+=1
  else:
    for j in range(c):
      print(sp[i-j][2])
    c=1
for j in range(c):
  print(sp[n-1-j][2])
Buggy code:
from functools import cmp_to_key
N = int(input())

my_list = []

for i in range(N):
    t, c = input().split()
    my_list.append((t, int(c), i+1))

def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1

my_list.sort(key=cmp_to_key(lambda x, y: cmp(x[0], y[0]) or cmp(x[1], y[1])))

for mi in my_list:
    print(mi[2])

Fixed code:
from functools import cmp_to_key
N = int(input())

my_list = []

for i in range(N):
    t, c = input().split()
    my_list.append((t, int(c), i+1))

def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1

my_list.sort(key=cmp_to_key(lambda x, y: cmp(x[0], y[0]) or cmp(y[1],x[1])))

for mi in my_list:
    print(mi[2])
Buggy code:
n = int(input())

graph = {}
for i in range(1, n+1):
    s, p = input().split(' ')
    newMap = {'number': i, 'score': p}
    if s not in graph:
        graph[s] = [newMap]
    else:
        graph[s].append(newMap)

keys = list(graph.keys())
keys.sort()
for key in keys:
    maps = sorted(graph[key], reverse=True, key=lambda x: x['score'])
    for map in maps:
        print(map['number'])


Fixed code:
n = int(input())

graph = {}
for i in range(1, n+1):
    s, p = input().split(' ')
    newMap = {'number': i, 'score': int(p)}
    if s not in graph:
        graph[s] = [newMap]
    else:
        graph[s].append(newMap)

keys = list(graph.keys())
keys.sort()
for key in keys:
    maps = sorted(graph[key], reverse=True, key=lambda x: x['score'])
    for map in maps:
        print(map['number'])
Buggy code:
n=int(input())
a=[]
b=[i for i in range(n)]
for i in range(n):
  m,l=(j for j in input().split())
  a.append([m,l])
for i in range(n):
  for j in range(n-1):
    if a[j][0]<a[j+1][0] or (a[j][0]==a[j+1][0] and a[j][1]<a[j+1][1]):
                 c=a[j]
                 a[j]=a[j+1]
                 a[j+1]=c
                 d=b[j]
                 b[j]=b[j+1]
                 b[j+1]=d
for i in range(n):
  print(b[i]+1)

Fixed code:
n=int(input())
a=[]
b=[i+1 for i in range(n)]
for i in range(n):
  m,l=(j for j in input().split())
  a.append([m,int(l)])
for i in range(n):
  for j in range(n-1):
    if a[j+1][0]<a[j][0] or (a[j+1][0]==a[j][0] and a[j][1]<a[j+1][1]):
                 c=a[j]
                 a[j]=a[j+1]
                 a[j+1]=c
                 d=b[j]
                 b[j]=b[j+1]
                 b[j+1]=d
for i in range(n):
  print(b[i])
Buggy code:
N = int(input())
SP = [list(input().split()) for i in range(N)]

hoge = sorted(SP, key = lambda x:x[1], reverse = True)
SPsort = sorted(hoge, key = lambda x:x[0]

for i in range(N):
    print(SP.index(SPsort[i]) + 1)

Fixed code:
N = int(input())
SP = [list(input().split()) for i in range(N)]

for row in SP:
    row[1] = int(row[1])

hoge = sorted(SP, key = lambda x:x[1], reverse = True)
SPsort = sorted(hoge, key = lambda x:x[0])

for i in range(N):
    print(SP.index(SPsort[i]) + 1)
Buggy code:
from operator import itemgetter

n = int(input())
sp = [list(map(str, input().split())) for i in range(n)]

for i in range(n):
    sp[i].append(i + 1)
    sp[i][1] = int(sp[i][1])

sp.sort()

t = []

t.append(sp[0])

for i in range(n - 1):
    i += 1
    if sp[i][0] == sp[i-1][0]:
        t.append(sp[i])
        print(t)
    else:
        t.sort(key=lambda t: t[1], reverse=True)
        for j in t:
            print(j[2])
        t = []
        t.append(sp[i])

t.sort(key=lambda t: t[1], reverse=True)
for j in t:
    print(j[2])


Fixed code:
from operator import itemgetter

n = int(input())
sp = [list(map(str, input().split())) for i in range(n)]

for i in range(n):
    sp[i].append(i + 1)
    sp[i][1] = int(sp[i][1])

sp.sort()

t = []

t.append(sp[0])

for i in range(n - 1):
    i += 1
    if sp[i][0] == sp[i - 1][0]:
        t.append(sp[i])
    else:
        t.sort(key=lambda t: t[1], reverse=True)
        for j in t:
            print(j[2])
        t = []
        t.append(sp[i])

t.sort(key=lambda t: t[1], reverse=True)
for j in t:
    print(j[2])
Buggy code:
n = int(input())
*a, = [input().split() for i in range(n)]

for i in range(n):
    a[i].append(i+1)

a_point = sorted(a, key = lambda x: x[1], reverse = True)
a_name = sorted(a_point, key = lambda x: x[0])
ans = []
for i in a_name:
    print(i[2])

Fixed code:
n = int(input())
*a, = [input().split() for i in range(n)]

for i in range(n):
    a[i].append(i+1)

a_point = sorted(a, key = lambda x: int(x[1]), reverse = True)

a_name = sorted(a_point, key = lambda x: x[0])

ans = []

for i in a_name:
    print(i[2])
Buggy code:
N = int(input())

xy = []
for i in range(N):
    x, y = map(str, input().split())
    y = int(y)
    xy.append([x, y])

print(xy)

sort_xy = sorted(sorted(xy), key=lambda x: x[1], reverse=True)

for i in range(N):
    for j in range(N):
        if xy[i][0] == sort_xy[j][0]:
            if xy[i][1] == sort_xy[j][1]:
                print(j + 1)
                

Fixed code:
N = int(input())

xy = []
for i in range(N):
    x, y = map(str, input().split())
    y = int(y)
    xy.append([x, y])

sort_xy = sorted(sorted(xy), key=lambda x: (x[0],-x[1]))

for i in range(N):
    for j in range(N):
        if sort_xy[i][0] == xy[j][0]:
            if sort_xy[i][1] == xy[j][1]:
                print(j + 1)
Buggy code:
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[1], reverse = True)
res3 = sorted(res2, key = lambda x:x[0])
for i in range(P):
    print(res.index(res3[i])+1)

Fixed code:
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 code:
N=input()
N=int(N)
S=[100]*N
P=[100]*N
for num in range(N):
    S[num]=input().split()
    S[num].append(num+1)
    S[num][1]=int(S[num][1])
S.sort()
for num in range(N-1):
    if(S[num][0]==S[num+1][0]):
        if(S[num][1]<S[num+1][1]):
            S[num],S[num+1]=S[num+1],S[num]
for num in range(N):
    print(S[num][2])


Fixed code:
N=input()
N=int(N)
S=[100]*N
P=[100]*N
for num in range(N):
    S[num]=input().split()
    S[num].append(num+1)
    S[num][1]=int(S[num][1])

S.sort()
flag=0
flag2=0
while(flag==0):
    flag2=0
    for num in range(0,N-1):
        if(S[num][0]==S[num+1][0]):
            if(S[num][1]<S[num+1][1]):
                S[num],S[num+1]=S[num+1],S[num]
                flag2=1
    if(flag2==0):
        flag=1
    
            

for num in range(N):
    print(S[num][2])
Buggy code:
N = int(input())
l = []
for i in range(N):
    S, P = input().split()
    P = int(P)
    l.append([S, -P, i+1])
l.sort
for l_ in l:
    print(l_[2])

Fixed code:
N = int(input())
l = []
for i in range(N):
    S, P = input().split()
    P = int(P)
    l.append([S, -P, i+1])
l.sort()
for l_ in l:
    print(l_[2])
Buggy code:
n = int(input())
res = []
 
for i in range(n):
    x, y = input().split()
    y = int(y)
    res.append((x, y, i))
 
res.sort(key=lambda x: (x[0], -x[1]))
 
for x, y, i in sp:
    print(i+1)

Fixed code:
n = int(input())
res = []
 
for i in range(n):
    x, y = input().split()
    y = int(y)
    res.append((x, y, i))
 
res.sort(key=lambda x: (x[0], -x[1]))
 
for x, y, i in res:
    print(i+1)
Buggy code:
N = int(input())
A = []
for i in range(1,N+1):
    S,P = input().split()
    A.append((S,P,i))
A = sorted(A,key=lambda x:x[1],reverse=True)
A = sorted(A,key=lambda x:x[0])
for x in A:
    print(x[2])

Fixed code:
N = int(input())
A = []
for i in range(1,N+1):
    S,P = input().split()
    P = int(P)
    A.append((S,P,i))
A = sorted(A,key=lambda x:x[1],reverse=True)
A = sorted(A,key=lambda x:x[0])
for x in A:
    print(x[2])
Buggy code:
n = int(input())
sp = [input().split() for i in range(n)]

sorted_sp = sorted(sp,key = lambda x: int(x[1]), reverse=True)
sorted_sp = sorted(sorted_sp,key = itemgetter(0))

for i in range(n):
    for j in range(n):
        if sp[j] == sorted_sp[i]:
            print(j+1)

Fixed code:
from operator import itemgetter

n = int(input())
sp = [input().split() for i in range(n)]

sorted_sp = sorted(sp,key = lambda x: int(x[1]), reverse=True)
sorted_sp = sorted(sorted_sp,key = itemgetter(0))

for i in range(n):
    for j in range(n):
        if sp[j] == sorted_sp[i]:
            print(j+1)
Buggy code:
#Guide Book https://atcoder.jp/contests/abc128/tasks/abc128_b
N = int(input())
Shop_List=[]
for i in range(N):
    Temp_List=list(input().split())
    Temp_List[1]=int(Temp_List[1])
    Temp_List.append(i+1)
    Shop_List.append(Temp_List)


Shop_List_Sorted = sorted(Shop_List, key=lambda x:(x[0], x[1]))
for k in range(N):
    print(Shop_List_Sorted[k][2])


Fixed code:
#Guide Book https://atcoder.jp/contests/abc128/tasks/abc128_b
N = int(input())
Shop_List=[]
for i in range(N):
    Temp_List=list(input().split())
    Temp_List[1]=int(Temp_List[1])
    Temp_List.append(i+1)
    Shop_List.append(Temp_List)


Shop_List_Sorted = sorted(Shop_List, key=lambda x:(x[0], -x[1]))
for k in range(N):
    print(Shop_List_Sorted[k][2])
Buggy code:
N = int(input())
dic = {}
for i in range(N):
    sp = input().split()
    s = sp[0]
    p = sp[1]
    if s in dic:
        dic[s].append([p,i])
    else:
        dic[s] = [[p,i]]
for key in sorted(dic):
  for j in sorted(dic[key], reverse = True):
    print(j[1]+1)

Fixed code:
N = int(input())
dic = {}
for i in range(N):
    sp = input().split()
    s = sp[0]
    p = int(sp[1])
    if s in dic:
        dic[s].append([p,i])
    else:
        dic[s] = [[p,i]]
for key in sorted(dic):
  for j in sorted(dic[key], reverse = True):
    print(j[1]+1)
Buggy code:
N = int(input())
mydict = []
for i in range(1, N+1):
  a, b=input().split()
  mydict.append([str(a), int(b), i])
mydict = sorted(mydict, key=lambda x:(x[0][1]))
for i in mydict:
  print(i[2])


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

sp=[]
for i in range(n):
    a=list(map(str,input().split()))
    a.append(i+1)
    sp.append(a)
    
sp=sorted(sp,key=lambda x:(x[0],x[1]))

for i in range(len(sp)):
    print(sp[i][2])


Fixed code:

n=int(input())

sp=[]
for i in range(n):
    a=list(map(str,input().split()))
    a.append(i+1)
    sp.append(a)
    
sp=sorted(sp,key=lambda x:int(x[1]),reverse=True)
sp=sorted(sp,key=lambda x:x[0])

for i in range(len(sp)):
    print(sp[i][2])
Buggy code:
N=int(input())
info=[input().split() for i in range(N)] #mojiretu
#print(info)
from operator import itemgetter
dic1={}
for i in range(len(info)):
    dic1[i+1]=info[i]
#print(dic1)
info1=sorted(info,key=itemgetter(1),reverse=True)
info2=sorted(info1,key=itemgetter(0))
#print(info1)
for i in info2:
    for key,value in dic1.items():
        if value==i:
            print(key)


Fixed code:
N=int(input())
info=[input().split() for i in range(N)] #mojiretu
#print(info)
from operator import itemgetter
dic1={}
for i in range(len(info)):
    dic1[i+1]=info[i]
#print(dic1)
info1=sorted(info,key=lambda x:int(x[1]),reverse=True)
info2=sorted(info1,key=itemgetter(0))
#print(info2)
for i in info2:
    for key,value in dic1.items():
        if value==i:
            print(key)
Buggy code:
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N = int(input())
L = []
for i in range(N):
    c, p = input().split()
    p = int(p)
    L.append([i+1, c, p])
L = sorted(L, lambda x: (x[1], -x[2]))
for i in range(N):
    print(L[i][0])


Fixed code:
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N = int(input())
L = []
for i in range(N):
    c, p = input().split()
    p = int(p)
    L.append([i+1, c, p])
L = sorted(L, key=lambda x: (x[1], -x[2]))
for i in range(N):
    print(L[i][0])
Buggy code:
number=int(input())
book=[]
for n in range(number):
    book.append(input().split())

for i in range(len(book)):
    book[i].append(i+1)
    book[i][1]=int(book[i][1])

book1=sorted(book,key=lambda k:-k[1])
book2=sorted(book1,key=lambda k:k[0])
print("book2=",book2)

for i in range(len(book2)):
    print(book2[i][2])

Fixed code:
number=int(input())
book=[]
for n in range(number):
    book.append(input().split())

for i in range(len(book)):
    book[i].append(i+1)
    book[i][1]=int(book[i][1])

book1=sorted(book,key=lambda k:-k[1])
book2=sorted(book1,key=lambda k:k[0])

for i in range(len(book2)):
    print(book2[i][2])
Buggy code:
n = int(input())
di = {}
li = []
for x in range(n):
    input_data = list(input().split())
    if input_data[0] not in di:
        di[input_data[0]] = {int(input_data[1]): x}
        li.append(input_data[0])
    else:
        di[input_data[0]][int(input_data[1])] = x

li.sort()
print(di)
for res in li:
    point_di = di[res]
    point_di_sorted = sorted(point_di.items(), key=lambda x:-x[0])
    for _,rank in point_di_sorted:
        print(rank + 1)


Fixed code:
n = int(input())
di = {}
li = []
for x in range(n):
    input_data = list(input().split())
    if input_data[0] not in di:
        di[input_data[0]] = {int(input_data[1]): x}
        li.append(input_data[0])
    else:
        di[input_data[0]][int(input_data[1])] = x

li.sort()
for res in li:
    point_di = di[res]
    point_di_sorted = sorted(point_di.items(), key=lambda x:-x[0])
    for _,rank in point_di_sorted:
        print(rank + 1)
Buggy code:
N = int(input())
li = [[i+1] + list(input().split()) for i in range(N)]

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

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

li = sorted(li, key=lambda x:(x[1],-int(x[2])))
i = 0
for i in range(N):
    print(li[i][0])
Buggy code:
n=int(input())
s=[]
for i in range(n):
    a=input().split()
    a[1]=int(a[1])
    s.append(a)
s.sort(key=lambda x:(x[0],-x[1]))
print(s)

Fixed code:
n=int(input())
s=[]
for i in range(n):
    a=input().split()
    a[1]=int(a[1])
    a.append(i)
    s.append(a)
s.sort(key=lambda x:(x[0],-x[1]))
for i in range(n):
    print(s[i][2]+1)
Buggy code:
n = int(input())
li = []

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

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

print(li)
for i in range(n):
    print(li[i][2]+1)


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

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

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

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

res = []
for i in range(n):
  city, value = input().split()
  value = int(value)
  res.append([city, value, i])
res_s = sorted(res, key = lambda x: (x[0], x[1]))
for i in range(n):
  res_s[i].append(i+1)
ans = sorted(res_s, key = lambda x: x[2])
for i in range(n):
  print(ans[i][3])

Fixed code:
n = int(input())

res = []
for i in range(n):
  city, value = input().split()
  value = int(value)
  res.append([city, value, i+1])
res_s = sorted(res, key = lambda x: (x[0], -x[1]))
for i in range(n):
  print(res_s[i][2])
Buggy code:
N = int(input())
SP = [list(map(str,input().split())) + [i+1] for i in range(N)]

SP.sort(key = lambda x:x[0])
idx = 0
init = SP[idx][0]
while idx < N:
    D = []
    while idx  < N and SP[idx][0] == init:
        D += [SP[idx]]
        idx += 1
    D.sort(reverse = True,key = lambda x:int(x[1]))
    for i in range(len(D)):
        print(D[i][2])
    idx += 1
    init = SP[min(idx,N-1)][0]
        

    
    

Fixed code:
N = int(input())
SP = [list(map(str,input().split())) + [i+1] for i in range(N)]

SP.sort(key = lambda x:x[0])
idx = 0
init = SP[idx][0]
while idx < N:
    D = []
    while idx  < N and SP[idx][0] == init:
        D += [SP[idx]]
        idx += 1
    D.sort(reverse = True,key = lambda x:int(x[1]))
    for i in range(len(D)):
        print(D[i][2])
    init = SP[min(idx,N-1)][0]
Buggy code:
n = int(input())
ls = [[_ for _ in input().split()] for _ in range(n)]

lss = sorted(ls, key=lambda x: int(x[1]), reverse=True)

ans = sorted(lss, key=lambda x: x[0])
print(ans) 

for i in range(n):
	print(1 + ls.index(ans[i]))

Fixed code:
n = int(input())
ls = [[_ for _ in input().split()] for _ in range(n)]

lss = sorted(ls, key=lambda x: int(x[1]), reverse=True)

ans = sorted(lss, key=lambda x: x[0])

for i in range(n):
	print(1 + ls.index(ans[i]))
Buggy code:
n = int(input())
lst = []
for i in range(n):
    l = input().split()
    lst.append([l[0], int(l[1]), i+1])
sorted_lst = sorted(lst, reverse=True)
print(sorted_lst)
while sorted_lst != []:
    p = sorted_lst.pop()
    temp = []
    while sorted_lst != [] and p[0] == sorted_lst[-1][0]:
        temp.append(sorted_lst.pop())
    while temp != []:
        print(temp.pop()[2])
    print(p[2])

Fixed code:
n = int(input())
lst = []
for i in range(n):
    l = input().split()
    lst.append([l[0], int(l[1]), i+1])
sorted_lst = sorted(lst, reverse=True)
while sorted_lst != []:
    p = sorted_lst.pop()
    temp = []
    while sorted_lst != [] and p[0] == sorted_lst[-1][0]:
        temp.append(sorted_lst.pop())
    while temp != []:
        print(temp.pop()[2])
    print(p[2])
Buggy code:
N = int(input())
X =[]
for i in range(N):
  SS,PP = map(str,input().split())
  X.append([int(i+1), SS, int(PP)])

A = sorted(X, key=lambda X:(X[1],-X[2]))
print (A)

Fixed code:
N = int(input())
X =[]
for i in range(N):
  SS,PP = map(str,input().split())
  X.append([int(i+1), SS, int(PP)])

A = sorted(X, key=lambda X:(X[1],-X[2]))

for i in range(N):
    print(A[i][0])
Buggy code:
n=int(input())
sp=[]
for i in range(n):
    s,p=input().split()
    sp.append([s,int(p),i+1])
    
sort=sorted(sp, key=lambda sp: sp[0], -sp[1])

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

Fixed code:
n=int(input())
sp=[]
for i in range(n):
    s,p=input().split()
    sp.append([s,int(p),i+1])
    
sort=sorted(sp, key=lambda sp: (sp[0], -sp[1]))

for i in sort:
    print(i[2])
Buggy code:
from operator import itemgetter

if __name__ == '__main__':
    n = int(input())
    input_list = [input() for i in range(n)]
    restaurant_list = []
    for index, _input in enumerate(input_list):
        _restaurant_data = {'id': index + 1, 'region': _input.split()[0], 'point': _input.split()[1]}
        restaurant_list.append(_restaurant_data)

    restaurant_list.sort(key=itemgetter('point'), reverse=True)
    restaurant_list.sort(key=itemgetter('region'))
    for restaurant in restaurant_list:
        print(restaurant['id'])


Fixed code:
from operator import itemgetter

if __name__ == '__main__':
    n = int(input())
    input_list = [input() for i in range(n)]
    restaurant_list = []
    for index, _input in enumerate(input_list):
        _restaurant_data = {'id': index + 1, 'region': _input.split()[0], 'point': int(_input.split()[1])}
        restaurant_list.append(_restaurant_data)

    restaurant_list.sort(key=itemgetter('point'), reverse=True)
    restaurant_list.sort(key=itemgetter('region'))
    for restaurant in restaurant_list:
        print(restaurant['id'])