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:
import numpy as np

N = int(input())
rests = []
evals = []

for n in range(N):
    i = input().split()
    rests.append(i[0])
    evals.append(int(i[1]))

rests = np.array(rests)
evals = np.array(evals)
nums = np.array([i + 1 for i in range(len(rests))])

order_by_name = np.argsort(rests)
rests = rests[order_by_name]
evals = evals[order_by_name]
nums = nums[order_by_name]
names = np.unique(rests)

for name in names:
    loc = np.where(rests == name)[0]
    if len(loc) == 1:
        pass
    else:
        start = loc[0]
        end = loc[-1] + 1
        order_by_eval = np.argsort(- evals[start:end])
        evals[start:end] = evals[start:end][order_by_eval]
        nums[start:end] = nums[start:end][order_by_eval]

for num in nums:
    print(num)

Submission status: Accepted

Solution code:
N = int(input())
List = [list(map(str,input().split())) for i in range(N)]

for i in range(N):
    List[i].append(i+1)
    List[i][1] = int(List[i][1])
List.sort(key=lambda x:x[1], reverse=True)
List.sort(key=lambda x:x[0])
for i in range(N):
    print("{}".format(List[i][2]))

Submission status: Accepted

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

for i in range(N):
    SPli.append(list(input().split()))
    SPli[i].append(i+1)

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

for SP in SPli:
    print(SP[2])

Submission status: Accepted

Solution code:
n=int(input())
arr=[]
for i in range(n):
	s,p=map(str,input().split())
	p=int(p)
	arr.append([s,p,i+1])
# arr=sorted(arr,key=lambda item:item[0])
arr=sorted(arr,key=lambda item:item[1],reverse=True)
arr=sorted(arr,key=lambda item:item[0])
# print(arr)
for i in range(len(arr)):
	print(arr[i][2])

Submission status: Accepted

Solution code:
n = int(input())
ls = []
for i in range(n):
    c,p = input().split()
    p = int(p)
    ls.append((c,p))
order = [i for i in range(n)]
order.sort(key = lambda x:(ls[x][0],-ls[x][1]))
for i in range(n):
    print(order[i]+1)

Submission status: Accepted

Solution code:
N = int(input())

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

city_dict = {}
for i,sp in enumerate(sp_list):
    s = sp[0]
    p = sp[1]
    if s in city_dict:
        city_dict[s] = city_dict[s]+[[p,i+1]]
    else:
#         print()
        city_dict[s] = [[p,i+1]]

from operator import itemgetter
for k, v in sorted(city_dict.items()):
#     print(k,v)
    v.sort(key=itemgetter(0))
    for v0,v1 in v[::-1]:
        print(v1)

Submission status: Accepted

Solution code:

N= int(input())
sa=[]
for i in range(N):
  tmp=input().split()
  sa.append([tmp[0],100-int(tmp[1]),i+1])
sa = sorted(sa)
#print(sa)
for i in range(len(sa)):
  print(sa[i][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+1])
l.sort()
flag=0
x=[]
for i in range(n-1):
    x.append([int(l[i][1]),int(l[i][2])])
    if l[i][0]==l[i+1][0]:
        pass
    else:
        x.sort()
        x.reverse()
        for j in range(len(x)):
            print(int(x[j][1]))
        x.clear()
x.append([int(l[n-1][1]),int(l[n-1][2])])
if x!=[]:
    x.sort()
    x.reverse()
    for j in range(len(x)):
            print(int(x[j][1]))
else:
    print(int(x[n-1][1]))

Submission status: Accepted

Solution code:
from operator import itemgetter
N = input()
t = []
for i in range(N):
	s,p = raw_input().split()
	p2 = int(p)
	t.append([s,p2,i+1])
t2 = sorted(t,key = itemgetter(1), reverse = True)
t3 = sorted(t2,key = itemgetter(0))
for c in t3:
	print(c[2])

Submission status: Accepted

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

new_list = sorted(list, key=lambda x: (x[0], x[1]))
for k in new_list:
    print(k[2])

