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

"""
AtCoder A
"""
import math






from operator import itemgetter

def main():
    N = int(input())
    S=[]
    P=[]
    for i in range(N):
        s, p = str(input()).split()
        
        S.append([s,int(p)])
        P.append(p)
    
    
    indx=sorted(range(len(S)), key=lambda k: S[k])
    
    
    
    prei=S[indx[0]][0]
    tmp=[]
    out=[]
    for i in indx:
        if prei!=S[i][0]:
            if tmp:
                tlist=sorted(range(len(tmp)), key=lambda k: tmp[k])
                tlist.reverse()
                for t in tlist:
                    out.append([prei,tmp[t]])
                tmp=[]
            prei=S[i][0]
        tmp+=[S[i][1]]
        prei=S[i][0]

    tlist=sorted(range(len(tmp)), key=lambda k: tmp[k])
    tlist.reverse()
    for t in tlist:
        out.append([prei,tmp[t]])
    
    for o in out:
        print(S.index(o)+1)
    




    
    
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
L = []
S = []
for i in range(N):
    L.append(input())
    C, P = L[i].split()
    S.append('{:s} {:3d}'.format(C, 100-int(P)))
S.sort()

LS = []
for i in range(N):
    C, P = S[i].split()
    LS.append('{:s} {:d}'.format(C, 100-int(P)))
    
for i in range(N):
    for j in range(N):
        if LS[i] == L[j]:
            print(j+1)

Solution (Python):
n = int(input())
c = {}
for i in range(n):
    s = input().split()
    if s[0] not in c:
        c[s[0]] = list()
    c[s[0]].append((int(s[1]), i))
s = sorted(c.keys())
for i in s:
    for r in sorted(c[i], key = lambda p : p[0])[-1::-1]:
        print(r[1] + 1)

Solution (Python):
N = int(input())
l = []
for i in range(N):
    s, p = input().split(' ')
    l.append([s, int(p), i+1])
l.sort(key=lambda x:(x[0], -x[1]))
_ = [print(a[2]) for a in l]

Solution (Python):
N = int(input())
L = []
for i in range(N):
    L.append(list(input().split()))
A = [i for i in range(1, N+1)]
tL = list(zip(*L))
B = tL[0]
C = map(int, tL[1])
Z = list(zip(A, B, C))
sortZ = sorted(Z, key=lambda x:x[2],reverse = True)
ans = sorted(sortZ, key=lambda x:x[1])
for i in range(N):
    print(ans[i][0])

Solution (Python):

from operator import itemgetter
N = int(input())
L = []
for i in range(N):
    n = i + 1
    s, p = input().split()
    s = str(s)
    p = int(p)
    tmp = (s,p,n)
    L.append(tmp)
ls = sorted(L, key = itemgetter(1), reverse = True)
ls = sorted(ls, key = itemgetter(0))
for itm in ls:
    print(itm[2])

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

sp = [(s, -int(p), i) for i, (s, p) in enumerate(sp)]

result = sorted(sp, key = lambda x: (x[0], x[1]))

for s, p, i in result:
    print(i + 1)

Solution (Python):
N = int(input())
a = []
for x in range(N):
	i = x + 1
	S_i, P_i = input().split()
	a.append([S_i, int(P_i), i])

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

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

Solution (Python):
N = int(input())
array = []
for i in range(N):
    array.append(list(map(str, input().split())))
array_new = sorted(array, key=lambda x: (x[0], -int(x[1])))
for i in range(N):
    print(int(array.index(array_new[i])+1))

Solution (Python):
N = int(input())
d = {}
city = []
for i in range(N):
    s, p = input().split()
    d[i] = (s, p)
    if s not in city:
        city.append(s)

ans = []
city.sort()
for c in city:
    key = [k for k, v in d.items() if v[0] == c]
    num = [int(d[k][1]) for k in key]
    key_num = [(key[i], num[i]) for i in range(len(key))]
    key_num = sorted(key_num, key=lambda x:int(x[1]), reverse=True)
    key_num = [k[0] + 1 for k in key_num]
    ans += key_num

for a in ans:
    print(a)

Solution (Python):
N = int(input())
SP = [input().split() for i in range(N)]
S = []
P = []
P_index = []
for i in range(len(SP)):
  SP[i][1] = int(SP[i][1])
  S.append(SP[i][0])
  P.append(SP[i][1])

