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):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
A = []
for i in range(n):
    s, p = input().split()
    p_ = (-1)*int(p)
    A.append((s, p_, i+1))
A.sort(key=itemgetter(0,1))

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

Solution (Python):
n = int(input())
cities = set()
scores = {}
scorelist = {}
sp = [[""]]*n
for i in range(n):
  sp[i] = input().split()
  s = sp[i][0]
  p = int(sp[i][1])
  if s in cities:
    scores[s][p] = i
    scorelist[s].append(p)
  else:
    scores[s] = {p:i}
    scorelist[s] = [p]
    cities.add(s)
citylist = list(cities)
citylist.sort()
for x in citylist:
  scorelist[x].sort(reverse = True)
  for i in range(len(scorelist[x])):
    print(scores[x][scorelist[x][i]]+1)

Solution (Python):
N=int(input())
lest=[]
for i in range(0,N):
    S,P=list(map(str,input().split()))
    lest.append([S,int(P),i+1])
lest.sort()
for n in range(0,100):
    for i in range(0,N-1):
        if lest[i][0]==lest[i+1][0] and lest[i][1]<lest[i+1][1]:
            a=lest[i][1]
            lest[i][1]=lest[i+1][1]
            lest[i+1][1]=a
            b = lest[i][2]
            lest[i][2] = lest[i + 1][2]
            lest[i + 1][2] = b
for i in range(0,N):
    print(lest[i][2])

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

Solution (Python):
from operator import itemgetter

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

data = sorted(data, key=itemgetter(1), reverse=True)
data = sorted(data, key=itemgetter(0), reverse=False)

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

Solution (Python):
def guidebook(n, spli):

    ans = []
    for i in range(n):
        temp = [i+1, spli[i][0], (-1)*int(spli[i][1])]
        ans.append(temp)
    ans.sort(key=lambda x: (x[1], x[2]))
    return ans
def main():
    n = int(input())
    spli = [list(map(str, input().split()))for i in range(n)]
    ans = guidebook(n, spli)
    for i in ans:
        print(i[0])

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [0] * n
for i in range(n):
    s, p = input().split()
    a[i] = [s, -int(p)]
b = sorted(a)
for i in range(len(a)):
    print(a.index(b[i])+1)

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

L.sort()
for _ in range(N):
    print(L[_][2]+1)

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

for i in range(n):
    j = i
    while j > 0:
        if T[j][0] < T[j - 1][0]:
            T[j], T[j - 1] = T[j - 1], T[j]
            ans[j], ans[j - 1] = ans[j - 1], ans[j]
            j = j - 1
        else:
            break

for i in range(n):
    j = i
    while j > 0:
        if int(T[j][1]) > int(T[j - 1][1]) and T[j][0] == T[j - 1][0]:
            T[j], T[j - 1] = T[j - 1], T[j]
            ans[j], ans[j - 1] = ans[j - 1], ans[j]
            j = j - 1
        else:
            break


for i in range(n):
    print(ans[i])

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

Solution (Python):


from operator import itemgetter

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

SP = sorted(SP, key=itemgetter(2), reverse=True)
SP = sorted(SP, key=itemgetter(1))
for sp in SP:
    print(sp[0])

Solution (Python):
N = int(input())
rest_dict = {}
city_list = []
for i in range(N):
    city, score = input().split()
    if city not in city_list:
        city_list.append(city)
        rest_dict[city] = [[int(score), i]]
    else:
        rest_dict[city].append([int(score), i])

city_list = sorted(city_list)
for city in city_list:
    rest_list = rest_dict[city]
    rest_list = sorted(rest_list, reverse=True)
    for rest in rest_list:
        print(rest[1]+1)

Solution (Python):
n = [(input().split()) for _ in range(int(input()))]
m = sorted(sorted(n,key=lambda x:int(x[1]), reverse=True),key=lambda x:x[0])
print('\n'.join([str(n.index(li)+1) for li in m]))

Solution (Python):