Submission status: Accepted

Solution code:
n = int(input())
s = []
p = []
items = []
for i in range(n):
    a, b = (x for x in input().split())
    s.append(a)
    p.append(int(b))
    items.append({'i':i+1, 's':a, 'p':-int(b)})
sorted_items = sorted(items,key = lambda x: (x['s'],x['p']))
for i in range(n):
    print(sorted_items[i]['i'])

Submission status: Accepted

Solution code:
N = int(input())

A = []

# 出力を受け取る
for i in range(N):
    Si , Pi = input().split()
    Pi = int(Pi) # 型変換

    A.append([i,Si,Pi])

# リストにアクセス
second = lambda A : A[1]
third = lambda A : A[2]

# ソート
A.sort(key=third,reverse=True)
A.sort(key=second)

for target in A:
    print(target[0] + 1)

Submission status: Accepted

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

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

[print(i) for _, _, i in rs]

Submission status: Accepted

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from copy import copy
import numpy as np
from numpy.fft import fft, ifft
from fractions import gcd


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()

sp = [[x for x in input().split()] for _ in range(n)]

for x in sp:
    x[1]=int(x[1])

lis=sp.copy()
sp.sort(key=lambda x:(x[0],-x[1]))

#print(sp)
#print(lis)

for x in sp:
    print(lis.index(x)+1)

Submission status: Accepted

Solution code:
class Shop:

    def __init__(self, s, p):
        self.s = str(s)
        self.p = int(p)

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

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

    def __lt__(self, other):
        return (self.s, -self.p) < (other.s, -other.p)

    def __le__(self, other):
        return (self.s, -self.p) < (other.s, -other.p)


def read():
    N = int(input().strip())
    shops = []
    for i in range(N):
        s, p = list(input().strip().split())
        shops.append(Shop(s, p))
    return N, shops


def solve(N, shops):
    order = sorted(range(N), key=lambda k: shops[k])
    return order


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    for i in outputs:
        print("%d" % (i + 1))

Submission status: Accepted

Solution code:
from sys import stdin

def main():
     n = int(stdin.readline())
     a = [[ x for x in stdin.readline().split()] for i in range(n)]
     b = [ i for i in a]
     a.sort(key=lambda x:100-int(x[1]))
     a.sort(key=lambda x:x[0])
     for i in a:
          for j in range(n):
               if i == b[j]:
                    print(j+1)
                    break
if __name__ == '__main__':
     main()

Submission status: Accepted

Solution code:
N = int(input())

NSP = list()

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

NSP.sort(key=lambda x: x[2])
NSP.reverse()
NSP.sort(key=lambda x: x[1])

for n in range(N):
    print(NSP[n][0])

Submission status: Accepted

Solution code:
n = int(input())
cities = set()
d = dict()
for i in range(n):
    s, p = input().split()
    cities.add(s)
    d.setdefault(s, [])
    d[s].append((i+1, int(p)))
