qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from operator import itemgetter

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

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

sp = sorted(sp, key=itemgetter(1), reverse=True)
sp = sorted(sp, key=itemgetter(0))

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

Fixed code:
from operator import itemgetter

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

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

sp = sorted(sp, key=itemgetter(1), reverse=True)
sp = sorted(sp, key=itemgetter(0))

for i in range(n):
  print(sp[i][2])
Buggy code:

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

for s, n, i in SP:
    print(i+1)


Fixed code:

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

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

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

for i in range(1, N+1):
    name, point = (x for x in input().split())
    r.append([name, point, i])
r.sort(key=lambda x: x[0])
r.sort(key=lambda x: x[1])

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


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

for i in range(1, N+1):
    name, point = (x for x in input().split())
    r.append([name, int(point), i])
    r.sort(key=lambda x: x[1], reverse=True)
    r.sort(key=lambda x: x[0])

for i in range(N):
    print(r[i][2])
Buggy code:
n = int(input())
s_p_list = list()
for i in range(n):
    input_ = input().split()
    input_[1] = int(input_[1])
    input_.append(i + 1)
    s_p_list.append(input_)


s_p_list.sort(key=lambda x: (x[0], -x[1]))

print(s_p_list)

for s, p, i in s_p_list:
    print(i)


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


s_p_list.sort(key=lambda x: (x[0], -x[1]))

# print(s_p_list)

for s, p, i in s_p_list:
    print(i)
Buggy code:
from collections import defaultdict

N = int(input())
di = defaultdict(list)

for n in range(1, N + 1):
    S, P = input().split()
    P = int(P)
    di[S].append({n: P})

li = sorted(di.items(), key=lambda x: x[0])

print(li)

di2 = {}

for tu in li:
    for mini_dict in tu[1]:
        for k, v in mini_dict.items():
            di2[k] = v
    sorted_di2 = sorted(di2.items(), key=lambda x: x[1], reverse=True)
    for tup2 in sorted_di2:
        print(tup2[0])

    sorted_di2 = []
    di2 = {}


Fixed code:
from collections import defaultdict

N = int(input())
di = defaultdict(list)

for n in range(1, N + 1):
    S, P = input().split()
    P = int(P)
    di[S].append({n: P})

li = sorted(di.items(), key=lambda x: x[0])

di2 = {}

for tu in li:
    for mini_dict in tu[1]:
        for k, v in mini_dict.items():
            di2[k] = v
    sorted_di2 = sorted(di2.items(), key=lambda x: x[1], reverse=True)
    for tup2 in sorted_di2:
        print(tup2[0])

    sorted_di2 = []
    di2 = {}
Buggy code:
#B

n = int(input())
S=[]

for i in range(n):
    s,p = (x for x in input().split())
    S.append((s,p, i+1))

S = sorted(S, key=lambda x: x[1], reverse=True)
S = sorted(S, key=lambda x: x[0])

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

Fixed code:
#B

n = int(input())
S=[]

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

S = sorted(S, key=lambda x: x[1], reverse=True)
S = sorted(S, key=lambda x: x[0])

for i in S:
    print(i[2])
Buggy code:
N = int(input())
data = [[i for i in input().split()] for j in range(N)]
for i in range(N):
    data[i].append(i+1)
sort_data = sorted(data)
print(sort_data)
start = sort_data[0][0]
num = [sort_data[0][2]]
for i in range(1,N):
    if sort_data[i][0] == start:
        num.append(sort_data[i][2])
    else:
        start = sort_data[i][0]
        for j in range(len(num)):
            print(num[len(num)-1-j])
        num = [sort_data[i][2]]
for j in range(len(num)):
    print(num[len(num)-1-j])  

Fixed code:
N = int(input())
data = [[i for i in input().split()] for j in range(N)]
for i in range(N):
    data[i].append(i+1)
for j in data:
    j[1] = int(j[1])
sort_data = sorted(data)
start = sort_data[0][0]
num = [sort_data[0][2]]
for i in range(1,N):
    if sort_data[i][0] == start:
        num.append(sort_data[i][2])
    else:
        start = sort_data[i][0]
        for j in range(len(num)):
            print(num[len(num)-1-j])
        num = [sort_data[i][2]]
