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

import sys;
import string;
sys.setrecursionlimit(20000) 

from functools import lru_cache



n = int(input())























def doit():
  rs = {}
  for x in range(n):
    s, p = input().split()
    p = int(p)
    
    if not s in rs:
      rs[s] = {}
    rs[s][p] = x + 1
  
    
  slist = sorted(rs)
  for x in slist:
    for y in sorted(rs[x].items(), reverse=True):
      print(y[1])

try:

  doit()
except Exception as e:
  print(e, file=sys.stderr)

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

tmp = []
for i,sp in enumerate(sp_list,1):
    tmp.append([i,sp[0],int(sp[1])])

sp_list1 = sorted(tmp, key=lambda x: x[2], reverse=True)
sp_list2 = sorted(sp_list1, key=lambda x: x[1], reverse=False)

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

Solution (Python):

n = int(input())

guidebook = {}
for i in range(n):
    s, p = input().split()
    p = int(p)

    if s in guidebook:
        guidebook[s].append((p, i+1))
    else:
        guidebook[s] = [(p, i+1)]

for city in sorted(guidebook.items(), key=lambda x: x[0]):
    for p, i in sorted(city[1], reverse=True):
        print(i)

Solution (Python):
from operator import itemgetter
n = int(input())
base_list = []
for i in range(n):
  name, point = input().split()
  base_list.append((name, -int(point), i+1))
sorted_list = sorted(base_list, key=itemgetter(0, 1))
for i in range(n):
  print(sorted_list[i][2])

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

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

L.sort()
j = 0
p = L[0][0]
ans = [[] for _ in range(N)]
for i in range(N):
    if L[i][0] == p:
        ans[j].append([L[i][1], L[i][2]])
    else:
        j += 1
        p = L[i][0]
        ans[j].append([L[i][1], L[i][2]])


for i in range(j+1):
    z = sorted(ans[i], reverse=True)
    [print(j[1]) for j in z]

Solution (Python):
from operator import itemgetter
N = int(input())
SP = sorted([[i+1]+input().split() for i in range(N)],key=lambda x:int(x[2]), reverse = True)
SP = sorted(SP,key=lambda x:x[1])
for sp in SP:
  print(sp[0])

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

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


cities = {}
for sp in sps:
    if not sp["city"] in cities:
        cities[sp["city"]] = []
    cities[sp["city"]].append(sp)


rest_sorted_cities = {}
for k, v in cities.items():
    rest_sorted_cities[k] = sorted(v, key=lambda x:x["score"], reverse=True)

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

for k, city in sorted_cities:
    [print(rest["index"] + 1) for rest in city]

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

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

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

for s in S:
  print(s[0])

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

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

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

li_a = sorted(li, key=lambda x:x[1], reverse=True)
li_b = sorted(li_a, key=lambda x:x[0])

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

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

data=[{"city":data[i][0],"score":int(data[i][1]),"number":i+1} for i in range(N)]

data.sort(key=lambda x: x['score'],reverse=True)
data.sort(key=lambda x: x['city'])


for i in [i["number"] for i in data]:
    print(i)

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

Solution (Python):
from operator import itemgetter
i = int(input())

data = []

def chg(x,y):
	print("hoge")
	if x[0] == y[0]:
		return x[1] > y[1]
	else:
		return x[0] > y[0]

for i in range(i):
	ip = input().split(' ')
	dt = [ip[0],int(ip[1])]
	data.append(dt)


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

for i in ls:
	cnt = 0
	for j in data:
		if i == j:
			break
		cnt += 1
	
	print(cnt + 1)

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

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

gen=page[0][0]
i=0
while i<n:
    town=[]
    while i!=n:
        
        if gen!=page[i][0]:
            break
        town.append(page[i])
        i+=1
    for j in range(len(town)):
        town[j]=town[j][::-1]
    town.sort(reverse=True)
    
    for j in range(len(town)):
        print(town[j][1])
    
    if i!=n:gen=page[i][0]

Solution (Python):
N, l = int(input()), []
for i in range(N):
    line = [x for x in input().split()]
    l.append([line[0], int(line[1]), i])

