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):
 # -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 18:54:20 2018
ABC113C
@author: maezawa
"""

n, m = list(map(int, input().split()))
p = [0]
y = [0]
for i in range(m):
    pi, yi = list(map(int, input().split()))
    p.append(pi)
    y.append(yi)

#print(p)
#print(y)
    
cityn = ['']*m

ps = [[] for _ in range(n+1)]
for i in range(1,m+1):
    ps[p[i]].append(i)
    
for j in range(1,n+1):
    ps[j].sort(key = lambda x: y[x])
    for i, k in enumerate(ps[j]):
        left = '000000'+ str(j)
        right = '000000' + str(i+1)
        cityn[k-1] = left[len(left)-5:] + right[len(right)-5:]

for i in range(m):
    print(cityn[i])
    

 # -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 18:54:20 2018
ABC113C
@author: maezawa
"""

n, m = list(map(int, input().split()))
p = [0]
y = [0]
for i in range(m):
    pi, yi = list(map(int, input().split()))
    p.append(pi)
    y.append(yi)

#print(p)
#print(y)
    
cityn = ['']*m

ps = [[] for _ in range(n+1)]
for i in range(1,m+1):
    ps[p[i]].append(i)
    
for j in range(1,n+1):
    ps[j].sort(key = lambda x: y[x])
    for i, k in enumerate(ps[j]):
        left = '000000'+ str(j)
        right = '000000' + str(i+1)
        cityn[k-1] = left[len(left)-5:] + right[len(right)-5:]

for i in range(m):
    print(cityn[i])
    

 # -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 18:54:20 2018
ABC113C
@author: maezawa
"""

n, m = list(map(int, input().split()))
p = [0]
y = [0]
for i in range(m):
    pi, yi = list(map(int, input().split()))
    p.append(pi)
    y.append(yi)

#print(p)
#print(y)
    
cityn = ['']*m

ps = [[] for _ in range(n+1)]
for i in range(1,m+1):
    ps[p[i]].append(i)
    
for j in range(1,n+1):
    ps[j].sort(key = lambda x: y[x])
    for i, k in enumerate(ps[j]):
        left = '000000'+ str(j)
        right = '000000' + str(i+1)
        cityn[k-1] = left[len(left)-5:] + right[len(right)-5:]

for i in range(m):
    print(cityn[i])
    

# -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 18:54:20 2018
ABC113C
@author: maezawa
"""

n, m = list(map(int, input().split()))
p = [0]
y = [0]
for i in range(m):
    pi, yi = list(map(int, input().split()))
    p.append(pi)
    y.append(yi)

#print(p)
#print(y)
    
cityn = ['']*m

ps = [[] for _ in range(n+1)]
for i in range(1,m+1):
    ps[p[i]].append(i)
    
for j in range(1,n+1):
    ps[j].sort(key = lambda x: y[x])
    for i, k in enumerate(ps[j]):
        left = '000000'+ str(j)
        right = '000000' + str(i+1)
        cityn[k-1] = left[len(left)-6:] + right[len(right)-6:]

for i in range(m):
    print(cityn[i])
    

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted