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())
li = []
for i in range(n):
    a, b = input().split()
    b = int(b)
    li.append([a, b, i+1])

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

Submission status: Accepted

Solution code:
n=int(input())

s = [0] * n
p = [0] * n
for i in range(n):
    s[i], p[i] = map(str,input().split())
    
P = [int(s) for s in p]
L=[]

for i in range(n):
    count=1
    for j in range(n):
        if i==j:
            continue
        if s[i]>s[j]:
            count=count+1
        if s[i]<s[j]:
            continue
        if s[i]==s[j]:
            if P[i]<P[j]:
                count=count+1
            else:
                continue
    L.append(count)

for i in range(n):
    print(L.index(i+1)+1)

Submission status: Accepted

Solution code:
N = int(input())
SP = [[i for i in input().split()]+[j] for j in range(N)]
for n in range(N):
    SP[n][1] = int(SP[n][1])
SP.sort(key=lambda x:x[1],reverse=True)
SP.sort(key=lambda x:x[0])


        
for n in range(N):
    print(SP[n][2]+1)

Submission status: Accepted

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

newSP = sorted(SP,key = lambda tup:(tup[1],-tup[2]))

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

Submission status: Accepted

Solution code:
from operator import itemgetter
N=int(input()) 
s = [input().split() for i in range(N)]
for i in range(N):
    s[i][1] = s[i][1].zfill(3)
    s[i].append(i)
s.sort(key=itemgetter(1),reverse=True)
s.sort(key=itemgetter(0))
[print(s[i][-1]+1) for i in range(N)]

Submission status: Accepted

Solution code:
#bin/usr/env python3

n = int(input())

s =[]
p =[]

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

s_list = sorted(s, key=lambda x:(x[0],-x[1]))
rank =[0 for i in range(n)]

for i in range(n):
    for j in range(n):
        if (s_list[i] == s[j]):
            rank[i] = j+1
            
for i in range(n):
    print(rank[i])

Submission status: Accepted

Solution code:
N = int(input())

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

ss = list(set(S))
ss.sort()

a = []
b = []
for i in ss:
    for s, p in t:
        if i == s:
            a.append(p)
    b.extend(sorted(a, reverse=True))
    a = []

for i in range(len(b)):
    for j in range(len(P)):
        if b[i] == P[j]:
            print(j+1)
            break

Submission status: Accepted

Solution code:
N = int(input())
M = [0 for i in range(N*3)]
for i in range(N):
    M[i *3], M[i * 3 +1] = input().split()
    M[i * 3 + 2] = i + 1
arr = [[0 for column in range(3)] for row in range(N)]
for i in range(N):
    arr[i][0] = M[i *3]
    arr[i][1] = int(M[i * 3 +1])
    arr[i][2] = M[i * 3 +2]
arr = sorted(arr, key=lambda x:(x[0], x[1]), reverse = True)
arr = sorted(arr, key=lambda x:x[0])
for i in range(N):
    print(arr[i][2])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())

    SP_list = [[i+1] + list(input().split()) for i in range(N)]

    SP_list = [[int(sp[0]), str(sp[1]), int(sp[2])] for sp in SP_list]

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

Submission status: Accepted

Solution code:
n = int(input())
lis = []
for i in range(n):
    s,p = map(str,input().split())
    lis.append([s,100 - int(p)])
