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())
sp = [[0, 0, 0] for i in range(n)]
for i in range(n):
  sp[i][0], sp[i][1] = list(map(str, input().split()))
  sp[i][1] = int(sp[i][1])
  sp[i][2] = i+1
sp.sort()

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

Submission status: Accepted

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


def main():
    sc = Scan()
    N = sc.intarr()[0]
    data = []
    for i in range(N):
        city, score = input().split()
        d = {'index': i+1, 'city': city, 'score': int(score)}
        data.append(d)
    tmp = sorted(data, key=lambda x: x['score'], reverse=True)
    sorted_data = sorted(tmp, key=lambda x: x['city'])

    for d in sorted_data:
        print(d['index'])


class Scan():

    def intarr(self):
        num_array = list(map(int, input().split()))
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  # 最大公約数
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):  # 最小公倍数
    return a * b // gcd(a, b)


main()

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])
    
sort=sorted(sp, key=lambda sp: (sp[0], -sp[1]))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
sp=[[i+1]+list(input().split()) for i in range(n)]
change=True
while change:
    change=False
    for i in range(n-1):
        if sp[i][1]>sp[i+1][1]:
            sp[i],sp[i+1]=sp[i+1],sp[i]
            change=True
        elif sp[i][1]==sp[i+1][1] and int(sp[i][2])<=int(sp[i+1][2]):
            sp[i],sp[i+1]=sp[i+1],sp[i]
            change=True
for ans in sp:
    print(ans[0])

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(key=lambda x:x[1],reverse = True)
sp.sort(key=lambda x:x[0])

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

Submission status: Accepted

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

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

Submission status: Accepted

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

N = int(input().strip())

a = []
for i in range(N):
    l = input().strip().split()
    l[1] = 100-int(l[1])
    l.append(i+1)
    a.append(l)
a.sort()

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

Submission status: Accepted

Solution code:
import functools

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

def cmp1(l, r):
   
    if l[0] < r[0]:
        return -1
    elif l[0] == r[0]:
        if l[1] == r[0]:
            return 0
        elif l[1] < r[1]:
            return 1 
        else:
            return -1
    else:
        return 1
        
    
for i in range(N):
    city, rate = input().split()
    l[i] =  city, int(rate), i+1


l.sort(key=functools.cmp_to_key(cmp1))

for _, _, idx in l:
    print(idx)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

for i in range(n):
    print(a[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))
    n-=1

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
nes = [0] * N
for i in range(N) :
    li = input().split()
    li.append(i+1)
    li[1] = "-" + li[1]
    nes[i] = li
for i in range(N) :
    nes[i][1] = int(nes[i][1])
nes.sort()
for i in range(N) :
    print(nes[i][2])

Submission status: Accepted

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

lss = sorted(ls, key=lambda x: int(x[1]), reverse=True)

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

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

Submission status: Accepted

Solution code:
# Guidebook

# libraries
import numpy as np

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

# solve
for e in sorted(res):
    print(e[2])

Submission status: Accepted

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

DP = sorted(SP, key=lambda x: (x[0], -x[1]), reverse=False)
for j in DP:
    for c, i in enumerate(SP):
        if i == j:
            print(c+1)

Submission status: Accepted

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

lss = sorted(ls, key=lambda x: int(x[1]), reverse=True)

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

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

Submission status: Accepted

Solution code:
N = int(input())

S = [input().split() +[_+1] for _ in range(N)]

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

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

now = S[0][0]
pre = []

for i in range(N):
    if now == S[i][0]:
        pre.append(S[i])
    else:
        pre.sort(key=lambda x: x[1],reverse=True)
        for j in range(len(pre)):
            print(pre[j][2])
        pre = [S[i]]
        now = S[i][0]

pre.sort(key=lambda x: x[1],reverse=True)
for j in range(len(pre)):
    print(pre[j][2])

Submission status: Accepted

Solution code:
print(*[s[2] for s in sorted(
        [input().split() + [i + 1] for i in range(int(input()))],
        key=lambda x:(x[0], -int(x[1]))
    )], sep="\n"
)

Submission status: Accepted

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

Submission status: Accepted

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

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:
N = int(input())
X = [list(input().split()) for i in range(N)]

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

for i in X:
    i[1] = int(i[1])
