qyliang/CodeNanoFix huggingface dataset:
Buggy code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
l = []
for i in range(n):
    tmp = isl()
    tmp.append(i+1)
    l.append(tmp)
#print(l)
l = sorted(l,key=lambda x:x[1],reverse=True)
#print(l)
l = sorted(l,key=lambda x:x[0])
for j in l:
    print(j[2])

Fixed code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
l = []
for i in range(n):
    tmp = isl()
    tmp.append(i+1)
    l.append(tmp)
#print(l)
l = sorted(l,key=lambda x:int(x[1]),reverse=True)
#print(l)
l = sorted(l,key=lambda x:x[0])
for j in l:
    print(j[2])
Buggy code:
n=int(input())
L=[]
for i in range(n):
    s,p=input().split()
    L.append(s,-int(p),i+1)
for l in sorted(L):
    print(l[2])

Fixed code:
n=int(input())
L=[]
for i in range(n):
    s,p=input().split()
    L.append([s,-int(p),i+1])
for l in sorted(L):
    print(l[2])
Buggy code:
n=int(input())

info=[]

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

info=sorted(info,key=lambda x:x[2],reverse=True)
info=sorted(info,key=lambda x:x[1])

for i in range(n):
  print(info[i][0]+1)

Fixed code:
n=int(input())

info=[]

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

info=sorted(info,key=lambda x:x[2],reverse=True)
info=sorted(info,key=lambda x:x[1])

for i in range(n):
  print(info[i][0]+1)
Buggy code:
N=int(input())
A=[]
for i in range(N):
    D=list(input().split())
    D.append(i+1)
    A.append(D)
B=sorted(A, key=lambda x: x[1])
B.reverse()
C=sorted(B, key=lambda x: x[0])
for i in range(N):
    print(C[i][2])   

Fixed code:
N=int(input())
A=[]
for i in range(N):
    E=list(input().split())
    D=[E[0],int(E[1])]
    D.append(i+1)
    A.append(D)
B=sorted(A, key=lambda x: x[1])
B.reverse()
C=sorted(B, key=lambda x: x[0])
for i in range(N):
    print(C[i][2])
Buggy code:
N=int(input())
List=[[i+1]+input().split() for i in range(N)]
List.sort(key=lambda x:(x[1],int(x[2])))
for s,r,t in List:
          print(s)

Fixed code:
N=int(input())
List=[[i+1]+input().split() for i in range(N)]
List.sort(key=lambda x:(x[1],-int(x[2])))
for s,r,t in List:
          print(s)
Buggy code:
from operator import itemgetter
N = int(input())
childs = [list(input().split()) for _ in range(N)]

a = sorted(childs, key=itemgetter(1), reverse=True)
b = sorted(a, key=itemgetter(0))

for i in b:
    print(childs.index(i)+1)

Fixed code:
from operator import itemgetter
N = int(input())
childs = [list(input().split()) for _ in range(N)]
for i in childs:
    i[1] = int(i[1])

a = sorted(childs, key=itemgetter(1), reverse=True)
b = sorted(a, key=itemgetter(0))

for i in b:
    print(childs.index(i)+1)
Buggy code:
N = int(input())

S = [input().split() +[_+1] for _ in range(N)]

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

now = S[0][0]
pre = []

for i in range(N):
    if now == S[i][0]:
        pre.append(S[i])
    else:
        pre.sort(key=lambda x: x[1],reverse=True)
        for j in range(len(pre)):
            print(pre[j][2])
        pre = [S[i]]
        now = S[i][0]

pre.sort(key=lambda x: x[1],reverse=True)
for j in range(len(pre)):
    print(pre[j][2])

Fixed code:
N = int(input())

S = [input().split() +[_+1] for _ in range(N)]

for i in range(N):
    S[i][1] = int(S[i][1])

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

now = S[0][0]
pre = []

