Problem:
 Score: 300 points    Problem Statement 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.      Constraints  1 \leq N \leq 10^5  1 \leq M \leq 10^5  1 \leq P_i \leq N  1 \leq Y_i \leq 10^9  Y_i are all different.  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  M  P_1  Y_1  :  P_M  Y_M       Output Print the ID numbers for all the cities, in ascending order of indices (City 1 , City 2 , ... ).        Sample Input 1 2 3
1 32
2 63
1 12      Sample Output 1 000001000002
000002000001
000001000001   As City 1 is the second established city among the cities that belong to Prefecture 1 , its ID number is 000001000002 .  As City 2 is the first established city among the cities that belong to Prefecture 2 , its ID number is 000002000001 .  As City 3 is the first established city among the cities that belong to Prefecture 1 , its ID number is 000001000001 .        Sample Input 2 2 3
2 55
2 77
2 99      Sample Output 2 000002000001
000002000002
000002000003

Solution (Python):
import bisect

N, M = map(int, input().split())
P = [0 for _ in range(M)]
Y = [0 for _ in range(M)]
y_p = [[] for _ in range(1, N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    y_p[P[i]-1].append(Y[i])

for p in set(P):
    y_p[p-1].sort()

for p, y in zip(P, Y):
    order = bisect.bisect_left(y_p[p-1], y)
    ans = str(p).zfill(6) + str(order+1).zfill(6)
    print(ans)

Solution (Python):
import bisect
N,M=map(int,input().split())
A=[[]for i in range(N)]
L=[]

for i in range(M):
    P,Y=map(int,input().split())
    A[P-1].append(Y)
    L.append([P-1,Y])



for j in range(N):
    A[j].sort()


for k in range(len(L)):
    ans1=str((L[k][0]+1)+1000000)
    ans1=ans1[1:]
    ans2=bisect.bisect_left(A[L[k][0]],L[k][1])
    ans2=str(ans2+1+1000000)
    ans2=ans2[1:]
    print(ans1+ans2)

Solution (Python):

N,M = list(map(int, input().split()))
P =[]
Y = []
yp = [(0,0,0)] * M
for i in range(M):
    P.append(0)
    Y.append(0)
    P[i], Y[i] = list(map(int, input().split()))
    yp[i] = (Y[i], P[i], i)

yp.sort()
dic = {}





pre = [0] * (N+1)
ansnum = [0] * M
for (y,p,i) in yp:
    pre[p] += 1
    ansnum[i] = "{0:06d}{1:06d}".format(p, pre[p])

import numpy as np
for i in range(M):
    print(ansnum[i])

Solution (Python):
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]


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

yp = [(0, 0, 0)]*M
for i in range(M):
    P, Y = map(int, input().split())
    yp[i] = (Y, P, i)

pre = [0]*(N+1)
ans = [0]*M

yp.sort()
for (y, p, i) in yp:
    pre[p] += 1
    right = str(pre[p])
    left = str(p)

    ans[i] = "0"*(6-len(left)) + left + "0"*(6-len(right)) + right

for i in range(M):
    print(ans[i])

Solution (Python):
def zerofill(s):
    return '0'*(6-len(s)) + s

n, m = map(int, input().split())
list = []
for i in range(m):
    p, y = map(int, input().split())
    list.append([p, y, i])
num = ['']*m 
list.sort()
cnt = 0
p = 1
for v in list:
    if(v[0]!=p):
        p = v[0]
        cnt = 1
    else:
        cnt += 1
    num[v[2]] = zerofill(str(v[0])) + zerofill(str(cnt))
for val in num:
    print(val)

Solution (Python):
import pprint

nn, mm = map(int, input().split())


list = []

for i in range(mm):
    p, y = map(int, input().split())
    dict = {}
    dict['i'] = i
    dict['p'] = p
    dict['y'] = y
    list.append(dict)

'''

2 3
1 32
2 63
1 12

dict = {}
dict['i']=1
dict['p']=1
dict['y']=32
list.append(dict)

dict = {}
dict['i']=2
dict['p']=2
dict['y']=63
list.append(dict)

dict = {}
dict['i']=3
dict['p']=1
dict['y']=12
list.append(dict)
'''



list.sort(key=lambda x: x['y'])





count_dict = {}

for l in list:
    if l['p'] in count_dict:
        count_dict[l['p']] += 1
    else:
        count_dict[l['p']] = 1
    l['ORDER'] = str(count_dict[l['p']]).zfill(6)



list.sort(key=lambda x: x['i'])




for l in list:
    print(str(l['p']).zfill(6) + l['ORDER'])

'''



d = list[0]
d['xx'] = 111

pprint.pprint(list)
'''

Solution (Python):
n,m=map(int,input().split())
l=list(list(map(int,input().split())) for i in range(m))
for i in range(m):
    l[i].append(i)
l.sort(key =lambda x:x[1])
l.sort(key =lambda x:x[0])
i=0
b=l[0][0]
for e in l:
    if b==e[0]:
        i+=1
    else:
        i=1
    e.append("%06d"%e[0]+"%06d"%i)
    b=e[0]
l.sort(key=lambda x:x[2])
for e in l:
    print(e[3])

Solution (Python):
N, M = map(int, input().split())
D = [[] for i in range(N)]

for i in range(M):
  p, y = map(int, input().split())
  D[p-1].append((y, i)) 
    
ans = [None]*M

for i, d in enumerate(D): 
  d.sort()
  for k, (y, j) in enumerate(d): 
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6) 

