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



Sample input:
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40


Sample output:
3
4
6
1
5
2

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]

Submission status: Accepted

Solution code:
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 = []

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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(str(S[n]) + " " + str(P[n]) + " " + str(ID[n]))
    print(ID[n])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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[:]
# point rev. sort
sub = sorted(l2, key=itemgetter(1), reverse=True)
# name sort
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)

Submission status: Accepted

Solution code:
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)
        #print(tmp)
        res.extend(tmp)
        index=i

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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=[]

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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):

"""

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
N=int(input())

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

#print(name)

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

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)
#print(s)
f = sorted(s, key=itemgetter(0), reverse=False)
#print(f)

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

Submission status: Accepted

Solution code:
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)
    #print(all)
    if(len(all) == 0):
        break

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

n=int(input())
l=[input().split() for i in range(n)]
"""
# print(l)
for i in range(len(l)):
    l[i].append(i+1)
    l[i][1]=int(l[i][1])
# print(l)
l.sort()
# print(l)
for i in range(len(l)):
    l[i]=irekae(l[i])
# print(l)
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])
#print(l)
l.sort(reverse=True)
#print(l)
for i in range(len(l)):
    l[i]=irekae(l[i])
#print(l)

lx=sorted(l,key=lambda x: x[0])
#print(lx)
for i in range(len(lx)):
    print(lx[i][2])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])
#print(R)
for j in range(N):
  print(Q.index(R[j]) +1)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]

Submission status: Accepted

Solution code:
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]

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])
#print("pairs", pairs)

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
    #print(before_key, tmp_key)
    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])
        #print("ss", before_key, ss)
        for a, b in ss:
            out.append(a)

        tmp_vals = [val]
        tmp_indexes = [index]

    before_key = tmp_key

 
#print("index", tmp_indexes)
#print("vals", tmp_vals)
ss = [[elm1, elm2] for elm1, elm2 in zip(tmp_indexes, tmp_vals)]
ss = sorted(ss, key=lambda x: -x[1])
#print("ss", tmp_key, ss)
for a, b in ss:
    out.append(a)

for elm in out:
    print(elm+1)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n = int(input())
val = {}
c = []
for i in range(n):
    a,b = input().split()
    if a in val:
         val[a].append(int(b))
         c.append(int(b))
    else : 
        val[a] = [int(b)]
        c.append(int(b))

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

d = []
for i in range(len(val_1)):
    if len(val_1[i]) == 1 :
        d.append(val_1[i][1][0])
    else:
        val_1[i][1].sort(reverse= True)
        for h in val_1[i][1]:
            d.append(h)


for i in d :
    for j in range(n):
        if i == c[j]:
            print("{}".format(j+1))

Submission status: Accepted

Solution code:
N = int(input())
dic = []
dic2 = []
for i in range(N):
    dic.append(i)
    dic.extend(input().split())
    dic2.append(dic)
    dic = []

for i in range(N):
    dic2[i][2] = int(dic2[i][2])
dic = sorted(dic2, key=lambda x:(x[1],-x[2]))

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

Submission status: Accepted

Solution code:
from functools import cmp_to_key
N = int(input())

my_list = []

for i in range(N):
    t, c = input().split()
    my_list.append((t, int(c), i+1))

def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1

my_list.sort(key=cmp_to_key(lambda x, y: cmp(x[0], y[0]) or cmp(y[1],x[1])))

for mi in my_list:
    print(mi[2])

Submission status: Accepted

Solution code:
import numpy as np

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

