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())
dic_name={}
dic_num={}
S=[]
P=[]
for i in range(n):
    s,p=input().split()
    S.append(s)
    P.append(int(p))
    dic_name.setdefault(S[i],[]).append(P[i])
    dic_num.setdefault(S[i],[]).append(i+1)
S=sorted(S)

i=0
while(i<n):
    arr_name=list(dic_name[S[i]])
    arr_num=list(dic_num[S[i]])
    for a in range(len(arr_name)):#bubble sort
        for b in range(a,len(arr_name)):
            if arr_name[a]<arr_name[b]:
                arr_name[a],arr_name[b]=arr_name[b],arr_name[a]
                arr_num[a],arr_num[b]=arr_num[b],arr_num[a]#sort num
                
    for a in range(len(arr_name)):
        print(arr_num[a])
    i+=len(dic_name[S[i]])

Submission status: Accepted

Solution code:
from sys import stdin
from copy import deepcopy


n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
for i, list in enumerate(data):
    list[1] = int(list[1])
    list.append(i+1)

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

for i, list in enumerate(sortdata):
    print(list[2])

Submission status: Accepted

Solution code:
N = int(input())
list_all = list()
list_name = list()
list_number = list()

for n in range(N):
  par = input()
  pars = par.split(' ')
  list_all.append([n+1,pars[0],int(pars[1])])
  list_name.append(pars[0])
list_unique = sorted(list(set(list_name)))

for name in list_unique:
  l = list()
  for elem in list_all:
    if elem[1] == name:
      l.append([elem[2],elem[0]])
  l = sorted(l, reverse=True)
  for tmp in l:
    list_number.append(tmp[1])

for num in list_number:
  print(num)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())
items = []
for i in range(N):
    S, P = input().split()
    items.append({'id': i+1, 'S': S, 'P': int(P), 'pri': i})

sorted_items = sorted(
  items,
  key = lambda x: (x['S'], -x['P'])
)

for i in range(N):
    sorted_items[i].update(pri=i+1)

sorted_items2 = sorted(
  sorted_items,
  key = lambda x:x['pri']
)

for i in sorted_items2:
    print(i['id'])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(str,input().split())
c = [int(b[i]) for i in range(n)]
d = [[a[i],c[i],i+1] for i in range(n)]
d.sort(key = lambda x:x[0])
cnt = 0
d[0].append(0)
for i in range(1,n):
    if d[i][0] != d[i-1][0]:
        cnt += 1
    d[i].append(cnt)
d.sort(key = lambda x:x[3]*10**3-x[1])
for i in range(n):
    print(d[i][2])

Submission status: Accepted

Solution code:
n=int(input())
listA=[list(map(str,input().split())) for i in range(n)]
for j in range(n):
    listA[j].append(j+1)
    listA[j][1]=int(listA[j][1])
listB = sorted(listA, key= lambda x:x[1], reverse=True)
listC = sorted(listB, key=lambda x:x[0])
for k in range(n):
    print(listC[k][2])

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
sp = [[i for i in input().split()] for i in range(n)]
sp = [i + [len(i[1])] for i in sp]
sp = [i + [j] for i, j  in zip(sp, range(n))]

sortsecond = lambda val: val[1]
sp.sort(key=sortsecond)

sortsecond = lambda val: val[2]
sp.sort(key=sortsecond)

sortsecond = lambda val: val[0]
sp.sort(key=sortsecond, reverse=True)

ans = np.array(sp[::-1])[:, 3].astype(int) + 1
for i in ans:
  print(i)

Submission status: Accepted

Solution code:
N = int(input())
X =[]
for i in range(N):
  SS,PP = map(str,input().split())
  X.append([int(i+1), SS, int(PP)])

A = sorted(X, key=lambda X:(X[1],-X[2]))

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

Submission status: Accepted

Solution code:
N  = int(input())
dict = {}
dict_shop = {}
for i in range(N):
  buf1,buf2 = input().split()
  buf3 = i+1
  dict.setdefault(buf1,[]).append(int(buf2))
  dict_shop[int(buf2)] = buf3
#print(dict)
list = sorted(dict.keys())
for str in list:
  list_buf =dict[str]
  list_buf.sort()
  list_buf.reverse()
  for i in list_buf:
    print(dict_shop[i])

