Problem:
 Score : 200 points    Problem Statement You have decided to write a book introducing good restaurants.
There are N restaurants that you want to introduce: Restaurant 1 , Restaurant 2 , ... , Restaurant N . Restaurant i is in city S_i , and your assessment score of that restaurant on a 100 -point scale is P_i .
No two restaurants have the same score.  You want to introduce the restaurants in the following order:   The restaurants are arranged in lexicographical order of the names of their cities.  If there are multiple restaurants in the same city, they are arranged in descending order of score.   Print the identification numbers of the restaurants in the order they are introduced in the book.      Constraints  1 ≤ N ≤ 100  S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.  0 ≤ P_i ≤ 100  P_i is an integer.  P_i ≠ P_j  (1 ≤ i < j ≤ N)         Input Input is given from Standard Input in the following format:  N  S_1  P_1  :  S_N  P_N       Output Print N lines. The i -th line ( 1 ≤ i ≤ N ) should contain the identification number of the restaurant that is introduced i -th in the book.        Sample Input 1 6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40      Sample Output 1 3
4
6
1
5
2  The lexicographical order of the names of the three cities is kazan  <  khabarovsk  <  moscow . For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,2 .       Sample Input 2 10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100      Sample Output 2 10
9
8
7
6
5
4
3
2
1

Solution (Python):
n = int(input())
val = {}
c = []
for i in range(n):
    a,b = input().split()
    if a in val:
         val[a].append(int(b))
         c.append(int(b))
    else : 
        val[a] = [int(b)]
        c.append(int(b))

val_1 = sorted(val.items(),key= lambda x:x[0])

d = []
for i in range(len(val_1)):
    if len(val_1[i]) == 1 :
        d.append(val_1[i][1][0])
    else:
        val_1[i][1].sort(reverse= True)
        for h in val_1[i][1]:
            d.append(h)


for i in d :
    for j in range(n):
        if i == c[j]:
            print("{}".format(j+1))

Solution (Python):
N = int(input())
dic = []
dic2 = []
for i in range(N):
    dic.append(i)
    dic.extend(input().split())
    dic2.append(dic)
    dic = []

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

for i in range(N):
    print(dic[i][0]+1)

Solution (Python):
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])

Solution (Python):
import numpy as np

N = input()
N = int(N)
a = []
for i in range(0,N):
    S, P = map(str,input().split())
    P = int(P)
    a.append([i,S,P])

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

Solution (Python):


import math

N = int(input())
d = {}
l = []
for i in range(N):
    s,p = list(input().split(" "))
    d[i+1] = s,p

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

for i in range(N-1):
    for j in range(N-1):
        if d1[j][1][0] == d1[j+1][1][0] and int(d1[j][1][1]) < int(d1[j+1][1][1]):
            
            d1[j],d1[j+1] = d1[j+1],d1[j]


for i in range(N):
    print(d1[i][0])

Solution (Python):
N = int(input())
restaurant = [[0 for i in range(3)] for j in range(N)]
for i in range(N):
    restaurant[i][0] = i
    restaurant[i][1], restaurant[i][2] = map(str, input().strip().split())
    restaurant[i][2] = int(restaurant[i][2])

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

Solution (Python):
N = input()
N = int(N)
s = [[ i for i in input().split()] for i in range(N)]
for i in range(N):
    s[i][1] = int(s[i][1])
    s[i].append(i + 1)
sorteds = sorted(s, key=lambda x:x[1],reverse = True)
sorteds.sort(key=lambda x:x[0])


for k in sorteds:
  print(k[2])

Solution (Python):
n=int(input())
A,B,C=[],[],[]
for _ in range(n):
    n = list(input().split())
    A.append([n[0], int(n[1])])
    B.append(n[0])
a=sorted(A)
C = sorted(set(B))
tmp=0
for i in C:
    count=B.count(i)
    for _ in range(B.count(i)):
        
        print(A.index(a[tmp+count-1])+1)
        count-=1
    tmp+=B.count(i)

Solution (Python):
n = int(input())
L = []
for i in range(n):
  t, p = input().split()
  p = -int(p)
  L.append([i, t, p])
  
L.sort(key=lambda x:(x[1],x[2]))

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

Solution (Python):
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

Solution (Python):
N = int(input())

S = [""] * N
P = [0] * N

for i in range(N):
    S[i], P[i] = input().split()
    P[i] = int(P[i])


