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())
sp = [list(input().split()) for _ in range(n)]
ans = [0]*n

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

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

for i in range(n):
    ans[i] += sp[i][2]

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

Solution (Python):










import sys


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


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


def main():
    n = int(input())
    d = {}
    for i in range(n):
        x, y = input().split()
        if x not in d:
            d[x] = []
        d[x].append((int(y), i + 1))
    for i in d:
        d[i].sort(reverse=True)
    from collections import OrderedDict
    od = OrderedDict(sorted(d.items()))
    
    for i in od:
        for j in od[i]:
            print(j[1])


if __name__ == "__main__":
    main()

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() + [i + 1] for i in range(n)]

n = i()
sp = ms(n)
ansli = [0] * n
for i in range(n):
    tmp = 1
    for j in range(n):
        if i != j:
            if sp[j][0] < sp[i][0]:
                tmp += 1
            elif sp[j][0] > sp[i][0]:
                tmp += 0
            else:
                if int(sp[j][1]) < int(sp[i][1]):
                    tmp += 0
                else:
                    tmp += 1
    ansli[i] = [tmp, i + 1]
ansli.sort()
for i in range(n):
    print(ansli[i][1])

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

S.sort(key=lambda s:(s[0], -int(s[1])))

for s, p, t in S:
    print(t)

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

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

Solution (Python):

N = int(input())

restaurants = []
for i in range(1, N + 1):
    name, point = input().split()
    restaurants.append([i, name, int(point)])

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

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

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


def f(n):
    n[1] = int(n[1])
    return n


a = sorted([input().split() + [str(i+1)] for i in range(n)])

a.append(['end', '0', '0'])

tmp = []
ans = []

for i in range(n):
    tmp.append(a[i])
    if a[i][0] != a[i+1][0]:
        ans.append(sorted(tmp, key=lambda x: int(x[1]), reverse=True))
        tmp = []

for c in ans:
    for d in c:
        print(d[2])

Solution (Python):
import numpy as np
N = int(input())
SList = []
PList = []
dic = {}
Slist = []
aa = []
for _ in range(N):
    S, P = input().split()
    dic[S] = int(P)
    Slist.append(S)
    aa.append((int(P), S))
dic = sorted(dic.items())

sortedS = list(sorted(set(Slist)))

for i in range(len(sortedS)):
    tempV = []
    tempI = []
    for j in range(N):
        if aa[j][1] == sortedS[i]:
            tempV.append(aa[j][0])
            tempI.append(j)
    indexList = np.argsort(tempV)
    for k in reversed(indexList):
        print(tempI[k] + 1)

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

ls = []
for i in range(N):
  a,b = [i for i in input().split()]
  tmp = [str(a),int(b)]
  ls.append(tmp)

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

for next,l in enumerate(new_ls):
  for i,tmp in enumerate(ls):
    if l[0]==tmp[0] and l[1]==tmp[1]:
      print(i+1)

Solution (Python):
n = int(input())
from operator import itemgetter
a=[]
for i in range(n):
  b,c=map(str,input().split())
  c=int(c)
  a.append([b,c,i])
a1= sorted(a,key=itemgetter(1),reverse=True)
a2=sorted(a1,key=itemgetter(0))
for i in range(n):
  print((a2[i][2]+1))

Solution (Python):

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

from collections import Counter

c = Counter()

for i in range(N):
    k = input().split()
    k[1] = int(k[1])
    k.append(i+1)
    n.append(k)
    c.update([k[0]])



n.sort()

prev = ""
l = []
cnt = 0

for a in n:
    

    if c[a[0]] > 1:
        l.append(a[1:])
        
        cnt+=1
        
        
        if cnt == c[a[0]]:
            l.sort()
            
            for i in l[::-1]:
                print(i[1])
            cnt = 0
            l = []
    else:
        print(a[2])

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

for i in range(N):
  a, b = input().split()
  b = int(b)
  lis = []
  lis.append(a)
  lis.append(0-b)
  lis.append(i)
  L.append(lis)
