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())
ans = []
for i in range(N):
    s, p = input().split()
    ans += [[s, -int(p), i+1]]
ans.sort()
for a in ans:
    print(a[2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
r = {}
for i in range(N):
    Si, Pi = input().split()
    Pi = int(Pi)
    r[(Si, -Pi)] = i + 1

for t in sorted(r.keys()):
    print(r[t])

Submission status: Accepted

Solution code:
n = int(input())
data=[]
for _ in range(n):
    s,p = input().split()
    data += [[s,-int(p),_+1]]

data.sort()

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

Submission status: Accepted

Solution code:
import math
import numpy as np


def main():
    N = int(input())
    SP = [list(input().split()) + [i + 1] for i in range(N)]
    SP.sort(key=lambda x: (x[0], -int(x[1])))
    _SP = np.array(SP)
    for i in _SP[:, 2]:
        print(i)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

S.sort()

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

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
y,s=list(),list()
for i in range(1,n+1):
	S=input().split()
	S[1]=int(S[1])
	S.append(i)
	s.append(S)
y=sorted(s,key=itemgetter(0))
for i in range(n):
	c=0
	for j in range(1,n):
		if((y[j-1][0]==y[j][0])&(y[j-1][1]<y[j][1])):
			y[j-1],y[j]=y[j],y[j-1]
			c=1
	if c==0:break
for i in range(n):
	print(y[i][2])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


def main():
    N = int(input())
    SP = [list(input().split()) + [i + 1] for i in range(N)]
    SP.sort(key=lambda x: (x[0], -int(x[1])))
    for i in map(lambda x: x[2], SP):
        print(i)


if __name__ == '__main__':
    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])

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
y,s=list(),list()
for i in range(1,n+1):
	S=input().split()
	S[1]=int(S[1])
	S.append(i)
	s.append(S)
y=sorted(s,key=itemgetter(0))
for i in range(n):
	for j in range(1,n):
		if((y[j-1][0]==y[j][0])&(y[j-1][1]<y[j][1])): y[j-1],y[j]=y[j],y[j-1]
for i in range(n):
	print(y[i][2])

Submission status: Accepted

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

rs = [(i + 1, sp[0], int(sp[1])) for i, sp in enumerate(SP)]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

scores = []
for i in range(1, n+1):
    c, s = input().split()
    scores.append(("{0}{1}{2:03d}".format(c, "0" * (10 - len(c)), 101 - int(s)), i))

for c, ind in sorted(scores):
    print(ind)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc127
# -*- coding: utf-8 -*-

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

s2=sorted(s,key=lambda x: (x[1]),reverse = True)
s2=sorted(s2,key=lambda x: (x[0]))
for i in s2:
    for j in range(n):
        if i==s[j]:
            print(j+1)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N) :
    S, P = input().split()
    A.append([S])
    A[i].append(100-int(P))
new_A_list = sorted(A)
for i in range(N) :
    print(A.index(new_A_list[i])+1)

Submission status: Accepted

Solution code:
N=int(input())
Set=[]
for i in range(N):
    a,b=input().split()
    Set.append([a,-int(b),i+1])
A=sorted(Set)

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

Submission status: Accepted

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

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


def solve(n, s_list):
    sorted_city_list = sorted(s_list, key=lambda x: (x[1], -x[2]))
    return '\n'.join(map(str, [item[0] for item in sorted_city_list]))


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


if __name__ == "__main__":
    import sys

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
sp = [None]*n
for i in range(n):
    sp[i] = input().split(" ")
sp = list(map(lambda x: [x[0], int(x[1])], sp))
sl = list(map(lambda x: x[0], sp))
sp2 = []
for s in sorted(list(set(sl))):
    l = list(filter(lambda x: x[0] == s, sp))
    sp2.extend(sorted(l, key=lambda x:x[1], reverse=True))
for x in sp2:
    print(sp.index(x)+1)

Submission status: Accepted

Solution code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#n=int(input())
#import fractions
#S=input()
#import math
#lis=list(map(int,input().split()))

n=int(input())
sp={}
for i in range(n):
    li=input().split()
    li.append(i+1)
    li[1]=int(li[1])
    if li[0] not in sp:
        sp[li[0]]=[li]
    else:
        sp[li[0]].append(li)
        sp[li[0]].sort(reverse=True)