Submission status: Accepted

Solution code:
a = int(input())

guidebook = {}
for i in range(a):
    li = list(input().split())
    if li[0] in guidebook:
        guidebook[li[0]][i+1] = int(li[1])
    else:
        guidebook[li[0]] = {i + 1: int(li[1])}

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

for rural in shop_sorted:
    # print(rural[1])
    score_sorted = sorted(rural[1].items(), key=lambda x: x[1], reverse=True)
    # print(score_sorted)
    for i in score_sorted:
        print(i[0])

Submission status: Accepted

Solution code:
from collections import defaultdict
dic = defaultdict()
n = int(input())

for i in range(1,n+1):
  k, v = input().split()
  dic[i] = [k, int(v)]
# value [0]asc, [1]dec  
dic_sorted = sorted(dic.items(), key=lambda v:(v[1][0], -v[1][1])) 
[print(k[0]) for k in dic_sorted]

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
dic = defaultdict(lambda : [])
for i in range(n):
    s, p = input().split()
    p = int(p)
    dic[s].append([p, i + 1])
dic = sorted(dic.items())
for t in dic:
    t = list(t[1:])
    t = t[0]
    t.sort(reverse = 1)
    for x in t:
        print(x[1])

Submission status: Accepted

Solution code:

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

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

list.sort(key=lambda x:(x[1],-x[2]))
for l in list:
    print(l[0])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n = int(input())


l = []

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

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])

Submission status: Accepted

Solution code:
N = int(input())
all_point_list = [input().split() for _ in range(N)]
for each_list in all_point_list:
    each_list[1] = int(each_list[1])
sorted_all_list = sorted(all_point_list, key=lambda x:(x[0], -x[1]))
for sorted_point in sorted_all_list:
    print(all_point_list.index(sorted_point) + 1)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
from operator import itemgetter 

N = int(stdin.readline())

#[競プロ等におけるpython3の標準入力 \- Qiita](https://qiita.com/zenrshon/items/c4f3849552348b3dbe67)
SP = []
for i in range(N):
    s,p = input().split()
    SP.append([s,int(p),i+1])

# [ソート HOW TO — Python 3\.7\.3 ドキュメント](https://docs.python.org/ja/3/howto/sorting.html)
# [sorted\(a, key=lambda x:\(x\[0\],\-x\[1\]\)\)](https://pashango-p.hatenadiary.org/entry/20090614/1244984058)
SP = sorted(SP, key=lambda x:(x[0],-x[1]))

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

Submission status: Accepted

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

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

list=sorted(list)
del_list=[]

while len(list)!=0:
    j=0
    list_same_s=[]
    city=list[0][0]
    list_same_s.append([list[0][1],list[0][2]])
    list.pop(0)
    for i in range(len(list)):
        if list[i][0]==city:
            list_same_s.append([list[i][1],list[i][2]])
            j=j+1
    while j!=0:
        list.pop(0)
        j=j-1
    list_same_s=sorted(list_same_s)
    for i in range(len(list_same_s)):
        print(list_same_s[len(list_same_s)-i-1][1]+1)

Submission status: Accepted

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

for i in range(n):
  tmp = input().split()
  tmp[1] = int(tmp[1])
  tmp.append(i+1)
  restaurants.append(tmp)

from operator import itemgetter

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

for j in restaurants:
    print(j[2])

Submission status: Accepted

Solution code:

num = int(input())

shops = {}
narabi = []

for _ in range(num):
    narabi.append(input().split())

jun = 1

for val in narabi:
    name, pt = val
    if name not in shops:
        shops[name] = {}
    shops[name][pt] = jun
    jun+=1

for name in shops:
    shops[name] = sorted(shops[name].items(),key=lambda x: int(x[0]),reverse=True)

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

for name in shops:
    for v in name[1]:
        print(v[1])

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
from collections import defaultdict

inputs =  list(map(int, sys.stdin.readline().split()))
N = inputs[0]

dic = defaultdict(list)
for i in range(N):
    inputs = list(sys.stdin.readline().split())
    dic[inputs[0]].append({"value":int(inputs[1]), "key":i+1})


sort = sorted(dic.items(), key=itemgetter(0))