L.sort()
for i in L:
  print(i[2]+1)

Solution (Python):


N = int(input())
S = []
P = []
I = []
Z = []

for i in range(N):
    s, p = input().split()
    S.append(s)
    P.append(int(p))
    I.append(i+1)

for i, j, k in zip(S,P,I):
    Z.append([i,j,k])

Z_sorted = sorted(Z)

for j in range(N-1):
    for i in range(N-1):
        if Z_sorted[i][0] == Z_sorted[i+1][0]:
            if Z_sorted[i][1] < Z_sorted[i+1][1]:
                a = Z_sorted[i]
                b = Z_sorted[i+1]
                Z_sorted[i] = b
                Z_sorted[i+1] = a

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

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

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

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

X = []
for i in range(len(x)):
    X.append(int(x[i][1]))
    
xx = sorted(x)
flag = True
temp = xx[0][0]
l = []
ans = []
l.append(xx[0][1])
for i in range(1, n):
    if temp == xx[i][0]:
        l.append(xx[i][1])
        flag = True
    else:
        flag = False
        l.sort(reverse=True)
        for j in l:
            ans.append(j)

        l = []
        temp = xx[i][0]
        l.append(xx[i][1])

if flag:
    l.sort(reverse=True)
    for j in l:
        ans.append(j)
    
ans = [int(a) for a in ans]

if len(ans) != len(X):
    ans.append(xx[i][1])
for j in range(n):
    print(X.index(ans[j]) + 1)

Solution (Python):
n = int(input())
table = []
for i in range(n):
    nest_table = []
    s, p = input().split()
    p = int(p)
    nest_table.append(s)
    nest_table.append(p)
    nest_table.append(i+1)
    table.append(nest_table)
    for j in range(i, 0, -1):
        if table[j][0] < table[j-1][0]:
            keep = table[j]
            table[j] = table[j-1]
            table[j-1] = keep
        elif table[j][0] == table[j-1][0]:
            if table[j][1] > table[j-1][1]:
                keep = table[j]
                table[j] = table[j-1]
                table[j-1] = keep    

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

Solution (Python):
from operator import itemgetter
N=int(input())
s= [[0]*3 for _ in range(N)]
for x in range(N):
    a,b=map(str,input().split())
    s[x][0]=a
    s[x][1]=100-int(b)
    s[x][2]=x+1
s.sort(key=itemgetter(0,1))
for un in range(N):
    print(s[un][2])

Solution (Python):
N = int(input())
lists_S = []
lists_P = []
for i in range(N):
    S,P = map(str,str(input()).split())
    lists_S.append(S)
    lists_P.append(int(P))
c = list(zip(lists_S,lists_P))
c = sorted(c,key=lambda x:(x[0],-x[1]))
s,p = zip(*c)
lists_index = []
for i in range(N):
    for j in range(N):
        if s[i] == lists_S[j] and p[i] == lists_P[j]:
            lists_index.append(p.index(p[j]) + int(1))
for i in range(len(lists_index)):
    print(lists_index[i])

Solution (Python):
n = int(input())
restaurants = [ input().split() for i in range(n) ]
names = [ restaurants[j][0] for j in range(n)]
names = set(names)
names = sorted(list(names))
for name in names:
    scores = list(map(int, [restaurants[l][1] for l in range(n) if restaurants[l][0] == name]))
    scores.sort(reverse = True)
    for m in scores:
        print(restaurants.index([name,str(m)]) +1)

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

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

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

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