for i in range(N):
    if now == S[i][0]:
        pre.append(S[i])
    else:
        pre.sort(key=lambda x: x[1],reverse=True)
        for j in range(len(pre)):
            print(pre[j][2])
        pre = [S[i]]
        now = S[i][0]

pre.sort(key=lambda x: x[1],reverse=True)
for j in range(len(pre)):
    print(pre[j][2])
Buggy code:
n = int(input())

s = []
for i in range(n):
	S,P=input().split()
    s.append(S,int(P),i+1)

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

for a in ans:
  print(a[2])

Fixed code:
n = int(input())

s = []
for i in range(n):
	S,P=input().split()
	s.append([S,-int(P),i+1])

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

for a in ans:
  print(a[2])
Buggy code:
n = int(input())
ls = []
ls2 = []
count = 0
while count < n:
    ab = input().split()
    a, b = str(ab[0]), int(ab[1])
    ls.append([a, b])
    ls2.append([a, b])
    count = count + 1
ls2.sort(key=lambda x: x[1], reverse=True)
ls2.sort(key=lambda x: x[0])
ans = []
for s in ls:
    for i, hoge in enumerate(ls2):
        if hoge == s:
            ans.append(i+1)
for s in ans:
    print(s)

Fixed code:
n = int(input())
ls = []
ls2 = []
count = 0
while count < n:
    ab = input().split()
    a, b = str(ab[0]), int(ab[1])
    ls.append([a, b])
    ls2.append([a, b])
    count = count + 1
ls2.sort(key=lambda x: x[1], reverse=True)
ls2.sort(key=lambda x: x[0])
ans = []
for s in ls2:
    for i, hoge in enumerate(ls):
        if hoge == s:
            ans.append(i+1)
for s in ans:
    print(s)
Buggy code:
import collections

n = int(input())

scores = collections.defaultdict(list)

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

# print(scores)

for city in sorted(scores):
    sorted_score = sorted(scores[city], key=lambda x: x[1], reverse=True)
    for v in sorted_score:
        print(v[0])


Fixed code:
import collections

n = int(input())

scores = collections.defaultdict(list)

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

# print(scores)

for city in sorted(scores):
    sorted_score = sorted(scores[city], key=lambda x: x[1], reverse=True)
    for v in sorted_score:
        print(v[0])
Buggy code:
N = int(input())
Arr = []
tmp = []
for i in range(N):
    tmp = list(map(str, input().split()))
    tmp.append(i+1)
    Arr.append(tmp)

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

for i in range(N):
    print(Arr[i][2])

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

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

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

lists = []
for _ in range (N):
    S = input().split(' ')
    lists.append(S)

list_sorted = lists.copy()

list_sorted.sort()
list_sorted.sort(key=lambda x:(x[0],x[1]),reverse =True)
for result in range(N):
    for sorted in range (N):
        if lists[result] == list_sorted[sorted]:
            print(sorted+1)


Fixed code:
N = int(input())

lists = []
for _ in range (N):
    S = input().split(' ')
    lists.append([S[0],int(S[1])])

list_sorted = lists.copy()

list_sorted.sort()
list_sorted.sort(key=lambda x:(x[0],-x[1]),reverse =False)
for sorted in range (N):
    for result in range(N):
        if lists[result] == list_sorted[sorted]:
            print(result+1)
Buggy code:
lst = [input().split()+[str(i+1)] for i in range(int(input()))]
print("\n".join([i[2] for i in sorted(lst, key=lambda x:(-1*int(x[1]), x[0]))]))

Fixed code:
lst = [input().split()+[str(i+1)] for i in range(int(input()))]
print("\n".join([i[2] for i in sorted(lst, key=lambda x:(x[0], -1*int(x[1])))]))
Buggy code:
N = int(input())
SP = []
print(SP)
for i in range(N):
    S,P = input().split()
    P = int(P)
    SP.append([S,-P,i+1])

SP.sort()

for i in range(N):
    print(SP[i][2])

Fixed code:
N = int(input())
SP = []

for i in range(N):
    S,P = input().split()
    P = int(P)
    SP.append([S,-P,i+1])