for s in sort:
    scores_sorted = sorted(s[1], key=lambda x: x['value'], reverse=True)
    for score in scores_sorted:
        print(score.pop("key"))

Submission status: Accepted

Solution code:
# input
N = int(input())
SA = [str(input()) for i in range(N)]

# process
cities = list(set([x.split()[0] for x in SA]))
cities.sort()

for y in cities:
    each_SA = []
    for i in SA:
        if i.split()[0] == y:
            each_SA.append(i)
    each_points = [int(x.split()[1]) for x in each_SA]
    each_points.sort(reverse=True)
    for j in each_points:
        print(SA.index(y + ' ' + str(j)) + 1)

Submission status: Accepted

Solution code:
#a, b, c, d = (int(i) for i in input().split())  

#a = [int(i) for i in input().split()] 

#N = (int(i) for i in input().split())  
N = int(input())
# A = [int(i) for i in input().split()] 
#S_dict = {}
#P_dict = {}
# for i in range(N):
#     tmp = input()
#     S = tmp.split()[0]
#     P = int(tmp.split()[1])
#     if S in S_dict.keys() and P < S_dict[S]:
#         pass
#     else:
#         S_dict[S] = P
#         pass
#     pass
# S_dict = sorted(S_dict.items())

# print(type(S_dict))
# name_lisy = []

# for k in S_dict:
#     name_lisy.append(k)
#     pass
# print(name_lisy)
S_list = []
P_list = []
for i in range(N):
    tmp = input()
    S = tmp.split()[0]
    P = int(tmp.split()[1])
    #print(S,P)
    S_list.append([S,P])
    #P_list.append(P)
    pass
#S_list.sort()
#print(S_list)
sorted_S_list = sorted(S_list, key=lambda x:x[1], reverse=True)
sorted_S_list = sorted(sorted_S_list, key=lambda x:x[0])
#print(sorted_S_list)

for i,k in enumerate(sorted_S_list):
    for j,l in enumerate(S_list):
        if sorted_S_list[i] == S_list[j]:
            print(j+1)
            break
        pass
    pass


#print(P_list)

# for i in range(M):
#     # A.sort()
#     if min(A) < C_list[i]:
#         for j in range(B_list[i]):        
#             if min(A) < C_list[i]:
#                 A.append(C_list[i])
#                 pass
#             pass
#         A.sort(reverse=True)
#         A = A[:N]
#         pass
#     pass
# #sum(A[:N-1])
# print(sum(A[:N]))
# for i in range(M):
#     A.sort()
#     cnt = 0
#     for j in range(N):
#         if cnt < B_list[i] and A[j] < C_list[i]:
#             A[j] = C_list[i]
#             cnt += 1
#             pass
#         pass
#     #print(A)
#     pass
# print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


from operator import itemgetter

N = read_a_int()
contents = []
for i in range(N):
    contents.append(list(input().split())+[i+1])

contents = [[a, -int(b), c] for a, b, c in contents]

contents.sort(key=itemgetter(0, 1))
ans = [a[2] for a in contents]
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())
A = []
city = []
for _ in range(n):
    s,p = input().split()
    city.append([s,-int(p)])
    A.append([s,-int(p)])

A = sorted(A, key=itemgetter(0,1))
for a in A:
    print(city.index(a)+1)

Submission status: Accepted

Solution code:
n = int(input())
a = []
c = []
for i in range(n):
  b = input().split()
  b[1] = int(b[1])
  a.append(b)
  c.append(b)

s = sorted(a, key=lambda a:a[1], reverse=True)
m = sorted(s, key=lambda s:s[0])

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

Submission status: Accepted

Solution code:
N = int(input())

S = []
P = []

cities = {}

for i in range(N):
    line = input().split()
    try:
        cities[line[0]].append(i)
    except:
        cities[line[0]] = [i]
    S.append(line[0])
    P.append(int(line[1]))

for k, v in sorted(cities.items()):
    v = sorted(v, key=lambda x: -P[x])
    for vv in v:
        print(vv+1)

Submission status: Accepted

Solution code:
n = int(input())
rep = [input().split()+[i+1] for i in range(n)]
unko = [[i[0],-1*int(i[1]),i[2]] for i in rep]
#print(sorted(rep))
#print(sorted(unko))
unko.sort()
for j in range(n):
  print(unko[j][2])

