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())
s = []
p = []
for i in range(n):
    si, pi = input().split()
    s.append(si)
    p.append(int(pi))

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

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

restaurant_list = [list(input().split()) for i in range(N)]

sorted_list = sorted(sorted(restaurant_list, reverse = True, key=lambda x:int(x[1])), key=lambda x:x[0])

for restaurant in sorted_list:
    for i, original in enumerate(restaurant_list):
        if restaurant == original:
            print(i+1)

Solution (Python):
from collections import defaultdict
l = defaultdict(list)

n = int(input())


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

for k in sorted(l.keys()):
    for i in sorted(l[k], key=lambda t: t[1], reverse=True):
        print(i[0])

Solution (Python):



import math
import re

def main(params):
    n = int(params[0])
    sp = params[1:]
    cnt = 0
    ipt = {}
    for i in sp:
        cnt += 1
        s,p = i.split()
        p = int(p)
        if s in ipt:
            ipt[s].append([p,cnt])
        else:
            ipt[s] = [[p,cnt]]
    keys = ipt.keys()
    keys.sort()
    for k in keys:
        if len(ipt[k]) == 1:
            print ipt[k][0][1]
        else:
            ranks = ipt[k]
            ranks.sort()
            ranks.reverse()
            for i in ranks:
                print i[1]

if __name__ == "__main__":
    n = int(raw_input())
    cnt = n 
    params = [n]
    for i in range(cnt):
        param = raw_input()
        params.append(param)
    main(params)

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

arr = []

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

arr2 = sorted(arr, key=lambda x: x[1], reverse=True)
arr3 = sorted(arr2, key=lambda x: x[0], reverse=False)

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

Solution (Python):
N = int(input())
R = []
for i in range(N):
  l = input().split()
  R.append((l[0], (-1)*int(l[1]), i))

R.sort()
for i in range(N):
  print(R[i][2]+1)

Solution (Python):
N=int(input())
SP=[]
for i in range(N):
  a, b=input().split()
  SP+=[[a,int(b)]]
SP2=sorted(range(N), key=lambda x: (SP[x][0], -SP[x][1]))
for i in range(N):
  print(SP2[i]+1)

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

X = []

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

X.sort()

for i in range(0, n):
    print(X[i][2] + 1)

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

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

Solution (Python):
import math

def parse(line, i):
    [s, p] = line.split()
    
    return [s, int(p), i]

input_n = int(input())
input_S = [parse(input(), i) for i in range(input_n)]

for line in sorted(input_S, key=lambda x: (x[0], -x[1])):
    print(line[2] + 1)

Solution (Python):
N = int(input())
ans = []
for i in range(N):
    S,P = map(str,input().split(" "))
    P = int(P)
    ans.append([S,P,i+1])
sort_list = sorted(ans,key = lambda x:(x[0],-x[1]))
for i in range(N-1):
    if sort_list[i][0] == sort_list[i+1][0]:
        if sort_list[i][1] < sort_list[i+1][1]:
            temp = sort_list[i][1]
            sort_list[i][1] = sort_list[i+1][1]
            sort_list[i+1][1] = temp

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

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

restaurants.sort(key=lambda i: (i[1], -i[2]))

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

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

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

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

l.sort(key=lambda e:-e[1])
l.sort(key=lambda e:e[0])
print('\n'.join(str(i[2]) for i in l))

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

n = int(stdin.readline().rstrip())

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

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

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

data = sorted(data, key=lambda t: t[0]+str(100 - t[1]).zfill(3))

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

Solution (Python):
n=int(input())
res=[]
city=[]
for i in range(n):
    s,p=map(str,input().split())
    p=int(p)
    res.append([s,p,i+1])
R=sorted(res,key=lambda x : x[1],reverse=True)
Res=sorted(R,key=lambda x : x[0])

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

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

for i in range(n):
    s, p = input().split()
    p = "{:04}".format(100 - int(p))
    shops.append((s, p, i + 1))

shops = sorted(shops)
for shop in shops:
    print(shop[2])

Solution (Python):

n = int(input())

shop = list()

for i in range(n):
    input_lines = input().split(" ")
    shop.append([input_lines[0],100-int(input_lines[1]),i+1])
    
shop = sorted(shop)

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

Solution (Python):