b = sorted(a, key=lambda x:(x[1],-x[2]))
for j in range(0,N):
    print(b[j][0]+1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import math

N = int(input())
d = {}
l = []
for i in range(N):
    s,p = list(input().split(" "))
    d[i+1] = s,p
#print(d[1][0])
d1 = sorted(d.items(),key = lambda x:x[1][0])
#print(d1)
for i in range(N-1):
    for j in range(N-1):
        if d1[j][1][0] == d1[j+1][1][0] and int(d1[j][1][1]) < int(d1[j+1][1][1]):
            #print(d1)
            d1[j],d1[j+1] = d1[j+1],d1[j]
#print(d1)
#print(d1)
for i in range(N):
    print(d1[i][0])

Submission status: Accepted

Solution code:
N = int(input())
restaurant = [[0 for i in range(3)] for j in range(N)]
for i in range(N):
    restaurant[i][0] = i
    restaurant[i][1], restaurant[i][2] = map(str, input().strip().split())
    restaurant[i][2] = int(restaurant[i][2])

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

Submission status: Accepted

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


for k in sorteds:
  print(k[2])

Submission status: Accepted

Solution code:
n=int(input())
A,B,C=[],[],[]
for _ in range(n):
    n = list(input().split())
    A.append([n[0], int(n[1])])
    B.append(n[0])
a=sorted(A)
C = sorted(set(B))
tmp=0
for i in C:
    count=B.count(i)
    for _ in range(B.count(i)):
        # print(A.index(A[]))
        print(A.index(a[tmp+count-1])+1)
        count-=1
    tmp+=B.count(i)

Submission status: Accepted

Solution code:
n = int(input())
L = []
for i in range(n):
  t, p = input().split()
  p = -int(p)
  L.append([i, t, p])
  
L.sort(key=lambda x:(x[1],x[2]))

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

Submission status: Accepted

Solution code:
n=int(input())
i = 1
alllist = []
while i < n+1 :
  a,b=map(str, input().split())
  c = [a ,int(b),i]
  alllist.append(c)
  i += 1
alllist.sort(key=lambda x:(x[0],-x[1]),reverse=True)
alllist.reverse()
j = 0
while j < n :
  print(alllist[j][2])
  j += 1

Submission status: Accepted

Solution code:
N = int(input())

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

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


new_S = sorted(S)

same_v = []
same_i = []
for i, name in enumerate(new_S):
    for k in range(N):
        if new_S[i] == S[k]:
            same_v.append(P[k])
            same_i.append(k)
    x = same_i[same_v.index(max(same_v))]
    print(x + 1)
    same_v = []
    same_i = []
    P[x] = -1

Submission status: Accepted

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


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


for j in range(n):
    for i in range(n):
        if set(s[i]) == set(t[j]):
            print(i+1)
            break

Submission status: Accepted

Solution code:
from bisect import insort_left as il
n=int(input())
a=[]

d={}
for i in range(n):
    s,p=input().split()
    p=int(p)
    a.append(p)
    
    if s not in d:
        d[s]=[p]
    else:
        il(d[s],p)

s=sorted(d)




for i in s:
    
    
    for j in range(len(d[i])):
        print(a.index(d[i].pop())+1)

Submission status: Accepted

Solution code:
n = int(input())

li = []

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

li.sort(key = lambda tup: tup[0])

li2 = []
while len(li) > 0:
  key = li[0][0]
  flag = True
  while flag and len(li) > 0:
    if li[0][0] == key:
      li2.append(li.pop(0))
    else:
      flag = False
  li2.sort(key = lambda tup: tup[1], reverse = True)
  for x in li2:
    print(x[2])
  li2 = []

Submission status: Accepted

Solution code:
from operator import itemgetter

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

last = shops[0][0]
lasti = 0

for i in range(N+1):
    if shops[i][0] != last:
        ans = sorted(shops[lasti:i],key=itemgetter(1),reverse=True)
        for a in ans:
            print(a[2])
        last = shops[i][0]
        lasti = i

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
#import numpy as np
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())



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


    rev_list_p_sorted = sorted(rev_list, key=lambda x: x[2], reverse=True)
    rev_list_s_sorted = sorted(rev_list_p_sorted, key=lambda x: x[1])
    # print(rev_list)
    # print(rev_list_p_sorted)
    # print(rev_list_s_sorted)

    for rev in rev_list_s_sorted:
        print(rev[0])

    # s_list = []
    # p_list = []
    # n = int(input())
    # for i in range(n):
    #     s, p = input().split()
    #     s_list.append(s)
    #     p_list.append(int(p))
    # s_npa = np.array(s_list, dtype=str)
    # p_npq = np.array(p_list, dtype=int)
    #
    # argp = np.argsort(p_npq)[::-1]
    # # print(argp)
    # # print(s_npa[argp])
    # args = np.argsort(s_npa[argp])
    # idx = np.array(range(n))[argp][args] + 1
    # for i in idx:
    #     print(i)

solve()

Submission status: Accepted

Solution code:
N = int(input())
sp=[[0]*3 for i in range(N)]
for i in range(N):
    sp[i][0], sp[i][1] = input().split()
    sp[i][1] = int(sp[i][1])
    sp[i][2] = i+1

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

list2 = sorted(list, key=itemgetter(1), reverse=True)
# print(list2)
list3 = sorted(list2, key=itemgetter(0))
# print(list3)

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

Submission status: Accepted

Solution code:
N=int(input())
L={}
for i in range(N):
    a,b=input().split()
    if a in L.keys():
        L[a].append([int(b),i+1])
    else:
        L[a]=[[int(b),i+1]]
L1= sorted(L.items(), key=lambda x:x[0])
for i in range(len(L1)):
    a=L1[i][1]
    a.sort(key=lambda x:x[0],reverse=True)
    for j in range(len(a)):
        print(a[j][1])

Submission status: Accepted

Solution code:
n = int(input())
init = []
tosort = []
final = []

for i in range(n):
    s, p = (str(_) for _ in input().split())
    init.append([s,int(p)])
cities = sorted(init)

prev = cities[0][0]

for city in cities:
    if city[0] == prev:
        tosort.append(city)
    else:
        tosort.sort(key=lambda x: x[1], reverse = True)
        final += tosort
        tosort = []
        tosort.append(city)
    prev = city[0]
tosort.sort(key=lambda x: x[1], reverse = True)
final += tosort

for f in final:
    print(init.index(f)+1)

Submission status: Accepted

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


for k in sorteds:
  print(k[2])

Submission status: Accepted

Solution code:
n=int(input())
data=sorted([[i for i in input().split()]+[_] for _ in range(n)],key=lambda x:x[0])
for i in range(n):
    data[i][1]=int(data[i][1])
l=[]
tmp=[(data[0][1],data[0][2])]
for i in range(1,n):
    if data[i][0]!=data[i-1][0]:
        l.append(tmp)
        tmp=[]
    tmp.append((data[i][1],data[i][2]))
l.append(tmp)

for i in range(len(l)):
    l[i]=sorted(l[i],key=lambda x:x[0])[::-1]
ans=[0]*n
count=0
for i in l:
    for j in i:
        ans[count]=j[1]+1
        count+=1
print(*ans,sep='\n')

Submission status: Accepted

Solution code:

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

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


copyli = li.copy()
ans = []
##copyli.sort()
a = sorted(copyli, key = lambda copyli: copyli[1],  reverse=True)
c = sorted(a, key = lambda a: a[0])


##copyli.sort(key=attrgetter(1), reverse=True)

for i in range(N):
    for j in range(N):
        if (li[j][0] == c[i][0]) and (li[j][1] == c[i][1]):
            ans.append(j+1)

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