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):
import numpy as np
N, M = map(int, input().split())
cities = {}
P = {}
Y = []
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = (p,y)
    Y.append(y)

sorted_Y = sorted(Y)
sorted_P = {p:sorted(P[p].items(), key=lambda x:x[1]) for p in P}

P_i = np.zeros(N)
ans = {}
for i in sorted_Y:
    city = Y.index(i)+1
    ans[city] = i

for i in ans:
    p,y = cities[i]
    print('{0:06}{1:06}'.format(p, i))


import numpy as np
N, M = map(int, input().split())
cities = {}
P = {}
Y = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = p
    Y[i] = y

ans = []
sorted_Y = sorted(Y.items(), key=lambda x:x[1])
P_i = np.zeros(N)
for i,y in sorted_Y:
    p = cities[i]
    P_i[p] += 1
    ans.append(p,P_i[p])

for p,x in ans:
    print('{0:06}{1:06}'.format(p, x))


N, M = map(int, input().split())
P = {}

for i in range(M):
    p,y = map(int, input().split())
    if not p in P:
        P[p] = [y]
    else:
        P[p].append(y)

sorted_city = {p:sorted(P[p]) for p in P}

print(sorted_city)
for p, cities in  sorted(sorted_city.items()):
    for i,city in enumerate(cities):
        print('{0:06d}{1:06d}'.format(p,i+1))


"""
import numpy as np
N, M = map(int, input().split())
cities = {}
Y = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = p
    Y[i] = y

ans = {}
sorted_Y = sorted(Y.items(), key=lambda x:x[1])
P_i = np.zeros(N)
for i,y in sorted_Y:
    p = cities[i]
    P_i[p-1] += 1
    ans[i] = (p, int(P_i[p-1]))

for i in range(M):
    print('{0:06}{1:06}'.format(ans[i][0], ans[i][1]))
"""

n, m = map(int,input().split())
pys = []
for i in range(m):
    x = map(int, input().split())
    x = [x[0],x[1],i]
    pys.append(x)

pys.sort()
pp = -1
lid = 0
ans = []
for i in range(m):
    if pp == pys[i][0]:
        lid += 1
    else:
        lid = 1
        pp = pys[i][0]
    ans.append(pp*10**6+lid)

for v in ans:
    print(':012d'.format(v))


"""
import numpy as np
N, M = map(int, input().split())
cities = {}
Y = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = p
    Y[i] = y

ans = {}
sorted_Y = sorted(Y.items(), key=lambda x:x[1])
P_i = np.zeros(N)
for i,y in sorted_Y:
    p = cities[i]
    P_i[p-1] += 1
    ans[i] = (p, int(P_i[p-1]))

for i in range(M):
    print('{0:06}{1:06}'.format(ans[i][0], ans[i][1]))
"""

n, m = map(int,input().split())
pys = []
for i in range(m):
    x = list(map(int, input().split()))
    x = [x[0],x[1],i]
    pys.append(x)

pys.sort()
pp = -1
lid = 0
ans = [0]*m
for i in range(m):
    if pp == pys[i][0]:
        lid += 1
    else:
        lid = 1
        pp = pys[i][0]
    ans[pys[i][2]] = pp*10**6+lid

for v in ans:
    print('{:012d}'.format(v))


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted