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

Solution (Python):
def sort1(A):
    for i in range(0, len(A)-1):
        select_min(A,i)
    return A

def select_min(A,i):
    min = i
    for j in range(i+1, len(A)):
        if A[min][0] == A[j][0]:
            if A[min][1] < A[j][1]:
                min = j
    A[i], A[min] = A[min], A[i]

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

SPlist = sort1(SPlist)
        
for u in range(N):
    print(SPlist[u][2])

Solution (Python):
N = int(input())
list = []
for i in range(N):
    input_list = input()
    S = input_list.split(" ")[0]
    P = int(input_list.split(" ")[1])
    list.append([i, S, 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]+1)

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

Solution (Python):
from collections import defaultdict

n = int(input())
test_dict = defaultdict(list)
count = 1
for i in range(n):
    s,p = map(str,input().split())
    test_dict[s].append([int(p),count])
    
    count += 1

for key,val in sorted(test_dict.items(), key=lambda x: x[0]):
    for j in sorted(val, key=lambda x:x[0], reverse=True):
        print(j[1])

Solution (Python):

N=int(input())
if N==1:
    print(1)
else:

    a=[]

    for i in range(N):
        d=list(map(str,input().split()))
        d.append(i+1)
        a.append(d)

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

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


    k=0
    b=[]
    c=[]
    c.append(a[0])
    for i in range(N-1):
        if a[i][0]==a[i+1][0]:
            c.append(a[i+1])
        else:
            c.sort(key=lambda x:x[1])
            c.reverse()
            k=len(c)

            for j in range(k):
                b.append(c[j][2])
            c=[]
            c.append(a[i+1])

    k=len(c)
    c.sort(key=lambda x: x[1])
    c.reverse()
    for j in range(k):
        b.append(c[j][2])


    for i in range(N):
        print(b[i])

Solution (Python):
n = int(input())
list = []

for i in range(n) :
	s,p = input().split()
	p = str(100-int(p))
	if (int(p) < 10) : p = '00' + p
	elif(int(p) < 100) : p = '0' + p
	index = str(i)
	if (i < 10) : index = '00' + index
	elif (i < 100) : index = '0' + index
	list.append(s+p+index)

list.sort()
for i in range(n) :
	print(int(list[i][-3:])+1)

Solution (Python):
from operator import itemgetter, attrgetter

class data:
    def __init__(self, i, c, n):
        self.ind = i
        self.city = c
        self.num = -int(n)

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

d.sort(key=attrgetter('city', 'num'))

for i in range(N):
    print(d[i].ind+1)

Solution (Python):

n = int(input())
d = {}
for i in range(n):
    l = input().split(" ")
    s = l[0]
    p = int(l[1])
    if s in d:
        d[s].append([p, i+1])
    else:
        d.setdefault(s, [[p, i+1]])

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

for item in dd:
    s = sorted(item[1], key=lambda x:x[0], reverse=True)
    for r in s:
        print(r[1])

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

s = sorted(enumerate(s),key= lambda x:(x[1][0],-int(x[1][1])))
for i in s:
    print(i[0]+1)

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

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

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

Solution (Python):
import copy

N = int(input())

S = []
P = []
for i in range(N):
	s, p = input().split()
	S.insert(i, s)
	P.insert(i, p)

list = []
for i in range(N):
	temp = [S[i], int(P[i])]
	list.append(temp)

clone = copy.copy(list)

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

for i in range(N):
	print(list.index(clone[i])+1)

Solution (Python):
n = int(input())
SP = []
for i in range(n):
  sp = input().split()
  sp.append(i+1)
  SP.append(sp)
sortedSP = sorted(SP, key = lambda x:x[0])
for i in range(n-1):
  for j in range(n-1-i):
    if sortedSP[j][0] == sortedSP[j+1][0] and int(sortedSP[j][1]) < int(sortedSP[j+1][1]):
      sortedSP[j], sortedSP[j+1] = sortedSP[j+1], sortedSP[j]
for i in range(n):
  print(sortedSP[i][2])

Solution (Python):
import sys

