Problem:


Score : 200 points

Problem Statement

You have decided to write a book introducing good restaurants.
There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i.
No two restaurants have the same score.

You want to introduce the restaurants in the following order:

The restaurants are arranged in lexicographical order of the names of their cities.

If there are multiple restaurants in the same city, they are arranged in descending order of score.

Print the identification numbers of the restaurants in the order they are introduced in the book.

Constraints

1 ≤ N ≤ 100

S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

0 ≤ P_i ≤ 100

P_i is an integer.

P_i ≠ P_j (1 ≤ i < j ≤ N)

Input

Input is given from Standard Input in the following format:

N
S_1 P_1
:
S_N P_N

Output

Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.

Sample Input 1

6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40

Sample Output 1

3
4
6
1
5
2

The lexicographical order of the names of the three cities is kazan < khabarovsk < moscow. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,2.

Sample Input 2

10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100

Sample Output 2

10
9
8
7
6
5
4
3
2
1



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


Sample output:
3
4
6
1
5
2

Submission status: Accepted

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

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

for shop in shops:
    print(shop[2])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N=int(input())
restaurant=[]
for i in range(N):
    s,p=input().split()
    restaurant.append((i+1,s,int(p)))
restaurant.sort(key=lambda x:(x[1],-x[2]))
for j in range(N):
    print(restaurant[j][0])

Submission status: Accepted

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

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.sort()
for s,p,i in list:
  print(i)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
	n = int(input().strip())
	res = []
	for i in range(n):
		S, P = input().strip().split()
		res.append((S, int(P), i+1))
	res_sed = sorted(res, key=lambda tup: tup[1], reverse=True)
	res_ans = sorted(res_sed, key=lambda tup: tup[0])
	for tup in res_ans:
		print(tup[2])

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())
l = [input().split() for x in range(n)]

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

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

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

Submission status: Accepted

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

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

for i in range(N):
  for j in range(N):
    if sorted_SP[i][0] == SP[j][0] and sorted_SP[i][1] == SP[j][1]:
      print(j+1)
      break

Submission status: Accepted

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

def main():
	n = int(input().strip())
	res = []
	for i in range(n):
		S, P = input().strip().split()
		res.append((S, int(P), i+1))
	res_sed = sorted(res, key=itemgetter(1), reverse=True)
	res_ans = sorted(res_sed, key=itemgetter(0))
	for tup in res_ans:
		print(tup[2])

if __name__ == '__main__':
	main()

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

B = sorted(A, key=lambda x:x[2],reverse=True)
C = sorted(B, key=lambda x:x[1])
for c in C:
    print(c[0])

Submission status: Accepted

Solution code:
from itertools import groupby

n = int(input())
dic = []
for i in range(n):
    (c, r) = input().split(" ")
    dic.append({"index": i+1, "city": c, "rating": int(r)})

std_dic= sorted(dic, key=lambda x:x['city'])
grp_dic = groupby(std_dic, key=lambda x:x["city"])
result = []
for key, group in grp_dic:
    # print(key, list(group))
    for s in sorted(group, key=lambda x:x["rating"], reverse=True):
        result.append(s)

for r in result:
    print(r["index"])

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    restaurants = []
    for i, s in enumerate(inputs):
        s = s.split()
        restaurants.append((i+1, s[0], int(s[1])))
    restaurants.sort(key=lambda x: x[2], reverse=True)
    restaurants.sort(key=lambda x: x[1])

    ret = list(map(lambda r: r[0], restaurants))

    return ret


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [N] = string_to_int(input())
    ret = solve(inputs(N))
    # print(ret)

    for r in ret:
        print(r)

Submission status: Accepted

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


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

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

Submission status: Accepted

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


# sort on secondary key
s = sorted(SP, key=lambda x: (x[0], -x[1]))
# now sort on primary key, descending
#sorted(s, key=attrgetter('grade'), reverse=True)

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
d = defaultdict(list)
h = {}
for i in range(n):
    m = list(input().split())
    d[m[0]].append(int(m[1]))
    h[int(m[1])] = i +1
