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



Sample input:
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40


Sample output:
3
4
6
1
5
2

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)) )
#print(target)
'''

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

Submission status: Accepted

Solution code:
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]))):
  #print(k, v, i, j)
  ans.append([s, p, i, j])
for a, b, c, d in sorted(ans, key=lambda x:(x[3])):
  print(c+1)

Submission status: Accepted

Solution code:
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]
#SP2 = [SP[i] + [i] for i in range(N)]
SP = sorted(SP, key = lambda x : x[1], reverse=True)
SP = sorted(SP, key = lambda x : x[0])
#SP = sorted(SP, key = lambda x : x[0]), key = lambda x : x[1], reverse=True)
#print(SP)
ans = [sp[2] for sp in SP]
for a in ans :
    print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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'])

Submission status: Accepted

Solution code:
# coding: utf-8
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=list(map(lambda x: x[0], SP))
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])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
# SP = sorted([list(input().split()) for _ in range(N)])
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])
# print(SP)


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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
#print(dic)
for adic in sorted(dic.keys()):
    d = dic[adic]
    #print(d)
    for s in sorted(d.keys(),reverse=True):
        print(d[s])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
items = []
for i in range(n):
    a, b = input().split()
    a = str(a)
    b = int(b)
    z = {"id": i+1, "name": a, "score": b}
    items.append(z)
sorted_items = sorted(items, key = lambda x: (x["name"], -x["score"]))
for a in sorted_items:
    print(a["id"])

Submission status: Accepted

Solution code:
N = int(input())

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

base_city = ''
prelist2 = []
anslist2 = []

for ans_tuple in anslist:
    city, score, position = ans_tuple[0], ans_tuple[1], ans_tuple[2]
    
    if base_city == city:
        prelist2.append((ans_tuple[1], ans_tuple[2]))
    
    elif base_city != city:
        # 処理
        base_city = city
        anslist2 = sorted(prelist2, reverse=True)
        for ans2_tuple in anslist2:
            score, position = ans2_tuple[0], ans2_tuple[1]
            print(position + 1)
            
        prelist2 = []
        anslist2 = []
        
        prelist2.append((ans_tuple[1], ans_tuple[2]))
    
#finalaize    
anslist2 = sorted(prelist2, reverse=True)
for ans2_tuple in anslist2:
    score, position = ans2_tuple[0], ans2_tuple[1]
    print(position + 1)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
dict = {}


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

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

Submission status: Accepted

Solution code:
N = int(input())

S = []
P = []
I = []

for i in range(N) : 
    a, b = input().split()
    S.append(a)
    P.append(100 -int(b))
    I.append(i+1)
    
I2 = [x for x in sorted(zip(S, P, I))]

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

Submission status: Accepted

Solution code:
N = int(input())
d = {}

for i in range(N):
	S, P = [x for x in input().split()]
	P = int(P)
	
	if S in d.keys():
		d[S].append([P, i])
	else:
		d[S] = [[P, i]]

keys = sorted(list(d.keys()))

for key in keys:
	values = sorted(d[key])
	values.reverse()
	for val in values:
		print(val[1]+1)

Submission status: Accepted

Solution code:
n = int(input())

l = [list(map(str,input().split()))for i in range(n)]

name = []
rate = []

for i in range(n):
    name.append(l[i][0])

for i in range(n):
    rate.append(int(l[i][1]))
    


for i in range(n):
    l[i][1] = int(l[i][1])

for i in range(n):
    l[i][1] = 100 - l[i][1]
    
sorted_l = sorted(l)


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

Submission status: Accepted

Solution code:
print("\n".join([str(y[0]) for y in sorted([[i + 1] + input().split() for i in range(int(input()))], key=lambda x: (x[1], -int(x[2])))]))

Submission status: Accepted

Solution code:
N = int(input())


ress = []

for i in range(N):
    inputs = input().split()
    s = str(inputs[0])
    p = int(inputs[1])

    ress.append([s, -p, i + 1])
ans = sorted(ress, key=lambda x: (x[0], x[1]), reverse=False)
for i in ans:
    print(i[2])

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
SP = [input().split()+[i] for i in range(1, N+1)]

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

for j in S:
  print(j[2])

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for i in range(n):
    s, p = input().split()
    if s in d:
        d[s].append((int(p), i + 1))
    else:
        d[s] = [(int(p), i + 1)]
for key in sorted(d.keys()):
    sorted_list = sorted(d[key], reverse =True)
    for item in sorted_list:
        print(item[1])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
A = []
for i in range(n):
    s, b = map(str, input().split())
    b = int(b)
    A.append([s, -b, i+1])
A.sort()
for i in A:
    print(i[2])

Submission status: Accepted

Solution code:
N = int(input())
li = []
for i in range(N):
    si, pi = input().split()
    pi = int(pi)
    li +=[ [i+1, si, pi]]
li.sort(key=lambda x:x[2], reverse=True)
li.sort(key=lambda x:x[1], reverse=False)
for j in li:
    print(j[0])

Submission status: Accepted

Solution code:
N=int(input())
r_dic={}
for i  in range(N):
    s,p=input().split()
    r_dic.setdefault(s,[]).append((int(p),i+1))
    
for city in  sorted(r_dic.keys()):
    for data in (sorted(r_dic[city], reverse=True)):
        print(data[1])

Submission status: Accepted

Solution code:
N = int(input())
hoge = []
for i in range(0,N):
	b = [x for x in input().split()]
	hoge.append(b)

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

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

Submission status: Accepted

Solution code:
N = int(input())
r = [input().split() for _ in range(N)]
R = r.copy()
r = sorted(r, key=lambda x:(x[0], -int(x[1])))

for i in r:
  if i in R:
    print(R.index(i)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())

n = ni()
lis = []
ans = [[] for _ in range(n)]
for i in range(n):
    s, p = nsm()
    p = -int(p)
    lis.append([s, p, i])
lis.sort()
for i in range(n):
    print(lis[i][2] + 1)

Submission status: Accepted

Solution code:
import copy
N=int(input())
SP=list(list(input().split()) for _  in range(N))
SSP=copy.deepcopy(SP)
SP.sort(key=lambda x:int(x[1]),reverse=True)
SP.sort(key=lambda x:x[0])

for i in SP:
    print(SSP.index(i)+1)

Submission status: Accepted

Solution code:
class Store:
    def __init__(self, c, p, id):
        self.city = c
        self.point = p
        self.id = id
N = int(input())
stores = []
for i in range(N):
    c, p = input().split()
    stores.append(Store(c, int(p), i+1))
stores.sort(key = lambda x: (x.city, -x.point))
for i in range(N):
    print(str(stores[i].id))

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
S = [0]*N
P = [0]*N
index = [i+1 for i in range(N)]
for i in range(N):
  S[i],P[i] = map(str,input().split())
  P[i] = int(P[i])
X = zip(S,P,index)
X = sorted(X,key = lambda x: (x[0],-x[1]),reverse = False)

S,P,index = zip(*X)
for i in range(N):
  print(index[i])

Submission status: Accepted

Solution code:
n = int(input())
spi = {}
for i in range(n):
    t = input().split()
    if t[0] in spi:
        spi[t[0]] += [(int(t[1]), i+1)]
    else:
        spi[t[0]] = [(int(t[1]), i+1)]

for e in spi:
    spi[e] = sorted(spi[e], key=lambda x: x[0], reverse=True)

spi = sorted(zip(*[spi.keys(), spi.values()]), key=lambda x: x[0])

for e in spi:
    for r in e[1]:
        print(r[1])

Submission status: Accepted

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


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

SP = {}

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


K = sorted(SP)

for k in K:
    SP[k].sort(reverse=True)
    for t in SP[k]:
        print(t[1])

Submission status: Accepted

Solution code:
N = int(input())

dic = []
for n in range(N):
  S, P = map(str, input().split())
  name = S + str(100 - int(P)).zfill(3)
  dic.append(name)

dic_sorted = sorted(dic)

for r in dic_sorted:
  print(dic.index(r)+1)

Submission status: Accepted

Solution code:
N = int(input())
restaurants = [(lambda t: (t[0], int(t[1]), i))(input().split()) for i in range(N)]
restaurants.sort(key=lambda t:(t[0], -t[1]))

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

Submission status: Accepted

Solution code:
n = int(input())

restaurants = {}

for i in range(n):
    s, p = [j for j in input().split()]
    if s in restaurants:
        restaurants[s].append([int(p), i])
    else:
        restaurants[s] = [[int(p), i]]

for ip in sorted(restaurants.items()):
     for i in sorted(ip[1], reverse=True):
         print(i[1] + 1)

Submission status: Accepted

Solution code:
from operator import itemgetter


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

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

    rest = sorted(rest, key=itemgetter(2), reverse=True)
    rest = sorted(rest, key=itemgetter(1))
    for i, _, _ in rest:
        print(i)


main()

Submission status: Accepted

Solution code:
# 辞書順かつ大きい順（リスト）
n = int(input())
hash = {}
for i in range(n):
    s, p = input().split()
    p = int(p)
    if s in hash.keys():
        hash[s].append([i, p])
    else:
        hash[s] = list()
        hash[s].append([i, p])

hash = sorted(hash.items())
for k, v in hash:
    vs = sorted(v, key=lambda x: x[1], reverse=True)
    for i in vs:
        print(i[0]+1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5)


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


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

X = sorted(X.items())
for v in X:
    a = sorted(v[1], reverse=True)
    for i in a:
        print(i[1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = [0]*n
p = [0]*n
w = [0]*n
for i in range(n):
    s[i], p[i] = input().split()
    p[i] = int(p[i])
    w[i] = [s[i], p[i],i+1]

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

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

Submission status: Accepted

Solution code:
N = int(input())
shops = [input().split() for _ in range(N)]
copy = shops.copy()
shops.sort(key=lambda x: (x[0], 1/(int(x[1])+1)))
for shop in shops:
    print(copy.index(shop)+1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 26 20:55:50 2019

@author: Yamazaki Kenichi
"""

N = int(input())
sp = [list(map(str,input().split()))+[i] for i in range(N)]

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

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

#sp1.sort(reverse = True, key=lambda x: x[1])

for c in sp1:
    print(int(c[2])+1)

Submission status: Accepted

Solution code:
n = int(input())

idx = [i+1 for i in range(n)]
s = []
p = []

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

for i in range(n-1):
    for j in range(i+1, n):
        if s[i] > s[j] or (s[i] == s[j] and p[i] < p[j]):
            idx[i], idx[j] = idx[j], idx[i]
            s[i], s[j] = s[j], s[i]
            p[i], p[j] = p[j], p[i]

for i in idx:
    print(i)

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
info=[]
for i in range(n):
    s,p=input().split()
    info.append([s,int(p),i+1])
info=sorted(info)
memo=info[0][0]
l=[]
for k in range(n):
    if memo==info[k][0]:
        l.append(info[k][2])
    else:
        for j in range(len(l)):
            print(l[-1-j])
        l=[info[k][2]]
        memo=info[k][0]
for j in range(len(l)):
    print(l[-1-j])

Submission status: Accepted

Solution code:
n = int(input())

shop_list = [[int('-'+j) if i==1 else j for i, j in enumerate(input().split())] for _ in range(n)]

intro_list = sorted(shop_list)

for shop in intro_list:
  print(shop_list.index(shop)+1)

Submission status: Accepted

Solution code:
N = int(input())

restrans = []
for i in range(N):
	inputs = list(input().split())
	restrans.append((str(inputs[0]), int(inputs[1]), i + 1))

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

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

Submission status: Accepted

Solution code:
N = int(input())

R_list = {}
for i in range(N):
    S, P = map(str, input().split(" "))

    if S in R_list:
        l = R_list[S]
        l.append((int(P), i+1))
    else:
        l = [(int(P), i+1)]
        R_list[S] = l

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



for S in score_sorted:
    S[1].sort(reverse=True)
    for P in S[1]:
        print(P[1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
Ss = [0] * N
Ps = [0] * N
cities = [0] * N
for i in range(N):
    l = input().split()
    Ss[i], Ps[i] = l[0], int(l[1])
    cities[i] = Ss[i]

cities = sorted(set(cities))

cities_dir = {}
for city in cities:
    cities_dir[city] = []

for i in range(N):
    cities_dir[Ss[i]].append((Ps[i], i))

for city in cities:
    vs = sorted(cities_dir[city], key=lambda x: x[0], reverse=True)
    for k in vs:
        print(k[1] + 1)

Submission status: Accepted

Solution code:
N = int(input())
SP_str = [list(input().split()) for i in range(N)]
SP = [[i[0],int(i[1])] for i in SP_str]


SP_sort = sorted(SP,key=lambda x: (x[0],-x[1]))
for i in range(N):
    a = SP.index(SP_sort[i])
    print(a+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

from operator import itemgetter
n = int(input())
sp={}
for i in range(n):
    [name,value] = input().split()
    if sp.get(name) is None:
        sp[name] = [(int(value),i)]
    else:
        sp[name].append((int(value),i))


for key in sp.keys():
    sp[key] = sorted(sp[key], key=itemgetter(0))

    
sp = sorted(sp.items())

for s in sp:
    for p in s[1][::-1]:
        print(p[1]+1)

Submission status: Accepted

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

for i in range(N):
    s, p = input().split()
    SP.append({'name':s, 'point':int(p), 'num':int(i+1)})

SP.sort(key=lambda x: x['point'], reverse=True)
SP.sort(key=lambda x: x['name'])

for v in SP:
    print(v['num'])

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
t_list = []
for i in range(N):
  a = list(map(str, input().split()))
  a[1] = int(a[1])
  a.append(i)
  t_list.append(a)
  

t_list = sorted(t_list, key=itemgetter(1), reverse=True)
t_list = sorted(t_list, key=itemgetter(0))
for j in range(N):
  print(t_list[j][2]+1)

Submission status: Accepted

Solution code:
n = int(input())

ls = []

for i in range(n):
  s, p = map(str,input().split())
  sp = [s,int(p)]
  sp.append(i+1)
  ls.append(sp)
  
ls_sort = sorted(ls, key=lambda x: (x[0],-x[1]))

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

Solution code:
import math
n = int(input())
h = []
for i in range(n):
    l = list(map(str, input().split()))
    l.append(i+1)
    h.append(l)

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

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

Submission status: Accepted

Solution code:
import sys
import os
from operator import itemgetter

N=int(input())

S=[0]*N
P=[0]*N
X=[0]*N
X2=[0]*N
for i in range(N):
    S[i], P[i] =  input().split()
    X[i]=S[i]+P[i]
    P[i]=int(P[i])

D=[list(x) for x in zip(*sorted(zip(P, S), key=itemgetter(0),reverse=True))]
S=D[1]
P=D[0]
D=[list(x) for x in zip(*sorted(zip(S, P), key=itemgetter(0)))]
S=D[1]
P=D[0]
for i in range(N):
    X2[i]=P[i]+str(S[i])
    print(X.index(X2[i])+1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
sp = [input().split() for _ in range(n)]
sp2 = sorted(sorted(sp, key=lambda x: -int(x[1])), key=lambda x: x[0])
for t in sp2:
  print(sp.index(t)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

    def __eq__(self, other):
        return (self.s == other.s) and (self.p == self.p)

    def __lt__(self, other):
        return (self.s < other.s) or (self.p > other.p and self.s == other.s)

    def __ne__(self, other):
        return not self.__eq__(other)

    def __le__(self, other):
        return self.__lt__(other) or self.__eq__(other)

    def __gt__(self, other):
        return not self.__le__(other)

    def __ge__(self, other):
        return not self.__lt__(other)

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

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

restaurants.sort()

for r in restaurants:
    print(r.i)

Submission status: Accepted

Solution code:
n = int(input())

dict_ = {}

for i in range(n):
    s, p = input().split()
    if s in dict_:
        dict_[s].append([p, i+1])
    else:
        dict_[s] = [[p, i+1]]

for key, item in sorted(dict_.items()):
    for p, i in sorted(item, key=lambda x:int(x[0]), reverse=True):
        print(i)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

n=int(input())
SP=[]
ind=1
for _ in range(n):
    s,p=(i for i in input().split())
    p=int(p)
    SP.append([s,p,ind])
    ind+=1
    
SP=sorted(SP, key=lambda x: (x[0],-x[1]))
for res in SP:
    print(res[2])

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input())
d = []
for i in range(n):
    _s, _p = input().split()
    d.append({'number': i, 'city': _s, 'point': int(_p)})
sortedd = sorted(d, key = lambda x: (x['city'], -x['point']))
for n in sortedd:
    print(n['number'] + 1)

Submission status: Accepted

Solution code:
n = int(input())
r = [input().split() + [i+1] for i in range(n)]
o = sorted(r,key=lambda x:(x[0],-int(x[1])))
[print(o[i][2]) for i in range(n)]