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

data=[]
for _ in range(N):

    S,P=input().split()
    data.append([_+1,S,int(P)])
    data.sort(key=lambda x:x[2])
    data.reverse()
    data.sort(key=lambda x:x[1])

for i,S,P in data:
    print(i)

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

r_list = [ [i,input().split()] for i in range(n)]

s_list = list(set([r[1][0] for r in r_list]))
s_list.sort()

r_map = {}
for r in r_list:
    if r[1][0] not in r_map:
        r_map[r[1][0]] = [[r[0], int(r[1][1])]]
    else:
        r_map[r[1][0]].append([r[0], int(r[1][1])])

for s in s_list:
    r_map[s].sort(key= lambda x: x[1], reverse=True)


for s in s_list:
    for r in r_map[s]:
        print(r[0]+1)

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

data = []
for i in range(N):
  S, P = input().split()
  P = int(P)
  data.append((i+1, S, P))
  
data_sorted = sorted(data, key=lambda x: (x[1], -x[2]))

for d in data_sorted:
  print(d[0])

Solution (Python):
N = int(input())
data = [[i, (lambda x: [x[0], int(x[1])])(input().split())] for i in range(N)]
for r in sorted(data, key=lambda x: (x[1][0], -x[1][1])):
    print(r[0]+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[0], x[1]))
for s, p, x in restaurant:
    print(x)

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

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

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

r = []

for b in range(n):
	i = input().split(" ")
	s = i[0]
	p = int(i[1])
	r.append((s, p, b + 1))

r = sorted(r, key=lambda i: i[1], reverse=True)
r = sorted(r, key=lambda i: i[0])

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

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

l = sorted([(i+1, s, int(p)) for i, (s, p) in enumerate(SP)], key=lambda x: (x[1], -x[2]))

for l_i in l:
    print(l_i[0])

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

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

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

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

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

Solution (Python):
def main():
    n = int(input())
    x = []
    for i in range(1, n+1):
        s_, p_ = input().split()
        x += [[i, s_, int(p_)]]
        x = sorted(x, key=lambda x:(x[1],-x[2]))
    for i in range(n):
        print(x[i][0])

if __name__ == '__main__':
    main()

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

SP=sorted(SP,key=lambda x:(x[0],(-1)*int(x[1])))
for lst in SP:
    print(lst[2])

Solution (Python):
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
def ddprint(x):
  if DBG:
    print(x)

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

Solution (Python):
def run(N, lists):
    sorted_items = sorted(
        lists,
        key=lambda x: (x['P']),
        reverse=True
    )
    sorted_items = sorted(
        sorted_items,
        key=lambda x: (x['S']),
    )
    return sorted_items


def main():
    N = int(input())
    lists = []
    for i in range(N):
        S, P = input().split()
        P = int(P)
        lists.append({'id': i+1, 'S': S, 'P': P})
    sorted_lists = run(N, lists)
    for item in sorted_lists:
        print(item['id'])


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return int(input())
from collections import defaultdict
from operator import itemgetter

n = SI()
dicts = []
for i in range(n):
    s, p = LS()
    p = int(p)
    dicts.append((i+1, s, p))
dicts = sorted(dicts, key=lambda x:(x[1],-x[2]))
for i, s, p in dicts:
    print(i)

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

Solution (Python):
N = int(input())
restaurants = []
for x in range(1, N + 1):
    name, point = list(input().split())
    restaurants.append([x, name, int(point)])
restaurants.sort(key=lambda x:(x[1],-x[2]))
for x in restaurants:
    print(x[0])

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

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    p_dic ={}
    for i in range(N):
        input_raw = read_func().strip().split()
        [S, P] = [(input_raw[0]), int(input_raw[1])]
        if S not in p_dic:
            p_dic[S] = [(P, i + 1)]
        else:
            p_dic[S].append((P, i + 1))

    dct = sorted(p_dic.keys())

    for d in dct:
        p_dic[d].sort(reverse=True)
        for p in p_dic[d]:
            print p[1]




if __name__ == '__main__':
    main()

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

    for p,i in l:
        print(i)

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

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

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

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

Solution (Python):
N=int(input())
num_list=[]
S=""
P=""
for i in range(0,N):
    S,P=map(str,input().split())
    P=int(P)
    num_list.append([i+1,S,100-P])
num_list=sorted(num_list,key=lambda x:(x[1],x[2]),reverse=False)

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

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
input = sys.stdin.readline
 










def main():
	
	N = int(input())
	

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

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

	for i in SP:
		a, b, c = i
		print(c)

	


if __name__ == "__main__":
	main()

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

Solution (Python):



def readInt():
    return int(input())

def readList():
    return list(input().split())