l = sorted(d)
j = sorted(h, reverse = True)
for word in l:
    for num in j:
        if num in d[word]:
            print(h[num])

Submission status: Accepted

Solution code:
import numpy as np

class Restaurant:
    def __init__(self, index, city, point):
        self.index = index
        self.city = city
        self.point = int(point)

N = int(input())
restaurant_dict = {}
S, P = [], []
for i in range(N):
    s, p = [x for x in input().split()]
    if not s in restaurant_dict:
        restaurant_dict[s] = [Restaurant(i + 1, s, p)]
    else:
        restaurant_dict[s].append(Restaurant(i + 1, s, p))
    if not s in S:
        S.append(s)
    # P.append(int(p))
    # restaurant_dict.append(Restaurant(i, s, p))
for s in sorted(S):
    scores = np.array([rest.point for rest in restaurant_dict[s]])
    index = scores.argsort()
    index = index.tolist()
    for ind in reversed(index):
        # print(restaurant_dict[s][ind].city)
        print(restaurant_dict[s][ind].index)
        # print(restaurant_dict[s][ind].point)

Submission status: Accepted

Solution code:
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def to_isp(i, s):
    sp = s.split(' ')
    return (i+1, sp[0], int(sp[1]))

def main():
    N = i2n()
    SP = [to_isp(i, s) for i, s in enumerate(ii2ss(N))]
    SP.sort(key=lambda v: v[2])
    SP.reverse()
    SP.sort(key=lambda v: v[1])
    for i, s, p in SP:
        print(i)

main()

Submission status: Accepted

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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

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

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

L = sorted(L)

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

Submission status: Accepted

Solution code:
N = int(input())
SPs = []
for i in range(N):
  l = input()
  ws = l.split()
  S = ws[0]
  P = int(ws[1])
  SPs.append([S, P])
#print(SPs)
a = list(range(1, N+1))
a.sort(key = lambda i: [SPs[i-1][0], -SPs[i-1][1]])
#print(a)
for i in range(N):
  print(a[i])

Submission status: Accepted

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

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

idx_list = range(len(lst))
idx_sorted = sorted(idx_list, key=lambda x: (lst[x][0], -lst[x][1]))

for idx in idx_sorted:
    print(idx+1)

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(list)
n = int(input())
for i in range(n):
    city, point = input().split()
    d[city].append((int(point), i+1))

d2 = sorted(d.items())
for i in range(len(d2)):
    d2[i] = list(d2[i])
    d2[i][1] = sorted((d2[i][1]), reverse = True)
    for j in range(len(d2[i][1])):
        print(d2[i][1][j][1])

Submission status: Accepted

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

mise1 = sorted(mise,key=lambda x:(x[1],-x[2]))

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

Submission status: Accepted

Solution code:
a = int(input())
c = list()
for b in range(a):
  z, zz = input().split()
  c.append([z,int(zz)]) 

l = list()
tmp = sorted(c, key=lambda x:x[1], reverse=True)
x = sorted(tmp, key=lambda x:x[0])
for a in x:
  for y in c:
    if (a == y):
      l.append(c.index(a)+1)
[print(i) for i in l]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy

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

calSP = copy.deepcopy(SP)
calSP = sorted(calSP, key=lambda x:(x[2]), reverse=True)
ss = sorted(ss)
num = 1
for sss in ss:
    for cal in calSP:
        if cal[1] == sss:
            cal.append(num)
            num += 1
calSP = sorted(calSP, key=lambda x:(x[3]))
for cal in calSP:
    print(cal[0])

Submission status: Accepted

Solution code:
#n, x = map(int,input().split())
n = int(input())
ls = [["",[[]]]]
for i in range(n):
  s, p = input().split()
  for j in ls:
    if s == j[0]:
      j[1].append([i+1,int(p)])
      break
    elif j == ls[-1]:
      ls.append([s,[[i+1,int(p)]]])
      break
