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())
	l = []
	for i in range(n):
		s, p = input().split()
		l.append([s, int(p), i+1])
	l = (sorted(l, key=lambda x: x[1], reverse=True))
	key_sort = (sorted(l, key=lambda x: x[0]))
	for ans in key_sort:
		print(ans[2])

if __name__ == '__main__':
	import sys
	sys.exit(main())

Solution (Python):
N = int(input())
M = []
for i in range(N):
  inp = list(input().split())
  M.append([inp[0], int(inp[1])])
res = [i[0]+1 for i in sorted(enumerate(M), key = lambda x : (x[1][0], -x[1][1]))]

for item in res:
  print (item)

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
d=dict()
for i in range(n):
    s,p=SL()
    if s in d:
        d[s].append([int(p),i+1])
    else:
        d[s]=[[int(p),i+1]]
k=list(d.keys())
k.sort()
for key in k:
    t=d[key]
    t.sort(reverse=True)
    for p,num in t:
        print(num)

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

num=input()
namae=[]
kazu=[]
for temp in range(int(num)):
    aaa=[i for i in input().split()]
    namae.append(aaa[0])
    kazu.append([aaa[0],int(aaa[1])])
for i,temp in enumerate(kazu):
    kazu[i].append(i+1)
kazu.sort(key = lambda x:(x[0],(x[1])))

itizi = kazu[0][0]
result=[]
for temp in kazu:
    if itizi == temp[0]:
        result.append(temp[2])
    else:
        itizi=temp[0]
        result.reverse()
        for temp2 in result:
            print(temp2)
        result=[temp[2]]
result.reverse()
for temp in result:
    print(temp)

Solution (Python):
def main():
    N = int(input())
    restaurants = {}
    for i in range(N):
        S, P = input().split()
        P = int(P)
        if not S in restaurants.keys():
            restaurants[S] = []
        restaurants[S].append([i, P])
    for s in sorted(restaurants.keys()):
        Ps = sorted(restaurants[s], key=lambda x:x[1], reverse=True)
        for p in Ps:
            print(p[0]+1)


if __name__ == '__main__':
    main()

Solution (Python):

import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    r = {}
    for i in range(N):
        s, p = i2s().split()
        p = int(p)
        if s in r.keys():
            r[s] += [(p, i)]
        else:
            r[s] = [(p, i)]

    rname = list(r.keys())
    rname.sort()
    
    for n in rname:
        out = [x[1] for x in sorted(r[n], reverse=True)]
        for m in out:
            print(m + 1)

main()

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

for k in range(n) :
	table[k][1] = int(table[k][1]) 
	table[k].append(k + 1)

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

for l in range(n) :
	print(sortedtable[l][2])

Solution (Python):
from operator import itemgetter

