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())
sp = [input().split() for _ in range(n)]
for (s, p), i in sorted(zip(sp, range(1, n + 1)), key=lambda x: (x[0][0], -int(x[0][1]))):
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
s = list([input() for _ in range(n)])

for x in sorted(enumerate(s), key=lambda x: (x[1].split()[0], -int(x[1].split()[1]))):
    print(x[0] + 1)

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for i in range(n):
    name, p = input().split(' ')
    p = int(p)
    d[name] = d.get(name, []) + [(-p, i+1)]
for key in sorted(d):
    d[key] = sorted(d[key])
    for i in range(len(d[key])):
        print(d[key][i][1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
rest=[input().split()+[i+1] for i in range(n)]
rest.sort(key=lambda i:(i[0],-int(i[1])))
ans=[rest[i][2] for i in range(n)]
print(*ans,sep='\n')

Submission status: Accepted

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

rest.sort(key=lambda i:i[0])
#print(rest)
cnt=0
for i in range(1,n):
  if rest[i-1][0]==rest[i][0]:
    continue
  else:
    res=rest[cnt:i]
    res.sort(key=lambda i:i[1],reverse=True)
    #print(res)
    for j in range(i-cnt):
      print(res[j][2])
    cnt=i
    #print(str(cnt)+'がcntです')
res=rest[cnt:n]
#print(res)
res.sort(key=lambda i:i[1],reverse=True)
for i in range(n-cnt):
  print(res[i][2])

Submission status: Accepted

Solution code:
a = range(1, int(input())+1)
b = sorted(a, key=lambda _:[(s, -int(p)) for s, p in[input().split()]])
print(*b)

Submission status: Accepted

Solution code:
N = int(input())
L = [input().split() + [i+1] for i in range(N)]
L.sort(key=lambda x: (x[0], -int(x[1])))
print(*[n[2] for n in L], sep='\n')

Submission status: Accepted

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

beta = sorted(lst, key=lambda x: x[1], reverse=True)
alpha = sorted(beta, key=lambda x: x[0])

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

Submission status: Accepted

Solution code:
n = int(input())

sp = []

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


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


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

Submission status: Accepted

Solution code:
N = int(input())
restaurant = []
for i in range(N):
  s, p = input().split()
  restaurant += [[s, int(p), i+1]]
restaurant.sort(key = lambda x:(x[0], -x[1]))

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

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
dic = defaultdict()
for i in range(1, N+1):
  k, v = input().split()
  dic[i] = [k, int(v)]
  
sorted_dic = sorted(dic.items(), key=lambda x:(x[1][0], -x[1][1]))
for k, *v in sorted_dic:
  print(k)

Submission status: Accepted

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

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

SP_sorted1 = sorted(lista, key=lambda x:x[1], reverse=True)
SP_sorted2 = sorted(SP_sorted1, key=lambda x:x[0])

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

Submission status: Accepted

Solution code:
def main(N, lst):
    L = []
    for i in range(len(lst)):
        target = lst[i]
        L.append({"id":i+1, "store":target[0], "point":int(target[1])})
    L.sort(key = lambda x:x["point"], reverse = True)
    L.sort(key = lambda x:x["store"])
    for i in range(len(L)):
        print(L[i]["id"])

N = int(input())
lst = list(list(map(str, input().split())) for _ in range(N))
main(N, lst)

Submission status: Accepted

Solution code:
def main(N, lst):
    L = []
    for i in range(len(lst)):
        target = lst[i]
        L.append({"id":i+1, "store":target[0], "point":int(target[1])})
        L.sort(key = lambda x:x["point"], reverse = True)
        L.sort(key = lambda x:x["store"])
    for i in range(len(L)):
        print(L[i]["id"])

N = int(input())
lst = list(list(map(str, input().split())) for _ in range(N))
main(N, lst)

Submission status: Accepted

Solution code:
N = int(input())

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

list=[]
for i in range(N):
    cnt = 1
    for j in range(N):
        if i == j:
            continue
        if S[i] > S[j]:
            cnt += 1
        if S[i] == S[j] and P[i]<P[j]:
            cnt +=1
    list.append(cnt)

for i in range(1,N+1):
    print(list.index(i) + 1)

Submission status: Accepted

Solution code:
n=int(input())
d=[]

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

d.sort()
for i in range(n):
    print(d[i][2])

Submission status: Accepted

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

d=sorted(d)
for i in range(N):
    print(d[i][2])

Submission status: Accepted

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

l.sort()
for item in l:
    print(item[2])

Submission status: Accepted

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

L.sort()
for j in range(N):
  print(L[j][2])

Submission status: Accepted

Solution code:
# https://www.planeta.tokyo/entry/3963/
# N = 3
# X =[[['Fuji', '5'], 1], [['Fuji', '2'], 2], [['Angus', '3'], 3]]
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])

