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())
SP = []
for i in range(N):
    s, p = input().split()
    p = int(p)
    SP.append(list([s, p, i+1]))
SP.sort(key=lambda x: (x[0], -x[1]))
for i in SP:
    print(i[2])

Submission status: Accepted

Solution code:
N=int(input())
a=[]
for i in range(N):
    s,p=input().split()
    p=int(p)
    #sortするために数値を逆にする
    a.append((s,-p,i+1))
a.sort()
for i in range(N):
    print(a[i][2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(list(input().split()))
b = a
for i in range(n):
    b[i][1] = -int(b[i][1])
b = sorted(b)
for i in range(n):
    b[i][1] = -b[i][1]
    print(a.index(b[i])+1)

Submission status: Accepted

Solution code:
n = int(input())
city = []
nums = []
result = []

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

for i in sorted(set(city)):
  for j in sorted(set(nums), reverse = True):
    for k in result:
      if k[0] == i and k[1] == j:
        print(k[2])

Submission status: Accepted

Solution code:
N = int(input())
line = []
for i in range(N):
    tmp = [j for j in input().split()]
    tmp[1] = -1 * int(tmp[1])
    tmp.append(i + 1)
    line.append(tmp)
line.sort()
for i in range(N):
    print(line[i][2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N = INT()
ans = {}

for i in range(N):
    S, P = input().split()
    P = int(P)
    
    if S in ans.keys():
        ans[S].append([P, i + 1])
        ans[S].sort(key = lambda x : x[0], reverse = True)
    else:
        ans[S] = [[P, i + 1]]
    
store = list(ans.keys())
store.sort()

for s in store:
    for p in ans[s]:
        print(p[1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 128 B

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

for i in range(n):
    tp = list(input().split())
    s.append(tp)

for i in range(n):
    s[i][1] = int(s[i][1]) * (-1)
    s[i].append(i+1)
s.sort()

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

Submission status: Accepted

Solution code:
N = int(input())
S = []
P = []

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

name = list(sorted(set(S)))

for i in range(len(name)):
    score = []
    number = []
    for j in range(N):
        if S[j] == name[i]:
            score.append(P[j])
            number.append(j+1)
    for k in range(S.count(name[i])):
        place = score.index(max(score))
        print(number[place])
        del number[place]
        del score[place]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(list)

for s, p, i in SP:
    d[s].append((int(p), i))

ans = []

for k, v in d.items():
    v = sorted(v)[::-1]
    for i, j in v:
        ans.append(str(j))

print('\n'.join(ans))

Submission status: Accepted

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

SPN = [[s, int(p), i + 1] for i, (s, p) in enumerate(SP)]
SPN.sort(key=lambda x: (x[0], -x[1]))

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

Submission status: Accepted

Solution code:
N = int(input())
lis = [(input() + " " + str(i+1)).split() for i in range(N)]

lis = [k for k in lis]

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = [0]*n
for i in range(n):
    a, b = map(str, input().split())
    b = int(b)
    ans[i] = [i+1, a, b]
ans.sort(key=lambda x: (x[1], -x[2]))
for j in ans:
    print(j[0])

Submission status: Accepted

Solution code:
d = []
for i in range(int(input())):
    s, p = input().split()
    d += (i + 1, s, int(p)),
d.sort(key = lambda l: (l[1], -l[2]))
for i, _, __ in d:print(i)

Submission status: Accepted

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

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

sorted_restaurants = restaurants.copy()
sorted_restaurants = sorted(sorted_restaurants, key=lambda x: (x[0], -x[1]))

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

Submission status: Accepted

Solution code:
num = int(input())
arr = []
for i in range(0, num):
  enter = input().split()
  arr.append(tuple((enter[0], int(enter[1]), i+1)))
             
sorted_by_score = sorted(arr, key = lambda x: x[1], reverse=True)
sorted_by_name = sorted(sorted_by_score, key = lambda x: x[0])
for i in sorted_by_name:
  print(i[2])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

n = int(input())

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

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

ans = [i[2] for i in sp]

print(*ans)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(input())
L =[stdin.readline().split() for _ in range(N)]
for n in range(N):
  L[n][1] = int(L[n][1])
for n in range(N):
  L[n].append(n)
L = sorted(L, reverse=True, key=lambda x: x[1])
L = sorted(L, reverse=False, key=lambda x: x[0]) #L.sort()だと他の列もsortされてしまう
for n in range(N):
  print(L[n][2]+1)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(input())
L =[stdin.readline().split() for _ in range(N)]
for n in range(N):
  L[n][1] = int(L[n][1])
for n in range(N):
  L[n].append(n)
L = sorted(L, reverse=True, key=lambda x: x[1])
L = sorted(L, reverse=False, key=lambda x: x[0])
for n in range(N):
  print(L[n][2]+1)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(input())
L =[stdin.readline().split() for _ in range(N)]
for n in range(N):
  L[n][1] = int(L[n][1])
for n in range(N):
  L[n][1] = -L[n][1]
for n in range(N):
  L[n].append(n)
L1 = sorted(L, reverse=False, key=lambda x: x[1])
L2 = sorted(L1, reverse=False, key=lambda x: x[0])
for n in range(N):
  print(L2[n][2]+1)

Submission status: Accepted

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

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

guide = sorted(raw, key=lambda x:x[1],reverse=True)
guide = sorted(guide, key=lambda x:x[2])
# print(guide)


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

Submission status: Accepted

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

# In[14]:


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


# In[16]:


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


# In[ ]:

Submission status: Accepted

Solution code:
n = int(input())
d = {}

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

d = sorted(d.items(), key=lambda x:x[1][1], reverse=True)
d = sorted(d, key=lambda x:x[1][0])

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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


for r in rs:
    print(r[2] + 1)

Submission status: Accepted

Solution code:
list1 = []
N = int(input())
# Looping in the range (N+1)-1
for i in range((N-1)+1):
  X=input()
  S, P = map(str, X.split())
  list1.append((i+1, S, int(P)))
# lamda sorting
list2 = sorted(list1, key=lambda x:(x[1], -x[2])) 
for all in list2:
  print(all[0])

Submission status: Accepted

Solution code:
n = input()
li = []
m = {}
x = set([])
for i in range(int(n)):
      s,p = [z for z in input().split()]
      x.add(s)
      m[str([s,int(p)])] = i
      li.append([s,int(p)])
new = sorted(li, reverse=True)
for i in sorted(list(x)):
      for j in range(int(n)):
            if (new[j][0]==i):
                  print(m[str(new[j])]+1)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())

l = []
for i in range(n):
    s, p = readline().decode().rstrip().split()
    p = int(p)
    tmp = [i+1,s,p]
    l.append(tmp)

l.sort(key=lambda x: x[2], reverse=True)
l.sort(key=lambda x: x[1])
for v in l:
    print(v[0])

Submission status: Accepted

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

for l in lst:
  print(l[0])

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    ls = []
    for i in range(N):
        tmp = input().split()
        tmp.append(i+1)
        ls.append(tmp)

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

    for l in ls:
        print(l[2])
    return

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    a = []
    for i in range(n):
        key, value = input().split()
        value = -int(value)
        a.append([key, value, i + 1])
    a.sort()
    for i in a:
        print(i[2])
 
 
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    A = [0] * N
    for i in range(N):
        s, p = readline().strip().split()
        p = int(p)
        A[i] = (s, p, i + 1)

    A.sort(key=itemgetter(1), reverse=True)
    A.sort(key=itemgetter(0))
    for s, p, i in A:
        print(i)

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    d = defaultdict(list)
    for i in range(N):
        s, p = readline().strip().split()
        p = int(p)
        d[s].append((p, i+1))

    for city, points in sorted(d.items()):
        points = sorted(points, reverse=True)
        for _, i in points:
            print(i)

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    a = []
    for i in range(n):
        key, value = input().split()
        value = -int(value)
        a.append([key, value, i + 1])
    a.sort()
    for i in a:
        print(i[2])


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

brr=sorted(arr,key=lambda x:(x[0][0],-int(x[0][1])))

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

Submission status: Accepted

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
city_point =[]
for i in range(N):
    c,p =input().split()
    city_point.append((c,int(p),i))

#sort
city_point.sort(key=lambda x: (x[0],-x[1]))
for i in city_point:
    print(i[2]+1)

Submission status: Accepted

Solution code:
N = int(input())
L = []
for i in range(N):
    N, K = input().split()
    K = int(K)
    L.append([N, -K, i+1])
L.sort()
for i in L:
    print(i[2])

Submission status: Accepted

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

for s,p,i in l:
  print(i)

Submission status: Accepted

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

for i in range(n):
  t = []
  a, b = input().split()
  t.append(a)
  t.append(b)
  t.append(str(i + 1))
  list_shop.append(t)

check = 0
c = []

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

for i in range(len(list_shop) - 1):
  if(list_shop[i][0] == list_shop[i + 1][0]):
    check = 1
  else:
    check = 0

  c.append(list(map(int, list_shop[i][1:3])))
  if(check == 1):
    continue
  else:
    c.sort(key=lambda x:x[0], reverse=True)
    for j in c:
      print(int(j[1]))
    c = []

if(check == 1):
  c.append(list(map(int, list_shop[n - 1][1:3])))
  c.sort(key=lambda x:x[0], reverse=True)
  for i in c:
    print(i[1])
else:
  print(int(list_shop[n - 1][2]))

Submission status: Accepted

Solution code:
n=int(input())
dicsp={}
listp=[]
for i in range(n):
  s,p=map(str,input().split())
  listp.append([s,p])
  dicsp.setdefault(s,[]).append(p)
  
#print(dicsp)
s=sorted(list(dicsp.keys()))
listsp=[]
for i in s:
  t=list(map(int,dicsp[i]))
  t.sort(reverse=True)
  for j in t:
    listsp.append([i,j])

for i,j in listsp:
  print(listp.index([i,str(j)])+1)

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
inf = {}
for i in range(1,N+1):
  s,p = input().split()
  pint = int(p)
  inf[(s,pint)] = i
a = sorted(inf.keys(), key=itemgetter(1), reverse=True)
dic2 = sorted(a, key=itemgetter(0))
for i in range(N):
  print(inf[dic2[i]])

Submission status: Accepted

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

for s,p,i in l:
  print(i)

Submission status: Accepted

Solution code:
class MaxHeapInt(object):
    def __init__(self, val, idx):
        self.val = val
        self.idx = idx

    def __lt__(self, other): return self.val > other.val
    def __eq__(self, other): return self.val == other.val
    def __str__(self): return str(self.val)


def resolve():
    import heapq
    from collections import defaultdict
    N = int(input())
    SS = []
    SP = defaultdict(list)
    for i in range(N):
        S, Pt = input().split()
        P = int(Pt)
        heapq.heappush(SS, S)
        heapq.heappush(SP[S], MaxHeapInt(P, i + 1))
    while len(SS) > 0:
        S = heapq.heappop(SS)
        while len(SP[S]) > 0:
            print(heapq.heappop(SP[S]).idx)


resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

n = int(input())
spL = [input().split(" ") + [i + 1] for i in range(n)]

for restaurant in sorted(spL, key=lambda x: (x[0], 1000000 - int(x[1]))):
    print(restaurant[2])

Submission status: Accepted

Solution code:
n = int(input())
l = []
for i in range(1, n+1):
    name, score = input().split()
    l.append({'id': i, 'name': name, 'score': int(score)*(-1)})

l = sorted(l, key = lambda x: (x['name'], x['score']))
for i in l:
    print(i['id'])

Submission status: Accepted

Solution code:
n = int(input())
SP = [input().split() for i in range(n)]
for i in range(n):
  SP[i][1] = 100 - int(SP[i][1])
A = sorted(SP)
ans = [0]*n

for i in range(n):
  for j in range(n):
    if A[i] == SP[j]:
      print(j+1)
    else:
      pass

Submission status: Accepted

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

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

    for d in data:
        print(d[2])



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
sp=[]
for i in range(n):
    s,p=input().split()
    sp.append([s,int(p),i+1])
sp.sort(key=lambda x: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:
# coding cell (SUBMIT ONLY THIS CELL)

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

for i in range(N):
    temp = input().split()
    scores.append([temp[0], -1 * int(temp[1]), i + 1])

scores.sort()

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

Submission status: Accepted

Solution code:
n = int(input())
data = []
name = set()
for i in range(n):
    s, p = input().split()
    name.add(s)
    p = int(p)
    data.append([i+1, s, p])
result = sorted(data, key=lambda x: x[2], reverse=True)
name_sorted = sorted(list(name))
for x in name_sorted:
    for y in result:
        if y[1] == x:
            print(y[0])

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    a={}
    for i in range(n):
        s,p = input().split()
        if s not in a:
            a[s] = []
        a[s].append((int(p), i))
    for e in sorted(a.keys()):
        for i in sorted(a[e], key=lambda x: x[0], reverse=True):
            print(i[1]+1)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

for _,_,i in sp:
    print(i + 1)

Submission status: Accepted

Solution code:
n = int(input())

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

l.sort(key=lambda i: i[1], reverse=True)

for i in sorted(set(city)):
  for j in l:
    if j[0] == i:
      print(j[2])

Submission status: Accepted

Solution code:
# Problem B - Guidebook

# input
N = int(input())
restaurant = {}
for i in range(N):
    s, p = input().split()
    p = int(p)
    if s in restaurant:
        restaurant[s].append((i+1, p))
    else:
        restaurant[s] = [(i+1, p)]

# dict sort
restaurant = sorted(restaurant.items(), key= lambda x:x[0])

# price sort
for r in restaurant:
    tmp = r[1]
    result = sorted(tmp, key= lambda x:x[1], reverse=True)
    for i in result:
        print(i[0])

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
sp = [None]*n
for i in range(n):
    sp[i] = [None]*3
# print(sp)
for i in range(n):
    sp[i] = input().split()
for i in range(n):
    sp[i][1] = int(sp[i][1])
for i in range(n):
    sp[i].append((i+1))
# print(sp)

sp2 = sorted(sp, key=lambda x: x[1], reverse=True)
# print(sp2)
sp3 = sorted(sp2, key=lambda x: x[0])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [[i]+input().split() for i in range(N)]
A = [[A[i][0],A[i][1],int(A[i][2])] for i in range(N)]
A = sorted(A,key=lambda x:x[2],reverse=True)
A = sorted(A,key=lambda x:x[1])
for i in range(N):
    j,_,_ = A[i]
    print(j+1)

Submission status: Accepted

Solution code:
n=int(input())
sp=[input().split()+[i]for i in range(n)]
sp.sort()
for i in range(n):
  sp[i][1]=int(sp[i][1])
ans=[[sp[0][0],sp[0][1:]]]
for s,p,i in sp[1:]:
  if ans[-1][0]==s:ans[-1].append([p,i])
  else:ans.append([s,[p,i]])
for i in range(len(ans)):
  ans[i]=ans[i][1:]
  ans[i].sort(reverse=1)
for i in ans:
  for _,j in i:print(j+1)

Submission status: Accepted

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

X.sort(key= lambda x: (x[0], -x[1]))
for s, p, i in X:
    print(i)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

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

for i in range(N):
    sp = input().split()
    l.append((i, sp[0], int(sp[1])))

l.sort(key=lambda t: (t[1], -t[2]))

for i, _, _ in l:
    print(i+1)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
List = [list(input().split()) for i in range(N)]
ANS=List
for j in range(N):
    List[j][1]=int(List[j][1])
RList=sorted(List,reverse=True, key=lambda x: x[1])
RList.sort(key=lambda x: x[0])
for i in range(N):
    print((ANS.index(RList[i]))+1)

Submission status: Accepted

Solution code:
n=int(input())
book=[]
for i in range(n):
    city,point=input().split()
    point=int(point)
    book.append([city,-point,i+1])
book.sort()
for i in range(n):
    print(book[i][2])

Submission status: Accepted

Solution code:
n=int(input())

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

s=sorted(lst,key=lambda x: (x[1], -(x[2])))
for i in s:
    print(i[0])

Submission status: Accepted

Solution code:
N = int(input())

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

S.sort(key=lambda x: (x[1], -(x[2])))

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

Submission status: Accepted

Solution code:
import sys 

N = int(sys.stdin.readline().strip())
shops = []
for i in range(N):
    s, p = sys.stdin.readline().strip().split()
    shops.append((s, -1 * int(p), i+1))

for (s, p, i) in sorted(shops):
    print(i)

Submission status: Accepted

Solution code:
_N, *_SP = open(0).read().split()
N = int(_N)

SP = {}

for i in range(N):
    SP[i+1] = [_SP[2*i], int(_SP[2*i+1])]

sorted_by_P = sorted(SP.items(), key = lambda x: x[1][1], reverse=True)
sorted_by_S = sorted(sorted_by_P, key = lambda x: x[1][0])

print(*[x[0] for x in sorted_by_S], sep="\n")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def actual(n, S, P):
    restaurant_dict_list = []

    for idx, (s, p) in enumerate(zip(S, P), start=1):
        d = dict(id=idx, name=s, point=p)
        restaurant_dict_list.append(d)

    ids = []

    for key in sorted(set(S)):
        # 市名昇順でループ → 市名ごとに抽出 → ポイント降順でソート
        s = [d for d in restaurant_dict_list if d['name'] == key]
        t = sorted(s, key=lambda x: x['point'], reverse=True)

        for u in t:
            ids.append(str(u['id']))

    return '\n'.join(ids)

n = int(input())

S, P = [], []
for _ in range(n):
  s, p = input().split()
  S.append(s)
  P.append(int(p))
  
print(actual(n, S, P))

Submission status: Accepted

Solution code:
n=int(input())
rest=[]
for i in range(n):
  x,y=list(input().split())
  y=100-int(y)
  rest.append([x,y])
sor=sorted(rest)

for i in sor:
  print(rest.index(i)+1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    d = dict()
    for i in range(N):
        k, v = input().split()
        v = int(v)
        if k in d:
            d[k].append((i + 1, v))
        else:
            d[k] = []
            d[k].append((i + 1, v))

    sd = sorted(d.items(), key=lambda x: x[0])
    for i in range(len(sd)):
        sd[i][1].sort(key=lambda x: x[1], reverse=True)

    # print(sd)
    for sdl in sd:
        for r in sdl[1]:
            print(r[0])


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit
from collections import defaultdict


def main():
    input = stdin.readline
    n = int(input())
    dic = defaultdict(list)
    for i in range(1, n + 1):
        s, p = map(str, input().split())
        dic[s].append([int(p), i])
        dic[s].sort(reverse=True)
    s_dic = sorted(dic.items(), key=lambda x: x[0])

    for k, arr in s_dic:
        for ai in arr:
            print(ai[1])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

Solution code:
## B - Guidebook
N = int(input())
val = []
for n in range(N):
    S, P = map(str, input().split())
    val.append([n+1, S, int(P)])
val = sorted(val, key=lambda x:(x[1],-x[2]))
for n in range(N):
    print(val[n][0])

Submission status: Accepted

Solution code:
r = [[i+1] + raw_input().split(' ') for i in range(int(raw_input()))]
r.sort(key = lambda x: (x[1], -int(x[2])))
for u in r: print u[0]

Submission status: Accepted

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

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


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

Submission status: Accepted

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

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.sort(key=lambda x:(x[0], -x[1]))
for j in range(N):
    print(List[j][2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
L = [list(input().split()) for i in range(N)]
for i in range(len(L)):
  L[i][1] = 100-int(L[i][1])
K = sorted(L)

ans = []
for i in range(len(K)):
  for j in range(len(L)):
    if K[i] == L[j]:
      ans.append(j+1)
for i in range(len(ans)):
  print(ans[i])

Submission status: Accepted

Solution code:
from operator import itemgetter

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

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

book = sorted(book, key=itemgetter(1), reverse=True)
book = sorted(book, key=itemgetter(0))
#print(book)

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ll = list()
    for i in range(n):
        tmp = list(map(str, input().split()))
        tmp[1] = int(tmp[1])
        tmp.append(i+1)
        ll.append(tmp)
    ll_s = sorted(ll, key=lambda x:(x[0],-x[1]))
    for i in ll_s:
        print(i[2])

if __name__ == '__main__':
    main()