SP.sort()

for i in range(N):
    print(SP[i][2])
Buggy code:
from sys import stdin


def sortFirst(val):
    return val[0]
N=stdin.readline().rstrip()
N=int(N)
l={}
for i in range(1,N+1):
    S,P = stdin.readline().rstrip().split()
    if S in l.keys():
        l[S].append([int(P),i])

    else:
        l[S]=[[int(P),i]]


for key in l.keys():
    l[key].sort(key=sortFirst,reverse=True)
for key in sorted(l):
    for val in l[key]:
        print "%d"%(val[1])


Fixed code:
from sys import stdin


def sortFirst(val):
    return val[0]
N=stdin.readline().rstrip()
N=int(N)
l={}
for i in range(1,N+1):
    S,P = stdin.readline().rstrip().split()
    if S in l.keys():
        l[S].append([int(P),i])

    else:
        l[S]=[[int(P),i]]


for key in l.keys():
    l[key].sort(key=sortFirst,reverse=True)
for key in sorted(l):
    for val in l[key]:
        print(val[1])
Buggy code:
from operator import itemgetter
N = int(input())
S = []
P = []
Num = []
for _ in range(N):
    S1, P1 = [_ for _ in input().split()]
    Num.append(_)
    S.append(S1)
    P.append(P1)
P = [int(_) for _ in P]

c = zip(Num, S, P)
c = sorted(c, key=itemgetter(2))
c = sorted(c, key=itemgetter(1))
Num, S2, P2 = zip(*c)
for i in Num:
    print(i)


Fixed code:
from operator import itemgetter
N = int(input())
S = []
P = []
Num = []
for _ in range(N):
    S1, P1 = [_ for _ in input().split()]
    Num.append(_)
    S.append(S1)
    P.append(P1)
P = [int(_) for _ in P]

c = zip(Num, S, P)
c = sorted(c, key=itemgetter(2), reverse=True)
c = sorted(c, key=itemgetter(1))
Num, S2, P2 = zip(*c)
for i in Num:
    print(i+1)
Buggy code:
a = []
n = int(input())
for i in range(n):
    key,value = input().split()
    a.append((key,value,int(i+1)))
a.sort(key=lambda x:(x[0],not x[1]))
for i in range(n):
    print(a[i][2])

Fixed code:
a = []
n = int(input())
for i in range(n):
    key,value = input().split()
    a.append((key,int(value),int(i+1)))
a.sort(key=lambda x:(x[0],-x[1]))
for i in range(n):
    print(a[i][2])
Buggy code:
n=int(input())
i = 1
alllist = []
while i < n :
  a,b=map(str, input().split())
  c = [a ,int(b),i]
  alllist.append(c)
  i += 1
alllist.sort(key=lambda x:-x[1],reverse=True)
#print(alllist[0][2])
j = 0
while j < n :
  print(alllist[j-1][2])
  j += 1

Fixed code:
n=int(input())
i = 1
alllist = []
while i < n+1 :
  a,b=map(str, input().split())
  c = [a ,int(b),i]
  alllist.append(c)
  i += 1
alllist.sort(key=lambda x:(x[0],-x[1]),reverse=True)
alllist.reverse()
j = 0
while j < n :
  print(alllist[j][2])
  j += 1
Buggy code:
from operator import itemgetter
N=int(input())
SP = [input().split() for l in range(N)]
SP2 = []
for i in range(N):
    SP[i].append(i+1)
    SP2.append(tuple(SP[i]))
    
SP2 = sorted(SP2, key=itemgetter(1),reverse=True)
SP2 = sorted(SP2, key=itemgetter(0))
for j in range(N):
    print(SP2[j][2])


Fixed code:
from operator import itemgetter
N=int(input())
SP = [input().split() for l in range(N)]
SP2 = []
for i in range(N):
    SP[i][1]=int(SP[i][1])
    SP[i].append(i+1)
    SP2.append(tuple(SP[i]))
    
