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:
from sys import stdin

N = int(input())
# print(N)

bcs = [list(x.split()) for x in stdin.readlines()]

for i in range(N):
	bcs[i][1] = int(bcs[i][1])
	bcs[i].append(int(i+1))
	# print(bcs[i])

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n = int(input())

city_list =[]
shop_list = []

for i in range(n):
	restaurant = input().split()
	shop_list.append(restaurant+[str(i+1)])
	city = restaurant[0]
	if city not in city_list:
		city_list.append(city)


city_list = sorted(city_list)
b = len(city_list)
for i in range(n):
	shop_list[i][0] = (b - 1 - city_list.index(shop_list[i][0]))
	shop_list[i][0] = shop_list[i][0] * 100 + int(shop_list[i][1])
	del shop_list[i][1]

shop_list= sorted(shop_list,reverse = True)

for i in range(n):
	print(shop_list[i][1])

Submission status: Accepted

Solution code:
N = int(input())

S = []
P = []

test_list = []

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

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

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

Submission status: Accepted

Solution code:
N=int(input())
A=[]
for i in range(N):
    E=list(input().split())
    D=[E[0],int(E[1])]
    D.append(i+1)
    A.append(D)
B=sorted(A, key=lambda x: x[1])
B.reverse()
C=sorted(B, key=lambda x: x[0])
for i in range(N):
    print(C[i][2])

Submission status: Accepted

Solution code:
N = int(input())

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

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

for j, _, _ in result:
    print(j)

Submission status: Accepted

Solution code:
from operator import attrgetter

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

n = int(input())

restaurants = []
for i in range(n):
    c, p = map(lambda x: x, input().split(' '))
    restaurants.append(Restaurant(c, 100 - int(p), i + 1))

result = sorted(restaurants, key=attrgetter('city', 'point'))
for r in result:
    print(str(r.num))

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
N  = int(input())
d = [0 for i in range(N)]
for i in range(N):
    S,P = map(str, input().split())
    d[i] = [S,int(P),i+1]
d.sort()
i = 0
while i < N:
    if i != N-1:
        if d[i][0] != d[i+1][0]:
            print(d[i][2])
            i += 1
        else:
            j = i+1
            while d[j][0] == d[i][0]:
                j += 1
                if j >= N:
                  break
                
                
            for k in reversed(range(i,j)):
                print(d[k][2])
            i = j
    else:
        print(d[i][2])
        break

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
import bisect
from operator import itemgetter

stdin = sys.stdin

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

s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]



n = ni()
r_list = list()


for i in range(n):
    s_i, p_i = ns().split(" ")
    r_list.append((s_i, int(p_i), i+1))

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

r_list.sort(key=lambda x:x[0])
for i in range(n):
    print(r_list[i][2])

Submission status: Accepted

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

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

#print(sp)
sp = sorted(sp.items(), key=lambda x:x[0])
#print(sp)

for key,v in sp:
    v.sort()
    v.reverse()
    for i in range(len(v)):
        print(v[i][1])

Submission status: Accepted

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

for s in sorted(dict.keys()):
    for (p, i) in reversed(sorted(dict[s])):
        print(i)

Submission status: Accepted

Solution code:
import copy
n = int(input())
sp = [[i for i in input().split()] for i in range(n)]
for index,value in enumerate(sp):
    sp[index] = [value[0],-int(value[1])]
orig = copy.deepcopy(sp)
sp.sort()
rank = {}
index = 1
for value in sp:
    rank[(value[0],value[1])] = index
    index += 1
indexes = {}
counter = 1
for i in range(n):
    # print(rank[(orig[i][0],orig[i][1])])
    indexes[(rank[(orig[i][0],orig[i][1])])] = counter
    # indexes[counter] = rank[(orig[i][0],orig[i][1])]
    counter += 1
# print(indexes)
for i in range(1,n+1):
    print(indexes[i])

Submission status: Accepted

Solution code:
count = int(input())

sonomama = []
city = {}
for i in range(count):
    score = input().split()
    sonomama.append(' '.join(score))
    if score[0] not in city:
        city[score[0]] = []
    city[score[0]].append(score[1])

city = sorted(city.items())