#ls = list(map(int,input().split()))
#s = input()
ls.remove(ls[0])
ls.sort()
for i in ls:
  i[1].sort(key=lambda x: x[1],reverse=True)
  for j in i[1]:
    print(j[0])

Submission status: Accepted

Solution code:
N = int(input())
town_names = dict()
assessments = []
for x in range(N):
  if x!=N:
    SP = input().split()
    assessments.append(SP[1])
    town_names.setdefault(SP[0],[]).append(assessments.index(SP[1])+1)
  else:
    break
result = []
for t in sorted(town_names):
  tmp = []
  for pointer in town_names[t]:
    tmp.append(assessments[pointer-1])
  for x in sorted(tmp, reverse=True,key=int):
    result.append(assessments.index(x)+1)
  tmp = []
for x in result:
  print(x)

Submission status: Accepted

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

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

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

for v in isp:
    print(v[0])

Submission status: Accepted

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

for i in range(n):
    name, score = map(str, input().split())
    shop_list.append([i+1, name, int(score)])

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

for shop_info in shop_list:
    print(shop_info[0])

Submission status: Accepted

Solution code:
#あなたは美味しいレストランを紹介する本を書くことにしました。 
#あなたは N 個のレストラン、レストラン 1、レストラン 2、…、レストラン N を紹介しようとしています。
#レストラン i は Si 市にあり、あなたは 100 点満点中 Pi 点と評価しています。
#異なる 2 個のレストランに同じ点数がついていることはありません。
#この本では、次のような順でレストランを紹介しようとしています。
#市名が辞書順で早いものから紹介していく。
#同じ市に複数レストランがある場合は、点数が高いものから紹介していく。
#この本で紹介される順にレストランの番号を出力してください

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

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

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

Submission status: Accepted

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

que=[]
prev_rest=sp[0][0]
for i in range(n):
    if prev_rest != sp[i][0]:
        que=sorted(que,key=lambda x:(x[0],x[1]))
        for j in range(len(que)):
            ans_list=que.pop()
            print(ans_list[2])
    que.append(sp[i])
    prev_rest = sp[i][0]
