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:
def main():
    n = int(input())
    restaurants = []

    for _ in range(n):
        city, point = input().split()
        restaurants.append((city, int(point)))
    
    for r in sorted(range(1, 1 + n), key=lambda i: (restaurants[i-1][0], -restaurants[i-1][1])):
        print(r)

main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, S: "List[str]", P: "List[int]"):
    SP =[]
    for i in range(N):
        SP.append([S[i],P[i]])

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

    # print(t)

    ans = []
    for x in t:
        for j in range(N):
            x1,x2 = x
            if(x1 == S[j] and x2 == P[j]):
                ans.append(j+1)


    for i in ans:
        print(i)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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())
ns = []
for i in range(N):
    n, s = input().split()
    ns.append([n, int(s)])
    ns[i].append(i+1)
ns.sort(reverse=True, key=lambda x:x[1])
ns.sort(key=lambda x:x[0])
[print(x[2]) for x in ns]

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 26 21:06:51 2019

@author: aono
"""

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

for i in range(N):
    city, p = input().split()
    info.append([city, int(p), i])

info.sort(key=lambda x: x[1])
info.reverse()
info.sort(key=lambda x: x[0])

for i in range(len(info)):
    print(info[i][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 + 1])
r = sorted(r, key=lambda x: x[1], reverse=True)
r = sorted(r, key=lambda x: x[0])
for i in r:
    print(i[2])

Submission status: Accepted

Solution code:
N = int(input())
S_P = []
for i in range(N):
    S , P = input().split()
    S_P.append([ S , int(P) , i])
S_P.sort( key = lambda x : x[0] )
state = S_P[0][0]
S_P_sort = []
temp = []
for S , P , i in S_P:
    if S != state:
        temp.sort( key = lambda x : x[1] , reverse = True)
        S_P_sort.extend(temp)
        state = S
        temp = []
        temp.append([S , P, i])
    else:
        temp.append([S , P, i])
temp.sort( key = lambda x : x[1] , reverse = True)
S_P_sort.extend(temp)
for j in range(N):
    print(S_P_sort[j][2]+1)

Submission status: Accepted

Solution code:
N=int(input())
c=[]
for i in range(N):
    city,point=input().split()
    c.append([city,int(point),i+1])
    c.sort(key=lambda c:c[1],reverse=True)
    c.sort(key=lambda c:c[0])
for i in range(N):
    c[i].append(i)
c.sort(key=lambda c:c[3])
for i in range(N):
    print(c[i][2])

Submission status: Accepted

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

SP.sort(key=lambda x: int(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:
from operator import attrgetter

class Rest:
    def __init__(self, city, point, index):
        self.city = city
        self.point = point
        self.index = index + 1


def main():
    N = int(input())
    restList = []
    for index in range(N):
        SP = input().split()
        city = SP[0]
        point = int(SP[1])
        restList.append(Rest(city, point, index))

    restList = sorted(restList, key=attrgetter("city"))
    citylistlist = []
    dummylist = [Rest("dummydummydummy",0,1000)]
    citylistlist.append(dummylist)
    for rest in restList:
        if citylistlist[-1][-1].city == rest.city:
            citylistlist[-1].append(rest)
        else:
            citylistlist.append([rest])
    citylistlist.pop(0)


    truelist = []
    for lis in citylistlist:
        truelist = truelist + sorted(lis, key=attrgetter("point"), reverse=True)

    for rest in truelist:
        print(rest.index)



main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
source = []
for i in range(int(input())):
    name, score = input().split(" ")
    source.append([i+1, name, 100-int(score)])
[print(i[0]) for i in sorted(source, key=lambda x: (x[1], x[2]))]

Submission status: Accepted

Solution code:
N = int(input())

S = []
for i in range(N):
    S.append(list(map(str,input().split())))

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

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

for c in C:
    print(c[2])

Submission status: Accepted

Solution code:
n = int(input())
lis = []
li = []
l = []
cou = 0
for i in range(n):
  a,b = map(str,input().split())
  if a not in li:
    lis.append([[int(b),i+1]])
    li.append(a)
    l.append([a,cou])
    cou += 1
  else:
    lis[li.index(a)].append([int(b),i+1])
l.sort()
for i in range(len(l)):
  lis[l[i][1]].sort(reverse=True)
  for num,nu in lis[l[i][1]]:
    print(int(nu))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

from functools import lru_cache
#@lru_cache(maxsize = None)

# 整数の入力
n = int(input())

# スペース区切りの整数の入力
#a = [x for x in map(int, input().split())]
#a, p = map(int, input().split())
#print(n, q, file=sys.stderr)

# 改行区切りの整数の入力
#a = []
#for x in range(n):
#  a.append(int(input()))

# 文字列の入力
#s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()


def doit():
  rs = {}
  for x in range(n):
    s, p = input().split()
    p = int(p)
    #print(s, p, file=sys.stderr)
    if not s in rs:
      rs[s] = {}
    rs[s][p] = x + 1
  #print(rs, file=sys.stderr)
    
  slist = sorted(rs)
  for x in slist:
    for y in sorted(rs[x].items(), reverse=True):
      print(y[1])

try:
#  print ((a * 3 + p) // 2)
  doit()
except Exception as e:
  print(e, file=sys.stderr)

Submission status: Accepted

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

tmp = []
for i,sp in enumerate(sp_list,1):
    tmp.append([i,sp[0],int(sp[1])])

sp_list1 = sorted(tmp, key=lambda x: x[2], reverse=True)
sp_list2 = sorted(sp_list1, key=lambda x: x[1], reverse=False)

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

Submission status: Accepted

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

guidebook = {}
for i in range(n):
    s, p = input().split()
    p = int(p)

    if s in guidebook:
        guidebook[s].append((p, i+1))
    else:
        guidebook[s] = [(p, i+1)]

for city in sorted(guidebook.items(), key=lambda x: x[0]):
    for p, i in sorted(city[1], reverse=True):
        print(i)

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
base_list = []
for i in range(n):
  name, point = input().split()
  base_list.append((name, -int(point), i+1))
sorted_list = sorted(base_list, key=itemgetter(0, 1))
for i in range(n):
  print(sorted_list[i][2])

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())

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

L.sort()
j = 0
p = L[0][0]
ans = [[] for _ in range(N)]
for i in range(N):
    if L[i][0] == p:
        ans[j].append([L[i][1], L[i][2]])
    else:
        j += 1
        p = L[i][0]
        ans[j].append([L[i][1], L[i][2]])


for i in range(j+1):
    z = sorted(ans[i], reverse=True)
    [print(j[1]) for j in z]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

sps = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    sps.append({
        "city": s,
        "score": p,
        "index": i
    })
# sps.sort()

cities = {}
for sp in sps:
    if not sp["city"] in cities:
        cities[sp["city"]] = []
    cities[sp["city"]].append(sp)

# [v.sort() for k, v in cities.items()]
rest_sorted_cities = {}
for k, v in cities.items():
    rest_sorted_cities[k] = sorted(v, key=lambda x:x["score"], reverse=True)

sorted_cities = sorted(rest_sorted_cities.items(), key=lambda x: x[0])

for k, city in sorted_cities:
    [print(rest["index"] + 1) for rest in city]

Submission status: Accepted

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

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

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

for s in S:
  print(s[0])

Submission status: Accepted

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

Submission status: Accepted

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

li_a = sorted(li, key=lambda x:x[1], reverse=True)
li_b = sorted(li_a, key=lambda x:x[0])

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

Submission status: Accepted

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

data=[{"city":data[i][0],"score":int(data[i][1]),"number":i+1} for i in range(N)]

data.sort(key=lambda x: x['score'],reverse=True)
data.sort(key=lambda x: x['city'])


for i in [i["number"] for i in data]:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter
i = int(input())

data = []

def chg(x,y):
	print("hoge")
	if x[0] == y[0]:
		return x[1] > y[1]
	else:
		return x[0] > y[0]

for i in range(i):
	ip = input().split(' ')
	dt = [ip[0],int(ip[1])]
	data.append(dt)


ls = sorted(data,key=itemgetter(1),reverse=True)
ls = sorted(ls,key=itemgetter(0))

for i in ls:
	cnt = 0
	for j in data:
		if i == j:
			break
		cnt += 1
	
	print(cnt + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
page=[]
for i in range(n):
    s,p=input().split()
    page.append((s,i+1,int(p)))
page.sort()
#print(page)
gen=page[0][0]
i=0
while i<n:
    town=[]
    while i!=n:
        #print("i="+str(i))
        if gen!=page[i][0]:
            break
        town.append(page[i])
        i+=1
    for j in range(len(town)):
        town[j]=town[j][::-1]
    town.sort(reverse=True)
    #print(town)
    for j in range(len(town)):
        print(town[j][1])
    
    if i!=n:gen=page[i][0]
    #print(gen)

Submission status: Accepted

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

l.sort(key = lambda x: x[0])
tmp_list, tmp_string = [[l[0][1], l[0][2]]], l[0][0]
for i in range(1, N):
    if tmp_string == l[i][0]:
        tmp_list.append([l[i][1], l[i][2]])
    else:
        tmp_list.sort(key = lambda x: x[0], reverse = True)
        for x in tmp_list:
            print(x[1]+1)
        tmp_string = l[i][0]
        tmp_list = [[l[i][1], l[i][2]]]

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

Submission status: Accepted

Solution code:
N = int(input())
rest = []
for k in range(N):
    i, j = map(str, input().split())
    rest.append([i, int(j), k+1])


rest.sort(key=lambda x: x[1])
rest.reverse()
rest.sort(key=lambda y: y[0])

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

Submission status: Accepted

Solution code:
from collections import OrderedDict
from sys import stdin
N = int(stdin.readline().rstrip())
SP = {} 
_P = []
for i in range(N):
    s, p = stdin.readline().rstrip().split()
    _P.append(int(p))
    if s in SP:
        SP[s].append(int(p))
    else:
        SP[s] = [int(p)]
for v in SP.values():
    v.sort(reverse=True)
SP = OrderedDict(sorted(SP.items()))
for k, V in SP.items():
    for v in V:
        print(_P.index(v)+1)

Submission status: Accepted

Solution code:
n = int(input())

book = [list(input().split()) for i in range(n)]
for i in range(n):
    book[i] += [i+1]
    book[i][1] = -1 * int(book[i][1])
book.sort()
for b in book:
    print(b[2])

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[24]:


import sys
#import numpy as np
input = sys.stdin.readline
N = int(input())
l = [input().split()+[i+1] for i in range(N)]


# In[25]:


sl = sorted(l, key=lambda x:int(x[1]), reverse=True)
sl = sorted(sl, key=lambda x:x[0])
#print(sl)
for i in range(N):
    print(sl[i][2])


# In[ ]:


"""
10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
"""

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
N = int(input())
guide_dic = {}
num_i_dic = {}
for _ in range(N):
    S,P = input().split()
    num_i_dic[int(P)] = _+1
    try:
        bisect.insort(guide_dic[S],int(P))
    except KeyError:
        guide_dic[S] = []
        bisect.insort(guide_dic[S],int(P))

for name,score in sorted(guide_dic.items()):
    for _ in score[::-1]:
        print(num_i_dic[_])

Submission status: Accepted

Solution code:
n = int(input())
sp = [list(input().split())+[i] for i in range(1,n+1)]
for i in range(n):
	sp[i][1] = int(sp[i][1])
sp.sort(key=lambda x:(x[0],x[1]))
# print(sp)
# sp.sort()
ans = []
sp.append(['hoge000'])
for i in range(n):
	if sp[i][0] == sp[i+1][0]:
		ans.append(sp[i])
		continue
	else:
		if len(ans):
			print(sp[i][2])
			for a in ans[::-1]:
				print(a[2])
			ans = []
			continue
		else:
			print(sp[i][2])

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())

S =[]
P = []
for i in range (N):
    s,p1 = [k for k in input().split()]
    p = 100-int(p1)
    
    S.append(s)
    P.append(p)

ls =[i for i in range (1,N+1)]
total = list(zip(S,P,ls))


total.sort()


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

Submission status: Accepted

Solution code:
N = int(input())

# {city1 : {(p1, n1), ...},...}
d = {}

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

  if S not in d:
    d[S] = {P: n+1}
  else:
    d[S][P] = n+1

keys = d.keys()
keys = list(keys)
keys.sort()

for k in keys:
  lis = d[k]
  
  ks = list(lis.keys())
  ks.sort()
  ks.reverse()
  for t in ks:
    print(lis[t])

Submission status: Accepted

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

for j in range(n):
    print(x[j][2]+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
dat=[]
for i in range(N):
  inp = input().split()
  dat.append([inp[0],int(inp[1]),i+1])
dat.sort()
for i in range(N):
  dat[i]=[dat[i][1],dat[i][0],dat[i][2]]

#print(dat)
res=[dat[0]]
for i in range(N-1):
  j=i+1
  if dat[j][1]==dat[j-1][1]:
    res.append(dat[j])
  else:
    res.sort(reverse=True)
    for k in range(len(res)):
    	print(res[k][2])
    res=[dat[j]]

res.sort(reverse=True)
for k in range(len(res)):
	print(res[k][2])

Submission status: Accepted

Solution code:
N = int(input())
Ss = []
for i in range(N):
    k = input().split(" ")
    Ss.append((i+1, k[0], k[1]))

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

Submission status: Accepted

Solution code:
import sys
inputs=[[int(i) if i.isnumeric() else i for i in l.split()] for l in sys.stdin.readlines()][1:]
s_i=sorted(inputs,key=lambda x: (x[0],-x[1]))
for r in s_i:
    for n,i in enumerate(inputs):
        if r==i:
            print(n+1)

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import *
from functools import *
from itertools import *

def main():
    n = int(input())
    #a, p = map(int, input().split())
    #xs = list(map(int, input().split()))
    xs = [ input().split() for _ in range(n) ]
    xs = [ (a[0], int(a[1])) for a in xs ]
    def cmp(a, b):
        if a[0] > b[0]:
            return 1
        if a[0] < b[0]:
            return -1
        return b[1] - a[1]
    xs = [ (x[0], x[1], i+1) for i, x in enumerate(xs) ]
    xs.sort(key=cmp_to_key(cmp))
    for s, p, i in xs:
        print(i)
        pass
    pass


if __name__ == "__main__":
    main()
    pass

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
for i in range(n):
    s, p = input().split()
    p = int(p)
    if s in dic:
        dic[s].append(p*101 + i+1)
        dic[s].sort()
        dic[s].reverse()
    else:
        dic[s] = []
        dic[s].append(p*101 + i+1)

dic_sorted = sorted(dic.items(), key = lambda x:x[0])

for tmp in dic_sorted:
    for i in range(len(tmp[1])):
        print(tmp[1][i] % 101)

Submission status: Accepted

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

for i in range(n):
	s,p = input().split()
	a = {"i":i+1,"s":s,"p":int(p)}
	arr.append(a)

arr = sorted(arr, key=lambda x:x["p"], reverse=True)
#print(arr)
arr = sorted(arr, key=lambda x:x["s"])

for a in arr:
	print(a["i"])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    arr = []
    for i in range(1, n + 1):
        inp = input().split(' ')
        arr.append({'n': int(i), 's': inp[0], 'p': int(inp[1])})
    _sorted = sorted(arr, key = lambda x: (x['s'], -x['p']))
    for item in _sorted:
        print(item['n'])

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

Submission status: Accepted

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

SP2 = sorted(sorted(SP, key=lambda x:int(x[2]), reverse=True), key=lambda x:x[1])

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

Submission status: Accepted

Solution code:
N = int(input())

S = []
P = []
for i in range(N):
    sp = input().split()
    S.append(sp[0])
    P.append(int(sp[1]))

SP = list(zip(range(1,N+1),S,P))

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

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

Submission status: Accepted

Solution code:
N = int(input())
dict = []
for i in range(N):
    line = input().split()
    S = line[0]
    P = int(line[1])
    dict.append({"id": i+1, "S":S, "P":P})

dict = sorted(dict, key=lambda x:(x["S"],-x["P"]))

for d in dict:
    print(d["id"])

Submission status: Accepted

Solution code:
N = int(input())

ls = []

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

SP.sort()
city = SP[0][0]
tmp = [[int(SP[0][1]), SP[0][2]]]
for i in range(0, N - 1):
    if SP[i + 1][0] == city:
        tmp.append([int(SP[i + 1][1]), SP[i + 1][2]])
    else:
        tmp.sort()
        tmp.reverse()
        for j in range(len(tmp)):
            print(tmp[j][1])
        tmp = [[int(SP[i + 1][1]), SP[i + 1][2]]]
        city = SP[i + 1][0]
tmp.sort()
tmp.reverse()
for j in range(len(tmp)):
    print(tmp[j][1])

Submission status: Accepted

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

for i in range(N):
    lst[i][2] = int(lst[i][2])

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

for j in range(N):
    print(lst[j][0])

Submission status: Accepted

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

li2 = li.copy()
li.sort()
for l in li:
    print(li2.index(l)+1)

Submission status: Accepted

Solution code:
number = int(input())
i = 1
l = list()
while i <= number:
  k,v = input().split()
  l.append((k,int(v),i))
  i += 1
# print(l)
sorted_list = sorted(l, key=lambda s:s[1], reverse=True)
sorted_list2 = sorted(sorted_list, key=lambda s:s[0])
#print(sorted_list2)
for k in sorted_list2:
  print(k[2])

Submission status: Accepted

Solution code:
from operator import itemgetter

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

Submission status: Accepted

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

from operator import itemgetter

N = int(input())
SP_list = []
SP_dict = {}
for i in range(N):
    name, point = input().split()
    pair = (name, int(point))
    SP_list.append(pair)
    SP_dict[pair] = i + 1

for i in range(len(SP_list)):
    SP_dict[SP_list[i]] = i + 1

point_sorted = sorted(SP_list, key=itemgetter(1), reverse=True)
name_sorted = sorted(point_sorted, key=itemgetter(0))

for pair in name_sorted:
    print (SP_dict[pair])

Submission status: Accepted

Solution code:
N = int(input())

into = []
for i in range(1, N+1):
    res, sc_str = [x for x in input().split()]
    sc = int(sc_str)

    into.append((i, res, sc))

from operator import itemgetter

sorted_into = sorted(into, key=lambda x:(x[1],-x[2]))

for z in  sorted_into:
    print(z[0])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from operator import itemgetter
n = int(input())
isp=[]
for i in range(n):
  s,p= input().split()
  isp.append([i+1, s, int(p)])
isp.sort(key=itemgetter(2))
isp.reverse()  
isp.sort(key=itemgetter(1))
for st in isp:
  print(st[0])

Submission status: Accepted

Solution code:
N=int(input())
rest_list = []
for i in range(N):
  Si, Pi = input().split()
  Pi = int(Pi)
  rest_list.append((i+1,Si,Pi))
  
for i in range(N-1):
  for j in range(i+1,N):
    ii,Si,Pi = rest_list[i]
    jj,Sj,Pj = rest_list[j]
    
    if Si > Sj or (Si == Sj and Pi < Pj):
      rest_list[i], rest_list[j] = (jj,Sj,Pj),(ii,Si,Pi)
      
for i in range(N):
  i,Si,Pi = rest_list[i]  
  print(i)

Submission status: Accepted

Solution code:
n=int(input())
l=[input().split() for i in range(n)]
l=[[x[0],int(x[1])] for x in l]
sorted_l=sorted([[x[0],-1*x[1]] for x in l]
                ,key=lambda x:(x[0],x[1]))

sorted_l=[[x[0],-1*int(x[1])] for x in sorted_l]

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

Submission status: Accepted

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


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

restaurants.sort(key=lambda x: x.p, reverse=True)
restaurants.sort(key=lambda x: x.s)

for r in restaurants:
    print(r.i)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
from operator import itemgetter
n=int(input())
l=[]
for i in range(n):
    a,b=map(str,input().split(" "))
    l.append((a,int(b),i+1))

c=sorted(l,key=itemgetter(1),reverse=True)
d=sorted(c,key=itemgetter(0))
for i in range(n):
    print(d[i][2])

Submission status: Accepted

Solution code:
N = int(input())
d = {}
for n in range(N):
    c, v = input().split()
    v = int(v)
    if c in  d:
        d[c] = d[c]+[(v, n+1)]
    else:
        d[c] = [(v, n+1)]
d = sorted(d.items())
for c in d:
    for v in sorted(c[1], reverse=True):
        print(v[1])

Submission status: Accepted

Solution code:

def input_from_console():
    n = int(input().rstrip())

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


def solve(n, s_list):

    final_order = []
    city_list = set([item[1] for item in s_list])
    city_list_sorted = sorted(city_list)
    for city in city_list_sorted:
        ranked_list = [item for item in s_list if item[1] == city]
        final_order.extend([item[0] for item in sorted(ranked_list, key=lambda x: x[2], reverse=True)])
    return '\n'.join(map(str, final_order))


def main():
    n, s_list = input_from_console()
    print(solve(n, s_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Accepted

Solution code:
n = int(input())
sp = [input().split() for _ in range(n)]
d = {}
for idx,(s,p) in enumerate(sp):
  if s in d.keys():
    d[s].append([int(p),idx])
  else:
    d[s] = [[int(p),idx]]

for key in sorted(d.keys()):
  for v in sorted(d[key])[::-1]:
    print(v[1]+1)

Submission status: Accepted

Solution code:
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N = int(input())
S = [0]*N
P = [0]*N
Dic = []
for i in range(N):
    S[i], P[i] = input().split()
   
for i in range(N):
    Dic.append([S[i], int(P[i]), i+1])

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

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

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    N = int(input())
    SP = [tuple(input().split()) for _ in [0] * N]

    sp = [(i, s, int(p)) for i, (s, p) in enumerate(SP, start=1)]
    sp.sort(key=lambda x: x[2], reverse=1)
    sp.sort(key=lambda x: x[1])
    for i, s, p in sp:
        print(i)

input = lambda: stdin.readline()
main()

Submission status: Accepted

Solution code:
n = int(input())

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

for s, points in sorted(restaurants.items(), key=lambda x: x[0]):
    for p, i in sorted(points,key=lambda x: x[0], reverse=True):
        print(i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter, attrgetter
n = int(input())
sp = [[i+1] + list(input().split()) for i in range(n)]

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

Submission status: Accepted

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

restaurant_dict = defaultdict(list)

for i in range(n):
  name, score = input().split()
  restaurant_dict[name].append((i+1, int(score)))
  
for n, t in sorted(restaurant_dict.items()):
  for s in sorted(t, key=lambda tup: tup[1], reverse=True):
    print(s[0])