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())
SP=[[list(input().split()), i+1] for i in range(N)]
for i in range(N):
  SP[i][0][1]=(-1)*int(SP[i][0][1])
SP.sort(key=lambda x:(x[0][0], x[0][1]))
for i in range(N):
  print(SP[i][1])

Solution (Python):
N = int(input())
MAIN = []
for i in range(N):
    S,P = map(str,input().split())
    MAIN.append([S,-int(P)])

ans = sorted(MAIN)
for m in ans:
    print(MAIN.index(m) + 1)

Solution (Python):
N = int(input())
MAIN = []
for i in range(N):
    S,P = map(str,input().split())
    MAIN.append([i+1,S,int(P)])

def swap(i,j):
    x = MAIN[i]
    MAIN[i] = MAIN[j]
    MAIN[j] = x

update = True
while update == True:
    update = False
    for i in range(1,N):
        if MAIN[i][1] > MAIN[i-1][1]:
            continue
        elif MAIN[i][1] == MAIN[i-1][1]:
            if MAIN[i][2] > MAIN[i-1][2]:
                swap(i,i-1)
                update = True
        else:
            swap(i,i-1)
            update = True


for m in MAIN:
    print(m[0])

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

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

for i in range(n):
    print(sp.index(sorted_sp[i]) + 1)

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

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

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

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

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

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

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

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

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

SLICE = [0]
for i in range(n - 1):
    if RESTAURANTS[i][0] != RESTAURANTS[i + 1][0]:
        SLICE.append(i + 1)
SLICE.append(n)

for i in range(len(SLICE) - 1):
    a, b = SLICE[i], SLICE[i + 1]
    RESTAURANTS2 = RESTAURANTS[a:b]
    for restaurant in RESTAURANTS2[::-1]:
        print(restaurant[2])

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

l = []
for i in range(n):
  x,y = map(str,input().split())
  l.append((x,y, i))


L = []

for i in range(n):
  L.append((l[i][0], int(l[i][1]), l[i][2]))

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


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

Solution (Python):

n=int(input())
res=[]
for i in range(n):
    a,b=list(input().split())
    b=-1*int(b)
    res.append([a,b,i+1])
res=sorted(res)
for x in res:
    print(x[2])

Solution (Python):


N=int(input())
restaurants=[]
name=""
score=0
for i in range(N):
    name,score=input().split()
    score=int(score)
    restaurants.append([name,score,i+1])
restaurants=sorted(restaurants,key=lambda x:x[1],reverse=True)
restaurants.sort(key=lambda x:x[0])
for i in range(N):
    print(restaurants[i][2])

Solution (Python):
n=int(input())
l=[]
for i in range(n):
  a,b=input().split()
  b=-1*int(b)
  l.append([a,b,i+1])
l=sorted(l)
for i in range(n):
  print(l[i][2])

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

Solution (Python):
def solve(n, SP):
    return [i for i, _, _ in sorted([(i + 1, s, p) for i, (s, p) in enumerate(SP)], key=lambda v: (v[1], -int(v[2])))]

_n = int(input())
_SP = [input().split() for _ in range(_n)]
print(*solve(_n, _SP), sep='\n')

Solution (Python):
N = int(input())
restaurants = dict()
ans = list()
target = list()
for i in range(N):
	S = list(map(str,input().split()))
	if S[0] not in restaurants :
		restaurants[S[0]] = [int(S[1])]
	else:
		dict_key = restaurants[S[0]]
		dict_key.append(int(S[1]))
		dict_key.sort(reverse=True)
		restaurants[S[0]] = dict_key
	target.append(S[0]+' '+S[1])


restaurants_sorted = sorted(restaurants.items(), key=lambda x:x[0])


for idx in range(len(restaurants_sorted)):
	for i in range(len(restaurants_sorted[idx][1])):
		print(target.index(restaurants_sorted[idx][0]+' '+str(restaurants_sorted[idx][1][i]))+1)

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

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

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

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