items_sorted = sorted(sp.items())
#print(items_sorted)
for i in range(len(items_sorted)):
    for j in range(len(items_sorted[i][1])):
        print(items_sorted[i][1][j][2])

Submission status: Accepted

Solution code:
n = int(input())
S = []
count = [0] * n
for i in range(n):
    a, b = input().split()
    S.append([a, -int(b), i + 1])

S.sort()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
read = input
N = int(read())
guidebook = {}
for i in range(1,N+1):
    n,s = read().split()
    s = int(s)
    if n not in guidebook:
        guidebook[n] = {}
    guidebook[n][s] = i
guidebook = list(guidebook.items())
guidebook.sort()
for n,d in guidebook:
    B = list(d.items())
    B.sort(reverse = True)
    for s,i in B:
        print(i)

Submission status: Accepted

Solution code:
n = int(input())
rest = {}
for i in range(n):
  s, p = input().strip().split()
  if s in rest:
    rest[s].append((int(p), i))
  else:
    rest[s] = [(int(p), i)]

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

Submission status: Accepted

Solution code:
N = int(input())
res_list=[]
for i in range(N):
    a,b = input().split()
    b = int(b)
    res_list.append([i+1,a,b])
res_list =sorted(res_list, key=lambda x: x[1])
tes_list=[]
for i in range(N):
    if tes_list == []:
        tes_list.append(res_list[i])
    if i == N-1:
        tes_list = sorted(tes_list, key=lambda x: x[2],reverse=True)
        for j in range(len(tes_list)):
            print(tes_list[j][0])
    else:
        if res_list[i][1] == res_list[i+1][1]:
            tes_list.append(res_list[i+1])
        else:
            tes_list = sorted(tes_list, key=lambda x: x[2],reverse=True)
            for j in range(len(tes_list)):
                print(tes_list[j][0])
            tes_list=[]

Submission status: Accepted

Solution code:
n = int(input())
sp = [None]*n
for i in range(n):
    sp[i] = [input().split(" "), i+1]
sp = list(map(lambda x: [[x[0][0], int(x[0][1])], x[1]], sp))
sl = list(map(lambda x: x[0][0], sp))
sp2 = []
for s in sorted(list(set(sl))):
    l = list(filter(lambda x: x[0][0] == s, sp))
    sp2.extend(sorted(l, key=lambda x:x[0][1], reverse=True))
for x in sp2:
    print(x[1])

Submission status: Accepted

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

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

for j in range(N):
    print(SP[j][2]+1)

Submission status: Accepted

Solution code:
from collections import OrderedDict

N = int(input())
X = {}
tmp1 = []
for i in range(N):
    tmp1.append(input())
    tmp2 = tmp1[i].split()
    if tmp2[0] in X:
        X[tmp2[0]].append(int(tmp2[1]))
    else:
        X[tmp2[0]] = [int(tmp2[1])]

X_sorted = OrderedDict(sorted(X.items(), key=lambda x:x[0]))
for i in X_sorted.keys():
    X_sorted[i] = sorted(X_sorted[i],reverse=True)

res = []
for i in X_sorted.keys():
    for j in range(len(X_sorted[i])):
        res.append(i+" "+str(X_sorted[i][j]))

for i in range(len(res)):
    print(tmp1.index(res[i])+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

S.sort()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: UTF-8
# sample code

n = int(input())
nsp = []
for i in range(n):
	v = list(map(str, input().split(' ')))
	nsp.append([v[0], -int(v[1]), i+1])

nsp.sort()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
from operator import itemgetter
 
N = int(input())
 
list = []
for i in range(N):
    a,b=input().split()
    list.append([a, int(b),i+1])
sort1 = sorted(list, key=itemgetter(0))
if N == 1:
  	print(1)
else:
    ans = []
    kari = []
    end = 1
    k = 1
    for i in range(0,N-1):
        if end == 1:
            kari.append(sort1[i])
        else:
            k = 0
        if sort1[i][0] == sort1[i+1][0]:  
            kari.append(sort1[i+1])
            end = 0
            if i+1 > N-2:
            	kari.sort(key=itemgetter(1),reverse=True)
            	ans.extend(kari)

        else:
            kari.sort(key=itemgetter(1),reverse=True)
            ans.extend(kari)
            if i+1 > N-2:
            	ans.append(sort1[i+1])
            kari = []
            end = 1
    
    for i in range(0,len(ans)):
        print(ans[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) * (-1), i + 1])

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
L = [[]*3]*N
S = ''
P = ''
for i in range(N):
  S, P = input().split()
  L[i] = [S, int(P)*-1, i+1]