n = int(input())
rst = []
for _ in range(n):
    s,p = map(str,input().split())
    rst.append([s,int(p)])
    
rst_sort = rst[:]
rst_sort.sort(key=lambda x: (x[0],-x[1]))

for i in range(n):
    print(rst.index(rst_sort[i]) + 1)

Solution (Python):
from sys import argv

debug = "a" in argv
n = int(input())
ls = []
la = ls.append
for i in range(1, n + 1):
    s = input().split()
    la((i, s[0], int(s[1])))
if debug:
    print("ls:",ls)
ls = sorted(ls, key=lambda x: x[2], reverse=1)
ls = sorted(ls, key=lambda x: x[1])
if debug:
    print("ls(sorted):",ls)
if debug:
    print("debug end")
for x in ls:
    print(x[0])

Solution (Python):
import heapq

N = int(input())
que = []
for i in range(N):
    l = input().split(' ')
    heapq.heappush(que, (l[0], -int(l[1]), i + 1))

while que:
    print(heapq.heappop(que)[2])

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

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

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

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

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

print(*S,sep="\n")

Solution (Python):
n = int(input())
list_2d = [[] for _ in range(n)]

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

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

s = [0]*n
p = [0]*n

list_2d = [[] for _ in range(n)]

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

Solution (Python):
N = int(input())
S = list(range(N))
P = list(range(N))
SP = list(range(N))

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

S_ = sorted(set(S))
P_ = sorted(set(P), reverse = True)

for n in range(len(S_)):
  for m in range(len(P_)):
    if (S_[n], P_[m]) in SP:
      print(SP.index((S_[n], P_[m])) + 1)

Solution (Python):

n = int(input())
sp = [0]*n
for i in range(n):
    s, p = map(str, input().split())
    p = int(p)
    sp[i] = [i+1, s, p]
sp.sort(key=lambda x:(x[1],-x[2]))
for _ in sp:
    print(_[0])

Solution (Python):
from collections import defaultdict
n = int(input())
restaurants = defaultdict(list)
for i in range(n):
    s, p = input().split()
    p = int(p)
    restaurants[s].append([p, i])

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

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

Solution (Python):
from collections import defaultdict

n = int(input())
dic = defaultdict(lambda:{})
for _ in range(n):
  i = input().split()
  dic[i[0]][int(i[1])] = _ + 1

for i in sorted(dic):
  for j in sorted(dic[i], reverse=True):
    print(dic[i][j])

Solution (Python):
n = int(input())
from operator import itemgetter
sset = set()
sp = [list(input().split()) + [i+1] for i in range(n)]
for i in range(n):
    sp[i][1] = int(sp[i][1])
for i in range(n):
    sset.add(sp[i][0])
sp.sort(key = itemgetter(1),reverse = True)
slist = sorted(list(sset))
anslist = []
for i in range(len(sset)):
    for j in range(n):
        if sp[j][0] == slist[i]:
            anslist.append(sp[j][2])

for ans in anslist:
    print(ans)

Solution (Python):

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

Solution (Python):
N=int(input())
shoplist=[]
for i in range(N):
    a,b=input().split()
    
    temp=[i+1,a,-1*int(b)]
    shoplist.append(temp)
    


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



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

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

Solution (Python):
import sys

readline = sys.stdin.readline

def main():
    N = int(input())
    store = []
    for i in range(N):
        S, P = readline().split()
        P = int(P)
        store.append([i+1,S,P])
    store.sort(key=lambda x: x[2], reverse=True)
    store.sort(key=lambda x: x[1])
    
    for s in store:
        print(s[0])

if __name__ == "__main__":
    main()

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

for i in range(N):
  item = list(input().split())
  item[1] = abs(100 - int(item[1]))
  item.append(i+1)
  items.append(item)

items = sorted(items)

for i in items:
  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 i in l:
  print(i[2])

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

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

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

dk=sorted(l.keys())
for i in dk:
  l[i].sort(reverse=True, key=lambda x:x[0])
  for j,k in l[i]:
    print(k)

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

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

