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

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

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

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

check = 0
c = []

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

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

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

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

Solution (Python):
n=int(input())
dicsp={}
listp=[]
for i in range(n):
  s,p=map(str,input().split())
  listp.append([s,p])
  dicsp.setdefault(s,[]).append(p)
  

s=sorted(list(dicsp.keys()))
listsp=[]
for i in s:
  t=list(map(int,dicsp[i]))
  t.sort(reverse=True)
  for j in t:
    listsp.append([i,j])

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

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

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

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

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

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


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


resolve()

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

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

Solution (Python):
import math

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

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

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

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

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

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

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

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

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

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



if __name__ == '__main__':
    main()

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

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

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

Solution (Python):


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

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

scores.sort()

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

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

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

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

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

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

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

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

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

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

Solution (Python):



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


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


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

Solution (Python):
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter


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


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


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


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



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
sp = [None]*n
for i in range(n):
    sp[i] = [None]*3

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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 _, _, i in L:
    print(i)

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

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

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

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

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

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

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

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

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

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

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

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

Solution (Python):
import sys 

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

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

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

SP = {}

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

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

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

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

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

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

    ids = []

    for key in sorted(set(S)):
        
        s = [d for d in restaurant_dict_list if d['name'] == key]
        t = sorted(s, key=lambda x: x['point'], reverse=True)

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

    return '\n'.join(ids)

n = int(input())

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

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

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

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

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

Solution (Python):
import sys

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


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

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

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


if __name__ == '__main__':
    solve()

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import defaultdict


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

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


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

Solution (Python):

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

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

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


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


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

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

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

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

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

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

Solution (Python):
from operator import itemgetter

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

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

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


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

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

if __name__ == '__main__':
    main()

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

sorted_dic1 = sorted(dic1.items())

for key, i_list in sorted_dic1:
    p_list = []
    for i in i_list:
        p_list.append((dic2[i], i))
    p_list.sort(reverse=True)
    for ans_i in p_list:
        print(ans_i[1])

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

for i in range(n):
  s[i].insert(0, i+1)

for i in range(1, n):
  tmp = s[i][:]
  for j in range(1, i+1):
    if tmp[1] < s[i-j][1]:
      s[i-j+1], s[i-j] = s[i-j], s[i-j+1]
    elif tmp[1] == s[i-j][1]:
      if int(tmp[2]) > int(s[i-j][2]):
        s[i-j+1], s[i-j] = s[i-j], s[i-j+1]

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

Solution (Python):
n = int(input())
li = [input().split() + [i] for i in range(n)]
li.sort(key=lambda x: (x[0], -int(x[1])))
for x, y, z in li:
    print(z + 1)

Solution (Python):
n = int(input())
sp = [0] * n
for i in range(n):
    sp[i] = input().split() + [i+1]
    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 range(n):
    print(sp[i][2])

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


S = [[0 for j in range(3)] for i in range(N)]

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


T=sorted(S,key=lambda x:x[2],reverse=True)
U=sorted(T,key=lambda x:x[1])
for i in range(N):
    print(U[i][0])

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

lis = []

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

nlis = copy.deepcopy(lis)
nlis = sorted(lis)

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

Solution (Python):
n=int(input())
y=[input() for i in range(n)]
x=sorted(y)

a=[list(map(str,x[i].split())) for i in range(n)]
b=[]
e=[]

while len(a):
  d=[]
  c=a[0][0]
  b.append(a[0][0])
  d.append(int(a[0][1]))
  a.pop(0)
  while len(a):
    if c==a[0][0]:
      b.append(a[0][0])
      d.append(int(a[0][1]))
      a.pop(0)
    else:
      break
  e+=sorted(d,reverse=True)

for i in range(n):
  print(y.index(b[i]+' '+str(e[i]))+1)

Solution (Python):
import math
def ip():return int(input())
def inp():return map(int,input().split())
def inpstr():return map(str,input().split())
def linp():return list(map(int,input().split()))
def linpstr():return list(map(str,input().split()))

n=ip()
city=[]
score=[]
for i in range(n):
    s,p=inpstr()
    city.append([s,-int(p),i+1])
city.sort()
for i in range(n):print(city[i][2])

Solution (Python):
import math
def ip():return int(input())
def inp():return map(int,input().split())
def inpstr():return map(str,input().split())
def linp():return list(map(int,input().split()))
def linpstr():return list(map(str,input().split()))

n=ip()
city=[]
score=[]
for i in range(n):
    s,p=inpstr()
    city.append([s,int(p),i+1])
city.sort(key=lambda e:e[0])
city.sort(key=lambda e:(e[0],-e[1]),reverse=False)
for i in range(n):print(city[i][2])

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

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




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

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

Solution (Python):
n=int(input())
key=[]
value=[]
for i in range(1,n+1):
    a,b=input().split()
    b=100-int(b)
    key.append((a,b))
    value.append(i)