Submission status: Accepted

Solution code:
n = int(input())
sp = [list(map(str,input().split())) for i in range(n)]
spstd = sorted(sp, key=lambda x:int(x[1]), reverse=True)
spstd.sort(key=lambda x:x[0])

for i in spstd:
  print(sp.index(i)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())

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

all = sorted(list, key=itemgetter(1), reverse=True)
all2 = sorted(all, key=itemgetter(0))
# all = sorted(list, key=lambda x: (x[0], x[1]))

# print(all2)

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
d = {}
di = defaultdict(list)
for i in range(n):
    tmp = input().split()
    s, p = tmp[0], int(tmp[1])
    d[(s, p)] = i+1
    di[s].append(int(p))
dii = list(di.items())
dii.sort(key=lambda x: x[0])

for i in dii:
    si, pi = i[0], i[1]
    pi.sort(reverse=True)
    for j in pi:
        print(d[(si, j)])

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

number = list(range(1, N+1))

lst = [[0]*3 for i in range(N)]

for i in range(N):
    name, point = map(str, input().split())
    point = int(point)
    lst[i][0] = name
    lst[i][1] = point
    lst[i][2] = i + 1

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

name = np.array(lst).T.tolist()[0]
point = np.array(lst).T.tolist()[1]
number = np.array(lst).T.tolist()[2]

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

inputs = input().split(' ')
N = int(inputs[0])

shop_dict = {}
shop_sort = {}
for i in range(N):
    inputs = input().split(' ')
    shop_dict[i] = (inputs[0], int(inputs[1]))
    if inputs[0] in shop_sort.keys():
        shop_sort[inputs[0]].append(int(inputs[1]))
    else:
        shop_sort[inputs[0]] = [int(inputs[1])]
    
for k in shop_sort.keys():
    shop_sort[k] = sorted(shop_sort[k], reverse=True)
names = sorted(shop_sort)

for n in names:
    for x in shop_sort[n]:
        key = [k for k, v in shop_dict.items() if v == (n, x)]
        print(key[0] + 1)

Submission status: Accepted

Solution code:
N = int(input())
s = [0] * N
p = [0] * N

list_ = [0]*N
for i in range(N):
    s[i],p[i] = (input()).split()

for i in range(N):
    list_[i] = "{} {} {:03d}".format(i+1,s[i],int(p[i])).split()

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


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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
stdin = sys.stdin

ni = lambda: int(ns()) #int
na = lambda: list(map(int, stdin.readline().split())) #int,list
ns = lambda: stdin.readline().rstrip()  # str
n=ni()
a=[]
for i in range(n):
	s,p = list(map(str, stdin.readline().split()))
	a.append([s,p])

ans = sorted(a, key=lambda x: (x[0],-int(x[1])))
for i in range(n):
	print(a.index(ans[i])+1)

Submission status: Accepted

Solution code:
N = int(input())
raw_list = [list(input().split()) for _ in range(N)]
#print(raw_list)
copylist = raw_list[:]
a=sorted(copylist,key=lambda x:int(x[1]),reverse=True) # 点でソート
#print(a)
b=sorted(a, key=lambda x:x[0]) #　所在地でソート
#print(b)

for mise in b:
    #print(mise)
    print(raw_list.index(mise)+1)

Submission status: Accepted

Solution code:
n=int(input())
l=[list(map(str,input().split())) for i in range(n)]
for i in range(n):
    l[i][1]=int(l[i][1])
    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):
    l[i].append(i+1)

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

Submission status: Accepted

Solution code:
N = int(input())
data = [[i for i in input().split()] for j in range(N)]
for i in range(N):
    data[i].append(i+1)
for j in data:
    j[1] = int(j[1])
sort_data = sorted(data)
start = sort_data[0][0]
num = [sort_data[0][2]]
for i in range(1,N):
    if sort_data[i][0] == start:
        num.append(sort_data[i][2])
    else:
        start = sort_data[i][0]
        for j in range(len(num)):
            print(num[len(num)-1-j])
        num = [sort_data[i][2]]
for j in range(len(num)):
    print(num[len(num)-1-j])

Submission status: Accepted