keys = sorted(set(s[0] for s in sp))

for k in keys:
    for ss in sorted([s[1:] for s in sorted(sp) if s[0]==k], reverse=True):
        print(ss[1])

Solution (Python):
rests = {}
for i in range(int(input())):
    S,P = input().split()
    P = int(P)
    if S in rests:
        rests[S] += [[P,i]]
    else:
        rests[S] = [[P,i]]
        
r = sorted(rests.items()) 
for city in r:
    city[1].sort()
    city[1].reverse()
    
    for score,i in city[1]:
        print(i+1)

Solution (Python):
n = int(input())
sp = []
for i in range(n):
  s,p = input().split()
  sp.append([s, 100 - int(p), i+1])
sp.sort()
ans = []
for s,p,i in sp:
  ans.append(i)
print("\n".join(map(str, ans)))

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

b = sp[0][0]
I = 0
ans = []
for s,p,i in sp:
  if b == s:
    ans.insert(I, i)
  else:
    ans.append(i)
    b = s
    I = len(ans)-1
print("\n".join(map(str, ans)))

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 i in range(n):
    print(l[i][2])

Solution (Python):
N = int(input())
T = [None]*N
for i in range(N):
    tmp = input().split()
    T[i] = (tmp[0], -int(tmp[1]), i+1)

T.sort()
for t in T:
    print(t[2])

Solution (Python):
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = [None]*n
for i in range(n):
    a[i] = [None]*2
for i in range(n):
    a[i] = input().split()

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

b = sorted(a, key=itemgetter(1), reverse=True)

c = sorted(b, key=itemgetter(0))

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

Solution (Python):
N = int(input())
S = [None]*N
P = [None]*N
I = [None]*N
for i in range(N):
    tmp = input().split()
    S[i] = tmp[0]
    P[i] = int(tmp[1])
    I[i] = i+1


def less(a, b):
    if a[0] == b[0]:
        if a[1] == b[1]:
            return a[2] < b[2]
        return a[1] > b[1]
    return a[0] < b[0]


for i in range(N):
    for j in range(i+1, N):
        if not less([S[i], P[i], I[i]], [S[j], P[j], I[j]]):
            S[i], S[j] = S[j], S[i]
            P[i], P[j] = P[j], P[i]
            I[i], I[j] = I[j], I[i]

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

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

List2=[]
List_sub=[]
for i in range(N):
    List_sub=[i+1,List[i][0],int(List[i][1])]
    List2.append(List_sub)

set_List=[]
for i in range(len(List)):
    set_List.append(List2[i][1])

set_List=list(set(set_List))
set_List.sort()

Ans_List=[]
const_const_List=[]
const_List=[]
for i in range(len(set_List)):
    const_List=[]
    for j in range(N):
        if set_List[i]==List2[j][1]:
            const_const_List=[List2[j][2],List2[j][0]]
            const_List.append(const_const_List)
    const_List.sort(reverse=True)
    Ans_List.extend(const_List)


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

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
data = [input().split()+[i+1] for i in range(n)]
data.sort(key = lambda tup: (tup[0],-int(tup[1])))
for city , k,number in data:
  print(number)

Solution (Python):
def main():
    from collections import defaultdict

    book = defaultdict(list)
    N = int(input())
    for ind in range(1, N + 1):
        s, p = input().split()
        book[s].append((int(p), ind))

    for s in sorted(book.keys()):
        book[s].sort(key=lambda x: x[0], reverse=True)
        for _, ind in book[s]:
            print(ind)


if __name__ == '__main__':
    main()

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

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

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

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


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return input().split()


def main():
    N = readint()
    sp = [readstrs() for _ in range(N)]
    S = list(map(lambda x: x[0], sp))
    t = {x: [] for x in S}
    for v in sp:
        t[v[0]].append(v[1])

    for k in t.keys():
        t[k] = sorted(list(map(int, t[k])), reverse=True)

    for k, v in sorted(t.items()):
        for vv in v:
            print(sp.index([k, str(vv)]) + 1)