sorted_shops = sorted(shops.items(), key=lambda x: x[0])

for s, p in sorted_shops:
  for shop in sorted(p, key=lambda x: x[0], reverse=True):
    print(shop[1])

Solution (Python):

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

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

Solution (Python):
rest = []

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

rest.sort()

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

Solution (Python):
N = int(input())
S = [input().split() for i in range(N)]
S_P = S[:]
for i in range(N):
    S_P[i][1] = -1*int(S_P[i][1])  
S_P.sort()
for i in range(N):
    S_P[i][1] = -1*int(S_P[i][1])
for i in range(N):
    print(S.index(S_P[i])+1)

Solution (Python):
N = int(input())
rest = []
for _ in range(N):
  s = input().split()
  s[1] = int(s[1])
  s.append(_+1)
  rest.append(s)    
rest.sort(key = lambda x:x[0])


tmp = []
A = []
for e in rest:
  if e == rest[0]:
    city = e[0]
  if e[0] == city:
    tmp.append(e)  
  else:
    tmp.sort(key = lambda x:x[1],reverse = True)
    A += tmp    
    tmp = [e]
    city = e[0]
  if e == rest[len(rest)-1]:
    tmp.sort(key = lambda x:x[1],reverse = True)
    A += tmp    
    
for i in A:
  print(i[2])

Solution (Python):
N = int(input())
Michelin = dict()
seen = []
number = 1
for _ in range(N):
    shop,point = map(str,input().split())
    if shop not in seen:
        Michelin[shop] = [[],[]] 
        Michelin[shop][0].append(int(point)) 
        Michelin[shop][1].append(number)
        number += 1
        seen.append(shop)
    else:
        Michelin[shop][0].append(int(point))
        Michelin[shop][1].append(number)
        number += 1
seen.sort() 

for shop in seen:
    while Michelin[shop][0] != []:
        shokai = max(Michelin[shop][0])
        bango = Michelin[shop][0].index(shokai)
        print(Michelin[shop][1][bango])
        Michelin[shop][0].remove(shokai)
        Michelin[shop][1].remove(Michelin[shop][1][bango])

Solution (Python):
import sys
import math

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[1],reverse = True) 
list = sorted(list, key=lambda x:x[0]) 
for j in range(N):
	print(list[j][2])

Solution (Python):
n = int(input())
l = [list(map(str, input().split())) for i in range(n)]
for row in l:
    row[1] = int(row[1])
    row.append(l.index(row))

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

for i in s:
  print(i[2]+1)

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

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

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

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

lts = sorted(lt)

for t in lts:
  print(lt.index(t)+1)

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

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

SP.sort()

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

Solution (Python):
n = int(input())
s = list()
for i in range(n):
    a,b = input().split()
    b = int(b) * -1
    s.append([a,b])
h = sorted(s)
for i in range(n):
    print(s.index(h[i])+1)

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

sp = sorted(sp, key=lambda x:(x[1],-x[2]))
for i,j,k in sp:
  print(i)

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

sorted_SP = sorted(SP, key=lambda x: (x[0], -x[1]))
for *i, j in sorted_SP:
    print(j)

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

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

s=[]
p=[]
f=[]

for i in range(n):
    ss,pp=input().split()
    s.append(ss)
    p.append(int(pp))
    tmp=(ss,int(pp))
    f.append(tmp)

c=zip(s,p)
d=sorted(c,reverse=True)
e=sorted(d,key=lambda x:x[0])


for i in range(n):
    print(f.index(e[i])+1)

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

cities = list(set([sp[i][0] for i in range(n)]))
cities.sort()

for city in cities:
    c = []
    for i in sp:
        if city == i[0]:
            c.append(i[1:])
    c.sort()
    c.reverse()
    for i in c:
        print(i[1])

Solution (Python):