n = int(input())
sp = [list(map(str, 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.sort()

t = []

t.append(sp[0])

for i in range(n - 1):
    i += 1
    if sp[i][0] == sp[i - 1][0]:
        t.append(sp[i])
    else:
        t.sort(key=lambda t: t[1], reverse=True)
        for j in t:
            print(j[2])
        t = []
        t.append(sp[i])

t.sort(key=lambda t: t[1], reverse=True)
for j in t:
    print(j[2])

Solution (Python):


from operator import itemgetter

N = int(input())
l = []
for i in range(N):
    r = input().split()	
    l.append(r)
    

    
l_copy = [] 
for i in range(N):
    l_copy.append(l[i])
l.sort(key=lambda x:(x[0],-int(x[1])))




for i in range(N):
    num = 0
    target = l[i]
    for j in range(N):
        if l_copy[j] == target:
            num = j + 1
            print(num)
            break

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

dic = {}
for i in range(1, N+1):
    s, p = map(str, input().split())
    p = int(p)
    if dic.get(s) is None:
        dic[s] = [(i, p)]
    else:
        dic[s].append((i, p))

for k in dic:
    tmp = sorted(dic[k][:], key=lambda x: -x[1])
    dic[k] = tmp

inds = []
ind = 1
for k in sorted(dic.keys()):
    for t in dic[k]:
        inds.append((t[0], ind))
        ind += 1

for ind in sorted(inds, key=lambda x: x[1]):
    print(ind[0])

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

aaa = {}
nums = []
for i in range(N):
    s, p = input().split()
    p = int(p)
    if s in aaa.keys():
        aaa[s].append(p)
    else:
        aaa[s] = [p]
    nums.append(p)

for key in sorted(aaa.keys()):
    for num in sorted(aaa[key])[::-1]:
        print(nums.index(num) + 1)

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

for i in range(n):
    if int(sp[i][1])==0:
        sp[i][1]=float('inf')
    else:
        sp[i][1]=1/int(sp[i][1])
ps=sorted(sp)
for i in range(n):
    print(sp.index(ps[i])+1)

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

Solution (Python):


import sys
s = sys.stdin.readlines()
N = s[0].split()
rest_dict = {}
order_dict = {}
count = 1
for e in s[1:]:
    S = e.split()[0]
    P = int(e.split()[1])
    if S in rest_dict:
        rest_dict[S].append(P)
    else:
        rest_dict[S] = [P]
    order_dict["{}_{}".format(S, P)] = count
    count += 1
    
for k, v in sorted(rest_dict.items()):
    v.sort()
    v.reverse()
    for p in v:
        print(order_dict["{}_{}".format(k, p)])

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

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

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

Solution (Python):

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

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

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

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

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

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

for s in sp:
    s[1].sort()
    s[1].reverse()
    for pp in s[1]:
        print(pp[1])

Solution (Python):
n = int(input())
arr = [input().split() for _ in range(n)]
for i in arr:
    i[1] = int(i[1])
ans = sorted(arr, key=lambda x: x[1])
list.sort(ans, key=lambda x: x[1] ,reverse=True)
list.sort(ans, key=lambda x: x[0])
for sorted_list in ans:
    for i, base in enumerate(arr, start = 1):
        if base == sorted_list:
            print(i)

Solution (Python):
from operator import itemgetter

n = int(input())
l = []
for i in range(n):
    k = [j for j in input().split()]
    l.append([k[0], int(k[1]), i])

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

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

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

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

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

for d in list1:
    print(d[0])

Solution (Python):






import sys
import math
import array


class mymath:
    
    pi = 3.14159265358979323846264338

    
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

mymath = mymath()


class output:
    
    def list(self, l):
        l = list(l)
        print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()
















def main():
    N = int(input())
    shop = []
    for i in range(N):
        s, p = [x for x in input().split()]
        shop.append([i,s,int(p)])
    
    shop.sort(key=lambda x:x[2])
    shop.reverse()
    shop.sort(key=lambda x:x[1])

    for i in shop:
        print(i[0]+1)

if __name__ == '__main__':
    main()

Solution (Python):
N =int(raw_input())
S =[]
P =[]
for i in range(N):
    s,p=map(str,raw_input().split())
    S.append(s)
    P.append(int(p))
ss=sorted(list(set(S)))
for sss in ss:
    a =[]
    b =[]
    for j in range(N):
        if sss==S[j]:
            a.append(j)
            b.append(P[j])
    if len(b)>0:
        c = sorted(b,reverse=True)
        
        for k in c:
            for j in range(len(b)):
                if k == b[j]:
                    print(a[j]+1)

Solution (Python):
N = int(input())
Ss, Ps = [ [], [] ]
for i in range(N):
    s, p = input().split(" ")
    Ss.append(s)
    Ps.append(int(p))
rests = list(zip(range(1, N+1), Ss, Ps))
rests.sort(key=lambda x: (x[1], -x[2]))
print('\n'.join([str(i) for i,_,_ in rests]))

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

Solution (Python):
n = int(input())
restaurants = [input().split() for i in range(n)]
stores = {}
for name, value in restaurants:
  stores.setdefault(name, [])
  stores[name].append(int(value))
for key, value in stores.items():
  stores[key] = sorted(value, reverse=True)
for name in sorted(stores):
  for i in stores[name]:
    print(restaurants.index([name, str(i)])+1)

Solution (Python):
N = input()
N = int(N)
R_list = [[0]*3 for i in range(N)]
for h in range(N):
    S, P = input().split()
    P = int(P)
    R_list[h][0] = S
    R_list[h][1] = P
    R_list[h][2] = h + 1

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

Solution (Python):
from operator import itemgetter

N = int(input())

news = []

for i in range(N):
  hoge = input().split()
  news.append((str(hoge[0]),int(hoge[1])))

b = sorted(news, key=itemgetter(1), reverse=True)
c = sorted(b, key=itemgetter(0))

for i in range(N):
  for j in range(N):
    if c[i] ==news[j]:
      print(j+1)

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

def comp(tsmall,tlarge):
    if tsmall[0]==tlarge[0]:
        return tsmall[1]>tlarge[1]
    else:
        return tsmall[0]<tlarge[0]
    
def sort(a):
    for i in range(0,n):
        for j in range(n-1,i,-1):
            if comp(a[j],a[j-1]):
                a[j],a[j-1]=a[j-1],a[j]

sort(rs)
for i in range(len(rs)):
    print(rs[i][2]+1)

Solution (Python):

from collections import defaultdict
n = int(input())
restaurants = defaultdict(list)
for i in range(n):
    parse = input().split()
    restaurants[parse[0]].append((i + 1, int(parse[1])))

for key in sorted(restaurants):
    for idx, score in sorted(restaurants[key], key=lambda x: x[1], reverse=True):
        print(idx)

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

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

Solution (Python):

from operator import itemgetter

N = int(input())

lst_1 = []

for i in range(N):

    lst_2 = []
    lst_2.extend(input().split())
    lst_2.append(str(i + 1))
    lst_1.append(lst_2)

for i in range(N):

    lst_1[i][1] = int(lst_1[i][1])

lst_1.sort(key=itemgetter(1))

lst_1.reverse()

lst_1.sort(key=itemgetter(0))

for i in range(N):

    print(int(lst_1[i][2]))

Solution (Python):
N = int(input())
l = {}
for i in range(N):
    s = input()
    Si , p = s.split(' ')
    if not Si in l:
         l[Si] = []
    l[Si].append((int(p),i))
l = sorted(l.items())
for i in l:
    
    x = dict(i[1])
    
    x = sorted(x.items(),key=lambda y: -y[0])
    for k in x:
        print(k[1]+1)

Solution (Python):
n = int(input())
l = []
for i in range(n):
    d = {}
    d["index"] = i+1
    d["city"], d["score"] = input().split()
    d["score"] = int(d["score"])
    l.append(d)
results = []
citys = list(set([l[i]["city"] for i in range(n)]))
citys.sort()
for city in citys:
    sorted_scores = sorted([l[i]["score"] for i in range(n) if l[i]["city"] == city], reverse=True)
    for score in sorted_scores:
        candidate = [l[i]["index"] for i in range(n) if (l[i]["city"] == city)&(l[i]["score"] == score)][0]
        results.append(candidate)
print(*results, sep="\n")

Solution (Python):
name=[]
point=[]
SP=[]
nameset=[]
pp=[]
key=[]

def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]
    
    
n=int(input())
for i in range(n):
    s,p=input().split()
    name.append(s)
    point.append(p)
    SP.append(s)
    SP.append(p)

nameset=list(set(name))
nameset.sort()

for i in range(len(nameset)):
    tmp=func1(name,nameset[i])
    for j in range(len(tmp)):
        pp.append(point[tmp[j]])
    pp=[int(s) for s in pp]
    pp.sort(reverse=True)
    pp=[str(s) for s in pp]
    for k in range(len(pp)):
        key.append(func1(point,pp[k]))
    pp=[]
    
for i in range(n):
    print(key[i][0]+1)

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

R.sort(key=lambda x: -int(x[1]))
R.sort(key=lambda x: x[0])
[print(n) for _, _, n in R]

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

for p in P:
    print(p[0])

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


a = list(set(list(data[i][0] for i in range(N))))
a.sort()

for i in a:
    
    temp=list(map(int, [data[x][1] for x in range(N) if data[x][0]==i]))
    temp.sort(reverse=True)
    temp=map(str,temp)
    for y in temp:
        print(data.index([i,y])+1)

Solution (Python):

n = int(input())
ll = []
d = {}
in_k = []
for i in range(n):
    s, p = map(str, input().split())
    if not s in d:
        d[s] = [[int(p), i+1]]
    else:
        d[s].append([int(p), i+1])
    if not s in in_k:
        in_k.append(s)
tmp = 1
num = 1
keys = sorted(d.keys())
for k in keys:
    d[k].sort(key=lambda x: x[0], reverse=True)
    for i in range(len(d[k])):
        d[k][i].append(num)
        num += 1
    d[k].sort(key=lambda x: x[1])
for k in d.keys():
    for j in range(len(d[k])):
        ll.append(d[k][j][1:])
ll.sort(key=lambda x: x[1])
for l in ll:
        print(l[0])

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

ss = []
ps = []
sps = []

for i in range(n):
    temp = input().split()
    ss.append(temp[0])
    ps.append(temp[1])
    sps.append(temp[0] + ' ' + temp[1] + ' ' + str(i))

def check(sps):
    city = sps[0].split()[0]
    score = int(sps[0].split()[1])

    index = int(sps[0].split()[2])
    target = 0


    for i in range(1, len(sps)):



        if sps[i].split()[0] == city and score < int(sps[i].split()[1]):

            city = sps[i].split()[0]
            score = int(sps[i].split()[1])
            index = int(sps[i].split()[2])
            target = i
        elif sps[i].split()[0] < city:
            city = sps[i].split()[0]
            score = int(sps[i].split()[1])
            index = int(sps[i].split()[2])
            target = i

    
    

    return target, index

for i in range(n):
    target, index = check(sps)
    print(index + 1)
    del sps[target]

Solution (Python):
import sys
import copy

N = int(input())
shops= [[i for i in input().split()] for i in range(N)]
for j in range(N):
    shops[j][1] = int(shops[j][1])
oshops = copy.deepcopy(shops)

for i in range(N):
    for j in range(i+1, N):
        if shops[i][0] > shops[j][0] :
            shops[i], shops[j] = shops[j], shops[i]

for i in range(N):
    for j in range(i+1, N):
        if shops[i][0] == shops[j][0] and shops[i][1] < shops[j][1] :
            shops[i], shops[j] = shops[j], shops[i]


for j in range(N):
    for k in range(N):
        if oshops[k][0] == shops[j][0] and oshops[k][1] == shops[j][1]:
            print(k+1)

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

cities = []
d1 = {}
d2 = {}

for i in range(N):
    s, p = input().split()
    P = int(p)
    if s not in cities:
         cities.append(s)
    if s not in d1:
        l = [P]
        d1[s] = l
    else:
        d1[s].append(P)

    d2[P] = i + 1

newcity = sorted(cities)

for i in newcity:
    newlist = sorted(d1[i], reverse=True)
    for j in newlist:
        print(d2[j])

Solution (Python):
n=int(input())
dic={}
for i in range(n):
    s,p=input().split()
    if s in dic:
        dic[s].append([p,i+1])
    else:
        dic[s]=[[p,i+1]]
d=sorted(dic.items())
for i in range(len(d)):
    d[i]=list(d[i])
    d[i][1]=sorted(d[i][1],key=lambda x:-int(x[0]))
for i in d:
    for j in i[1]:
        print(j[1])

Solution (Python):
n = int(input())
book = []
for i in range(n):
    name, rate = input().split()
    book.append((i+1, name, int(rate)))
b = sorted(book, key=lambda s: s[2], reverse=True)
b2 = sorted(b, key=lambda s: s[1])

for i, _, _ in b2:
    print(i)

Solution (Python):
N = int(input())
restlist = []
for i in range(N):
    name = ""
    point = ""
    name,point = input().split()
    restlist.append([name,100-int(point),i+1])

restlist.sort()

for j in range(N):
    print(restlist[j][2])

Solution (Python):
N = int(input())
S = [[0]*10]*N
P = [0]*N
n = [0]*N
for i in range(N):
    S[i],P[i]= input().split()
    n[i] = i+1

P_list = list(map(int,P))

for j in range (N-1):
    for i in range(N-1):
        if S[i] > S[i+1]:
            tmp = S[i]
            S[i] = S[i+1]
            S[i+1] = tmp
            tmp = P_list[i]
            P_list[i] = P_list[i+1]
            P_list[i+1] = tmp
            tmp = n[i]
            n[i] = n[i+1]
            n[i+1] = tmp
        elif S[i] == S[i+1]:
            if P_list[i] < P_list[i+1]:
                tmp = P_list[i]
                P_list[i] = P_list[i+1]
                P_list[i+1] = tmp
                tmp = n[i]
                n[i] = n[i+1]
                n[i+1] = tmp

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

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

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

m_i = 0
m_p = -1
for i in range(N-1):
    for j in range(i,N):
        if (m_p < P[j]):
            m_i = j
            m_p = P[j]
    tmp = P[i]
    P[i] = P[m_i]
    P[m_i] = tmp
    tmp_s = S[i]
    S[i] = S[m_i]
    S[m_i] = tmp_s
    tmp_i = Idx[i]
    Idx[i] = Idx[m_i]
    Idx[m_i] = tmp_i
    m_p = -1

for i in range(0,N-1):
    for j in range(1,N-i):
        if (S[j] < S[j-1]):
            tmp = P[j]
            P[j] = P[j-1]
            P[j-1] = tmp
            tmp_s = S[j]
            S[j] = S[j-1]
            S[j-1] = tmp_s
            tmp_i = Idx[j]
            Idx[j] = Idx[j-1]
            Idx[j-1] = tmp_i


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

Solution (Python):
from collections import OrderedDict

number = int(input())
character_number = OrderedDict()

for i in range(number):
    name, number = input().split()
    if name in character_number:
        tmp_dict = character_number[name]
        tmp_dict[int(number)] = i + 1
        character_number[name] = tmp_dict
    else:
        number_dict = OrderedDict()
        number_dict[int(number)] = i + 1
        character_number[name] = number_dict

sort_character_number = OrderedDict(sorted(character_number.items(), key = lambda x:x[0]))

resort_dict = {}
for k, v in sort_character_number.items():
    resort_dict[k] = OrderedDict(sorted(v.items(), key = lambda x:x[0], reverse=True))

sort_character_number = OrderedDict(sorted(resort_dict.items(), key = lambda x:x[0]))

for k, v in sort_character_number.items():
    for k_2, v_2 in v.items():
        print(v_2)

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

for i in range(n):
    sp.append(list(input().split()))
    sp[i][1]=int(sp[i][1])
    sp[i].append(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])

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

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

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

Solution (Python):
import heapq

N = int(input())

a = []
for n in range(N):
    sp = input().split()
    s = sp[0]
    p = int(sp[1])
    heapq.heappush(a, (s, -p, n))

while len(a)>0:
    _, _, i = heapq.heappop(a)
    print(i+1)

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

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

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

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

SP = {}
SPset = set()
S = []
P = []
R = []
for i in range(N):
    s, p = input().split()
    SPset.add(s)
    P.append(int(p))
    S.append(s)


SPset = list(SPset)
SPset.sort()

for spset in SPset:
    tmp = [i for i, x in enumerate(S) if x == spset]
    Plist = []
    for t in tmp:
        Plist.append(P[t])
    Plist.sort()
    for p in Plist[::-1]:
        R.append(P.index(p) + 1)
        
for r in R:
    print(r)

Solution (Python):
from operator import itemgetter

n=int(input())
ls=[list(map(str,input().split())) for i in range(n)]
for i in range(len(ls)):
    ls[i][1]=int(ls[i][1])
    ls[i].append(i+1)
ls.sort()

answer=[]
previous=ls[0][0]
while ls!=[]:
    que=[]
    while ls!=[]:
        if ls[0][0]==previous:
            que.append(ls.pop(0))
        else:
            previous=ls[0][0]
            break
    ap_que=sorted(que, key=itemgetter(1))
    ap_que.reverse()
    for k in ap_que:
        answer.append(k)
for i in answer:
    print(i[2])

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

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

Solution (Python):
N = int(input())
S = []
P = []
spa = []
moji = []
memo = {}
for i in range(N):
    s, p = list(input().split())
    if moji.count(s) == 0:
        memo[s] = []
        moji.append(s)
    p = int(p)
    memo[s].append([p, i])
    spa.append([s, p, i])

_spa = sorted(spa)
_moji = sorted(moji)

ans = []
_memo = sorted(memo)


for i in range(len(_memo)):
    buff = sorted(memo[_memo[i]])
    for n in range(len(buff)):
        ans.append(buff[::-1][n])

_len = len(ans)

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

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

res_list = []

for i in range(a):
  b,c = input().split()

  ref = {'name':b, 'point':int(c), 'num': i+1}
  res_list.append(ref)

  
scores_sorted = sorted(res_list, key=lambda x:(x['name'],-x['point']))

for k in scores_sorted:
  print(k['num'])

Solution (Python):
from operator import itemgetter
import copy
N= int(input())
S=[]
P=[]
SP=[]


for i in range(N):
    S1,P1=input().split()
    S.append(S1)
    P.append(int(P1))
    SP.append([S1,int(P1)])
SPold = copy.deepcopy(SP)

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



for i in range(N):
    for j in range(N):
        if SPsort[i] == SPold[j]:
            print(j+1)

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

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

for isp in ISP:
    print(isp[0])

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

array = []
dict_array = {}
for i in range(1, n+1):
  name, p = input().split()
  array.append([name, int(p)])
  dict_array[str(name)+str(p)] = i

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

for i in range(0, len(sort_array)):
  print(dict_array[str(sort_array[i][0])+str(sort_array[i][1])])

Solution (Python):
n = int(input())
S = []
P = []
S_P = {}
index = {}
for i in range(n):
    s, p = input().split()
    if str(s) in S_P.keys():
        S_P[str(s)].append(int(p))
    else:
        S_P[str(s)] = [int(p)]
    index["{}:{}".format(int(p),str(s))] = i + 1

for i in sorted(S_P.keys()):
    for j in sorted(S_P[i], reverse=True):
        print(index["{}:{}".format(j,i)])

Solution (Python):
from operator import itemgetter

n = int(input())
input_list = []
for i in range(n) :
    a = input().split()
    input_list.append((a[0],int(a[1])))  

sorted_list = sorted(input_list, key=itemgetter(1), reverse=True)
sorted_list = sorted(sorted_list, key=itemgetter(0), reverse=False)
    
for i in sorted_list :
    print(input_list.index(i)+1)

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

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


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

Solution (Python):
def qsort_by_point(d3_lst):
    if len(d3_lst) < 2:
        return d3_lst
    
    pivot = d3_lst[0][1]
    more = [i for i in d3_lst if i[1] > pivot]
    less = [i for i in d3_lst if i[1] < pivot]
    same = [i for i in d3_lst if i[1] == pivot]

    return qsort_by_point(more) + same + qsort_by_point(less)

def qsort_by_city(d3_lst):
    if len(d3_lst) < 2:
        return d3_lst
    pivot = d3_lst[0][0]
    more = [i for i in d3_lst if i[0] > pivot]
    less = [i for i in d3_lst if i[0] < pivot]
    same = [i for i in d3_lst if i[0] == pivot]

    return qsort_by_city(less) + same + qsort_by_city(more)

N = int(input())

restrant_and_point_lst = []

for number in range(1, N+1):
    Si, Pi = input().split()
    Pi = int(Pi)

    restrant_and_point_lst.append((Si, Pi, number))


restrant_and_point_lst = qsort_by_point(restrant_and_point_lst)
restrant_and_point_lst = qsort_by_city(restrant_and_point_lst)

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

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

s = sorted(list(set([l[i][0] for i in range(n)])))
for q in s:
    p = sorted([int(l[i][1]) for i in range(n) if l[i][0] == q], reverse=1)
    for pp in p:
        ans = l.index([q,str(pp)]) + 1
        print(ans)

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

Solution (Python):
import copy

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

calSP = copy.deepcopy(SP)
calSP = sorted(calSP, key=lambda x:(x[2]), reverse=True)
ss = sorted(ss)
num = 1
for sss in ss:
    for cal in calSP:
        if cal[1] == sss:
            cal.append(num)
            num += 1
calSP = sorted(calSP, key=lambda x:(x[3]))
for cal in calSP:
    print(cal[0])

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

r = []
city = [""] * n
for i in range(n):
    s, p = map(str, input().split())
    r.append([i+1,s,p])
    city[i] = s


cs = set(city)
cs_sorted = sorted(cs)

rs = sorted(r)
for c_name in cs_sorted:
    tmp = []
    for i in range(n):
        if rs[i][1] == c_name:
            tmp.append([int(rs[i][2]), rs[i][0]])

    rest =  sorted(tmp, key=lambda x: x[0], reverse=True)
    for pp, rank in rest:
        print(rank)

Solution (Python):
N = int(input())
S = []
P = []
res = [-1]*N
for i in range(N):
    tmp = input().split()
    S.append(tmp[0])
    P.append(int(tmp[1]))
    this = 1
    for j in range(i):
        if S[i] < S[j]:
            res[j] += 1
            continue
        if S[i] == S[j]:
            if P[i] > P[j]:
                res[j] += 1
                continue
        this += 1
    res[i] = this
ans = [-1]*N
for i, v in enumerate(res):
    ans[v-1] = i + 1
for v in ans:
    print(v)

Solution (Python):
import numpy as np
N= int(input())
s_list = []
p_list = []
for _ in range(N):
    s, p = input().split()
    s_list.append(s)
    p_list.append(int(p))

s_unique = list(set(s_list))
s_unique.sort()
for s in s_unique:
    ps = []
    indexs = [i for i,x in enumerate(s_list) if x==s]
    for index in indexs:
        ps.append(p_list[index])
    ps_sorted_index = np.argsort(ps)[::-1]
    for i in ps_sorted_index:
        print(indexs[i]+1)

Solution (Python):
from operator import itemgetter
n = int(input())
a = [input().split() for _ in range(n)]
a = [[i + 1, k, int(v)] for i,(k, v) in enumerate(a)]

a.sort(key=itemgetter(2), reverse=True)

a.sort(key=itemgetter(1))

{print(t[0]) for t in a}

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

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

d = sorted(d.items(), key=lambda y:(y[1][0], -y[1][1]))

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