def readListI():
    return list(map(int, input().split()))

def main():
    n = readInt()
    l = {}
    for i in range(n):
        s, p = readList()
        l[(s, -int(p), i+1)] = True
    l = sorted(l)
    for e in l:
        print(e[2])


if __name__ == '__main__':
    main()

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

Solution (Python):



import sys  
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools



sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe


def local_input():
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)


def solve():
    N = int(input())
    X = []
    for i in range(N):
        S,P = map(str, input().split())
        P = int(P)
        X.append((S,P,i))
    X.sort(key=lambda x: x[1], reverse=True)
    X.sort(key=lambda x: x[0])

    for x in X:
        print(x[2]+1)

    return 0

if __name__ == "__main__":
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

Solution (Python):
import sys
from functools import reduce
def b():
    p = [r.split(' ') for r in sys.stdin.read().split('\n') if r != '']
    SP = p[1:]
    sp = sorted(enumerate(SP), key=lambda x: -int(x[1][1]))
    sc = sorted(sp, key=lambda x: x[1][0])
    for i, t in sc:
        print(i + 1)
b()

Solution (Python):



from operator import itemgetter


n = int(input())
splist = list()

for i in range(n):
    s, p = input().split()
    sp = list()
    sp.append(s)
    sp.append(int(p))
    sp.append(i+1)
    splist.append(sp)
    
splist.sort(key=itemgetter(1), reverse=True)
splist.sort(key=itemgetter(0))


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

Solution (Python):
n = int(input())
SP = []
for i in range(n):
    s,p = input().split()
    SP.append([i+1,s,int(p)])
    
from operator import itemgetter

SP.sort(key = itemgetter(2),reverse = True)
SP.sort(key = itemgetter(1))
for j,s,p in SP:
    print(j)

Solution (Python):
from operator import itemgetter


def main():
    N = int(input())
    SP = []
    for n in range(N):
        s, p = input().split()
        SP.append((n + 1, s, int(p)))
    SP = sorted(SP, key=itemgetter(2), reverse=True)
    SP = sorted(SP, key=itemgetter(1))
    for n, s, p in SP:
        print(n)


main()

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

n = int(input())

a = []

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

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

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

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

for s in sorted(list(d.keys())):
    for c in sorted(d[s],key=lambda x:-x[1]):
        print(c[0])

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

for i in range(n):
  r=list(map(str,input().split()))
  r[1]=int(r[1])
  r.append(i+1)
  r_list.append(r)

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

for j in range(n):
  print(r_list[j][2])

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

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

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

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

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

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

plist = []

spm = {}
for s, p in SP:
	plist += [int(p)]
	if not s in spm:
		spm[s] = [int(p)]
	else:
		spm[s] += [int(p)]

spl = []
for m in sorted(spm):
	for p in sorted(spm[m])[::-1]:
		spl += [p]



for p in spl:
	print(plist.index(p) + 1)

Solution (Python):
n = int(input())
r = []
for i in range(n):
  S, praw = input().split()
  p = int(praw)
  r.append((i, S, 100-p))
  
r_sorted = sorted(r, key=lambda x:(x[1], x[2]))

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

Solution (Python):
from operator import itemgetter
N = int(input())
hoge = []
for i in range(1,N+1):
    s, p = input().split()
    p = int(p)
    hoge.append((s,100-p,i))
a = sorted(hoge, key=lambda x:(x[0],x[1]))
for b in a:
    print(b[2])

Solution (Python):
from collections import defaultdict


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

s_unique = sorted(list(set(Ss)))
for s in s_unique:
    
    pairs = sorted(p_dict[s], key=lambda e: e[0], reverse=True)
    for pair in pairs:
        print(pair[1])

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

Solution (Python):


def main():
    N = int(input())
    
    data = []
    for i in range(N):
        s, p = input().split()
        data.append({"num": i+1, "s":s, "p":int(p)})
    data.sort(key=lambda x: x["p"])
    data.reverse()
    data.sort(key=lambda x: x["s"])

    for tmp in data:
        print(tmp["num"])

if __name__ == "__main__":
    main()

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    restaurants = []
    for _ in range(N):
        s, p = input().split()
        restaurants.append((s.strip(), int(p)))

    rank = sorted(restaurants, key=lambda x: (x[0], -x[1]))
    for a in rank:
        print(int(restaurants.index(a)) + 1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

def f(s):
    return s

N=int(input())
a=[list(map(f,input().split()))+[i] 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]+1)

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

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

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

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

ans = [str(b) for _, _, b in Cities]
print('\n'.join(ans))

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

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

Solution (Python):
N = int(input())
SPs = list()
memo = dict()
for i in range(N):
  S, P = input().split()
  SP = (S, -int(P))
  SPs.append(SP)
  memo[SP] = i

