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())
Vs = [ input().split() for _ in range(N)]
Vs = list(map(lambda x: (x[0], int(x[1])),Vs))
Vss = sorted(Vs, key=lambda x: (x[0], -x[1]))

for v in Vss:
    print(Vs.index(v)+1)

Submission status: Accepted

Solution code:
n = int(input())
cities = {}
r = []
for i in range(n):
    c, s = input().split(" ")
    r.append([c,int(s)])
    if cities.get(c) == None:
        cities[c] = [i]
    else:
        cities[c].append(i)

# sort

for c, num in sorted(cities.items()):
    for j in sorted(num, key=lambda x:r[x][1], reverse=True):
        print(j+1)

Submission status: Accepted

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

dic = {}
for x,p in sp:
    if x in dic:
        dic[x].append(int(p))
    else:
        dic[x] = [int(p)]

res_l = []
for x,p in sp:
    res = 0
    flg = False
    for k in sorted(dic):
        if x != k:
            res+=len(dic[k])
        else:
            l = sorted(dic[k], reverse=True)
            #print(l)
            for i in l:
                res += 1
                if int(i) == int(p):
                    flg == True
                    res_l.append(res)
                    break

        if flg:
            break

xx = [0]*n
for i,x in enumerate(res_l):
    xx[x-1] = i+1

for x in xx:
    print(x)

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)])
#print(l)

m = sorted(l,key=lambda x:(x[1],-x[2]))
#print(m)
for i in m:
    print(i[0])

Submission status: Accepted

Solution code:
n = int(input())
index=0
listA=[]
hashMap={}
while index < n:
    s, p = map(str, input().split())
    listA.append([s, p])
    if s in hashMap:
        hashMap[s].append(int(p))
    else:
        hashMap[s] = [int(p)]
    index+=1

answerL=[]
newHashMap={}
index=0
num = 1
keyL = list(hashMap.keys())
keyL.sort()
while index < len(keyL):
    index2=0
    listV = hashMap[keyL[index]]
    listV.sort(reverse = True)
    while index2 < len(listV):
        newHashMap[keyL[index]+str(listV[index2])]=num
        num+=1
        index2+=1
    index+=1

index=0
while index < len(listA):
    answerL.append(newHashMap[listA[index][0]+listA[index][1]])
    index+=1
newAnsL=[0]*n
index=0
while index < len(answerL):
    newAnsL[answerL[index]-1] = index+1
    index+=1
for ans in newAnsL:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
data=[]
for i in range(N):
  B,C=input().split()
  B=str(B)
  C=int(C)
  data.append([i+1,B,C])
  

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

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

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
dic2 = {}
for i in range(N):
    s, p = input().split()
    dic[int(p)] = s
    dic2[int(p)] = i
dic = sorted(dic.items(), reverse=True)
for i,j in sorted(dic, key=lambda x:x[1]):
    print(dic2[i]+1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
a = list()

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

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

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

Submission status: Accepted

Solution code:
N=int(input())
sp = []
n = 1
for i in range(N):
  iin = input().split()
  Sin = iin[0]
  Pin = int(iin[1])
  sp.append( [Sin, Pin, n] )
  n+=1
sp = sorted( sp, key=lambda ii:ii[1], reverse=True)
sp = sorted( sp, key=lambda ii:ii[0])
for ss in sp:
  print(ss[2])

Submission status: Accepted

Solution code:
N = int(input())
city2l = {}
for i in range(N):
    s,p = input().split()
    p = int(p)
    if s not in city2l:
        city2l[s]=[]
    city2l[s].append([p,i+1])
l = []
for key in city2l:
    ins = city2l[key]
    ins = sorted(ins, key=lambda x:-x[0])
    for one in ins:
        l.append([key, one[1]])
l = sorted(l, key=lambda x:x[0])
for o in l:
    print(o[1])

Submission status: Accepted

Solution code:
N = int(input())

lst = []
for i in range(N):
    s, p = input().split()
    town = [s, int(p), i + 1]
    lst.append(town)
# print(lst)

lst.sort(key=lambda x: (x[0],-x[1]))
# print(lst)

for a in lst:
    print(a[2])

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())

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