Solution (Python):
N = int(input())
SP = [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 = sorted(SP, key = lambda x: (x[0], -x[1]))
for i in range(N):
    print(SP[i][2])

Solution (Python):

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


B = sorted(A, key=lambda x: x[1], reverse=True)

C = sorted(B, key=lambda x: x[0])

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

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

Solution (Python):

n = int(input())
lis = [list(input().split())+[x] for x in range(n)]
lis = sorted(lis,key=lambda x:x[0])
now = lis[0][0]
ans_lis = []
sublis = []
for x in lis:
    if x[0] == now:
        sublis.append(x)
    else:
        now = x[0]
        sublis = sorted(sublis,key=lambda x:int(x[1]),reverse=True)
        ans_lis.append(sublis)
        sublis = []
        sublis.append(x)
sublis.sort(key=lambda x:int(x[1]),reverse=True)
ans_lis.append(sublis)
sublis = []
sublis.append(x)       
ans_lis = [item for sublist in ans_lis for item in sublist]
for x in ans_lis:
    print(x[2]+1)

Solution (Python):

import copy

N = int(input())
list = [input().split() for i in range(N)]
list2 = copy.deepcopy(list)
list2.sort(key=lambda x:(x[0],-int(x[1])))

for i in range(N):
    a = list2[i]
    b = list.index(a)
    print(int(b + 1))

Solution (Python):
n=int(input())
sp=[list(map(str,input().split())) for l in range(n)]
sn=[]
ss=[]
sn2=[]
ss2=[]
for i in range(n):
    sn.append(sp[i][0])
    ss.append(sp[i][1])
sn2=sorted(sn)
ss=sorted(range(len(sn)), key=lambda k: sn[k])
for i in range(n):
    ss2.append(int(sp[ss[i]][1]))
for i in range(n):
    for j in range(n-1,i,-1):
        if sn2[j]==sn2[j-1]:
            if ss2[j-1]<ss2[j]:
                ss[j-1],ss[j]=ss[j],ss[j-1]
                ss2[j-1],ss2[j]=ss2[j],ss2[j-1]

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

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

List = []
for i in range(a):
	b, c = input().split()
	c = int(c)
	List.append([b, c, i])
List = sorted(List, key = lambda x:(x[0],-x[1]))

List2 = []
for i in range(a):
  List2.append(List[i][2]+1)
  
print(*List2)

Solution (Python):
N = int(input())
value_dict = {}
for i in range(1, N + 1):
    place, value = input().split()
    if not place in value_dict.keys():
        value_dict[place] = {}
    value_dict[place][int(value)] = i
for key, value_set in sorted(value_dict.items(), key=lambda x: x[0]):
    for value, index in sorted(value_set.items(), key=lambda y: -y[0]):
        print(index)

Solution (Python):
n=int(input())
s =[]
l =[]
ans = []
for i in range(n):
    s1,p = map(str,input().split())
    p1 = int(p)
    l.append(s1)
    s.append(list([s1,p1]))
l = sorted(list(set(l)))
for i in l:
    t =[]
    index_num = [n for n, v  in enumerate(s) if v[0] == i]
    for k in index_num:
        t.append(list([s[k][1],k]))
    t=sorted(t,reverse=True)
    for z in t:
        ans.append(z[1]+1)
[print(i) for i in ans]

Solution (Python):
n = int(input())
li = []
li1 = []
li2 = []
li3 = []
for i in range(n):
    s,p = input().split()
    li.append([s,int(p)])
    li2.append(int(p))
    li3 .append(s)
sortedli = sorted(li)
for a in sorted(set(li3)):
    for j in range(n):
        if a == sortedli[j][0]:
            li1.append(sortedli[j][1])
            li1.sort(reverse = True)
    for b in li1:
        print(1 + li2.index(b))
    li1 = []

Solution (Python):
def sol(_inp=input):
    n=int(_inp())
    shops=[_inp().split()+[i] for i in range(n)]
    for i in range(n):
        shops[i][1]=-int(shops[i][1])
    shops=sorted(shops)
    nums={i:shops[i][2]+1 for i in range(n)}
    return('\n'.join(str(nums[i]) for i in range(n)))
print(sol())

Solution (Python):
N = int(input())
l = []
d = {}
for i in range(N):
  S, P = input().split()
  t = tuple((S, 100-int(P)))
  d[t] = i+1
  l.append(t)

for val in sorted(l):
  print(d[val])

Solution (Python):
N = int(input())
S = []
P = []
ID = []
for n in range(N):
    S_temp, P_temp = list(input().split())
    S_temp = str(S_temp)
    P_temp = int(P_temp)
    S.append(S_temp)
    P.append(P_temp)
    ID.append(n + 1)

for n in range(N):
    for m in range(N - 1, n, -1):
        if S[m] < S[m - 1]:
            S[m], S[m - 1] = S[m - 1], S[m]
            P[m], P[m - 1] = P[m - 1], P[m]
            ID[m], ID[m - 1] = ID[m - 1], ID[m]
        elif S[m] == S[m - 1]:
            if P[m] > P[m - 1]:
                S[m], S[m - 1] = S[m - 1], S[m]
                P[m], P[m - 1] = P[m - 1], P[m]
                ID[m], ID[m - 1] = ID[m - 1], ID[m]

for n in range(N):
    
    print(ID[n])

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

result = []

def bubble_sort(arr):
    change = True
    while change:
        change = False
        for i in range(len(arr) - 1):
            if arr[i][0] == arr[i+1][0] and int(arr[i][1]) < int(arr[i+1][1]):
                arr[i], arr[i + 1] = arr[i + 1], arr[i]
                change = True
    return arr
_list = bubble_sort(t)

for a in _list:
    for i, item in enumerate(o):
        i+=1
        if a == item:
            result.append(i)
for r in result:
    print(r)

Solution (Python):
from operator import itemgetter
n = int(input())
l = []
for i in range(n):
    pair = input().split()
    l.append([pair[0], int(pair[1])])
l2 = l[:]

sub = sorted(l2, key=itemgetter(1), reverse=True)

l_sorted = sorted(sub, key=itemgetter(0))
for i in range(n):
    for j in range(n):
        if (l[j] == l_sorted[i]):
            print(j+1)

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

res=[]
index=0
arr.append([1000000,'na',111])
for i in range(1,n+1):
    if arr[i][1]!=arr[i-1][1]:
        tmp=arr[index:i]
        tmp.sort(key=lambda x:x[2],reverse=True)
        
        res.extend(tmp)
        index=i

for i in range(n):
    print(res[i][0])

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

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

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


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

Solution (Python):
n = int(input())
sp = [input().split() for _ in range(n)]
ps = [[p,s] for s,p in sp]
pn = {sp[1]:i+1 for i,sp in enumerate(sp)}

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

for p, s in ps:
    print(pn[p])

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

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

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

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

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

flg=0
AT=[]
for i in range(A):
    AT.append([T[i][1],T[i][2]])

    if i+1 == A:
        AT.sort(reverse=True)
        for j in range(len(AT)):
            print(AT[j][1])
        quit()

    if T[i][0] == T[i+1][0]:
        continue
    else:
        AT.sort(reverse=True)
        for j in range(len(AT)):
            print(AT[j][1])
        AT=[]

Solution (Python):
N = int(input())
city_list = []
score_list = []
for i in range(N):
    city,score = input().split()
    score = int(score)
    city_list.append(city)
    score_list.append(score)
city_sort = sorted(city_list)
for i in sorted(list(set(city_list))):
    if(city_list.count(i) == 1):
        print(score_list.index(score_list[city_list.index(i)])+1)
    else:
        list_a = []
        len_same_city = city_list.count(i)
        for j in range(len_same_city):
            list_a.append(score_list[city_list.index(i)])
            city_list[city_list.index(i)] = -1
        list_a = sorted(list_a,reverse=True)
        for k in list_a:
            print(score_list.index(k)+1)

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

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

Solution (Python):

from operator import itemgetter
n = int(input())
restList = []
for i in range(n):
    city, p = map(str, input().split())
    restList.append([i + 1, city, int(p)])
restList.sort(key=itemgetter(1))

city = restList[0][1]
same_list = []
for R in restList:
    if R[1] == city:
        same_list.append(R)
    else:
        if same_list:
            same_list.sort(key=itemgetter(2), reverse=True)
            for s in same_list:
                print(s[0])
            same_list = []
            same_list.append(R)
    city = R[1]
if same_list:
    same_list.sort(key=itemgetter(2), reverse=True)
    for s in same_list:
        print(s[0])

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

S = [""]*N
P = [0]*N
Q = [0]*N

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


SS, PP, ans = zip(*sorted(zip(S, Q, range(N))))

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

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

X = []
R = {}

for i in range(N):
    S, P = list(input().split())
    if S not in X:
        X.append(S)
    try:
        R[S].append([int (P), i+1])
    except:
        R[S] = []
        R[S].append([int (P), i+1])

for key in R:
    R[key].sort(reverse = True)

X.sort()

for i in X:
    for j in range(len (R[i])):
        print (R[i][j][1])

Solution (Python):
import functools

def compr(tup1, tup2):
    if tup1[1] < tup2[1]:
        return -1
    elif tup1[1] == tup2[1]:
        if tup1[2] > tup2[2]:
            return -1
        else:
            return 1
    else:
        return 1


n = int(input())

rests = []

for i in range(n):
    nome, score = input().split()
    rests.append((i, nome, int(score)))

rests.sort(key=functools.cmp_to_key(compr))

for tup in rests:
    print(tup[0] + 1)

Solution (Python):
from operator import itemgetter
n = int(input())
dic = {}
num = {}
dd = []
for i in range(n):
    data = input().split()
    a = str(data[0])
    b = str(data[1])
    y = a+b
    num[y] = i+1
    data[1] = int(data[1])
    dd.append(data)
dd = sorted(dd,key=lambda x:(x[0],x[1]),reverse = True)
x = sorted(dd,key = itemgetter(1),reverse=True)
x = sorted(x,key = itemgetter(0))

aa = []
for i in range(n):
    ans = str(x[i][0]) +str(x[i][1])
    aa.append(ans)

for i in range(n):
    print(num[aa[i]])

"""
for i in range(n):
    data = input().split()
    num.append(data[1])
    dic[i+1]= data[0]
    
dic = sorted(dic.items(),key = lambda x:x[1])
print(dic)
for i in range(n):

"""

Solution (Python):
number = int(input())
my_set = set()
for i in range(number):
    input_line = input()
    splitted_line = input_line.split(" ")
    my_set.add((splitted_line[0], - int(splitted_line[1]), i+1))

my_sorted = sorted(my_set)

for item in my_sorted:
    print(item[2])

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

name=[input().split() for i in range(N)]
score=[]



name2=sorted(name,key=lambda x:(x[0],-int(x[1])))



for i in range(N):
    for j,city in enumerate(name):
        if name2[i]==city:
            print(j+1)

Solution (Python):
from collections import defaultdict
def solve():
    n = input()
    s = []
    m = defaultdict(list)
    mm = {}
    for i in range(0, int(n)):
        si, pi = map(str, input().split())
        s.append(si)
        m[si].append(int(pi))
        mm[int(pi)] = i + 1
    ss = set(s)
    sss = list(ss)
    sss.sort()
    for i in range (len(sss)):
        s2 = sss[i]
        pd = m[s2]
        pd.sort()
        pd.reverse()
        for j in range (len(pd)):
            print(mm[pd[j]])


if __name__ == "__main__":
    solve()

Solution (Python):
def irekae(array2):
    return [array2[1],array2[0],array2[2]]
n=int(input())
l=[input().split() for i in range(n)]
for i in range(len(l)):
    l[i].append(i+1)
    l[i][1]=int(l[i][1])
for i in range(len(l)):
    l[i]=irekae(l[i])
l.sort(reverse=True)
for i in range(len(l)):
    l[i]=irekae(l[i])
lx=sorted(l,key=lambda x: x[0])
for i in range(len(lx)):
    print(lx[i][2])

Solution (Python):
from operator import itemgetter, attrgetter

a = int(input())
b = []
for i in range(a):
    c = input().split()
    b.append((c[0], int(c[1]), i+1))
s = sorted(b, key=itemgetter(1), reverse=True)

f = sorted(s, key=itemgetter(0), reverse=False)


for i in f:
    print(i[-1])

Solution (Python):
N = int(input())
city_score = [[i for i in input().split()] for i in range(N)]
city = list()
score = list()
all = list()
for i in range(N):
    city.append(city_score[i][0])
    score.append(city_score[i][1])
    all.append([city_score[i][0], int(city_score[i][1]), i+1])
    
while(True):
    min_word = "zzzzzzzzzz"
    max_score = -1
    ans = 0
    index = 0
    for i in range(len(all)):
        if((all[i][0] < min_word) or (all[i][0] == min_word and all[i][1] > max_score)):
                max_score = all[i][1]
                min_word = all[i][0]
                ans = all[i][2]
                index = i
    print(ans)
    all.pop(index)
    
    if(len(all) == 0):
        break

Solution (Python):
from operator import itemgetter
N = int(input())
e = {}
for i in range(N):
    c,p = input().split()
    if c in e.keys():
        e[c].append((int(p),i))
    else:
        e[c] = [(int(p),i)]

for k,v in sorted(e.items()):
    for p,q in sorted(v,key=itemgetter(0),reverse=True):
        print(q+1)

Solution (Python):
def irekae(array2):
    return [array2[1],array2[0],array2[2]]

n=int(input())
l=[input().split() for i in range(n)]
"""

for i in range(len(l)):
    l[i].append(i+1)
    l[i][1]=int(l[i][1])

l.sort()

for i in range(len(l)):
    l[i]=irekae(l[i])

lsort=[]
while l!=[]:
    """
for i in range(len(l)):
    l[i].append(i+1)
    l[i][1]=int(l[i][1])
for i in range(len(l)):
    l[i]=irekae(l[i])

l.sort(reverse=True)

for i in range(len(l)):
    l[i]=irekae(l[i])


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

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

Solution (Python):
N = int(input())
S = [[t if index==0 else -int(t) for index,t in enumerate(input().split())]+[i] for i in range(N)]
S = sorted(S)
for s in S:
	print(s[2]+1)

Solution (Python):
N = int(input())
R = []
Q = []
for i in range(N):
  R.append(input().split())
  R[i][1] = int(R[i][1])
for i in range(N):
  Q.append(R[i])
R.sort(key=lambda x:x[1], reverse=True)
R.sort(key=lambda x:x[0])

for j in range(N):
  print(Q.index(R[j]) +1)

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

lists = []
for _ in range (N):
    S = input().split(' ')
    lists.append([S[0],int(S[1])])

list_sorted = lists.copy()

list_sorted.sort()
list_sorted.sort(key=lambda x:(x[0],-x[1]),reverse =False)
for sorted in range (N):
    for result in range(N):
        if lists[result] == list_sorted[sorted]:
            print(result+1)

Solution (Python):
from collections import OrderedDict

N = int(input())

city = set()

rest = OrderedDict()

for i in range(N):
    sp = input().split()

    if sp[0] in city:
        rest[sp[0]].append([int(sp[1]), i])
    else:
        city.add(sp[0])
        rest[sp[0]] =[[int(sp[1]), i]]

index = sorted(rest)

for i in index:
    for r in sorted(rest[i], reverse=True):
        print(r[1]+1)

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

Solution (Python):
N=int(input())
SP=[input().split() for l in range(N)]
for n,sp in enumerate(SP):
    sp.append(n+1)
    sp[1]=100-int(sp[1])
SP.sort(key = 
lambda x: (x[0], x[1])
)
for s,p,t in SP:
    print(t)

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

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

arr = sorted(arr, key=lambda x:x[0])
arr.append(['zzzzzz',100,100])
tmp=arr[0][0]
arr2=[]
for x in arr:
    if tmp==x[0]:
        arr2.append(x[1:3])
    else:
        arr2=sorted(arr2, key=lambda x:x[0], reverse=True)
        for y in arr2:
            print(y[1])
        arr2=[x[1:3]]
        tmp=x[0]

Solution (Python):
n = int(input())
SQ  = []
for i in range(n):
    s,q = input().split()
    SQ.append([s,q,i+1])
SQ.append(['zzzzzzzzzzzzzz',0,i+2])
X = sorted(SQ)
res = []
city = X[0][0]
for i in range(n+1):
    if X[i][0] == city:
        res.append([int(X[i][1]),X[i][2]])
    else:
        res.sort(reverse=True)
        for r in res:
            print(r[1])
        res = [[int(X[i][1]),X[i][2]]]
        city = X[i][0]

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


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

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

T = [input() for i in range(N)]
S = [0] * N
P = [0] * N
d = defaultdict(list)

mylist = []
for i in range(N):
    S[i], P[i] = map(str, T[i].split())
    d[S[i]].append(int(P[i]))    

s_d = sorted(d)
ans = []
for i in s_d:
    A = d[i]
    so_A = sorted(A, reverse=True)
    for j in so_A:
        ans.append(i + ' ' + str(j))

for k in ans:
    print(T.index(k) + 1)

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

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


idx = 0
while idx < N:
        city = A[idx][0]
        num = 0
        while idx + num < N and A[idx+num][0] == city:
                num += 1
        B = A[idx:idx+num]
        B.sort(key=lambda x: x[1])
        
        for val in range(num):
                print(B[num-val-1][2] + 1)
        idx += num

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

for i in range(N):
    S, P = map(str,input().split())
    if S not in restourants:
        restourants[S] = {}
    restourants[S][int(P)] = i+1
for k, v in sorted(restourants.items()):
    v = sorted(v.items(),reverse=True)
    for i in v:
        print(i[1])

Solution (Python):
import numpy as np

N = int(input())
same_dict = {}
keys = []

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

pairs = sorted(inputs, key=lambda x: x[0])


before_key = pairs[0][0]
tmp_indexes = [pairs[0][2]]
tmp_vals = [pairs[0][1]]

out = []
for pair in pairs[1:]:
    tmp_key, val, index = pair
    
    if before_key == tmp_key:
        tmp_indexes.append(index)
        tmp_vals.append(val)
    else:
        both_l = []
        ss = [[elm1, elm2] for elm1, elm2 in zip(tmp_indexes, tmp_vals)]
        ss = sorted(ss, key=lambda x: -x[1])
        
        for a, b in ss:
            out.append(a)

        tmp_vals = [val]
        tmp_indexes = [index]

    before_key = tmp_key

 


ss = [[elm1, elm2] for elm1, elm2 in zip(tmp_indexes, tmp_vals)]
ss = sorted(ss, key=lambda x: -x[1])

for a, b in ss:
    out.append(a)

for elm in out:
    print(elm+1)

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

lis = []

sortsecond0 = lambda val: val[0]
sortsecond1 = lambda val: val[1]

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

lis.sort(key=sortsecond1, reverse=True)
lis.sort(key=sortsecond0)

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

Solution (Python):
from operator import itemgetter


input_ = input().split('\n')
N = int(input_[0])
list_ = list()


for i in range(1, N + 1):
    city, score = input().split(' ')

    list_.append([city, int(score), i])


list_sortByScore = sorted(list_,          key=itemgetter(1), reverse=True)
list_sortByCity = sorted(list_sortByScore, key=itemgetter(0))


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

Solution (Python):
import fractions
import numpy as np
import os
import sys

n=int(input())
tt=[]
for i in range(n):
    a,b=input().split()
    tt.append([a,int(b)])
t=tt.copy()
t=sorted(t,key=lambda x: x[1],reverse=True)
t=sorted(t,key=lambda x: x[0])

for i in t:
    print(tt.index(i)+1)