n=int(input())
if n==1:
	print(1)
	sys.exit()
elif n==0:
	sys.exit()
book=[]
for i in range(n):
	s,p=map(str,input().split())
	book.append([s,int(p),i+1])
book.sort(key=lambda book:book[0])
tmp=[]
for i in range(n):
	if i==0:
		tmp.append(book[i])
	elif tmp[0][0]!=book[i][0]:
		tmp.sort(key=lambda tmp:tmp[1],reverse=True)
		for j in range(len(tmp)):
			print(tmp[j][2])
		tmp.clear()
		if i!=n-1:
			tmp.append(book[i])
		if i==n-1:
			print(book[i][2])
	elif i==n-1:
		tmp.append(book[i])
		tmp.sort(key=lambda tmp:tmp[1],reverse=True)
		for j in range(len(tmp)):
			print(tmp[j][2])
	else:
		tmp.append(book[i])

Solution (Python):
N = int(input())
ls = []

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

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

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

Solution (Python):
from operator import itemgetter as ig

N = int(input())
li = []
di = {}
for i in range(N):
    Si, Pi = input().split()
    Pi = int(Pi)
    li.append([Si, Pi, i + 1])

li = sorted(li, key=ig(1), reverse=True)

for sp in li:
    if sp[0] in di:
        di[sp[0]].append(sp[2])
    else:
        di[sp[0]] = [sp[2]]
    
for i, j in sorted(di.items(), key=lambda x:x[0]):
    for k in range(len(j)):
        print(j[k])

Solution (Python):
n=int(input())
dic_name={}
dic_num={}
S=[]
P=[]
for i in range(n):
    s,p=input().split()
    S.append(s)
    P.append(int(p))
    dic_name.setdefault(S[i],[]).append(P[i])
    dic_num.setdefault(S[i],[]).append(i+1)
S=sorted(S)

i=0
while(i<n):
    arr_name=list(dic_name[S[i]])
    arr_num=list(dic_num[S[i]])
    for a in range(len(arr_name)):
        for b in range(a,len(arr_name)):
            if arr_name[a]<arr_name[b]:
                arr_name[a],arr_name[b]=arr_name[b],arr_name[a]
                arr_num[a],arr_num[b]=arr_num[b],arr_num[a]
                
    for a in range(len(arr_name)):
        print(arr_num[a])
    i+=len(dic_name[S[i]])

Solution (Python):
from sys import stdin
from copy import deepcopy


n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
for i, list in enumerate(data):
    list[1] = int(list[1])
    list.append(i+1)

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

for i, list in enumerate(sortdata):
    print(list[2])

Solution (Python):
N = int(input())
list_all = list()
list_name = list()
list_number = list()

for n in range(N):
  par = input()
  pars = par.split(' ')
  list_all.append([n+1,pars[0],int(pars[1])])
  list_name.append(pars[0])
list_unique = sorted(list(set(list_name)))

for name in list_unique:
  l = list()
  for elem in list_all:
    if elem[1] == name:
      l.append([elem[2],elem[0]])
  l = sorted(l, reverse=True)
  for tmp in l:
    list_number.append(tmp[1])

for num in list_number:
  print(num)

Solution (Python):


N = int(input())
items = []
for i in range(N):
    S, P = input().split()
    items.append({'id': i+1, 'S': S, 'P': int(P), 'pri': i})

sorted_items = sorted(
  items,
  key = lambda x: (x['S'], -x['P'])
)

for i in range(N):
    sorted_items[i].update(pri=i+1)

sorted_items2 = sorted(
  sorted_items,
  key = lambda x:x['pri']
)

for i in sorted_items2:
    print(i['id'])

Solution (Python):
n = int(input())
sp = []
for i in range(n):
    spi = list(input().split())
    spi[1] = int(spi[1])
    spi.append(i+1)
    sp.append(spi)

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

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

Solution (Python):
n = int(input())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(str,input().split())
c = [int(b[i]) for i in range(n)]
d = [[a[i],c[i],i+1] for i in range(n)]
d.sort(key = lambda x:x[0])
cnt = 0
d[0].append(0)
for i in range(1,n):
    if d[i][0] != d[i-1][0]:
        cnt += 1
    d[i].append(cnt)