for sp in sorted(SPs):
  print(memo[sp] + 1)

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

res = []

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

res.sort()

for r in res:
    print(r[2]+1)

Solution (Python):
import sys
rr = lambda: sys.stdin.readline().strip()
rri = lambda: int(rr())
rrs = lambda: [int(_) for _ in rr().split()]

from operator import itemgetter

N = rri()
data = [[i + 1] + rr().split() for i in range(N)]

for d in data:
	d[2] = int(d[2])

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

for d in data:
	print(d[0])

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

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

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

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

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
shop = []
order = {}
for i in range(n):
    s,p = ls()
    p = int(p)
    shop.append([s,p])
    order[(s,p)] = i

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


for i, (name, point) in enumerate(ans):
    print(order[(name, point)] + 1)
    order[(name, point)] = i

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

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

city_now = sp_sorted[0][0]
tmp = []
for sp in sp_sorted:
	if sp[0] == city_now:
		tmp.append(sp)
	else:
		tmp_sorted = sorted(tmp, key=lambda x:int(x[1]), reverse=True)
		for t in tmp_sorted:
			print(t[2])
		city_now = sp[0]
		tmp = [sp]

if tmp:
	tmp_sorted = sorted(tmp, key=lambda x:int(x[1]), reverse=True)
	for t in tmp_sorted:
		print(t[2])

Solution (Python):
import sys

def intinput(): return map(int,sys.stdin.readline().split())

n=int(sys.stdin.readline())
l = []
for i in range(n):
    a,b = sys.stdin.readline().split()
    l.append([a,-int(b),i+1])
l.sort()
for (x,y,z) in l:
    print(z)

Solution (Python):
import sys

fin = sys.stdin.readline

N = int(fin())
sp = [fin().split() for i in range(N)]
sp = [(sp[i][0], int(sp[i][1]), i) for i in range(N)]

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

print(*[s[2]+1 for s in sp], sep="\n")

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

        A.append((s, -int(p), i))

    A.sort()
    
    for i in range(N):
        print (A[i][2])
    
if __name__ == "__main__":  
    solve()

Solution (Python):
from collections import defaultdict

N = int(input())

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

names = sorted(cities.keys())
for name in names:
    ps = sorted(cities[name].items(), reverse=True, key=lambda p: p[1])
    for p in ps:
        print('{}'.format(p[0]+1))

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

lc = []
l = []

for i in range(n):
    s,p = (num for num in input().split())
    p = int(p)
    if s in lc:
        idx = lc.index(s)
        l[idx][1].append((i,p))
    else:
        lc.append(s)
        l.append([s,[(i,p)]])
        



l.sort(key = lambda x:x[0])
for i in range (len(lc)):
    t = l[i][1]
    t.sort(key = lambda x: x[1], reverse=True)
    for tu in t:
        print(tu[0]+1)

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

dic = {}
for i in range(N):
    S, P = [i for i in input().split()]
    if S in dic:
        dic[S].append((int(P), i + 1))
    else:
        dic[S] = [(int(P), i + 1)]

for s in sorted(dic.keys()):
    for l in reversed(sorted(dic[s])):
        print(l[1])

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

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

itm = sorted(
    items,
    key = lambda x: (x[1],-x[2])
)

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

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

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

Solution (Python):
from functools import cmp_to_key

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

def cmp(a, b):
    if a[0] != b[0]:
        return -1 if a[0] < b[0] else 1
    else:
        return -1 if a[1] > b[1] else 1

sorted_S_P = sorted(S_P, key=cmp_to_key(cmp))
for _, _, i in sorted_S_P:
    print(i)

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

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

Solution (Python):
import sys
_ = input()

Rs = [line.strip().split(' ') for line in sys.stdin]
Rs = sorted([[i+1, r[0], int(r[1])] for i,r in enumerate(Rs)], key=lambda x: (x[1],-x[2]))
for r in Rs:
  print(r[0])

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

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

city_now = sp_sorted[0][0]
tmp = []
for sp in sp_sorted:
	if sp[0] == city_now:
		tmp.append(sp)
	else:
		tmp_sorted = sorted(tmp, key=lambda x:int(x[1]), reverse=True)
		for t in tmp_sorted:
			print(t[2])
		city_now = sp[0]
		tmp = [sp]

if tmp:
	tmp_sorted = sorted(tmp, key=lambda x:int(x[1]), reverse=True)
	for t in tmp_sorted:
		print(t[2])

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

Solution (Python):
n = int(input())
A = []
for i in range(n):
  b,c = input().split()
  cc = int(c)
  A += [[b,10000-cc,i+1]]
A.sort()
for i in range(n):
  print(A[i][2])