Solution code:
# ABC128B - Guidebook
n = int(input())
lst = [input().rstrip().split() for _ in range(n)]
city = sorted(set([i[0] for i in lst]))
ans = [[] for i in range(len(city))]
for i, l in enumerate(lst, start=1):
    idx = city.index(l[0])
    ans[idx] += [[i, l]]
for i in ans:
    for j in sorted(i, key=lambda x: int(x[1][1]), reverse=True):
        print(j[0])

Submission status: Accepted

Solution code:
N = int(input())
list = []
for i in range(N):
	si,ten = input().split()
	list.append((si,int(ten)))
list_a = sorted(list, key=lambda x:(x[0],-x[1])) 
for i in range(N):
  print(list.index(list_a[i])+1)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

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

sp_sorted = sorted(sp)
city = sp_sorted[0][0]
group = [sp_sorted[0]]
first = 0
# print(sp_sorted)
for i in range(1,N):
    if city == sp_sorted[i][0]:
        group.append(sp_sorted[i])
    else:
        # print(group)
        group = sorted(group,key = lambda x:x[1],reverse=True)
        if len(group) == 1:
            pass
        else:
            sp_sorted[first:i] = group
        group = [sp_sorted[i]]
        city = sp_sorted[i][0]
        first = i
    if i == N-1 and len(group) != 1:
        group = sorted(group,key = lambda x:x[1],reverse=True)
        sp_sorted[first:] = group


# print(sp_sorted)


ans = [-1 for i in range(N)]
for i in range(N):
    ans[i] = sp.index(sp_sorted[i])

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

Submission status: Accepted

Solution code:
from operator import itemgetter
sp=[]
for i in range(int(input())):
	t=list(input().split())
	t[1]=100-int(t[1])
	t.append(i+1)
	sp.append(t)
sp=sorted(sp, key=itemgetter(0, 1))
print('\n'.join([str(i[2]) for i in sp]))

Submission status: Accepted

Solution code:
I = []
N = int(input())
for i in range(N):
    s, p = map(str,input().split())
    I.append([s, i+1, 100-int(p)])
    