cities = list(cities)
cities.sort()
for c in cities:
    l = d[c]
    l.sort(key=lambda i: -i[1])
    for i in l:
        print(i[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

N = int(input())
# L = [int(x) for x in input().split()]
# S, P = map(int, input().split())

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

for x in SP:
    print(x[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))
l_s = sorted(l, key=lambda x:x[1], reverse=True)
l_s2 = sorted(l_s, key=lambda x:x[0])
for i in range(N):
    print(l_s2[i][2] + 1)

Submission status: Accepted

Solution code:
n=int(input())
sp = {}
for i in range(n):
  s,p = list(input().split(' '))
  if s not in sp.keys():
    sp[s] = [[int(p), i+1]]
  else:
    sp[s].append([int(p),i+1])
for a in sorted(sp.items()):
  for p,i in sorted(a[1], reverse=True):
    print(i)

Submission status: Accepted

Solution code:
n = int(input())

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

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

count = 0
while count != n:
	for i in range(n):
		if rest_sort[count] == rest[i]:
			print(i+1)
	count += 1

Submission status: Accepted

Solution code:
n = int(input())

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

d = sorted(d.items(), key=lambda x:x[0])
d = [sorted(x[1], reverse=True)  for x in d]

for xs in d:
    for x in xs:
        print(x[1])

Submission status: Accepted

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

sp_list.sort(reverse=True,key=lambda x:int(x[1]))

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(list)
N = int(input())

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

l = list(d.items())
l.sort()

for s,t in l:
	t.sort(reverse = True)
	for a,b in t:
		print(b)

Submission status: Accepted

Solution code:
N = int(input())
X = []
for i in range(N):
    a,b = map(str, input().split())
    X.append([a, int(b), i + 1])

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

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

Submission status: Accepted

Solution code:
# coding; utf-8
def main():
    N = int(input())
    rest = []
    for i in range(N):
        si, tempP = input().split()
        pi = int(tempP)
        rest.append([i+1, si, pi])

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

rest_dict = {}


rest_arr = []
for i in range(N):
    tmp = input().split()
    rest_arr.append(tmp)

for i in range(N):
    if rest_arr[i][0] in rest_dict:
        rest_dict[rest_arr[i][0]].append(int(rest_arr[i][1]))
    else:
        rest_dict[rest_arr[i][0]] = [int(rest_arr[i][1])]
    rest_dict[rest_arr[i][0]] = sorted(rest_dict[rest_arr[i][0]], key=lambda x: -x)



rest_dict = sorted(rest_dict.items())


def search_num(rest, num):
    for i in range(N):
        if rest_arr[i][0] == rest and int(rest_arr[i][1]) == num:
            return i + 1
 

for i in rest_dict:
    for j in i[1]:
        print(search_num(i[0], j))

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

fin = sys.stdin.readline
N = int(fin())
conditions = [[elem for elem in fin().split()] + [idx+1] for idx in range(N)]
conditions = [[x[0], int(x[1]), x[2]] for x in conditions]

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

[print(x[2]) for x in conditions]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
# import math
# import random
# import fractions
# import sys
# sys.setrecursionlimit(100000)
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]
N = int(stdin.readline().rstrip().split()[0])
S=[]
for i in range(N):
  s, p = [x for x in stdin.readline().rstrip().split()]
  S.append(s+str(999-int(p)))
# print(S)
Sidx=sorted(S)
# print(S)
# print(Sidx)
for i in range(N):
  print(S.index(Sidx[i])+1)

Submission status: Accepted

Solution code:
N = int(input())
city = []
point = []
for i in range(N):
    S,P = input().split()
    P = int(P)
    city += [S]
    point += [P]

citys = sorted(city)
i = 0
while i < N:
    how = city.count(citys[i])
    if how == 1:
        print(city.index(citys[i])+1)
        i += 1
    else:
        indexes = [j for j, x in enumerate(city) if x == citys[i]]
        points = sorted([point[j] for j in indexes])[::-1]
        for k in points:
            print(point.index(k)+1)
        i += len(indexes)

Submission status: Accepted

Solution code:
N = int(input())
SP_ = []
for i in range(N):
  s,p = input().split()
  SP_.append([s,int(p),i])
  
SP_s = sorted(SP_,key=lambda x:(x[0],-x[1]))
#print(SP_s)

for i in range(N):
  print(SP_s[i][2]+1)

Submission status: Accepted

Solution code:
N = int(input())
X = [[None for i in range(3)] for j in range(N)]
for i in range(N):
    X[i][0] = i+1
    a = input().split()
    X[i][1] = a[0]
    X[i][2] = int(a[1])
X.sort(key=lambda x: (x[1], -x[2]))
for i in range(N):
    print(X[i][0])

Submission status: Accepted

Solution code:
n = int(input())
l =[]
for i in range(n):
  l.append(list(input().split()))
  l[i][1] = int(l[i][1])
  l[i].append(i+1)
l.sort(key=lambda x:(x[0],-x[1]))
#l.sort(key=lambda x:x[1],reverse=True)
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()
    p = int(p)
    l.append([s, p, i+1])
    
#print(l)
l = sorted(l, key=lambda x:x[1], reverse=True)
#print(l)
l = sorted(l, key=lambda x:x[0])
#print(l)

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

Submission status: Accepted

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

for i in range(n):
  a,b=map(str,input().split())
  b=int(b)
  s.append([a,100-b,i+1])
  
s.sort(key=lambda x:(x[0],x[1]))
#print(s)

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

Submission status: Accepted

Solution code:
N=input()

L=[]

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

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

for x,y,z in L:
	print z

Submission status: Accepted

Solution code:
N = int(input())
S = []
 
for i in range(N):
    ts,tp = input().split()
    ts = str(ts)
    tp = 100-int(tp)
    S.append([ts,tp,i+1])
    
S.sort(key=lambda x:(x[0],x[1]))

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from operator import itemgetter
# input
x = int(input())
#a, b, c = map(int, input().split())
#a, b, c = input().split()
o = []
for i in range(x):
    a, b = input().split()
    o.append([i+1, a, int(b)])
o.sort(key=itemgetter(2), reverse=True)
o.sort(key=itemgetter(1))
# print(o)
for j in range(x):
    print(o[j][0])

Submission status: Accepted

Solution code:
n = int(input())
sp = [list(map(str,input().split())) for _ in range(n)]

c = 1
for i in sp:
    i[1] = int(i[1])
    i.append(c)
    c += 1

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

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

Submission status: Accepted

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

ispList = []
for i, sp in enumerate(spList):
    ispList.append((i+1, sp[0], int(sp[1])))

ispList.sort(key=lambda x: (x[1], -x[2]))
for i, isp in enumerate(ispList):
    print(isp[0])

Submission status: Accepted

Solution code:
n = int(input())
x = {}
for i in range(1,n+1):
  si,pi = map(str,input().split())
  if si not in x.keys():
    x[si] = [(int(pi),i)]
  else:
    x[si].append((int(pi),i))
y = sorted(x.keys())
for k in y:
  xk = x[k]
  xk.sort(key=lambda xx:xx[0],reverse=True)
  for i in xk:
    print(i[1])

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
SP = []
d = {}
for i in range(1, N+1):
    s, p = input().split()
    SP.append([s, -int(p), i])
    d[int(p)] = i
# SP.sort(key= lambda x:x[0])
# SP.sort(key=lambda x:x[1])
SP.sort()
[print(i[2]) for i in SP]

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
res = [[i] + input().split() for i in range(n)]

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

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

Submission status: Accepted

Solution code:
n = int(input())  # 数値入力
li = list()

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

li.sort()
lastcity = li[0][0]
newli = list()

for i in range(n):
    if lastcity == li[i][0]:
        newli.append([li[i][1], li[i][2]])
        lastcity = li[i][0]
    else:
        newli = newli[::-1]
        for tmp in newli:
            print(tmp[1])
        newli = list()
        newli.append([li[i][1], li[i][2]])
        lastcity = li[i][0]

newli = newli[::-1]
for tmp in newli:
    print(tmp[1])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    sp = []
    for i in range(n):
        a, b = input().split()
        b = int(b)
        sp.append([a, b, i])
    sp.sort(key=lambda x:(x[0], -x[1]))
    for arr in sp:
        print(arr[2]+1)

Submission status: Accepted

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

R.sort()
for i in R:
    print(i[2] + 1)

Submission status: Accepted

Solution code:
n = int(input())
book = {}
for i in range(n):
  tmp = input().split()
  name = tmp[0]
  score = int(tmp[1])
  if name not in book:
    book[name] = {}
    book[name][score] = i + 1
  else:
    book[name][score] = i + 1

for key_city in sorted(book.keys()):
  for key_score in sorted(book[key_city].keys(), key=lambda x: -x):
  	print(book[key_city][key_score])

Submission status: Accepted

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

for i,_,_2 in sorted(a, key=lambda x:(x[1],x[2])):
        print(i)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ls(): return stdin.readline().split()
N = ii()
city_r = defaultdict(list)
for i in range(1, N + 1):
    c, s = ls()
    s = int(s)
    city_r[c].append( (s, i) )
keys = sorted(city_r.keys())
for k in keys:
    vs = city_r[k]
    vs.sort(key=lambda x:-x[0])
    for v in vs:
        print(v[1])

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
p = [list(map(str, input().split())) for i in range(n)]
for i in range(n):
    p[i][1] = int(p[i][1])
    p[i].append(i+1)
pp = sorted(p, key=itemgetter(1), reverse=True)
ppp = sorted(pp, key=itemgetter(0))
for i in range(n):
    print(ppp[i][2])

Submission status: Accepted

Solution code:
import operator
n = int(input())
s = []
p = []
for i in range(n):
    x, y = input().split()
    s.append((x, int(y), i+1))
s = sorted(s, key=lambda x:(x[0], -x[1]))
for c in s:
    print(c[2])

Submission status: Accepted

Solution code:
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[0],-x[1]))

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

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    s_list=[]
    for i in range(n):
        city,score=input().split(' ')
        s_list.append((score,city,i+1))
    s_list=sorted(s_list,key=lambda s_list: int(s_list[0]),reverse=True)
    s_list=sorted(s_list,key=lambda s_list: s_list[1])
    for i in s_list:
        print(i[2])

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