from collections import defaultdict
n = int(input())
li = defaultdict(list)
for i in range(n):
    s, p = list(input().split())
    li[s].append((int(p), i+1))
ks = sorted(li)
for k in ks:
    kk = sorted(li[k], key=lambda x: x[0],  reverse=True)
    for i in kk:
        print(i[1])

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

l = []
for i, (s, p) in enumerate(sp):
    l.append((s, -int(p), i + 1))

l.sort()

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

Solution (Python):
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint

import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) 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 MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    
    x = root(x)
    y = root(y)
    if x == y:
        return
    
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  
        return x
    else:
        node[x] = root(node[x])  
        return node[x]
def dfs(v):
    
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  
            continue
        if visited[v2] == True:  
            continue
        dfs(v2)


n = II()
sp = [LS() for i in range(n)]
for i, s in enumerate(sp):
    s.append(i+1)
sp = sorted(sp, key=lambda x: (x[0], -int(x[1])))
for i in sp:
    print(i[2])

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

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

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

for d in List:
    k,L=d
    L.sort(key=lambda x:x[0],reverse=True)
    for l in L:
        print(l[1])

Solution (Python):
from operator import itemgetter

n=int(input())
arr=[]
for z in range(n):
  name,point=input().split(" ")
  point=int(point)
  arr.append((name,point,z+1))
  arr=sorted(arr,key=itemgetter(1),reverse=True)
  arr=sorted(arr,key=itemgetter(0))

for z in arr:
  print(z[2])

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

Solution (Python):
n= int(input())
dic = {}
for i in range(1, n+1):
    s, p = input().split()
    if s in dic.keys():
        dic[s].append((int(p), i))
    else:
        dic[s]=[(int(p), i)]
List = sorted(dic.items())
for li in List:
    ll = sorted(li[1], reverse = True, key = lambda x:x[0])
    for lli in ll:
        print(lli[1])

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

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

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

Solution (Python):
N = int(input())
S_P = { i+1: input().split() for i in range(N)}
for i in range(N):
    S_P[i+1][1] = int(S_P[i+1][1])
S_P = sorted(S_P.items(), key=lambda x:x[1][1], reverse=True)
S_P = sorted(S_P, key = lambda x:x[1][0])
for i in range(N):
    print(S_P[i][0])
print()

Solution (Python):
n=int(raw_input())
checck = {}
for i in xrange(n):
    s,p=map(str,raw_input().split())
    p=int(p)
    if s in checck:
        checck[s].append((p,i))
    else:
        checck.update({s:[(p,i)]})
check=list(checck)
check=sorted(check)

for i in check:
    l=checck[i]
    l=sorted(l)
    for j in xrange(len(l)-1,-1,-1):
        print l[j][1]+1

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

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

for x,y,z in R:
    print(z)

Solution (Python):

N = int(input())
temp = []
l = []
for n in range(N):
    temp = input().split()
    l.append([temp[0], int(temp[1]), n+1])
    temp = []

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

Solution (Python):
from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    sps = [(i, x.split()) for i,x in enumerate(stdin.readlines())]
    sps = [(x[0], x[1][0], 100-int(x[1][1])) for x in sps]
    sps.sort(key=lambda x: (x[1], x[2]))

    for i,s,p in sps:
        print(i+1)
    
if __name__=='__main__':
    main()

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

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

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

Solution (Python):
n = int(input())
sp =[]
for i in range(n):
    a, b = input().split()
    sp.append([a, int(b), i + 1])
sp.sort()
s = 0
ans = []
for i in range(1, n):
    if sp[s][0] == sp[i][0]:
        continue
    else:
        ans.extend(sp[s:i:][::-1])
        s = i
ans.extend(sp[s::][::-1])
for i in ans:
    print(i[2])

Solution (Python):

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


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

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

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

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

Solution (Python):
def main():

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

    d = {}
    for i in range(N):
        if S[i] in d.keys():
            d[S[i]].append((i+1, P[i]))
        else:
            d[S[i]] = [(i+1, P[i])]

    for key in sorted(d.keys()):
        a = d[key]
        a = sorted(a, key=lambda x: -x[1])
        for i, score in a:
            print(i)
            

main()

