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())
d = [list(map(str, input().split())) for i in range(n)]
for i in range(1, n+1):
    d[i-1].append(i)
    d[i-1][1] = int(d[i-1][1])
d.sort()
ans = []
tmp = []
now_city = d[0][0]
for i in range(n):
    if now_city == d[i][0]:
        tmp.append(d[i])
    else:
        tmp.sort(key=lambda x: x[1], reverse=True)
        for j in range(len(tmp)):
            ans.append(tmp[j][2])
        tmp = []
        tmp.append(d[i])
        now_city = d[i][0]
tmp.sort(key=lambda x: x[1], reverse=True)
for j in range(len(tmp)):
    ans.append(tmp[j][2])
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
sp=[]
for i in range(n):
  s,p = map(str, 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())
A = []
for i in range(n):
    a,b = input().split()
    A.append([a,-int(b), i+1])
A.sort()
for s,t,i in A:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())

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

S.sort()

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

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
l = []
x = 0
y = 1
for i in range(N):
  a = input().split()
  a[1] = int(a[1])
  l.append(a)
  l[x].insert(2,y)
  x +=1
  y +=1
# print(l)

# l.sort()
b = sorted(l, key=itemgetter(1), reverse=True)
c = sorted(b, key=itemgetter(0))

# print(c)
for i in c:
  # print(i)
  print(i[2])

Submission status: Accepted

Solution code:
n = int(input())

res = [] 
for i in range(n):
    si, pi = input().split()

    res.append([i, si, int(pi)])

for i in sorted(res, key = lambda w: (w[1], -w[2])):
    print(i[0]+1)

Submission status: Accepted

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

for num in lis:
  print(num[0])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