new_S = sorted(S)

same_v = []
same_i = []
for i, name in enumerate(new_S):
    for k in range(N):
        if new_S[i] == S[k]:
            same_v.append(P[k])
            same_i.append(k)
    x = same_i[same_v.index(max(same_v))]
    print(x + 1)
    same_v = []
    same_i = []
    P[x] = -1

Solution (Python):
n = int(input())
s = []
for i in range(n):
    s.append(list(input().split()))
    s[i] = [s[i][0] , int(s[i][1])]


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


for j in range(n):
    for i in range(n):
        if set(s[i]) == set(t[j]):
            print(i+1)
            break

Solution (Python):
from bisect import insort_left as il
n=int(input())
a=[]

d={}
for i in range(n):
    s,p=input().split()
    p=int(p)
    a.append(p)
    
    if s not in d:
        d[s]=[p]
    else:
        il(d[s],p)

s=sorted(d)




for i in s:
    
    
    for j in range(len(d[i])):
        print(a.index(d[i].pop())+1)

Solution (Python):
n = int(input())

li = []

for i in range(n):
    [si, pi] = input().split()
    li.append((si, int(pi), i+1))

li.sort(key = lambda tup: tup[0])

li2 = []
while len(li) > 0:
  key = li[0][0]
  flag = True
  while flag and len(li) > 0:
    if li[0][0] == key:
      li2.append(li.pop(0))
    else:
      flag = False
  li2.sort(key = lambda tup: tup[1], reverse = True)
  for x in li2:
    print(x[2])
  li2 = []

Solution (Python):
from operator import itemgetter

N = int(input())
shops = []
for i in range(N):
    S,P = input().split()
    P = int(P)
    shops.append([S,P,i+1])
shops = sorted(shops)
shops.append(["",0,0])

last = shops[0][0]
lasti = 0

for i in range(N+1):
    if shops[i][0] != last:
        ans = sorted(shops[lasti:i],key=itemgetter(1),reverse=True)
        for a in ans:
            print(a[2])
        last = shops[i][0]
        lasti = i

Solution (Python):
import sys
sys.setrecursionlimit(10**7)








def solve():
    n = int(input())
    rev_list = []
    for i in range(n):
        idx = i + 1
        s, p = input().split()
        rev_list.append([idx, s, int(p)])


    rev_list_p_sorted = sorted(rev_list, key=lambda x: x[2], reverse=True)
    rev_list_s_sorted = sorted(rev_list_p_sorted, key=lambda x: x[1])
    
    
    

    for rev in rev_list_s_sorted:
        print(rev[0])

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

solve()

Solution (Python):
N = int(input())
sp=[[0]*3 for i in range(N)]
for i in range(N):
    sp[i][0], sp[i][1] = input().split()
    sp[i][1] = int(sp[i][1])
    sp[i][2] = i+1

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

Solution (Python):
from operator import itemgetter

N = int(input())
list =[]
for i in range(N):
    SP = input().split()
    SP[1] = int(SP[1])
    SP.append(i+1)
    list.append(SP)
    
    
    
    

list2 = sorted(list, key=itemgetter(1), reverse=True)

list3 = sorted(list2, key=itemgetter(0))


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

Solution (Python):
N=int(input())
L={}
for i in range(N):
    a,b=input().split()
    if a in L.keys():
        L[a].append([int(b),i+1])
    else:
        L[a]=[[int(b),i+1]]
L1= sorted(L.items(), key=lambda x:x[0])
for i in range(len(L1)):
    a=L1[i][1]
    a.sort(key=lambda x:x[0],reverse=True)
    for j in range(len(a)):
        print(a[j][1])

Solution (Python):
n = int(input())
init = []
tosort = []
final = []

for i in range(n):
    s, p = (str(_) for _ in input().split())
    init.append([s,int(p)])
cities = sorted(init)

prev = cities[0][0]

for city in cities:
    if city[0] == prev:
        tosort.append(city)
    else:
        tosort.sort(key=lambda x: x[1], reverse = True)
        final += tosort
        tosort = []
        tosort.append(city)
    prev = city[0]
tosort.sort(key=lambda x: x[1], reverse = True)
final += tosort

for f in final:
    print(init.index(f)+1)

Solution (Python):
N = input()
N = int(N)
s = [[ i for i in input().split()] for i in range(N)]
for i in range(N):
    s[i][1] = int(s[i][1])
    s[i].append(i + 1)