L.sort()

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

Submission status: Accepted

Solution code:
N = int(input())
location = []
sorted_location = []
score = []

for i in range(N):
	a, b = input().split()
	location.append(a)
	score.append(int(b))

#	print('location:' + str(location))
#	print('score:' + str(score))

sorted_location = location[:]
sorted_location.sort()
#print(location)
#print(sorted_location)

a = [] # 掲載順
for i in range(N):
	# 対象の地名、スコアを格納
	l = location[i]
	s = score[i]

#	print('l:' + l)
#	print('s:' + str(s))

	# 地名のスコアを格納
	score_num = [j for j, x in enumerate(location) if x == l]
	score_list = []
	for j in score_num:
		score_list.append(score[j])
	score_list.sort(reverse=True)

#	print('score_list:' + str(score_list))
	
	# 対象の場所の1番最初の順番
	loc1 = sorted_location.index(l) + 1
#	print('loc1:' + str(loc1))

	# 対象の地名の中で、対象のスコアが何番目か
	loc2 = score_list.index(s)
#	print('loc2:' + str(loc2))

	# 対象の掲載順を格納
	a.append(loc1 + loc2)

# 掲載順を出力
for i in range(N):
	print(a.index(i+1) + 1)

Submission status: Accepted

Solution code:
# coding: utf-8
import os
import time
import re
import math


N = int(input())
SP=[]
for a in range(N):
    temp=input().split()
    SP.append([temp[0],int(temp[1]),(a+1)])
#SP=list(map(lambda x: x[0], SP))
SP=sorted(SP, key=lambda x:(x[1]), reverse=True)
SP=sorted(SP, key=lambda x: x[0])
for a in range(N):
    print(SP[a][2])

Submission status: Accepted

Solution code:
from operator import itemgetter

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

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

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

Submission status: Accepted

Solution code:
# B - Guidebook
# https://atcoder.jp/contests/abc128/tasks/abc128_b

import collections

n = int(input())

rest = [list(input().split()) for i in range(n)]
rest_hash = collections.OrderedDict()



for i in range(len(rest)):
    rest[i].append(i+1)


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


for i in range(len(rest)):
    if rest[i][0] in rest_hash:
        rest_hash[rest[i][0]].append(list([rest[i][1], rest[i][2]]))
    else:
        rest_hash[rest[i][0]] = [[rest[i][1], rest[i][2]]]



for n in rest_hash:
    for element in reversed(rest_hash[n]):
        print(element[1])

Submission status: Accepted

Solution code:
n=int(input())
cityLst=[]
for i in range(n):
	s,p=map(str,input().split(" "))
	cityLst.append(["{:<10}".format(s),p])
sCityLst=sorted(cityLst,key=lambda x:x[0]+"a"+chr(-1*(int(x[1])-100)+97))
for o in sCityLst:
	print(cityLst.index(o)+1)

Submission status: Accepted

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

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

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

for i in range(n):
    ans[i] += sp[i][2]

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

Submission status: Accepted

Solution code:
#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <26/May/2019 06:11:19 PM>


#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT), Gwalior


import sys


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    d = {}
    for i in range(n):
        x, y = input().split()
        if x not in d:
            d[x] = []
        d[x].append((int(y), i + 1))
    for i in d:
        d[i].sort(reverse=True)
    from collections import OrderedDict
    od = OrderedDict(sorted(d.items()))
    # print(od)
    for i in od:
        for j in od[i]:
            print(j[1])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() + [i + 1] for i in range(n)]

n = i()
sp = ms(n)
ansli = [0] * n
for i in range(n):
    tmp = 1
    for j in range(n):
        if i != j:
            if sp[j][0] < sp[i][0]:
                tmp += 1
            elif sp[j][0] > sp[i][0]:
                tmp += 0
            else:
                if int(sp[j][1]) < int(sp[i][1]):
                    tmp += 0
                else:
                    tmp += 1
    ansli[i] = [tmp, i + 1]
ansli.sort()
for i in range(n):
    print(ansli[i][1])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

sp.sort()
for i in range(n):
    print(sp[i][2])

Submission status: Accepted

Solution code:

N = int(input())

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

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

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

Submission status: Accepted

Solution code:
n = int(input())