d.sort(key = lambda x:x[3]*10**3-x[1])
for i in range(n):
    print(d[i][2])

Solution (Python):
n=int(input())
listA=[list(map(str,input().split())) for i in range(n)]
for j in range(n):
    listA[j].append(j+1)
    listA[j][1]=int(listA[j][1])
listB = sorted(listA, key= lambda x:x[1], reverse=True)
listC = sorted(listB, key=lambda x:x[0])
for k in range(n):
    print(listC[k][2])

Solution (Python):
import numpy as np

n = int(input())
sp = [[i for i in input().split()] for i in range(n)]
sp = [i + [len(i[1])] for i in sp]
sp = [i + [j] for i, j  in zip(sp, range(n))]

sortsecond = lambda val: val[1]
sp.sort(key=sortsecond)

sortsecond = lambda val: val[2]
sp.sort(key=sortsecond)

sortsecond = lambda val: val[0]
sp.sort(key=sortsecond, reverse=True)

ans = np.array(sp[::-1])[:, 3].astype(int) + 1
for i in ans:
  print(i)

Solution (Python):
N = int(input())
X =[]
for i in range(N):
  SS,PP = map(str,input().split())
  X.append([int(i+1), SS, int(PP)])

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

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

Solution (Python):
N  = int(input())
dict = {}
dict_shop = {}
for i in range(N):
  buf1,buf2 = input().split()
  buf3 = i+1
  dict.setdefault(buf1,[]).append(int(buf2))
  dict_shop[int(buf2)] = buf3

list = sorted(dict.keys())
for str in list:
  list_buf =dict[str]
  list_buf.sort()
  list_buf.reverse()
  for i in list_buf:
    print(dict_shop[i])

Solution (Python):
a = int(input())

guidebook = {}
for i in range(a):
    li = list(input().split())
    if li[0] in guidebook:
        guidebook[li[0]][i+1] = int(li[1])
    else:
        guidebook[li[0]] = {i + 1: int(li[1])}

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

for rural in shop_sorted:
    
    score_sorted = sorted(rural[1].items(), key=lambda x: x[1], reverse=True)
    
    for i in score_sorted:
        print(i[0])

Solution (Python):
from collections import defaultdict
dic = defaultdict()
n = int(input())

for i in range(1,n+1):
  k, v = input().split()
  dic[i] = [k, int(v)]

dic_sorted = sorted(dic.items(), key=lambda v:(v[1][0], -v[1][1])) 
[print(k[0]) for k in dic_sorted]

Solution (Python):
from collections import defaultdict
n = int(input())
dic = defaultdict(lambda : [])
for i in range(n):
    s, p = input().split()
    p = int(p)
    dic[s].append([p, i + 1])
dic = sorted(dic.items())
for t in dic:
    t = list(t[1:])
    t = t[0]
    t.sort(reverse = 1)
    for x in t:
        print(x[1])

Solution (Python):

n = int(input())
list = []

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

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

Solution (Python):


n = int(input())


l = []

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

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

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

Solution (Python):
N = int(input())
all_point_list = [input().split() for _ in range(N)]
for each_list in all_point_list:
    each_list[1] = int(each_list[1])
sorted_all_list = sorted(all_point_list, key=lambda x:(x[0], -x[1]))
for sorted_point in sorted_all_list:
    print(all_point_list.index(sorted_point) + 1)

Solution (Python):
from sys import stdin
import numpy as np
from operator import itemgetter 

N = int(stdin.readline())


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



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

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

Solution (Python):
n=int(input())
list=[]

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

list=sorted(list)
del_list=[]

while len(list)!=0:
    j=0
    list_same_s=[]
    city=list[0][0]
    list_same_s.append([list[0][1],list[0][2]])
    list.pop(0)
    for i in range(len(list)):
        if list[i][0]==city:
            list_same_s.append([list[i][1],list[i][2]])
            j=j+1
    while j!=0:
        list.pop(0)
        j=j-1
    list_same_s=sorted(list_same_s)
    for i in range(len(list_same_s)):
        print(list_same_s[len(list_same_s)-i-1][1]+1)

