Problem: 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.

Submission attempts (in order):
import numpy as np
from operator import itemgetter
 
N = int(input())
 
list = []
for i in range(N):
    a,b=input().split()
    list.append([a, int(b),i+1])
sort1 = sorted(list, key=itemgetter(0))
if N == 1:
  	print(1)
else:
    ans = []
    kari = []
    end = 1
    k = 1
    for i in range(0,N-1):
        if end == 1:
            kari.append(sort1[i])
        else:
            k = 0
        if sort1[i][0] == sort1[i+1][0]:  
            kari.append(sort1[i+1])
            end = 0
            if i+1 > N-2:
            	kari.sort(key=itemgetter(1),reverse=True)
            	ans.extend(kari)

        else:
            kari.sort(key=itemgetter(1),reverse=True)
            ans.extend(kari)
            if i+1 > N-2:
            	ans.append(sort1[i+1])
            	kari = []
            	end = 1
    print(sort1)
    print(ans)
    for i in range(0,len(ans)):
        print(ans[i][2])

import numpy as np
from operator import itemgetter

N = int(input())

list = []
for i in range(N):
    a,b=input().split()
    list.append([a, int(b),i+1])
sort1 = sorted(list, key=itemgetter(0))
if N == 1:
  print(1)
else:
  ans = []
  kari = []
  end = 1
  k = 1
  for i in range(0,N-1):
    if end == 1:
      kari.append(sort1[i])
      else:
        k = 0
        if sort1[i][0] == sort1[i+1][0]:  
          kari.append(sort1[i+1])
          end = 0
          if i+1 > N-2:
            kari.sort(key=itemgetter(1),reverse=True)
            ans.extend(kari)

            else:
              kari.sort(key=itemgetter(1),reverse=True)
              ans.extend(kari)
              if i+1 > N-2:
                ans.append(sort1[i+1])
                kari = []
                end = 1
  print(sort1)
  print(ans)
  for i in range(0,len(ans)):
      print(ans[i][2])

import numpy as np
from operator import itemgetter
 
N = int(input())
 
list = []
for i in range(N):
    a,b=input().split()
    list.append([a, int(b),i+1])
sort1 = sorted(list, key=itemgetter(0))
if N == 1:
  	print(1)
else:
    ans = []
    kari = []
    end = 1
    k = 1
    for i in range(0,N-1):
        if end == 1:
            kari.append(sort1[i])
        else:
            k = 0
        if sort1[i][0] == sort1[i+1][0]:  
            kari.append(sort1[i+1])
            end = 0
            if i+1 > N-2:
            	kari.sort(key=itemgetter(1),reverse=True)
            	ans.extend(kari)

        else:
            kari.sort(key=itemgetter(1),reverse=True)
            ans.extend(kari)
            if i+1 > N-2:
            	ans.append(sort1[i+1])
            kari = []
            end = 1
    
    for i in range(0,len(ans)):
        print(ans[i][2])

Verdicts: Wrong Answer

Runtime Error

Accepted