SP = {}
for i in range(N):
    s, p = input().split()
    if s in SP.keys():
        SP[s].append([int(p), i])
    else:
        SP[s] = [[int(p), i]]
    
SP = sorted(SP.items(), key=lambda x:x[0], reverse=False)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
dic = {}

for i in range(n):
    shop, ten = input().split()
    ten = int(ten)
    if shop in dic:
        dic[shop].append({i+1:ten})
    else:
        dic.update({shop: [{i+1:ten}]})


for k, v in sorted(dic.items()):
    d = {}
    for a in v:
        d.update(a)

    for a, b in sorted(d.items(), key=lambda x: -x[1]):
        print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

res = []
for i in range(1, n+1):
    si, pi = list(input().split())
    res.append([si, int(pi), i])
    
res.sort(key = lambda x: x[1], reverse=True)
#print(res)
res.sort(key = lambda x: x[0])
#print(res)

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

Submission status: Accepted

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

for index in range(N):
    S, strP = input().split()
    P = int(strP)
    if S in guideBook.keys():
        guideBook[S].setdefault(P,index+1)
    else:
        guideBook.setdefault(S,{P:(index+1)})

citylist = list(guideBook.keys())
citylist.sort()

for city in citylist:
    pointList = list(guideBook[city].keys())
    pointList.sort(reverse=True)
    for point in pointList:
        print(guideBook[city][point])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