l.sort(key = lambda x: x[0])
tmp_list, tmp_string = [[l[0][1], l[0][2]]], l[0][0]
for i in range(1, N):
    if tmp_string == l[i][0]:
        tmp_list.append([l[i][1], l[i][2]])
    else:
        tmp_list.sort(key = lambda x: x[0], reverse = True)
        for x in tmp_list:
            print(x[1]+1)
        tmp_string = l[i][0]
        tmp_list = [[l[i][1], l[i][2]]]

tmp_list.sort(key = lambda x: x[0], reverse = True)
for x in tmp_list:
    print(x[1]+1)

Solution (Python):
N = int(input())
rest = []
for k in range(N):
    i, j = map(str, input().split())
    rest.append([i, int(j), k+1])


rest.sort(key=lambda x: x[1])
rest.reverse()
rest.sort(key=lambda y: y[0])

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

Solution (Python):
from collections import OrderedDict
from sys import stdin
N = int(stdin.readline().rstrip())
SP = {} 
_P = []
for i in range(N):
    s, p = stdin.readline().rstrip().split()
    _P.append(int(p))
    if s in SP:
        SP[s].append(int(p))
    else:
        SP[s] = [int(p)]
for v in SP.values():
    v.sort(reverse=True)
SP = OrderedDict(sorted(SP.items()))
for k, V in SP.items():
    for v in V:
        print(_P.index(v)+1)

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

book = [list(input().split()) for i in range(n)]
for i in range(n):
    book[i] += [i+1]
    book[i][1] = -1 * int(book[i][1])
book.sort()
for b in book:
    print(b[2])

Solution (Python):






import sys

input = sys.stdin.readline
N = int(input())
l = [input().split()+[i+1] for i in range(N)]





sl = sorted(l, key=lambda x:int(x[1]), reverse=True)
sl = sorted(sl, key=lambda x:x[0])

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





"""
10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
"""

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

Solution (Python):
import bisect
N = int(input())
guide_dic = {}
num_i_dic = {}
for _ in range(N):
    S,P = input().split()
    num_i_dic[int(P)] = _+1
    try:
        bisect.insort(guide_dic[S],int(P))
    except KeyError:
        guide_dic[S] = []
        bisect.insort(guide_dic[S],int(P))

for name,score in sorted(guide_dic.items()):
    for _ in score[::-1]:
        print(num_i_dic[_])

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


ans = []
sp.append(['hoge000'])
for i in range(n):
	if sp[i][0] == sp[i+1][0]:
		ans.append(sp[i])
		continue
	else:
		if len(ans):
			print(sp[i][2])
			for a in ans[::-1]:
				print(a[2])
			ans = []
			continue
		else:
			print(sp[i][2])

Solution (Python):


N = int(input())

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

ls =[i for i in range (1,N+1)]
total = list(zip(S,P,ls))


total.sort()


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

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


d = {}

for n in range(N):
  S, P = input().split()
  P = int(P)

  if S not in d:
    d[S] = {P: n+1}
  else:
    d[S][P] = n+1

keys = d.keys()
keys = list(keys)
keys.sort()

for k in keys:
  lis = d[k]
  
  ks = list(lis.keys())
  ks.sort()
  ks.reverse()
  for t in ks:
    print(lis[t])

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

for j in range(n):
    print(x[j][2]+1)

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

Solution (Python):
N=int(input())
dat=[]
for i in range(N):
  inp = input().split()
  dat.append([inp[0],int(inp[1]),i+1])
dat.sort()
for i in range(N):
  dat[i]=[dat[i][1],dat[i][0],dat[i][2]]


res=[dat[0]]
for i in range(N-1):
  j=i+1
  if dat[j][1]==dat[j-1][1]:
    res.append(dat[j])
  else:
    res.sort(reverse=True)
    for k in range(len(res)):
    	print(res[k][2])
    res=[dat[j]]

res.sort(reverse=True)
for k in range(len(res)):
	print(res[k][2])

Solution (Python):
N = int(input())
Ss = []
for i in range(N):
    k = input().split(" ")
    Ss.append((i+1, k[0], k[1]))

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

