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 = map(int,input().split())
py_list = []
d = dict()
for i in range(M):
    p,y = map(int,input().split())
    py_list.append([p,y])
py_sorted =  sorted(py_list)
p_temp = py_sorted[0][0]
count = 1
for p,y in py_sorted:
    if p_temp != p:
        p_temp = p
        count = 1
    d[(p,y)] = count
    count += 1

for i in range(M):
    s = d[(py_list[i][0],py_list[i][-1])]
    s = str(s)
    print(str(py_list[i][0]).zfill(6),s.zfill(6))



import sys
n,m = map(int,input().split())
py = []
d = dict()

for i in range(m):
    (a,b) = map(int,input().split())
    py.append((a,b))
sort_py = sorted(py)

tmp_p = sort_py[0][0]
cnt = 1
for p,y in sort_py:
    if p == tmp_p:
        d[(p,y)] = cnt
    else:
        tmp_p = p
        cnt = 1
        d[(p,y)] = cnt
    cnt += 1
for i in range(m):
    print('{0} {1}'.format(str(py[i][0]).zfill(6), str(d[py[i]]).zfill(6)))    


N,M = map(int,input().split())
py_list = []
d = dict()
for i in range(M):
    p,y = map(int,input().split())
    py_list.append([p,y])
py_sorted =  sorted(py_list)
p_temp = py_sorted[0][0]
count = 1
for p,y in py_sorted:
    if p_temp != p:
        p_temp = p
        count = 1
    d[(p,y)] = count
    count += 1

for i in range(M):
    s = d[(py_list[i][0],py_list[i][-1])]
    s = str(s)
    print(str(py_list[i][0]).zfill(6),s.zfill(6))



import sys
n,m = map(int,input().split())
py = []
d = dict()

for i in range(m):
    (a,b) = map(int,input().split())
    py.append((a,b))
sort_py = sorted(py)

tmp_p = sort_py[0][0]
cnt = 1
for p,y in sort_py:
    if p == tmp_p:
        d[(p,y)] = cnt
    else:
        tmp_p = p
        cnt = 1
        d[(p,y)] = cnt
    cnt += 1
print(d)
for i in range(m):
    print('{0} {1}'.format(str(py[i][0]).zfill(6), str(d[py[i]]).zfill(6)))    


from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
d = dict()
z = []
res = [None] * m
for i in range(m):
    a,b = inpl()
    d[(a,b)] = i
    z.append([a,b])
z.sort(key=lambda x:x[1])
z.sort(key=lambda x:x[0])
# print(z)
cnt = 0
now = z[0][0]
for i,t in enumerate(z):
    ind = d[(t[0],t[1])]
    if now == t[0]:
        cnt += 1
        res[ind] = [now,cnt]
    else:
        cnt = 1
        now = t[0]
        res[ind] = [now,cnt]

for a,b in res:
    print(str(a).zfill(6) + str(b).zfill(6))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted