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

Solution (Python):
import bisect
from operator import itemgetter
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
SP = []

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

sp = sorted(SP,key=itemgetter(1),reverse=True)
sp = sorted(sp,key=itemgetter(0))

for i,j,k in sp:
    print(k)

Solution (Python):

















import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations
from bisect import bisect_left, bisect_right


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")





N = i_inpl()
D = []
for i in range(N):
    si, pi = input().split()
    D.append([si, int(pi), i+1])

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

Solution (Python):
n = int(input())
l = [list(_ for _ in input().split()) for i in range(n)]
l = [[l[i][0] ,int(l[i][1]),i+1] for i in range(n)]
l = sorted(l,key = lambda x:(x[0],-x[1]))
[print(l[i][2]) for i in range(n)]

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]


N = int(input())

restaurants = []

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

    restaurants.append(
        {
            'S': S,
            'P': P,
            'number': i + 1
        }
    )

restaurants.sort(key=lambda x: (x['S'], -int(x['P'])))

for res in restaurants:
    print(res['number'])

Solution (Python):


import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

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

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

Solution (Python):
import sys

readline = sys.stdin.readline

N = int(readline())

SP = [readline().split() for i in range(N)]
iSP = [(i, s, int(p)) for i,(s,p) in enumerate(SP)]

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

for i,s,p in iSP:
    print(i + 1)

Solution (Python):
N = int(input())
SP = [[j] + [i for i in input().split()] for j in range(N)]

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

Solution (Python):
inpl = lambda: list(map(int,input().split()))
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[0]+("%03d" % (100-x[1])))
for S, P, i in SP:
    print(i)

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

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

for a,b,c in rest:
    print(a)

Solution (Python):
N = input()

arr = []

for i in xrange(N):
    A,B = raw_input().split()
    B = int(B)
    arr.append([A,B,i+1])


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

for i in xrange(N):
    print arr[i][2]

Solution (Python):
N = int(input())
dict = {}
for i in range(1,N+1):
    s,p = input().split()
    pt = int(p)
    if s in dict:
        dict[s].append((pt,i))
    else:
        dict[s] = [(pt,i)]
for key in dict:
    dict[key].sort(key = lambda x: -x[0])
    
d = list(dict)
d.sort()

for town in d:
    for p,id in dict[town]:
        print(id)

Solution (Python):
N=int(input())
rest={}
for i in range(N):
    S,P=input().split(" ")
    P=int(P)
    tmp=rest.get(S,[])
    tmp.append((P,i+1))
    rest[S]=tmp
for key in sorted(rest.keys()):
    Rs=rest[key]
    for s in sorted(Rs,reverse=True):
        print(s[1])

Solution (Python):
N = int(input())
restrant = []
for i in range(N):
    name, p = input().split()
    p = str(200 - int(p))
    restrant.append([name+p, i+1])
restrant.sort(key=lambda x:x[0])
for r in restrant:
    print(r[1])

Solution (Python):
N = int(input())
R = [[] for i in range(N)]
for i in range(N):
  S, P = input().split()
  R[i] = [S, int(P), i + 1]
R.sort(key=lambda x: (x[0], -x[1]))
for r in R:
  print(r[2])

Solution (Python):
N = int(input())
SP = [None] * N
for i in range(N):
    s, p = input().split()
    SP[i] = (s, int(p))

cities = {sp[0] for sp in SP}
cities = sorted(list(cities))
points = sorted([sp[1] for sp in SP], reverse=True)

for c in cities:
    for p in points:
        tpl = (c, p)
        if tpl in SP:
            print(SP.index(tpl) + 1)

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

Solution (Python):
import numpy as np
from collections import defaultdict
from functools import reduce


n = int(input())


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

for k in sorted(cites.keys()):
    [ print(i[1]) for i in sorted(cites[k], reverse=True)]

Solution (Python):
n = int(input())

r = []

for i in range(n):
    city, score = input().split()
    score = int(score)
    r.append((i + 1, city, score))

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

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

Solution (Python):
n = int(input())
sp = [input().split() for _ in range(n)]
for i in sorted(range(n), key=lambda i: (sp[i][0], -int(sp[i][1]))):
    print(i + 1)

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

