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):
n = int(input())
items = []
for i in range(n):
    a, b = input().split()
    a = str(a)
    b = int(b)
    z = {"id": i+1, "name": a, "score": b}
    items.append(z)
sorted_items = sorted(items, key = lambda x: (x["name"], -x["score"]))
for a in sorted_items:
    print(a["id"])

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

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

base_city = ''
prelist2 = []
anslist2 = []

for ans_tuple in anslist:
    city, score, position = ans_tuple[0], ans_tuple[1], ans_tuple[2]
    
    if base_city == city:
        prelist2.append((ans_tuple[1], ans_tuple[2]))
    
    elif base_city != city:
        
        base_city = city
        anslist2 = sorted(prelist2, reverse=True)
        for ans2_tuple in anslist2:
            score, position = ans2_tuple[0], ans2_tuple[1]
            print(position + 1)
            
        prelist2 = []
        anslist2 = []
        
        prelist2.append((ans_tuple[1], ans_tuple[2]))
    

anslist2 = sorted(prelist2, reverse=True)
for ans2_tuple in anslist2:
    score, position = ans2_tuple[0], ans2_tuple[1]
    print(position + 1)

Solution (Python):
import numpy as np
n = int(input())
dict = {}


x =[]
for i in range(n):
    x1, y1 = [i for i in input().split()]
    x.append(x1+"{0:03d}".format(100-int(y1)))

for i in range(len(x)):
    print(np.argsort(x)[i]+1)

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

S = []
P = []
I = []

for i in range(N) : 
    a, b = input().split()
    S.append(a)
    P.append(100 -int(b))
    I.append(i+1)
    
I2 = [x for x in sorted(zip(S, P, I))]

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

Solution (Python):
N = int(input())
d = {}

for i in range(N):
	S, P = [x for x in input().split()]
	P = int(P)
	
	if S in d.keys():
		d[S].append([P, i])
	else:
		d[S] = [[P, i]]

keys = sorted(list(d.keys()))

for key in keys:
	values = sorted(d[key])
	values.reverse()
	for val in values:
		print(val[1]+1)

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

l = [list(map(str,input().split()))for i in range(n)]

name = []
rate = []

for i in range(n):
    name.append(l[i][0])

for i in range(n):
    rate.append(int(l[i][1]))
    


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

for i in range(n):
    l[i][1] = 100 - l[i][1]
    
sorted_l = sorted(l)


for i in sorted_l:
    print(l.index(i)+1)

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

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


ress = []

for i in range(N):
    inputs = input().split()
    s = str(inputs[0])
    p = int(inputs[1])

    ress.append([s, -p, i + 1])
ans = sorted(ress, key=lambda x: (x[0], x[1]), reverse=False)
for i in ans:
    print(i[2])

Solution (Python):
from operator import itemgetter
N = int(input())
SP = [input().split()+[i] for i in range(1, N+1)]

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

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

Solution (Python):
n = int(input())
d = {}
for i in range(n):
    s, p = input().split()
    if s in d:
        d[s].append((int(p), i + 1))
    else:
        d[s] = [(int(p), i + 1)]
for key in sorted(d.keys()):
    sorted_list = sorted(d[key], reverse =True)
    for item in sorted_list:
        print(item[1])

Solution (Python):
N = int(input())
guidebook = []
for i in range(N):
  S, P = input().split()
  guidebook.append([i + 1, S, int(P)])
sort_guidebook = sorted(guidebook, key=lambda x:(x[1],-x[2]))
for i in range(N):
  print(sort_guidebook[i][0])

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

for sorted_sp in sorted(sp, key=lambda x: (x[1], -int(x[2]))):
    print(sorted_sp[0])

Solution (Python):
n = int(input())
A = []
for i in range(n):
    s, b = map(str, input().split())
    b = int(b)
    A.append([s, -b, i+1])
A.sort()
for i in A:
    print(i[2])

Solution (Python):
N = int(input())
li = []
for i in range(N):
    si, pi = input().split()
    pi = int(pi)
    li +=[ [i+1, si, pi]]
li.sort(key=lambda x:x[2], reverse=True)
li.sort(key=lambda x:x[1], reverse=False)
for j in li:
    print(j[0])

