qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())
T = [input().split() for _ in range(n)]
ans = list(range(1, n + 1))

for i in range(n):
    j = i
    while j > 0:
        if T[j][0] < T[j - 1][0]:
            T[j], T[j - 1] = T[j - 1], T[j]
            ans[j], ans[j - 1] = ans[j - 1], ans[j]
            j = j - 1
        else:
            break

for i in range(n):
    j = i
    while j > 0:
        if int(T[j][1]) > int(T[j - 1][1]) and T[j][0] == T[j - 1][0]:
            T[j], T[j - 1] = T[j - 1], T[j]
            ans[j], ans[j - 1] = ans[j - 1], ans[j]
            j = j - 1
        else:
            break


print(ans)

Fixed code:
n = int(input())
T = [input().split() for _ in range(n)]
ans = list(range(1, n + 1))

for i in range(n):
    j = i
    while j > 0:
        if T[j][0] < T[j - 1][0]:
            T[j], T[j - 1] = T[j - 1], T[j]
            ans[j], ans[j - 1] = ans[j - 1], ans[j]
            j = j - 1
        else:
            break

for i in range(n):
    j = i
    while j > 0:
        if int(T[j][1]) > int(T[j - 1][1]) and T[j][0] == T[j - 1][0]:
            T[j], T[j - 1] = T[j - 1], T[j]
            ans[j], ans[j - 1] = ans[j - 1], ans[j]
            j = j - 1
        else:
            break


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

sList = []
for i in range(n):
  sList.append(list(input().split())+[i+1])
  sList[i][1] = -1*int(sList[i][1])
sList.sort()

print(sList)
for i in sList:
  print(i[2])


Fixed code:
n = int(input())

sList = []
for i in range(n):
  sList.append(list(input().split())+[i+1])
  sList[i][1] = -1*int(sList[i][1])
sList.sort()

for i in sList:
  print(i[2])
Buggy code:
from collections import defaultdict


def main():
    D = defaultdict(list)
    names = set()
    N = int(input())
    for i in range(1, N+1):
        inp = input().split()
        s = inp[0]
        p = inp[1]
        names.add(s)
        D[s].append((p, i))
    names = sorted(list(names))
    for n in names:
        D[n].sort(key=lambda x: x[0], reverse=True)
        for x in D[n]: print(x[1])


if __name__ == '__main__':
    main()


Fixed code:
from collections import defaultdict


def main():
    D = defaultdict(list)
    names = set()
    N = int(input())
    for i in range(1, N+1):
        inp = input().split()
        s = inp[0]
        p = inp[1]
        names.add(s)
        D[s].append((p, i))
    names = sorted(list(names))
    for n in names:
        D[n].sort(key=lambda x: int(x[0]), reverse=True)
        for x in D[n]: print(x[1])


if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
l = [[i+1]+input().split() for i in range(n) ]


l.sort(key=lambda x: [x[1],-1*x[2]])

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

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

l.sort(key=lambda x: (x[1],(x[2]*-1)))

for i in range(n):
    print(l[i][0])
Buggy code:
N = int(input())
sp = []
for i in range(N):
  s, p = input().split()
  sp.append([s, int(p), i+1])
sp1 = sorted(sp, key = lambda x: x[0])
sp2 = sorted(sp1, key = lambda x: -1*x[1])
for i in range(N):
  print(sp2[i][2])
  

Fixed code:
N = int(input())
sp = []
for i in range(N):
  s, p = input().split()
  sp.append([s, int(p), i+1])
sp1 = sorted(sp, key = lambda x: (x[0], -1*x[1]))
for i in range(N):
  print(sp1[i][2])
Buggy code:
N = int(input())
Ss, Ps = [ [], [] ]
for i in range(N):
    s, p = input().split(" ")
    Ss.append(s)
    Ps.append(int(p))
rests = list(zip(range(1, N+1), Ss, Ps))
rests.sort(key=lambda x: (x[1], -x[2]))
print(rests)
print('\n'.join([str(i) for i,_,_ in rests]))


Fixed code:
N = int(input())
Ss, Ps = [ [], [] ]
for i in range(N):
    s, p = input().split(" ")
    Ss.append(s)
    Ps.append(int(p))
