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

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

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

main()

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

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

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

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

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

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

for i in sorted(res_keys):
    for j in sorted(dic[i])[::-1]:
        ans = res.index([i, j])
        print(ans + 1)

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

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

Solution (Python):
from operator import itemgetter

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

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

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

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

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

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

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

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

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

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

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

arr.sort()

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

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

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

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

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

A = []

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

A.sort()

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

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

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

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

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

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

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

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

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

st = 0

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

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

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

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

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

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


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

for i in c:
  print(r[i]+1)

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

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

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

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

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

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

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

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

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

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

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

Solution (Python):

import sys


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



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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

for item in arr2:
    print(item[0])

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

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

s.sort()

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

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

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

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

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

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

for i in sorted(l):
    print(i[2] + 1)

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

Solution (Python):
import numpy as np

N=int(input())

restaurant={}

for i in range(N):
  temp=input().split()
  restaurant.setdefault(temp[0], []).append([int(i+1), int(temp[1])])
  
keys=[]
for key in restaurant:
  keys.append(key)
  
keys.sort()
for key in keys:
  temp=np.array(restaurant[key])
  temp=temp[np.argsort(temp, axis=0)[::-1, 1]]
  for i in range(temp.shape[0]):
    print(temp[i, 0])

Solution (Python):
N=int(input())
l=[]
for i in range(N):
  l.append(list(input().split()))
  l[i][1]=int(l[i][1])
l1=sorted(l,key=lambda x:x[1],reverse=True)
l2=sorted(l1,key=lambda x:x[0])
for i in range(N):
  print(l.index(l2[i])+1)

Solution (Python):
n = int(input())
R = [list(input().split()) for i in range(n)]
for i in range(n):
  R[i][1] = int(R[i][1])
sR = sorted(R, key=lambda x: x[1], reverse=True)
sR = sorted(sR, key=lambda x: x[0])
A = []
for i in range(n):
  print((R.index(sR[i]) + 1))

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

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

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

restaurants = []

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

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

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

Solution (Python):
from operator import itemgetter

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

SP.sort(key=itemgetter(1, 2))
for x in SP:
    print(x[0] + 1)

Solution (Python):
from operator import itemgetter

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

D = {}
for i, s, p in SP:
    if not D.get(s):
        D[s] = []
    D[s].append([i, p])

for k, v in D.items():
    v.sort(key=itemgetter(1), reverse=True)

S = sorted(D.keys())



for si in S:
    ds = D.get(si)
    for i, v in ds:
        print(i + 1)

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

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

data = []
for i in range(N):
    name, point = input().split()
    data.append({'id': i + 1, 'name': name, 'point': 100 - int(point)})

data.sort(key=lambda x: [x['name'], x['point']])

res = [d['id'] for d in data]

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

Solution (Python):
n=int(input())
l=[input().split() + [i+1] for i in range(n)]
l=sorted(l,key=lambda x:(x[0],-int(x[1])))
print(*[s[2] for s in l],sep='\n')

Solution (Python):
n=int(input())
l=[input().split() + [i+1] for i in range(n)]
l=sorted(l,key=lambda x:(x[0],-int(x[1])))
print(*[s[2] for s in l],sep='\n')

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

Solution (Python):
from collections import defaultdict

dic = defaultdict(list)
n = int(input())

for no in range(1, n+1):
    city, point = input().split()
    dic[city].append([int(point), no])

for city in sorted(dic):
    for point, no in sorted(dic[city], reverse=True):
        print(no)

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

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

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

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

for key in dct.keys():
    dct[key].sort()
    dct[key].reverse()
dct = sorted(dct.items())

for store in dct:
    for p in store[1]:
        print(score.index(p)+1)

Solution (Python):
N = int(input())
S = [0] * N
P = [0] * N

n = [i for i in range(N)]

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

items = zip(S, P, n)
items = sorted(items, key = lambda x:(x[0], -x[1]))

for S, P, n in items:
    print(n + 1)

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

Solution (Python):
n=int(input())
A=[[0]*3 for i in range(n)]
for i in range(n):
    a,b=map(str,input().split())
    b=int(b)
    A[i][0],A[i][1],A[i][2]=a,-b,i+1
A.sort()

for i,a in enumerate(zip(*A)):
	if i==2:print(*a,sep='\n')

Solution (Python):
from operator import itemgetter
n = int(input())
restaurants = []
for i in range(n):
    a,b = input().split()
    restaurants.append([i,a,int(b)]) 