for item in city:
    holder = sorted(map(int, item[1]), reverse=True)
    for i in range(len(item[1])):
        print(sonomama.index(item[0]+' '+str(holder[i]))+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
book= []
for i in range(N):
    a = input().split()
    city = a[0]
    score = (100-int(a[1]))
    book.append((city, score))
b=sorted(book)

for i in b:
    ans =  1
    for j in book:
        if i == j:
            print(ans)
        else:
            ans += 1

Submission status: Accepted

Solution code:
N=input()

s_li = []

for i in range(int(N)):
	S,P=map(str,input().split())
	s_li_tmp = {'Num':i+1, 'Point':int(P), 'Shop':S}
	s_li.append(s_li_tmp)

s_li_sorted = sorted(s_li, key=lambda x:(x['Shop'],-x['Point']))

for k in range(int(N)):
	print(s_li_sorted[k].get('Num'))

Submission status: Accepted

Solution code:
n = int(input())
ls = []
ls2 = []
count = 0
while count < n:
    ab = input().split()
    a, b = str(ab[0]), int(ab[1])
    ls.append([a, b])
    ls2.append([a, b])
    count = count + 1
ls2.sort(key=lambda x: x[1], reverse=True)
ls2.sort(key=lambda x: x[0])
ans = []
for s in ls2:
    for i, hoge in enumerate(ls):
        if hoge == s:
            ans.append(i+1)
for s in ans:
    print(s)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
b = [list(map(str,input().split())) for p in [0]*n]
for i in range(n):
  b[i][1] = int(b[i][1])
  b[i].append(i+1)
b.sort(key=lambda q:(q[0],-q[1]))
for k in range(n):
  print(b[k][2])

Submission status: Accepted

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

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

for info in info_list:
    print(info[0])

Submission status: Accepted

Solution code:
from operator import itemgetter

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

dic.sort(key=itemgetter(1), reverse=True)
dic.sort(key=itemgetter(0))
for listd in dic:
  print(listd[2]+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

Submission status: Accepted

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

for id_ in range(n):
    c_s = input().split()
    r_l.append((id_ + 1, c_s[0], 100-int(c_s[1])))

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
#B問題
N = int(input())
S = []
for i in range(N):
    s = list(input().split())
    s.append(i+1)
    S.append(s)
    
for i in range(N):
    S[i][1] = int(S[i][1])

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

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

Submission status: Accepted

Solution code:
N =int(input())
# スペース区切りの整数の入力
SP=[]
for i in range(N):
    nakami=input().split()
    SP.append([nakami[0],nakami[1],i])

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

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

Submission status: Accepted

Solution code:
N = int(input())
res = []
for i in range(N):
    Si, Pi = input().split(' ')
    resi = [i+1, Si, int(Pi)]
    res.append(resi)

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

Submission status: Accepted

Solution code:
N = int(input())

restaurants = {}
for i in range(N):
  city, score = tuple(map(str, input().split()))
  if city not in restaurants.keys():
    restaurants[city] = [(i + 1, int(score))]
  else:
    restaurants[city].append((i + 1, int(score)))

for k, v in sorted(restaurants.items()):
  sorted_restaurants = sorted(v, key=lambda x: x[1], reverse=True)
  for restaurant in sorted_restaurants:
    print(restaurant[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    restaurant_map = {}
    n = int(input())
    for i in range(n):
        line = input()
        s, p = line.split(" ")
        p = int(p)
        if s not in restaurant_map:
            restaurant_map[s] = []
        restaurant_map[s].append({
            'no': i+1,
            'point': p,
        })
    for key in sorted(restaurant_map.keys()):
        restaurant_list = sorted(restaurant_map[key], key=lambda x: x['point'], reverse=True)
        for r in restaurant_list:
            print(r['no'])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
sp = {}
for i in range(n):
    s, p = input().split()
    if s in sp:
        sp[s].append([int(p), i+1])
    else:
        sp[s] = []
        sp[s].append([int(p), i+1])
        
for i in sp.keys():
    sp[i].sort(reverse=True)
sp = sorted(sp.items(), key=lambda x:x[0])

for i in sp:
    for j in i[1]:
        print(j[1])

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
ans = []
for i in range(N):
  s,p = input().split()
  ans.append([s,int(p),int(i+1)])
ans = sorted(ans)
ans_list = []
tmp = [ans[0]]
for i in range(1,N):
  if ans[i][0] == ans[i-1][0]:
    tmp.append(ans[i])
  else:
    tmp = sorted(tmp, key=itemgetter(1),reverse=True)
    for j in range(len(tmp)):
      ans_list.append(tmp[j])
    tmp = []
    tmp.append(ans[i])
tmp = sorted(tmp, key=itemgetter(1),reverse=True)
for j in range(len(tmp)):
  ans_list.append(tmp[j])
for i in range(N):
  print(ans_list[i][2])

Submission status: Accepted

Solution code:
num = int(input())

lists = []

for i in range(1, num+1):
  inpu = input()
  name = inpu.split()[0]
  score = int(inpu.split()[1])
  a = [int(i), name, int(score)]
  lists.append(a)
  
sor = sorted(lists, key=lambda x:(x[1], -x[2]))

for a in sor:
  print(a[0])

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())

D = defaultdict(list)
for i in range(N):
    s,p = input().split()
    D[s].append((i+1,int(p)))
    
for k in sorted(D.keys()):
    for v in sorted(D[k],key=lambda x:x[1],reverse=True):
        print(v[0])

Submission status: Accepted

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

s = [_sp[0] for _sp in sp]
p = [int(_sp[1]) for _sp in sp]

s_idx = sorted(range(len(s)), key=s.__getitem__)

s_unique = list(set(s))
s_unique.sort()

for i in range(len(s_unique)):
    l = []
    for j in range(n):
        if s[j] == s_unique[i]:
            l.append(j)
    _p = []
    for k in l:
        _p.append(p[k])
    _p_idx = sorted(range(len(_p)), key=_p.__getitem__)
    _p_idx = _p_idx[::-1]
    for x in _p_idx:
        print(l[x] + 1)

Submission status: Accepted

Solution code:
N = int(input())

SP = []

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

a = sorted(list, key=itemgetter(1), reverse=True)
b = sorted(a, key=itemgetter(0))  

for city, score, index in b:
  print(index)

Submission status: Accepted

Solution code:
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------

N = int(input()) #1行目のNを取得


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


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

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

Submission status: Accepted

Solution code:
n = int(input())

hyouka = []
for i in range(n):
    tmpS, tmpP = input().split()
    ss = ""
    for j in range(10-len(tmpS)):
        ss = ss + "a"
    tmpHyouka = tmpS + ss + str(9999-int(tmpP)-1)
    hyouka.append(tmpHyouka)

ans = sorted(range(len(hyouka)), key=lambda k: hyouka[k])

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

Submission status: Accepted

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

SP.sort(key = lambda x:x[0])
idx = 0
init = SP[idx][0]
while idx < N:
    D = []
    while idx  < N and SP[idx][0] == init:
        D += [SP[idx]]
        idx += 1
    D.sort(reverse = True,key = lambda x:int(x[1]))
    for i in range(len(D)):
        print(D[i][2])
    init = SP[min(idx,N-1)][0]

Submission status: Accepted

Solution code:
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    N = makeMultiInteger(input_string[0])
    S = makeStringMatrix(input_string[1:])
    for _i, s in enumerate(S):
        s.append(_i+1)
    S = sorted(S, key=lambda x: x[0])
    a = []
    i = 0
    for _i, s in enumerate(S):
        #print(s)
        if a != []:
            if s[0] == a[i-1][0]:
                a.append(s)
            else:
                if len(a) > 1:
                    a = sorted(a, key=lambda x: int(x[1]), reverse=True)
                    #print(a)
                    for _a in a:
                        print(_a[2])
                else:
                    for _a in a:
                        print(_a[2])
                i = 0
                a = []
                a.append(s)
        else:
            a.append(s)
    if a != []:
        if len(a) > 1:
            a = sorted(a, key=lambda x: int(x[1]), reverse=True)
            for _a in a:
                print(_a[2])
        else:
            for _a in a:
                print(_a[2])


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    #print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

l = []


for i in range(n):
    s = list(input().split())
    l.append(s)

for i in range(n):
    l[i].append(i+1)
    
l.sort()
s = [0,0,0]
l.append(s)

i = 0

while i != n:
    if l[i][0] == l[i+1][0]:
        if int(l[i][1]) < int(l[i+1][1]):
            l[i][1], l[i+1][1] = l[i+1][1], l[i][1]
            l[i][2], l[i+1][2] = l[i+1][2], l[i][2]
            i = -1
    i += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

for c in sorted(R):
    R[c].sort(reverse = True, key = itemgetter(0))
    for r in R[c]:
        print(r[1])

Submission status: Accepted

Solution code:
from sys import stdin
n = int(input())
data = {}
for i in range(n):
  key, val = input().split()
  if key not in data:
    data[key] = {}
  data[key][int(val)] = i+1
# print(data)

keys = sorted(data.keys())
for key in keys:
  li = sorted(data[key], reverse=True)
  for j in li:
    print(data[key][j])

Submission status: Accepted

Solution code:
N = int(input())

cities = []
points = []
for i in range(N):
    s, p = input().split()
    p = int(p)
    cities.append(s)
    points.append([p, i])
    
dictionary = {city: [] for city in set(cities)}
for i in range(len(cities)):
    dictionary[cities[i]].append([points[i], i])
    
for key in sorted(list(dictionary.keys())):
    values = sorted(dictionary[key], key=lambda x: x[0],reverse=True)
    for v, i in values:
        print(1+i)

Submission status: Accepted

Solution code:
N = int(input())

eva_list = []

for i in range(N):
    key, value = input().split()
    eva_list.append([key,int(value),i+1])

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

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

Submission status: Accepted

Solution code:
n = int(input())
L = []
i = 0
while i < n:
    s,p = map(str,input().split(' '))
    p = -1*int(p)
    L.append((s,p,i))
    i += 1
L.sort()
ans = ''
for l in L:
    ans += str(l[2]+1)+'\n'
print(ans[:-1])

Submission status: Accepted

Solution code:
N = int(input())
Rests = [input().split() for l in range(N)]
sorted_rests = sorted(Rests, key=lambda x:(int(x[1])), reverse=True)
sorted_rests = sorted(sorted_rests, key=lambda x:(x[0]), reverse=False)
for i in sorted_rests:
    print(Rests.index(i) + 1)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

lib = {}

for _ in range(n):
    l = input().split()

    if not l[0] in lib.keys():
        lib[l[0]] = []

    lib[l[0]].append([l[1], _])


lib = sorted(lib.items())
for v in lib:
    for i in sorted(v[1], key=lambda x: -int(x[0])):
        print(i[1]+1)

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

Solution code:
def main():

    N = int(input())

    shop_list = []
    for i in range(N):
        Sn, Pn = input().strip().split()
        shop_list.append((i + 1, Sn, int(Pn)))

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

    print("\n".join([str(i) for i, _, _ in shop_list]))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin


def sortFirst(val):
    return val[0]
N=stdin.readline().rstrip()
N=int(N)
l={}
for i in range(1,N+1):
    S,P = stdin.readline().rstrip().split()
    if S in l.keys():
        l[S].append([int(P),i])

    else:
        l[S]=[[int(P),i]]


for key in l.keys():
    l[key].sort(key=sortFirst,reverse=True)
for key in sorted(l):
    for val in l[key]:
        print(val[1])

Submission status: Accepted

Solution code:
n=input()
sn=[]
for num in range(int(n)):
    st=input()
    st=st.split()
    st[1]=int(st[1])
    st.append(num)
    sn.append(st)

sn2=sorted(sn, key=lambda x:(x[0],-x[1]))
for n in sn2:
    print(int(n[2]+1))

Submission status: Accepted

Solution code:
n = int(input())
dic = []
dic3 = []
for i in range(n):
    a,b = input().split()
    b = int(b)
    dic3.append(b)
    for j in dic:
        if a in j:
            j.append(b)
            break
    else:
        dic.append([a,b])
#print(dic3)
dic.sort()
#print(dic)
dic2 = []
for re in dic:
    del re[0]
    re.sort()
    re.reverse()
    for j in re: dic2.append(j)
for res in dic2:
    print(dic3.index(res)+1)

Submission status: Accepted

Solution code:
from operator import itemgetter
N=int(input())
S=[];P=[];R=[]
for i in range(N):
  s,p =[i for i in input().split()]
  p=int(p)
  r=i+1
  S+=[s];P+=[p];R+=[r]
Z=zip(S,P,R)
Y=sorted(Z,key=itemgetter(1),reverse=True)
#print(Y)
X=sorted(Y,key=itemgetter(0))
#print(X)
S,P,R=zip(*X)
#print(S,P,R)
for i in R:
  print(i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
B = []
for i in range(N):
    L1, R1 = input().split()
    R2 = -1 * int(R1)
    B.append((L1,R2))
BC = np.array(B,dtype= [('town', "U10"),("s", "i1")])
a= np.argsort(BC ,order = ['town', 's'])
for i in range(N):
    print(int(a[i])+1)

Submission status: Accepted

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

for n in range(N):
    rest[n][1] = int(rest[n][1])
    rest[n].append(n + 1)
    
rest.sort(key = lambda x: x[1], reverse = True)
rest.sort(key=lambda x: x[0], reverse=False)


for n in range(N):
    print(rest[n][2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
q=[input().split()+[i]for i in range(n)]
for i in range(n):
    q[i][1]=int(q[i][1])
p=sorted(sorted( q ,key=lambda x:x[1],reverse=1),key=lambda x:x[0])
for s,t,r in p:
    print(r+1)

Submission status: Accepted

Solution code:
N = int(input())
args_list = [input().split() for i in range(N)]
tuples_list = [(args[0], int(args[1]), i+1) for i, args in enumerate(args_list)]
tuples_list.sort(key=lambda x: x[1], reverse=True)
tuples_list.sort(key=lambda x: x[0])
for tuples in tuples_list:
  print(tuples[2])

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(list(input().split()))
    a[i][1] = 100-int(a[i][1])
    a[i].append(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(1, N+1):
    name, point = (x for x in input().split())
    r.append([name, int(point), i])
    r.sort(key=lambda x: x[1], reverse=True)
    r.sort(key=lambda x: x[0])

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
import copy
sys.setrecursionlimit(1000000)
 
N = int(input())
SP =  [ input().split() for N in range(N)]

SP_raw = copy.deepcopy(SP)

for i in range(N):
    SP[i][1] = -int(SP[i][1])

SP.sort()

"""
print(SP)
print(SP_raw)

sys.exit()
"""
for i in range(N):
    SP[i][1] = str(-SP[i][1])
    
#print(SP)
#print(SP_raw)
#sys.exit()
#print(SP.index(SP_raw[0]))
for i in range(N):
    print(SP_raw.index(SP[i])+1)

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
spl = [('', 0)]*n
for i in range(n):
    sp = input().split()
    spl[i] = (i+1, sp[0], -int(sp[1]))
for i, j, k in sorted(spl, key=itemgetter(1,2)):
    print(i)

Submission status: Accepted

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

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

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

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


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

Submission status: Accepted

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


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

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

Submission status: Accepted

Solution code:
N = int(input())

S = []


for i in range(N):
	a,b = map(str, input().split())
	c = int(b)
	S.append([i, a, c])

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

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

Submission status: Accepted

Solution code:
n = int(input())

e = [[i for i in input().split()] for i in range(n)] 

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

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


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

Submission status: Accepted

Solution code:
class Restaurant:
	def __init__(self,id,name,score):
		self.id = id
		self.name = name
		self.score = score

N=int(input())

arr=[]

for n in range(N):
	name,score=input().split()
	arr.append(Restaurant(n+1,name,-1*int(score)))

arr.sort(key=lambda x: (x.name,x.score))

ans = ""
for a in arr:
	print(a.id)

Submission status: Accepted

Solution code:
inp_st = input()
n = int(inp_st)
s_dictionary = {}
for i in range(n):
    inp_st = input()
    split_input = inp_st.split()
    s = split_input[0]
    p = int(split_input[1])
    if s in s_dictionary:
        p_dictionary = s_dictionary[s]
        p_dictionary[p] = i + 1
    else:
        p_dictionary = {}
        p_dictionary[p] = i + 1
        s_dictionary[s] = p_dictionary

s_list = sorted(s_dictionary.keys())
for k_s in s_list:
    p_dictionary = s_dictionary[k_s]
    p_list = sorted(p_dictionary.keys())
    for k_p in reversed(p_list):
        print(p_dictionary[k_p])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    ans = []

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

    ans.sort(reverse=True)  # Point
    ans.sort(key=lambda x: x[1])  # Alphabet

    for row in ans:
        print(row[2])


if __name__ == "__main__":
    main()

Submission status: Accepted

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