Solution (Python):
N=int(input())
r_dic={}
for i  in range(N):
    s,p=input().split()
    r_dic.setdefault(s,[]).append((int(p),i+1))
    
for city in  sorted(r_dic.keys()):
    for data in (sorted(r_dic[city], reverse=True)):
        print(data[1])

Solution (Python):
N = int(input())
hoge = []
for i in range(0,N):
	b = [x for x in input().split()]
	hoge.append(b)

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

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

Solution (Python):
N = int(input())
r = [input().split() for _ in range(N)]
R = r.copy()
r = sorted(r, key=lambda x:(x[0], -int(x[1])))

for i in r:
  if i in R:
    print(R.index(i)+1)

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

Solution (Python):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())

n = ni()
lis = []
ans = [[] for _ in range(n)]
for i in range(n):
    s, p = nsm()
    p = -int(p)
    lis.append([s, p, i])
lis.sort()
for i in range(n):
    print(lis[i][2] + 1)

Solution (Python):
import copy
N=int(input())
SP=list(list(input().split()) for _  in range(N))
SSP=copy.deepcopy(SP)
SP.sort(key=lambda x:int(x[1]),reverse=True)
SP.sort(key=lambda x:x[0])

for i in SP:
    print(SSP.index(i)+1)

Solution (Python):
class Store:
    def __init__(self, c, p, id):
        self.city = c
        self.point = p
        self.id = id
N = int(input())
stores = []
for i in range(N):
    c, p = input().split()
    stores.append(Store(c, int(p), i+1))
stores.sort(key = lambda x: (x.city, -x.point))
for i in range(N):
    print(str(stores[i].id))

Solution (Python):
from operator import itemgetter

N = int(input())
S = [0]*N
P = [0]*N
index = [i+1 for i in range(N)]
for i in range(N):
  S[i],P[i] = map(str,input().split())
  P[i] = int(P[i])
X = zip(S,P,index)
X = sorted(X,key = lambda x: (x[0],-x[1]),reverse = False)

S,P,index = zip(*X)
for i in range(N):
  print(index[i])

Solution (Python):
n = int(input())
spi = {}
for i in range(n):
    t = input().split()
    if t[0] in spi:
        spi[t[0]] += [(int(t[1]), i+1)]
    else:
        spi[t[0]] = [(int(t[1]), i+1)]

for e in spi:
    spi[e] = sorted(spi[e], key=lambda x: x[0], reverse=True)

spi = sorted(zip(*[spi.keys(), spi.values()]), key=lambda x: x[0])

for e in spi:
    for r in e[1]:
        print(r[1])

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


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

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

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

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

SP = {}

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


K = sorted(SP)

for k in K:
    SP[k].sort(reverse=True)
    for t in SP[k]:
        print(t[1])

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

dic = []
for n in range(N):
  S, P = map(str, input().split())
  name = S + str(100 - int(P)).zfill(3)
  dic.append(name)

dic_sorted = sorted(dic)

for r in dic_sorted:
  print(dic.index(r)+1)

Solution (Python):
N = int(input())
restaurants = [(lambda t: (t[0], int(t[1]), i))(input().split()) for i in range(N)]
restaurants.sort(key=lambda t:(t[0], -t[1]))

for r in restaurants:
    print(r[2]+1)

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

restaurants = {}

for i in range(n):
    s, p = [j for j in input().split()]
    if s in restaurants:
        restaurants[s].append([int(p), i])
    else:
        restaurants[s] = [[int(p), i]]

for ip in sorted(restaurants.items()):
     for i in sorted(ip[1], reverse=True):
         print(i[1] + 1)

Solution (Python):
from operator import itemgetter


def main():
    n = int(input())

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

    rest = sorted(rest, key=itemgetter(2), reverse=True)
    rest = sorted(rest, key=itemgetter(1))
    for i, _, _ in rest:
        print(i)


main()

Solution (Python):

n = int(input())
hash = {}
for i in range(n):
    s, p = input().split()
    p = int(p)
    if s in hash.keys():
        hash[s].append([i, p])
    else:
        hash[s] = list()
        hash[s].append([i, p])

hash = sorted(hash.items())
for k, v in hash:
    vs = sorted(v, key=lambda x: x[1], reverse=True)
    for i in vs:
        print(i[0]+1)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def LF(): return [float(x) for x in sys.stdin.readline().split()]