for i, (name, tup) in enumerate(sorted(city.items())):
    for score, num in sorted(tup, reverse=True):
        print(num)

Submission status: Accepted

Solution code:
def solve():
  N = int(input())
  SP = [[i for i in input().split()] for s in range(N)]
  name = []
  dictionary = {}
  for i in range(N):
    S, P = SP[i]
    if S not in dictionary:
      dictionary[S] = []
      name.append(S)
    dictionary[S].append([i + 1, int(P)])
  name.sort()
  for n in name:
    d = sorted(dictionary[n], key=lambda x: x[1], reverse=True)
    for _d in d:
      print(_d[0])

solve()

Submission status: Accepted

Solution code:
n = int(input())
rs = [input().split() for _ in range(n)]
rs = [(r, int(p)) for r, p in rs]
srs = sorted(sorted(rs, key=lambda p: p[1], reverse=True), key=lambda p: p[0])
 
for p in srs:
  print(rs.index(p)+1)

Submission status: Accepted

Solution code:
n=int(input())
from collections import defaultdict
d=defaultdict(list)
for i in range(n):
    s,p=input().split()
    d[s].append((int(p),i+1))
keys=sorted(d.keys())
# print(keys)
# print(d)
for key in keys:
    for item in sorted(d[key],key=lambda x : x[0],reverse=True):
        print(item[1])

Submission status: Accepted

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

for i in range(N):
  S, P = input().split()
  P = int(P)
  res.append([i, S, P])
  
res.sort(key=lambda x: x[1])
buf = []

for e in res:
  if len(buf) == 0 or buf[-1][1] == e[1]:
    buf.append(e)
  else:
    buf.sort(key=lambda x: -x[2])
    for f in buf:
      print(f[0] + 1)
    buf = [e]

if len(buf) > 0:
  buf.sort(key=lambda x: -x[2])
  for f in buf:
    print(f[0] + 1)

Submission status: Accepted

Solution code:
n=int(input())

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

#print(li)
lis = sorted(li)
#print(lis)

for i in range(0,n):
    print(lis[i][2])

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
X = [None for _ in range(N)]
for i in range(N):
    Si, Pi = input().split()
    Pi = int(Pi)
    X[i] = list((Si, Pi, i + 1))
X.sort(key=itemgetter(1), reverse=True)
X.sort(key=itemgetter(0))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
SP=[list(map(str,input().split())) for __ in range(n)]
for i in range(len(SP)):
    SP[i][1] = str(SP[i][1]).zfill(3)
    SP[i].extend([i+1])

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

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

Submission status: Accepted

Solution code:
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

def main():
    N = II()
    li = []
    for i in range(N):
        S, P = LS()
        li.append([S, int(P), i])

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

main()

Submission status: Accepted

Solution code:
def f(l):
    a, b, c = l
    return int(b)

def f2(l):
    a, b, c = l
    return a

N = int(input())
SP = [list(map(str, input().split())) for _ in range(N)] #N_length and M_times args

for _ in range(len(SP)):
    SP[_].append(_+1)

SP.sort(key=f, reverse=True)
SP.sort(key=f2)

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

Submission status: Accepted

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


def main():
    n = int(input())
    rest = dict()

    for i in range(n):
        si, pi = input().split()

        if si not in rest.keys():
            rest[si] = [(i + 1, int(pi))]
        else:
            rest[si].append((i + 1, int(pi)))

    for key, values in sorted(rest.items(), key=lambda x: x[0]):
        for no, values in sorted(values, key=lambda y: y[1], reverse=True):
            print(no)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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 = sorted(SP, reverse=True, key=lambda x: x[1])
SP = sorted(SP, key=lambda x: x[0])
for s, p, i in SP:
    print(i)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

N = int(input())
data = []
for i in range(N):
    city, value = input().strip().split(' ')
    data.append((city, int(value), i+1))
data.sort(key=lambda x: x[1], reverse=True)
data.sort(key=lambda x: x[0])
for i in range(N):
    print(data[i][2])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