if __name__ == "__main__":
    main()

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

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

name=sorted(D)

for n in name:
    d=sorted(D[n], reverse=True)
    for t in d:
        p,n=t
        print(n)

Solution (Python):
n = int(input())
d = {}
for i in range(n):
    a,b = input().split()
    if a in d:
        d[a].append([int(b),i+1])
    else:
        d.setdefault(a,[[int(b),i+1]])
for k in sorted(d.keys()):
    d[k].sort(reverse=True)
    for i in d[k]:
        print(i[1])

Solution (Python):
import sys













ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





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

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

    for t in tmp1:
        print(t[2])


if __name__ == '__main__':
    main()

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

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

a = []
for s,p in sp:
  a.append([s, 100-int(p)])
A = sorted(a)
for i in range(n):
  print(a.index(A[i])+1)

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



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

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

Solution (Python):
N = int(input())
a = {}
b = set()

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

    if not S in a:
        a[S] = []

    a[S].append((int(P), i+1))
    b.add(S)
b = list(b)
b.sort()

for v in a.values(): v.sort(reverse=True)

for s in b:
    for _, i in a[s]:
        print(i)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    SP = []
    for i in range(n):
        s, p = map(str, input().split())
        SP.append([i + 1, s, int(p)])
    SP = sorted(SP, key=lambda x: x[2], reverse=True)
    SP = sorted(SP, key=lambda x: x[1])

    for idx, _,_ in SP:
        print(idx)


if __name__ == '__main__':
    resolve()

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

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

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[1], reverse=True)
SP.sort(key=lambda x: x[0])
for s, p, i in SP:
    print(i)

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

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

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

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

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
sp = [S_LIST() for _ in range(n)]
sp = [[sp[i][0], -int(sp[i][1]), i + 1] for i in range(n)]
sp.sort(key=lambda x:(x[0], x[1]))
for i in range(n):
    print(sp[i][2])

Solution (Python):
def main():
    n = int(input())
    group = {}
    city = []
    for i in range(n):
        s, p = input().split()
        if s not in city:
            city.append(s)
        if s in group:
            group[s].append([int(p), i + 1])
        else:
            group[s] = [[int(p), i + 1]]
    city.sort()
    for c in city:
        group[c].sort(key=lambda x: x[0], reverse=True)
        for _, n in group[c]:
            print(n)


if __name__ == '__main__':
    main()

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

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

sp.sort(key=lambda x: -x[1])
sp.sort(key=lambda x: x[0])
for i in range(n):
    print(sp[i][2])

Solution (Python):
n = int(input())
s = [list(map(str, input().split())) for _ in range(n)]
t = sorted(s, key=lambda s:(s[0], -int(s[1])))
for i in range(n):
    for j in range(n):
        if t[i] == s[j]:
            print(j+1)

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

def resolve():
    l=[]
    n=int(input())
    for i in range(n):
        s,p=input().split()
        l1=[s,-int(p),i+1]
        l.append(l1)
    from operator import itemgetter
    l2=sorted(l,key=itemgetter(0,1))
    for s,p,i in l2:
        print(i)
resolve()

Solution (Python):

class restaurant:
    def __init__(self, name, point, num):
        self.name = name
        self.point = point
        self.num = num
    def __repr__(self):
        return "%d" % (self.num)



def main():
    N  = int(input())
    restaurants = []
    for i in range(N):
        S = input().split()   
        restaurants.append(restaurant(str(S[0]),int(S[1]),i+1))

    restaurants = sorted(restaurants, key=lambda x: x.point , reverse=True)
    restaurants = sorted(restaurants, key=lambda x: x.name)

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



if __name__ == '__main__':
    main()

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

def resolve():
    l=[]
    n=int(input())
    for i in range(n):
        s,p=input().split()
        ll=[s,int(p),i+1]
        l.append(ll)
    lll = sorted(l, key=lambda x:x[1], reverse=True)
    llll=sorted(lll,key=lambda x:x[0])
    for s,p,i in llll:
        print(i)