rests = list(zip(range(1, N+1), Ss, Ps))
rests.sort(key=lambda x: (x[1], -x[2]))
print('\n'.join([str(i) for i,_,_ in rests]))
Buggy code:
n = int(input())
r = [list(map(int, input().split())).append(i+1) for i in range(n)] 
tmp = sorted(r, key=lambda x:x[1], reverse=True)
res = sorted(tmp, key=lambda x:x[0])
for arr in res:
  print(arr[2])

Fixed code:
n = int(input())
r = []
for i in range(1, n+1):
  hoge = input().split()
  hoge.append(i)
  r.append(hoge) 
tmp = sorted(r, key=lambda x:int(x[1]), reverse=True)
res = sorted(tmp, key=lambda x:x[0])
for arr in res:
  print(arr[2])
Buggy code:
N = int(input())
assign = []
for index in range(1,N+1):
    S, P = map(str, input().split())
    P = int(P)
    assign.append([S, P, index])

assign = sorted(assign, key=lambda x:(x[0], -x[1]))
print(assign)

Fixed code:
N = int(input())
assign = []
for index in range(1,N+1):
    S, P = map(str, input().split())
    P = int(P)
    assign.append([S, P, index])

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

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

eva_list = []

for i in range(N):
    key, value = input().split()
    eva_list.append([key,value,i+1])

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

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

Fixed code:
N = int(input())

eva_list = []

for i in range(N):
    key, value = input().split()
    eva_list.append([key,int(value),i+1])

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

for i in range(N):
    print(eva_list[i][2])
Buggy code:
n = int(input())
r = []
for i in range(n):
    city, score = map(str, input().split())
    score = int(score)
    r.append((city, score, i+1))

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

for x in r:
    print(x[2])


Fixed code:
n = int(input())
r = []
for i in range(n):
    city, score = map(str, input().split())
    score = int(score)
    r.append((city, score, i+1))

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

for x in r:
    print(x[2])
Buggy code:
N = int(input())

SP = []
for i in range(N):
    str = input().split()
    SP.append([str[0] ,int(str[1])*-1,i])

SP.sort()

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

Fixed code:
N = int(input())

SP = []
for i in range(N):
    str = input().split()
    SP.append([str[0] ,int(str[1])*-1,i])

SP.sort()

for i in range(N):
    print(SP[i][2]+1)
Buggy code:
n = int(input())
SP = []
for i in range(n):
    s,p = input().split()
    SP.append([i+1,s,int(p)])
    
from operator import itemgetter

SP.sort(key = itemgetter(2))
SP.sort(key = itemgetter(1))
for j,s,p in SP:
    print(j)

Fixed code:
n = int(input())
SP = []
for i in range(n):
    s,p = input().split()
    SP.append([i+1,s,int(p)])
    
from operator import itemgetter

SP.sort(key = itemgetter(2),reverse = True)
SP.sort(key = itemgetter(1))
for j,s,p in SP:
    print(j)
Buggy code:
A=[]
p = int(input())
for i in range(p):
  j,k = input().split()
  A.append([j,k,i+1])
A = sorted(A)
for j,k,l in A:
  print(l)

Fixed code:
A=[]
p = int(input())
for i in range(p):
  j,k = input().split()
  A.append([j,-int(k),i+1])
A = sorted(A)
for j,k,l in A:
  print(l)
Buggy code:
r_list = []
ans_list = []
N = int(input())
for i in range(1, N+1):
    Si, Pi = input().split()
    r_list.append((Si, int(Pi), i))
    
name_sorted_list = sorted(r_list, key=lambda x:x[0])
while len(name_sorted_list) > 0:
    test_list = []
    list_index = [i for i, x in enumerate(name_sorted_list) if x  == name_sorted_list[0]]
    for i in list_index:
        test_list.append(name_sorted_list[i])
        del name_sorted_list[i]
    test_list = sorted(test_list, key=lambda x:x[1], reverse = True)
    for item in test_list:
        ans_list.append(item)

for item in ans_list:
    print(item[2])

Fixed code:
r_list = []
ans_list = []
N = int(input())
for i in range(1, N+1):
    Si, Pi = input().split()
    r_list.append((Si, int(Pi), i))
    