res = sorted(res, key=lambda x:x[2], reverse=True)
res = sorted(res, key=lambda x:x[1], reverse=False)
for r in res:
    print(r[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import defaultdict


def solve(N: int, S: "List[str]", P: "List[int]"):
    d = defaultdict(list)

    for i,(s,p) in enumerate(zip(S,P)):
        d[s].append((i,p))
    d = sorted(d.items())

    for k,v in d:
        v.sort(key=lambda x:x[1],reverse = True)
        for vv in v:
            print(vv[0]+1)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [str()] * (N)  # type: "List[str]" 
    P = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        S[i] = next(tokens)
        P[i] = int(next(tokens))
    solve(N, S, P)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
    s,p=input().split()
    pp=int(p)
    l.append([s,pp,i])
l.sort(key=lambda x:x[0])
buf=l[0][0]
b=n
m=[]
for i in range(n):
    [s,p,index]=l[i]
    if (buf!=s):
        b-=1
        buf=s
    m.append([b*100+p,index,s])
m.sort(key=lambda x:x[0],reverse=True)
for i in range(n):
    print(m[i][1]+1)

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
    l.append(list(input().split())+[i+1])
l=sorted(l, key=lambda x: x[0])
s=sorted(set([x[0] for x in l]))
for c in s:
    x=sorted([a for a in l if a[0]==c], key=lambda x: int(x[1]))[::-1]
    for a in x:
        print(a[2])

Submission status: Accepted

Solution code:

if __name__ == '__main__':
    n = int(input())
    d = {}
    for i in range(n):
        s,p = input().split()
        p = int(p)
        if( s not in d ):
            d[s] = []
        temp = d[s]
        temp.append([p,i])
    
    k = d.keys()
    k = sorted(k)
    for i in k:
        d[i].sort(key=lambda x: -x[0])
        for j in d[i]:
            print(j[1] + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

for sp_t in sp:
        print(sp_t[2]+1)

Submission status: Accepted

Solution code:
N = int(input())
L = [[0]*3 for i in range(N)]

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

tmp = sorted(L, key=lambda x: x[1], reverse=True)
ans = sorted(tmp, key=lambda x: x[0])
for a in ans:
    print(a[2])

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())
sp = [input().split() for i in range(n)]

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

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

Submission status: Accepted

Solution code:
N = int(input())
s = [(lambda x, v: (x, -int(v)))(*input().split()) for i in range(N)]
s2 = s.copy()

s.sort()
for i in s:
    print(s2.index(i)+1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from operator import itemgetter

N = int(input())
data = []
for i in range(N):
    r = input().split()
    data.append((r[0], int(r[1]), i+1))

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

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

Submission status: Accepted

Solution code:
n = int(input())
sp = [list(input().split()) for _ in range(n)]
for i in range(len(sp)):
    sp[i][1] = int(sp[i][1])
d = sorted(sp, key=lambda x:(x[0],-x[1]))
for i in range(len(sp)):
    print(sp.index(d[i])+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = (input().split() for _ in range(n))
for x in sorted((s, -int(p), i) for i, (s, p) in enumerate(a, 1)):
    print(x[2])

Submission status: Accepted

Solution code:
n = int(input())

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

for k, v, t in sorted(rest_list, key=lambda x: (x[0],-x[1])):
    print(t)

Submission status: Accepted

Solution code:
import numpy as np

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

for n in sorted(set(S)):
    d = []
    p = []
    for i in range(N):
        if S[i] == n:
            d.append(i)
            p.append(P[i])

    for i in np.argsort(p)[::-1]:
        print(d[i] + 1)

Submission status: Accepted

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

for i in sorted(list(set(s))):
    c = [[j+1, p[j]] for j in range(n) if s[j] == i]
    c = sorted(c, key = lambda x: x[1], reverse = True)
    for ci in c:
        print(ci[0])

Submission status: Accepted

Solution code:
N = int(input())

restaurant_list = [list(input().split()) for i in range(N)]

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

for restaurant in sorted_list:
    for i, original in enumerate(restaurant_list):
        if restaurant == original:
            print(i+1)

Submission status: Accepted

Solution code:
from collections import defaultdict
l = defaultdict(list)

n = int(input())


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

for k in sorted(l.keys()):
    for i in sorted(l[k], key=lambda t: t[1], reverse=True):
        print(i[0])

Submission status: Accepted

Solution code:
# coding:utf-8
# BBBBBBBBBBB

import math
import re

def main(params):
    n = int(params[0])
    sp = params[1:]
    cnt = 0
    ipt = {}
    for i in sp:
        cnt += 1
        s,p = i.split()
        p = int(p)
        if s in ipt:
            ipt[s].append([p,cnt])
        else:
            ipt[s] = [[p,cnt]]
    keys = ipt.keys()
    keys.sort()
    for k in keys:
        if len(ipt[k]) == 1:
            print ipt[k][0][1]
        else:
            ranks = ipt[k]
            ranks.sort()
            ranks.reverse()
            for i in ranks:
                print i[1]

if __name__ == "__main__":
    n = int(raw_input())
    cnt = n # TODO: edit here
    params = [n]
    for i in range(cnt):
        param = raw_input()
        params.append(param)
    main(params)

Submission status: Accepted

Solution code:
N = int(input())

arr = []

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

arr2 = sorted(arr, key=lambda x: x[1], reverse=True)
arr3 = sorted(arr2, key=lambda x: x[0], reverse=False)

for e in arr3:
    print(e[2])

Submission status: Accepted

Solution code:
N = int(input())
R = []
for i in range(N):
  l = input().split()
  R.append((l[0], (-1)*int(l[1]), i))

R.sort()
for i in range(N):
  print(R[i][2]+1)

Submission status: Accepted

Solution code:
N=int(input())
SP=[]
for i in range(N):
  a, b=input().split()
  SP+=[[a,int(b)]]
SP2=sorted(range(N), key=lambda x: (SP[x][0], -SP[x][1]))
for i in range(N):
  print(SP2[i]+1)

Submission status: Accepted

Solution code:
n = int(input())

X = []

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

X.sort()

for i in range(0, n):
    print(X[i][2] + 1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

def parse(line, i):
    [s, p] = line.split()
    
    return [s, int(p), i]

input_n = int(input())
input_S = [parse(input(), i) for i in range(input_n)]

for line in sorted(input_S, key=lambda x: (x[0], -x[1])):
    print(line[2] + 1)

Submission status: Accepted

Solution code:
N = int(input())
ans = []
for i in range(N):
    S,P = map(str,input().split(" "))
    P = int(P)
    ans.append([S,P,i+1])
sort_list = sorted(ans,key = lambda x:(x[0],-x[1]))
for i in range(N-1):
    if sort_list[i][0] == sort_list[i+1][0]:
        if sort_list[i][1] < sort_list[i+1][1]:
            temp = sort_list[i][1]
            sort_list[i][1] = sort_list[i+1][1]
            sort_list[i+1][1] = temp
#print(sort_list)
for i in range(N):
    print(sort_list[i][2])

Submission status: Accepted

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

restaurants.sort(key=lambda i: (i[1], -i[2]))

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

Submission status: Accepted

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

Submission status: Accepted

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

l.sort(key=lambda e:-e[1])
l.sort(key=lambda e:e[0])
print('\n'.join(str(i[2]) for i in l))

Submission status: Accepted

Solution code:
from sys import stdin
from operator import itemgetter

n = int(stdin.readline().rstrip())

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

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

Submission status: Accepted

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

data = sorted(data, key=lambda t: t[0]+str(100 - t[1]).zfill(3))

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

Submission status: Accepted

Solution code:
n=int(input())
res=[]
city=[]
for i in range(n):
    s,p=map(str,input().split())
    p=int(p)
    res.append([s,p,i+1])
R=sorted(res,key=lambda x : x[1],reverse=True)
Res=sorted(R,key=lambda x : x[0])

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

Submission status: Accepted

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

for i in range(n):
    s, p = input().split()
    p = "{:04}".format(100 - int(p))
    shops.append((s, p, i + 1))

shops = sorted(shops)
for shop in shops:
    print(shop[2])

Submission status: Accepted

Solution code:

n = int(input())

shop = list()

for i in range(n):
    input_lines = input().split(" ")
    shop.append([input_lines[0],100-int(input_lines[1]),i+1])
    
shop = sorted(shop)

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
from collections import defaultdict
n = int(input())
li = defaultdict(list)
for i in range(n):
    s, p = list(input().split())
    li[s].append((int(p), i+1))
ks = sorted(li)
for k in ks:
    kk = sorted(li[k], key=lambda x: x[0],  reverse=True)
    for i in kk:
        print(i[1])

Submission status: Accepted

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

l = []
for i, (s, p) in enumerate(sp):
    l.append((s, -int(p), i + 1))

l.sort()

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

Submission status: Accepted

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n = II()
sp = [LS() for i in range(n)]
for i, s in enumerate(sp):
    s.append(i+1)
sp = sorted(sp, key=lambda x: (x[0], -int(x[1])))
for i in sp:
    print(i[2])

Submission status: Accepted

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

for i in range(N):
    s,p=input().split()
    if s not in dict:
        dict[s]=[[int(p),i+1]]
    else:
        dict[s].append([int(p),i+1])

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

for d in List:
    k,L=d
    L.sort(key=lambda x:x[0],reverse=True)
    for l in L:
        print(l[1])

Submission status: Accepted

Solution code:
from operator import itemgetter

n=int(input())
arr=[]
for z in range(n):
  name,point=input().split(" ")
  point=int(point)
  arr.append((name,point,z+1))
  arr=sorted(arr,key=itemgetter(1),reverse=True)
  arr=sorted(arr,key=itemgetter(0))

for z in arr:
  print(z[2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n= int(input())
dic = {}
for i in range(1, n+1):
    s, p = input().split()
    if s in dic.keys():
        dic[s].append((int(p), i))
    else:
        dic[s]=[(int(p), i)]
List = sorted(dic.items())
for li in List:
    ll = sorted(li[1], reverse = True, key = lambda x:x[0])
    for lli in ll:
        print(lli[1])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
S_P = { i+1: input().split() for i in range(N)}
for i in range(N):
    S_P[i+1][1] = int(S_P[i+1][1])
S_P = sorted(S_P.items(), key=lambda x:x[1][1], reverse=True)
S_P = sorted(S_P, key = lambda x:x[1][0])
for i in range(N):
    print(S_P[i][0])
print()

Submission status: Accepted

Solution code:
n=int(raw_input())
checck = {}
for i in xrange(n):
    s,p=map(str,raw_input().split())
    p=int(p)
    if s in checck:
        checck[s].append((p,i))
    else:
        checck.update({s:[(p,i)]})
check=list(checck)
check=sorted(check)
#print check
for i in check:
    l=checck[i]
    l=sorted(l)
    for j in xrange(len(l)-1,-1,-1):
        print l[j][1]+1

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
N = int(input())
temp = []
l = []
for n in range(N):
    temp = input().split()
    l.append([temp[0], int(temp[1]), n+1])
    temp = []

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

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    sps = [(i, x.split()) for i,x in enumerate(stdin.readlines())]
    sps = [(x[0], x[1][0], 100-int(x[1][1])) for x in sps]
    sps.sort(key=lambda x: (x[1], x[2]))

    for i,s,p in sps:
        print(i+1)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

for x in iSP:
    print(x[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
shop=[]
for i in range(n):
  name,s=input().split()
  score=int(s)
  shop.append([name,score,i+1])
ans=sorted(shop, key=lambda x:(x[0],-x[1]))
for i in range(n):
  print(ans[i][2])

Submission status: Accepted

Solution code:
def main():

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

    d = {}
    for i in range(N):
        if S[i] in d.keys():
            d[S[i]].append((i+1, P[i]))
        else:
            d[S[i]] = [(i+1, P[i])]

    for key in sorted(d.keys()):
        a = d[key]
        a = sorted(a, key=lambda x: -x[1])
        for i, score in a:
            print(i)
            

main()

Submission status: Accepted

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

restaurants = [(i+1, s, p) for i, (s, p) in enumerate(restaurants)]

sort_key = lambda x:(x[1],-x[2])
restaurants = sorted(restaurants, key = sort_key)

#print(restaurants)
for r in restaurants:
    print(r[0])