dic=dict(zip(key,value))

key.sort()
for j in key:
    print(dic[j])

Solution (Python):
N = int(input())
citys = []
SP = []
for i in range(0,N,1):
    S,P = input().split()
    citys.append(S)
    SP.append([S,int(P)])
citys = list(set(citys))
citys.sort()
for i in citys:
    tmp = []
    for j in range(0,N,1):
        if i == SP[j][0]:
            tmp.append([SP[j][1],j])
    tmp.sort(reverse=True)
    for j in tmp:
        print(j[1]+1)

Solution (Python):
from operator import itemgetter

N = int(input())
SPi = [input().split()+[i] for i in range(N)]
for v in SPi:
    v[1] = int(v[1])
SPi.sort(reverse=True, key=itemgetter(1))
SPi.sort(key=itemgetter(0))
for v in SPi:
    print(v[2]+1)

Solution (Python):
from collections import defaultdict
n = int(input())
d = defaultdict(list)
for i in range(n):
  s, p = map(str, input().split())
  d[s].append([int(p), i + 1])
d = dict(d)
d = sorted(d.items(), key=lambda x:x[0])
for e in d:
  e[1].sort(key=lambda x: x[0], reverse=True)
  for i in range(len(e[1])):
    print(e[1][i][1])

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

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

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

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

Solution (Python):
n = int(input())
ls = [list(map(str,input().split())) for _ in range(n)]
nums = [e for e in range(1,n+1)]
for i in range(n):
    ls[i][1] = 100-int(ls[i][1])
    ls[i] = ls[i] + [nums[i]] 
ls = sorted(ls)
for i in range(n):
    print(ls[i][2])

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

Solution (Python):
from collections import defaultdict
N = int(input())
restaurant = []
for i in range(N):
    s, p = input().split()
    restaurant += [(i + 1, s, - int(p))]
sorted_restaurant = sorted(restaurant, key=lambda x: (x[1], x[2]))
print('\n'.join([str(s[0]) for s in sorted_restaurant]))

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

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

a.sort()
for aa in a:
	print(aa[2]+1)

Solution (Python):
N = int(input())
A = []
for i in range(N):
    a,b=input().split()
    b=100-int(b)
    if b<10:
        A.append(a+'00'+str(b))
    elif b==100:
        A.append(a+str(b))
    else:
        A.append(a+'0'+str(b))
B=sorted(A)
for b in B:
    print(A.index(b)+1)

Solution (Python):

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



for _ in range(n):
    s,ps = map(str,input().split())
    p = ps
    sp[_][0] = _
    sp[_][1] = s
    sp[_][2] = p

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

for _ in sp:
    print(_[0]+1)

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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
from collections import defaultdict

n = int(input())
d = defaultdict(list)
for i in range(n):
    s, p = input().split()
    d[s].append([int(p), i + 1])
keys = list(d.keys())
keys.sort()
ans = []
for key in keys:
    values = d[key]
    values = sorted(values, reverse=True)
    for i, j in values:
        ans.append(j)
for i in ans:
    print(i)

Solution (Python):
N = int(input())
S = []
P = []
Num = []
for i in range(N):
  s, p = input().split()
  S.append(s)
  P.append(int(p))
  Num.append(i+1)
for i in range(N):
  for m in range(i):
    if S[m] > S[i] or (S[m] == S[i] and P[i] > P[m]):
      S[m], S[i] = S[i], S[m]
      P[m], P[i] = P[i], P[m]
      Num[m], Num[i] = Num[i], Num[m]
for i in range(N):
  print("{}".format(Num[i]))

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

data = [0] * n

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


data2 = sorted(data)

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

Solution (Python):
n = int(input())
lis = []
for i in range(n):
    a, b = input().split()
    lis.append((a, int(b), i + 1))
lis.sort(key=lambda x: x[1], reverse=True)
lis.sort(key= lambda x: x[0])
print(*[lis[i][2] for i in range(n)], sep="\n")

Solution (Python):
n=int(input())
lis=[]
for i in range(n):
    s,p=input().split()
    lis.append((i+1, str(s), int(p)))
ans=[]
lis=sorted(lis, key=lambda x:x[1])
tmp=[]
for l in lis:
    if tmp==[]:
        tmp.append(l)
    elif tmp[0][1]==l[1]:
        tmp.append(l)
    else:
        tmp=sorted(tmp,reverse=True,key=lambda x:x[2])
        for t in tmp:
            ans.append(t[0])
        tmp=[l]
tmp=sorted(tmp,reverse=True,key=lambda x:x[2])
for t in tmp:
    ans.append(t[0])

for i in ans:
    print(i)

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

Solution (Python):
from collections import defaultdict
N = int(input())
a = defaultdict(list)
for i in range(N):
    s, p = map(str, input().split())
    a[s].append([int(p),int(i+1)])