name_sorted_list = sorted(r_list, key=lambda x:x[0])

while len(name_sorted_list) > 0:
    test_list = []
    list_index = [i for i, x in enumerate(name_sorted_list) if x[0]  == name_sorted_list[0][0]]
    for i in list_index:
        test_list.append(name_sorted_list[i])
    for i in reversed(list_index):
        del name_sorted_list[i]
    test_list = sorted(test_list, key=lambda x:x[1], reverse = True)
    for item in test_list:
        ans_list.append(item)
    
for item in ans_list:
    print(item[2])
Buggy code:
n=input()
a=[input().split() + [i+1] for i in range(n)]
for i in range(n):
  a[i][1]= -int(a[i][1])
a.sort()
for i in range(n):
  print(a[i][2])

Fixed code:
n=int(input())
a=[input().split() + [i+1] for i in range(n)]
for i in range(n):
  a[i][1]= -int(a[i][1])
a.sort()
for i in range(n):
  print(a[i][2])
Buggy code:
N = int(input())
SP = [input().split()+[0] for _ in range(N)]
r = []
for x, y, z in SP:
  r.append([x, int(y), z])

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

g = 1
for i in range(N):
  sortK[i][2] = g
  g += 1

for c in r:
  print(c[2])

Fixed code:
N = int(input())
SP = [input().split() for _ in range(N)]
r = []
g= 1
for x, y in SP:
  r.append([x, int(y), g])
  g+=1

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

for x, y,z in sortK:
  print(z)
Buggy code:
N = int(input())
list=[]
for i in range(N):
    s, p = input().split()
    list.append([s, int(p)])
A=list
list.sort(key=lambda, list:(list[0], -list[1]))
for i in A:
    print(list.index(i)+1)

Fixed code:
N = int(input())
list=[]
for i in range(N):
    s, p = input().split()
    list.append([s, int(p), i+1])
list.sort(key=lambda list:(list[0], -list[1]))
for i in list:
    print(i[2])
Buggy code:
N = int(input())
A = [0 for i in range(N)]
for i in range(N):
    A[i] = list(map(str,input().split()))

B = sorted(A, key=lambda x: x[1], reverse=True)

C = sorted(B, key=lambda x: x[0])

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

Fixed code:

N = int(input())
A = [0 for i in range(N)]
for i in range(N):
    A[i] = list(map(str,input().split()))
for i in range(N):
    A[i].append(str(i+1))
for i in range(N):
    A[i][1] = int(A[i][1]) 


B = sorted(A, key=lambda x: x[1], reverse=True)

C = sorted(B, key=lambda x: x[0])

for i in range(N):
    print(int(C[i][2]))
Buggy code:
n = int(input())
sp = [list(map(int, input().split())) for _ in range(n)]

d = sorted(sp, key=lambda x:(x[0],-x[1]))
for i in range(len(sp)):
    print(sp.index(d[i]))

Fixed code:
n = int(input())
sp = [list(input().split()) for _ in range(n)]
for i in range(len(sp)):
    sp[i][1] = int(sp[i][1])
d = sorted(sp, key=lambda x:(x[0],-x[1]))
for i in range(len(sp)):
    print(sp.index(d[i])+1)
Buggy code:
n = int(input())

cities = []
for i in range(1, n+1):
    a,b = input().split()
    b = int(b)
    cities.append([i, a, b])
    
cities = sorted(cities, key=lambda x : x[2])
print(cities)
cities.reverse()
print(cities)
cities = sorted(cities, key=lambda x: x[1])
print(cities)
for i in cities:
    print(i[0])

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

sorted_SP = sorted(SP, key=lambda x:x[1], reverxe=True)
sorted_SP = sorted(sorted_SP, key=lambda x:x[0])

for i in range(N):
  for j in range(N):
    if SP[i][0] == SP[j][0] and SP[i][1] == SP[j][1]:
      print(j+1)
      break