X.sort()
# print(X)

for i in range(N):
    for j in range(i + 1, N):
        if X[i][0] == X[j][0]:
            if X[i][1] < X[j][1]:
                X[i], X[j] = X[j], X[i]

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

Submission status: Accepted

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

restaurant = {}
for i in range(N):
  S, P = clues[i]
  score = restaurant.get(S, {})
  score[i] = int(P)
  restaurant[S] = score

for S in restaurant:
  score = restaurant[S]
  restaurant[S] = sorted(score.items(), key=lambda x:x[1], reverse=True)

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())

restaurnats = []
for i in range(N):
    name, points = input().split()
    restraunt = [name, int(points), i+1]   
    restaurnats.append(restraunt)

restaurnats = sorted(restaurnats, key=itemgetter(1), reverse=True)
restaurnats = sorted(restaurnats, key=itemgetter(0))
for i in restaurnats:
    print(i[2])

Submission status: Accepted

Solution code:
N=int(input())
p=1
S=[]
A=[]
U=[]
T=[]
L= [list(map(str,input().split())) for i in range(N)]
for j in range(1,N+1):
  L[j-1].append(j)
L.sort(key=lambda x: x[0])
#print(L)
S=L[:]
S.sort(reverse=True,key=lambda x: int(x[1]))
#print(S)
T.append(L[0][0])
for i in range(1,N):
  if L[i-1][0]!=L[i][0]:
    T.append(L[i][0])
#print(T)
for j in range(len(T)):
  for k in range(N):
    if S[k][0]==T[j]:
      A.append(S[k][2])
for i in range(N):
  print(A[i])

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
def f(x): return (x[0], -int(x[1]))
SP = [(f(input().split()), i) for i in range(1, N+1)]
SP.sort()
for _, i in SP:
    print(i)

Submission status: Accepted

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

n = int(input())
sp = ["" for _ in range(n)]

for i in range(n):
    a, b = map(str, input().split())
    sp[i] = [a, int(b)]
    sp[i].insert(2, i+1)
#print(sp)

sp2 = sorted(sp, key=lambda x:x[1], reverse=True)
#print(sp2)

sp3 = sorted(sp2, key=lambda x:x[0], reverse=False)
#print(sp3)

for i in range(len(sp3)):
    print(sp3[i][2])

Submission status: Accepted

Solution code:
from collections import namedtuple
from operator import attrgetter


Restaurant = namedtuple("Restaurant", ("id", "city", "score"))
restaurants = []
N = int(input())
for i in range(N):
    s, p = input().split()
    restaurant = Restaurant(i+1, s, int(p))
    restaurants.append(restaurant)
for restaurant in sorted(sorted(restaurants, key=attrgetter("score"), reverse=True), key=attrgetter("city")):
    print(restaurant.id)

Submission status: Accepted

Solution code:
n=int(input())

l=[]
a=[]
b=[]
d={}
s=[]

for i in range(1,n+1):
    t=list(input().split())
    l.append([t[0],int(t[1])])
    if t[0] not in a:
        a.append(t[0])
    b.append(t[0])
c=l.copy()
for e in a:
    d[e]=b.count(e)
c.sort()
i=0
while i<n:
    if d[c[i][0]]==1:
        s.append(l.index(c[i])+1)
        i+=1
    else:
        for j in range(d[c[i][0]]):
            s.append(l.index(c[i+d[c[i][0]]-1-j])+1)
        i+=d[c[i][0]]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for a in sp:
    print(sp2idx[tuple(a)])

Submission status: Accepted

Solution code:
N, *L,  = [s.split() for s in open(0)]
d = {(L[i][0], -int(L[i][1])): i for i in range(len(L))}