SN = sorted(S)
num = []
for j in range(len(SN)):
  num.append([i for i, x in enumerate(S) if x == SN[j]])

num_uniq = []
for x in num:
    if x not in num_uniq:
        num_uniq.append(x)

for i in range(len(num_uniq)):
  P_queue = []
  for j in range(len(num_uniq[i])):
    P_queue.append([P[num_uniq[i][j]],num_uniq[i][j]])
  P_only = []
  for j in range(len(num_uniq[i])):
    P_only.append(P_queue[j][0])
  P_o = sorted(P_only,reverse=True)
  for j in range(len(num_uniq[i])):
    P_index.append(P.index(P_o[j]))
    
for i in range(len(P_index)):
  print(P_index[i]+1)

Solution (Python):
t = int(input())
data = []
ans = []
c = 0
for i in range(t):
    n, p = map(str, input().split())
    p = int(p)
    data.append([n, p, i+1]) 
data = sorted(data, key=lambda x: x[1], reverse=True)
data = sorted(data, key=lambda x: x[0])


for i in range(len(data)):
    ans.append([i, data[i][2]])

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

for i in ans:
    print(i[1])

Solution (Python):
N = int(input())
items = []

for i in range(N):
    s, p = [v for v in input().split()]
    dic = {'city':str(s), 'score':-int(p), 'index':i+1}
    items.append(dic)

sorted_items = sorted(items, key = lambda x: (x['city'], x['score']))
for s in sorted_items: print(s['index'])

Solution (Python):

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

for i in range(N):
    for k in range(N-1):
        if rest_list[k][0] == rest_list[k+1][0]:
            if rest_list[k][1] < rest_list[k+1][1]:
                temp = rest_list[k]
                rest_list[k] = rest_list[k + 1]
                rest_list[k + 1] = temp
        elif rest_list[k][0] > rest_list[k+1][0]:
            temp = rest_list[k]
            rest_list[k] = rest_list[k+1]
            rest_list[k+1] = temp

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

Solution (Python):
N=int(input())
inl= [] 
for i in range(N):
    name, score = input().split()
    score = -int(score)
    inl.append((name, score, i+1))

inl.sort()

for name, score, i in inl:
    print(i)

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

Solution (Python):
n=int(input())
c,m=[],[]
d={}
t={}
for i in range(n):
    s,p=map(str,input().split())
    m.append((s,int(p)))
    if s not in c:
        c.append(s)
        d[s]=[int(p)]
    else:
        d[s].append(int(p))
    t[(s,int(p))]=i+1
c.sort()
ans={}
cnt=1
for i in c:
    d[i].sort(reverse=True)
    for j in d[i]:
        ans[cnt]=(i,j)
        cnt+=1
for i in range(1,n+1):
    print(t[ans[i]])

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

for key in sorted(d.keys()):
    for dk in sorted(d[key], reverse=True):
        print(dk[1])

Solution (Python):
num1 = int(input())
numArray = [[0]*2]*num1

for index1 in range(num1):
    numArray[index1] = [j for j in input().split()]
    numArray[index1].append(index1+1)
    numArray[index1][1] = int(numArray[index1][1])

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

for index2 in range(num1):
    print(numArray[index2][2])

Solution (Python):
N = int(input())
rests = []

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

def sort(A):
    for i in range(0, len(A) - 1):
        modify_order(A, i)

def modify_order(A,i):
    for j in range(len(A) - 1, i, -1):
        if A[j-1][0] == A[j][0] and A[j-1][1] < A[j][1]:
            A[j-1], A[j] = A[j], A[j - 1]
        elif A[j-1][0] > A[j][0]:
            A[j-1], A[j] = A[j], A[j - 1]

sort(rests)

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

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

Solution (Python):
from __future__ import print_function


import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

import math
import string
import fractions
import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop



import random


def main():
    n = int(input())
    dict={}
    for i in range(n):
        name, score= input().split()
        if not(name in dict):
            dict[name]=[((int(score),i+1))]
        else:
            dict[name].append((int(score),i+1))
            dict[name].sort(reverse=True)
    eprint(dict)
    ll=list(dict.items())
    eprint(ll)
    ll.sort()
    eprint(ll)
    for x in ll:
        for y in x[1]:
            print(y[1])
        
if __name__ == '__main__':
    main()

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

for i in range(n):
    a, b = input().split()
    arr.append([str(i+1), a, b])