Solution (Python):
N = int(input())
SP = []
for _ in range(N):
    s, p = input().split()
    SP.append((s, int(p)))
    
restaurants = SP[:]

restaurants = [(i+1, s, p) for i, (s, p) in enumerate(restaurants)]

sort_key = lambda x:(x[1],-x[2])
restaurants = sorted(restaurants, key = sort_key)


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

Solution (Python):
n=int(input())
sp_list=[]
for i in range(n):
	s,p=map(str,input().split())
	sp_list.append({'key': i+1,'city':s,'point':int(p)})
sp_list=sorted(sp_list,key = lambda x: (x['city'], -x['point']))
for i in sp_list:
	print(i['key'])

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


shop_dict = {}
for i in range(1,N+1):
    input_li = input().split()
    s = input_li[0]
    p = int(input_li[1])
    if s not in shop_dict.keys():
        shop_dict[s] = {}
    shop_dict[s][p] = i

all_city = list(shop_dict.keys())
all_city.sort()

for city in all_city:
    pt_list = list(shop_dict[city].keys())
    pt_list.sort(reverse=True)
    for pt in pt_list:
        print(shop_dict[city][pt])

Solution (Python):
N = int(input())
s = []
SP = {}
for i in range(N):
    S, P = input().split()
    P = int(P)
    if S not in SP:
        SP[S] = [[P, i+1]]
    else:
        SP[S].append([P, i+1])
    if S not in s:
        s.append(S)
s.sort()

for s_ in s:
    tmp = SP[s_]
    tmp.sort(reverse=True)
    for x in tmp:
        print(x[1])

Solution (Python):
from operator import itemgetter
n=int(input())
data=[]
for i in range(n):
    a = list(input().split())
    a[1] = int(a[1])
    a.append(i+1)
    data.append(a)
data = sorted(data, key=itemgetter(1), reverse=True)
data = sorted(data, key=itemgetter(0), reverse=False)
for i in data:
    print(i[2])

Solution (Python):
N = int(input())
bag = []
shi = []
for i in range(N):
    s, p = input().split()
    p = int(p)
    shi.append(s)
    
    bag.append((s, p, i))

sorted_bag = sorted(bag, key=lambda x:x[0])
sorted_shi = sorted(list(set(shi)))


dic = {}
for s, p, i in bag:
    if s not in dic.keys():
        dic[s] = [[p, i+1]]
    else:
        dic[s].append([p, i+1])

for s in sorted_shi:
    if len(dic[s]) == 1:
        print(dic[s][0][1])
    else:
        so = sorted(dic[s], key=lambda x:x[0])[-1::-1]
        for e in so:
            print(e[1])

Solution (Python):
l = raw_input().split()
N = int(l[0])

S = []
P = []

for i in range(N):
    l = raw_input().split()
    S.append(l[0])
    P.append(int(l[1]))

S1 = []
for i in range(N):
    S1.append([i + 1, S[i], P[i]])


S1.sort(key = lambda x: -x[2])
S1.sort(key = lambda x: x[1])

for s in S1:
    print(s[0])

Solution (Python):
import math
import fractions
import copy

def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n = ip()                                     









a =[]
for i in range(n):
    a.append(input().split())
    a[i][1] = 100-int(a[i][1])
b = copy.copy(a)
a.sort()
for i in range(n):
    print(b.index(a[i])+1)

Solution (Python):
n = int(input())
rest = []
for i in range(n):
  name,point = input().split()
  rest.append((name,-int(point),i))

rest.sort()
for i in range(n):
  print(rest[i][2]+1)

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

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

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

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

Solution (Python):
n=int(input())
List=[]
for i in range(n):
    s,p=input().split()
    p=int(p)
    List.append([s,p,i+1])
List.sort()
S=List[0][0]
k=[]
for i in List:
    if i[0]==S:
        k.append([i[1],i[2]])
    else:
        k.sort(reverse=True)
        for j in k:
            print(j[1])
        S=i[0]
        k=[]
        k.append([i[1],i[2]])
k.sort(reverse=True)
for j in k:
    print(j[1])

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

Solution (Python):
n = int(raw_input())
r = []
for i in xrange(1,n+1):
	rest,score = raw_input().split()
	score=int(score)
	r.append((rest,score,i))