Solution (Python):
n=int(input())

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

for i in arr:
    print(i[2]+1)

Solution (Python):
n=int(input())
a,b=[],[]
for i in range(n):
  s,p=input().split();p=int(p)
  if not s in a:a.append(s);b.append([s,[[p,i]]])
  else:b[a.index(s)][1].append([p,i])
b.sort()
for i in range(len(b)):
  b[i][1].sort(reverse=1)
  for j in b[i][1]:print(j[1]+1)

Solution (Python):




def main():
  stores = [[i + 1] + list(input().split()) for i in range(int(input()))]
  stores = [(i, s.strip(), int(p)) for i, s, p in stores]
  stores.sort(key=lambda x: (x[1], -x[2]))

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


if __name__ == '__main__':
  main()

Solution (Python):
N = int(input())

out = [(i+1, ) + tuple([x for x in input().split(' ')]) for i in range(N)]
out.sort(key=lambda x : int(x[2]), reverse=True)
out.sort(key=lambda x : x[1])

for i, S, P in out:
    print(i)

Solution (Python):
import math

n = list(map(int, input().split()))
lista = []

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

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

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

Solution (Python):
from operator import itemgetter

N = int(input())
SP = []
for i in range(N):
    Si, Pi = input().split(" ")
    SP.append([Si, int(Pi), i+1])
SP = sorted(SP, key=itemgetter(0, 1))
before = SP[0][0]
stack = []
for Si, Pi, i in SP:
    if before == Si:
        stack.append(i)
    else:
        for j in reversed(stack):
            print(j)
        stack = [i]
        before = Si
if len(stack) > 0:
    for j in reversed(stack):
        print(j)

Solution (Python):
n = int(input())

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

ss = sorted(list(set(sp.keys())))
for s in ss:
    for p, i in sorted(sp[s], reverse = True):
        print(i)

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

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

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op



inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    
    n = get_int()
    S, P = get_data(n, [str, int])
    R = [(i+1, s, p) for i, (s, p) in enumerate(zip(S, P))]
    R.sort(key=lambda r: r[2], reverse=True)
    R.sort(key=lambda r: r[1])
    for i, s, p in R:
        print(i)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Solution (Python):
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])
SP.sort(key=lambda x:x[0])
for i in range(N):
    print(SP[i][2])

Solution (Python):



N = int(input())

X = []
for i in range(N):
    s, p = input().rstrip().split(' ')
    p = int(p)
    X.append([i+1, s, p])
    
X = sorted(X, key=lambda x: '{}{:03d}'.format(x[1], 100-x[2]))

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

Solution (Python):
N = int(input())
I = [i+1 for i in range(N)]
S, P = [], []
for _ in range(N):
    inp = input().split()
    S.append(inp[0])
    P.append(int(inp[1]))

for i in range(N-1):
    for j in range(i+1, N):
        if S[i] > S[j] or (S[i] == S[j] and P[i] < P[j]):
            tmp = S[i]
            S[i] = S[j]
            S[j] = tmp
            tmp = P[i]
            P[i] = P[j]
            P[j] = tmp
            tmp = I[i]
            I[i] = I[j]
            I[j] = tmp

for i in I:
    print(i)

Solution (Python):
import itertools
N=int(input())
a = []
for i in range(N):
	s,b = input().split()
	a.append([s, int(b), i+1])


a.sort(key=lambda x:x[0])
for k,g in itertools.groupby(a, key=lambda x:x[0]):
	g= list(g)
	g.sort(key=lambda x:x[1],reverse=True)
	for a in g:
		print(a[2])

Solution (Python):
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[0], 100 - x[1]])

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

Solution (Python):
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[0], -x[1]))

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

Solution (Python):
def resolve():
    N = int(input())
    L = []
    for i in range(N):
        s, p = input().split()
        p = int(p)
        L.append((s, p, i+1))
    L = sorted(L, key=lambda x: (x[0], -x[1]))
    for l in L:
        print(l[2])
        
resolve()

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

    sort_with_score = sorted(data, key=lambda x: x[2], reverse=True)
    sort_with_name = sorted(sort_with_score, key=lambda x: x[1])

    for place in sort_with_name:
        print(place[0])


if __name__ == '__main__':
    main()

Solution (Python):


class Restaurant():
    def __init__(self, i, name, point):
        self.i = i
        self.name = name
        self.point = point

def solve():
    N = int(input())
    restaurants = []
    for i in range(N):
        s, p = input().split()
        r = Restaurant(i, s, int(p))
        restaurants.append(r)
    
    sorted_restaurants = sorted(restaurants, key=lambda r: r.point, reverse=True)
    sorted_restaurants = sorted(sorted_restaurants, key=lambda r: r.name)

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


if __name__ == "__main__":
    solve()

Solution (Python):
n=int(input())
L=[]
for i in range(n):
  a,b=input().split()
  L+=[[a,-int(b),i+1]]
L.sort()
for i in L:
  print(i[2])

Solution (Python):
N = int(input())
SPs = [[i for i in input().split()] for j in range(N)]
SPs = [[i+1, sp[0], int(sp[1])] for i, sp in enumerate(SPs)]
SPs = sorted(SPs, key=lambda x: (x[1], -x[2]))
[print(sp[0]) for sp in SPs]

Solution (Python):
import sys


s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    SP = ii2ss(N)
    D = []
    for i, sp in enumerate(SP):
        s, p = sp.split(' ')
        p = int(p)
        D.append((i+1, s, p))
    D.sort(key=lambda v: v[2])
    D.reverse()
    D.sort(key=lambda v: v[1])
    for i, s, p in D:
        print(i)

main()

Solution (Python):
import sys  
input = sys.stdin.readline

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

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

for a, b, c in SP:
    print(a)

Solution (Python):
from collections import defaultdict
N = int(input())
d = defaultdict(list)
city = set()
for i in range(N):
    S, P = input().split()
    P = int(P)
    d[S].append((P, i+1))
    city.add(S)

for s in d.keys():
    d[s].sort(reverse=True)

city = list(city)
city.sort()

for s in city:
    for p, i in d[s]:
        print(i)

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

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

for x in sp:
    s, v = x
    v.sort(key=lambda x:x[0], reverse=True)
    for p,i in v:
        print(i)

Solution (Python):
N = int(input())

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

SP.sort()
for _, _, i in SP:
    print(i)

Solution (Python):
from collections import defaultdict

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

for c in sorted(dic.keys()):
    for v, i in sorted(dic[c], key=lambda x: x[0], reverse=True):
        print(i + 1)

Solution (Python):
from operator import itemgetter

n = int(input())
sp = []
for i in range(n):
    s, p = input().split()
    sp.append([s, int(p), i + 1])
sp = sorted(sorted(sp, key=itemgetter(1), reverse=True), key=itemgetter(0))
for i in sp:
    print(i[2])

Solution (Python):
from operator import itemgetter

N = int(input())

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

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

Solution (Python):




N = int(input())

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

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

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

Solution (Python):
ans = []
for i in range(1, int(input()) + 1):
    s, p = input().split()
    p = -int(p)
    ans.append([s, p, i])
ans.sort()
print(*list(zip(*ans))[2], sep="\n")

Solution (Python):
N = int(input())
rest = []

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

rest.sort()
for i in range(N):
  print(rest[i][2])

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


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


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

Solution (Python):
n = int(raw_input())

ans = []
for i in range(0, n):
    s, p = raw_input().split(" ")
    p = int(p)

    ans.append((s, p * -1, i + 1))

sort = sorted(ans)

for i in range(0, len(sort)):
    city, point, index = sort[i]
    print(index)

Solution (Python):


def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  restaurants = []
  for i in range(N):
    S, P = input().split(" ")
    restaurants.append((S, int(P), i+1))
  restaurants.sort(key=lambda x: (x[0], -1 * x[1]))
  for _, _, n in restaurants:
    print(n)

if __name__ == "__main__":
  main()

Solution (Python):
def li():
    return list(map(int, input().split()))