a = sorted(a.items())
for b in a:
    b[1].sort(reverse=True)
    for c in b[1]:
        print(c[1])

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    b,c=input().split()
    c=int(c)
    a.append([b,c])
sa=sorted(a)
sa.append(["STOP"])
ssa=[]
ssaa=[]
while len(sa)>1:
    while True:
        ssa.append(sa[0])
        sa=sa[1:]
        if ssa[-1][0]!=sa[0][0] or sa[0]=="STOP":
            break
    ssa=ssa[::-1]
    for i in ssa:
        ssaa.append(i)
    ssa=[]
for i in ssaa:
    print(a.index(i)+1)

Solution (Python):
n = int(input())
sp = [0]*n
z = [0]*n
for i in range(n):
    sp[i]    = input().split() + [i+1]
    sp[i][1] = int(sp[i][1])
    z[i]     = sp[i][0]
a = sp
a.sort(key=lambda val : val[0])
import collections
c = collections.Counter(z)

i = 0
while i < n:
    b = c[a[i][0]]
    d = a[i:i+b][:]
    d.sort(key= lambda val : val[1],reverse=True)
    for j in range(b):
        print(d[j][2])
    i += b

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

Solution (Python):

from operator import itemgetter
n = int(input())

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

b = sorted(a, key=itemgetter(1), reverse=True)
guidebook = sorted(b, key=itemgetter(0))

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

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

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

Solution (Python):

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

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

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

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

    Q = [[] for _ in range(N)]
    for i in range(N):
        pp, ss = input().split()
        Q[i] = [i + 1, pp, - int(ss)]

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

    for QQ in Q:
        print(QQ[0])


resolve()

Solution (Python):
import numpy as np
N = int(input())
S_list= []
P_list= []
for i in range(N):
    S,P = map(str,input().split())
    S_list.append(S+str(100-int(P)).zfill(3))

for j in np.argsort(S_list):
    print(j+1)

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

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

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

Solution (Python):
from operator import itemgetter

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

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

for x in A:
    ans = SP.index(x)
    print(ans + 1)

Solution (Python):
n = int(input())
dic = {}
for i in range(1,n+1):
    s,p = map(str,input().split())
    dic[i]=s+str(1/(int(p)+1))
for s in sorted(dic.items(),key=lambda x:x[1]):
    print(s[0])

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 sp:(sp[0],-sp[1]))
for i in sp:
  print(i[2])

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

s = []
p = []
num = []
for i in range(n):
  tmp = input().split()
  s.append(tmp[0])
  p.append(tmp[1])
  num.append(i)
sp = []
st = []
sn = []
spnum = zip(s,p,num)
spnum_s = sorted(spnum)

for i in range(0,len(spnum_s)):
  st.append(spnum_s[i][0])
  sp.append(int(spnum_s[i][1]))
  sn.append(spnum_s[i][2])
  
  if(i == len(spnum_s)-1 or st[-1] != spnum_s[i+1][0]):
    tmp = zip(sp,sn)
    tmp2 = sorted(tmp, reverse=True)
    
    for j in range(0,len(tmp2)):
      print(tmp2[j][1]+1)
    st = []
    sp = []
    sn = []

Solution (Python):
n = int(input())
data = {}
for i in range(n):
    s,p = map(str,input().split())
    p = int(p)
    if s in data:
        data[s].append((p,i+1))
    else:
        data[s] = [(p,i+1)]
D = sorted(data.items())
for i in range(len(D)):
    P = D[i][1]
    P.sort()
    while P:
        print(P.pop()[1])

Solution (Python):
N = 6
ARR = [
    ["khabarovsk", 20],
    ["moscow", 10],
    ["kazan", 50],
    ["kazan", 35],
    ["moscow", 60],
    ["khabarovsk", 40]
]
N = int(input())
ARR = []

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


def calculate(n, arr):
    dict = {}
    for i in range(N):
        if dict.get(arr[i][0]) == None:
            dict.__setitem__(arr[i][0], [[arr[i][1], i]])
        else:
            rates = dict.get(arr[i][0])
            rates.append([arr[i][1], i])
            rates = sorted(rates, key=lambda x: -x[0])
            dict.__setitem__(arr[i][0], rates)

    keys = sorted(dict.keys())

    for key in keys:
        aaa = dict.get(key)
        for a in aaa:
            print(a[1] + 1)


calculate(N, ARR)

Solution (Python):


n = int(input())

data = {}
for i in range(n):
    s, p = list(map(str, input().split()))
    p = int(p)
    if s in data:
        data[s].append([p, i+1])
    else:
        data[s] = [[p, i+1]]


name_list = list(data.keys())
name_list.sort()


for i in name_list:
    data_tmp = data[i]
    data_tmp = sorted(data_tmp, key=lambda x: x[0], reverse=True)
    for j in data_tmp:
        print(j[1])

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

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

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