d = sorted(d.items())
for i in d:
    print(i[1]+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter


def solve():
    N = int(input())
    SP = [['', 0, 0] for _ in range(N)]
    for i in range(N):
        S, P = map(str, input().split())
        P = -int(P)
        SP[i] = [S, P, i+1]
    
    SP.sort(key=itemgetter(0, 1))
    for i in range(N):
        print(SP[i][2])


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = int(input())

s = [input().split() for i in range(n)]
# 整数に戻す
for i in range(n):
    s[i][1] = int(s[i][1])

c = s.copy()
s.sort()
s.append("fin")

cnt = 0
for i in range(n):
    if (s[i][0] != s[i + 1][0]):
        for j in reversed(range(i - cnt, i + 1)):
            for k in range(n):
                if s[j][1] == c[k][1]:
                    print(k + 1)
                    break
        cnt = 0
    else:
        cnt += 1

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, S: "List[str]", P: "List[int]"):
    isp = [(i+1,S[i],P[i]) for i in range(N)]
    isp.sort(key= lambda x: (x[1],-x[2]))
    for t in isp:
        print(t[0])
    return


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())
L=[list(input().split()) for i in range(n)]
for i in range(n):
    L[i][1]=-int(L[i][1])
    L[i].append(i+1)
L.sort()
for i in range(n):
    print(L[i][2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

for i in range(N):
    for j in range(N):
        if sort_xy[i][0] == xy[j][0]:
            if sort_xy[i][1] == xy[j][1]:
                print(j + 1)

Submission status: Accepted

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

for g in sorted(sorted(guide, key = lambda x: x[1], reverse = True), key = lambda x: x[0]):
    print(g[2])

Submission status: Accepted

Solution code:
n = int(input())
d = dict()
name_list = []
for j in range(n):
    s, i = input().split()
    if s not in d.keys():
        d[s] = []
    d[s].append([int(i), j])
    name_list.append(s)
name_list = list(set(name_list))
name_list.sort()
for t in name_list:
    tar = sorted(d[t], reverse=True)
    for ans in tar:
        print(ans[1] + 1)

Submission status: Accepted

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

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()
for i in range(n):
    print(lst[i][2])

Submission status: Accepted

Solution code:
N = int(input())
city_dict = {}
for i in range(N):
  S, P = input().split()
  if S in city_dict:
    city_dict[S].append({'num' : i, 'score' : int(P)})
    continue
  city_dict[S] = [{'num' : i, 'score' : int(P)}]
  
for city in sorted(city_dict):
  sorted_city_list = sorted(city_dict[city], key=lambda x : x['score'], reverse = True)
  for node in sorted_city_list:
    print(node['num']+1)

Submission status: Accepted

Solution code:
n = int(input())

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

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

[print(lst[i][2]) for i in range(n)]

Submission status: Accepted

Solution code:
# 15:09 giveup
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:
n = int(input())
c =[]
for i in range(n):
    a,b =input().split()
    c.append([a,int(b),i+1])
c.sort(key=lambda x:(x[0],-x[1]))
for j in c:
    print(j[2])

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
SP = defaultdict(list)

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

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

for key,item in SP:
    item_sort = sorted(item, reverse=True)
    for _,i in item_sort:
        print(i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
l=[[] for i in range(n)]
for i in range(n):
  s,p=input().split()
  l[i].append(s)
  l[i].append(int(p))
  l[i].append(i+1)
l2=sorted(l,key=itemgetter(1),reverse=True)
l3=sorted(l2,key=itemgetter(0))
for i in range(n):
  print(l3[i][2])

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 = sorted(l, key=lambda x: (x[0],-x[1]))

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

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 = sorted(l, key=lambda x: x[1],reverse=True)
l = sorted(l, key=lambda x: x[0])       

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

Submission status: Accepted

Solution code:
n = int(input())

l = []
ans = []

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

ans = sorted(l, key=lambda x:(x[0],-x[1]))    
for j in ans:
    print(j[2])

Submission status: Accepted

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

Submission status: Accepted

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

dic = {}
for i in range(n):
    s[i][1] = int(s[i][1])
    s[i].append(i+1)
    restaurant = s[i][0]
    if restaurant not in dic:
        dic[restaurant] = [[s[i][1], s[i][2]]]
    else:
        dic[restaurant].append([s[i][1], s[i][2]])
#print(dic)
keys = sorted(dic.keys())
#print(keys)
for i in keys:
    for j in range(len(dic[i])):
        value = sorted(dic[i], key=lambda x: x[0], reverse=True)
        print(value[j][1])

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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

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 i in sp:
    print(i[2])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

for i in range(len(List)):
    print(List[i][2])

Submission status: Accepted

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

sp.sort()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
sr = []
ans = [0]*n
for _ in range(n):
    s,r = input().split()
    sr += [[str(s), int(r)]]
se = sorted(sr, key=lambda x: (x[0], -x[1]))
for i in range(n):
    ans[i] = sr.index(se[i])+1
for i in range(n):
    print(ans[i])

Submission status: Accepted

Solution code:
r_list = []
ans_list = []
N = int(input())
for i in range(1, N+1):
    Si, Pi = input().split()
    r_list.append((Si, int(Pi), i))
    
name_sorted_list = sorted(r_list, key=lambda x:x[0])

while len(name_sorted_list) > 0:
    test_list = []
    list_index = [i for i, x in enumerate(name_sorted_list) if x[0]  == name_sorted_list[0][0]]
    for i in list_index:
        test_list.append(name_sorted_list[i])
    for i in reversed(list_index):
        del name_sorted_list[i]
    test_list = sorted(test_list, key=lambda x:x[1], reverse = True)
    for item in test_list:
        ans_list.append(item)
    
for item in ans_list:
    print(item[2])

Submission status: Accepted

Solution code:
N = int(input())

a = [list(map(str, input().split())) for _ in range(N)]
lst = []

for i, (x, y) in enumerate(a):
    lst.append([i + 1, x, int(y)])

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

Submission status: Accepted

Solution code:
N = int(input())

a = [list(map(str, input().split())) for _ in range(N)]
lst = []
for i, (x, y) in enumerate(a):
    lst.append([i + 1, x, int(y)])

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

for i in range(len(S_P)):
    print(S_P[i][2])

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
dict1 = defaultdict(list)
for i in range(N):
    S,P = map(str,input().split())
    P = int(P)
    dict1[S].append([P,i+1])

dict2 = sorted(dict1.items())
for i,v in dict2:
    v.sort(reverse = True)
    for j in v:
        print(j[1])

Submission status: Accepted

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

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    lr = []
    for i in range(n):
        s, r = rl()
        lr.append((s, -int(r), i+1))
    lr.sort()
    for r in lr:
        print(r[2])



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

sort1=sorted(X, key=lambda x:x[1], reverse=True)
sort2=sorted(sort1, key=lambda x:x[0])

for j in range(N):
    print(X.index(sort2[j])+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=[]
for i in range(N):
  a = list(input().split())
  A.append([a[0],int(a[1]),(i+1)])
A.sort(key=lambda x:x[1],reverse=True)  #二個目の要素で降順並び替え
A.sort(key=lambda x:x[0])  #二個目の要素で降順並び替え
for i in A:
  print(i[2])

Submission status: Accepted

Solution code:
N = int(input())

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


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

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 operator import itemgetter
N = int(input())
SP_1 = [list(input().split()) for i in range(N)]
for i in range(N) :
    SP_1[i][1] = int(SP_1[i][1])
buf = 0
SP_2 = SP_1
SP_1 = sorted(SP_1,key = itemgetter(0))
# print(SP_1)
for i in range(1,N) :
    if SP_1[i][0] != SP_1[i-1][0] :
        #print(SP_1[buf:i])
        SP_1[buf:i] = sorted(SP_1[buf:i],key = itemgetter(1),reverse = True)
        buf = i
SP_1[buf:N] = sorted(SP_1[buf:N],key=itemgetter(1),reverse = True)
# print(SP_1) 
for i in range(N) :
    for j in range(N) :
        if SP_1[i] == SP_2[j] :
            print(j+1)
            break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())
r = [['', 0, 0]] * n

for i in range(n):
  s_input, p_input = input().split(' ')
  r[i] = [s_input, int(p_input), i+1]
# print(n)
# print(r)

s = sorted(r, key=itemgetter(1), reverse=True)
sorted_for_book = sorted(s, key=itemgetter(0))
# print(sorted_for_book)
for item in sorted_for_book:
  print(item[2])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC128 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
lst = []
for i in range(n):
    s,p = input().split()
    lst.append((s,int(p),i+1))
lst.sort(key = lambda x:(x[0],-x[1]))
for i,j,k in lst:
    print(k)

Submission status: Accepted

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

for i in range(N):
  x_new.append([i+1, x[i][0], int(x[i][1])])
  
x_new.sort(key=lambda x: x[2], reverse=True)
x_new.sort(key=lambda x: x[1])

for j in x_new:
  print(j[0])