for j in range(len(num)):
    print(num[len(num)-1-j])
Buggy code:
N = int(input())
S = []

for i in range(N):
    ts,tp = input().split()
    ts = str(ts)
    tp = int(tp)
    S.append([ts,tp,i+1])

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

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

Fixed code:
N = int(input())
S = []
 
for i in range(N):
    ts,tp = input().split()
    ts = str(ts)
    tp = 100-int(tp)
    S.append([ts,tp,i+1])
    
S.sort(key=lambda x:(x[0],x[1]))

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

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


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

list = sorted(list, key=lambda x:(x[0],-x[1]))
for i in range(N):
    print(list[i][2])
Buggy code:
n =  int(input())

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

  table.append([i+1, city, score])

sorted_table = sorted(table, key=lambda x:(x[1], -x[2]))

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

Fixed code:
n =  int(input())

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

  table.append([i+1, city, score])

sorted_table = sorted(table, key=lambda x:(x[1], -x[2]))

for i in range(n):
  print(sorted_table[i][0])
Buggy code:
N = int(input())
bag = []
shi = []
for i in range(N):
    s, p = input().split()
    p = int(p)
    shi.append(s)
    
    bag.append((s, p, i))

sorted_bag = sorted(bag, key=lambda x:x[0])
sorted_shi = sorted(list(set(shi)))


dic = {}
for s, p, i in bag:
    if s not in dic.keys():
        dic[s] = [[p, i]]
    else:
        dic[s].append([p, i])

for s in sorted_shi:
    if len(dic[s]) == 1:
        print(dic[s][0][1])
    else:
        so = sorted(dic[s], key=lambda x:x[0])[-1::-1]
        for e in so:
            print(e[1])

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

sorted_bag = sorted(bag, key=lambda x:x[0])
sorted_shi = sorted(list(set(shi)))


dic = {}
for s, p, i in bag:
    if s not in dic.keys():
        dic[s] = [[p, i+1]]
    else:
        dic[s].append([p, i+1])

for s in sorted_shi:
    if len(dic[s]) == 1:
        print(dic[s][0][1])
    else:
        so = sorted(dic[s], key=lambda x:x[0])[-1::-1]
        for e in so:
            print(e[1])
Buggy code:
from collections import defaultdict
d = defaultdict(list)
n = int(input())
for i in range(n):
    city, point = input().split()
    d[city].append((int(point), i))

d2 = sorted(d.items())
for i in range(len(d2)):
    sorted(d2[i][1])
    for j in range(len(d2[i])):
        print(d2[i][1][j][1] + 1)



Fixed code:
from collections import defaultdict
d = defaultdict(list)
n = int(input())
for i in range(n):
    city, point = input().split()
    d[city].append((int(point), i+1))

d2 = sorted(d.items())
for i in range(len(d2)):
    d2[i] = list(d2[i])
    d2[i][1] = sorted((d2[i][1]), reverse = True)
    for j in range(len(d2[i][1])):
        print(d2[i][1][j][1])
Buggy code:
from operator import itemgetter

N = input()
N = int(N)

X = []
Y = []
for i in range(N):
    S_x,P_x = input().split()
    X.append(S_x)
    X.append(P_x)
    X.append(i+1)
    Y.append(X)
    X = []

Y = sorted(Y,key=itemgetter(1),reverse=True)
Y = sorted(Y,key=itemgetter(0))

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


Fixed code:
from operator import itemgetter

N = input()
N = int(N)

X = []
Y = []
for i in range(N):
    S_x,P_x = input().split()
    X.append(S_x)
    X.append(int(P_x))
    X.append(i+1)
    Y.append(X)
    X = []

Y = sorted(Y,key=itemgetter(1),reverse=True)
Y = sorted(Y,key=itemgetter(0))

for i in range(N):
    print(Y[i][2])