Solution (Python):
import sys
inputs=[[int(i) if i.isnumeric() else i for i in l.split()] for l in sys.stdin.readlines()][1:]
s_i=sorted(inputs,key=lambda x: (x[0],-x[1]))
for r in s_i:
    for n,i in enumerate(inputs):
        if r==i:
            print(n+1)

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

data=[]
for i in range(N):
    S,P = input().split()
    li = [i+1,S,int(P)]
    data.append(li)
    
data.sort(reverse=True, key=lambda x: x[2])
data.sort(key=lambda x: x[1])
for i in range(N):
    print(str(data[i][0]))

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

Solution (Python):
from collections import *
from functools import *
from itertools import *

def main():
    n = int(input())
    
    
    xs = [ input().split() for _ in range(n) ]
    xs = [ (a[0], int(a[1])) for a in xs ]
    def cmp(a, b):
        if a[0] > b[0]:
            return 1
        if a[0] < b[0]:
            return -1
        return b[1] - a[1]
    xs = [ (x[0], x[1], i+1) for i, x in enumerate(xs) ]
    xs.sort(key=cmp_to_key(cmp))
    for s, p, i in xs:
        print(i)
        pass
    pass


if __name__ == "__main__":
    main()
    pass

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

Solution (Python):
n = int(input())
dic = {}
for i in range(n):
    s, p = input().split()
    p = int(p)
    if s in dic:
        dic[s].append(p*101 + i+1)
        dic[s].sort()
        dic[s].reverse()
    else:
        dic[s] = []
        dic[s].append(p*101 + i+1)

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

for tmp in dic_sorted:
    for i in range(len(tmp[1])):
        print(tmp[1][i] % 101)

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

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

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

arr = sorted(arr, key=lambda x:x["s"])

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

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    arr = []
    for i in range(1, n + 1):
        inp = input().split(' ')
        arr.append({'n': int(i), 's': inp[0], 'p': int(inp[1])})
    _sorted = sorted(arr, key = lambda x: (x['s'], -x['p']))
    for item in _sorted:
        print(item['n'])

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))
sp.sort(key=lambda x:(x[0],-x[1]))
for i in sp:
    print(i[2])

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

SP2 = sorted(sorted(SP, key=lambda x:int(x[2]), reverse=True), key=lambda x:x[1])

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

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

S = []
P = []
for i in range(N):
    sp = input().split()
    S.append(sp[0])
    P.append(int(sp[1]))

SP = list(zip(range(1,N+1),S,P))

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

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

Solution (Python):
N = int(input())
dict = []
for i in range(N):
    line = input().split()
    S = line[0]
    P = int(line[1])
    dict.append({"id": i+1, "S":S, "P":P})

dict = sorted(dict, key=lambda x:(x["S"],-x["P"]))

for d in dict:
    print(d["id"])

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

ls = []

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

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

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

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

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

SP.sort()
city = SP[0][0]
tmp = [[int(SP[0][1]), SP[0][2]]]
for i in range(0, N - 1):
    if SP[i + 1][0] == city:
        tmp.append([int(SP[i + 1][1]), SP[i + 1][2]])
    else:
        tmp.sort()
        tmp.reverse()
        for j in range(len(tmp)):
            print(tmp[j][1])
        tmp = [[int(SP[i + 1][1]), SP[i + 1][2]]]
        city = SP[i + 1][0]
tmp.sort()
tmp.reverse()
for j in range(len(tmp)):
    print(tmp[j][1])

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

for i in range(N):
    lst[i][2] = int(lst[i][2])

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

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

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

li2 = li.copy()
li.sort()
for l in li:
    print(li2.index(l)+1)

Solution (Python):
number = int(input())
i = 1
l = list()
while i <= number:
  k,v = input().split()
  l.append((k,int(v),i))
  i += 1

sorted_list = sorted(l, key=lambda s:s[1], reverse=True)
sorted_list2 = sorted(sorted_list, key=lambda s:s[0])

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

Solution (Python):
from operator import itemgetter

N= int(input())
lst = []
for i in range(N):
    s, p = input().split()
    lst.append([s, int(p), i])