for restaurant in sorted(sorted(restaurants,key = itemgetter(2),reverse=True),key = itemgetter(1)):
    print(restaurant[0]+1)

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

from collections import deque

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


if __name__ == "__main__":
    main()

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

class Restaurant:
    def __init__(self, id=None, name=None, score=None):
        self.id = id
        self.name = name
        self.score = score

r = [None for _ in range(n)]

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

r.sort(key=lambda x:(x.name, -x.score))

for i in range(n):
    print(r[i].id)

Solution (Python):
import sys


def solve(N: int, S: "List[str]", P: "List[int]"):
    data = list(zip(S, map(lambda x: -x, P), range(1, N + 1)))
    data.sort()
    return "\n".join(str(t[2]) for t in data)


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))
    ans = solve(N, S, P)
    if ans is not None:
        print(ans)

if __name__ == "__main__":
    main()

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

cookbook = [0] * N

for n in range(N):
    line = input().split()
    s = line[0]
    p = int(line[1])
    cookbook[n] = (n + 1, s, p)

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

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

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

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

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

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

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

l.sort()
for a,p,i in l:
    print(i)

Solution (Python):
def solve():
  n = int(input())
  query = []
  for i in range(n):
    s,p = input().split()
    query.append((s+str(900-int(p)),i+1))
  query.sort()
  for i in range(n):
    print(query[i][1])
solve()

Solution (Python):
def solve():
  n = int(input())
  query = []
  for i in range(n):
    tmp = input()
    s,p = tmp.split()
    p = str(90000000-int(p))
    s = s+p
    query.append((s,i+1))
  query.sort()
            
    
  for i in range(n):
    print(query[i][1])
solve()

Solution (Python):
def solve():
  n = int(input())
  query = []
  for i in range(n):
    tmp = input()
    s,p = tmp.split()
    query.append((s,p,i+1))
  query.sort()
  count = 0
  while count<n/2:
    count += 1
    for i in range(n):
      for j in range(i+1,n):
        if query[i][0] == query[j][0]:
          if int(query[i][1]) <int(query[j][1]):
            buf = query[i]
            query[i] = query[j]
            query[j] = buf
            
    
  for i in range(n):
    print(query[i][2])
solve()

Solution (Python):
def solve():
  n = int(input())
  query = []
  for i in range(n):
    tmp = input()
    s,p = tmp.split()
    query.append((s,p,i+1))
  query.sort()
  count = 0
  while count<n:
    count += 1
    for i in range(n):
      for j in range(i+1,n):
        if query[i][0] == query[j][0]:
          if int(query[i][1]) <int(query[j][1]):
            buf = query[i]
            query[i] = query[j]
            query[j] = buf
            
    
  for i in range(n):
    print(query[i][2])
solve()

Solution (Python):
def solve():
  n = int(input())
  query = []
  for i in range(n):
    tmp = input()
    s,p = tmp.split()
    query.append((s,p,i+1))
  query.sort()
  count = 0
  while count<1000:
    count += 1
    for i in range(n):
      for j in range(i+1,n):
        if query[i][0] == query[j][0]:
          if int(query[i][1]) <int(query[j][1]):
            buf = query[i]
            query[i] = query[j]
            query[j] = buf
            
    
  for i in range(n):
    print(query[i][2])
solve()

Solution (Python):
N = int(input())
list_r = []
for i in range(N):
    a,b = input().split()
    list_r.append((i+1, a, int(b)))
sorted_list=sorted(list_r, key=lambda x:(x[1],-x[2]))

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

Solution (Python):
def main():
    N = int(input())
    S, P = [], []
    for _ in range(N):
        si, pi = input().split()
        S.append(si)
        P.append(int(pi))

    d = dict()
    for i in range(N):
        if S[i] not in d:
            d[S[i]] = [[P[i], i+1]]
        else:
            d[S[i]].append([P[i], i+1])
    output = []

    cities = sorted(d.keys())
    for c in cities:
        output += [x[1] for x in sorted(d[c], key = lambda x: x[0], reverse = True)]
    return output

if __name__ == '__main__':
    output = main()
    for i in range(len(output)):
        print(output[i])

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


if __name__ == "__main__":
    test()

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

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

Solution (Python):
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
SP = [[x for x in input().split()] for _ in range(n)]
ans_list = defaultdict(list)
for i, sp in enumerate(SP):
    ans_list[sp[1]] = i

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


for x in li:
    print(ans_list[x[1]]+1)