Buggy code:
n = int(input())
list = []
for xi in range(n):
    add1, add2 = input().split()
    add = [add2, add1, xi+1]
    list.append(add)
list.sort(key=lambda list2: list2[1])

print(list)

name = list[0][1]
list2 = [list[0]]
count = 1
for xi in range(1,n):
    if name == list[xi][1]:
        list2.append(list[xi])
        count += 1
    else:
        list2.sort(key=int, reverse=True)
        for yi in range(count-1,-1,-1):
            print(list2[yi][2])
        name = list[xi][1]
        list2 = [list[xi]]
        count = 1

if len(list2)<n:
    list2.sort(key=int, reverse=True)
for yi in range(count-1,-1,-1):
    print(list2[yi][2])
name = list[xi][1]
list2 = [list[xi]]
count = 1


Fixed code:
n = int(input())
list = []
for xi in range(n):
    add1, add2 = input().split()
    add = [int(add2), add1, xi+1]
    list.append(add)
list.sort(key=lambda list2: list2[1])


name = list[0][1]
list2 = [list[0]]
count = 1
for xi in range(1,n):
    if name == list[xi][1]:
        list2.append(list[xi])
        count += 1
    else:
        list2.sort()
        for yi in range(count-1,-1,-1):
            print(list2[yi][2])
        name = list[xi][1]
        list2 = [list[xi]]
        count = 1

if len(list2)<n:
    list2.sort()
for yi in range(count-1,-1,-1):
    print(list2[yi][2])
name = list[xi][1]
list2 = [list[xi]]
count = 1
Buggy code:
n = int(input())
l = [list(input().split()) for i in range(n)]
s,p = [list(i) for i in zip(*l)]
p = [int(i) for i in p]
z = list(set(s))
z.sort()
m = list(p)
m.sort(reverse = True)
l = []

k = 0
for i in range(len(z)):
    l.append(k)
    k += 200

o = []
for i in range(n):
    w = l[z.index(s[i])]
    w += m.index(p[i])
    o.append(w)

r = list(o)
r.sort()
for i in range(n):
    print(r.index(o[i]) + 1) 

Fixed code:
n = int(input())
l = [list(input().split()) for i in range(n)]
s,p = [list(i) for i in zip(*l)]
p = [int(i) for i in p]
z = list(set(s))
z.sort()
m = list(p)
m.sort(reverse = True)
l = []
 
k = 0
for i in range(len(z)):
    l.append(k)
    k += 200
 
o = []
for i in range(n):
    w = l[z.index(s[i])]
    w += m.index(p[i])
    o.append(w)
 
r = list(o)
r.sort()
for i in range(n):
    print(o.index(r[i]) + 1)
Buggy code:
def main():
    N = int(input())
    SP = [list(input().split()) for i in range(N)]
    for i, SPl in enumerate(SP):
        SPl.append(i+1)
    # print(SP)
    SP.sort(reverse=True, key=lambda x: x[1])
    # print(SP)
    SP.sort(key=lambda x: x[0])
    # print(SP)

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


if __name__ == "__main__":
    main()


Fixed code:
def main():
    N = int(input())
    SP = [list(input().split()) for i in range(N)]
    for i, SPl in enumerate(SP):
        SPl.append(i+1)
        SPl[1] = int(SPl[1])
    # print(SP)
    SP.sort(reverse=True, key=lambda x: x[1])
    # print(SP)
    SP.sort(key=lambda x: x[0])
    # print(SP)

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


if __name__ == "__main__":
    main()
Buggy code:
from operator import itemgetter

n = int(input())
A = []
city = []
for _ in range(n):
    s,p = input().split()
    city.append([s,-int(p)])
    A.append([s,-int(p)])

A = sorted(A, key=itemgetter(0,1))
for c in city:
    print(A.index(c)+1)

Fixed code:
from operator import itemgetter

n = int(input())
A = []
city = []
for _ in range(n):
    s,p = input().split()
    city.append([s,-int(p)])
    A.append([s,-int(p)])

A = sorted(A, key=itemgetter(0,1))
for a in A:
    print(city.index(a)+1)