print(*ans, sep = '\n')

Solution (Python):
from collections import defaultdict

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

KEN = defaultdict(list)
KENOUT = defaultdict(dict)
OUTPUT = []
for i in range(M):
    p,y = map(int,input().split())
    KEN[p].append(y)
    OUTPUT.append((p,y))

for p in KEN:
    for i,y in enumerate(sorted(KEN[p])):
        KENOUT[p][y] = i+1
        
for p,y in OUTPUT:
    print(str(p).zfill(6)+str(KENOUT[p][y]).zfill(6))

Solution (Python):


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

answer_list = [0] * M
prefectures = [0] * (N+1)
data_set = [0] * M

for i in range(M):
	P, Y = map(int, input().split())
	data_set[i] = [P, Y, i]

data_set.sort()

for i in range(M):
	answer = ''
	P, Y, a = data_set[i]
	prefectures[P] += 1

	for j in range(6-len(list(str(P)))):
		answer += '0'

	answer += str(P)

	for k in range(6-len(list(str(prefectures[P])))):
		answer += '0'

	answer += str(prefectures[P])

	answer_list[a] = answer

for i in range(M):
	print(answer_list[i])

Solution (Python):
N, M = (int(i) for i in input().split())
P, Y = ({}, {})
for i in range(M):
    pp, yy = (int(i) for i in input().split())
    P[i] = pp
    Y[i] = yy

Y = sorted(Y.items(), key=lambda x:x[1])
Pnum = {}
Res = {}
for i, yy in Y:
    pp = P[i]
    if Pnum.get(pp):
        Pnum[pp] += 1
    else:
        Pnum[pp] = 1
    Res[i] = "{:0=6}{:0=6}".format(pp, Pnum[pp])

Res = sorted(Res.items(), key=lambda x:x[0])
for i, rr in Res:
    print(rr)

Solution (Python):
from bisect import bisect_left


n,m = list(map(int,input().split()))
a = [[0] for i in range(n)]
b = [None]*m
for i in range(m):
    p,s = list(map(int,input().split()))
    p-=1
    a[p].append(s)
    b[i] = [p,s]
for i in range(len(a)):
    a[i].sort()
for i in range(len(b)):
    ken = b[i][0]
    si = bisect_left(a[ken], b[i][1])
    ken = str(ken+1).zfill(6)
    si = str(si).zfill(6)
    print("".join([ken,si]))

Solution (Python):

def pad(n):
    return '{:0>6}'.format(n)


N, M = map(int, input().split())
work = [None for _ in range(M)]
orig = [None for _ in range(M)]  
for i in range(M):
    Pi, Yi = map(int, input().split())
    data = [Pi, Yi, 1, i]
    work[i] = data
    orig[i] = data

work.sort(key=lambda x: x[1])  
work.sort(key=lambda x: x[0])  

for i in range(1, M):
    if work[i][0] == work[i - 1][0]:
        work[i][2] = work[i - 1][2] + 1

ans = ''
for di in orig:
    ans += (pad(di[0]) + pad(di[2])) + '\n'
print(ans)

Solution (Python):

def pad(n):
    return '{:0>6}'.format(n)


N, M = map(int, input().split())
work = [None for _ in range(M)]
orig = [None for _ in range(M)]  
for i in range(M):
    Pi, Yi = map(int, input().split())
    data = [Pi, Yi, 1, i]
    work[i] = data
    orig[i] = data