if __name__ == '__main__':
    n = int(input())
    sp = [input().split() for _ in range(n)]
    for index, spi in enumerate(sp):
        spi[1] = int(spi[1])
        spi.append(index + 1)

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

    for spi in sp:
        print(spi[2])

Solution (Python):
n = int(input())

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

lis.sort()
for i in lis:
    print(i[-1])

Solution (Python):
N = int(input())

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

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

Solution (Python):
import numpy as np
words = lambda t : list(map(t, input().split()))

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

cs = sorted(cs)
for (s,p,i) in cs:
    print(i)

Solution (Python):
N, = (int(x) for x in input().split())

SP_arr = []
for _ in range(N):
    S,P = input().split()
    SP_arr.append([S, int(P)])

I_arr = list(range(N))
I_arr.sort(key=lambda x: SP_arr[x][1], reverse=True)
I_arr.sort(key=lambda x: SP_arr[x][0])

for i in I_arr:
    print(i+1)

Solution (Python):
import sys





























if __name__ == '__main__':

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

Solution (Python):
N=int(input())
temp=[input().split() for i in range(N)]
A=[[i+1,temp[i][0],int(temp[i][1])] 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):
    print(A[i][0])

Solution (Python):


N = int(input())
pairs = [input().split() for _ in range(N)]
pairs = [(a, int(b)) for a, b in pairs]
indices = list(range(N))
indices.sort(key=lambda idx: (pairs[idx][0], -pairs[idx][1]))
for idx in indices:
    print(idx + 1)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()

SP = [input().strip().split() for _ in range(N)]

dic = defaultdict(str)
for i, (S, P) in enumerate(SP):
	
	dic["{},{}".format(S, P)] = i+1
SP.sort(key=lambda x: (x[0], -int(x[1])))
for S, P in SP:
	print(dic["{},{}".format(S, P)])

Solution (Python):
import sys
INPUT = sys.stdin.readline

def SINGLE_INT(): return int(INPUT())
def MULTIPLE_INT_LIST(): return list(map(int, INPUT().split()))
def MULTIPLE_INT_MAP(): return map(int, INPUT().split())
def SINGLE_FLOAT(): return float(INPUT())
def MULTIPLE_FLOAT_LIST(): return list(map(float, INPUT().split()))
def MULTIPLE_FLOAT_MAP(): return map(float, INPUT().split())
def SINGLE_STRING(): return INPUT()
def MULTIPLE_STRING(): return INPUT().split()

N = SINGLE_INT()

ratings = []

for i in range(N):
    c, s = MULTIPLE_STRING()
    s_int = int(s)

    ratings.append((c, s_int, i+1))

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

for c, s_int, id in ratings:
    print(id)

Solution (Python):
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    N = int(single_input())
    point = dict()
    city = []
    for i in range(N):
        s, p = map(str, line_input())
        if s in point:
            point[s].append((int(p), i+1))
        else:
            point[s] = [(int(p), i+1)]
            city.append(s)
    city.sort()
    for s in city:
        l = point[s]
        l.sort(reverse = True)
        for p, i in l:
            print(i)
    return 0
  
if __name__ == "__main__":
    solve()

Solution (Python):


from collections import defaultdict



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

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

Solution (Python):
from collections import defaultdict


def main():
    n = int(input())
    restaurants = defaultdict(list)
    for i in range(n):
        s, p = input().split()
        p = int(p)
        restaurants[s].append((p, i))
    for key, restaurant in restaurants.items():
        restaurants[key] = sorted(restaurant, reverse=True)
    list_ress = [(key, val) for key, val in restaurants.items()]
    for key, val in sorted(list_ress):
        for p, i in val:
            print(i+1)


if __name__ == '__main__':
    main()

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

SP.sort()

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

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

def main():
  n=I()
  l=[]

  for i in range(n):
    a,b=LS()
    l.append([a,-int(b),i+1])

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

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

main()

Solution (Python):
from collections import Counter, deque, defaultdict
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N = int(input())
SP = [list(map(str, input().split())) for _ in range(N)]

d = defaultdict(lambda: [])
for s, p in SP:
    d[s].append(int(p))