Buggy code:
N = int(input())
SP = [(i + 1, input().split()) for i in range(N)]
P = [[0, 0, 0] for _ in range(N)]
for i in range(N):
    P[i][0] = SP[i][0]
    P[i][1] = SP[i][1][0]
    P[i][2] = int(SP[i][1][1])
P.sort(key=lambda x: x[1][1], reverse=True)
P.sort(key=lambda x: x[1][0])

for p in P:
    print(p[0])


Fixed code:
N = int(input())
SP = [(i + 1, input().split()) for i in range(N)]
P = [[0, 0, 0] for _ in range(N)]
for i in range(N):
    P[i][0] = SP[i][0]
    P[i][1] = SP[i][1][0]
    P[i][2] = int(SP[i][1][1])
P.sort(key=lambda x: x[2], reverse=True)
P.sort(key=lambda x: x[1])

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


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

Fixed code:
n = int(input())
x = []
for i in range(n):
    s, p = input().split()
    p = -int(p)
    x.append([s, p, i + 1])
x.sort()
for i in range(n):
    print(x[i][2])
Buggy code:
n = int(input())
sp = [[i] + list(input().split()) for i in range(n)]
sp2 = sorted(sp,key=lambda x:(x[2]),reverse=True)
sp3 = sorted(sp2,key=lambda x:(x[1]))
for r in sp3:
  print(r[0]+1)

Fixed code:
n = int(input())
sp = [[i] + list(input().split()) for i in range(n)]
sp2 = sorted(sp,key=lambda x:(int(x[2])),reverse=True)
sp3 = sorted(sp2,key=lambda x:(x[1]))
for r in sp3:
  print(r[0]+1)
Buggy code:
from operator import itemgetter


N=int(input())
A=[0]*N
for i in range(N):
    A[i]=input().split()

i=0
while i<N:
    A[i][1]=int(A[i][1])
    i+=1

i=0
while i<N:
    A[i]=tuple(A[i])
    i+=1

B1 = sorted(A, key=itemgetter(1),reverse=True)
B2 = sorted(B1,key=itemgetter(0))

print(B2)

for i in B2:
    print(A.index(i)+1)    

Fixed code:
from operator import itemgetter

N=int(input())
A=[0]*N
for i in range(N):
    A[i]=input().split()

i=0
while i<N:
    A[i][1]=int(A[i][1])
    i+=1

i=0
while i<N:
    A[i]=tuple(A[i])
    i+=1

B1 = sorted(A, key=itemgetter(1),reverse=True)
B2 = sorted(B1,key=itemgetter(0))

for i in B2:
    print(A.index(i)+1)
Buggy code:
n = int(input())
res = {}
for i in range(0, n):
  s, p = [elem for elem in input().split()]
  if not s in res:
    res[s] = [(p, i + 1)]
  else:
    res[s].append((p, i + 1))

for key in sorted(res.keys()):
  for score, idx in sorted(res[key], reverse=-1):
    print(idx)

Fixed code:
n = int(input())
res = {}
for i in range(0, n):
  s, p = [elem for elem in input().split()]
  if not s in res:
    res[s] = [(int(p), i + 1)]
  else:
    res[s].append((int(p), i + 1))

for key in sorted(res.keys()):
  for score, idx in sorted(res[key], reverse=-1):
    print(idx)
Buggy code:
a= input()
dict ={}
for num in range(int(a)):
    b= input().split()
    if b[0] in dict:
      dict[b[0]][b[1]]=num
    else:
      dict2={}
      dict2[b[1]]=num
      dict[b[0]] = dict2

dict = sorted(dict.items())
for i in dict:
  lits_i =i[1]
  dict2 = sorted(lits_i .items(), reverse=True)
  for j in dict2:
    print(j[1]+1)

Fixed code:
a= input()
dict ={}
for num in range(int(a)):
    b= input().split()
    if b[0] in dict:
      dict[b[0]][int(b[1])]=num
    else:
      dict2={}
      dict2[int(b[1])]=num
      dict[b[0]] = dict2