work.sort(key=lambda x: x[1])  
work.sort(key=lambda x: x[0])  

for i in range(1, M):
    if work[i][0] == work[i - 1][0]:
        work[i][2] = work[i - 1][2] + 1

ans = []
for di in orig:
    ans.append(pad(di[0]) + pad(di[2]))
print('\n'.join(ans))

Solution (Python):

def pad(n):
    return '{:0>6}'.format(n)


N, M = map(int, input().split())
data = [None for _ in range(M)]
for i in range(M):
    Pi, Yi = map(int, input().split())
    data[i] = [Pi, Yi, 1, i]

data.sort(key=lambda x: x[1])  
data.sort(key=lambda x: x[0])  

for i in range(1, M):
    if data[i][0] == data[i - 1][0]:
        data[i][2] = data[i - 1][2] + 1

data.sort(key=lambda x: x[-1])  
ans = []
for di in data:
    ans.append(pad(di[0]) + pad(di[2]))
print('\n'.join(ans))

Solution (Python):

def pad(n):
    return '{:0>6}'.format(n)


N, M = map(int, input().split())
P, Y = [0 for _ in range(M)], [0 for _ in range(M)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())

data = [[P[i], Y[i], 1, i] for i in range(M)]
data.sort(key=lambda x: x[1])  
data.sort(key=lambda x: x[0])  

for i in range(1, M):
    if data[i][0] == data[i - 1][0]:
        data[i][2] = data[i - 1][2] + 1

data.sort(key=lambda x: x[-1])  
ans = []
for di in data:
    ans.append(pad(di[0]) + pad(di[2]))
print('\n'.join(ans))

Solution (Python):

def pad(n):
    return '{:0>6}'.format(n)


N, M = map(int, input().split())
P, Y = [0 for _ in range(M)], [0 for _ in range(M)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())

data = [[P[i], Y[i], 1, i] for i in range(M)]
data.sort(key=lambda x: x[1])  
data.sort(key=lambda x: x[0])  

for i in range(1, M):
    if data[i][0] == data[i - 1][0]:
        data[i][2] = data[i - 1][2] + 1

data.sort(key=lambda x: x[-1])  
for di in data:
    print(pad(di[0]) + pad(di[2]))

Solution (Python):
n,m = map(int,input().split())
arr = []
for i in range(m):
    arr += [list(map(int,input().split())) + [i]]  

dic = {}
for j in range(n+1):
    dic[j] = 1

arr.sort(key = lambda x : x[1])


for k in range(m):
    arr[k] += [dic[arr[k][0]]]
    dic[arr[k][0]] += 1

arr.sort(key = lambda x : x[2])
    
for v in range(m):
    print("{:06d}{:06d}".format(arr[v][0],arr[v][3]))

Solution (Python):
n, m = map(int, input().split())

info_list = []

for i in range(m):
    pi, yi = map(int, input().split())
    info_list.append([i+1, pi, yi])


from operator import itemgetter
info_list.sort(key = itemgetter(2))



xth = [1 for i in range(1, n+1)]


for info in info_list:
    info.append(str(info[1]).zfill((6)) + str(xth[info[1]-1]).zfill(6))
    xth[info[1]-1]+=1


info_list.sort(key = itemgetter(0))

for ele in info_list:
    print(ele[3])

Solution (Python):
n, m = map(int, input().split())

array = []
for i in range(m):
    temp = list(map(int, input().split()))
    temp.append(i)
    array.append(temp)

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

count = 1
eq = True

for i in range(m):
    if eq is False:
        count = 1
    array[i][1] = count
    count += 1
    if i != m - 1:
        if array[i][0] == array[i + 1][0]:
            eq = True
        else:
            eq = False

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

for i in range(m):
    out = '%06d' % array[i][0] + '%06d' % array[i][1]
    print(out)

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

dict_p = {}
dict_c = {}

for i, p, y in sorted(ipy, key=lambda x: x[2]):
  if not p in dict_p:
    dict_p[p] = 0
  dict_p[p] += 1
  dict_c[p,i] = dict_p[p]

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

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
py = []
for _ in range(m):
    py.append(list(li()))
    
towns = [[] for _ in range(n+1)]
table = [{} for _ in range(n+1)]
for p,y in py:
    towns[p].append(y)
    
for i in range(n+1):
    if len(towns[i]) > 0:
        towns[i].sort()
        
for i in range(n+1):
    if len(towns[i]) > 0:
        for j, tj in enumerate(towns[i]):
            table[i].update({tj: j+1})
            