si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
snm = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
l=[]
d=set()
for i in range(n):
    s,p=snm()
    d.add(s)
    l.append([s,int(p),i+1])
l.sort(key=lambda x:(x[0]))
d=list(d)
d.sort()

len_d=len(d)
a=[[] for i in range(len_d)]

for i in range(n):
    for j in range(len_d):
        if d[j]==l[i][0]:
            a[j].append(l[i])

for aa in a:
    aa.sort(key=lambda x:x[1],reverse=True)

for aa in a:
    for aaa in aa:
        print(aaa[2])

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

cities = list(set([sp[i][0] for i in range(n)]))
cities.sort()

for city in cities:
  c = []
  for i in sp:
    if city == i[0]:
      c.append(i[1:])
  
  c.sort()
  
  c.reverse()
  for i in c:
    print(i[1])

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

lst = list()
for i in range(1, N+1):
    s, p = input().split()
    lst.append({"id":i, "s":s, "p":int(p)})

lst.sort(key=lambda x:x["p"], reverse=True)
lst.sort(key=lambda x:x["s"])

for i in range(0, len(lst)):
    print(lst[i]["id"])

Solution (Python):
n=int(input())
A=[input().split() for _ in range(n)]
for i in range(n):
  A[i][1]=-int(A[i][1])
B=sorted(A)
for i in range(n):
  print(A.index(B[i])+1)

Solution (Python):
N = int(input())
book = []
for i in range(N):
    s,p = input().split()
    book.append([s, int(p)*-1])
book1 = sorted(book,key = lambda x:x[1])
book2 = sorted(book1, key = lambda x:x[0])

for i in range(N):
    print(book.index(book2[i])+1)

Solution (Python):
from operator import itemgetter

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

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

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

Solution (Python):
N = int(input())
data = [[x.split(), y ] for x, y in [ [ input(), z+1 ] for z in range(N) ]]

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

current_city_name = ""
result = []
sumup = 0

for elem in data_sorted:
    if current_city_name != elem[0][0] and current_city_name != "":
        result = sorted(result, key=lambda x: x[0])[::-1]
        for res_elem in result:
            print(res_elem[1])
        result = []
        sumup = 0
    result.append([int(elem[0][1]), elem[1]])
    current_city_name = elem[0][0]


result = sorted(result, key=lambda x: x[0])[::-1]
for res_elem in result:
    print(res_elem[1])

Solution (Python):
N=int(input())
sp=[["",0,0] for _ in range(N)]

for i in range(N):
    a,b=map(str,input().split())
    sp[i]=[a,200-int(b),i+1]
sp.sort()

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

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

x.sort()

while len(x) > 0:
   if (x.count(x[0][0]) == 1):
      y = x.pop(0)
      print(y[2])
   else:
      yy = [z for z in x if z[0] == x[0][0]]
      yy.sort(reverse=True)
      [print(z[2]) for z in yy]
      x = [z for z in x if z not in yy]

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

for i in range(N):
    S, P = input().split()
    restaurants.append((i + 1, S, int(P)))

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

for (i, _, _) in restaurants:
    print(i)

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

b = 1
for j in a: 
    j.append(b)
    b += 1

for k in a: 
    x=k.pop(1)
    k.insert(1,int(x)*-1)

a.sort()

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

Solution (Python):

import numpy as np


N = int(input())
A, B = [[], []]

for _ in range(N):
  a, b = [i for i in input().split()]
  A.append(a)
  B.append(int(b))


A = np.array(A)[:, np.newaxis]
B = np.array(B)[:, np.newaxis].astype('int')
C = np.concatenate([A, B], axis=1)
C = C.tolist()

ans = sorted(C, key=lambda x:(x[0],-int(x[1])))

for i in ans:
  print(C.index(i)+1)


"""
df = pd.DataFrame(C, index=[i+1 for i in range(N)])
df = df.sort_values([0, 1], ascending=[True, False])
"""

Solution (Python):
N = int(input())
 