def LS(): return sys.stdin.readline().split()


def II(): return int(sys.stdin.readline())


def SI(): return input()


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

X = sorted(X.items())
for v in X:
    a = sorted(v[1], reverse=True)
    for i in a:
        print(i[1])

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

Solution (Python):
n = int(input())
s = [0]*n
p = [0]*n
w = [0]*n
for i in range(n):
    s[i], p[i] = input().split()
    p[i] = int(p[i])
    w[i] = [s[i], p[i],i+1]

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

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

Solution (Python):
N = int(input())
shops = [input().split() for _ in range(N)]
copy = shops.copy()
shops.sort(key=lambda x: (x[0], 1/(int(x[1])+1)))
for shop in shops:
    print(copy.index(shop)+1)

Solution (Python):

"""
Created on Sun May 26 20:55:50 2019

@author: Yamazaki Kenichi
"""

N = int(input())
sp = [list(map(str,input().split()))+[i] for i in range(N)]

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

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



for c in sp1:
    print(int(c[2])+1)

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

idx = [i+1 for i in range(n)]
s = []
p = []

for i in range(n):
    _s, _p = input().split()
    s.append(_s)
    p.append(int(_p))

for i in range(n-1):
    for j in range(i+1, n):
        if s[i] > s[j] or (s[i] == s[j] and p[i] < p[j]):
            idx[i], idx[j] = idx[j], idx[i]
            s[i], s[j] = s[j], s[i]
            p[i], p[j] = p[j], p[i]

for i in idx:
    print(i)

Solution (Python):
from operator import itemgetter
n=int(input())
info=[]
for i in range(n):
    s,p=input().split()
    info.append([s,int(p),i+1])
info=sorted(info)
memo=info[0][0]
l=[]
for k in range(n):
    if memo==info[k][0]:
        l.append(info[k][2])
    else:
        for j in range(len(l)):
            print(l[-1-j])
        l=[info[k][2]]
        memo=info[k][0]
for j in range(len(l)):
    print(l[-1-j])

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

shop_list = [[int('-'+j) if i==1 else j for i, j in enumerate(input().split())] for _ in range(n)]

intro_list = sorted(shop_list)

for shop in intro_list:
  print(shop_list.index(shop)+1)

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

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

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

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

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

R_list = {}
for i in range(N):
    S, P = map(str, input().split(" "))

    if S in R_list:
        l = R_list[S]
        l.append((int(P), i+1))
    else:
        l = [(int(P), i+1)]
        R_list[S] = l

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



for S in score_sorted:
    S[1].sort(reverse=True)
    for P in S[1]:
        print(P[1])

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

Solution (Python):
N = int(input())
Ss = [0] * N
Ps = [0] * N
cities = [0] * N
for i in range(N):
    l = input().split()
    Ss[i], Ps[i] = l[0], int(l[1])
    cities[i] = Ss[i]

cities = sorted(set(cities))

cities_dir = {}
for city in cities:
    cities_dir[city] = []

for i in range(N):
    cities_dir[Ss[i]].append((Ps[i], i))

for city in cities:
    vs = sorted(cities_dir[city], key=lambda x: x[0], reverse=True)
    for k in vs:
        print(k[1] + 1)

Solution (Python):
N = int(input())
SP_str = [list(input().split()) for i in range(N)]
SP = [[i[0],int(i[1])] for i in SP_str]


SP_sort = sorted(SP,key=lambda x: (x[0],-x[1]))
for i in range(N):
    a = SP.index(SP_sort[i])
    print(a+1)

Solution (Python):
N=int(input())
L = []
for i in range(N):
  T,P = input().split()
  L.append([i+1, T, int(P) ])
l_sorted = sorted(L, key=lambda x: (x[1], -x[2]))
for i in l_sorted:
  print(i[0])

Solution (Python):



from operator import itemgetter
n = int(input())
sp={}
for i in range(n):
    [name,value] = input().split()
    if sp.get(name) is None:
        sp[name] = [(int(value),i)]
    else:
        sp[name].append((int(value),i))


for key in sp.keys():
    sp[key] = sorted(sp[key], key=itemgetter(0))

    
sp = sorted(sp.items())

for s in sp:
    for p in s[1][::-1]:
        print(p[1]+1)

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