resolve()

Solution (Python):
N = int(input())
l=list()
 
for i in range(1,N+1):
    tempS,tempP = input().split()
    l.append([tempS,-int(tempP),i])
 
sortedList = sorted(l,key=lambda item:(item[0],item[1]))
 
for i in range(1,N+1):
    print(sortedList[i-1][2])

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

def resolve():
    l=[]
    n=int(input())
    for i in range(n):
        s,p=input().split()
        ll=[s,-int(p),i+1]
        l.append(ll)
    l.sort()
    for i in range(n):
        print(l[i][2])
resolve()

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

for i in range(1,N+1):
    tempS,tempP = input().split()
    l.append([tempS,-int(tempP),i])

sortedList = sorted(l,key=lambda item:(item[0],item[1]))

for i in range(1,N+1):
    print(sortedList[i-1][2])

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

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

for i in range(1,n+1):
  name,score =input().split()
  a.append([name,-int(score),i])
  
a.sort()
for n,s,idx in a:
  print(idx)

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

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

rest.sort()
for re in rest:
    print(re[2])

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

Solution (Python):
N=int(input())
t=[input().split() for _ in range(N)]
for i in range(N):
  t[i].append(i+1)
  t[i][1]=100-int(t[i][1])
t.sort()
for j in range(N):
  print(t[j][2])

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

Solution (Python):

n = int(input())
s = [input().split() for i in range(n)]
print(*[i + 1 for i, _ in sorted(enumerate(s), key = lambda x: (x[1][0], -int(x[1][1])))], sep="\n")

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

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

SP.sort()

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

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

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

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

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

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

for i in ans_list:
  print(i)

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

sp.sort(key=lambda x:(x[1], -x[2]))
for i, _, _ in sp:
    print(i)

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

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

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

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


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

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

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

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

Solution (Python):
n = int(input())
a = [list(input().split()) for nesya in range(n)]
s = 1

for hoge in a:
  hoge[1] = int(hoge[1])*(-1)
  hoge.append(s)
  s += 1
a.sort()
for raw in a:
  print(raw[2])

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

Solution (Python):
n = int(input())
S, P = [], []
Sdic = {}
line = [list(input().split()) for _ in range(n)]
for i in range(n):
    S.append(line[i][0])
    P.append(int(line[i][1]))
    if line[i][0] not in Sdic:
        Sdic[line[i][0]] = 1
Sdic2 = sorted(Sdic.items())
Sa = []
for i in range(len(Sdic2)):
    Sa.append(Sdic2[i][0])
for s in Sa:
    data = []
    for j in range(n):
        if S[j] == s:
            data.append(j)
    Pd = [[k, P[k]] for k in data]
    Pd = sorted(Pd, reverse=True, key=lambda x: x[1])
    for j in range(len(Pd)):
        print(Pd[j][0] + 1)

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

Restaurants =[]

for i in range(N):
    Rest,score =input().split()
    Restaurants.append([i+1,Rest,int(score)])

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

for j in Restaurants:
    print(j[0])

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






sp = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    sptemp = [s, -p, i]
    sp.append(sptemp)
spsorted = sorted(sp)

for temp in spsorted:
    print(temp[2] + 1)

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

def main():
    N = int(readline())
    SP = []
    for i in range(N):
        s, p = readline().rstrip().split()
        SP.append((s, int(p), i+1))
    SP.sort(key=itemgetter(1), reverse=True)
    SP.sort(key=itemgetter(0))
    for i in range(N):
        print(SP[i][2])

if __name__ == '__main__':
    main()

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

def main():
    N = int(readline())
    SP = [readline().rstrip().split() for _ in range(N)]
    SP = [(s, -int(p), i+1) for i, (s, p) in enumerate(SP)]
    SP = sorted(SP, key=itemgetter(0, 1))
    for i in range(N):
        print(SP[i][2])

if __name__ == '__main__':
    main()