sorteds = sorted(s, key=lambda x:x[1],reverse = True)
sorteds.sort(key=lambda x:x[0])


for k in sorteds:
  print(k[2])

Solution (Python):
n=int(input())
data=sorted([[i for i in input().split()]+[_] for _ in range(n)],key=lambda x:x[0])
for i in range(n):
    data[i][1]=int(data[i][1])
l=[]
tmp=[(data[0][1],data[0][2])]
for i in range(1,n):
    if data[i][0]!=data[i-1][0]:
        l.append(tmp)
        tmp=[]
    tmp.append((data[i][1],data[i][2]))
l.append(tmp)

for i in range(len(l)):
    l[i]=sorted(l[i],key=lambda x:x[0])[::-1]
ans=[0]*n
count=0
for i in l:
    for j in i:
        ans[count]=j[1]+1
        count+=1
print(*ans,sep='\n')

Solution (Python):

N = int(input())
li = []

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


copyli = li.copy()
ans = []

a = sorted(copyli, key = lambda copyli: copyli[1],  reverse=True)
c = sorted(a, key = lambda a: a[0])




for i in range(N):
    for j in range(N):
        if (li[j][0] == c[i][0]) and (li[j][1] == c[i][1]):
            ans.append(j+1)

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

Solution (Python):
n = int(input())
li = []
for i in range(n):
    a, b = input().split()
    b = int(b)
    li.append([a, b, i+1])

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])

Solution (Python):
n=int(input())

s = [0] * n
p = [0] * n
for i in range(n):
    s[i], p[i] = map(str,input().split())
    
P = [int(s) for s in p]
L=[]

for i in range(n):
    count=1
    for j in range(n):
        if i==j:
            continue
        if s[i]>s[j]:
            count=count+1
        if s[i]<s[j]:
            continue
        if s[i]==s[j]:
            if P[i]<P[j]:
                count=count+1
            else:
                continue
    L.append(count)

for i in range(n):
    print(L.index(i+1)+1)

Solution (Python):
N = int(input())
SP = [[i for i in input().split()]+[j] for j in range(N)]
for n in range(N):
    SP[n][1] = int(SP[n][1])
SP.sort(key=lambda x:x[1],reverse=True)
SP.sort(key=lambda x:x[0])


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

Solution (Python):
n = int(input())
SP = []
for i in range(n):
    s,p = input().split()
    sp = (i,s,int(p))
    SP.append(sp)

newSP = sorted(SP,key = lambda tup:(tup[1],-tup[2]))

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

Solution (Python):
from operator import itemgetter
N=int(input()) 
s = [input().split() for i in range(N)]
for i in range(N):
    s[i][1] = s[i][1].zfill(3)
    s[i].append(i)
s.sort(key=itemgetter(1),reverse=True)
s.sort(key=itemgetter(0))
[print(s[i][-1]+1) for i in range(N)]

Solution (Python):


n = int(input())

s =[]
p =[]

for i in range(n):
    a = input().split()
    s.append([a[0],int(a[1])])

s_list = sorted(s, key=lambda x:(x[0],-x[1]))
rank =[0 for i in range(n)]

for i in range(n):
    for j in range(n):
        if (s_list[i] == s[j]):
            rank[i] = j+1
            
for i in range(n):
    print(rank[i])

Solution (Python):
N = int(input())

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

ss = list(set(S))
ss.sort()

a = []
b = []
for i in ss:
    for s, p in t:
        if i == s:
            a.append(p)
    b.extend(sorted(a, reverse=True))
    a = []

for i in range(len(b)):
    for j in range(len(P)):
        if b[i] == P[j]:
            print(j+1)
            break

Solution (Python):
N = int(input())
M = [0 for i in range(N*3)]
for i in range(N):
    M[i *3], M[i * 3 +1] = input().split()
    M[i * 3 + 2] = i + 1
arr = [[0 for column in range(3)] for row in range(N)]
for i in range(N):
    arr[i][0] = M[i *3]
    arr[i][1] = int(M[i * 3 +1])
    arr[i][2] = M[i * 3 +2]
arr = sorted(arr, key=lambda x:(x[0], x[1]), reverse = True)
arr = sorted(arr, key=lambda x:x[0])
for i in range(N):
    print(arr[i][2])