que=sorted(que,key=lambda x:(x[0],x[1]))
for j in range(len(que)):
    ans_list=que.pop()
    print(ans_list[2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

def index_Multi(List,liter):
    index_L = []
    for val in range(0,len(List)):
        if liter == List[val]:
            index_L.append(val)
    return index_L

for i in sorted(set(S)):
    indexes = index_Multi(S, i)
    L = []
    d = {}
    for j in indexes:
        d[j+1] = P[j]
    d = sorted(d.items(), key=lambda x:x[1], reverse=True)
    for k in d:
        print(k[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
res_list = [None] * N
for i in range(N):
  city, point = input().split()
  point = int(point)
  res_list[i] = (city, - point, i + 1)
for res in sorted(res_list):
  print(res[2])

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

ans = [i[2] for i in data]
for i in ans: print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
myList = []
for i in range(N):
    S,P = input().split()
    myList.append([S,int(P),i+1])
myList = sorted(myList)
while len(myList)!=0:
    n = myList[0][0]
    tmp = []
    while len(myList)!=0:
        if myList[0][0] == n :
            d = myList.pop(0)
            tmp.append([d[1],d[2]])
        else :
            break
    tmp = sorted(tmp,reverse=True)
    for i in range(len(tmp)):
        print(tmp[i][1])

Submission status: Accepted

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

SP = sorted(sorted(SP, key=lambda e: e[2], reverse=True), key=lambda e: e[1])

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

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
A = list()
for i in range(N):
  S,P = list(input().split())
  A.append([S, (-1) * int(P), i+1])
  
A.sort(key=itemgetter(0,1))

for k in A:
  print(k[2])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
l = [list(input().split()) for i in range(n)]
l_with_index = []
for i in range(len(l)):
    l[i].append(i+1)
    l_with_index.append(l[i])
tmp = sorted(l_with_index, key=lambda x:int(x[1]), reverse=True)
l_with_index = sorted(tmp, key=lambda x:x[0])
for i in range(len(l_with_index)):
    print(l_with_index[i][2])

Submission status: Accepted

Solution code:
n = int(input())
from collections import defaultdict
loc2score = defaultdict(lambda : [])
score2idx = defaultdict(lambda : 0)
for i in range(n):
    loc, score = input().split()
    loc2score[loc].append(int(score))
    score2idx[int(score)] = i

for key in sorted(loc2score.keys()):
    scores = sorted(loc2score[key], reverse=True)
    for i in range(len(scores)):
        print(score2idx[scores[i]]+1)

Submission status: Accepted

Solution code:
n = int(input())

lis = []

for i in range(n):
    s, p = input().split()
    lis.append([i+1, s, p])
    
lis.sort(key=lambda x: x[1])

names =[]

for i in lis:
    if i[1] not in names:
        names.append(i[1])
        
score = 100000


for name in names:
    for l in lis:
        if name in l:
            l[2] = int(l[2]) + score
        else:
            score -= 200
            
lis.sort(key=lambda x: x[2], reverse=True)
            
for i in lis:
    print(i[0])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

restaurants = sorted(sorted(restaurants, key=lambda r: r[2], reverse=True), key=lambda r: r[1])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
c = int(input())
tupList = []
for i in range(c):
  name,score = input().split()
  tup = (name, int(score) * -1, i)
  tupList.append(tup)

tupList.sort()

for each in tupList:
    print(each[2] + 1)

Submission status: Accepted

Solution code:
from operator import itemgetter
import copy

data = []


for n in range(int(input())):
	data.append(input().split(" "))


for n in range(len(data)):
	data[n][1] = int(data[n][1])

base = copy.deepcopy(data)

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

data.sort(key=itemgetter(0))

for n in range(len(data)):
	print(base.index(data[n])+1)

Submission status: Accepted

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

rest_list = []
for i in range(N):
  town, score = input().split(' ')
  rest_list.append(('{}'.format(i),town,int(score)))

sort1 = sorted(rest_list,key=itemgetter(2),reverse=True)
sort2 = sorted(sort1,key=itemgetter(1))

for i in range(N):
  print('{}'.format(int(sort2[i][0])+1))

Submission status: Accepted

Solution code:
n = int(input())

data = []

for i in range(n):
  x, y = input().split()
  y = int(y)
  data.append((i+1, x, y))
  
data.sort(key=lambda x: x[2], reverse=True)
data.sort(key=lambda x: x[1])

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

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())
sp = []
for i in range(n):
    row = input().split()
    row[1] = - int(row[1])
    row.append(i+1)
    sp.append(row)

sp.sort(key=itemgetter(0, 1))
for index in sp:
    print(index[2])

Submission status: Accepted

Solution code:
N = int(input())
S=[""]*N
P=[0]*N
num = [0]*N

for i in range(N):
    tmp,tmp2 = input().split()
    S[i] = tmp 
    P[i] = 100 - int(tmp2)
    num[i] = i+1

user =  list(zip(num,S,P))

test = sorted(user,key = lambda x:(x[1],x[2]))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
SP = []
for i in range(N):
    SP.append(input().split())
#番号を入れる
for j in range(N):
    SP[j].append(j+1)

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter, attrgetter

N = int(input())
shoplist = []
i = 0
for i in range(N):
	tmplist = input().split(" ")
	shoplist.append(list())
	shoplist[i].append(tmplist[0])
	shoplist[i].append(int(tmplist[1]))
	shoplist[i].append(i+1)

s1 = sorted(shoplist, key = itemgetter(1), reverse = True)
s2 = sorted(s1, key = itemgetter(0))
for i in range(N):
	print(s2[i][2])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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)) # reverse point for downer sort , and memorize order i+1
ls.sort()
#print(ls) # for debug
for r in ls:
  print(r[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))
L.sort(key=lambda x:(x[0],-x[1]))
for i in range(N):
    print(L[i][2])

Submission status: Accepted

Solution code:
N = int(input())

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

arr.sort()
for s, p, i in arr:
    print(i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from copy import deepcopy
from collections import defaultdict
d = defaultdict(list)
N = int(input())
for i in range(N):
    s, p = map(str, input().split())
    d[s].append([int(p), i+1])
dic = deepcopy(d)
key = sorted(d)
for x in key:
    dic[x].sort(reverse=True)
    for y in dic[x]:
        print(y[1])

Submission status: Accepted

Solution code:
N = int(input())
L = []
for Resturant_number in range(1, N+1):
    tmp = [Resturant_number]
    tmp += input().split()
    tmp[2] = int(tmp[2])
    L.append(tmp)
L.sort(key=lambda x:(x[1],-x[2]))
for Restaurant_data in L:
    print(Restaurant_data[0])

Submission status: Accepted

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

Submission status: Accepted

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

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

for _,_,i in SP:
    print(i+1)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    SP = []
    for _ in range(N):
        temp = input().split()
        SP.append((temp[0], int(temp[1])))

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

    indices = [SP.index(x)+1 for x in sorted_SP]
    # print(sorted_SP)
    for i in indices:
        print(i)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#ABC128B

N = int(input())

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

# score
restaurant.sort(key = lambda store: -1 * store[2])
# city
restaurant.sort(key = lambda store: store[1])

for r in restaurant:
    print(r[0])

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

print('\n'.join(str(ai[2]) for ai in a))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    store = []
    for i in range(n):
        s, p = input().split()
        #(順番、店名、点数)
        store.append((i+1, s, int(p)))

    #第二キーは降順にしたい場合、キーに-をつける
    store.sort(key=lambda x:(x[1],-x[2]))
    for i in range(n):
        print(store[i][0])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N=int(input())

L=[]

for i in range(N):
  S,P=input().split()
  L=L+[[S,-int(P),i]]
  
#print(L)
 
L.sort()

#print(L)
#print(L[1][1])

for z in range(N):
  print(L[z][2]+1)

Submission status: Accepted

Solution code:
a = []
n = int(input())
for i in range(n):
    key,value = input().split()
    a.append((key,int(value),int(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())
r=[]
for i in range(n):
    s,p=input().split()
    r.append((s,int(p),i))

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter

n = input()
n = int(n)


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

Submission status: Accepted

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

for i in range(n):
    a[i].append(i+1)

a_point = sorted(a, key = lambda x: int(x[1]), reverse = True)

a_name = sorted(a_point, key = lambda x: x[0])

ans = []

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

Submission status: Accepted

Solution code:
N = int(input())
review = []
for i in range(N):
    name, score = input().split()
    score = int(score)
    review.append([name, -score, i+1])

review.sort()
for res in review:
    print(res[2])

Submission status: Accepted

Solution code:
#coding:utf-8

L = []

N = int(input())

for i in range(N):
    x,y=[str(i) for i in input().split()]
    y = int(y)
    L.append([x,-y,i+1])

L.sort()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import bisect
from collections import defaultdict

def main():
    N = int(input())
    city_score_list = []
    for i in range(N):
        s, p = input().split()
        city_score_list.append((i, s, int(p)))

    city_score_list = sorted(city_score_list, key=lambda x: (x[1], -x[2]))
    for i, s, p in city_score_list:
        print(i+1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import cmp_to_key

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


def main():
    N = int(input())
    SP = []
    for i in range(N):
        sp = input().split()
        SP.append((sp[0], int(sp[1]), i+1))
    for a in sorted(SP, key=cmp_to_key(cmp)):
        print(a[2])


main()