Solution (Python):
from operator import itemgetter

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

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

Solution (Python):
n = int(input())
city_score = {}
for i in range(n):
    city, score = input().split()
    city_score[city] = city_score.get(city, []) + [(int(score), i)]

for city in sorted(city_score.keys()):
  for score in sorted(city_score[city], reverse=True):
    print(score[1]+1)

Solution (Python):
from collections import defaultdict


def inpl():
    return list(map(int, input().split()))


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

key = []
for k in d.keys():
    key.append(k)
    d[k].sort(reverse=True)

key.sort()
for k in key:
    for i in d[k]:
        print(ans_dic[(k, i)])

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

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

rest = [[0] for i in range(N)]
for i in range(N):
    s, p = map(str, input().split())
    rest[i] = [s, -1 * int(p), i+1]

rest.sort()
for i in range(N):
    print(rest[i][2])

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

n = int(input())
s = []
for i in range(n):
    ts, tp = input().split()
    s.append([ts, int(tp), i+1])
s.sort(key=itemgetter(1), reverse=True)
s.sort(key=itemgetter(0))
for i in s:
    print(i[2])

Solution (Python):

import sys
INF = float("inf")


def solve(N: int, S: "List[str]", P: "List[int]"):
    SP = []
    for i, (s, p) in enumerate(zip(S, P)):
        SP.append([i+1, s, p])
    SP.sort(key=lambda x: x[2], reverse=True)
    SP.sort(key=lambda x: x[1])
    for i, s, p in SP:
        print(i)


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = [str()] * (N)  
    P = [int()] * (N)  
    for i in range(N):
        S[i] = next(tokens)
        P[i] = int(next(tokens))
    solve(N, S, P)


if __name__ == '__main__':
    main()

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

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

A = [x[2] for x in sorted(I, key=lambda x: (x[0], x[1]))]

for i in A:
    print(i)

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

rs.sort(key=lambda x:(x[1], -x[2]))
for r in rs:
  print(r[0])

Solution (Python):
read = input 
n = int(read())
A = {}
for i in range(1, n+1):
    s, p = read().split()
    p = int(p)
    if s not in A:
        A[s] = {}
    A[s][p] = i
A = list(A.items())
A.sort()
for s,d in A:
    B = list(d.items())
    B.sort(reverse=True)
    for p,i in B:
        print(i)

Solution (Python):
from heapq import heappush, heappop
n = int(input())
q = []
for i in range(n):
  s, p = input().split()
  heappush(q, [s, int(p) * (-1), i])
for i in range(n):
  _, _, r = heappop(q)
  print(r + 1)

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

s = sorted(stack,key=lambda x:(x[0],x[1]))
for i in range(n):
    print(s[i][2])

Solution (Python):

import numpy as np
N = int(input())
ls_sp = []
for n in range(N):
    s,p = input().split()
    sp = s + str(100-int(p)).zfill(3)
    ls_sp.append(sp)
ans = np.argsort(ls_sp)
for a in ans:
    print (a+1)

Solution (Python):
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline


    n = int(input())
    restaurant = [None]*n
    for i in range(n):
        input_list = list(input().split())
        input_list[1] = int(input_list[1])
        input_list.append(i+1)
        restaurant[i] = input_list

    restaurant.sort(key= lambda num: num[1], reverse=True)
    restaurant.sort(key= lambda num: num[0])
    for num in restaurant:
        print(num[2])

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

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

rest_dict = {}
for i in range(N):
    s, p = input().split()
    p = int(p)
    if s in rest_dict:
        rest_dict[s].append((i, p))
    else:
        rest_dict[s] = [(i, p)]

cities = list(rest_dict.keys())
cities.sort()
for city in cities:
    rest_dict[city].sort(key=lambda r: r[1], reverse=True)
    for rest in rest_dict[city]:
        print(rest[0]+1)

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

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

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

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

Solution (Python):
from operator import itemgetter
a = int(input())
shop_list = []
for i in range(a):
    b, c = input().split()
    c_num = int(c)
    shop_list.append([i+1, c_num, b])
shop_list.sort(key=itemgetter(1), reverse=True)
shop_list.sort(key=itemgetter(2))
for shop in shop_list:
    print(shop[0])

Solution (Python):
from operator import attrgetter, itemgetter
n = int(input())
a = []
for i in range(n):
  s,p = input().split()
  a.append([s,100-int(p),i+1])
a = sorted(a, key=itemgetter(0, 1))
for t in a:
  print(t[2])

Solution (Python):
n = int(input())
a = []
for i in range(n):
    s, t = map(str, input().split())
    a.append([s, 100-int(t), i+1])
a.sort()
for i in range(n):
    print(a[i][2])