X=[]
for i in range(N):
    S, P = input().split()
    X.append([S,int(P)])
 
sort1=sorted(X, key=lambda x:x[1], reverse=True)
sort2=sorted(sort1, key=lambda x:x[0])
 
for j in range(N):
    print(X.index(sort2[j])+1)

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

b = 1
for j in a: 
    j.append(b)
    b += 1

for k in a: 
    x=k.pop(1)
    k.insert(1,int(x)*-1)

a.sort()

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

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

b = 1
for j in a:
    j.append(b)
    b += 1

for k in a:
    x=k.pop(1)
    k.insert(1,int(x)*-1)

a.sort()

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

Solution (Python):
def Guide():
    N = int(input())
    lst = []
    for i in range(1, N + 1):
        city, score = input().split()
        lst.append([city, int(score), i])
    sorted_lst = sorted(lst, key=lambda x:(x[0], -x[1]))

    for l in sorted_lst:
        print(l[2])


Guide()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    sp = [input().split() + [i+1] for i in range(n)]
    sp = sorted(sp, key=lambda x: (x[0], -int(x[1])))
    for _, _, i in sp:
        print(i)

if __name__ == '__main__':
    main()

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

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

SP.sort()

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

Solution (Python):
n = int(input())
from collections import defaultdict
l = defaultdict(list)

for i in range(n):
  s,p = input().split()
  p=int(p)
  l[s].append({"i":i,"p":p})

for city in sorted(l.keys()):
  l[city].sort(
    key = lambda x: (x["p"])
    ,reverse = True
  )
  for c in l[city]:
    print(c["i"]+1)

Solution (Python):
n = int(input())
l =[[' ', 0, -1] for i in range(n)]
for i in range(n):
    l[i][0], p = input().split()
    l[i][1] = -int(p)
    l[i][2] = i+1

l_ = sorted(l)
for i in range(n):
    print(l_[i][2])

Solution (Python):
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys


import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
SP = [(x.split()[0].decode('utf8'), int(x.split()[1])) for x in readlines()]
SPs = sorted((name, -pt, i + 1) for i, (name, pt) in enumerate(SP))
print('\n'.join(str(a[2]) for a in SPs))

Solution (Python):

import operator as op
n=int(input())
res=[]
for i in range(n):
  x,y = map(str, input().split())
  res.append((i+1, x, -int(y)))

for i in sorted(res, key=op.itemgetter(1,2)):
  print(i[0])

Solution (Python):
def main():
    n = int(input())
    if n == 1:
        print(1)
        return 
    a = [list(input().split()) for i in range(n)]
    s = sorted(a, key=lambda x:(x[0],-int(x[1])))
    for i in s:
        print(a.index(i)+1)

if __name__ == '__main__':
    main()

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

Solution (Python):
N = int(input())
L1 = []
for i in range(N):
    L1.append(list(input().split()))

L2 = L1

ans=[]
for i in L1:
    seq = 1
    for j in L2:
        if i[0] > j[0]:
            seq += 1
        elif i[0] == j[0]:
            if int(i[1]) < int(j[1]):
                seq += 1
    ans.append(seq)
    
for i in range(N):
    print(ans.index(i+1)+1)

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

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


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

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

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

l1 = []
count = 0
left = 0
while n > count:
    
    l1 = []
    a = l[count][0]

    while l[count][0] == a:
        l1.append((l[count][1],l[count][2]))
        count += 1
        if count == n:
            break
    
    l1.sort(key = lambda x: x[0], reverse=True)
    
    for b,c in l1:
        print(c)

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

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

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

Solution (Python):
def examA():
    A, P = LI()
    ans = (A*3+P)//2
    print(ans)
    return

def examB():
    N = I()
    SP = [[]for _ in range(N)]
    for i in range(N):
        SP[i] = LSI()
        SP[i][1] = int(SP[i][1])
        SP[i].append(i)

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

    for v in SP:
        print(v[2]+1)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

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

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