Solution (Python):
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
SP = [[x for x in input().split()] for _ in range(n)]
ans_list = defaultdict(list)
for i, sp in enumerate(SP):
    ans_list[sp[1]] = i

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


for x in li:
    print(ans_list[x[1]]+1)

Solution (Python):
n = int(input())
a = [list(input().split()) for i in range(n)]
d = sorted(set([i[0] for i in a]))
for i in a:
  for j in range(len(d)):
    if i[0] == d[j]:
      i[0] = 10000**(len(d)-(j+1))
c = [i[0]*int(i[1]) if int(i[1]) != 0 else i[0]*0.1 for i in a ]
e = sorted(c,reverse=True)
for i in e:
  print(c.index(i)+1)

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

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

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

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

for v in ls:
  print(v[2])

Solution (Python):

N=int(input())
X=[]
for i in range(N):
    s,t=map(str, input().split())
    X.append([s,int(t)*-1,i+1])
for i in range(N):
    print(sorted(X)[i][2])

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

Solution (Python):

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

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



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


for _, _, number in rank:
    print(number)

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

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

for sp in Sp:
    print(sp[2]+1)

Solution (Python):
import os,re,sys,operator,math
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq
import string

setrecursionlimit(10**6)

n=int(stdin.readline().rstrip())
town=[]
for i in range(n):
    p,g=stdin.readline().rstrip().split()
    town.append((p,int(g),i+1))
town.sort(key=lambda x:(x[0],-x[1]))
for i in town:
    print(i[2])

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

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

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

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

Solution (Python):
from collections import defaultdict
N = int(input())
d = defaultdict(list)
p2n = {}
for n in range(N):
  s, p = input().split()
  d[s].append(int(p))
  p2n[int(p)] = n + 1

for key in sorted(d):
  for p in sorted(d[key],reverse=True):
    print(p2n[p])

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


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

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

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

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

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

Solution (Python):
from operator import itemgetter

N = int(input())
SP = []
lst = []
for i in range(N):
  lst = list(input().split())
  lst.append(i+1)
  SP.append(lst)
  SP[i][1] = int(SP[i][1])
SP = sorted(SP, key=itemgetter(1), reverse=True)
SP = sorted(SP, key=itemgetter(0))

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

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())
lst = []
for x in range(1, N + 1):
    s, p = input().split()
    lst.append((s, -int(p), x))

lst.sort()
for (_, _, idx) in lst:
    print(idx)

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

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

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

Solution (Python):
N = int(input())
h = {}
for i in range(N):
    restaurant, score = list(input().split())
    item = h.get(restaurant, [])
    item.append([int(score), i+1])
    h[restaurant] = sorted(item,key=lambda x: -x[0])

for key in sorted(h.keys()):
    for item in h[key]:
        print(item[1])

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

res_s = sorted(res, key=lambda x: x[2], reverse=True)    
res_s = sorted(res_s, key=lambda x: x[1], reverse=False)
for x in res_s:
    print(x[0])

Solution (Python):
N = int(input())
mydict = []
for i in range(1, N+1):
  a, b=input().split()
  mydict.append([str(a), int(b), i])
mydict = sorted(mydict, key=lambda x:x[1], reverse=True)
mydict = sorted(mydict, key=lambda x:x[0])
for i in mydict:
  print(i[2])

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

for i in range(n):
    a, b = input().split()
    dic += [[a, -int(b), i + 1]]
 
dic.sort()

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

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

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

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

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

for i in range(n):
    a, b = map(str, input().split())
    dic.append([a, int(b), i + 1])
 
dic.sort(key= lambda x: x[1], reverse= True)
dic.sort(key= lambda x: x[0])

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

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

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

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

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

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

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

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

Solution (Python):
import numpy as np

n = int(input())
num_list = [i for i in range(n)]
city_list = []
point_list = []

for _ in range(n):
  temp = input().split()
  city_list.append(temp[0])
  point_list.append(int(temp[1]))
  
city_set = list(set(city_list))
city_set.sort()

ans=[]
for name in city_set:
  temp = list(filter(lambda x:city_list[x]==name,range(n)))
  temp_num = [num_list[i] for i in temp]
  temp_point = [point_list[i] for i in temp]
  
  
  while len(temp_num)!=0:
    ans.append(temp_num[np.argmax(temp_point)]+1)
    
    del temp_num[np.argmax(temp_point)]
    del temp_point[np.argmax(temp_point)]
for i in ans:
  print(i)