Solution (Python):
n = int(input())
restaurants = []

for i in range(n):
  tmp = input().split()
  tmp[1] = int(tmp[1])
  tmp.append(i+1)
  restaurants.append(tmp)

from operator import itemgetter

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

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

Solution (Python):

num = int(input())

shops = {}
narabi = []

for _ in range(num):
    narabi.append(input().split())

jun = 1

for val in narabi:
    name, pt = val
    if name not in shops:
        shops[name] = {}
    shops[name][pt] = jun
    jun+=1

for name in shops:
    shops[name] = sorted(shops[name].items(),key=lambda x: int(x[0]),reverse=True)

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

for name in shops:
    for v in name[1]:
        print(v[1])

Solution (Python):
import sys
from operator import itemgetter
from collections import defaultdict

inputs =  list(map(int, sys.stdin.readline().split()))
N = inputs[0]

dic = defaultdict(list)
for i in range(N):
    inputs = list(sys.stdin.readline().split())
    dic[inputs[0]].append({"value":int(inputs[1]), "key":i+1})


sort = sorted(dic.items(), key=itemgetter(0))

for s in sort:
    scores_sorted = sorted(s[1], key=lambda x: x['value'], reverse=True)
    for score in scores_sorted:
        print(score.pop("key"))

Solution (Python):

N = int(input())
SA = [str(input()) for i in range(N)]


cities = list(set([x.split()[0] for x in SA]))
cities.sort()

for y in cities:
    each_SA = []
    for i in SA:
        if i.split()[0] == y:
            each_SA.append(i)
    each_points = [int(x.split()[1]) for x in each_SA]
    each_points.sort(reverse=True)
    for j in each_points:
        print(SA.index(y + ' ' + str(j)) + 1)

Solution (Python):





N = int(input())






















S_list = []
P_list = []
for i in range(N):
    tmp = input()
    S = tmp.split()[0]
    P = int(tmp.split()[1])
    
    S_list.append([S,P])
    
    pass


sorted_S_list = sorted(S_list, key=lambda x:x[1], reverse=True)
sorted_S_list = sorted(sorted_S_list, key=lambda x:x[0])


for i,k in enumerate(sorted_S_list):
    for j,l in enumerate(S_list):
        if sorted_S_list[i] == S_list[j]:
            print(j+1)
            break
        pass
    pass

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

Solution (Python):

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


from operator import itemgetter

N = read_a_int()
contents = []
for i in range(N):
    contents.append(list(input().split())+[i+1])

contents = [[a, -int(b), c] for a, b, c in contents]

contents.sort(key=itemgetter(0, 1))
ans = [a[2] for a in contents]
print(*ans, sep='\n')

Solution (Python):
from operator import itemgetter

n = int(input())
A = []
city = []
for _ in range(n):
    s,p = input().split()
    city.append([s,-int(p)])
    A.append([s,-int(p)])

A = sorted(A, key=itemgetter(0,1))
for a in A:
    print(city.index(a)+1)

Solution (Python):
n = int(input())
a = []
c = []
for i in range(n):
  b = input().split()
  b[1] = int(b[1])
  a.append(b)
  c.append(b)

s = sorted(a, key=lambda a:a[1], reverse=True)
m = sorted(s, key=lambda s:s[0])

for i in range(n):
  for j in range(n):
    if m[i] == c[j]:
      print(j+1)

Solution (Python):
N = int(input())

S = []
P = []

cities = {}

for i in range(N):
    line = input().split()
    try:
        cities[line[0]].append(i)
    except:
        cities[line[0]] = [i]
    S.append(line[0])
    P.append(int(line[1]))

for k, v in sorted(cities.items()):
    v = sorted(v, key=lambda x: -P[x])
    for vv in v:
        print(vv+1)

Solution (Python):
n = int(input())
rep = [input().split()+[i+1] for i in range(n)]
unko = [[i[0],-1*int(i[1]),i[2]] for i in rep]