SP2 = sorted(SP2, key=itemgetter(1),reverse=True)
SP2 = sorted(SP2, key=itemgetter(0))
for j in range(N):
    print(SP2[j][2])
Buggy code:
n = int(input())
sp = [None]*n
for i in range(n):
    sp[i] = input().split(" ")
sp = list(map(lambda x: [x[0], int(x[1])], sp))
sl = list(map(lambda x: x[0], sp))
sp2 = []
for s in sorted(list(set(sl))):
    l = list(filter(lambda x: x[0] == s, sp))
    sp2.extend(sorted(l, key=lambda x:x[1], reverse=True))
for x in sp:
    print(sp2.index(x)+1)


Fixed code:
n = int(input())
sp = [None]*n
for i in range(n):
    sp[i] = [input().split(" "), i+1]
sp = list(map(lambda x: [[x[0][0], int(x[0][1])], x[1]], sp))
sl = list(map(lambda x: x[0][0], sp))
sp2 = []
for s in sorted(list(set(sl))):
    l = list(filter(lambda x: x[0][0] == s, sp))
    sp2.extend(sorted(l, key=lambda x:x[0][1], reverse=True))
for x in sp2:
    print(x[1])
Buggy code:
import sys
input = sys.stdin.readline
n = int(input())
print(n)
b = [list(map(str,input().split())) for p in [0]*n]
for i in range(n):
	b[i][1] = int(b[i][1])
	b[i].append(i+1)
print(b)
b.sort(key=lambda q:(q[0],-q[1]))
for k in range(n):
	print(b[k][2])

Fixed code:
import sys
input = sys.stdin.readline
n = int(input())
b = [list(map(str,input().split())) for p in [0]*n]
for i in range(n):
  b[i][1] = int(b[i][1])
  b[i].append(i+1)
b.sort(key=lambda q:(q[0],-q[1]))
for k in range(n):
  print(b[k][2])
Buggy code:
n = int(input())
sp = [[i+1] + list(input().split()) for i in range(n)]

for sorted_sp in sorted(sp, key=lambda x: (x[1], -int(x[2]))):
    print(sorted_sp)

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

for sorted_sp in sorted(sp, key=lambda x: (x[1], -int(x[2]))):
    print(sorted_sp[0])
