Problem p03030 (python)

Fixed submission:
n = int(input())

s_list = []
cnt = 0
for j in range(n):
    i,p = input().split()
    s_list.append([i,int(p),j])

s_list.sort(key=lambda x:(x[0],-x[1]))
 
for k in s_list:
  print(k[2]+1)

Buggy submission (verdict: Runtime Error):
n = int(input())

city_list = []
point_list = []
#tmp_list = []
for i in range(n):
    tmp = list(input().split())
    city_list.append(tmp[0])
    point_list.append(int(tmp[1]))
    #tmp_list.append(tmp)

indices = [*range(len(city_list))]
sorted_indices = sorted(indices, key=lambda i: city_list[i])
sorted_city = [city_list[i] for i in sorted_indices]

#print(sorted_city)
#print(sorted_indices)

tmp_list = []
tmp_indices_list = []
ans_indices_list = []
for j in range(n):
    if j == 0:
        tmp_list.append(point_list[int(sorted_indices[j])]) # 同一cityのpointを追加していく
        tmp_indices_list.append(int(sorted_indices[j])) # 同一cityのindicesを追加していく
    else:
        if sorted_city[j] == sorted_city[j-1]:
            tmp_list.append(point_list[int(sorted_indices[j])]) # 同一cityのpointを追加していく
            tmp_indices_list.append(int(sorted_indices[j])) # 同一cityのindicesを追加していく

            if j == n-1:
                indices = [*range(len(tmp_list))]
                sorted_tmp_indices = sorted(indices, key=lambda i: -tmp_list[i])
                sorted_tmp_point = [tmp_list[i] for i in sorted_tmp_indices]
                #print(sorted_tmp_indices)

                for k in sorted_tmp_indices:
                    ans_indices_list.append(tmp_indices_list[k])

        elif sorted_city[j] != sorted_city[j-1]:
            #print(tmp_list)
            indices = [*range(len(tmp_list))]
            sorted_tmp_indices = sorted(indices, key=lambda i: -tmp_list[i])
            sorted_tmp_point = [tmp_list[i] for i in sorted_tmp_indices]
            #print(sorted_tmp_indices)

            for k in sorted_tmp_indices:
                ans_indices_list.append(tmp_indices_list[k])

            if j == n-1:
                ans_indices_list.append(int(sorted_indices[j]))

            tmp_list = []
            tmp_indices_list = []
            tmp_list.append(point_list[int(sorted_indices[j])]) # 同一cityのpointを追加していく
            tmp_indices_list.append(int(sorted_indices[j])) # 同一cityのindicesを追加していく

#print(ans_indices_list)

for ans in ans_indices_list:
    print(str(ans+1))

Buggy submission (verdict: Runtime Error):
n = int(input())

city_list = []
point_list = []
#tmp_list = []
for i in range(n):
    tmp = list(input().split())
    city_list.append(tmp[0])
    point_list.append(int(tmp[1]))
    #tmp_list.append(tmp)

indices = [*range(len(city_list))]
sorted_indices = sorted(indices, key=lambda i: city_list[i])
sorted_city = [city_list[i] for i in sorted_indices]

#print(sorted_city)
#print(sorted_indices)

tmp_list = []
tmp_indices_list = []
ans_indices_list = []
for j in range(n):
    if j == 0:
        tmp_list.append(point_list[int(sorted_indices[j])]) # 同一cityのpointを追加していく
        tmp_indices_list.append(int(sorted_indices[j])) # 同一cityのindicesを追加していく
    else:
        if sorted_city[j] == sorted_city[j-1]:
            tmp_list.append(point_list[int(sorted_indices[j])]) # 同一cityのpointを追加していく
            tmp_indices_list.append(int(sorted_indices[j])) # 同一cityのindicesを追加していく

            if j == n-1:
                indices = [*range(len(tmp_list))]
                sorted_tmp_indices = sorted(indices, key=lambda i: -tmp_list[i])
                sorted_tmp_point = [tmp_list[i] for i in sorted_tmp_indices]
                #print(sorted_tmp_indices)

                for k in sorted_tmp_indices:
                    ans_indices_list.append(tmp_indices_list[k])

        elif sorted_city[j] != sorted_city[j-1]:
            #print(tmp_list)
            indices = [*range(len(tmp_list))]
            sorted_tmp_indices = sorted(indices, key=lambda i: -tmp_list[i])
            sorted_tmp_point = [tmp_list[i] for i in sorted_tmp_indices]
            #print(sorted_tmp_indices)

            for k in sorted_tmp_indices:
                ans_indices_list.append(tmp_indices_list[k])

            if j == n-1:
                ans_indices_list.append(int(sorted_indices[j]))

            tmp_list = []
            tmp_indices_list = []
            tmp_list.append(point_list[int(sorted_indices[j])]) # 同一cityのpointを追加していく
            tmp_indices_list.append(int(sorted_indices[j])) # 同一cityのindicesを追加していく

#print(ans_indices_list)

for ans in ans_indices_list:
    print(ans+1)