Problem: In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.  City i is established in year Y_i and belongs to Prefecture P_i.  You can assume that there are no multiple cities that are established in the same year.  It is decided to allocate a 12-digit ID number to each city.  If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.  Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.  Find the ID numbers for all the cities.  Note that there can be a prefecture with no cities.

Submission attempts (in order):
n, m = list(map(int, input().split()))
city_list = [[] for i in range(n)]
numbers = []

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list[pm-1].append(ym)

for i in range(n):
    city_list[i].sort()
    for j in range(len(city_list[i])):
        print("{:0=6}{:0=6}".format(i+1, j+1))


n, m = list(map(int, input().split()))
city_list = [[] for i in range(n)]

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list[pm-1].append(ym)

for i in range(n):
    city_list_copied[i].sort()
    for j in range(len(city_list[i])):
        cindex = sum(x <= city_list[i][j] for x in city_list[i])
        print("{:0=6}{:0=6}".format(i+1, cindex))


n, m = list(map(int, input().split()))
city_list = [[] for i in range(n)]

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list[pm-1].append(ym)
city_list_copied = copy.deepcopy(city_list)

for i in range(n):
    city_list_copied[i].sort()
    for j in range(len(city_list[i])):
        cindex = sum(x <= city_list[i][j] for x in city_list[i])
        print("{:0=6}{:0=6}".format(i+1, cindex))


import copy
n, m = list(map(int, input().split()))
city_list = [[] for i in range(n)]
numbers = []
 
for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list[pm-1].append(ym)
city_list_copied = copy.deepcopy(city_list)
 
for i in range(n):
    city_list_copied[i].sort()
    for j in range(len(city_list[i])):
        cindex = city_list_copied[i].index(city_list[i][j])
        print("{:0=6}{:0=6}".format(i+1, cindex+1))

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

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list.append([i,pm,ym])

city_count = {}
city = {}

for i,p,y in sorted(city_list, key=lambda x: x[1]):
    if not p in city_count:
        city_count[p] = 1
    else:
        city_count[p] += 1
    city[i,p] = city_count[p]

for i,p,y in city_list:
    print("{:0=6}{:0=6}".format(p, city[i,p]))

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

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list.append([i,pm,ym])

city_count = {}
city = {}

for i,p,y in sorted(city_list, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 1
    else:
        city_count[p] += 1
    city[i,p] = city_count[p]

for i,p,y in city_list:
    print("{:0=6}{:0=6}".format(p, city[i,p]))

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Accepted