Solution (Python):
if __name__ == '__main__':
    N = int(input())

    SP_list = [[i+1] + list(input().split()) for i in range(N)]

    SP_list = [[int(sp[0]), str(sp[1]), int(sp[2])] for sp in SP_list]

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

Solution (Python):
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)

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

Solution (Python):
n=int(input())
cityscore=[]
cityscore_true=[]
for i in range(n):
  s,p=input().split()
  cityscore.append((s,int(p)))
cityscore_true=sorted(cityscore)
for i in range(n):
  for j in range(n):
    if cityscore_true[i][0]==cityscore_true[j][0]:
      if cityscore_true[i][1]>cityscore_true[j][1]:
        cityscore_true.insert(j,cityscore_true[i])
        cityscore_true.pop(i+1)
for i in range(n):
  print(cityscore.index(cityscore_true[i])+1)

Solution (Python):
N=int(input())
S=[['' for i in range(3)] for j in range(N)]
S3=[['' for i in range(3)] for j in range(N)]
for i in range(N):
  a=input().split()
  S[i][0]=(int(a[1]))
  S[i][1]=(a[0])
  S[i][2]=(i+1)
S2=sorted(S, reverse=True, )
for i in range(N):
  S3[i][0]=S2[i][1]
  S3[i][1]=S2[i][0]
  S3[i][2]=S2[i][2]
S4=sorted(S3, key = lambda x:x[0])
for i in range(N):
  print(S4[i][2])

Solution (Python):
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)

Solution (Python):
n = int(input())
sp = {}
ids = {}

for i in range(n):
    tmp = input().split()

    if tmp[0]in ids:
        ids[tmp[0]][int(tmp[1])] = i+1
    else:
        ids[tmp[0]] = {}
        ids[tmp[0]][int(tmp[1])] = i+1

    if tmp[0] in sp:
        sp[tmp[0]].append(int(tmp[1]))
    else:
        sp[tmp[0]] = [int(tmp[1])]

ks = list(sp.keys())
ks.sort()

for k in ks:
    sp[k].sort(reverse=True)
    
    for i in range(len(sp[k])):
        print(ids[k][sp[k][i]])

Solution (Python):
def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    
    left = arr[:mid]
    right = arr[mid:]

    
    left = merge_sort(left)
    right = merge_sort(right)

    
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    
    while l_i < len(left) and r_i < len(right):
        
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged



N = int(input())
 
list = []
 
for i in range(N):
    A, B = input().split()
 
    A = A + "000000000000"
    A = A[:10]
    B = str(2000-int(B))+str(i+1001)
    list.append(A+B)
 
list = merge_sort(list)
 
for i in list:
    print(int(i[-3:]))

Solution (Python):
import numpy as np

N = int(input())
city = [0]*N
score = [0]*N
itetator = [0]*N
for i in range(N):
    city_i, score_str = input().split()
    city[i] = city_i
    score_i = int(score_str)
    score[i] = score_i
    itetator[i] = i+1
for j in range(N):
    for k in range(N-1):
        if city[k] > city[k + 1]:
            city[k], city[k + 1] = city[k + 1], city[k]
            score[k], score[k + 1] = score[k + 1], score[k]
            itetator[k], itetator[k + 1] = itetator[k + 1], itetator[k]

        elif city[k] == city[k + 1] and score[k] < score[k + 1]:
            score[k], score[k + 1] = score[k + 1], score[k]
            itetator[k], itetator[k + 1] = itetator[k + 1], itetator[k]


for m in range(N):
    print("{}".format(itetator[m]))

Solution (Python):
n = int(input())
res = []
for i in range(n):
    a,b = input().split()
    res.append ((a,b))        
res_1 = sorted(res,key=lambda x: (x[0], -int(x[1])))
for i in range(len(res_1)):
    print(res.index(res_1[i])+1)

Solution (Python):
N = int(input())

S = [0] * N
P = [0] * N
A = [[i] * 3 for i in range(1, N+1)]

for i in range(N):
    S[i], P[i] = input().strip().split()

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

A.sort(key=lambda x: x[2], reverse = True)
A.sort(key=lambda x: x[1])

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

Solution (Python):
from collections import defaultdict
from itertools import cycle
N = int(input())
S = []
P = []
for i in range(N):
    s,p = input().split()
    S.append(s)
    P.append(int(p))