dict = sorted(dict.items())
for i in dict:
  lits_i =i[1]
  dict2 = sorted(lits_i .items(), reverse=True)
  for j in dict2:
    print(j[1]+1)
Buggy code:
from operator import itemgetter

n = int(input())

wrap = []

for i in range(n):
    input_data = input()
    wrap.append([i+1, input_data.split()[0], int(input_data.split()[1])])

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

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

Fixed code:
from operator import itemgetter

n = int(input())

wrap = []

for i in range(n):
    input_data = input()
    wrap.append([i+1, input_data.split()[0], int(input_data.split()[1])])

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

for i in wrap:
    print(i[0])
Buggy code:
N = int(input())
X = []
for i in range(N):
	s, p = input()
	X.append([s, -int(p),  i+1])
X.sort()
for i in range(N):
	print(-X[i][1])

Fixed code:
N = int(input())
X = []
for i in range(N):
	s, p = input().split()
	X.append([s, -int(p),  i+1])
X.sort()
for i in range(N):
	print(X[i][2])
Buggy code:
N = int(input())
rest = {}
cities = []
for i in range(N):
    k,s = input().split()
    if k not in rest:
        rest[k] = []
        cities.append(k)
    rest[k].append([int(s),i+1])
print(sorted(rest))
for k in cities:
    rest[k].sort(reverse = True)
    for i in range(len(rest[k])):
        print(rest[k][i][1])

Fixed code:
N = int(input())
rest = {}
cities = []
for i in range(N):
    k,s = input().split()
    if k not in rest:
        rest[k] = []
        cities.append(k)
    rest[k].append([int(s),i+1])
cities.sort()
for k in cities:
    rest[k].sort(reverse = True)
    for i in rest[k]:
        print(i[1])
Buggy code:
n = int(input())
lis = []
for i in range(n):
    s,p = map(str,input().split())
    lis.append([s,100 - int(p)])
liss = lis.copy()
lis.sort()
print(liss)
for i in range(n):
    print(lis.index(liss[i]) + 1)

Fixed code:
n = int(input())
lis = []
for i in range(n):
    s,p = map(str,input().split())
    lis.append([s,100 - int(p)])
liss = lis.copy()
lis.sort()
for i in range(n):
    print(liss.index(lis[i]) + 1)
Buggy code:
N = int(input())
lis = [(input() + " " + str(i+1)).split() for i in range(N)]

lis.sort(key=lambda k: k[1], reverse=True)
lis.sort(key=lambda k: k[0])

for j in lis:
    print(j[2])


Fixed code:
N = int(input())
lis = [(input() + " " + str(i+1)).split() for i in range(N)]

lis = [k for k in lis]

lis.sort(key=lambda k: int(k[1]), reverse=True)
lis.sort(key=lambda k: k[0])


for j in lis:
    print(j[2])
Buggy code:
N = int(input())
A = []
for x in range(N):
  s, p = input().split()
  A.sppend([s, -int(p), x+1])
  
A.sort()

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


Fixed code:
N = int(input())
A = []
for x in range(N):
  s, p = input().split()
  A.append([s, -int(p), x+1])
  
A.sort()

for i in range(N):
  print(A[i][2])
Buggy code:
N = int(input())
L = [list(map(str, input().split())) for _ in range(N)]

for i in range(N):
    L[i].append(i+1)

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(map(str, input().split())) for _ in range(N)]

for i in range(N):
    L[i][1] = int(L[i][1])
    L[i].append(i+1)

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())
arr = []

for i in range(n):
	s,p = input().split()
	a = {"i":i+1,"s":s,"p":int(p)}
	arr.append(a)

arr = sorted(arr, key=lambda x:x["p"], reverse=True)
print(arr)
arr = sorted(arr, key=lambda x:x["s"])

for a in arr:
	print(a["i"])


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

for i in range(n):
	s,p = input().split()
	a = {"i":i+1,"s":s,"p":int(p)}
	arr.append(a)

arr = sorted(arr, key=lambda x:x["p"], reverse=True)
#print(arr)
arr = sorted(arr, key=lambda x:x["s"])