for i in range(N):
    s, p = input().split()
    SP.append({'name':s, 'point':int(p), 'num':int(i+1)})

SP.sort(key=lambda x: x['point'], reverse=True)
SP.sort(key=lambda x: x['name'])

for v in SP:
    print(v['num'])

Solution (Python):
from operator import itemgetter
N = int(input())
t_list = []
for i in range(N):
  a = list(map(str, input().split()))
  a[1] = int(a[1])
  a.append(i)
  t_list.append(a)
  

t_list = sorted(t_list, key=itemgetter(1), reverse=True)
t_list = sorted(t_list, key=itemgetter(0))
for j in range(N):
  print(t_list[j][2]+1)

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

ls = []

for i in range(n):
  s, p = map(str,input().split())
  sp = [s,int(p)]
  sp.append(i+1)
  ls.append(sp)
  
ls_sort = sorted(ls, key=lambda x: (x[0],-x[1]))

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

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

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

score_sorted = sorted(score, key=lambda x:(x[1], -x[2]), reverse=False)

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

Solution (Python):
import math
n = int(input())
h = []
for i in range(n):
    l = list(map(str, input().split()))
    l.append(i+1)
    h.append(l)

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

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

Solution (Python):
import sys
import os
from operator import itemgetter

N=int(input())

S=[0]*N
P=[0]*N
X=[0]*N
X2=[0]*N
for i in range(N):
    S[i], P[i] =  input().split()
    X[i]=S[i]+P[i]
    P[i]=int(P[i])

D=[list(x) for x in zip(*sorted(zip(P, S), key=itemgetter(0),reverse=True))]
S=D[1]
P=D[0]
D=[list(x) for x in zip(*sorted(zip(S, P), key=itemgetter(0)))]
S=D[1]
P=D[0]
for i in range(N):
    X2[i]=P[i]+str(S[i])
    print(X.index(X2[i])+1)

Solution (Python):
from operator import itemgetter
N = int(input())
S = [[] for i in range(N)]
for i in range(N):
    a = input().split()
    S[i].append(a[0])
    S[i].append(int(a[1]))
for i in range(N):
    S[i].append(i+1)
S = sorted(S, key=itemgetter(1),reverse=True)
S = sorted(S, key=itemgetter(0))

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

Solution (Python):
n = int(input())
sp = [input().split() for _ in range(n)]
sp2 = sorted(sorted(sp, key=lambda x: -int(x[1])), key=lambda x: x[0])
for t in sp2:
  print(sp.index(t)+1)

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

Solution (Python):

class Restaurant():
    def __init__(self, i, s, p):
        self.i = i
        self.s = s
        self.p = p

    def __eq__(self, other):
        return (self.s == other.s) and (self.p == self.p)

    def __lt__(self, other):
        return (self.s < other.s) or (self.p > other.p and self.s == other.s)

    def __ne__(self, other):
        return not self.__eq__(other)

    def __le__(self, other):
        return self.__lt__(other) or self.__eq__(other)

    def __gt__(self, other):
        return not self.__le__(other)

    def __ge__(self, other):
        return not self.__lt__(other)

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

for i in range(N):
    s, p = input().split()
    p = int(p)
    restaurants.append(Restaurant(i+1, s, p))

restaurants.sort()

for r in restaurants:
    print(r.i)

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

dict_ = {}

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

for key, item in sorted(dict_.items()):
    for p, i in sorted(item, key=lambda x:int(x[0]), reverse=True):
        print(i)

Solution (Python):



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

Solution (Python):


n = int(input())
d = []
for i in range(n):
    _s, _p = input().split()
    d.append({'number': i, 'city': _s, 'point': int(_p)})
sortedd = sorted(d, key = lambda x: (x['city'], -x['point']))
for n in sortedd:
    print(n['number'] + 1)

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

Solution (Python):
import numpy as np

N = int(input())
rests = []
evals = []

for n in range(N):
    i = input().split()
    rests.append(i[0])
    evals.append(int(i[1]))

rests = np.array(rests)
evals = np.array(evals)
nums = np.array([i + 1 for i in range(len(rests))])

order_by_name = np.argsort(rests)
rests = rests[order_by_name]
evals = evals[order_by_name]
nums = nums[order_by_name]
names = np.unique(rests)