def comp_rest(a,b):
    if a[0] > b[0]:
        return True
    elif a[0] < b[0]:
        return False
    elif a[0] == b[0]:
        return a[1] < b[1]

def solve():
    N = int(raw_input())
    SP = []
    for i in range(N):
        SiPi = raw_input().split()
        Si = SiPi[0]
        Pi = int(SiPi[1])
        SP.append([Si, Pi, i+1])
    for i in range(N):
        for j in range(i+1, N):
            if comp_rest(SP[i], SP[j]):
                SP[i], SP[j] = SP[j], SP[i]
    for i in range(N):
        print SP[i][2]

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# スペース区切りの整数の入力
N = int(input())


SP_list=[]

for i in range(N):
  S,P = map(str, input().split())
  SP_list.append([S,int(P),i+1])
  
SP_list.sort(key=lambda x:(x[0],-x[1]))

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

Submission status: Accepted

Solution code:
import math
import sys
sys.setrecursionlimit(10 ** 6 + 10)
from collections import defaultdict




def main():
    num = int(input())
    data = [input().split() for i in range(num)]

    for i in range(num):
        data[i][1] = int(data[i][1])
        data[i].append(i + 1)

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




if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
data = []
for i in range(n):
    name, review = input().split()
    data.append([name, int(review), i + 1])