lst = sorted(lst, key=itemgetter(1), reverse=True)
lst = sorted(lst, key=itemgetter(0))
for l in lst:
    print(l[2]+1)

Solution (Python):


from operator import itemgetter

N = int(input())
SP_list = []
SP_dict = {}
for i in range(N):
    name, point = input().split()
    pair = (name, int(point))
    SP_list.append(pair)
    SP_dict[pair] = i + 1

for i in range(len(SP_list)):
    SP_dict[SP_list[i]] = i + 1

point_sorted = sorted(SP_list, key=itemgetter(1), reverse=True)
name_sorted = sorted(point_sorted, key=itemgetter(0))

for pair in name_sorted:
    print (SP_dict[pair])

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

into = []
for i in range(1, N+1):
    res, sc_str = [x for x in input().split()]
    sc = int(sc_str)

    into.append((i, res, sc))

from operator import itemgetter

sorted_into = sorted(into, key=lambda x:(x[1],-x[2]))

for z in  sorted_into:
    print(z[0])

Solution (Python):

from operator import itemgetter
n = int(input())
isp=[]
for i in range(n):
  s,p= input().split()
  isp.append([i+1, s, int(p)])
isp.sort(key=itemgetter(2))
isp.reverse()  
isp.sort(key=itemgetter(1))
for st in isp:
  print(st[0])

Solution (Python):
N=int(input())
rest_list = []
for i in range(N):
  Si, Pi = input().split()
  Pi = int(Pi)
  rest_list.append((i+1,Si,Pi))
  
for i in range(N-1):
  for j in range(i+1,N):
    ii,Si,Pi = rest_list[i]
    jj,Sj,Pj = rest_list[j]
    
    if Si > Sj or (Si == Sj and Pi < Pj):
      rest_list[i], rest_list[j] = (jj,Sj,Pj),(ii,Si,Pi)
      
for i in range(N):
  i,Si,Pi = rest_list[i]  
  print(i)

Solution (Python):
n=int(input())
l=[input().split() for i in range(n)]
l=[[x[0],int(x[1])] for x in l]
sorted_l=sorted([[x[0],-1*x[1]] for x in l]
                ,key=lambda x:(x[0],x[1]))

sorted_l=[[x[0],-1*int(x[1])] for x in sorted_l]

for x in sorted_l:
  print(l.index(x)+1)

Solution (Python):
class Restaurant:
    def __init__(self, i, s, p):
        self.i, self.s, self.p = i, s, p


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

restaurants.sort(key=lambda x: x.p, reverse=True)
restaurants.sort(key=lambda x: x.s)

for r in restaurants:
    print(r.i)

Solution (Python):


from operator import itemgetter
n=int(input())
l=[]
for i in range(n):
    a,b=map(str,input().split(" "))
    l.append((a,int(b),i+1))

c=sorted(l,key=itemgetter(1),reverse=True)
d=sorted(c,key=itemgetter(0))
for i in range(n):
    print(d[i][2])

Solution (Python):
N = int(input())
d = {}
for n in range(N):
    c, v = input().split()
    v = int(v)
    if c in  d:
        d[c] = d[c]+[(v, n+1)]
    else:
        d[c] = [(v, n+1)]
d = sorted(d.items())
for c in d:
    for v in sorted(c[1], reverse=True):
        print(v[1])

Solution (Python):

def input_from_console():
    n = int(input().rstrip())

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


def solve(n, s_list):

    final_order = []
    city_list = set([item[1] for item in s_list])
    city_list_sorted = sorted(city_list)
    for city in city_list_sorted:
        ranked_list = [item for item in s_list if item[1] == city]
        final_order.extend([item[0] for item in sorted(ranked_list, key=lambda x: x[2], reverse=True)])
    return '\n'.join(map(str, final_order))


