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: state num
M: city num
"""

state_cnt = {}
city_id_dict = {}

(N, M) = list(map(int, input().split()))

for z in range(M):
    (P, Y) = list(map(int, input().spilt()))

    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    state_num = str(P).zfill(6)
    city_num = str(Y).zfill(6)
    tmp_id = state_num + city_num
    city_id_dict[Y] = tmp_id
    

# all_state = set(range(1, N+1, 1))
# remain = set(all_state) - set(get_state)
# for num in ramain:
#     tmp_id = str(num).zfill(6) + "0"*6
#     city_id_list.append(tmp_id)
    
[print(city_id) for _, city_id in sorted(city_id_dict.items())]

"""
N: state num
M: city num
"""

state_cnt = {}
city_id_dict = {}

(N, M) = list(map(int, input().split()))
# N = 2
# m = 3

for z in range(M):
# p_y_list = [
#     [1, np.random.randint(100)]
#     ,[3, np.random.randint(100)]
#     ,[2, np.random.randint(100)]
#     ,[2, np.random.randint(100)]
#     ,[1, np.random.randint(100)]
#     ,[2, np.random.randint(100)]
    
# ]
# for (P, Y) in p_y_list:
    (P, Y) = list(map(int, input().split()))

    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    state_num = str(P).zfill(6)
    city_num = str(state_cnt[P]).zfill(6)
    tmp_id = state_num + city_num
    city_id_dict[Y] = tmp_id
    

# all_state = set(range(1, N+1, 1))
# remain = set(all_state) - set(get_state)
# for num in ramain:
#     tmp_id = str(num).zfill(6) + "0"*6
#     city_id_list.append(tmp_id)
    
for _, city_id in sorted(city_id_dict.items()):
    print(city_id)

(N, M) = list(map(int, input().split()))

state_cnt = {}
city_id_list = []
city_id_dict = {}
for z in range(M):
# for (P, Y) in p_y_list:
    
    (P, Y) = list(map(int, input().split()))

    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    state_num = str(P).zfill(6)
    city_num = str(state_cnt[P]).zfill(6)
    tmp_id = state_num + city_num

#     city_id_list.append([Y, P, tmp_id])
    
    city_id_dict[Y] = tmp_id
    

city_id_dict = sorted(city_id_dict.items())
for cid in city_id_dict:
    print(cid[1])

N, M = map(int, input().split(' '))

cities = []
for i in range(M):
    p, y = map(int, input().split(' '))
    cities.append([p, y, i])

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

p = cities[0][0]
cnt = 1
for i in range(M):

    if (cities[i][0] == p):
        cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
        cnt += 1
    else:
        p = cities[i][0]
        cnt = 1
        cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
        cnt += 1

sorted(cities, key=lambda x: x[2])

for i in range(M):
    print(cities[i][3])


"""
N: state num
M: city num
"""

state_cnt = {}
city_id_dict = {}

(N, M) = list(map(int, input().split()))
# N = 3
# m = 3

for z in range(M):
# p_y_list = [
#     [1, np.random.randint(100)]
#     ,[3, np.random.randint(100)]
#     ,[2, np.random.randint(100)]
#     ,[2, np.random.randint(100)]
#     ,[1, np.random.randint(100)]
#     ,[2, np.random.randint(100)]
    
# ]
# for (P, Y) in p_y_list:
    (P, Y) = list(map(int, input().spilt()))

    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    state_num = str(P).zfill(6)
    city_num = str(state_cnt[P]).zfill(6)
    tmp_id = state_num + city_num
    city_id_dict[Y] = tmp_id
    

# all_state = set(range(1, N+1, 1))
# remain = set(all_state) - set(get_state)
# for num in ramain:
#     tmp_id = str(num).zfill(6) + "0"*6
#     city_id_list.append(tmp_id)
    
for _, city_id in sorted(city_id_dict.items()):
    print(city_id)

from collections import defaultdict
import numpy as np

n, m = map(int, input().split())

list_ans = []
list_y = []
pre_p = -1
p_y = defaultdict(list)

for i in range(m):
    p, y = map(int, input().split())
    p_y[p].append(y)

for p in p_y.keys():
    list_y = p_y[p]
    list_num = np.argsort(list_y)
    for num in list_num:
        ans = str(p).zfill(6) + str(num + 1).zfill(6)
        print(ans)


debug = 0
"""
N: state num
M: city num
"""


if debug:
    N = 2
    m = 10
else:
    (N, M) = list(map(int, input().split()))

if debug:
    p_y_list = [
        [1, 30]
        ,[1, 20]
        ,[1, 10]
        ,[1, 3]
        ,[2, 63]
        ,[2, 33]
        ,[2, 23]
        ,[3, 21]
        ,[3, 7]
    ]

city_id_list = []
for z in range(M):
# for (P, Y) in p_y_list:
    
    if not debug:
        (P, Y) = list(map(int, input().split()))

    city_id_list.append([Y, P])
    
city_id_list = sorted( city_id_list, key= lambda x: x[0])

state_cnt = {}
tmp_list = []
for (Y, P) in city_id_list:
    
    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    tmp_id = str(P).zfill(6) + str(state_cnt[P]).zfill(6)
    
    tmp_list.append([state_cnt[P], tmp_id])
    
for cid in sorted(tmp_list, key=lambda x: (x[0], x[1])):
    print(cid[1])

debug = 0
"""
N: state num
M: city num
"""


if debug:
    N = 2
    m = 10
else:
    (N, M) = list(map(int, input().split()))

if debug:
    p_y_list = [
        [1, 30]
        ,[1, 20]
        ,[1, 10]
        ,[1, 3]
        ,[2, 63]
        ,[2, 33]
        ,[2, 23]
        ,[3, 21]
        ,[3, 7]
    ]

city_id_list = []

for (P, Y) in p_y_list:
    
    if not debug:
        (P, Y) = list(map(int, input().split()))

    city_id_list.append([Y, P])
    
city_id_list = sorted( city_id_list, key= lambda x: x[0])

state_cnt = {}
tmp_list = []
for (Y, P) in city_id_list:
    
    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    tmp_id = str(P).zfill(6) + str(state_cnt[P]).zfill(6)
    
    tmp_list.append([state_cnt[P], tmp_id])
    
for cid in sorted(tmp_list, key=lambda x: x[0]):
    print(cid[1])

debug = 0
"""
N: state num
M: city num
"""


if debug:
    N = 2
    m = 10
else:
    (N, M) = list(map(int, input().split()))

if debug:
    p_y_list = [
        [1, 30]
        ,[1, 20]
        ,[1, 10]
        ,[1, 3]
        ,[2, 63]
        ,[2, 33]
        ,[2, 23]
        ,[3, 21]
        ,[3, 7]
    ]

city_id_list = []
for z in range(M):
# for (P, Y) in p_y_list:
    
    if not debug:
        (P, Y) = list(map(int, input().split()))

    city_id_list.append([Y, P])
    
city_id_list = sorted( city_id_list, key= lambda x: x[0])

state_cnt = {}
tmp_list = []
for (Y, P) in city_id_list:
    
    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    tmp_id = str(P).zfill(6) + str(state_cnt[P]).zfill(6)
    
    tmp_list.append([state_cnt[P], tmp_id])
    
for cid in sorted(tmp_list, key=lambda x: x[0]):
    print(cid[1])

state_cnt = {}
city_id_dict = {}

(N, M) = list(map(int, input().split()))

for z in range(M):
    (P, Y) = list(map(int, input().spilt()))
    city_num_list.append(Y)

    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    state_num = str(P).zfill(6)
    city_num = str(state_cnt[P]).zfill(6)
    tmp_id = state_num + city_num
    city_id_dict[Y] = tmp_id
    

# all_state = set(range(1, N+1, 1))
# remain = set(all_state) - set(get_state)
# for num in ramain:
#     tmp_id = str(num).zfill(6) + "0"*6
#     city_id_list.append(tmp_id)
    
[print(city_id) for _, city_id in sorted(city_id_dict.items())]

N, M = map(int, input().split(' '))

cities = []
for i in range(M):
    p, y = map(int, input().split(' '))
    cities.append([p, y, i])

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

p = cities[0][0]
cnt = 1
for i in range(M):

    if (cities[i][0] == p):
        cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
        cnt += 1
    else:
        p = cities[i][0]
        cnt = 1
        cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
        cnt += 1

sorted(cities, key=lambda x: x[2])

for i in range(M):
    print(cities[i][3])


N, M = map(int, input().split(' '))

cities = []
for i in range(M):
    p, y = map(int, input().split(' '))
    cities.append([p, y, i])

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

p = cities[0][0]
cnt = 1
for i in range(M):

    if (cities[i][0] == p):
        cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
        cnt += 1
    else:
        p = cities[i][0]
        cnt = 1
        cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
        cnt += 1

cities = sorted(cities, key=lambda x: x[2])

for i in range(M):
    print(cities[i][3])


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Accepted