arr2 = sorted(arr, key=lambda x:(x[1], -int(x[2])))

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

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

SP = [list(input().split()) for _ in range(N)]

sp=[]
count=1
for s,p in SP:
    sp.append([s,int(p),count])
    count+=1
    

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

for i,j,k in sp:
    print(k)

Solution (Python):
N=int(input())
L = []
for i in range(1,N+1):
    S,P = input().split()
    if P == "0":
        L.append([i,S+"9999999999"])
    elif 100-int(P) < 10:
        L.append([i,S+"0"+str(100-int(P))])
    else:
        L.append([i,S+str(100-int(P))])

L.sort(key=lambda x:x[1])
for i in range(N):
    print(L[i][0])

Solution (Python):
N = int(input())
list = []
cities = []
for i in range(N):
    L, R = input().split()
    list.append([L,int(R),i+1])
    cities.append(L)
li = []
for i in cities:
    if i in li:
        pass
    else:
        li.append(i)
li.sort()
cata = []
for i in li:
    cur_i = []
    for j in list:
        if j[0] == i:
            cur_i.append(j[1:3])
    cata.append(cur_i)
anslist = []
for i in cata:
    i.sort(reverse=True,key=lambda x: x[0])
    for j in i:
        anslist.append(j[1])
for i in anslist:
    print(i)

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

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


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

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

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

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

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

Solution (Python):
from operator import itemgetter, attrgetter
N = int(input())
keys=[]
values=[]
nums = []
number = 0 

for i in range(N):
    num = i+1
    a, b = input().split()
    nums.append(num)
    keys.append(a)
    values.append(int(b))

d = zip(nums, keys, values)

dout = sorted(d, key=itemgetter(2), reverse=True)
dout = sorted(dout, key=itemgetter(1))

nu, a, b = zip(*dout)
for n in nu:
    print(n)

Solution (Python):
n = int(input())
restaurants = []
for index in range(n):
    tmp = input().split()
    restaurants.append((tmp[0], int(tmp[1]), index + 1))

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

for restaurant in restaurants:
    print(restaurant[2])

Solution (Python):
(lambda N:print("\n".join(list(map(lambda t:str(t[2]+1),sorted([(lambda t:(t[0],int(t[1]),i))(input().split())for i in range(N)],key=lambda t:(t[0],-t[1])))))))(int(input()))

Solution (Python):
n = int(input())
list = []
for i in range(1, n+1):
    s, p = input().split()
    p = int(p)
    dict = {}
    dict["i"] = i
    dict["s"] = s
    dict["p"] = p
    list.append(dict)

tmp = sorted(list, key=lambda x:x['p'], reverse=True)
ans = sorted(tmp, key=lambda x:x['s'])
for a in ans:
    print(a["i"])

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

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

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

shops = sorted(shops, key=lambda x: (x[1], -x[2]), reverse=False)

for sh in shops:
	print(sh[0])

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


restaurants = []
names = []

for i in range(N):
    S,P = (input().split())
    P = int(P)
    newinput = [S,P]
    restaurants.append([S,P])
    if S not in names:
        names.append(S)

names.sort()
sortedrestaurants = sorted(restaurants, key=lambda x: x[1], reverse = True)

ans = []
for i in range(len(names)):
    for j in range(N):
        if sortedrestaurants[j][0] == names[i]:
            ans.append(sortedrestaurants[j])

for i in range(N):
    print(restaurants.index(ans[i])+1)

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

sp= [[input().split(),i+1] for i in range(N)]

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




for k in sd2:
  print(k[1])

Solution (Python):
n = int(input())
d = []
t = [0] * n

for i in range(n):
    d.append(input().split())
    d[i].append(str(i + 1))

a = sorted(d, key=lambda x: (x[0], -int(x[1])))

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

Solution (Python):
N = int(input())
List = [list(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[0],-x[1]))

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

Solution (Python):










import numpy as np
import math
import copy

n=int(input())

ls = []
for i in range(n):
    a, b = input().split()
    ls.append([a,int(b),i])

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


new_ls =[]
city = ls_s[0][0]
tmp = []
for elem in ls_s:
    if city == elem[0]:
            tmp.append(elem)
    else:
        city = elem[0]
        new_ls.extend(sorted(tmp, key=lambda x:x[1], reverse=True))
        tmp = []
        tmp.append(elem)