for name in names:
    loc = np.where(rests == name)[0]
    if len(loc) == 1:
        pass
    else:
        start = loc[0]
        end = loc[-1] + 1
        order_by_eval = np.argsort(- evals[start:end])
        evals[start:end] = evals[start:end][order_by_eval]
        nums[start:end] = nums[start:end][order_by_eval]

for num in nums:
    print(num)

Solution (Python):
N = int(input())
List = [list(map(str,input().split())) for i in range(N)]

for i in range(N):
    List[i].append(i+1)
    List[i][1] = int(List[i][1])
List.sort(key=lambda x:x[1], reverse=True)
List.sort(key=lambda x:x[0])
for i in range(N):
    print("{}".format(List[i][2]))

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

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

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

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

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

arr=sorted(arr,key=lambda item:item[1],reverse=True)
arr=sorted(arr,key=lambda item:item[0])

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

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

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

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

city_dict = {}
for i,sp in enumerate(sp_list):
    s = sp[0]
    p = sp[1]
    if s in city_dict:
        city_dict[s] = city_dict[s]+[[p,i+1]]
    else:

        city_dict[s] = [[p,i+1]]

from operator import itemgetter
for k, v in sorted(city_dict.items()):

    v.sort(key=itemgetter(0))
    for v0,v1 in v[::-1]:
        print(v1)

Solution (Python):

N= int(input())
sa=[]
for i in range(N):
  tmp=input().split()
  sa.append([tmp[0],100-int(tmp[1]),i+1])
sa = sorted(sa)

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

Solution (Python):
n=int(input())
l=[]
for i in range(n):
    x,y=map(str,input().split())
    l.append([x,y,i+1])
l.sort()
flag=0
x=[]
for i in range(n-1):
    x.append([int(l[i][1]),int(l[i][2])])
    if l[i][0]==l[i+1][0]:
        pass
    else:
        x.sort()
        x.reverse()
        for j in range(len(x)):
            print(int(x[j][1]))
        x.clear()
x.append([int(l[n-1][1]),int(l[n-1][2])])
if x!=[]:
    x.sort()
    x.reverse()
    for j in range(len(x)):
            print(int(x[j][1]))
else:
    print(int(x[n-1][1]))

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

Solution (Python):
from operator import itemgetter
N = input()
t = []
for i in range(N):
	s,p = raw_input().split()
	p2 = int(p)
	t.append([s,p2,i+1])
t2 = sorted(t,key = itemgetter(1), reverse = True)
t3 = sorted(t2,key = itemgetter(0))
for c in t3:
	print(c[2])

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

new_list = sorted(list, key=lambda x: (x[0], x[1]))
for k in new_list:
    print(k[2])

Solution (Python):
n = int(input())
s = []
p = []
items = []
for i in range(n):
    a, b = (x for x in input().split())
    s.append(a)
    p.append(int(b))
    items.append({'i':i+1, 's':a, 'p':-int(b)})
sorted_items = sorted(items,key = lambda x: (x['s'],x['p']))
for i in range(n):
    print(sorted_items[i]['i'])

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

A = []


for i in range(N):
    Si , Pi = input().split()
    Pi = int(Pi) 

    A.append([i,Si,Pi])


second = lambda A : A[1]
third = lambda A : A[2]


A.sort(key=third,reverse=True)
A.sort(key=second)

for target in A:
    print(target[0] + 1)

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

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

[print(i) for _, _, i in rs]

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from copy import copy
import numpy as np
from numpy.fft import fft, ifft
from fractions import gcd


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


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()

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

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

lis=sp.copy()
sp.sort(key=lambda x:(x[0],-x[1]))




for x in sp:
    print(lis.index(x)+1)

Solution (Python):
class Shop:

    def __init__(self, s, p):
        self.s = str(s)
        self.p = int(p)

    def __eq__(self, other):
        return (self.s, self.p) == (other.s, other.p)

    def __ne__(self, other):
        return not self.__eq__(other)

    def __lt__(self, other):
        return (self.s, -self.p) < (other.s, -other.p)

    def __le__(self, other):
        return (self.s, -self.p) < (other.s, -other.p)


def read():
    N = int(input().strip())
    shops = []
    for i in range(N):
        s, p = list(input().strip().split())
        shops.append(Shop(s, p))
    return N, shops