unko.sort()
for j in range(n):
  print(unko[j][2])

Solution (Python):
n = int(input())
sp = [list(map(str,input().split())) for i in range(n)]
spstd = sorted(sp, key=lambda x:int(x[1]), reverse=True)
spstd.sort(key=lambda x:x[0])

for i in spstd:
  print(sp.index(i)+1)

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

Solution (Python):
from operator import itemgetter

n = int(input())

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

all = sorted(list, key=itemgetter(1), reverse=True)
all2 = sorted(all, key=itemgetter(0))




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

Solution (Python):
from collections import defaultdict
n = int(input())
d = {}
di = defaultdict(list)
for i in range(n):
    tmp = input().split()
    s, p = tmp[0], int(tmp[1])
    d[(s, p)] = i+1
    di[s].append(int(p))
dii = list(di.items())
dii.sort(key=lambda x: x[0])

for i in dii:
    si, pi = i[0], i[1]
    pi.sort(reverse=True)
    for j in pi:
        print(d[(si, j)])

Solution (Python):
import numpy as np

N = int(input())

number = list(range(1, N+1))

lst = [[0]*3 for i in range(N)]

for i in range(N):
    name, point = map(str, input().split())
    point = int(point)
    lst[i][0] = name
    lst[i][1] = point
    lst[i][2] = i + 1

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

name = np.array(lst).T.tolist()[0]
point = np.array(lst).T.tolist()[1]
number = np.array(lst).T.tolist()[2]

for i in range(N):
    print(number[i])

Solution (Python):


inputs = input().split(' ')
N = int(inputs[0])

shop_dict = {}
shop_sort = {}
for i in range(N):
    inputs = input().split(' ')
    shop_dict[i] = (inputs[0], int(inputs[1]))
    if inputs[0] in shop_sort.keys():
        shop_sort[inputs[0]].append(int(inputs[1]))
    else:
        shop_sort[inputs[0]] = [int(inputs[1])]
    
for k in shop_sort.keys():
    shop_sort[k] = sorted(shop_sort[k], reverse=True)
names = sorted(shop_sort)

for n in names:
    for x in shop_sort[n]:
        key = [k for k, v in shop_dict.items() if v == (n, x)]
        print(key[0] + 1)

Solution (Python):
N = int(input())
s = [0] * N
p = [0] * N

list_ = [0]*N
for i in range(N):
    s[i],p[i] = (input()).split()

for i in range(N):
    list_[i] = "{} {} {:03d}".format(i+1,s[i],int(p[i])).split()

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


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

Solution (Python):


N = int(input())

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

Solution (Python):
import sys
import numpy as np
stdin = sys.stdin

ni = lambda: int(ns()) 
na = lambda: list(map(int, stdin.readline().split())) 
ns = lambda: stdin.readline().rstrip()  
n=ni()
a=[]
for i in range(n):
	s,p = list(map(str, stdin.readline().split()))
	a.append([s,p])

ans = sorted(a, key=lambda x: (x[0],-int(x[1])))
for i in range(n):
	print(a.index(ans[i])+1)

Solution (Python):
N = int(input())
raw_list = [list(input().split()) for _ in range(N)]

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

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


for mise in b:
    
    print(raw_list.index(mise)+1)