new_ls.extend(sorted(tmp, key=lambda x:x[1], reverse=True))
for elem in new_ls:
    print(elem[2] + 1)

Solution (Python):
x=[]
n=int(input())
i=0
c=[]
while i!=n:
    i=i+1
    a=input().split()
    a[1]=int(a[1])
    a.append(i)

    x.append(a)
x=sorted(x, key=lambda x: -x[1])

x.sort()


while True:
    try:
        c=[]
        a=x[0]
        b=a[0]
        i=0
        c.append(x[0])
        del x[0]
        while True:
           try:

               a=x[0]
               bb=a[0]
               if b==bb:
                   c.append(x[0])
                   del x[0]
               else:
                   break
           except:
               break
        c = sorted(c, key=lambda x: -x[1])

        i=0
        while True:
            try:
                k=c[i]
                ans=k[2]
                i=i+1
                print(ans)
            except:
                break
    except:
        break

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

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

Solution (Python):
n =  int(input())
r = [0]*n

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

Solution (Python):
n=int(input())
s=[0]*n
p=[0]*n
for i in range(n):
  s[i],p[i]=input().split()
a=[[s[i],int(p[i]),i+1]for i in range(n)]
a.sort(key=lambda x:(x[0],-x[1]))     
for i in range(n):
  print(a[i][2])

Solution (Python):

N = int(input())
R_list = []
for i in range(N):
    S, P=map(str, input().split())
    R_list.append([S , int(P)*-1 , i+1])
R_list.sort()
for i in range(N):
    R_list[i].append(i+1)
R_list.sort(key=lambda x:x[3])
for i in range(N):
    print(R_list[i][2])

Solution (Python):



n = input()

n = int(n)

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

    s = s
    p = str(100 - int(p)).zfill(3)

    id = s + "__" + p + "__" + str(i+1)

    d += (id,)

d.sort()

for i in d:
    i = i.split("__")

    print(i[2])

Solution (Python):
l = []
n = int(input())
for i in range(n):
    key, val = input().split()
    val = int(val)
    l.append((key, val, i+1))

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

Solution (Python):
N = int(input())
book = []
for i in range(N):
    key, val = input().split()
    val = tuple((int(val), i))
    book.append(tuple((key, val)))

book_sorted = sorted(book)

book_sorted.append(('xxxxxxxxxxxx',(1,1)))
tmp = [book_sorted[0][1][1]]
for i in range(N):
    if book_sorted[i][0] != book_sorted[i+1][0]:
        for k in range(len(tmp)):
            print(tmp[-1-k]+1)
        tmp = [book_sorted[i+1][1][1]]
    else:
        tmp.append(book_sorted[i+1][1][1])

Solution (Python):
from collections import defaultdict
N = int(input())
dict = defaultdict(list)
dlist = []
names =[]
newnums = []
for n in range(N):
    s,p = input().split()
    dlist.append((s,int(p)))
    dict[s].append(int(p))
    names.append(s)
names.sort()
usedname = []
for name in names:
    if name in usedname:
        continue
    usedname.append(name)
    numlist = dict[name]
    numlist.sort(reverse=True)
    for num in numlist:
        print(dlist.index((name,int(num)))+1)

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

ss = {}

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

for city in sorted(ss.keys()):
  for poi in sorted(ss[city].keys(),reverse=True):
    print(ss[city][poi])

Solution (Python):
from operator import itemgetter

n = int(input())
w = []
for i in range(n):
    s,p = map(str,input().split())
    p = int(p)
    w.append((s,p,i))
w = list(sorted(w,key=itemgetter(1),reverse=True))
w = list(sorted(w,key=itemgetter(0)))

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

Solution (Python):
n=int(input())
import numpy as np
S = [[0,0]]
for i in range(n):
  s,p = list(input().split())
  S.append([s,int(p),i])
del S[0]
newarr = sorted(S, key=lambda x:(x[0],-x[1]), reverse=False)
for i in range(n):
  print(newarr[i][2]+1)

Solution (Python):
from collections import OrderedDict
N = int(input())

rest = OrderedDict()
num = {}
for i in range(N):
    s = input().split()
    rest.setdefault(s[0],[]).append(int(s[1]))
    num[s[0] +s[1]] = i + 1

book = OrderedDict(sorted(rest.items(), key=lambda t: t[0]))