r = sorted(r,key=lambda x:(x[0], -x[1], x[2]))
for x in r:
	print x[2]

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
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()
from collections import Counter

def main():
    N = II()
    SP = []
    for i in range(1, N + 1):
        s, p = LS()
        p = int(p)
        SP.append([s + '{:06}'.format(100 - p), i])
    SP.sort()
    for _, id in SP:
        print(id)
    return

main()

Solution (Python):


from sys import stdin

input = stdin.readline

N = int(input())

SP = []

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

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

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

Solution (Python):
N =int(input())
S=[]
for i in range(N):
    s, p = input().split()
    S.append([s, -1*int(p), i])


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

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

Solution (Python):



def solv(ds):
    ds = sorted(ds, key=lambda d: -d[2])
    ds = sorted(ds, key=lambda d: d[1])
    return ds


if __name__ == '__main__':

    n = int(input())

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

    ans = solv(ds)

    for a in ans:
        print(a[0])

Solution (Python):

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

for i in range(n):
    r, p = input().strip().split()
    rs.append((r, -int(p), i+1))

rs.sort()
for r, p, s in rs:
    print(s)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = []

for i in range(n):
  s,p = nn()
  a.append([s,-int(p),i])

a = sorted(a)

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

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

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

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

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

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

l = []

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

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

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

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

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

sorted_stores = sorted(list(stores.keys()))

for s in sorted_stores:
    stores[s].sort(key=lambda x: x[0], reverse=True)

    for ss in stores[s]:
        print(ss[1])

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

Solution (Python):
N = int(input())
book = []
for i in range(1, N+1):
    s, p = input().split(" ")
    book.append((s, -int(p), i))
book.sort()
for r in book:
    print(r[2])

Solution (Python):
n=int(input())
name=[]
m=[]
for i in range(1,n+1):
  s,p=input().split()
  p=int(p)
  if s not in name:
    name+=[s]
  m+=[[i,s,p]]
name.sort()
for n in name:
  aa=[]
  for a in m:
    if a[1]==n:
      aa+=[a]
  aa.sort(reverse=1,key=lambda x:x[2])
  for a in aa:
    print(a[0])

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

N = int(stdin.readline().rstrip())
SP = [stdin.readline().rstrip().split() for _ in range(N)]
for i in range(N):
    SP[i].append(i+1)
    SP[i][1] = int(SP[i][1]) * -1

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

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

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

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

mem.sort()

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

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

result = []
for i in range(n):
    tmp1,tmp2 = input().split(" ") 
    result.append((tmp1, int(tmp2),i+1))

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

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

Solution (Python):
N = int(input())
SP = sorted([[_ for _ in input().split()] + [i] for i in range(N)],
            key=lambda xs: xs[0] + 'Z' * (100 - int(xs[1])))
[print(_[2] + 1) for _ in SP]

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

i  = lambda: int(input())
ms = lambda: map(str, input().split())

N = i()

rank = dict()
for i in range(N):
  S, P = ms()
  if S in rank.keys():
    rank[S][i+1] = int(P)
  else:
    rank[S] = {i+1: int(P)}

for k, v in sorted(rank.items()):
  for vk, vv in sorted(rank[k].items(), key=lambda x:x[1], reverse=True):
    print(vk)

Solution (Python):


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

r = [(k,v) for k, v in ls.items()]
r.sort(key=(lambda x: x[0]))

for l in r:
    vals = l[1]
    vals.sort(key=(lambda x: x[1]), reverse=True)
    for v in vals:
        print(v[0])

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

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

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

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

el = int(input())

for ei in range(1,el+1):
    s,p = input().split()
    p = int(p)
    d[s] = d[s] + [(p,ei)]

d = list(d.items())
d.sort(key=lambda spei: spei[0])
for spei in d:
    peis = spei[1]
    peis.sort(key=lambda pei: -pei[0])
    for pei in peis:
        print(pei[1])

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

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

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

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

from operator import itemgetter
shops = sorted(shops, key=itemgetter(2), reverse=True)
shops = sorted(shops, key=itemgetter(1))

for num, s, p in shops:
    print(num)

Solution (Python):
def getlist():
	return list(map(int, input().split()))

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

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

L = sorted(L)

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

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

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

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


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