Solution (Python):
from collections import defaultdict
n=int(input())

rest=defaultdict(list)
for i in range(n):
	s,h=input().split()
	rest[s].append([int(h),i+1])
for k in sorted(list(rest.keys())):
	for p,i in sorted(list(rest[k]),key=lambda x:x[0])[::-1]:
		print(i)

Solution (Python):
print(*list(zip(*sorted(sorted(map(lambda x:[x[0],int(x[1]),x[2]+1],[input().split()+[i]for i in range(int(input()))]),key=lambda x:-x[1]),key=lambda x:x[0])))[2])

Solution (Python):
N=int(input())
from collections import defaultdict
d = defaultdict(list)
for i in range(N):
  s,p=input().split()
  d[s].append([int(p),i])
for k in sorted(list(d.keys())):
  for p,i in sorted(list(d[k]),key=lambda x:x[0])[::-1]:
    print(i+1)

Solution (Python):
def main():
    N = int(input())
    restaurants = []
    for i in range(N):
        s, p = input().split(" ")
        restaurants.append((s, -1 * int(p), i + 1))
    restaurants.sort()
    for r in restaurants:
        print(r[2])


if __name__ == '__main__':
    main()

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

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

SP.sort()

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

Solution (Python):
n = int(input())
ans = [[] for i in range(n)]
for i in range(n):
    ss,pp = map(str,input().split())
    ans[i].append(ss)
    ans[i].append(int(pp))
    ans[i].append(i+1)
ans.sort(key=lambda x: (x[0],-x[1]))
for i in range(n):
    print(ans[i][2])

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

SP.sort(key=lambda x: (x[1][0], -int(x[1][1])))
for x in SP:
  print(x[0])

Solution (Python):
N = int(input())
SP = []
for _ in range(N):
    a = input().split()
    a.append(_+1)
    SP.append(a)


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

for s in sorted_items:
    print(s[2])

Solution (Python):
N = int(input())
reviews = [[i] + input().split() for i in range(N)]
for i, s, p in sorted(reviews, key=lambda x: (x[1], -int(x[2]))):
    print(i+1)

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

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

Solution (Python):
n = int(input())
sp = [[0, 0, 0] for i in range(n)]
for i in range(n):
  sp[i][0], sp[i][1] = list(map(str, input().split()))
  sp[i][1] = int(sp[i][1])
  sp[i][2] = i+1
sp.sort()

c=1
for i in range(n-1):
  if sp[i][0] == sp[i+1][0]:
    c+=1
    i+=1
  else:
    for j in range(c):
      print(sp[i-j][2])
    c=1
for j in range(c):
  print(sp[n-1-j][2])

Solution (Python):
n=int(input())
sp=[]
for i in range(n):
    s,p=input().split()
    sp.append([s,int(p),i+1])
    
l=sorted(sp, key=lambda sp: (sp[0], -sp[1]))
 
for i in l:
    print(i[2])

Solution (Python):
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    N = sc.intarr()[0]
    data = []
    for i in range(N):
        city, score = input().split()
        d = {'index': i+1, 'city': city, 'score': int(score)}
        data.append(d)
    tmp = sorted(data, key=lambda x: x['score'], reverse=True)
    sorted_data = sorted(tmp, key=lambda x: x['city'])

    for d in sorted_data:
        print(d['index'])


class Scan():

    def intarr(self):
        num_array = list(map(int, input().split()))
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):  
    return a * b // gcd(a, b)


main()

Solution (Python):
n=int(input())
sp=[]
for i in range(n):
    s,p=input().split()
    sp.append([s,int(p),i+1])
    
sort=sorted(sp, key=lambda sp: (sp[0], -sp[1]))

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

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