dic = defaultdict(list)
for s,p in zip(S,P):
    dic[s].append(p)

for k in dic:
    dic[k].sort(reverse = True)

city = sorted(set(S))

SP = dict()
for i,s,p in zip(range(1,N+1),S,P):
    SP[(s,p)] = i
ans = []
for c in city:
    for po in dic[c]:
        ans.append((c,po))
for a in ans:
    print(SP[a])

Solution (Python):
n = int(input())

d1 = dict()

for i in range(n):
	s, p = [x for x in input().split()]
	if (s not in d1.keys()):
		d1[s] = []
		d1[s].append((int(p), i + 1))
	else:
		d1[s].append((int(p), i + 1))

for v in d1.values():
	v.sort(reverse = True)

l1 = list()

for k, v in d1.items():
		l1.append((k, v))

l1.sort()

for i in range(len(l1)):
	for j in l1[i][1]:
		print(j[1])

Solution (Python):
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)

Solution (Python):
n = int(input())
ss = []
for i in range(n):
    s, p = input().split()
    ss.append(s+"{:03}".format(200-int(p)))

sss = []
for s in ss:
    sss.append(s)
sss.sort()
for s in sss:
    print(ss.index(s)+1)

Solution (Python):
n = int(input())
shop_list = list()
shop_dict = dict()
for i in range(n):
  s, p = input().split()
  p = int(p)
  shop_list.append(tuple([s, p]))
  shop_dict[tuple([s,p])] = i + 1
  
shop_list = sorted(shop_list, key = lambda x:x[1], reverse = True)

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


for shop in shop_list:
  print(shop_dict[shop])

Solution (Python):
n=int(input())
rows=[input().split() for i in range(n)]
new_rows=sorted(rows)
new_rows.sort(key=lambda x: (x[0],-int(x[1])))
for i in range(n):
    print(rows.index(new_rows[i])+1)

Solution (Python):
N = int(input())
Lis = []
for i in range(N):
	S, P = input().split()
	Lis.append([i+1, S, int(P)])
Lis = sorted(Lis, key = lambda x: (x[1], -x[2]))
for i in range(N):
	print(Lis[i][0])

Solution (Python):
n = int(input())
sp = []
for i in range(n):
    s = input().split()
    s[1] = int(s[1])
    s.append(i+1)
    sp.append(s)

sp2 = sorted(sp, key=lambda x:(x[0],-x[1]),reverse=False)

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

Solution (Python):
N = int(input())
dic = {}
lt = []
for i in range(N):
	S, P = map(str, input().split())
	lt.append([S, int(P)])
	dic.setdefault(S, []).append(int(P))
dic = sorted(dic.items())
for i in range(len(dic)):
	key = dic[i][0]
	value = dic[i][1:][0]
	value.sort(reverse=True)
	for j in range(len(value)):
		print(lt.index([key, value[j]]) + 1)

Solution (Python):
from operator import itemgetter as ite

n=int(input())
l=[]
name=[]
for i in range(n):
    l.append(list(input().split()))
    name.append(l[i][0])
name=set(name)
name=list(name)
name.sort()

na=len(name)
tmp=99
k=0
ma=0
while k!=na:
    for j in range(len(l)):
        if l[j][0]==name[k]:
            if ma<=int(l[j][1]):
                ma=int(l[j][1])
                out=j
    if tmp==out:
        k+=1
    else:
        print(out+1)
        l[out][1]=-3
    ma=0
    tmp=out

Solution (Python):
n = int(input())
ans = []

for i in range(n):
    x, y = input().split()
    y = int(y)
    ans.append([x, y])

newans = ans.copy()

newans.sort(key = lambda x: (x[0], -x[1]))
for i in newans:
    print(ans.index(i)+1)

Solution (Python):
from collections import defaultdict
N = int(input())
alst = []
slst = defaultdict(list)
for i in range(N):
    k, v = map(str, input().split())
    slst[k].append(v)
    alst.append(k + ',' + v)

tmp = sorted(slst)
xlst = []
for i in tmp:
    x = slst[i]
    xx = []
    for j in x:
        xx.append(int(j))
    xtmp = sorted(xx, reverse=True)
    for j in xtmp:
        xlst.append(i + ',' + str(j))

anslst = [0] * N
anstmp = 0
for i in xlst:
    for j in range(len(alst)):
        if alst[j] == i:
            anslst[anstmp] = j + 1
            anstmp += 1
            break