def f(n):
    n[1] = int(n[1])
    return n


a = sorted([input().split() + [str(i+1)] for i in range(n)])

a.append(['end', '0', '0'])

tmp = []
ans = []

for i in range(n):
    tmp.append(a[i])
    if a[i][0] != a[i+1][0]:
        ans.append(sorted(tmp, key=lambda x: int(x[1]), reverse=True))
        tmp = []

for c in ans:
    for d in c:
        print(d[2])

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
SList = []
PList = []
dic = {}
Slist = []
aa = []
for _ in range(N):
    S, P = input().split()
    dic[S] = int(P)
    Slist.append(S)
    aa.append((int(P), S))
dic = sorted(dic.items())

sortedS = list(sorted(set(Slist)))

for i in range(len(sortedS)):
    tempV = []
    tempI = []
    for j in range(N):
        if aa[j][1] == sortedS[i]:
            tempV.append(aa[j][0])
            tempI.append(j)
    indexList = np.argsort(tempV)
    for k in reversed(indexList):
        print(tempI[k] + 1)

Submission status: Accepted

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

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

new_ls = sorted(ls, key=lambda x:x[1], reverse=True)
new_ls = sorted(new_ls, key=lambda x:x[0])

for next,l in enumerate(new_ls):
  for i,tmp in enumerate(ls):
    if l[0]==tmp[0] and l[1]==tmp[1]:
      print(i+1)

Submission status: Accepted

Solution code:
n = int(input())
from operator import itemgetter
a=[]
for i in range(n):
  b,c=map(str,input().split())
  c=int(c)
  a.append([b,c,i])
a1= sorted(a,key=itemgetter(1),reverse=True)
a2=sorted(a1,key=itemgetter(0))
for i in range(n):
  print((a2[i][2]+1))

Submission status: Accepted

Solution code:
#from IPython import embed
N=int(input())
n = []

from collections import Counter

c = Counter()

for i in range(N):
    k = input().split()
    k[1] = int(k[1])
    k.append(i+1)
    n.append(k)
    c.update([k[0]])



n.sort()
#n = n[::-1]
prev = ""
l = []
cnt = 0
#print(c)
for a in n:
    #print(a)

    if c[a[0]] > 1:
        l.append(a[1:])
        #print(a[1:])
        cnt+=1
        #print(a[0])
        #embed()
        if cnt == c[a[0]]:
            l.sort()
            #print(l)
            for i in l[::-1]:
                print(i[1])
            cnt = 0
            l = []
    else:
        print(a[2])

Submission status: Accepted

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

for i in range(N):
  a, b = input().split()
  b = int(b)
  lis = []
  lis.append(a)
  lis.append(0-b)
  lis.append(i)
  L.append(lis)
L.sort()
for i in L:
  print(i[2]+1)

Submission status: Accepted

Solution code:
# 190526_2

N = int(input())
S = []
P = []
I = []
Z = []

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

for i, j, k in zip(S,P,I):
    Z.append([i,j,k])

Z_sorted = sorted(Z)

for j in range(N-1):
    for i in range(N-1):
        if Z_sorted[i][0] == Z_sorted[i+1][0]:
            if Z_sorted[i][1] < Z_sorted[i+1][1]:
                a = Z_sorted[i]
                b = Z_sorted[i+1]
                Z_sorted[i] = b
                Z_sorted[i+1] = a

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

Submission status: Accepted

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

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

for i in range(n):
    x[i][1] = int(x[i][1])

X = []
for i in range(len(x)):
    X.append(int(x[i][1]))
    
xx = sorted(x)
flag = True
temp = xx[0][0]
l = []
ans = []
l.append(xx[0][1])
for i in range(1, n):
    if temp == xx[i][0]:
        l.append(xx[i][1])
        flag = True
    else:
        flag = False
        l.sort(reverse=True)
        for j in l:
            ans.append(j)

        l = []
        temp = xx[i][0]
        l.append(xx[i][1])

if flag:
    l.sort(reverse=True)
    for j in l:
        ans.append(j)
    
ans = [int(a) for a in ans]

if len(ans) != len(X):
    ans.append(xx[i][1])
for j in range(n):
    print(X.index(ans[j]) + 1)

Submission status: Accepted