for s in sorted(d.keys()):
    d[s].sort(reverse=True)
    for p in d[s]:
        print(SP.index([s, str(p)]) + 1)

Solution (Python):
N=int(input())
info=[]
for i in range(N):
	name, p = input().split()
	p = int(p)
	info.append([i+1, name, p])

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

Solution (Python):

N = int(input())
NP = [0 for i in range(N)]
for i in range(N):
    NP[i] = [str(n) for n in input().split()]
    NP[i].append(i+1)
NP = sorted(NP, key=lambda x: -int(x[1]))
NP = sorted(NP, key=lambda x: x[0])
for i in NP:
    print(i[2])

Solution (Python):
import bisect
import heapq
N = int(input())
vals = {}
for i in range(N):
	s,p = input().split()
	p = int(p)
	if s in vals.keys():
		vals[s].append([p,i+1])
	else:
		vals[s] = [[p,i+1]]

keys = []
for k in vals.keys():
	vals[k].sort(key = lambda x: -x[0])
	keys.append(k)

keys.sort()
for k in keys:
	for v in vals[k]:
		print(v[1])

Solution (Python):
N = int(input())

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

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

Solution (Python):
from collections import defaultdict

N = int(input())

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

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

Solution (Python):
N = int(input())

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

res = sorted(res)

for r in res:
    print(r[2])

Solution (Python):
N = int(input())
rs = []
for no in range(N):
    S, P = [i for i in input().split()]
    rs.append((S, int(P), no+1))
rs = sorted(rs, key=lambda x: x[1], reverse=True)
rs = sorted(rs, key=lambda x: x[0])
for r in rs:
    print(r[2])

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

Solution (Python):
N=int(input())
from collections import defaultdict
city=set()
data=defaultdict(list)
for i in range(N):
    S,P=input().split()
    P=int(P)
    city|={S}
    data[S].append((P,i+1))
city=list(city)
city.sort()
for c in city:
    x=data[c]
    x.sort(key=lambda x:x[0],reverse=True)
    for p,k in x:
        print(k)

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

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

for k in keys:
    sp[k].sort(reverse=True)
    for p,i in sp[k]:
        print(i)

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

Solution (Python):
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 e in L :
    print(e[2])

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

result = sorted(
    sorted(s_p_list, key=lambda x: x[2], reverse=True),
    key=lambda x: x[1]
)
for i, s, p in result:
    print(i)

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

SP.sort()

print('\n'.join(str(spi[2]) for spi in SP))

Solution (Python):
def main():
    N = int(input())
    restrants = [None] * N
    for i in range(N):
        S, P = input().split()
        restrants[i] = (S, -int(P), i)
    restrants.sort()
    for i in range(N):
        _, _, i = restrants[i]
        print(i+1)


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
N=int(input())
D=[]
for i in range(N):
  s,p=input().split()
  D.append((s, int(p), i+1))
D.sort(key=lambda d: (d[0], -d[1], d[2]))

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

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

Solution (Python):
n=int(input())
sp=[list(input().split()) for _ 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])

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

Solution (Python):

"""



"""
import sys


def solve(N, restaurants):
    restaurants.sort(key=lambda x: [x[0], -x[1]])
    return [r[2] for r in restaurants]


def main(args):
    N = int(input())
    restaurants = []
    for i in range(N):
        s, p = input().split()
        p = int(p)
        restaurants.append([s, p, i+1])
    ans = solve(N, restaurants)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
N = int(input())
L = [list(input().split()) for k in range(N)]
for k in range(N):
    L[k][1] = int(L[k][1])
    L[k].append(k+1)
L = sorted(L,key=lambda x:(x[0],-x[1]))
for l in L:
    print(l[2])

Solution (Python):
N = int(input())

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

lst.sort()
for i in lst:
    print (i[2])

Solution (Python):
n = int(input())
d = {}
for i in range(n):
	c, s = input().split()
	if c not in d:
		d[c] = []
	d[c].append((int(s), i))
for c in sorted(d.keys()):
	for s, i in sorted(d[c], reverse=True):
		print(i + 1)