for a in arr:
	print(a["i"])
Buggy code:
N=int(input())
rest=[]
for i in range(1,N+1):
    s,p=input().split()
    p=int(p)
    rest.append((s,-p,i))


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

    


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

x=sorted(rest)


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


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

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

print([out[2] for out in ss_sorted])

Fixed code:
N = int(input())


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

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

for out in ss_sorted:
    print(out[2] + 1)
Buggy code:
from operator import itemgetter
N=int(input())
listA=[[] for i in range(N)]
listANS=[]
for i in range(N):
  S,P=input().split()
  listA[i]+=[S,int(P),i+1]
listA.sort()
for i in range(1,N):
  before=0
  if listA[i-1][0]!=listA[i][0] or i==N-1:
    listN=listA[before:i+1]
    listN.sort(key=itemgetter(1),reverse=True)
    listANS+=listN
    before=i
for i in range(N):
  print(listANS[i][2])

Fixed code:
from operator import itemgetter
N=int(input())
listA=[[] for i in range(N)]
listANS=[]
for i in range(N):
  S,P=input().split()
  listA[i]+=[S,int(P),i+1]
listA.sort()
before=0
if N!=1:
  for i in range(1,N):
    if listA[i-1][0]!=listA[i][0]:
      listN=listA[before:i]
      listN.sort(key=itemgetter(1),reverse=True)
      listANS+=listN
      before=i
 
    if i==N-1:
      listN=listA[before:N]
      listN.sort(key=itemgetter(1),reverse=True)
      listANS+=listN
else:
  listANS=listA
for i in range(N):
  print(listANS[i][2])
Buggy code:
num = int(input())
guide = [[i for i in input().split()] for j in range(0, num)]
dic = 1
for i in range(0, len(guide)):
    guide[i].append(dic)
    dic += 1
guide.sort(reverse=True)
guide_book = sorted(guide, key=lambda x : x[0])

for i in range(0, len(guide)):
    print(guide_book[i][2])


Fixed code:
num = int(input())
guide = [[i for i in input().split()] for j in range(0, num)]
dic = 1
for i in range(0, len(guide)):
    guide[i][1] = int(guide[i][1])
    guide[i].append(dic)
    dic += 1
guide.sort(reverse=True, key=lambda x: x[1])
guide_book = sorted(guide, key=lambda x: x[0])

for i in range(0, len(guide)):
    print(guide_book[i][2])
Buggy code:
n=int(input())
sp=[]
for i in range(n):
    temp=list(map(str,input().split())) + [i+1]
    sp.append(temp)
    sp[i][1]=int(sp[i][1])
sp=sorted(sp,key=lambda x:(x[0],x[1]))

que=[]
prev_rest=sp[0][0]
for i in range(n):
    if prev_rest != sp[i][0]:
        for j in range(len(que)):
            ans_list=que.pop()
            print(ans_list[2])
    else:
        que.append(sp[i])
        prev_rest = sp[i][0]

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

que=[]
prev_rest=sp[0][0]
for i in range(n):
    if prev_rest != sp[i][0]:
        que=sorted(que,key=lambda x:(x[0],x[1]))
        for j in range(len(que)):
            ans_list=que.pop()
            print(ans_list[2])
    que.append(sp[i])
    prev_rest = sp[i][0]
que=sorted(que,key=lambda x:(x[0],x[1]))
for j in range(len(que)):
    ans_list=que.pop()
    print(ans_list[2])
Buggy code:
import math


def main():
    N = int(input())
    SP = [list(input().split()) + [i + 1] for i in range(N)]
    SP.sort(key=lambda x: (x[0], -int(x[1])))

    print(SP)

    for i in map(lambda x: x[2], SP):
        print(i)


if __name__ == '__main__':
    main()


Fixed code:
import math


def main():
    N = int(input())
    SP = [list(input().split()) + [i + 1] for i in range(N)]
    SP.sort(key=lambda x: (x[0], -int(x[1])))
    for i in map(lambda x: x[2], SP):
        print(i)


if __name__ == '__main__':
    main()