Submission status: Accepted

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

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
SP=[[list(input().split()), i+1] for i in range(N)]
for i in range(N):
  SP[i][0][1]=(-1)*int(SP[i][0][1])
SP.sort(key=lambda x:(x[0][0], x[0][1]))
for i in range(N):
  print(SP[i][1])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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


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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

Submission status: Accepted

Solution code:
n = int(input())

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


L = []

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

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


restaurants_sorted = sorted(restaurants.items(), key=lambda x:x[0])
# print(restaurants_sorted)
# print(restaurants_sorted[0])
for idx in range(len(restaurants_sorted)):
	for i in range(len(restaurants_sorted[idx][1])):
		print(target.index(restaurants_sorted[idx][0]+' '+str(restaurants_sorted[idx][1][i]))+1)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
rest = []

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

rest.sort()

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
N = int(input())
Michelin = dict()
seen = []
number = 1
for _ in range(N):
    shop,point = map(str,input().split())
    if shop not in seen:
        Michelin[shop] = [[],[]] #moscow:{[[],[]]} point,number
        Michelin[shop][0].append(int(point)) 
        Michelin[shop][1].append(number)
        number += 1
        seen.append(shop)
    else:
        Michelin[shop][0].append(int(point))
        Michelin[shop][1].append(number)
        number += 1
seen.sort() #店の名前が辞書順になる。
#{'khabarovsk': [[20, 40], [1, 6]], 'moscow': [[10, 60], [2, 5]], 'kazan': [[50, 35], [3, 4]]}
for shop in seen:
    while Michelin[shop][0] != []:
        shokai = max(Michelin[shop][0])
        bango = Michelin[shop][0].index(shokai)
        print(Michelin[shop][1][bango])
        Michelin[shop][0].remove(shokai)
        Michelin[shop][1].remove(Michelin[shop][1][bango])

Submission status: Accepted

Solution code:
import sys
import math

N = int(input())

list = []

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

lts = sorted(lt)

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

Submission status: Accepted

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

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

SP.sort()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
n=int(input())

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

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

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


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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

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

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

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

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

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

Submission status: Accepted

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

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

current_city_name = ""
result = []
sumup = 0

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


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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

x.sort()

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(input().split()) #二重リスト作成

b = 1
for j in a: #★レストランの番号をindex2に付与
    j.append(b)
    b += 1

for k in a: #★点数をpopで取り出し-1を乗じてinsert→降順にソートするため
    x=k.pop(1)
    k.insert(1,int(x)*-1)

a.sort()

for m in a: #index2を取り出す
    print(m[2])

Submission status: Accepted

Solution code:
# B - Guidebook
import numpy as np
# import pandas as pd 

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

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


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

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

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(input().split()) #二重リスト作成

b = 1
for j in a: #レストランの番号をindex2に付与
    j.append(b)
    b += 1

for k in a: #点数をpopで取り出し-1を乗じてinsert→降順にソートするため
    x=k.pop(1)
    k.insert(1,int(x)*-1)

a.sort()

for m in a: #index2を取り出す
    print(m[2])

Submission status: Accepted

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

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

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

a.sort()

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

Submission status: Accepted

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

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


Guide()

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

SP.sort()

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

# import numpy as np
import itertools

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

L2 = L1

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

Submission status: Accepted

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

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


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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A=[]
p = int(input())
for i in range(p):
  j,k = input().split()
  A.append([j,-int(k),i+1])
A = sorted(A)
for j,k,l in A:
  print(l)

Submission status: Accepted

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

def examB():
    N = I()
    SP = [[]for _ in range(N)]
    for i in range(N):
        SP[i] = LSI()
        SP[i][1] = int(SP[i][1])
        SP[i].append(i)
#    print(SP)
    SP = sorted(SP,key = lambda x:x[1], reverse = True)
    SP = sorted(SP,key = lambda x:x[0])
#    print(SP)
    for v in SP:
        print(v[2]+1)
    return

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

if __name__ == '__main__':
    examB()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

SP.sort()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


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

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

Submission status: Accepted

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