for p,y in py:
    print(str(p).zfill(6) + str(table[p][y]).zfill(6))

Solution (Python):
N, M = map(int,input().split())
P = [[] for k in range(N)]
A = [0 for k in range(M)]

for k in range(M):
    s, t = map(int,input().split())
    P[s-1].append([t,k])

for k in range(N):
    P[k].sort()
    for l in range(len(P[k])):
        A[P[k][l][1]] = str(k+1).zfill(6) + str(l+1).zfill(6)

for a in A:
    print("".join(a))

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

id = []
city.sort(key=lambda x: x[1])
city.sort(key=lambda x: x[0])

pref = city[0][0]
num = 0
for i in range(m):
    if city[i][0] == pref:
        num += 1
        P = str(city[i][0]).zfill(6)
        Y = str(num).zfill(6)
        id.append([P+Y, city[i][2]])
    else:
        num = 1
        pref = city[i][0]
        P = str(city[i][0]).zfill(6)
        Y = str(num).zfill(6)
        id.append([P + Y, city[i][2]])

id.sort(key=lambda x: x[1])
for i in range(m):
    print(id[i][0])

Solution (Python):
import sys
fin = sys.stdin.readline
from collections import defaultdict


N, M = [int(elem) for elem in fin().split()]
cities = [[int(elem) for elem in fin().split()] for _ in range(M)]
sorted_cities = sorted(cities, key= lambda x: x[1])

num_cities_in_pref = defaultdict(int)
years_to_identification = dict()
for pref, year in sorted_cities:
    num_cities_in_pref[pref] += 1
    years_to_identification[year] = "{:06}{:06}".format(pref, num_cities_in_pref[pref])

for _, year in cities:
    print(years_to_identification[year])

Solution (Python):
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]

cs = [[] for i in range(N+1)]
for i,(p,y) in enumerate(src):
    cs[p].append((y,i))

ans = [None]*M
for pi,cities in enumerate(cs):
    for order,(y,i) in enumerate(sorted(cities)):
        ans[i] = str(pi).zfill(6) + str(order+1).zfill(6)
print(*ans, sep='\n')

Solution (Python):
N , M = map(int, input().split())
field = []
for i in range(M):
    p,y = map(int, input().split())
    field.append((y, p, i))
field.sort()

sum = [0 for i in range(N)]
field2 = []

for i in range(M):
	sum[field[i][1]-1] += 1
	field2.append((field[i][2], field[i][1], sum[field[i][1]-1]))
field2.sort()
for i in range(M):
	print(str(field2[i][1]).zfill(6)+str(field2[i][2]).zfill(6))

Solution (Python):
import sys as sys

lines =  input().split()
n = int(lines[0])
m = int(lines[1])

py = []
od = {}



for i in range(0,m):


    
    l = input().split()
    p = int(l[0])
    y = int(l[1])
    
    if p in od :
        od[p].append([i,y])
    else:
        od[p] = [[i,y]]

a = []
for p in od.keys():
    od[p].sort(key=lambda x:x[1])
    r = 1

    for o in od[p]:
        cs = ""

        tmp = p
        digit = 0
        while tmp > 0 :        
            digit += 1
            tmp = tmp // 10
        
        l = 6-digit
        for j in range(l):
            cs += '0'
        cs += str(p)

        tmp = r 
        digit = 0
        while tmp > 0 :        
            digit += 1
            tmp = tmp // 10

        l = 6-digit
        for j in range(l):
            cs += '0'
        cs += str(r)        

        a.append([o[0],cs])
        r += 1

a.sort(key=lambda x:x[0])
for aa in a:
    print(aa[1])

Solution (Python):
n,m=map(int,input().split())
p=[]
for i in range(m):
    t1,t2=map(int,input().split())
    p.append([i,t1,t2])
p.sort(key=lambda x:x[2])
c=[1 for i in range(n+1)]
num=[]
for i,pre,yea in p:
    tmp=str(pre).zfill(6)+str(c[pre]).zfill(6)
    num.append([i,tmp])
    c[pre]+=1
num.sort()
for i in num:
    print(i[1])

Solution (Python):
n, m = map(int, input().split())

prefectures = []

i = 0
while i < m:
    p, y = map(int, input().split())
    prefectures.append((i, p, y))
    i += 1
prefectures.sort(key=lambda x: x[2])