Solution (Python):
from collections import defaultdict
N=int(input())
SP=defaultdict(list)
S=set()
for i in range(N):
    s,p=input().split()
    p=int(p)
    SP[s].append([p,i+1])
    S.add(s)
S=list(S)
S.sort()
for i in S:
    l=SP[i]
    l.sort(reverse=True)
    for k in l:
        print(k[1])

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

Solution (Python):


N = int(input())
S_P = [input().split() for _ in range(N)]
S_P = [tuple([s_p[0], int(s_p[1]), i]) for i, s_p in enumerate(S_P)]

S_P = sorted(S_P, key=lambda x: x[1])[::-1]
S_P = sorted(S_P, key=lambda x: x[0])
print("\n".join([str(x[2] + 1) for x in S_P]))

Solution (Python):
n = int(input())
a = []
for _ in range(n):
  s,p = input().split()
  a.append((s,p))
b = sorted(a,key=lambda x:-int(x[1]))
b = sorted(b,key=lambda x:x[0])
for _ in range(n):
  for i in range(n):
    if b[_] == a[i]:
      print(i+1)
      break

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

Solution (Python):
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


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


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N = I()
    
    city = set()
    sp = []
    for i in range(N):
        i += 1
        s, p = input().split()
        p = int(p)
        sp.append([s, p, i])
        city.add(s)
    city = list(city)
    city.sort()
    ans = [[] for i in range(len(city))]
    sp.sort(reverse=True, key=lambda x: x[1])
    for s, p, i in sp:
        for j, c in enumerate(city):
            if s == c:
                ans[j].append(i)

    for a in ans:
        print(*a, sep="\n")


if __name__ == '__main__':
    main()

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

Solution (Python):
N = int(input())
X = [list(input().split()) for _ in range(N)]
for i, t in sorted(enumerate(X), key=lambda x: (x[1][0], -int(x[1][1]))):
  print(i + 1)

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

Solution (Python):
N = int(input())
SP = [list(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.sort(key=lambda x:(x[0],-x[1]))

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

Solution (Python):
N = int(input())
restaurant = []
for i in range(N):
    Sn, Pn = input().split()
    Pn = int(Pn)
    restaurant.append([i, Sn, -1 * Pn])

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

Solution (Python):
n = int(input())
sp=[]
for i in range(n):
    s1,p1 = map(str,input().split())
    sp.append([i+1,s1,int(p1)])
sp = list(reversed(sorted(sp,key=lambda x:x[2])))
sp = sorted(sp,key=lambda x:x[1])
for i in range(n):
    print(sp[i][0])

Solution (Python):
from collections import defaultdict

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

for city in sorted(d):
    l = d[city]
    l.sort(reverse=True)
    for p, i in l:
        print(i)

Solution (Python):

import sys


def solve(N: int, S: "List[str]", P: "List[int]"):
    merged_list = [[i+1,s,p] for i, (s, p) in enumerate(zip(S, P))]
    merged_list = sorted(merged_list, key = lambda x:(x[1], -x[2]))
    for i in range(N):
        print(merged_list[i][0])
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = [str()] * (N)  
    P = [int()] * (N)  
    for i in range(N):
        S[i] = next(tokens)
        P[i] = int(next(tokens))
    solve(N, S, P)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
res = dict()
for i in range(N):
    S, P = input().split()
    if S in res.keys():
        res[S].append([int(P),i+1])
        res[S].sort(reverse = True)
    else:
        res[S] = [[int(P), i+1]]
dct = sorted(res.items())
for name, plist in dct:
    for i in range(len(plist)):
        print(plist[i][1])

Solution (Python):
from sys import stdin
input = stdin.readline

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

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

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

Solution (Python):
from operator import itemgetter
n = int(input())
A = []
for i in range(1, n+1):
    tmp = input().split()
    tmp[1] = -int(tmp[1])
    tmp.append(i)
    A.append(tmp)
A = sorted(A, key=itemgetter(0,1))
for i in range(n):
    print(A[i][-1])

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

Solution (Python):
N = int(input())
SP_list = [(str(i) + " " + input()).split() for i in range(1, N+1)]
key = lambda sp: (sp[1], int(sp[2])*(-1))
sorted_SP_list = sorted(SP_list, key=key)
for i, s, p in sorted_SP_list:
    print(i)