info = sorted(info, key=lambda x: x[2], reverse=True)
info = sorted(info, key=lambda x: x[1])
#ソートの優先度が市名→評価順となっているので、評価でソートした後、市名でソートする。
#sorted(【リストor辞書】, key=lambda x: 【keyにしたい要素】)
for i in range(N):
    print(info[i][0]+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = []
for n in range(N):
    S.append(input())
d={}
for s in S:
    s=s.split(" ")
    c=s[0]
    n=int(s[1])
    if c not in d:
        d[c]=[]
    d[c].append(n)

d_sorted=sorted(d.items(), key=lambda x:x[0])
for k in d_sorted:
    k[1].sort(reverse=True)
    for p in k[1]:
        key = k[0] + " " + str(p)
        print(S.index(key)+1)

Submission status: Accepted

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

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

for k,vs in sorted(d.items(), key=itemgetter(0)):
    for i,p in sorted(vs, key=itemgetter(1), reverse=True):
        print(i)

Submission status: Accepted

Solution code:
n = int(input())
spList = [input().split() for _ in range(n)]
for i in range(n):
    spList[i][1] = 100 - int(spList[i][1])

spResultList = sorted(spList)
for i in range(n):
    print(spList.index(spResultList[i]) + 1)

Submission status: Accepted

Solution code:
N = int(input())
SP = [input().split() + [_ + 1, ] for _ in range(N)]  # type:list
SP.sort(key=lambda x: (x[0], -int(x[1])))
for v in SP:
    print(v[2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
stack = [['zzzzzzzzzzz', -1]]
for i in range(n):
    s, p = input().split()
    p = int(p)
    stack.append([s, p])
cnt = {0}
for i in range(len(stack)-1):
    x = 0
    for j in range(1,len(stack)):
        if j in cnt:
            continue
        else:
            if stack[x][0] > stack[j][0]:
                x = j
            elif stack[x][0] == stack[j][0] and stack[x][1] < stack[j][1]:
                x = j
    cnt.add(x)
    print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

info=[]

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
# input().split()をi+1と前後させると挙動が変化する
X = [[input().split(), i + 1] for i in range(N)]
X_sorted = sorted(X, key=lambda x: (x[0][0], -int(x[0][1])))

for x in X_sorted:
    print(x[1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
l=[["a",-1] for i in range(N)]

for i in range(N):
    a,b=map(str,input().split())
    b=int(b)
    l[i]=[a,200-b,i+1]

l.sort()

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

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

b = sorted(a,key=lambda x: x[1], reverse=True)
c = sorted(b,key=lambda x: x[0])

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

Submission status: Accepted

Solution code:
n = int(input())

city_pts = {}
cities = set()

for i in range(n):
    city, pts_raw = input().split()
    pts = int(pts_raw)

    if city in cities:
        city_pts[city].append((pts,i))
    else:
        city_pts[city] = [(pts,i)]

    cities.add(city)

for c in sorted(cities):
    pts = city_pts[c]

    for p in sorted(pts,reverse=True):
        print(p[1]+1)

Submission status: Accepted

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

_r=sorted(r, key=lambda x: (x[1][0], x[1][1]), reverse=True)
for __r in sorted(_r, key=lambda x: x[1][0]):
    print(__r[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(): 
    
    N = int(input())

    SP = [input().split() for _ in range(N)]

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

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())

list=[[i+1]+input().split() for i in range(n)]

list2=sorted(list,key =lambda x:(x[1], -int(x[2])))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    s,p = map(str, input().split())
    p = int(p)
    a.append((s,p,i+1))
#scoreが高い順にソート
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())
sp=[[i for i in input().split()] for j in range(n)]
i=1
isp=[[]for i in range(n)]
for s,p in sp:
    isp[i-1]=[s,-int(p),i]
    i+=1
isp=sorted(isp)
for s,p,i in isp:
    print(i)

Submission status: Accepted

Solution code:
N=int(input())
A=[]
for i in range(1,N+1):
    S,P=input().split()
    P=int(P)
    A.append((S,P,i))
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())
A = []
for i in range(1,N+1):
    S,P = input().split()
    P = int(P)
    A.append((S,P,i))
A = sorted(A,key=lambda x:x[1],reverse=True)
A = sorted(A,key=lambda x:x[0])
for x in A:
    print(x[2])

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    x = []
    for i in range(n):
        a, b = list(map(str, str(input().rstrip('\n')).split()))
        x.append([a, -int(b), i+1])
    x.sort()
    for i in range(n):
        print(x[i][2])


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N= int(input())
li = list()

for i in range(N):
  res,score = input().split()
  score = int(score)
  li.append([res,-score,i+1])
  
li.sort()

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

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

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

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

b=sorted(a)
for i in range(n):
  print(b[i][2])

Submission status: Accepted

Solution code:
N = int(input())
A = [0]*N
P = [0]*N
for i in range(N):
  D = list(map(str, input().split()))
  A[i] = D[0]
  P[i] = int(D[1])

for i in range(N):
  A.insert(2*i+1, P[i])

for i in range(N):
  A.insert(3*i+2, i+1)

#print(A)  
B = [A[i:i + 3] for i in range(0, len(A), 3)]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

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][1] = int(sp[i][1])
    sp[i].append(i+1)

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

for j in range(N):
    print(sp3[j][2])

Submission status: Accepted

Solution code:
n = int(input())
ds = {}
for i in range(1, n+1):
    s, p = input().split()
    dp = ds.get(s,{})
    dp[int(p)] = i
    ds[s] = dp
for si in sorted(ds.keys()):
    s = ds[si]
    for pi in sorted(s.keys(), reverse=True):
        print(s[pi])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for i in ll2:
    print(ll.index(i)+1)

Submission status: Accepted

Solution code:
n = int(input())
l = []
for i in range(n):
    s, p = input().split()
    l.append((s.strip(), int(p)))
r = sorted(l, key=lambda x: (x[0], -x[1]))
for j in r:
    print(l.index(j)+1)

Submission status: Accepted

Solution code:
N = int(input())
a = [list(map(str, input().split())) for _ in range(N)]
tmp = sorted(a, key = lambda x:(int(x[1])), reverse = True)
array = sorted(tmp, key = lambda x:(x[0]))

for i in range(N):
    print(a.index(array[i]) + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
sp = []
for i in range(n):
    s_input, p_input = input().split()
    sp.append([s_input] + [int(p_input)] + [i])
sorted1 = sorted(sp, key=itemgetter(1), reverse=True)
sorted2 = sorted(sorted1, key=itemgetter(0))

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict
import sys,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

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

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
R = []
for i in range(N):
    s, p = input().split()
    R.append([i+1, s, -int(p)])
    
R_sort = sorted(R, key=lambda x : (x[1], x[2]))

for city in R_sort:
    print(city[0])

Submission status: Accepted

Solution code:
while True:
    try:
        N = int(input())
        SP = []
        for i in range(1, N+1):
            S, P = map(str, input().split())
            SP.append([S, int(P), i])
            
        for sp in sorted(SP, key=lambda x: (x[0], -x[1])):
            print(sp[2])
    except:
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
data=[tuple(input().split()+[i+1]) for i in range(n)]
data.sort(key=lambda tup:(tup[0],-int(tup[1])))
for i in data:
	print(i[2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, *A = open(0).read().split()
A = [(s, -int(p)) for s, p in zip(*[iter(A)] * 2)]
I = [i for i in range(int(N))]
I.sort(key=lambda i: A[i])
for i in I:
    print(i + 1)

Submission status: Accepted

Solution code:
N = int(input())
S =[""]*N
R =[0]*N
for i in range(N):
    S[i], R[i] = input().split()
Ri = [0]*N
for i in range(N):
    Ri[i] = -1*int(R[i])
SR = [0]*N
for i in range(N):
    SR[i]=[S[i],Ri[i],i+1]
SR.sort()
for i in range(N):
    print(SR[i][2])

Submission status: Accepted

Solution code:
N = int(input())
S, P = [""], [0]
for _ in range(N):
    s, p = input().split()
    S.append(s)
    P.append(int(p))

I = [i for i in range(1, N + 1)]
I.sort(key=lambda i: P[i], reverse=True)
I.sort(key=lambda i: S[i])

print(*I, sep='\n')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    sort_A = sorted(A, key=lambda x:(x[0], -x[1])) 
    for i in range(N):
        print(sort_A[i][2])

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

Submission status: Accepted

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

r.sort(key=lambda _r: _r[1], reverse=True)
r.sort(key=lambda _r: _r[0])

for num in r:
    print(num[2])

Submission status: Accepted

Solution code:
N = int(input())
res = []
dic = {}

for _ in range(N):
    S, P = input().split()
    res.append([S, int(P)])
    if S in dic:
        dic[S].append(int(P))
    else:
        dic[S] = [int(P)]
res_keys = set(list(list(zip(*res))[0]))

for i in sorted(res_keys):
    for j in sorted(dic[i])[::-1]:
        ans = res.index([i, j])
        print(ans + 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 + 1))

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

L = sorted(L, key=itemgetter(1), reverse=True)
L = sorted(L, key=itemgetter(0))

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

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

Submission status: Accepted

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

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

for i in range(len(gr)):
  print(gr[i][1]+1)

Submission status: Accepted

Solution code:
n = int(input())
z = []
for i in range(n):
    x, y = map(str, input().split())
    z.append([x, - int(y)])
cz = z.copy()
cz.sort()
for i in cz:
    print(z.index(i) + 1)

Submission status: Accepted

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

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

arr.sort()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

A = []

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

A.sort()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
r = []
for i in range(n):
    city, score = map(str, input().split())
    score = int(score)
    r.append((city, score, i+1))

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

for x in r:
    print(x[2])

Submission status: Accepted

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

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

R_sorted = sorted(R, key=lambda x: x[1])

st = 0

for i in range(1, N):
    if R_sorted[i - 1][1] != R_sorted[i][1]:
        R_sorted[st:i] = sorted(R_sorted[st:i], key=lambda x: x[2], reverse=True)
        st = i
    if i == N - 1:
        R_sorted[st:N] = sorted(R_sorted[st:N], key=lambda x: x[2], reverse=True)

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

Submission status: Accepted

Solution code:
n=int(input())
a=[input().split() for i in range(n)]
for i in range(n):
  a[i][1]=int(a[i][1])*-1
b=sorted(a)
for i in range(n):
  for j in range(n):
    if a[j][0]==b[i][0]and a[j][1]==b[i][1]:
      print(j+1)

Submission status: Accepted

Solution code:
N = int(input())
P = [input().split() for i in range(N)]
for i in range(N):
    P[i][1] = int(P[i][1]) * -1
P1 = P.copy()
P1.sort()
for i in range(N):
    for j in range(N):
        if P[j][0] == P1[i][0] and P[j][1] == P1[i][1]:
            print(j + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
r={}


for i in range(n):
  a,b=map(str,input().split())
  r[a.ljust(10,"*")+str((100-int(b))).zfill(3)]=i
  
c=list(r.keys())
c.sort()
#print(r)
for i in c:
  print(r[i]+1)

Submission status: Accepted

Solution code:
from operator import itemgetter, attrgetter
N=int(input())
output = [input().split() for i in range(N)]

a = [ [i,r[0], -1*int(r[1])] for i,r in enumerate(output)]

a =sorted(a, key=itemgetter(1,2))

for b in a:
    print(b[0]+1)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, S: "List[str]", P: "List[int]"):
    restaurant = [[S[i], P[i], i] for i in range(N)]
    restaurant.sort(key=lambda x: (x[0], 100 - x[1]))
    print('\n'.join([str(r[2]+1) for r in restaurant]))
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [str()] * (N)  # type: "List[str]"
    P = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        S[i] = next(tokens)
        P[i] = int(next(tokens))
    solve(N, S, P)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 r in restaurant:
    print(r[0])

Submission status: Accepted

Solution code:
N = int(input())
ans = []
for i in range(1,N+1):
    A,B = input().split()
    A = str(A)
    B = int(B)
    ans.append([A,100-B,i])
ans = sorted(ans)
for i in range(N):
    print(ans[i][2])

Submission status: Accepted

Solution code:
N = int(input())
SP = []
for i in range(N):
    s,p = input().split()
    SP.append([0,0])
    SP[i][0] = s
    SP[i][1] = -int(p)
SP_new = sorted(SP)
for i in SP_new:
    print(SP.index(i)+1)

Submission status: Accepted

Solution code:
import collections
from operator import itemgetter
N = int(input())
SP = []
for i in range(N):
    s,p = input().split()
    SP.append([0,0])
    SP[i][0] = s
    SP[i][1] = int(p)
SP_new = sorted(SP)
t = 0
for i in range(N):
    if t > 0:
        t -= 1
        continue
    s = SP_new[i][0]
    t = 0
    for j in range(i+1, N):
        if s == SP_new[j][0]:
            t += 1
        else:
            break
    SP_new_new = SP_new[i:i+t+1]
    SP_new_new.sort(key = itemgetter(1))
    for k in range(1,len(SP_new_new)+1):
        u = SP_new_new[-k]
        print(SP.index(u)+1)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=[[j for j in input().split()] for i in range(n)]
for i in range(n):
    s[i][1]=int(s[i][1])
    s[i].append(i)
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]+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

L.sort()
for n in range(N):
    print(L[n][2])