Solution (Python):
n=int(input())
l=[list(map(str,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(key=lambda x:x[1], reverse=True)
l.sort(key=lambda x:x[0])
for i in range(n):
    l[i].append(i+1)

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

Solution (Python):
N = int(input())
data = [[i for i in input().split()] for j in range(N)]
for i in range(N):
    data[i].append(i+1)
for j in data:
    j[1] = int(j[1])
sort_data = sorted(data)
start = sort_data[0][0]
num = [sort_data[0][2]]
for i in range(1,N):
    if sort_data[i][0] == start:
        num.append(sort_data[i][2])
    else:
        start = sort_data[i][0]
        for j in range(len(num)):
            print(num[len(num)-1-j])
        num = [sort_data[i][2]]
for j in range(len(num)):
    print(num[len(num)-1-j])

Solution (Python):

n = int(input())
lst = [input().rstrip().split() for _ in range(n)]
city = sorted(set([i[0] for i in lst]))
ans = [[] for i in range(len(city))]
for i, l in enumerate(lst, start=1):
    idx = city.index(l[0])
    ans[idx] += [[i, l]]
for i in ans:
    for j in sorted(i, key=lambda x: int(x[1][1]), reverse=True):
        print(j[0])

Solution (Python):
N = int(input())
list = []
for i in range(N):
	si,ten = input().split()
	list.append((si,int(ten)))
list_a = sorted(list, key=lambda x:(x[0],-x[1])) 
for i in range(N):
  print(list.index(list_a[i])+1)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) 

N = int(input())
sp = [[] for i in range(N)]
for i in range(N):
    s,p = input().split()
    sp[i] = [str(s),int(p)]

sp_sorted = sorted(sp)
city = sp_sorted[0][0]
group = [sp_sorted[0]]
first = 0

for i in range(1,N):
    if city == sp_sorted[i][0]:
        group.append(sp_sorted[i])
    else:
        
        group = sorted(group,key = lambda x:x[1],reverse=True)
        if len(group) == 1:
            pass
        else:
            sp_sorted[first:i] = group
        group = [sp_sorted[i]]
        city = sp_sorted[i][0]
        first = i
    if i == N-1 and len(group) != 1:
        group = sorted(group,key = lambda x:x[1],reverse=True)
        sp_sorted[first:] = group





ans = [-1 for i in range(N)]
for i in range(N):
    ans[i] = sp.index(sp_sorted[i])

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

Solution (Python):
from operator import itemgetter
sp=[]
for i in range(int(input())):
	t=list(input().split())
	t[1]=100-int(t[1])
	t.append(i+1)
	sp.append(t)
sp=sorted(sp, key=itemgetter(0, 1))
print('\n'.join([str(i[2]) for i in sp]))

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

sorted_I = sorted(I, key=lambda x:(x[0],x[2]))

for i in range(N):
    print(sorted_I[i][1])

Solution (Python):

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

if __name__ == '__main__':
    main()

Solution (Python):
l = []
for i in range(int(raw_input ())):
   s, p = [x for x in raw_input ().split()]
   l.append((s, -1 * int(p), i + 1))
l.sort()
for i in l: print i[-1]

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

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

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

Solution (Python):
class GuideBook:
    def __init__(self):
        self.N = int(input())
        self.SP = []
        for i in range(self.N):
            s, p = input().split()
            self.SP.append([s, int(p), i])

    def main(self):
        tmp = sorted(self.SP, key=lambda x: x[1], reverse=True)
        result = sorted(tmp, key=lambda x: x[0])
        for x in result:
            print(x[2] + 1)


guideBook = GuideBook()
guideBook.main()

Solution (Python):
N=int(input())
s=[[]]
for i in range(N):
  a,b=map(str,input().split()) 
  b=int(b)
  s.append([i,a,b])
  
s.pop(0)

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

for row in sorted_items:
  print(row[0]+1)

Solution (Python):

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

for i in range(N):
	a,b = (input().split())

	rest.append((a,int(b),int(i+1)))


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


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

Solution (Python):
n=int(input())

L=[]
for i in range(n):
    k,v=input().split()
    L.append({'num':i,'name':k,'score':int(v)})
L.sort(key=lambda x: (x['name'],-x['score']))
l_n = [d.get('num') for d in L]

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

Solution (Python):
n = int(input())
stores = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    stores.append({'id': i+1, 'city': s, 'point': p})
stores_sorted = sorted(stores, key=lambda x:x['point'], reverse=True)
stores_sorted = sorted(stores_sorted, key=lambda x:x['city'])
for store in stores_sorted:
    print(store['id'])

Solution (Python):
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])

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

for i, _ in sorted(a, key=lambda x: (x[1][0], -int(x[1][1]))):
    print(i)

Solution (Python):
from collections import defaultdict

N = int(input())

dd = defaultdict(lambda: dict())

for i in range(N):
  k,v = input().split()
  dd[k][i] = (int(v))