liss = lis.copy()
lis.sort()
for i in range(n):
    print(liss.index(lis[i]) + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
cityscore=[]
cityscore_true=[]
for i in range(n):
  s,p=input().split()
  cityscore.append((s,int(p)))
cityscore_true=sorted(cityscore)
for i in range(n):
  for j in range(n):
    if cityscore_true[i][0]==cityscore_true[j][0]:
      if cityscore_true[i][1]>cityscore_true[j][1]:
        cityscore_true.insert(j,cityscore_true[i])
        cityscore_true.pop(i+1)
for i in range(n):
  print(cityscore.index(cityscore_true[i])+1)

Submission status: Accepted

Solution code:
N=int(input())
S=[['' for i in range(3)] for j in range(N)]
S3=[['' for i in range(3)] for j in range(N)]
for i in range(N):
  a=input().split()
  S[i][0]=(int(a[1]))
  S[i][1]=(a[0])
  S[i][2]=(i+1)
S2=sorted(S, reverse=True, )
for i in range(N):
  S3[i][0]=S2[i][1]
  S3[i][1]=S2[i][0]
  S3[i][2]=S2[i][2]
S4=sorted(S3, key = lambda x:x[0])
for i in range(N):
  print(S4[i][2])

Submission status: Accepted

Solution code:
a= input()
dict ={}
for num in range(int(a)):
    b= input().split()
    if b[0] in dict:
      dict[b[0]][int(b[1])]=num
    else:
      dict2={}
      dict2[int(b[1])]=num
      dict[b[0]] = dict2

dict = sorted(dict.items())
for i in dict:
  lits_i =i[1]
  dict2 = sorted(lits_i .items(), reverse=True)
  for j in dict2:
    print(j[1]+1)

Submission status: Accepted

Solution code:
n = int(input())
sp = {}
ids = {}

for i in range(n):
    tmp = input().split()

    if tmp[0]in ids:
        ids[tmp[0]][int(tmp[1])] = i+1
    else:
        ids[tmp[0]] = {}
        ids[tmp[0]][int(tmp[1])] = i+1

    if tmp[0] in sp:
        sp[tmp[0]].append(int(tmp[1]))
    else:
        sp[tmp[0]] = [int(tmp[1])]

ks = list(sp.keys())
ks.sort()

for k in ks:
    sp[k].sort(reverse=True)
    # print(sp[k])
    for i in range(len(sp[k])):
        print(ids[k][sp[k][i]])
# print(ids)

Submission status: Accepted

Solution code:
def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged

# 以上マージソート

N = int(input())
 
list = []
 
for i in range(N):
    A, B = input().split()
 
    A = A + "000000000000"
    A = A[:10]
    B = str(2000-int(B))+str(i+1001)
    list.append(A+B)
 
list = merge_sort(list)
 
for i in list:
    print(int(i[-3:]))

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
city = [0]*N
score = [0]*N
itetator = [0]*N
for i in range(N):
    city_i, score_str = input().split()
    city[i] = city_i
    score_i = int(score_str)
    score[i] = score_i
    itetator[i] = i+1
for j in range(N):
    for k in range(N-1):
        if city[k] > city[k + 1]:
            city[k], city[k + 1] = city[k + 1], city[k]
            score[k], score[k + 1] = score[k + 1], score[k]
            itetator[k], itetator[k + 1] = itetator[k + 1], itetator[k]

        elif city[k] == city[k + 1] and score[k] < score[k + 1]:
            score[k], score[k + 1] = score[k + 1], score[k]
            itetator[k], itetator[k + 1] = itetator[k + 1], itetator[k]


for m in range(N):
    print("{}".format(itetator[m]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

S = [0] * N
P = [0] * N
A = [[i] * 3 for i in range(1, N+1)]

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

for i in range(N):
    A[i][1]= S[i]
for i in range(N):
    A[i][2]= int(P[i])

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import cycle
N = int(input())
S = []
P = []
for i in range(N):
    s,p = input().split()
    S.append(s)
    P.append(int(p))

dic = defaultdict(list)
for s,p in zip(S,P):
    dic[s].append(p)

for k in dic:
    dic[k].sort(reverse = True)

city = sorted(set(S))

SP = dict()
for i,s,p in zip(range(1,N+1),S,P):
    SP[(s,p)] = i
ans = []
for c in city:
    for po in dic[c]:
        ans.append((c,po))
for a in ans:
    print(SP[a])

Submission status: Accepted

Solution code:
n = int(input())

d1 = dict()

for i in range(n):
	s, p = [x for x in input().split()]
	if (s not in d1.keys()):
		d1[s] = []
		d1[s].append((int(p), i + 1))
	else:
		d1[s].append((int(p), i + 1))

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

l1 = list()

for k, v in d1.items():
		l1.append((k, v))

l1.sort()

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

Submission status: Accepted

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

for row in SP:
    row[1] = int(row[1])

hoge = sorted(SP, key = lambda x:x[1], reverse = True)
SPsort = sorted(hoge, key = lambda x:x[0])

for i in range(N):
    print(SP.index(SPsort[i]) + 1)

Submission status: Accepted

Solution code:
n = int(input())
ss = []
for i in range(n):
    s, p = input().split()
    ss.append(s+"{:03}".format(200-int(p)))

sss = []
for s in ss:
    sss.append(s)
sss.sort()
for s in sss:
    print(ss.index(s)+1)

Submission status: Accepted

Solution code:
n = int(input())
shop_list = list()
shop_dict = dict()
for i in range(n):
  s, p = input().split()
  p = int(p)
  shop_list.append(tuple([s, p]))
  shop_dict[tuple([s,p])] = i + 1
  #print(shop_dict)
shop_list = sorted(shop_list, key = lambda x:x[1], reverse = True)
#print(shop_list)
shop_list = sorted(shop_list, key = lambda x:x[0])
#print(shop_list)

for shop in shop_list:
  print(shop_dict[shop])

Submission status: Accepted

Solution code:
n=int(input())
rows=[input().split() for i in range(n)]
new_rows=sorted(rows)
new_rows.sort(key=lambda x: (x[0],-int(x[1])))
for i in range(n):
    print(rows.index(new_rows[i])+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
lt = []
for i in range(N):
	S, P = map(str, input().split())
	lt.append([S, int(P)])
	dic.setdefault(S, []).append(int(P))
dic = sorted(dic.items())
for i in range(len(dic)):
	key = dic[i][0]
	value = dic[i][1:][0]
	value.sort(reverse=True)
	for j in range(len(value)):
		print(lt.index([key, value[j]]) + 1)

Submission status: Accepted

Solution code:
from operator import itemgetter as ite

n=int(input())
l=[]
name=[]
for i in range(n):
    l.append(list(input().split()))
    name.append(l[i][0])
name=set(name)
name=list(name)
name.sort()

na=len(name)
tmp=99
k=0
ma=0
while k!=na:
    for j in range(len(l)):
        if l[j][0]==name[k]:
            if ma<=int(l[j][1]):
                ma=int(l[j][1])
                out=j
    if tmp==out:
        k+=1
    else:
        print(out+1)
        l[out][1]=-3
    ma=0
    tmp=out

Submission status: Accepted

Solution code:
n = int(input())
ans = []

for i in range(n):
    x, y = input().split()
    y = int(y)
    ans.append([x, y])

newans = ans.copy()

newans.sort(key = lambda x: (x[0], -x[1]))
for i in newans:
    print(ans.index(i)+1)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
alst = []
slst = defaultdict(list)
for i in range(N):
    k, v = map(str, input().split())
    slst[k].append(v)
    alst.append(k + ',' + v)

tmp = sorted(slst)
xlst = []
for i in tmp:
    x = slst[i]
    xx = []
    for j in x:
        xx.append(int(j))
    xtmp = sorted(xx, reverse=True)
    for j in xtmp:
        xlst.append(i + ',' + str(j))

anslst = [0] * N
anstmp = 0
for i in xlst:
    for j in range(len(alst)):
        if alst[j] == i:
            anslst[anstmp] = j + 1
            anstmp += 1
            break

for i in anslst:
    print(i)

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
j = []
h = []
index = 1
for i in range(n):
    s, p = readms()
    p = -(int(p))
    heapq.heappush(h, (s, p,index))
    index += 1
index = 1
while(h):
    s,p,index = heapq.heappop(h)
    print(index)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
dic = defaultdict(list)
dic2 = {}
for i in range(N):
    S,P = input().split()
    new = [P,i]
    dic[S].append(new)
ans = sorted(dic.items(), key=lambda x: x[0])
for i in ans:
    new_i = list(i)[-1]
    # print(new_i)
    x = []
    for i1 in new_i:
        # print(i1)
        dic2[i1[0]] = i1[-1]
        x.append(int(i1[0]))
    else:
        x.sort(reverse=True)
        for i in x:
            print(dic2[str(i)]+1)

Submission status: Accepted

Solution code:
# coding: UTF-8

N = int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())
sp = []
for i in range(n):
    a,b= input().split(" ")
    sp.append([a,int(b),i+1])
sp.sort()

ans = []
t = []
for j in range(len(sp)):
    if j == len(sp) - 1:
        t.append(sp[j])
        t.reverse()
        ans.append(t)
        break
    if sp[j][0] == sp[j+1][0]:
        t.append(sp[j])
    else:
        t.append(sp[j])
        t.reverse()
        ans.append(t)
        t = []

for w in ans:
    for x,y,z in w:
        print(z)

Submission status: Accepted

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

# 得点が高い＝100からの減算値が小さい。文字列を昇順に並べながら得点が高い特徴を並べやすく
# 文字列と入力順番値を辞書型で登録
sp = {s.lower()+' '+"{:03}".format(100-int(p)):n+1 for n, (s, p) in enumerate(SP)}

# 昇順文字列に並べ、その文字列に対応する入力順番値を表示する
for k in sorted(sp):
    print(sp[k])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
info = []
for i in range(N):
  list = []
  S_i,P_i=input().split()
  list.append(S_i)
  list.append(100-int(P_i))
  list.append(i)
  info.append(list)
info.sort()
for i in range(N):
  print(info[i][2]+1)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    data = []
    for i in range(1, N+1):
        tmp = []
        city, score = input().split()
        tmp.append(i)
        tmp.append(city)
        tmp.append(int(score))
        data.append(tmp)

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=[]
b=[]


for i in range(n):
    s,p=input().split()
    p=int(p)
    a.append(s)
    b.append(p)

x=list(zip(a,b))

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

for i in range(n):
    print(int(x.index(y[i]))+1)

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    D = defaultdict(list)
    names = set()
    N = int(input())
    for i in range(1, N+1):
        inp = input().split()
        s = inp[0]
        p = inp[1]
        names.add(s)
        D[s].append((p, i))
    names = sorted(list(names))
    for n in names:
        D[n].sort(key=lambda x: int(x[0]), reverse=True)
        for x in D[n]: print(x[1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

x.sort()

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

Submission status: Accepted

Solution code:
n=int(input())
l=[[0]*3 for _ in range(n)]
for i in range(n):
  s,c=input().split()
  l[i][0]=s
  l[i][1]=int(c)
  l[i][2]=int(i+1)
A=sorted(l,key=lambda x:(x[0],-x[1]))
for i in range(n):print(A[i][2])

Submission status: Accepted

Solution code:
N = int(input())
SP = [input().split() for _ in range(N)]
r = []
g= 1
for x, y in SP:
  r.append([x, int(y), g])
  g+=1

sortV = sorted(r, key = lambda x: -x[1])
sortK = sorted(sortV, key = lambda x: x[0])

for x, y,z in sortK:
  print(z)

Submission status: Accepted

Solution code:
N = int(input())
from collections import defaultdict
res = defaultdict(list)
for i in range(N):
    S1,P1 = input().split()
    res[S1].append([int(P1),i])

for k,v in sorted(res.items()):
    lists = sorted(res[k],reverse=True)
    # print(lists)
    for l in lists:
        print(l[1]+1)

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
s = [input().split() for i in range(n)]
for i in range(len(s)):
    s[i].append(i+1)
    s[i][1] = int(s[i][1])
s = sorted(s,key=lambda x:(x[0],-x[1]))

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())

x =[]
for i in range(n):
    x1, y1 = [i for i in input().split()]
    x.append(x1+"{0:04d}".format(100-int(y1)))

for i in range(len(x)):
    print(np.argsort(x)[i]+1)

Submission status: Accepted

Solution code:
r_num = int(input())
r_list = []

for i in range(r_num):
    name, score = input().split()
    temp_li = [i + 1, name, int(score)]
    r_list.append(temp_li)

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

for index, name, score in r_sorted_li:
    print(index)

Submission status: Accepted

Solution code:
from sys import stdin


n = int(stdin.readline().rstrip())
a = [stdin.readline().rstrip().split() for _ in range(n)]

#b=[0]*n



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

#b=sorted(a,reverse=True ,key=lambda x: x[1])

#print(b)

#b.sort()
a.sort()

for i in range(n):
    for j in range(n-1):
        if(a[j][0]==a[j+1][0] and a[j][1]<a[j+1][1]):
            k=a[j]
            a[j]=a[j+1]
            a[j+1]=k


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

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

Submission status: Accepted

Solution code:
n=int(input())

line=[]

for i in range(n):
    sub=list(input().split( ))
    sub[1]=-int(sub[1])
    sub.append(i+1)
    line.append(sub)

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

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

Submission status: Accepted

Solution code:
N=int(input())
lis=[]
for i in range(N):
    A,B=input().split()
    B=str(999-int(B))
    lis.append(A+B+'_'+str(i))
               
lis=sorted(lis)
for i in range(N):
    print(int(lis[i].split('_')[1])+1)

Submission status: Accepted

Solution code:
N = int(input())

List = []

for i in range(N):
    S_i,P_i = map(str, input().split() )
    temp_list = [i+1, S_i, int(P_i)]
    List.append(temp_list)

result = sorted(List,key=lambda x:x[2], reverse = True)
result = sorted(result,key=lambda x:x[1])

for j in range(N):
    print(str(result[j][0]))

Submission status: Accepted

Solution code:

def main():
    N = int(input())
    SP_list = [list(list(input().split())) for i in range(N)]

    # N = 6
    # SP_list = [['khabarovsk', '20'], ['moscow', '10'], ['kazan', '50'], ['kazan', '35'], ['moscow', '60'], ['khabarovsk', '40']]

    for i, line in enumerate(SP_list):
        line[1] = -int(line[1])
        line.append(str(i + 1))
    SP_list.sort(key=lambda x: (x[1], x[2]))
    SP_list.reverse()
    SP_list.sort()

    for line in SP_list:
        print(line[2])
    pass


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())

book = []

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

book = sorted(book, key = itemgetter(2), reverse = True)
book = sorted(book, key = itemgetter(1))

for num in book:
  print(int(num[0])+1)

Submission status: Accepted

Solution code:

N=int(input())
#cmdから2次元配列Gを作成
G = []
for i in range(N):
    array = list(input().strip().split())
    G.append(array)
for i, alpha in enumerate(G):
    alpha.append(i)
for i in range(0,N):
    y=G[i][1]
    G[i][1]=int(y)


#print(G)
tmp = sorted(G, key=lambda x:x[1], reverse=True)
b= sorted(tmp, key=lambda x:x[0])
#print(b)
for i in range (0,N):
    print(int(b[i][2])+1)

Submission status: Accepted

Solution code:
import sys

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

for i in range(0,n):
    si,pi = input().split()
    list.append({'i':i,'s':si,'p':int(pi)})

list = sorted(list, key=lambda x: (x['s'],-x['p'])) 

for i in range(0,n):
    print(list[i]['i']+1)

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
rest = []

for i in range(N) :
  raw = list(input().split())
  raw[1] = int(raw[1]) 
  raw.append(int(i + 1))
  rest.append(raw)

rest.sort(key=itemgetter(1), reverse = True )
rest.sort(key=itemgetter(0))

for k in range(N) :
  print(rest[k][2])

Submission status: Accepted

Solution code:
n = int(input())
restaurants = {}
cities = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    if s not in cities:
        cities.append(s)
    if s not in restaurants.keys():
        restaurants[s] = []
    restaurants[s].append([p, i+1])

cities.sort()
for city in cities:
    restaurants[city] = sorted(restaurants[city], key=lambda x:x[0], reverse=True)
    for res in restaurants[city]:
        print(res[1])

Submission status: Accepted

Solution code:
N = int(input())
restran_dict = {}
for i in range(N):
  city, score = input().split()
  try: 
    restran_dict[city].append((i+1,int(score)))
  except :
    restran_dict[city] = []
    restran_dict[city].append((i+1,int(score)))

sorted_city_names = sorted(restran_dict.keys())

def get_score_id(dict_,key_):
    return [(i,v, key_) for i,v in reversed(sorted(dict_[key_],key=lambda x:x[1]))]
result_list = []
for k in sorted_city_names:
  result_list.extend(get_score_id(restran_dict,k))
for i in result_list:
  print(i[0])

Submission status: Accepted

Solution code:
import sys
args = sys.stdin.readlines()
N = int(args[0])
d = {}
for i, line in enumerate(args[1:]):
  S, p = line.split(' ')
  P = int(p)
  if S in d:
    d[S].append((i+1, P))
  else:
    d[S] = []
    d[S].append((i+1, P))
    
for key in sorted(d.keys()):
    d[key].sort(key=lambda x:x[1], reverse=True)
    for (i, p) in d[key]:
        print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def sort1(A):
    for i in range(0, len(A)-1):
        select_min(A,i)
    return A

def select_min(A,i):
    min = i
    for j in range(i+1, len(A)):
        if A[min][0] == A[j][0]:
            if A[min][1] < A[j][1]:
                min = j
    A[i], A[min] = A[min], A[i]

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

SPlist = sort1(SPlist)
        
for u in range(N):
    print(SPlist[u][2])

Submission status: Accepted

Solution code:
N = int(input())
list = []
for i in range(N):
    input_list = input()
    S = input_list.split(" ")[0]
    P = int(input_list.split(" ")[1])
    list.append([i, S, P])

#from operator import itemgetter

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

for key,val in sorted(test_dict.items(), key=lambda x: x[0]):
    for j in sorted(val, key=lambda x:x[0], reverse=True):
        print(j[1])

Submission status: Accepted

Solution code:

N=int(input())
if N==1:
    print(1)
else:

    a=[]

    for i in range(N):
        d=list(map(str,input().split()))
        d.append(i+1)
        a.append(d)

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

    for i in range(N):
        a[i][1]=int(a[i][1])


    k=0
    b=[]
    c=[]
    c.append(a[0])
    for i in range(N-1):
        if a[i][0]==a[i+1][0]:
            c.append(a[i+1])
        else:
            c.sort(key=lambda x:x[1])
            c.reverse()
            k=len(c)

            for j in range(k):
                b.append(c[j][2])
            c=[]
            c.append(a[i+1])

    k=len(c)
    c.sort(key=lambda x: x[1])
    c.reverse()
    for j in range(k):
        b.append(c[j][2])


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

Submission status: Accepted

Solution code:
n = int(input())
list = []

for i in range(n) :
	s,p = input().split()
	p = str(100-int(p))
	if (int(p) < 10) : p = '00' + p
	elif(int(p) < 100) : p = '0' + p
	index = str(i)
	if (i < 10) : index = '00' + index
	elif (i < 100) : index = '0' + index
	list.append(s+p+index)

list.sort()
for i in range(n) :
	print(int(list[i][-3:])+1)

Submission status: Accepted

Solution code:
from operator import itemgetter, attrgetter

class data:
    def __init__(self, i, c, n):
        self.ind = i
        self.city = c
        self.num = -int(n)

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

d.sort(key=attrgetter('city', 'num'))

for i in range(N):
    print(d[i].ind+1)

Submission status: Accepted

Solution code:

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

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

for item in dd:
    s = sorted(item[1], key=lambda x:x[0], reverse=True)
    for r in s:
        print(r[1])

Submission status: Accepted

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

s = sorted(enumerate(s),key= lambda x:(x[1][0],-int(x[1][1])))
for i in s:
    print(i[0]+1)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import copy

N = int(input())

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

list = []
for i in range(N):
	temp = [S[i], int(P[i])]
	list.append(temp)

clone = copy.copy(list)

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

for i in range(N):
	print(list.index(clone[i])+1)

Submission status: Accepted

Solution code:
n = int(input())
SP = []
for i in range(n):
  sp = input().split()
  sp.append(i+1)
  SP.append(sp)
sortedSP = sorted(SP, key = lambda x:x[0])
for i in range(n-1):
  for j in range(n-1-i):
    if sortedSP[j][0] == sortedSP[j+1][0] and int(sortedSP[j][1]) < int(sortedSP[j+1][1]):
      sortedSP[j], sortedSP[j+1] = sortedSP[j+1], sortedSP[j]
for i in range(n):
  print(sortedSP[i][2])

Submission status: Accepted

Solution code:
import sys

n=int(input())
if n==1:
	print(1)
	sys.exit()
elif n==0:
	sys.exit()
book=[]
for i in range(n):
	s,p=map(str,input().split())
	book.append([s,int(p),i+1])
book.sort(key=lambda book:book[0])
tmp=[]
for i in range(n):
	if i==0:
		tmp.append(book[i])
	elif tmp[0][0]!=book[i][0]:
		tmp.sort(key=lambda tmp:tmp[1],reverse=True)
		for j in range(len(tmp)):
			print(tmp[j][2])
		tmp.clear()
		if i!=n-1:
			tmp.append(book[i])
		if i==n-1:
			print(book[i][2])
	elif i==n-1:
		tmp.append(book[i])
		tmp.sort(key=lambda tmp:tmp[1],reverse=True)
		for j in range(len(tmp)):
			print(tmp[j][2])
	else:
		tmp.append(book[i])

Submission status: Accepted

Solution code:
N = int(input())
ls = []

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

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter as ig

N = int(input())
li = []
di = {}
for i in range(N):
    Si, Pi = input().split()
    Pi = int(Pi)
    li.append([Si, Pi, i + 1])

li = sorted(li, key=ig(1), reverse=True)

for sp in li:
    if sp[0] in di:
        di[sp[0]].append(sp[2])
    else:
        di[sp[0]] = [sp[2]]
    
for i, j in sorted(di.items(), key=lambda x:x[0]):
    for k in range(len(j)):
        print(j[k])