answers = []
ranks = [1 for i in range(n + 1)]
for i, p, y in prefectures:
    answers.append((i, str(p).zfill(6) + str(ranks[p]).zfill(6)))
    ranks[p] += 1

answers.sort()

for i, answer in answers:
    print(answer)

Solution (Python):
n, m = map(int, raw_input().split())
v = []
for i in range(m):
    p, y = map(int, raw_input().split())
    v.append((i, p, y))
v = sorted(v, key=lambda _: _[2])
D = {p: 1 for p in range(1,n+1)}
w = []
for i, p, y in v:
    x = D[p]
    D[p] += 1
    w.append((i, "%06d%06d" % (p, x)))
for i, code in sorted(w):
    print code

Solution (Python):
N, M = map(int, input().split())

D = []
for i in range(M):
    P, Y = map(int, input().split())
    D.append((i, P, Y))
D.sort(key=lambda x: x[2])

X = [1 for _ in range(N+1)]
A = []
for i, p, y in D:
    A.append((i, "{0:06d}{1:06d}".format(p, X[p])))
    X[p] += 1
A.sort()
for i, x in A:
    print(x)

Solution (Python):
from operator import itemgetter

n, m = map(int, input().split())
city = []
pre = set()
for i in range(m):
    p, y = map(int, input().split())
    city.append((p, y, i))
    pre.add(p)
city.sort(key=itemgetter(0, 1))
ans = []
now = city[0][0]
count = 1
for i in range(m):
    if city[i][0] != now:
        now = city[i][0]
        count = 1
    bangou = "0" * (6 - len(str(now))) + str(now) +\
             "0" * (6 - len(str(count))) + str(count)
    ans.append((city[i][2], bangou))
    count += 1
for i in sorted(ans):
    print(i[1])

Solution (Python):
from operator import itemgetter

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

A.sort(key=itemgetter(1,2))

prev = 0
no = 1
for i in range(m):
    if A[i][1] != prev:
        no = 1
        prev = A[i][1]
    else:
        no += 1
    A[i][2] = no

A.sort(key=itemgetter(0))
for a in A:
    print("%06d%06d" % (a[1], a[2]))

Solution (Python):
N, M = map(int, input().split())

all_cities = []
pref = {}
for _ in range(M):
    Pi, Yi = map(int, input().split())

    
    city = [Yi, None]

    all_cities.append(city)

    if Pi not in pref:
        pref[Pi] = []
    pref[Pi].append(city)

for pref_id, pref_cities in pref.items():
    for city_id, city in enumerate(sorted(pref_cities, key=lambda c: c[0])):
        city[1] = "{:06}{:06}".format(pref_id, city_id + 1)

for city in all_cities:
    print(city[1])

Solution (Python):
n,m=map(int,input().split())
l=[]
k=['_']*m
x=[1]*(n+1)
for i in range(m):
    a,b=map(int,input().split())
    l.append([i,a,b])
y=sorted(l,key=lambda c:c[2])
for i in y:
    k[i[0]]=str(i[1]).zfill(6)+str(x[i[1]]).zfill(6)
    x[i[1]]+=1
for i in k:
    print(i)

Solution (Python):
from sys import stdin
import numpy as np

s_in = lambda: stdin.readline()[:-1]  
d_in = lambda: int(stdin.readline())  
ds_in = lambda: list(map(int, stdin.readline().split()))  
N, M = ds_in()
info_list = []
for _ in range(M):
    info_list.append(ds_in())
info_list = np.array(info_list)
ordered = np.argsort(info_list[:, 1])
pref_count = np.zeros(N)
ans_list = ['' for _ in range(M)]
for i in ordered:
    pref = info_list[i, 0]
    pref_count[pref - 1] += 1
    ans_list[i] = '%06d%06d' % (pref, pref_count[pref - 1])
for a in ans_list:
    print(a)

Solution (Python):

from sys import stdin
import numpy as np

s_in = lambda: stdin.readline()[:-1]  
d_in = lambda: int(stdin.readline())  
ds_in = lambda: list(map(int, stdin.readline().split()))  


N, M = ds_in()

info_list = []
for _ in range(M):
    info_list.append(ds_in())
info_list = np.array(info_list)

ordered = np.argsort(info_list[:, 1])
pref_count = np.zeros(N)
ans_list = ['' for _ in range(M)]
for i in ordered:
    pref = info_list[i, 0]
    pref_count[pref - 1] += 1
    ans_list[i] = '%06d%06d' % (pref, pref_count[pref - 1])

for a in ans_list:
    print(a)