for i in anslst:
    print(i)

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
j = []
h = []
index = 1
for i in range(n):
    s, p = readms()
    p = -(int(p))
    heapq.heappush(h, (s, p,index))
    index += 1
index = 1
while(h):
    s,p,index = heapq.heappop(h)
    print(index)

Solution (Python):
from collections import defaultdict
N = int(input())
dic = defaultdict(list)
dic2 = {}
for i in range(N):
    S,P = input().split()
    new = [P,i]
    dic[S].append(new)
ans = sorted(dic.items(), key=lambda x: x[0])
for i in ans:
    new_i = list(i)[-1]
    
    x = []
    for i1 in new_i:
        
        dic2[i1[0]] = i1[-1]
        x.append(int(i1[0]))
    else:
        x.sort(reverse=True)
        for i in x:
            print(dic2[str(i)]+1)

Solution (Python):


N = int(input())

list = []
for i in range(N):
    a,b = input().split()
    list.append((a, int(b), int(i+1)))

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

Solution (Python):
n = int(input())
sp = []
for i in range(n):
    a,b= input().split(" ")
    sp.append([a,int(b),i+1])
sp.sort()

ans = []
t = []
for j in range(len(sp)):
    if j == len(sp) - 1:
        t.append(sp[j])
        t.reverse()
        ans.append(t)
        break
    if sp[j][0] == sp[j+1][0]:
        t.append(sp[j])
    else:
        t.append(sp[j])
        t.reverse()
        ans.append(t)
        t = []

for w in ans:
    for x,y,z in w:
        print(z)

Solution (Python):
N = int(input())
SP = [input().split() for n in range(N)]



sp = {s.lower()+' '+"{:03}".format(100-int(p)):n+1 for n, (s, p) in enumerate(SP)}


for k in sorted(sp):
    print(sp[k])

Solution (Python):
n = int(input())
dic = []
for i in range(n):
    a,b=input().split()
    b=int(b)
    dic.append([a,b])
dic1 = sorted(dic, key=lambda x:(x[0], -x[1]))
for i in dic1:
    print(dic.index(i)+1)

Solution (Python):
N = int(input())
info = []
for i in range(N):
  list = []
  S_i,P_i=input().split()
  list.append(S_i)
  list.append(100-int(P_i))
  list.append(i)
  info.append(list)
info.sort()
for i in range(N):
  print(info[i][2]+1)

Solution (Python):
def main():
    N = int(input())
    data = []
    for i in range(1, N+1):
        tmp = []
        city, score = input().split()
        tmp.append(i)
        tmp.append(city)
        tmp.append(int(score))
        data.append(tmp)

    data.sort(key=lambda x: x[2], reverse = True)
    data.sort(key=lambda x: x[1])

    for i in range(0, N):
        print(data[i][0])


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=[]
b=[]


for i in range(n):
    s,p=input().split()
    p=int(p)
    a.append(s)
    b.append(p)

x=list(zip(a,b))

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

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

Solution (Python):
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()

Solution (Python):
N = int(input())

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

x.sort()

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

Solution (Python):
n=int(input())
l=[[0]*3 for _ in range(n)]
for i in range(n):
  s,c=input().split()
  l[i][0]=s
  l[i][1]=int(c)
  l[i][2]=int(i+1)
A=sorted(l,key=lambda x:(x[0],-x[1]))
for i in range(n):print(A[i][2])

Solution (Python):
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)

Solution (Python):
N = int(input())
from collections import defaultdict
res = defaultdict(list)
for i in range(N):
    S1,P1 = input().split()
    res[S1].append([int(P1),i])

for k,v in sorted(res.items()):
    lists = sorted(res[k],reverse=True)
    
    for l in lists:
        print(l[1]+1)

Solution (Python):
from operator import itemgetter
n = int(input())
s = [input().split() for i in range(n)]
for i in range(len(s)):
    s[i].append(i+1)
    s[i][1] = int(s[i][1])
s = sorted(s,key=lambda x:(x[0],-x[1]))

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

Solution (Python):
import numpy as np
n = int(input())

x =[]
for i in range(n):
    x1, y1 = [i for i in input().split()]
    x.append(x1+"{0:04d}".format(100-int(y1)))

for i in range(len(x)):
    print(np.argsort(x)[i]+1)

Solution (Python):
r_num = int(input())
r_list = []