Solution code:
n = int(input())
table = []
for i in range(n):
    nest_table = []
    s, p = input().split()
    p = int(p)
    nest_table.append(s)
    nest_table.append(p)
    nest_table.append(i+1)
    table.append(nest_table)
    for j in range(i, 0, -1):
        if table[j][0] < table[j-1][0]:
            keep = table[j]
            table[j] = table[j-1]
            table[j-1] = keep
        elif table[j][0] == table[j-1][0]:
            if table[j][1] > table[j-1][1]:
                keep = table[j]
                table[j] = table[j-1]
                table[j-1] = keep    

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

Submission status: Accepted

Solution code:
from operator import itemgetter
N=int(input())
s= [[0]*3 for _ in range(N)]
for x in range(N):
    a,b=map(str,input().split())
    s[x][0]=a
    s[x][1]=100-int(b)
    s[x][2]=x+1
s.sort(key=itemgetter(0,1))
for un in range(N):
    print(s[un][2])

Submission status: Accepted

Solution code:
N = int(input())
lists_S = []
lists_P = []
for i in range(N):
    S,P = map(str,str(input()).split())
    lists_S.append(S)
    lists_P.append(int(P))
c = list(zip(lists_S,lists_P))
c = sorted(c,key=lambda x:(x[0],-x[1]))
s,p = zip(*c)
lists_index = []
for i in range(N):
    for j in range(N):
        if s[i] == lists_S[j] and p[i] == lists_P[j]:
            lists_index.append(p.index(p[j]) + int(1))
for i in range(len(lists_index)):
    print(lists_index[i])

Submission status: Accepted

Solution code:
n = int(input())
restaurants = [ input().split() for i in range(n) ]
names = [ restaurants[j][0] for j in range(n)]
names = set(names)
names = sorted(list(names))
for name in names:
    scores = list(map(int, [restaurants[l][1] for l in range(n) if restaurants[l][0] == name]))
    scores.sort(reverse = True)
    for m in scores:
        print(restaurants.index([name,str(m)]) +1)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
SP = [input().split() for i in range(N)]
for i in range(N):
    SP[i][1] = int(SP[i][1])
    SP[i].append(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())
A = [0 for i in range(N)]
for i in range(N):
    A[i] = list(map(str,input().split()))
for i in range(N):
    A[i].append(str(i+1))
for i in range(N):
    A[i][1] = int(A[i][1]) 


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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#b.py
n = int(input())
lis = [list(input().split())+[x] for x in range(n)]
lis = sorted(lis,key=lambda x:x[0])
now = lis[0][0]
ans_lis = []
sublis = []
for x in lis:
    if x[0] == now:
        sublis.append(x)
    else:
        now = x[0]
        sublis = sorted(sublis,key=lambda x:int(x[1]),reverse=True)
        ans_lis.append(sublis)
        sublis = []
        sublis.append(x)
sublis.sort(key=lambda x:int(x[1]),reverse=True)
ans_lis.append(sublis)
sublis = []
sublis.append(x)       
ans_lis = [item for sublist in ans_lis for item in sublist]
for x in ans_lis:
    print(x[2]+1)

Submission status: Accepted

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

N = int(input())
list = [input().split() for i in range(N)]
list2 = copy.deepcopy(list)
list2.sort(key=lambda x:(x[0],-int(x[1])))

for i in range(N):
    a = list2[i]
    b = list.index(a)
    print(int(b + 1))

Submission status: Accepted

Solution code:
n=int(input())
sp=[list(map(str,input().split())) for l in range(n)]
sn=[]
ss=[]
sn2=[]
ss2=[]
for i in range(n):
    sn.append(sp[i][0])
    ss.append(sp[i][1])
sn2=sorted(sn)
ss=sorted(range(len(sn)), key=lambda k: sn[k])
for i in range(n):
    ss2.append(int(sp[ss[i]][1]))
for i in range(n):
    for j in range(n-1,i,-1):
        if sn2[j]==sn2[j-1]:
            if ss2[j-1]<ss2[j]:
                ss[j-1],ss[j]=ss[j],ss[j-1]
                ss2[j-1],ss2[j]=ss2[j],ss2[j-1]

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

Submission status: Accepted

Solution code:
a = int(input())

List = []
for i in range(a):
	b, c = input().split()
	c = int(c)
	List.append([b, c, i])
List = sorted(List, key = lambda x:(x[0],-x[1]))

List2 = []
for i in range(a):
  List2.append(List[i][2]+1)
  
print(*List2)