Solution (Python):
n,m=map(int,input().split())
l=[[] for i in range(n)]
for i in range(m):
    p,y=input().split()
    l[int(p)-1].append(y.zfill(10)+str(i).zfill(6))
for i in range(n):
    l[i].sort()
s=[0]*m
for i in range(n):
    for j in range(len(l[i])):
        s[int(l[i][j][10:16])]=str(i+1).zfill(6)+str(j+1).zfill(6)
for i in s:
    print(i)

Solution (Python):
n,m=map(int,input().split())
l=[{} for k in range(n)]
for i in range(m):
    p,y=map(int,input().split())
    l[p-1][y]=i
for k in range(n):
    l[k]=sorted(l[k].items(), key=lambda x:x[0])
s=[0]*m
for k in range(n):
    for r, p in enumerate(l[k]):
        s[p[1]]=[k,r]
for i in s:
    print('{:06}{:06}'.format(i[0]+1,i[1]+1))

Solution (Python):
n,m=map(int,input().split())
l=[{} for k in range(n)]
for i in range(m):
    p,y=map(int,input().split())
    l[p-1][y]=i
for k in range(n):
    l[k]=sorted(l[k].items(), key=lambda x:x[0])
s=[0]*m
for k in range(n):
    for r, p in enumerate(l[k]):
        s[p[1]]=str(k+1).zfill(6)+str(r+1).zfill(6)
for i in s:
    print(i)

Solution (Python):


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

data = [[] for i in range(n)]

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

ans = [0 for i in range(m)]
for i in range(n):
    data[i].sort()
    for j in range(len(data[i])):
        _id = "0"*(6-len(str(i+1)))+str(i+1)+"0"*(6-len(str(j+1)))+str(j+1)
        ans[data[i][j][1]] = _id

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

Solution (Python):
if __name__ == '__main__':
    N, M = map(int, input().split())

    ans = [None] * M
    prefMap = {}
    for i in range(M):
        P, Y = map(int, input().split())

        if P in prefMap:
            prefMap[P].append((Y, i))
        else:
            prefMap[P] = [(Y, i)]

    for P, L in prefMap.items():
        L.sort()

        for j, (y, i) in enumerate(L):
            ans[i] = str(P).zfill(6) + str(j + 1).zfill(6)

    print("\n".join(ans))

Solution (Python):
def main():
    n, m = map(int, input().split())

    dic = dict()
    for i in range(m):
        p, y = map(int, input().split())
        if p not in dic:
            dic[p] = list()
        dic[p].append([y,i])

    for v in dic.values():
        v.sort(key=lambda x:x[0])

    l = [0 for i in range(m)]
    last_k = n+1
    for k, v in dic.items():
        if k != last_k:
            j = 1
        for V in v:
            P = str(k)
            O = str(j)
            len_P = len(P)
            len_O = len(O)
            i = V[1]
            l[i] = "0"*(6-len_P) + P + "0"*(6-len_O) + O
            j += 1
            
    for num in l:
        print(num)

if __name__ == "__main__":
    main()

Solution (Python):
from operator import itemgetter

def main():
    num_prefecture, num_city = map(int, input().rstrip().split())
    
    prefecture_list = [[] for i in range(num_prefecture)]
    
    '''prefecture_list[prefecture_number-1] = [[city index, born year], ...]'''
    for idx_city in range(num_city):
        p_belong, y_born = map(int, input().rstrip().split())
        prefecture_list[p_belong - 1].append([idx_city, y_born]) 
    
    
    prefecture_list = [sorted(each_prefecture_list, key = itemgetter(1)) for each_prefecture_list in prefecture_list]
    
    id_list = []
    for idx_p, each_prefecture_list in enumerate(prefecture_list):
        for city_order, [idx_city, y_born] in enumerate(each_prefecture_list):
            id_num = str(idx_p + 1).zfill(6) + str(city_order + 1).zfill(6)
            id_list.append([idx_city, id_num])
    
    
    id_list.sort(key = itemgetter(0))
    
    for id_num in id_list:
        print(id_num[1])
    
if __name__ == '__main__':
    main()

Solution (Python):
from operator import itemgetter