copy = sorted(data, key=lambda x: -x[1])
copy.sort(key=lambda x: x[0])
for p in copy:
    print(p[2])

Submission status: Accepted

Solution code:
restrunt_num = int(input())

restrunt_list = []
for i in range(1, restrunt_num+1):
    city, point = input().split()
    restrunt_list.append([city, int(point), i])

sorted_list = sorted(restrunt_list, key=lambda x: (x[0], -x[1]))
for r in sorted_list:
    print(r[2])

Submission status: Accepted

Solution code:
n = int(input())
s, p = [], []
for _ in range(n):
    s_, p_ = input().split()
    s.append(s_)
    p.append(100 - int(p_))

max_len = max([len(e) for e in s])
s = [e.ljust(max_len, '0') for e in s]
p = [str(e).rjust(3, '0') for e in p]
m = [str(e).rjust(3, '0') for e in range(1, n+1)]

merged = [s[i]+p[i]+m[i] for i in range(n)]

merged.sort()

for i in range(n):
    print(int(merged[i][-3:]))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

for i in range(n):
    e[i][1]=(-1)*int(e[i][1])
for i in range(n):
    e[i]+=[i+1]
e.sort()
for i in range(n):
    print(e[i][2])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

for i in range(N):
    t = input().strip().split()
    
    S[i] = [t[0], int(t[1]), i]
    
S.sort(key = lambda x:(x[0], -x[1]))

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

Submission status: Accepted

Solution code:
import numpy as np
N= int(input())
s_list = []
p_list = []
for _ in range(N):
    s, p = input().split()
    s_list.append(s)
    p_list.append(int(p))

s_unique = list(set(s_list))
s_unique.sort()
for s in s_unique:
    ps = []
    indexs = [i for i,x in enumerate(s_list) if x==s]
    for index in indexs:
        ps.append(p_list[index])
    ps_sorted_index = np.argsort(ps)[::-1]
    for i in ps_sorted_index:
        print(indexs[i]+1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-


from sys import stdin



############################################

import numpy as np
# read data for n sequences.
a = int(stdin.readline().split()[0])
n = []
for i in range(a):
    write = stdin.readline().split()
    n.append([write[0],-int(write[1]),i])
#    b = str(n[0])
#    c = int(n[1])
#word = str(stdin.readline().split()[0])

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


for el in n2:
    print(el[2]+1)

Submission status: Accepted

Solution code:
# coding: utf-8
from operator import itemgetter
n = int(input())
data = []
for i in range(n):
    s, p = map(str, input().split())
    data.append([i+1, s, int(p)])
data = sorted(data, key=itemgetter(2), reverse=True)
data = sorted(data, key=itemgetter(1))
for j in range(n):
    print(data[j][0])

Submission status: Accepted

Solution code:
#  --*-coding:utf-8-*--

def main():
    N = int(input())
    SP = []
    for i in range(N):
        s, p = input().split()
        SP.append((s, -int(p), i+1))
            
    X = map(lambda x:str(x[2]), sorted(SP))
    print('\n'.join(X))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
dc = {}
for i in range(n):
    s, p= input().split()
    if s not in dc:
        dc[s] = []
        dc[s].append((i+1, int(p)))
    else:
        dc[s].append((i+1,int(p)))
dc = sorted(dc.items())
for k, v in dc:
    v.sort(key=itemgetter(1), reverse=True)
    for i in range(len(v)):
        print(v[0][0])
        v.pop(0)

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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

l=[[] for i in range(n)]
from operator import itemgetter
sp.sort(key=itemgetter(1))
sp.reverse()
sp.sort(key=itemgetter(0))

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

Submission status: Accepted

Solution code:
N = int(input())
list = []
for i in range(N):
  r = input().split()
  list.append((r[0], 100-int(r[1]), i+1))
list.sort()
for i in range(N):
  print(list[i][2])