for i in range(r_num):
    name, score = input().split()
    temp_li = [i + 1, name, int(score)]
    r_list.append(temp_li)

r_sorted_li = sorted(r_list, key = lambda x:(x[1],-x[2]))

for index, name, score in r_sorted_li:
    print(index)

Solution (Python):
from sys import stdin


n = int(stdin.readline().rstrip())
a = [stdin.readline().rstrip().split() for _ in range(n)]





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






a.sort()

for i in range(n):
    for j in range(n-1):
        if(a[j][0]==a[j+1][0] and a[j][1]<a[j+1][1]):
            k=a[j]
            a[j]=a[j+1]
            a[j+1]=k


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

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

Solution (Python):
n=int(input())

line=[]

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

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

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

Solution (Python):
N=int(input())
lis=[]
for i in range(N):
    A,B=input().split()
    B=str(999-int(B))
    lis.append(A+B+'_'+str(i))
               
lis=sorted(lis)
for i in range(N):
    print(int(lis[i].split('_')[1])+1)

Solution (Python):
N = int(input())

List = []

for i in range(N):
    S_i,P_i = map(str, input().split() )
    temp_list = [i+1, S_i, int(P_i)]
    List.append(temp_list)

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

for j in range(N):
    print(str(result[j][0]))

Solution (Python):

def main():
    N = int(input())
    SP_list = [list(list(input().split())) for i in range(N)]

    
    

    for i, line in enumerate(SP_list):
        line[1] = -int(line[1])
        line.append(str(i + 1))
    SP_list.sort(key=lambda x: (x[1], x[2]))
    SP_list.reverse()
    SP_list.sort()

    for line in SP_list:
        print(line[2])
    pass


if __name__ == '__main__':
    main()

Solution (Python):
from operator import itemgetter

N = int(input())

book = []

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

book = sorted(book, key = itemgetter(2), reverse = True)
book = sorted(book, key = itemgetter(1))

for num in book:
  print(int(num[0])+1)

Solution (Python):

N=int(input())

G = []
for i in range(N):
    array = list(input().strip().split())
    G.append(array)
for i, alpha in enumerate(G):
    alpha.append(i)
for i in range(0,N):
    y=G[i][1]
    G[i][1]=int(y)



tmp = sorted(G, key=lambda x:x[1], reverse=True)
b= sorted(tmp, key=lambda x:x[0])

for i in range (0,N):
    print(int(b[i][2])+1)

Solution (Python):
import sys

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

for i in range(0,n):
    si,pi = input().split()
    list.append({'i':i,'s':si,'p':int(pi)})

list = sorted(list, key=lambda x: (x['s'],-x['p'])) 

for i in range(0,n):
    print(list[i]['i']+1)

Solution (Python):
from operator import itemgetter
N = int(input())
rest = []

for i in range(N) :
  raw = list(input().split())
  raw[1] = int(raw[1]) 
  raw.append(int(i + 1))
  rest.append(raw)

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

for k in range(N) :
  print(rest[k][2])

Solution (Python):
n = int(input())
restaurants = {}
cities = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    if s not in cities:
        cities.append(s)
    if s not in restaurants.keys():
        restaurants[s] = []
    restaurants[s].append([p, i+1])

cities.sort()
for city in cities:
    restaurants[city] = sorted(restaurants[city], key=lambda x:x[0], reverse=True)
    for res in restaurants[city]:
        print(res[1])

Solution (Python):
N = int(input())
restran_dict = {}
for i in range(N):
  city, score = input().split()
  try: 
    restran_dict[city].append((i+1,int(score)))
  except :
    restran_dict[city] = []
    restran_dict[city].append((i+1,int(score)))

sorted_city_names = sorted(restran_dict.keys())

def get_score_id(dict_,key_):
    return [(i,v, key_) for i,v in reversed(sorted(dict_[key_],key=lambda x:x[1]))]
result_list = []
for k in sorted_city_names:
  result_list.extend(get_score_id(restran_dict,k))
for i in result_list:
  print(i[0])

Solution (Python):
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)

Solution (Python):
n = int(input())
sp = []
for i in range(n):
    sp.append(list(input().split()))
ans = sorted(sp,key=lambda x:int(x[1]),reverse=True)
ans1 = sorted(ans,key=lambda x:x[0])
for i in ans1:
    print(sp.index(i) + 1)