Buggy code:
n = int(input())
s = list(i, int(j) for i, j in input().split()
ans = [s.index(i)+1 for i in sorted(s, key=lambda x:(x[0], -x[1]))]
print(i) for i in ans


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

list=sorted(l,key=lambda x:(x[0],x[1]))
for i in list:
  print(l[2])


Fixed code:
N=int(input())
l=[]
for i in range(N):
  s,p=input().split(" ")
  l.append((s,-int(p),i+1))
 
l2=sorted(l,key=lambda x:(x[0],x[1]))
for l in l2:
  print(l[2])
Buggy code:
N = int(input())
list = [None]*N
for i in range(N):
  s, P = input().split()
  list[i]=(i,s,int(p)*-1)
for i in sorted(list, key = lamda x: (x[1],x[2])):
  print(i[0]+1)

Fixed code:
N = int(input())
list = [None]*N
for i in range(N):
  s, p = input().split()
  list[i]=(i,s,int(p)*-1)
for i in sorted(list, key = lambda x: (x[1],x[2])):
  print(i[0]+1)
Buggy code:
n = int(input())
r = []
for i in range(n):
    s,p = input().split()
    p = int(p)
    r.append([s,p,i])
a = sorted(r)
for i in range(n):
    print(a[i][2]+1)

Fixed code:
n = int(input())
r = []
for i in range(n):
    s,p = input().split()
    p = -int(p)
    r.append([s,p,i])
a = sorted(r)
for i in range(n):
    print(a[i][2]+1)
Buggy code:
n=int(input())
sp_lis=[]
s,p=input().split()
for i in range(1,n+1):
  sp_lis.append([s,100-p,i])
for j in range(n)
print(sorted(sp_lis[j][2]))

Fixed code:
n=int(input())
sp_lis=[]
for i in range(n):
    s,p=input().split()
    sp_lis.append([s,100-int(p),i+1])
sp_lis.sort()
for j in range(n):
    print(sp_lis[j][2])
Buggy code:
import copy
N = int(input())
SP = [[] for _ in range(N)]
for i in range(N):
    SP[i] = list(input().split())
    SP[i][1] = int(SP[i][1])
    
unique = list(set(s[0] for s in SP))
unique.sort(reverse=True)
for i, uni in enumerate(unique):
    for j, S in enumerate(SP):
        if uni == S[0]:
            S[0] = i

print(SP)
copy_SP = copy.copy(SP)
SP.sort(reverse=True)
for i, c in enumerate(SP):
    for j, sp in enumerate(copy_SP):
        if c == sp:
            print(j+1)

Fixed code:
import copy
N = int(input())
SP = [[] for _ in range(N)]
for i in range(N):
    SP[i] = list(input().split())
    SP[i][1] = int(SP[i][1])
    
unique = list(set(s[0] for s in SP))
unique.sort(reverse=True)
for i, uni in enumerate(unique):
    for j, S in enumerate(SP):
        if uni == S[0]:
            S[0] = i

copy_SP = copy.copy(SP)
SP.sort(reverse=True)
for i, c in enumerate(SP):
    for j, sp in enumerate(copy_SP):
        if c == sp:
            print(j+1)
Buggy code:
N = int(input())
A = []
B = []
for i in range(N):
    n,a=input().split()
    A.append(n)
    B.append(int(a))
for i in range(N):
    c = i
    for k in range(i+1,N):
        if A[i] > A[k]:
            l = B[k]
            B[k] = B[i]
            B[i] = l
            l = A[k]
            A[k] = A[i]
            A[i] = l
            c = k
        elif A[i] == A[k]:
            if B[i] < B[k]:
                l = B[k]
                B[k] = B[i]
                B[i] = l
                l = A[k]
                A[k] = A[i]
                A[i] = l
                c = k

    print(c+1)



Fixed code:
N = int(input())
A = []
B = []
C = []
for i in range(N):
    n,a=input().split()
    A.append(n)
    B.append(int(a))  
    C.append(i)
for i in range(N):
    c = i
    for k in range(i+1,N):
        if A[i] > A[k]:
            l = B[k]
            B[k] = B[i]
            B[i] = l
            l = A[k]
            A[k] = A[i]
            A[i] = l
            l = C[k]
            C[k] = C[i]
            C[i] = l
            
        elif A[i] == A[k]:
            if B[i] < B[k]:
                l = B[k]
                B[k] = B[i]
                B[i] = l
                l = A[k]
                A[k] = A[i]
                A[i] = l
                l = C[k]
                C[k] = C[i]
                C[i] = l
               

    
for i in range(N):
    print(C[i]+1)
Buggy code:
N = int(input())
List = [list(map(int,input().split())) for i in range(N)]

for i in range(N):
    List[i].append(i+1)
List.sort(key=lambda x:x[1], reverse=True)
List.sort(key=lambda x:x[0])
for i in range(N):
    print("{}".format(List[i][2]))

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

for i in range(N):
    List[i].append(i+1)
    List[i][1] = int(List[i][1])
List.sort(key=lambda x:x[1], reverse=True)
List.sort(key=lambda x:x[0])
for i in range(N):
    print("{}".format(List[i][2]))
Buggy code:
#from IPython import embed
N=int(input())
n = []

from collections import Counter

c = Counter()

for i in range(N):
    k = input().split()
    k.append(i+1)
    n.append(k)
    c.update([k[0]])



n.sort()
#n = n[::-1]
prev = ""
l = []
cnt = 0
#print(c)
for a in n:
    #print(a)

    if c[a[0]] > 1:
        l.append(a[1:])
        #print(a[1:])
        cnt+=1
        #print(a[0])
        #embed()
        if cnt == c[a[0]]:
            l.sort()
            #print(l)
            for i in l[::-1]:
                print(i[1])
            cnt = 0
            l = []
    else:
        print(a[2])


Fixed code:
#from IPython import embed
N=int(input())
n = []

from collections import Counter

c = Counter()

for i in range(N):
    k = input().split()
    k[1] = int(k[1])
    k.append(i+1)
    n.append(k)
    c.update([k[0]])



n.sort()
#n = n[::-1]
prev = ""
l = []
cnt = 0
#print(c)
for a in n:
    #print(a)

    if c[a[0]] > 1:
        l.append(a[1:])
        #print(a[1:])
        cnt+=1
        #print(a[0])
        #embed()
        if cnt == c[a[0]]:
            l.sort()
            #print(l)
            for i in l[::-1]:
                print(i[1])
            cnt = 0
            l = []
    else:
        print(a[2])
Buggy code:
N = int(input())
Rests = [input().split() for l in range(N)]
sorted_rests = sorted(Rests, key=lambda x:(x[1]), reverse=True)
sorted_rests = sorted(sorted_rests, key=lambda x:(x[0]), reverse=False)
for i in sorted_rests:
    print(Rests.index(i) + 1)


Fixed code:
N = int(input())
Rests = [input().split() for l in range(N)]
sorted_rests = sorted(Rests, key=lambda x:(int(x[1])), reverse=True)
sorted_rests = sorted(sorted_rests, key=lambda x:(x[0]), reverse=False)
for i in sorted_rests:
    print(Rests.index(i) + 1)
Buggy code:
n=int(input())
l=[]
for i in range(n):
    l.append(list(input().split())+[i+1])
l=sorted(l, key=lambda x: x[0])
s=sorted(set([x[0] for x in l]))
for c in s:
    x=sorted([a for a in l if a[0]==c], key=lambda x: x[1])[::-1]
    for a in x:
        print(a[2])

Fixed code:
n=int(input())
l=[]
for i in range(n):
    l.append(list(input().split())+[i+1])
l=sorted(l, key=lambda x: x[0])
s=sorted(set([x[0] for x in l]))
for c in s:
    x=sorted([a for a in l if a[0]==c], key=lambda x: int(x[1]))[::-1]
    for a in x:
        print(a[2])
Buggy code:
n=int(input())
l=[[i+1] for i in range(n)]
for i in range(n):
    l[i]+=list(input().split(' '))
print(l)
l.sort(key=lambda x:x[2],reverse=True)
l.sort(key=lambda x:x[1])
for i in range(n):
    print(l[i][0])

Fixed code:
n=int(input())
l=[[i+1] for i in range(n)]
for i in range(n):
    l[i]+=list(input().split(' '))
    l[i][2]=int(l[i][2])
#print(l)
l.sort(key=lambda x:x[2],reverse=True)
l.sort(key=lambda x:x[1])
for i in range(n):
    print(l[i][0])
Buggy code:
n=int(input())
l1=[]
l2=[]
for i in range(n):
    sp=input().rstrip().split()
    l1.append(sp[0])
    l2.append(-int(sp[1]))
l=list(zip(l1,l2))

ans=sorted(l)
print(ans)
for i in range(len(ans)):
    print(l.index(ans[i])+1)





Fixed code:
n=int(input())
l1=[]
l2=[]
for i in range(n):
    sp=input().rstrip().split()
    l1.append(sp[0])
    l2.append(-int(sp[1]))
l=list(zip(l1,l2))

ans=sorted(l)

for i in range(len(ans)):
    print(l.index(ans[i])+1)
Buggy code:
n = int(input())
citynames = set()
citydict = dict()

for i in range(n):
  s,p = input().split()
  citynames.add(s)
  if not s in citydict:
    citydict[s] = [(int(p), i)]
  else:
    citydict[s].append((int(p), i))

for name in sorted(citynames):
  for point in sorted(citydict[name], reverse=True):
    print(point[1])

Fixed code:
n = int(input())
citynames = set()
citydict = dict()

for i in range(n):
  s,p = input().split()
  citynames.add(s)
  if not s in citydict:
    citydict[s] = [(int(p), i)]
  else:
    citydict[s].append((int(p), i))

for name in sorted(citynames):
  for point in sorted(citydict[name], reverse=True):
    print(point[1]+1)
Buggy code:
N = int(input())
s = []
for i in range(N):
    tmp = input().split()
    tmp .append(i+1)
    s.append(tmp)


s.sort(key=lambda x: x[1], reverse=True)
s.sort(key=lambda x: x[0])
for x in s:
    print(x[2])

Fixed code:
N = int(input())
s = []
for i in range(N):
    tmp = input().split()
    tmp .append(i+1)
    tmp[1] = int(tmp[1])
    s.append(tmp)

s.sort(key=lambda x: x[1], reverse=True)
s.sort(key=lambda x: x[0])
for x in s:
    print(x[2])
Buggy code:
n = input()
a = []
for i in range(n):
    city,core = input().split()
    a.append((city,score,i+1))
a.sort(key=lambda k: (k[1],-k[0]))

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

Fixed code:
n = int(input())
a= []
for i in range(n):
	city, score = input().split()
	score = int(score)
	a.append((city, score, i+1))
a.sort(key=lambda k : (k[0], -k[1]))
for i in range(n):
	print(a[i][2])
Buggy code:
N = int(input())
SP = [0]*N
for n in range(N):
    SP[n] = list(input().split())+ [n+1]

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

for sp in SP:
    print(sp[2])

Fixed code:
N = int(input())
SP = [0]*N
for n in range(N):
    SP[n] = list(input().split())+ [n+1]

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

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

for sp in SP:
    print(sp[2])
Buggy code:
N = int(input())
R = []
for i in range(N):
    s, p = input().split()
    R.append((s, -int(p), i))

R.sort()
print(R)
for i in R:
    print(i[2] + 1)


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

R.sort()
for i in R:
    print(i[2] + 1)
Buggy code:
N = int(input())
SPlist = []
for i in range(N):
    buff  = input().split()
    SPlist.append([i+1,str(buff[0]),int(buff[1])])
print(SPlist)
SPlist = sorted(SPlist,key = lambda x:x[2],reverse=True)
SPlist = sorted(SPlist,key=lambda x:x[1])
[print(i[0]) for i in SPlist]

Fixed code:
N = int(input())
SPlist = []
for i in range(N):
    buff  = input().split()
    SPlist.append([i+1,str(buff[0]),int(buff[1])])
SPlist = sorted(SPlist,key = lambda x:x[2],reverse=True)
SPlist = sorted(SPlist,key=lambda x:x[1])
[print(i[0]) for i in SPlist]
Buggy code:
N = int(input())
B = []
for i in range(N):
    s,p = map(str,input().split())
    tmp = [i+1,s,int(p)]
    B.append(tmp)
B.sort(key=lambda x:x[2],reverse=True)
B.sort(key=lambda x:x[1])
print(B)
for x in B:
    print(x[0])


Fixed code:
N = int(input())
B = []
for i in range(N):
    s,p = map(str,input().split())
    tmp = [i+1,s,int(p)]
    B.append(tmp)
B.sort(key=lambda x:x[2],reverse=True)
B.sort(key=lambda x:x[1])
for x in B:
    print(x[0])
Buggy code:
from operator import itemgetter

n=int(input())
list1=[]
for i in range(n):
    a=list(input().split())
    a.append(i)
    list1.append(a)
 
list1.sort(reverse=True,key=itemgetter(1))
list1.sort(key=itemgetter(0))

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

Fixed code:
from operator import itemgetter

n=int(input())
list1=[]
for i in range(n):
    a=list(input().split())
    a[1]=int(a[1])
    a.append(i)
    list1.append(a)

    

list1.sort(reverse=True,key=itemgetter(1))
list1.sort(key=itemgetter(0))

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