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

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    RDictionary={}
    index=1
    for i in range(N):
        SP=input().split()
        S=SP[0]
        P=int(SP[1])
        if (S in RDictionary.keys()):
            RDictionary[S].append((P,index))
        else:
            RDictionary[S]=[(P,index)]
        index+=1

    Names=list(RDictionary.keys())
    Restaurants=list(RDictionary.values())

    Rest_Town=zip(Names,Restaurants)

    Rest_Town=sorted(Rest_Town)

    Names,Restaurants=zip(*Rest_Town)
    Restaurants=list(Restaurants)

    #Restraurants => [[(),(),()],[(),()],...]

    for i in range(len(Restaurants)):
        Restaurants[i]=sorted(Restaurants[i],reverse=True)

    for town in Restaurants:
        for rest in town:
            print(rest[1])


if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
sps=dict()
for i in range(n):
    s,p=input().split()
    if not s in sps:
        sps[s]=[]
    sps[s].append([int(p),i+1])
for k in sorted(list(sps.keys())):
    for _,v in sorted(sps[k], reverse=True):
        print(v)

Submission status: Accepted

Solution code:
n = int(input())
d = []
for i in range(n):
    a,b = map(str,input().split())
    b = -int(b)
    d.append([a,b,i])
d.sort()
for i in range(n):
  print(d[i][2]+1)

Submission status: Accepted

Solution code:
n = int(input())
d = []
for i in range(1,n+1):
    city, score = input().split()
    d.append({'id':i, 'restaurant':{'city':city, 'score':int(score)}})

sorted_d = sorted(
    d,
    key = lambda x: (x['restaurant']['city'], -x['restaurant']['score'])
)

for l in sorted_d:
    print (l['id'])

Submission status: Accepted

Solution code:
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))

n=int(input())

a=[]
for j in range(n):
    v,i=input().split()
    i=int(i)
    a.append([v,i,j])