sorted_I = sorted(I, key=lambda x:(x[0],x[2]))

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    SP=[list(map(str,input().split())) for i in range(N)]
    for k in range(len(SP)):
        SP[k].append(k)
    #print(SP)
    for i in range(len(SP)):
        SP[i][1] = int(SP[i][1])
    #print(N,SP)
    SP.sort(key=lambda x:(x[0],-x[1]))
    for j in range(len(SP)):
        print(SP[j][2]+1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
l = []
for i in range(int(raw_input ())):
   s, p = [x for x in raw_input ().split()]
   l.append((s, -1 * int(p), i + 1))
l.sort()
for i in l: print i[-1]

Submission status: Accepted

Solution code:
n=int(input())
sp=[[0 for i in range(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[0],-x[1]))
for i in range(n):
    print(sp[i][2])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
class GuideBook:
    def __init__(self):
        self.N = int(input())
        self.SP = []
        for i in range(self.N):
            s, p = input().split()
            self.SP.append([s, int(p), i])

    def main(self):
        tmp = sorted(self.SP, key=lambda x: x[1], reverse=True)
        result = sorted(tmp, key=lambda x: x[0])
        for x in result:
            print(x[2] + 1)


guideBook = GuideBook()
guideBook.main()

Submission status: Accepted

Solution code:
N=int(input())
s=[[]]
for i in range(N):
  a,b=map(str,input().split()) 
  b=int(b)
  s.append([i,a,b])
  
s.pop(0)

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

for row in sorted_items:
  print(row[0]+1)

Submission status: Accepted

Solution code:

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

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

	rest.append((a,int(b),int(i+1)))


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


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

Submission status: Accepted

Solution code:
n=int(input())

L=[]
for i in range(n):
    k,v=input().split()
    L.append({'num':i,'name':k,'score':int(v)})
L.sort(key=lambda x: (x['name'],-x['score']))
l_n = [d.get('num') for d in L]

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

Submission status: Accepted

Solution code:
n = int(input())
stores = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    stores.append({'id': i+1, 'city': s, 'point': p})
stores_sorted = sorted(stores, key=lambda x:x['point'], reverse=True)
stores_sorted = sorted(stores_sorted, key=lambda x:x['city'])
for store in stores_sorted:
    print(store['id'])

Submission status: Accepted

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

Submission status: Accepted

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

for i, _ in sorted(a, key=lambda x: (x[1][0], -int(x[1][1]))):
    print(i)

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())

dd = defaultdict(lambda: dict())

for i in range(N):
  k,v = input().split()
  dd[k][i] = (int(v))

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

for k,v in sorted_dct:
  a = sorted(v.items(), key=lambda x: -x[1])
  for k1 in a:
    print(int(k1[0]) + 1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
SP = tuple(input().split() for _ in range(N))

# input -> (str, int)
SP_list = []
for i in SP:
    i[1] = int(i[1])
    SP_list.append(i)

# add number to head of these lists
for i in range(len(SP)):
    SP_list[i].insert(0, i+1)

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

for i in reversed(SP_list):
    print(i[0])

Submission status: Accepted

Solution code:
n=int(input())



dsl={}
for i in range(n):
    sp=input().split()
    if sp[0] in dsl.keys():
        dsl[sp[0]].append([i,int(sp[1])])
    else:
        dsl[sp[0]]=[[i,int(sp[1])]]
l=sorted(dsl.items())
for i in range(len(l)):
    l[i][1].sort(key=lambda x:-x[1])
    for dd in l[i][1]:
        print(dd[0]+1)

Submission status: Accepted

Solution code:
def introduce_rest(no_city_points):
    for no, _, _ in sorted(no_city_points, key=lambda x: (x[1], -x[2])):
        print(no)


def main():
    n = int(input())
    input_ = []
    for i in range(1, n+1):
        city, p = input().split()
        input_.append((i, city, int(p)))
    introduce_rest(input_)
    
main()

Submission status: Accepted

Solution code:
N = int(input())
DF = []
for i in range(N):
    S1, SP = input().split()
    DF = DF + [[i+1, S1, int(SP)]]
DF1 = sorted(DF, key=lambda x:x[2], reverse=True)
DF2 = sorted(DF1, key=lambda x:x[1], reverse=False)
for i in range(N):
    print(DF2[i][0])

Submission status: Accepted

Solution code:
N = int(raw_input())
sp_list = []
for i in range(N):
    sp_list.append(map(str, raw_input().split()))
    sp_list[i][1] = int(sp_list[i][1])
    sp_list[i].append(i+1)

sp_list.sort()

check_set = set()
for i in range(N):
    check_set.add(sp_list[i][0])

for i in check_set:
    idx_list = []
    num_list = []
    for j in range(N):
        if sp_list[j][0] == i:
            idx_list.append(j)
            num_list.append([sp_list[j][1],sp_list[j][2]])
    idx_list.sort()
    num_list.sort()
    num_list.reverse()
    for k in range(len(idx_list)):
        sp_list[idx_list[k]][1] = num_list[k][0]
        sp_list[idx_list[k]][2] = num_list[k][1]


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

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
arr_ = [[str(i) for i in input().split()] for _ in range(n)]
for i in range(n):
    arr_[i].append(i+1)
    arr_[i][1] = int(arr_[i][1])

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

Submission status: Accepted

Solution code:
from operator import itemgetter
N=int(input())
R=[]
for i in range(N):
    s,p=input().split()
    p=int(p)
    R.append([s,p])

sorted_R=sorted(R,key = itemgetter(1),reverse=True)
sorted_R=sorted(sorted_R, key = itemgetter(0))

for i in range(len(R)):
    for j in range(len(R)):
        if R[j]==sorted_R[i]:
            print(j+1)

Submission status: Accepted

Solution code:

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

from operator import itemgetter
sorted_items = sorted(items, key=itemgetter(1), reverse=True)
sorted_items = sorted(sorted_items, key=itemgetter(0), reverse=False)

for key, value, ind in sorted_items:
  print(ind)

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())

wrap = []

for i in range(n):
    input_data = input()
    wrap.append([i+1, input_data.split()[0], int(input_data.split()[1])])

wrap.sort(key=itemgetter(2), reverse=True)
wrap.sort(key=itemgetter(1))

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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())

Submission status: Accepted

Solution code:
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]))]
# res = sorted(enumerate(M), key = lambda x : (x[1][0], -x[1][1]))
for item in res:
  print (item)

Submission status: Accepted

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

Submission status: Accepted

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