def main():
    num_prefecture, num_city = map(int, input().rstrip().split())
    
    prefecture_list = [[] for i in range(num_prefecture)]
    
    '''prefecture_list[prefecture_number-1] = [[city index, born year], ...]'''
    for idx_city in range(num_city):
        p_belong, y_born = map(int, input().rstrip().split())
        prefecture_list[p_belong - 1].append([idx_city, y_born]) 
    
    
    prefecture_list = [sorted(each_prefecture_list, key = itemgetter(1)) for each_prefecture_list in prefecture_list]
    
    id_list = []
    for idx_p, each_prefecture_list in enumerate(prefecture_list):
        for city_order, [idx_city, y_born] in enumerate(each_prefecture_list):
            id_first = str(idx_p + 1).zfill(6)
            id_end = str(city_order + 1).zfill(6)
            id_num = id_first + id_end
            id_list.append([idx_city, id_num])
    
    
    id_list.sort(key = itemgetter(0))
    
    for id_num in id_list:
        print(id_num[1])
    
if __name__ == '__main__':
    main()

Solution (Python):
from operator import itemgetter

def main():
    num_prefecture, num_city = map(int, input().rstrip().split())
    
    prefecture_list = [[] for i in range(num_prefecture)]
    
    '''prefecture_list[prefecture_number-1] = [[city index, born year], ...]'''
    for idx_city in range(num_city):
        p_belong, y_born = map(int, input().rstrip().split())
        p_belong -= 1 
        prefecture_list[p_belong].append([idx_city, y_born])
    
    
    prefecture_list = [sorted(each_prefecture_list, key = itemgetter(1)) for each_prefecture_list in prefecture_list]
    
    id_list = []
    for idx_p, each_prefecture_list in enumerate(prefecture_list):
        for city_order, [idx_city, y_born] in enumerate(each_prefecture_list):
            id_first = '{0:06d}'.format(idx_p + 1)
            id_end = '{0:06d}'.format(city_order + 1)
            id_num = str(id_first) + str(id_end)
            id_list.append([idx_city, id_num])
    
    
    id_list.sort(key = itemgetter(0))
    
    for id_num in id_list:
        print(id_num[1])
    
if __name__ == '__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
l=[[] for i in range(n)]
for i in range(m):
    p,y=input().split()
    l[int(p)-1].append(y.zfill(10)+str(i).zfill(6))
for i in range(n):
    l[i].sort()
s=[0]*m
for i in range(n):
    for j in range(len(l[i])):
        s[int(l[i][j][10:16])]=str(i+1).zfill(6)+str(j+1).zfill(6)
for i in s:
    print(i)

Solution (Python):
N, M = map(int, input().split())
D = {}
for i in range(M):
    p, y = map(int, input().split())
    if p not in D:
        D[p] = [(i, y)]
    else:
        D[p].append((i, y))

for p in D.keys():
    D[p].sort(key=lambda p: p[1])

ans = [None for i in range(M)]
for p, pairs in D.items():
    for x, pair in enumerate(pairs):
        x += 1
        i = pair[0]
        y = pair[1]
        out = "{0:06d}{1:06d}".format(p, x)
        ans[i] = out
        

for an in ans:
    print(an)

Solution (Python):
n, m = map(int, input().split())

towns = []  

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

towns = sorted(towns, key=lambda tup: (tup[0], tup[1]))

p_cur = 0
x = 1
for i in range(m):
    if (towns[i][0] == p_cur):
        x += 1
    else:
        x = 1
        p_cur = towns[i][0]

    towns[i][1] = x

towns = sorted(towns, key=lambda tup: tup[2])

for i in range(m):
    print('{:06d}{:06d}'.format(towns[i][0], towns[i][1]))

Solution (Python):
tmp = list(map(int, input().split(" ")))
N = tmp[0]
M = tmp[1]

data = [[i] for i in range(M)]

for i in range(M):
    tmp = list(map(int, input().split(" ")))
    data[i].extend(tmp)

data = sorted(data, key=lambda x:(x[1],x[2]), reverse=False)

before = -1
counter = 1
for i in range(M):
    if data[i][1] != before:
        counter = 1
        before = data[i][1]
    data[i].append(counter)
    counter += 1

data = sorted(data, key=lambda x:(x[0]), reverse=False)

for d in data:
    print('{0:06}'.format(d[1]), end="")
    print('{0:06}'.format(d[3]))

Solution (Python):
n, m = [int(i) for i in input().split()]
p = [0 for i in range(m)]
y = [0 for i in range(m)]

out = [[0, 0] for i in range(m)]
hash = [[] for i in range(10**5+1)]
for i in range(m):
    p[i], y[i] = [int(i) for i in input().split()]
    hash[p[i]].append([y[i], i])