def main():
    n, s_list = input_from_console()
    print(solve(n, s_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  
        check_cases()
    else:
        main()

Solution (Python):
n = int(input())
sp = [input().split() for _ in range(n)]
d = {}
for idx,(s,p) in enumerate(sp):
  if s in d.keys():
    d[s].append([int(p),idx])
  else:
    d[s] = [[int(p),idx]]

for key in sorted(d.keys()):
  for v in sorted(d[key])[::-1]:
    print(v[1]+1)

Solution (Python):
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N = int(input())
S = [0]*N
P = [0]*N
Dic = []
for i in range(N):
    S[i], P[i] = input().split()
   
for i in range(N):
    Dic.append([S[i], int(P[i]), i+1])

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

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

Solution (Python):
from sys import stdin

def main():
    N = int(input())
    SP = [tuple(input().split()) for _ in [0] * N]

    sp = [(i, s, int(p)) for i, (s, p) in enumerate(SP, start=1)]
    sp.sort(key=lambda x: x[2], reverse=1)
    sp.sort(key=lambda x: x[1])
    for i, s, p in sp:
        print(i)

input = lambda: stdin.readline()
main()

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

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

for s, points in sorted(restaurants.items(), key=lambda x: x[0]):
    for p, i in sorted(points,key=lambda x: x[0], reverse=True):
        print(i)

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

for i in range(N):
    line = input().split()
    SP.append([i+1, line[0], int(line[1])])
    
for i, c, s in sorted(SP, key=lambda x:(x[1], -x[2])):
    print(i)

Solution (Python):
from operator import itemgetter, attrgetter
n = int(input())
sp = [[i+1] + list(input().split()) for i in range(n)]

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

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

restaurant_dict = defaultdict(list)

for i in range(n):
  name, score = input().split()
  restaurant_dict[name].append((i+1, int(score)))
  
for n, t in sorted(restaurant_dict.items()):
  for s in sorted(t, key=lambda tup: tup[1], reverse=True):
    print(s[0])

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

for i, S_P in enumerate(S_P_list):
    S_P_list[i][1] = (int)(S_P_list[i][1])
    S_P_list[i].append(i+1)

S_P_list = sorted(S_P_list)

for i, S_P in enumerate(S_P_list):
    for j in range(i):
        if (S_P_list[i][0] == S_P_list[j][0])and (S_P_list[i][1] > S_P_list[j][1]):
            tmp = S_P_list[i]
            S_P_list[i] = S_P_list[j]
            S_P_list[j] = tmp

for i, S_P in enumerate(S_P_list):
    print(S_P_list[i][2])

Solution (Python):
N = int(input())
sp_list = [ input().split() for _ in range(N) ]
s_list = [ sp[0] for sp in sp_list ]
p_list = [ str(100 - int(sp[1])).zfill(3) for sp in sp_list]

sp_dict = {}
for i in range(N):
  key = s_list[i] + ' ' + p_list[i]
  sp_dict[key] = (i+1)

for k in sorted(sp_dict.keys()):
  print(sp_dict[k])

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

Solution (Python):
N = int(input())
target = [{'id':i+1,'val':input().split()}for i in range(N)]
target = sorted(target,key=lambda x:(x['val'][0],(int(x['val'][1]))* (-1)) )

'''

'''
for i in range(N):
    print(target[i]['id'])

Solution (Python):
n = int(input())
list1 = []
for i in range(n):
  s, p = input().split()
  list1.append([s, int(p), i])
ans = []
for j, (k, v, i) in enumerate(sorted(list1, key=lambda x:(x[0], -x[1]))):
  
  ans.append([s, p, i, j])
for a, b, c, d in sorted(ans, key=lambda x:(x[3])):
  print(c+1)

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

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


ans = [sp[2] for sp in SP]
for a in ans :
    print(a)

Solution (Python):
N = int(input())
S=[]
P=[]
spi=[]
idx=1
for i in range(N):
    s_tmp, p_tmp = input().split()
    S.append(s_tmp)
    P.append(int(p_tmp))
    spi.append([s_tmp,-(int(p_tmp)),idx])
    idx=idx+1

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

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

for i in range(N):
    inp = input().split()
    if book.get(inp[0]):
        book[inp[0]].append( (i, int(inp[1])) )
    else:
        book[inp[0]] = [(i, int(inp[1])),]

for s in sorted(book.items(), key=lambda x:x[0]):
    rests = s[1]
    for r in sorted(rests, key=lambda x:x[1], reverse=True):
        print(r[0]+1)

Solution (Python):
N = int(input())
from operator import itemgetter
ls = [[]]*N
for i in range(N):
    ls[i]  = list(input().split())
    ls[i].append(i+1)
    ls[i][1] = int(ls[i][1])
ls = sorted(ls,key=itemgetter(1))
ls = sorted(ls,reverse=True,key=itemgetter(0))
for p,q,r in reversed(ls):
    print(r)

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

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

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

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    S = []
    P = []
    num = []
    for i in range(N):
        s = input().rstrip().split(' ')
        S.append(s[0])
        P.append(int(s[1]))
        num.append(i+1)

    Z = list(zip(S,P,num))

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

    for elem in Z:
        print(elem[2])

Solution (Python):
n = int(input())
dict = {}

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

for k,v in sorted(dict.items(), key=lambda x: x[1]):
    print(k+1)

Solution (Python):
from collections import defaultdict

N = int(input())

shops = defaultdict(list)
for i in range(N):
    Si, Pi = input().split()
    shops[Si].append({
        'no': i + 1,
        'point': int(Pi)
    })

for city, city_shops in sorted(shops.items(), key=lambda x:x[0]):
    for shops in sorted(city_shops, key=lambda x:(x['point']), reverse=True):
        print(shops['no'])

Solution (Python):

import os
import time
import re
import math


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

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

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

Solution (Python):
n = int(input())
a = [0]*n
b = [0]*n
c = []
for i in range(n):
    a[i],b[i] = input().split()
    c.append([a[i],100-int(b[i])])
d = sorted(c)
for j in d:
    print(c.index(j)+1)

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

SP = {}
for i in range(N):
    city,score = input().split()
    if city in SP:
        SP[city].append([int(score),i])
    else:
        SP[city] = []
        SP[city].append([int(score),i])



for city in sorted(SP.keys()):

    score = sorted(SP[city], reverse=True)
    for s in score:
        print(s[1]+1)

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

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

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

Solution (Python):
n = int(input())
SP = []
for ni in range(n):
    s, p = input().split()
    SP.append([ni+1, s, int(p)])
SP.sort(key = lambda x: x[1])

sameNameList = []
s = SP[0][1]
sameNameList.append(SP[0])
for ni in range(1,n):
    if SP[ni][1] != s and sameNameList != []:
        sameNameList.sort(key = lambda x: x[2], reverse = True)
        for i in sameNameList:
            print(i[0])
        sameNameList = []
    sameNameList.append(SP[ni])
    s = SP[ni][1]
if sameNameList != []:
    sameNameList.sort(key = lambda x: x[2], reverse = True)
    for i in sameNameList:
        print(i[0])

Solution (Python):
from operator import itemgetter

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

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

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

Solution (Python):
N = int(input())
S=[]
P=[]
for i in range(1,N+1):
    s,p=input().split()
    S.append([s+"{:03d}".format(100-int(p)),i])
S.sort()
for i in S:
    print(i[1])

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

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

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

for i in range(len(sp)):
    sp[i].append(i)
sp.sort(key=lambda x:(x[0],-int(x[1])))

for ele in sp:
    print(ele[2]+1)

Solution (Python):
from operator import itemgetter

N = input()
N = int(N)

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

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

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

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

for adic in sorted(dic.keys()):
    d = dic[adic]
    
    for s in sorted(d.keys(),reverse=True):
        print(d[s])

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

tmp = sorted(SP, key=lambda x:(x[0], x[1]), reverse=True)
tmp2 = sorted(tmp, key=lambda x:x[0])
for j in tmp2:
  print(j[2])

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

restaurants = []
for index in range(1, num_input+1):
    name, score_str = input().split(' ')
    reduced_score = 100 - int(score_str)
    restaurants.append((name, reduced_score, index))

restaurants.sort()

ordered_indexes = [index for _, _, index in restaurants]

for index in ordered_indexes:
    print(index)

exit(0)

Solution (Python):
from operator import itemgetter
n = int(input())
sp = [input().split() for i in range(n)]

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

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


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