Fixed code:
N = int(input())
SP = [list(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=lambda x:x[0])

for i in range(N):
  for j in range(N):
    if sorted_SP[i][0] == SP[j][0] and sorted_SP[i][1] == SP[j][1]:
      print(j+1)
      break
Buggy code:
from operator import itemgetter

N = int(input())

news = []

for i in range(N):
  hoge = input().split()
  news.append((str(hoge[0]),int(hoge[1])))

b = sorted(news, key=itemgetter(1), reverse=True)
c = sorted(b, key=itemgetter(0))
print(c)

for i in range(N):
  for j in range(N):
    if c[i] ==news[j]:
      print(j+1)


Fixed code:
from operator import itemgetter

N = int(input())

news = []

for i in range(N):
  hoge = input().split()
  news.append((str(hoge[0]),int(hoge[1])))

b = sorted(news, key=itemgetter(1), reverse=True)
c = sorted(b, key=itemgetter(0))

for i in range(N):
  for j in range(N):
    if c[i] ==news[j]:
      print(j+1)
Buggy code:
n = int(input())

s = {}
for i in range(n):
    a, b=input().split()
    if a in s:
        s[a].append((i+1, int(b)))
    else:
        s[a]=[(i+1, int(b))]

print(s)
for key in sorted(s):
    for i, score in sorted(s[key], key=lambda t:~t[1]):
        print(i)


Fixed code:
n = int(input())

s = {}
for i in range(n):
    a, b=input().split()
    if a in s:
        s[a].append((i+1, int(b)))
    else:
        s[a]=[(i+1, int(b))]

for key in sorted(s):
    for i, score in sorted(s[key], key=lambda t:~t[1]):
        print(i)
Buggy code:
N = int(input())
SP = []
a = 1
for i in range(N):
    SP.append(input().split())
for i in SP:
    i.append(a)
    a += 1
SP.sort(reverse=True)
SP.sort(key=lambda x: x[0])
for i in range(N):
    print(SP[i][2])

Fixed code:
N = int(input())
SP = []
a = 1
for i in range(N):
    SP.append(input().split())
for i in SP:
    i.append(a)
    a += 1
for i in range(N):
    SP[i][1] = int(SP[i][1])
SP.sort(reverse=True)
SP.sort(key=lambda x: x[0])
for i in range(N):
    print(SP[i][2])
Buggy code:
N = int(input())
ls = []
for i in range(N):
  s, p = input().split()
  ls.append((s,-int(p),i+1)) # reverse point for downer sort , and memorize order i+1
ls.sort()
print(ls) # for debug
for r in ls:
  print(r[2])


Fixed code:
N = int(input())
ls = []
for i in range(N):
  s, p = input().split()
  ls.append((s,-int(p),i+1)) # reverse point for downer sort , and memorize order i+1
ls.sort()
#print(ls) # for debug
for r in ls:
  print(r[2])
Buggy code:
print('\n'.join([s[2] for s in sorted([input().split() + [i + 1] for i in range(int(input()))], key=lambda x:(x[0], -int(x[1])))]))

Fixed code:
print('\n'.join([l[2] for l in sorted(sorted([[l[0], -int(l[1]), str(l[2] + 1)] for l in [input().split() + [i] for i in range(int(input()))]], key=lambda x: x[1]), key=lambda x: x[0])]))
Buggy code:
print('\n'.join([l[2] for l in sorted(sorted([[l[1][0], int(l[1][1]), l[0] + 1] for l in enumerate(input().split() for _ in range(int(input())))], key=lambda l: l[1], reverse=True), key=lambda l: l[0])]))

Fixed code:
print('\n'.join([l[2] for l in sorted(sorted([[l[1][0], int(l[1][1]), str(l[0] + 1)] for l in enumerate(input().split() for _ in range(int(input())))], key=lambda l: l[1], reverse=True), key=lambda l: l[0])]))
Buggy code:
N = int(input())
R = []
for i in range(N):
  l = input().split()
  R.append((l[0], (-1)*int(l[1]), i))

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

Fixed code:
N = int(input())
R = []
for i in range(N):
  l = input().split()
  R.append((l[0], (-1)*int(l[1]), i))

R.sort()
for i in range(N):
  print(R[i][2]+1)
Buggy code:
# -*- coding: utf-8 -*-

n = int(input())
sp = ["" for _ in range(n)]

for i in range(n):
    sp[i] = list(map(str, input().split()))
    sp[i].insert(2, i+1)
#print(sp)

sp2 = sorted(sp, key=lambda x:x[1], reverse=True)
#print(sp2)

sp3 = sorted(sp2, key=lambda x:x[0], reverse=False)
#print(sp3)

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

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

n = int(input())
sp = ["" for _ in range(n)]

for i in range(n):
    a, b = map(str, input().split())
    sp[i] = [a, int(b)]
    sp[i].insert(2, i+1)
#print(sp)

sp2 = sorted(sp, key=lambda x:x[1], reverse=True)
#print(sp2)

sp3 = sorted(sp2, key=lambda x:x[0], reverse=False)
#print(sp3)

for i in range(len(sp3)):
    print(sp3[i][2])
Buggy code:
N = int(input())
l = []
for i in range(N):
    a,b = input().split()
    l.append((a,-int(b),i+1))
    print(l)
l.sort()
for a,b,k in l:
    print(k)

Fixed code:
N = int(input())
l = []
for i in range(N):
    a,b = input().split()
    l.append((a,-int(b),i+1))
l.sort()
for a,b,k in l:
    print(k)
Buggy code:
import sys

def main():
    num = int(sys.stdin.readline())
    
    input = [None] * num

    for i in range(num):
        read = sys.stdin.readline().split()
        input[i] = [i, read[0], int(read[1])]

    input.sort(key=lambda x:(x[1], x[2]))

    for restaurant in input:
        print(restaurant[0])

if __name__ == "__main__":
    main()


Fixed code:
import sys

def main():
    num = int(sys.stdin.readline())
    
    input = [None] * num

    for i in range(num):
        read = sys.stdin.readline().split()
        input[i] = [i+1, read[0], int(read[1])]

    input.sort(key=lambda x:(x[1], -x[2]))

    for restaurant in input:
        print(restaurant[0])

if __name__ == "__main__":
    main()
Buggy code:
import sys
args = sys.stdin.readlines()
N = int(args[0])
d = {}
for i, line in enumerate(args[1:]):
  S, p = line.split(' ')
  P = int(p)
  if S in d:
    d[S].append((i+1, P))
  else:
    d[S] = []
    d[S].append((i+1, P))
    
for key in d.keys():
    d[key].sort(key=lambda x:x[1], reverse=True)
    for (i, p) in d[key]:
        print(i)

Fixed code:
import sys
args = sys.stdin.readlines()
N = int(args[0])
d = {}
for i, line in enumerate(args[1:]):
  S, p = line.split(' ')
  P = int(p)
  if S in d:
    d[S].append((i+1, P))
  else:
    d[S] = []
    d[S].append((i+1, P))
    
for key in sorted(d.keys()):
    d[key].sort(key=lambda x:x[1], reverse=True)
    for (i, p) in d[key]:
        print(i)
Buggy code:
n=int(input())
l=[]
for i in range(n):
  s,p=map(int,input().split())
  l.append([i+1,s,p])
l.sort(key=lambda x:x[2],reverse=True)
l.sort(key=lambda x:x[1])
for ll in l:
  print(ll[0])

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

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

data = sorted(data, key=itemgetter(1), reverse=True)
data = sorted(data, key=itemgetter(0), reverse=False)

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

Fixed code:
from operator import itemgetter

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

data = sorted(data, key=itemgetter(1), reverse=True)
data = sorted(data, key=itemgetter(0), reverse=False)

for i in range(n):
    print(data[i][2])
Buggy code:
n=int(input())
lists=[list(input().split()) for x in range(n)]
for x in range(n):
  lists[x].append(x+1)
lists.sort(key=lambda t:t[1],reverse=True)
lists.sort(key=lambda t:t[0])
for x in range(n):
  print(lists[x][2])

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

l.sort()
for i in l:
    print(i[2])

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

l.sort()
for i in l:
    print(i[2])
Buggy code:
n = int(input())
SPN = []
for i in range(n):
    s,p = input().split()
    SPN.append([s,int(p),i+1])
SPN = sorted(sorted(SPN, key=lambda x:x[1], reverse=1), lambda x:x[0])
for s,p,n in SPN:
    print(n)


Fixed code:
n = int(input())
SPN = []
for i in range(n):
    s,p = input().split()
    SPN.append([s,int(p),i+1])
SPN.sort(key = lambda x:x[1],reverse=True)
SPN.sort(key = lambda x:x[0])
for s,p,n in SPN:
    print(n)
Buggy code:
n = iint(input())
ls = []
for i in range(1,n+1):
  s,p = input().split()
  ls.append([i,s,int(p)])
ls.sort(key=lambda x:(x[1], x[2]))
for j in range(len(ls)):
  print(ls[j][0])

Fixed code:
n = int(input())
ls = []
for i in range(1,n+1):
    s,p = input().split()
    ls.append([i,s,int(p)])
ls.sort(key=lambda x:(x[1], -x[2]))
for j in range(len(ls)):
    print(ls[j][0])
Buggy code:
import sys
rr = lambda: sys.stdin.readline().strip()
rri = lambda: int(rr())
rrs = lambda: [int(_) for _ in rr().split()]

from operator import itemgetter

N = rri()
data = [[i + 1] + rr().split() for i in range(N)]

data.sort(key=itemgetter(2), reverse=True)
data.sort(key=itemgetter(1))

for d in data:
	print(d[0])

Fixed code:
import sys
rr = lambda: sys.stdin.readline().strip()
rri = lambda: int(rr())
rrs = lambda: [int(_) for _ in rr().split()]

from operator import itemgetter

N = rri()
data = [[i + 1] + rr().split() for i in range(N)]

for d in data:
	d[2] = int(d[2])

data.sort(key=itemgetter(2), reverse=True)
data.sort(key=itemgetter(1))

for d in data:
	print(d[0])
Buggy code:
n = int(input())
sp = [input().split() + [i] for i in range(n)]
sp.sort(key=lambda x: x[1], reverse=True)
sp.sort(key= lambda x: x[0])
for i in sp:
    print(i[2] + 1)

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

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

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

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

Fixed code:
n = int(input())
dic = [[x for x in input().split()] for i in range(n)]

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

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

for i in range(n):
    print(dic[i][2])
Buggy code:
n=int(input())
li=[0]*n
for i in range(n):
    a=input().split()
    li[i]=[a[0], -int(a[1]), i+1]

li.sort(key=lambda x:(x[0],int(x[1])))
print(li)
for i in li:
    print(i[2])

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

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

for i in li:
    print(i[2])
Buggy code:
n = int(input())
rs = [input().split() for _ in range(n)]
rs = [(r, int(p)) for r, p in rs]
srs = sorted(sorted(rs, key=lambda p: p[1]), key=lambda p: p[0])

for p in rs:
  print(srs.index(p)+1)

Fixed code:
n = int(input())
rs = [input().split() for _ in range(n)]
rs = [(r, int(p)) for r, p in rs]
srs = sorted(sorted(rs, key=lambda p: p[1], reverse=True), key=lambda p: p[0])
 
for p in srs:
  print(rs.index(p)+1)
Buggy code:
N = int(input())
names = set()
citydict = dict()
for i in range(N):
    S, P = input().split()
    names.append(S)
    if S[i] in citydict:
        citydict[S].append((int(P),i))
    else:
        citydict[S] = [(int(P),i)]

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

Fixed code:
N = int(input())
names = set()
citydict = dict()
for i in range(N):
    S,P = input().split()
    names.add(S)
    if S in citydict:
        citydict[S].append((int(P),i))
    else:
        citydict[S] = [(int(P),i)]

for name in sorted(names):
    for point in sorted(citydict[name],reverse = True):
        print(point[1] + 1)
Buggy code:
N = int(input())
S = [(i, tuple(input().split())) for i in range(1, N + 1)]

arr = sorted(S, key=lambda item: item[1][1], reverse=True)
arr2 = sorted(arr, key=lambda item: item[1][0])

for item in arr2:
    print(item[0])



Fixed code:
N = int(input())
S = [(i, tuple(input().split())) for i in range(1, N + 1)]

arr = sorted(S, key=lambda item: int(item[1][1]), reverse=True)
arr2 = sorted(arr, key=lambda item: item[1][0])

for item in arr2:
    print(item[0])
Buggy code:
n = int(input())
r = sorted([list(input().split())+[i+1] for i in range(n)], reverse = True)
r.sort(key = lambda x: x[0])
for i in r: print(i[2])

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