def solve(N, shops):
    order = sorted(range(N), key=lambda k: shops[k])
    return order


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    for i in outputs:
        print("%d" % (i + 1))

Solution (Python):
from sys import stdin

def main():
     n = int(stdin.readline())
     a = [[ x for x in stdin.readline().split()] for i in range(n)]
     b = [ i for i in a]
     a.sort(key=lambda x:100-int(x[1]))
     a.sort(key=lambda x:x[0])
     for i in a:
          for j in range(n):
               if i == b[j]:
                    print(j+1)
                    break
if __name__ == '__main__':
     main()

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

NSP = list()

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

NSP.sort(key=lambda x: x[2])
NSP.reverse()
NSP.sort(key=lambda x: x[1])

for n in range(N):
    print(NSP[n][0])

Solution (Python):
n = int(input())
cities = set()
d = dict()
for i in range(n):
    s, p = input().split()
    cities.add(s)
    d.setdefault(s, [])
    d[s].append((i+1, int(p)))
cities = list(cities)
cities.sort()
for c in cities:
    l = d[c]
    l.sort(key=lambda i: -i[1])
    for i in l:
        print(i[0])

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

Solution (Python):


import sys
input = sys.stdin.readline

N = int(input())



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

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

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

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

Solution (Python):
n=int(input())
sp = {}
for i in range(n):
  s,p = list(input().split(' '))
  if s not in sp.keys():
    sp[s] = [[int(p), i+1]]
  else:
    sp[s].append([int(p),i+1])
for a in sorted(sp.items()):
  for p,i in sorted(a[1], reverse=True):
    print(i)

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

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

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

count = 0
while count != n:
	for i in range(n):
		if rest_sort[count] == rest[i]:
			print(i+1)
	count += 1

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

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

d = sorted(d.items(), key=lambda x:x[0])
d = [sorted(x[1], reverse=True)  for x in d]

for xs in d:
    for x in xs:
        print(x[1])

Solution (Python):
n = int(input())
sp_list = []
for i in range(n):
    l = input().split()
    l.append(str(i))
    sp_list.append(l)

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

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

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

Solution (Python):
from collections import defaultdict
d = defaultdict(list)
N = int(input())

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

l = list(d.items())
l.sort()

for s,t in l:
	t.sort(reverse = True)
	for a,b in t:
		print(b)

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

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

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

Solution (Python):

def main():
    N = int(input())
    rest = []
    for i in range(N):
        si, tempP = input().split()
        pi = int(tempP)
        rest.append([i+1, si, pi])

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


if __name__ == "__main__":
    main()

Solution (Python):
from operator import itemgetter
N = int(input())
l = []
for i in range(N):
  a = input().split()
  a[1] = int(a[1])
  a.append(i+1)
  l.append(a)
l.sort(key=itemgetter(1),reverse=True)
l.sort(key=itemgetter(0))
for j in l:
  print(j[2])

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

rest_dict = {}


rest_arr = []
for i in range(N):
    tmp = input().split()
    rest_arr.append(tmp)

for i in range(N):
    if rest_arr[i][0] in rest_dict:
        rest_dict[rest_arr[i][0]].append(int(rest_arr[i][1]))
    else:
        rest_dict[rest_arr[i][0]] = [int(rest_arr[i][1])]
    rest_dict[rest_arr[i][0]] = sorted(rest_dict[rest_arr[i][0]], key=lambda x: -x)



rest_dict = sorted(rest_dict.items())


def search_num(rest, num):
    for i in range(N):
        if rest_arr[i][0] == rest and int(rest_arr[i][1]) == num:
            return i + 1
 

for i in rest_dict:
    for j in i[1]:
        print(search_num(i[0], j))

Solution (Python):
import sys
from operator import itemgetter

fin = sys.stdin.readline
N = int(fin())
conditions = [[elem for elem in fin().split()] + [idx+1] for idx in range(N)]
conditions = [[x[0], int(x[1]), x[2]] for x in conditions]

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

[print(x[2]) for x in conditions]

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

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









N = int(stdin.readline().rstrip().split()[0])
S=[]
for i in range(N):
  s, p = [x for x in stdin.readline().rstrip().split()]
  S.append(s+str(999-int(p)))

Sidx=sorted(S)


for i in range(N):
  print(S.index(Sidx[i])+1)