for i in range(len(hash)):
    hash[i] = sorted(hash[i])
    for j in range(len(hash[i])):
        out[hash[i][j][1]] = i, j+1
for i in range(len(out)):
    print("{}{}".format(str(out[i][0]).zfill(6), str(out[i][1]).zfill(6)))

Solution (Python):
n, m = [int(i) for i in input().split()]
p = [0 for i in range(m)]
y = [0 for i in range(m)]

out = [[0, 0] for i in range(m)]
hash = [[] for i in range(10**5+10)]
for i in range(m):
    p[i], y[i] = [int(i) for i in input().split()]
    hash[p[i]].append([y[i], i])

for i in range(len(hash)):
    hash[i] = sorted(hash[i])
    for j in range(len(hash[i])):
        out[hash[i][j][1]] = i, j+1
for i in range(len(out)):
    print("{}{}".format(str(out[i][0]).zfill(6), str(out[i][1]).zfill(6)))

Solution (Python):
N,M=map(int,input().split())
List=[[int(i) for i in input().split()] for i in range(M)]
for i in range(M):
  List[i].append(i)
List.sort(key=lambda x:[x[0],x[1]])
x=0
pre_p=1
ID=[""]*M
for i in List:
  if pre_p==i[0]:
    x+=1
  else:
    x=1
  ID[i[2]]+="0"*(6-len(str(i[0])))
  ID[i[2]]+=str(i[0])
  ID[i[2]]+="0"*(6-len(str(x)))
  ID[i[2]]+=str(x)
  pre_p=i[0]
for i in ID:
  print(i)

Solution (Python):
N, M = map(int, input().split())

num = {}
for i in range(M):
    P_i, Y_i = map(int, input().split())
    if P_i in num:
        num[P_i].append((Y_i, i))
    else:
        num[P_i] = [(Y_i, i)]

display = [0] * M
for i in num:
    k = str(0) * (6 - len(str(i))) + str(i)
    for index, j in enumerate(sorted(num[i], key=lambda x: x[0])):
        l = str(0) * (6 - len(str(index + 1))) + str(index + 1)
        display[j[1]] = k + l

for item in display:
    print(item)

Solution (Python):
N, M = map(int, input().split())

ans = []

for i in range(M):
   tmp = list(map(int, input().split()))
   tmp.append(i)
   tmp.append(-1)
   
   ans.append(tmp)
   
ans.sort(key=lambda x: x[1])

Check = [1]*N

for i in range(M):
    ans[i][3]=Check[ans[i][0]-1]
    Check[ans[i][0]-1] = Check[ans[i][0]-1]+1
                
ans.sort(key=lambda x: x[2])          

for i in range(M):
    ansA = str(ans[i][0]).zfill(6)
    ansB = str(ans[i][3]).zfill(6)
    tmp = [ansA, ansB]
    print(''.join(tmp))

Solution (Python):
N,M = (int(x) for x in input().split())

p_y_list = [0]*M
y_count = [1]*(N+1)

for i in range(M):
    p,y = (int(x) for x in input().split())
    p_y_list[i] = [p,y,i]
p_y_list.sort(key = lambda x:x[1])

for i in p_y_list:
    i[1] = y_count[i[0]]
    y_count[i[0]] += 1

p_y_list.sort(key = lambda x:x[2])
for i in p_y_list:
    print(str(i[0]).rjust(6,"0") + str(i[1]).rjust(6,"0"))

Solution (Python):
def main():
  n, m = map(int, input().split())
  a = [list(map(int, input().split())) for _ in range(m)]
  r = [0] * m
  pr = [[] for _ in range(n)]
  for i, x in enumerate(a):
    pr[x[0]-1].append([i, x[1]])
  pr = list(map(lambda x: sorted(x, key=lambda y: y[1]), pr))
  for i, x in enumerate(pr):
    for j, a in enumerate(x):
      r[a[0]] = str(i+1).zfill(6)+str(j+1).zfill(6)
  for x in r:
    print(x)
  
if __name__ == '__main__':
  main()

Solution (Python):
N,M = map(int,input().split())
t = [[] for i in range(N)]
ans = []
for i in range(M): 
    p,y = map(int,input().split())
    t[p-1].append([y,i])
    ans.append('')
for i in range(N):
    t[i].sort(key=lambda x:x[0])
    for j in range(len(t[i])):
        ans[t[i][j][1]] = str(i+1).zfill(6)+str(j+1).zfill(6)
for i in range(M):
    print(ans[i])