for k,v in book.items():
    a = list(v)
    a.sort(reverse=True)
    for i in a:
        print(num[k + str(i)])

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

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

for i, s, p in sorted(sorted(score, key=lambda x:x[2], reverse=True), key=lambda x:x[1]):
    print(i)

Solution (Python):
import copy
N = int(input())
hai = []
hai2 = []
datanum = 1
for i in range(N):
    name, num = input().split()
    num = int(num)
    hai.append(name)
    hai.append(num)
    hai.append(datanum)
    hai3 = copy.copy(hai)
    hai2.append(hai3)
    hai.clear()
    datanum += 1
hai2.sort(key=lambda x:(x[0], -x[1]))


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

Solution (Python):
n = int(input())
li = [0]*n
for i in range(n):
  li[i] = input().split()
  li[i] = li[i] + [i]

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

Solution (Python):
N=int(input())
Slist=list()
Plist=list()
tmp=list()
for i in range(N):
    S,P=input().split()
    Slist.append(S)
    Plist.append(int(P))
    tmp.append(int(P))
change = True
while change:
    change = False
    for i in range(len(Plist) - 1):
        if Plist[i] < Plist[i + 1]:
            Plist[i], Plist[i + 1] = Plist[i + 1], Plist[i]
            Slist[i], Slist[i + 1] = Slist[i + 1], Slist[i]
            change = True
change = True
while change:
    change = False
    for i in range(len(Slist) - 1):
        if Slist[i] > Slist[i + 1]:
            Slist[i], Slist[i + 1] = Slist[i + 1], Slist[i]
            Plist[i], Plist[i + 1] = Plist[i + 1], Plist[i]
            change = True
ans=list()
for i in range(N):
    ans.append(tmp.index(Plist[i]))
for i in range(N):
    print(ans[i]+1)

Solution (Python):
N = int(input())
namelist = [input().split() for i in range(N)]
for i in range(N):
  namelist[i].append(i+1)
namelist.sort(key=lambda x:-int(x[1]))
namelist.sort(key=lambda x:x[0])
for i in range(N):
  print(namelist[i][2])

Solution (Python):

n = int(input())
rlist = []
for i in range(n):
    s, p= input().split()
    rlist.append({'i':i+1, 's':s, 'p':int(p)})

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

for r in sorted_items:
    print(r['i'])

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

restraunts = []

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

restraunts.sort()

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

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

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


if __name__ == '__main__':
    main()

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

l = []

for i in range(N):
    s , p = map(str, input().split())
    p = 100-int(p)
    if p == 100:
        l.append(s+str(999))
    elif p < 10:
        l.append(s+str(0)+str(p))
    else:
        l.append(s+str(p))
l_new = sorted(l)


for i in l_new:
    print(l.index(i)+1)

Solution (Python):
from collections import OrderedDict
n = int(input())
t = [input().split() for i in range(n)]
c =1
for i in range(n):
  t[i][1] = int(t[i][1])
  t[i].append(c)
  c = c+1
  
s = sorted(t,key=lambda x:x[1],reverse=True)
s = sorted(s,key = lambda x:x[0])

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

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

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

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

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

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

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

Solution (Python):
import sys
from operator import itemgetter
input=sys.stdin.readline

N=int(input())
SPs=[0]*N
for i in range(N):
  Str,integ = input().split()
  SPs[i] = [Str,int(integ),i+1]

SPs.sort(key=itemgetter(0))
name=''
queue=[]
for sp in SPs:
  if sp[0] != name:
    queue.sort(key=itemgetter(1),reverse=True)
    for q in queue:
      print(q[2])
    queue=[]
    name = sp[0]
    queue.append(sp)
  else:
    queue.append(sp)
queue.sort(key=itemgetter(1),reverse=True)
for q in queue:
  print(q[2])

Solution (Python):
N = int(input())
restaurants = {}
for i in range(N):
    S, P = input().split()
    if S not in restaurants:
        restaurants[S] = [[int(P), i + 1]]
        continue
    restaurants[S] = restaurants[S] + [[int(P), i + 1]]

restaurants_sorted = sorted(restaurants.items(), key=lambda x:x[0])
for city in restaurants_sorted:
    city = list(city[1])
    city.sort(reverse=True)
    for restaurant in city:
        print(restaurant[1])

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

Solution (Python):