a.sort(key=lambda x:(x[0],-x[1]))
for each in a:
    print(each[2]+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

rests.sort(key=lambda x: x[0]+chr(100-x[1]))
for rest in rests:
    print(rest[2])

Submission status: Accepted

Solution code:
N = int(input())
rests = {}
cities = []
lst = []

for i in range(N):
    S, P = input().split()
    cities.append(S)
    lst.append((S, int(P)))
    try:
        rests[S].append(int(P))
        rests[S].sort()
    except KeyError:
        rests[S] = [int(P)]

cities.sort()
order = [(city, rests[city].pop()) for city in cities]

for rest in order:
    print(lst.index(rest) + 1)

Submission status: Accepted

Solution code:
N=int(input())
SP=[list(map(str, input().split())) for _ in range(N)]
for i in range(N):
    SP[i].append(i+1)
    SP[i][1]=int(SP[i][1])*-1#2列目を降順ソートさせるため、正負をひっくり返す
#print(SP)
SP.sort()#1列目が同じ場合、2列目を基準にソートされる
#print(SP)
for i in range(N):
    print(SP[i][2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
SP = [None] * N
for i in range(N):
    SP[i] = input().split()
    SP[i][1] = int(SP[i][1]) * -1

for i in range(N):
    SP[i].append(i + 1)

S = sorted(SP)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(len(sp)):
    print(sp[i][2])

Submission status: Accepted

Solution code:
n=int(input())
a=[[""]*3 for ii in range(n)]
for ii in range(n):
  s=input().split()
  #print(s)
  a[ii][0]=s[0]
  a[ii][1]=100-int(s[1])
  a[ii][2]=ii
a.sort()
for ii in range(n):
  print(a[ii][2]+1)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
import copy

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

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

Submission status: Accepted

Solution code:
n = int(input())
s =[]
p = []
for _ in range(n):
    si, pi = input().split()
    s.append(si)
    p.append(int(pi))
s_ord = sorted(list(set(s)))
for c in s_ord:
    ind = [i for i, x in enumerate(s) if x == c]
    p_ord = sorted([point for num, point in enumerate(p) if num in ind], reverse = True)
    for r in p_ord:
        print(p.index(r) + 1)

Submission status: Accepted

Solution code:

n=int(input())

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

for i in range(len(sp)):
    print(sp[i][2])

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = []
B = []
E = []
for i in range(N):
  l = list(input().split())
  l[1] = int(l[1])
  A.append(l)
  B.append(l[0])
  E.append(l[1])
A.sort()
C = Counter(B)
C = sorted(C.items(), key=lambda x:x[0])
cnt = 0
for c in C:
  c = c[1]
  D = reversed(A[cnt:cnt+c])
  cnt += c
  for d in D:
    print(E.index(d[1])+1)

Submission status: Accepted

Solution code:
N = int(input())


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

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

for out in ss_sorted:
    print(out[2] + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#Guide Book https://atcoder.jp/contests/abc128/tasks/abc128_b
N = int(input())
Shop_List=[]
for i in range(N):
    Temp_List=list(input().split())
    Temp_List[1]=int(Temp_List[1])
    Temp_List.append(i+1)
    Shop_List.append(Temp_List)


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

Submission status: Accepted

Solution code:
N = int(input())

ss = dict()
sss = dict()
for i in range(N):
    s, p = input().split()
    sss[s, p] = i + 1
    if s in ss:
        ss[s] = ss[s] + ',' + p
    else:
        ss[s] = p

ss_sorted = sorted(ss.items())

for tmp_ss in ss_sorted:
    s = tmp_ss[0]
    ps = list(map(int, tmp_ss[1].split(',')))
    ps.sort(reverse=True)
    for p in ps:
        print(sss[s, str(p)])

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

N = int(readline())
rest = [None] * N
for i in range(N):
  s,p = readline().split()
  rest[i] = [s,int(p),i + 1]
  
rest = sorted(rest, key = lambda x:(x[0],-x[1]))
for r in rest:
  print(r[2])

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def bit_count(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

N = inputI()
data = inputSLL(N)

dic = {}
for i in range(N):
  c,p = data[i]
  if c not in dic:
    dic[c] = [(int(p),i)]
  else:
    dic[c].append((int(p),i))
    
key = [k for k in dic]
key.sort()
for k in key:
  dic[k].sort(reverse=True)
  for p,i in dic[k]:
    print(i+1)

Submission status: Accepted

Solution code:
N = int(input())
lst = []
for i in range(N):
    m, p = map(str, input().split())
    lst.append((i+1, m, 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())
sp = [list(map(str,input().split())) for _ in range(N)]

for i in range(N):
    sp[i].append(i+1)

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

city = []
for k in range(N):
    if sp[k][0] not in city:
        city.append(sp[k][0])

A = []
for i in range(len(city)):
    cnt = 0
    end = 0
    for j in range(i,N):
        if sp[j][0] == city[i]:
            cnt += 1
            end = j
    A.append((cnt,end+1-cnt))

B = [0] * len(A)
for i in range(len(A)):
    begin = A[i][1]
    end = A[i][0]+A[i][1]
    B[i] = sp[begin:end]

for k in B:
    k.sort(key=lambda x:int(x[1]))
    for i in range(len(k)):
        print(k[len(k)-i-1][2])

Submission status: Accepted

Solution code:
n = int(input())

l = []
for i in range(n):
  x,y = map(str,input().split())
  l.append([x,int(y),i+1])

l.sort(key = lambda l:(l[0],-l[1]))
for j in range(n):
  print(l[j][2])

Submission status: Accepted

Solution code:
n = int(input())
L = [input().split() for _ in range(n)]
d = {}
for s, p in L:
    if s not in d.keys():
        d[s] = [int(p)]
    else:
        d[s].append(int(p))
for i, v in enumerate(L, start=1):
    v.append(i)
for i in sorted(d):
    for j in sorted(d[i], reverse=True):
        for k in range(n):
            if L[k][1] == str(d[i][d[i].index(j)]):
                print(L[k][2])

Submission status: Accepted

Solution code:
N = int(input())
SP = [input().split() for _ in range(N)]
for k in range(N):
  City = "zzzzzzzzzzzzzz"
  Point = 0
  Num = 0
  for i in range(len(SP)):
    if SP[i][0] < City:
      City = SP[i][0]
  for j in range(len(SP)):
    if SP[j][0] == City and int(SP[j][1]) >= Point:
      Point = int(SP[j][1])
      Num = j
  print(Num+1)
  SP[Num][0] = "zzzzzzzzzzzzzzzzz"
  SP[Num][1] = 0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    book = [input().split() for i in range(N)]
    for i, j in enumerate(book):
        j[1] = int(j[1])
        j.append(i + 1)

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for list in sp:
    list[1]= -int(list[1])
sp.sort()

for s, p, num in sp:
    print(num)

Submission status: Accepted

Solution code:
n = int(input())

t = []
for i in range(1,n+1):
  s,p = tuple(input().split())
  p = int(p)
  t.append((s,p,i))
t = sorted(t,key = lambda a:a[1],reverse=True)
t = sorted(t,key = lambda a:a[0])

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

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())

splist = [[0, 0, 0]]*N

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

s1splist = sorted(splist, key=itemgetter(1), reverse=True)
s2splist = sorted(s1splist, key=itemgetter(0))

for s in s2splist:
    print(s[2])

Submission status: Accepted

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

for i in range(N):
    restrante[i].append(i+1)
    restrante[i][1] = int(restrante[i][1])

sorted_res= sorted(restrante, key = lambda x:(x[1]), reverse=True)
sorted_ans = sorted(sorted_res, key = lambda x:(x[0]))

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

Submission status: Accepted

Solution code:
n = int(input())

score = {}

for i in range(n):
    s, p = input().split()

    if s not in score:
        score[s] = []

    t = [i+1,int(p)]
    score[s].append(t)

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

    for i in range(len(score[key])):
        print(score[key][i][0])

Submission status: Accepted

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

l = sorted(l, reverse=True, key=lambda x:x[1])
#name -> dneed reverse
l = sorted(l, key=lambda x:x[0])

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

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    N=int(input())
    A=[]
    for i in range(N):
        S,P=pin(str)
        P=int(P)
        A.append((S,P,i+1))
    A.sort(key=lambda x:x[1],reverse=True)
    A.sort(key=lambda x:x[0])
    for a in A:
        print(a[2])

#%%submit!
resolve()

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

for i in range(N):
    for j in range(N-1):
        if L[j][0] > L[j+1][0] or (L[j][0] == L[j+1][0] and L[j][1] < L[j+1][1]):
            L[j],L[j+1] = L[j+1],L[j]

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

Submission status: Accepted

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

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

for k in range(N):
  print(L[k][2]+1)

Submission status: Accepted

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

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

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

for n in restaurant:
    print(n[2]+1)

Submission status: Accepted

Solution code:
#B
n = int(input())

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

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])
sort1=lambda val: val[1]
list.sort(reverse=True,key=sort1)
sort2=lambda val: val[0]
list.sort(key=sort2)
for i in range(n):
    print(list[i][2])

Submission status: Accepted

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

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

P = [int(p) for p in P]
I = [j+1 for j in range(N)]
x = [(s, p, i) for s, p, i in zip(S, P, I)]

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
s = []
p = []
b = []
cnt = 1
while True:
  try:
    ts,tp = map(str,input().split())
    s.append(ts)
    p.append(int(tp))
    b.append((ts,int(tp),cnt))
    cnt +=1
  except:
    break

data = sorted(b, key=itemgetter(1), reverse=True)
data = sorted(data, key=itemgetter(0), reverse=False)

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

Submission status: Accepted

Solution code:
n = int(input())

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

for key in sorted(list(d.keys())):
  for i in sorted(d[key], key = lambda x: x[1], reverse=True):
    print(i[0])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    DIC = [[]]*N
    for i in range(N):
        name, score = input().split()
        DIC[i] = [name, int(score)*-1, i]
    sDIC = sorted(DIC)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
A = []
for i in range(n):
    s, p = input().split()
    p_ = (-1)*int(p)
    A.append((s, p_, i+1))
A.sort(key=itemgetter(0,1))
# print(A)
for a in A:
    print(a[2])

Submission status: Accepted

Solution code:
n = int(input())
cities = set()
scores = {}
scorelist = {}
sp = [[""]]*n
for i in range(n):
  sp[i] = input().split()
  s = sp[i][0]
  p = int(sp[i][1])
  if s in cities:
    scores[s][p] = i
    scorelist[s].append(p)
  else:
    scores[s] = {p:i}
    scorelist[s] = [p]
    cities.add(s)
citylist = list(cities)
citylist.sort()
for x in citylist:
  scorelist[x].sort(reverse = True)
  for i in range(len(scorelist[x])):
    print(scores[x][scorelist[x][i]]+1)

Submission status: Accepted

Solution code:
N=int(input())
lest=[]
for i in range(0,N):
    S,P=list(map(str,input().split()))
    lest.append([S,int(P),i+1])
lest.sort()
for n in range(0,100):
    for i in range(0,N-1):
        if lest[i][0]==lest[i+1][0] and lest[i][1]<lest[i+1][1]:
            a=lest[i][1]
            lest[i][1]=lest[i+1][1]
            lest[i+1][1]=a
            b = lest[i][2]
            lest[i][2] = lest[i + 1][2]
            lest[i + 1][2] = b
for i in range(0,N):
    print(lest[i][2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

data = sorted(data, key=itemgetter(1), reverse=True)
data = sorted(data, key=itemgetter(0), reverse=False)

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

Submission status: Accepted

Solution code:
def guidebook(n, spli):

    ans = []
    for i in range(n):
        temp = [i+1, spli[i][0], (-1)*int(spli[i][1])]
        ans.append(temp)
    ans.sort(key=lambda x: (x[1], x[2]))
    return ans
def main():
    n = int(input())
    spli = [list(map(str, input().split()))for i in range(n)]
    ans = guidebook(n, spli)
    for i in ans:
        print(i[0])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [0] * n
for i in range(n):
    s, p = input().split()
    a[i] = [s, -int(p)]
b = sorted(a)
for i in range(len(a)):
    print(a.index(b[i])+1)

Submission status: Accepted

Solution code:
N = int(input())
L = []
for _ in range(N):
    s, p = input().split()
    p = int(p)
    L.append((s, 100 - p, _))

L.sort()
for _ in range(N):
    print(L[_][2]+1)

Submission status: Accepted

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

for i in range(n):
    j = i
    while j > 0:
        if T[j][0] < T[j - 1][0]:
            T[j], T[j - 1] = T[j - 1], T[j]
            ans[j], ans[j - 1] = ans[j - 1], ans[j]
            j = j - 1
        else:
            break

for i in range(n):
    j = i
    while j > 0:
        if int(T[j][1]) > int(T[j - 1][1]) and T[j][0] == T[j - 1][0]:
            T[j], T[j - 1] = T[j - 1], T[j]
            ans[j], ans[j - 1] = ans[j - 1], ans[j]
            j = j - 1
        else:
            break


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - Guidebook

from operator import itemgetter

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

SP = sorted(SP, key=itemgetter(2), reverse=True)
SP = sorted(SP, key=itemgetter(1))
for sp in SP:
    print(sp[0])

Submission status: Accepted

Solution code:
N = int(input())
rest_dict = {}
city_list = []
for i in range(N):
    city, score = input().split()
    if city not in city_list:
        city_list.append(city)
        rest_dict[city] = [[int(score), i]]
    else:
        rest_dict[city].append([int(score), i])

city_list = sorted(city_list)
for city in city_list:
    rest_list = rest_dict[city]
    rest_list = sorted(rest_list, reverse=True)
    for rest in rest_list:
        print(rest[1]+1)

Submission status: Accepted

Solution code:
n = [(input().split()) for _ in range(int(input()))]
m = sorted(sorted(n,key=lambda x:int(x[1]), reverse=True),key=lambda x:x[0])
print('\n'.join([str(n.index(li)+1) for li in m]))

Submission status: Accepted

Solution code:
#B
n = int(input())
rst = []
for _ in range(n):
    s,p = map(str,input().split())
    rst.append([s,int(p)])
    
rst_sort = rst[:]
rst_sort.sort(key=lambda x: (x[0],-x[1]))

for i in range(n):
    print(rst.index(rst_sort[i]) + 1)

Submission status: Accepted

Solution code:
from sys import argv

debug = "a" in argv
n = int(input())
ls = []
la = ls.append
for i in range(1, n + 1):
    s = input().split()
    la((i, s[0], int(s[1])))
if debug:
    print("ls:",ls)
ls = sorted(ls, key=lambda x: x[2], reverse=1)
ls = sorted(ls, key=lambda x: x[1])
if debug:
    print("ls(sorted):",ls)
if debug:
    print("debug end")
for x in ls:
    print(x[0])

Submission status: Accepted

Solution code:
import heapq

N = int(input())
que = []
for i in range(N):
    l = input().split(' ')
    heapq.heappush(que, (l[0], -int(l[1]), i + 1))

while que:
    print(heapq.heappop(que)[2])

Submission status: Accepted

Solution code:
n = int(input())
li = []
for i in range(n):
    a,b = map(str,input().split())
    li.append([a,int(b),i+1])

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

for i in range(n):
    print(li[i][-1])

Submission status: Accepted

Solution code:
N=int(input())
S={}

for i in range(N):
  p,q=input().split()
  S[i+1]=(p,int(q))
S=sorted(S,key=lambda x:(S[x][0],-S[x][1]))

print(*S,sep="\n")

Submission status: Accepted

Solution code:
n = int(input())
list_2d = [[] for _ in range(n)]

for i in range(n):
    s, p = input().split()
    list_2d[i].append(s)
    list_2d[i].append(p)
list_2d_sorted = sorted(list_2d, key = lambda x: (x[0],-int(x[1])))
for i in range(n):
    print(list_2d.index(list_2d_sorted[i])+1)

Submission status: Accepted

Solution code:
n = int(input())

s = [0]*n
p = [0]*n

list_2d = [[] for _ in range(n)]

for i in range(n):
    s, p = input().split()
    list_2d[i].append(s)
    list_2d[i].append(p)
list_2d_sorted = sorted(list_2d, key = lambda x: (x[0],-int(x[1])))
for i in range(n):
    print(list_2d.index(list_2d_sorted[i])+1)

Submission status: Accepted

Solution code:
N = int(input())
S = list(range(N))
P = list(range(N))
SP = list(range(N))

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

S_ = sorted(set(S))
P_ = sorted(set(P), reverse = True)

for n in range(len(S_)):
  for m in range(len(P_)):
    if (S_[n], P_[m]) in SP:
      print(SP.index((S_[n], P_[m])) + 1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
sp = [0]*n
for i in range(n):
    s, p = map(str, input().split())
    p = int(p)
    sp[i] = [i+1, s, p]
sp.sort(key=lambda x:(x[1],-x[2]))
for _ in sp:
    print(_[0])

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
restaurants = defaultdict(list)
for i in range(n):
    s, p = input().split()
    p = int(p)
    restaurants[s].append([p, i])

cnt = 0
for k, v in sorted(restaurants.items(), key=lambda x: x[0]):
    for p, i in sorted(v, key=lambda x: -x[0]):
        print(i + 1)

Submission status: Accepted

Solution code:
N = int(input())
rest_list = []
for i in range(N):
    a,b=input().split()
    temp=[i+1,a,(-1)*int(b)]
    rest_list.append(temp)
rest_list.sort(key=lambda x: (x[1], x[2]))
for i in rest_list:
    print(i[0])

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
dic = defaultdict(lambda:{})
for _ in range(n):
  i = input().split()
  dic[i[0]][int(i[1])] = _ + 1

for i in sorted(dic):
  for j in sorted(dic[i], reverse=True):
    print(dic[i][j])

Submission status: Accepted

Solution code:
n = int(input())
from operator import itemgetter
sset = set()
sp = [list(input().split()) + [i+1] for i in range(n)]
for i in range(n):
    sp[i][1] = int(sp[i][1])
for i in range(n):
    sset.add(sp[i][0])
sp.sort(key = itemgetter(1),reverse = True)
slist = sorted(list(sset))
anslist = []
for i in range(len(sset)):
    for j in range(n):
        if sp[j][0] == slist[i]:
            anslist.append(sp[j][2])

for ans in anslist:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
shoplist=[]
for i in range(N):
    a,b=input().split()
    #得点を-1倍して、ソートをやりやすくする。
    temp=[i+1,a,-1*int(b)]
    shoplist.append(temp)
    
#多次元リストを複数キーでソートする。
#print(shoplist)
shoplist.sort(key=lambda x:(x[1],x[2]))

#print(shoplist)

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