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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

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

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

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

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

    return 0

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

    solve()

# vim: set foldmethod=marker:}}}

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 2019/05/26
# AtCoder Beginner Contest 128 - B

from operator import itemgetter

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

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

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

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)])
    
from operator import itemgetter

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

Submission status: Accepted

Solution code:
from operator import itemgetter


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


main()

Submission status: Accepted

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

n = int(input())

a = []

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

Submission status: Accepted

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

plist = []

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def f(s):
    return s

N=int(input())
a=[list(map(f,input().split()))+[i] for i in range(N)]
for i in range(N):
    a[i][1]=100-int(a[i][1])
a.sort()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

res = []

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

res.sort()

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

Submission status: Accepted

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

from operator import itemgetter

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

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

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

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

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

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


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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

Solution code:
import sys

fin = sys.stdin.readline

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())

lc = []
l = []

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from functools import cmp_to_key

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
_ = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict


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


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

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

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

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()
for e in l:
    print(e[2])

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter
import sys
input = sys.stdin.readline

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


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


def main():

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

for i in A:
    print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
from operator import itemgetter
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
SP = []

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

sp = sorted(SP,key=itemgetter(1),reverse=True)
sp = sorted(sp,key=itemgetter(0))

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

Submission status: Accepted

Solution code:
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

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

N = i_inpl()
D = []
for i in range(N):
    si, pi = input().split()
    D.append([si, int(pi), i+1])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]


N = int(input())

restaurants = []

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

    restaurants.append(
        {
            'S': S,
            'P': P,
            'number': i + 1
        }
    )

restaurants.sort(key=lambda x: (x['S'], -int(x['P'])))

for res in restaurants:
    print(res['number'])

Submission status: Accepted

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

import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

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

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

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline

N = int(readline())

SP = [readline().split() for i in range(N)]
iSP = [(i, s, int(p)) for i,(s,p) in enumerate(SP)]

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

for i,s,p in iSP:
    print(i + 1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
N = int(input())
SP = []
for i in range(N):
    S, P = input().split()
    P = int(P)
    SP.append([S,P,i+1])
SP.sort(key=lambda x: x[0]+("%03d" % (100-x[1])))
for S, P, i in SP:
    print(i)

Submission status: Accepted

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

rest=sorted(rest,key=lambda x: x[2],reverse=True)
rest=sorted(rest,key=lambda x: x[1])

for a,b,c in rest:
    print(a)

Submission status: Accepted

Solution code:
N = input()

arr = []

for i in xrange(N):
    A,B = raw_input().split()
    B = int(B)
    arr.append([A,B,i+1])


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

for i in xrange(N):
    print arr[i][2]

Submission status: Accepted

Solution code:
N = int(input())
dict = {}
for i in range(1,N+1):
    s,p = input().split()
    pt = int(p)
    if s in dict:
        dict[s].append((pt,i))
    else:
        dict[s] = [(pt,i)]
for key in dict:
    dict[key].sort(key = lambda x: -x[0])
    # print(key,dict[key])
d = list(dict)
d.sort()
# print(d)
for town in d:
    for p,id in dict[town]:
        print(id)

Submission status: Accepted

Solution code:
N=int(input())
rest={}
for i in range(N):
    S,P=input().split(" ")
    P=int(P)
    tmp=rest.get(S,[])
    tmp.append((P,i+1))
    rest[S]=tmp
for key in sorted(rest.keys()):
    Rs=rest[key]
    for s in sorted(Rs,reverse=True):
        print(s[1])

Submission status: Accepted

Solution code:
N = int(input())
restrant = []
for i in range(N):
    name, p = input().split()
    p = str(200 - int(p))
    restrant.append([name+p, i+1])
restrant.sort(key=lambda x:x[0])
for r in restrant:
    print(r[1])

Submission status: Accepted

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

Submission status: Accepted

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

cities = {sp[0] for sp in SP}
cities = sorted(list(cities))
points = sorted([sp[1] for sp in SP], reverse=True)

for c in cities:
    for p in points:
        tpl = (c, p)
        if tpl in SP:
            print(SP.index(tpl) + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
from collections import defaultdict
from functools import reduce

# s = input()
n = int(input())
# A = list(map(int, input().split()))

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

for k in sorted(cites.keys()):
    [ print(i[1]) for i in sorted(cites[k], reverse=True)]

Submission status: Accepted

Solution code:
n = int(input())

r = []

for i in range(n):
    city, score = input().split()
    score = int(score)
    r.append((i + 1, city, score))

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

for i in range(n):
    print(r[i][0])

Submission status: Accepted

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

Submission status: Accepted

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