sorted_dct = sorted(dict(dd).items(), key=lambda x:x[0])

for k,v in sorted_dct:
  a = sorted(v.items(), key=lambda x: -x[1])
  for k1 in a:
    print(int(k1[0]) + 1)

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

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

Solution (Python):
from operator import itemgetter

N = int(input())
SP = tuple(input().split() for _ in range(N))


SP_list = []
for i in SP:
    i[1] = int(i[1])
    SP_list.append(i)


for i in range(len(SP)):
    SP_list[i].insert(0, i+1)

SP_list = sorted(SP_list, key=itemgetter(2))
SP_list = sorted(SP_list, key=itemgetter(1), reverse=True)

for i in reversed(SP_list):
    print(i[0])

Solution (Python):
n=int(input())



dsl={}
for i in range(n):
    sp=input().split()
    if sp[0] in dsl.keys():
        dsl[sp[0]].append([i,int(sp[1])])
    else:
        dsl[sp[0]]=[[i,int(sp[1])]]
l=sorted(dsl.items())
for i in range(len(l)):
    l[i][1].sort(key=lambda x:-x[1])
    for dd in l[i][1]:
        print(dd[0]+1)

Solution (Python):
def introduce_rest(no_city_points):
    for no, _, _ in sorted(no_city_points, key=lambda x: (x[1], -x[2])):
        print(no)


def main():
    n = int(input())
    input_ = []
    for i in range(1, n+1):
        city, p = input().split()
        input_.append((i, city, int(p)))
    introduce_rest(input_)
    
main()

Solution (Python):
N = int(input())
DF = []
for i in range(N):
    S1, SP = input().split()
    DF = DF + [[i+1, S1, int(SP)]]
DF1 = sorted(DF, key=lambda x:x[2], reverse=True)
DF2 = sorted(DF1, key=lambda x:x[1], reverse=False)
for i in range(N):
    print(DF2[i][0])

Solution (Python):
N = int(raw_input())
sp_list = []
for i in range(N):
    sp_list.append(map(str, raw_input().split()))
    sp_list[i][1] = int(sp_list[i][1])
    sp_list[i].append(i+1)

sp_list.sort()

check_set = set()
for i in range(N):
    check_set.add(sp_list[i][0])

for i in check_set:
    idx_list = []
    num_list = []
    for j in range(N):
        if sp_list[j][0] == i:
            idx_list.append(j)
            num_list.append([sp_list[j][1],sp_list[j][2]])
    idx_list.sort()
    num_list.sort()
    num_list.reverse()
    for k in range(len(idx_list)):
        sp_list[idx_list[k]][1] = num_list[k][0]
        sp_list[idx_list[k]][2] = num_list[k][1]


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

Solution (Python):
from operator import itemgetter
n = int(input())
arr_ = [[str(i) for i in input().split()] for _ in range(n)]
for i in range(n):
    arr_[i].append(i+1)
    arr_[i][1] = int(arr_[i][1])

arr_.sort(key=itemgetter(1), reverse=True)
arr_.sort(key=itemgetter(0))
for i in range(n):
    print(arr_[i][2])

Solution (Python):
from operator import itemgetter
N=int(input())
R=[]
for i in range(N):
    s,p=input().split()
    p=int(p)
    R.append([s,p])

sorted_R=sorted(R,key = itemgetter(1),reverse=True)
sorted_R=sorted(sorted_R, key = itemgetter(0))

for i in range(len(R)):
    for j in range(len(R)):
        if R[j]==sorted_R[i]:
            print(j+1)

Solution (Python):

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

from operator import itemgetter
sorted_items = sorted(items, key=itemgetter(1), reverse=True)
sorted_items = sorted(sorted_items, key=itemgetter(0), reverse=False)

for key, value, ind in sorted_items:
  print(ind)

Solution (Python):
from operator import itemgetter

n = int(input())

wrap = []

for i in range(n):
    input_data = input()
    wrap.append([i+1, input_data.split()[0], int(input_data.split()[1])])

wrap.sort(key=itemgetter(2), reverse=True)
wrap.sort(key=itemgetter(1))

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