import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        n = int(lines[0])
        for i in range(n):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        n = int(lines[0])

    sp = []
    for i in range(1, n+1):
        token = lines[i].split()
        s = token[0]
        p = int(token[1])
        sp.append((s, p, i))

    return (n, sp)


def solve(n, sp):

    sp2 = [(e[0], -e[1], e[2]) for e in sp]
    sp2.sort()
    for e in sp2:
        print(e[2])


def main():
    



    solve(*parse_input())

if __name__ == '__main__':

    main()

Solution (Python):
from operator import itemgetter
from sys import stdin

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

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

data2 = sorted(data, key=itemgetter(1),reverse=True)
data3 = sorted(data2, key=itemgetter(0))
for k in range(n):
	print(data3[k][2])

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

Solution (Python):
from sys import stdin
N=int(stdin.readline().rstrip())
data=[]
dic=dict()
word=set()
for i in range(N):
    A,B=[x for x in stdin.readline().rstrip().split()]
    word.add(A)
    data.append((A,int(B),i+1))
for j in data:
    dic[j[0]] = []
for k in data:
    dic[k[0]].append((k[1],k[2]))
for l in sorted(list(word)):
    for m in sorted(dic[l],reverse=True):
        print(m[1])

Solution (Python):

N = int(input())

p = []

for j in range(N):
    S, P = input().split()
    p.append((S, int(P), j))




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




for (s,p,j) in sorted_items:
    print(j+1)

Solution (Python):
from operator import itemgetter

n = int(input())

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

for restaurant in sorted(restaurants, key=itemgetter(0, 1)):
  print(restaurant[2])

Solution (Python):
N = int(input())
List = []

for i in range(N):
  A,B = map(str,input().split(' '))
  P = int(B)
  List.append((i,A,P))

sorted_list = sorted(List,key=lambda x:(x[1],-x[2]))

X = []
for j,b in enumerate(sorted_list):
  X.append((j+1,b))
Y = sorted(X,key=lambda x:x[1][0])
Z = []
for i,b in enumerate(Y):
  Z.append((i+1,b))
Z_sort = sorted(Z,key=lambda x:x[1][0])

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

Solution (Python):
from sys import stdin

N = int(input())


bcs = [list(x.split()) for x in stdin.readlines()]

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

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


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

Solution (Python):
N = int(input())
LI = []
for i in range(N):
    s,p = input().split()
    LI.append([s,100-int(p),i+1])
LI.sort()
for i in range(N):
    print(LI[i][2])

Solution (Python):

n = int(input())

city_list =[]
shop_list = []

for i in range(n):
	restaurant = input().split()
	shop_list.append(restaurant+[str(i+1)])
	city = restaurant[0]
	if city not in city_list:
		city_list.append(city)


city_list = sorted(city_list)
b = len(city_list)
for i in range(n):
	shop_list[i][0] = (b - 1 - city_list.index(shop_list[i][0]))
	shop_list[i][0] = shop_list[i][0] * 100 + int(shop_list[i][1])
	del shop_list[i][1]

shop_list= sorted(shop_list,reverse = True)

for i in range(n):
	print(shop_list[i][1])

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

S = []
P = []

test_list = []

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

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

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

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

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

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

result = sorted(city_list, key=lambda x:(x[1], -x[2]))

for j, _, _ in result:
    print(j)

Solution (Python):
from operator import attrgetter

class Restaurant:
    def __init__(self, city, point, num):
        self.city = city
        self.point = point
        self.num = num

n = int(input())

restaurants = []
for i in range(n):
    c, p = map(lambda x: x, input().split(' '))
    restaurants.append(Restaurant(c, 100 - int(p), i + 1))

result = sorted(restaurants, key=attrgetter('city', 'point'))
for r in result:
    print(str(r.num))

Solution (Python):
N = int(input())
SP = [list(map(str, input().split())) for _ in range(N)]

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

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

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

Solution (Python):
N  = int(input())
d = [0 for i in range(N)]
for i in range(N):
    S,P = map(str, input().split())
    d[i] = [S,int(P),i+1]
d.sort()
i = 0
while i < N:
    if i != N-1:
        if d[i][0] != d[i+1][0]:
            print(d[i][2])
            i += 1
        else:
            j = i+1
            while d[j][0] == d[i][0]:
                j += 1
                if j >= N:
                  break
                
                
            for k in reversed(range(i,j)):
                print(d[k][2])
            i = j
    else:
        print(d[i][2])
        break