Solution (Python):
n=int(input())
sp=[[i+1]+list(input().split()) for i in range(n)]
change=True
while change:
    change=False
    for i in range(n-1):
        if sp[i][1]>sp[i+1][1]:
            sp[i],sp[i+1]=sp[i+1],sp[i]
            change=True
        elif sp[i][1]==sp[i+1][1] and int(sp[i][2])<=int(sp[i+1][2]):
            sp[i],sp[i+1]=sp[i+1],sp[i]
            change=True
for ans in sp:
    print(ans[0])

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

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

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

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

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

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

N = int(input().strip())

a = []
for i in range(N):
    l = input().strip().split()
    l[1] = 100-int(l[1])
    l.append(i+1)
    a.append(l)
a.sort()

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

Solution (Python):
import functools

N = int(input())
l = [None] * N

def cmp1(l, r):
   
    if l[0] < r[0]:
        return -1
    elif l[0] == r[0]:
        if l[1] == r[0]:
            return 0
        elif l[1] < r[1]:
            return 1 
        else:
            return -1
    else:
        return 1
        
    
for i in range(N):
    city, rate = input().split()
    l[i] =  city, int(rate), i+1


l.sort(key=functools.cmp_to_key(cmp1))

for _, _, idx in l:
    print(idx)

Solution (Python):
n=int(input())
l=[input().split() for i in range(n)]
l_new=[[l[x][0],int(l[x][1]),x+1] for x in range(n)]
l_new=sorted(l_new,reverse=True,key=lambda x:x[1])
l_new=sorted(l_new,key=lambda x:x[0])
for i in range(n):
    print(l_new[i][-1])

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

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

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

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

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    l=input().split()
    l.append(i+1)
    l[1]=100-int(l[1])
    a.append(l)
a.sort()

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

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
nes = [0] * N
for i in range(N) :
    li = input().split()
    li.append(i+1)
    li[1] = "-" + li[1]
    nes[i] = li
for i in range(N) :
    nes[i][1] = int(nes[i][1])
nes.sort()
for i in range(N) :
    print(nes[i][2])

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

lss = sorted(ls, key=lambda x: int(x[1]), reverse=True)

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

for i in range(n):
    print(1 + ls.index(ans[i]))

Solution (Python):



import numpy as np


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


for e in sorted(res):
    print(e[2])

Solution (Python):
N = int(input())
SP = [[str(i) for i in input().split()]for j in range(N)]
for i in range(N):
    SP[i][1] = int(SP[i][1])

DP = sorted(SP, key=lambda x: (x[0], -x[1]), reverse=False)
for j in DP:
    for c, i in enumerate(SP):
        if i == j:
            print(c+1)

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

lss = sorted(ls, key=lambda x: int(x[1]), reverse=True)

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

for i in range(n):
	print(1 + ls.index(ans[i]))

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

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

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

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

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

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

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

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

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

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

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

SP.sort()
for s, p, i in SP:
  print(i)

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

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


for i in X:
    i[1] = int(i[1])
X.sort()


for i in range(N):
    for j in range(i + 1, N):
        if X[i][0] == X[j][0]:
            if X[i][1] < X[j][1]:
                X[i], X[j] = X[j], X[i]

for value in X:
    print(value[2])

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

restaurant = {}
for i in range(N):
  S, P = clues[i]
  score = restaurant.get(S, {})
  score[i] = int(P)
  restaurant[S] = score

for S in restaurant:
  score = restaurant[S]
  restaurant[S] = sorted(score.items(), key=lambda x:x[1], reverse=True)

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

for S in restaurant:
  for i in S[1]:
    print(i[0] + 1)

Solution (Python):
from operator import itemgetter

N = int(input())

restaurnats = []
for i in range(N):
    name, points = input().split()
    restraunt = [name, int(points), i+1]   
    restaurnats.append(restraunt)

restaurnats = sorted(restaurnats, key=itemgetter(1), reverse=True)
restaurnats = sorted(restaurnats, key=itemgetter(0))
for i in restaurnats:
    print(i[2])