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):
n,m=map(int,input().split())
pref=[[] for _ in range(n+1)]
py = [[i]+list(map(int,input().split())) for i in range(m)]
py.sort(key=lambda x: (x[1],x[2]))
ans=list()
now=0
cnt=0
for x in py:
  cnt = 1 if now != x[1] else cnt + 1
  now = x[1]
  ans.append([x[0],x[1],cnt])
ans.sort(key=lambda x:x[0])
for x in ans:
  print(str(x[1]).zfill(6)+str(x[2]).zfill(6))

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

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

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

	no = 1
	tmp = 0
	for b in B:
		if tmp == b[0]:
			no += 1
		else:
			tmp = b[0]
			no = 1

		
		cityno = str(b[0]).zfill(6) + str(no).zfill(6)
		b[3] = cityno

	
	C = sorted(B,key=lambda x:(x[2]))
	
	for c in C:
		print(c[3])

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)
import math






INF = 1 << 50


def run():
    N,M, *PY = map(int, read().split())
    PY = [(PY[2 * i + 1], PY[2 * i], i) for i in range(M)]

    count_town = [0] * (N+1)
    ans = [''] * M
    PY = sorted(PY)
    for y, p, i in PY:
        count_town[p] += 1
        right = count_town[p]
        left = p
        right = (6- len(str(right))) * '0' + str(right)
        left = (6 - len(str(left))) * '0' + str(left)
        ans[i] = left + right

    for a in ans:
        print(a)






if __name__ == "__main__":
    run()

Solution (Python):
N,M = map(int,input().split())
P = [list(map(int,input().split())) for i in range(M)]
for i in range(M):
    P[i].append(i)
P.sort(key=lambda x: x[1])
B = [1]*N

for i in range(M):
    P[i] += "0"*(6 - len(str(P[i][0]))) + str(P[i][0]) + "0"*(6 - len(str(B[P[i][0]-1]))) + str(B[P[i][0]-1]),
    B[P[i][0]-1] += 1
    
P.sort(key=lambda x: x[2])
for i in range(M):
    print(P[i][3])

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    
    N,M = map(int,input().split())
    PY = [[i]+list(map(int,input().split())) for i in range(M)]

    PY = sorted(PY,key = lambda x:(x[1],x[2]))
    
    ans_li = ['0'*12]*M
    town_dict = {}

    for idx,p,y in PY:
        x = town_dict.get(p,1)

        id_ = ('{:6d}'.format(p)+'{:6d}'.format(x)).replace(' ','0')
        ans_li[idx] = id_

        town_dict[p] = town_dict.get(p,1)+1

    print('\n'.join(ans_li))
    
if __name__=='__main__':
    main()

Solution (Python):
from collections import defaultdict
N, M = map(int, input().split())
L = []
A = []
for _ in range(M):
    p, y = map(int, input().split())
    L.append([p, y])
    A.append([p, y])

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

ans_d = defaultdict()
dp = [0] * (N + 1)
for i, v in enumerate(L):
    
    s = ''
    if (dp[v[0]] != 0):
        l_dp = 6 - len(str(dp[v[0]] + 1))
        for j in range(l_dp):
            s += '0'

        s += str(dp[v[0]] + 1)
        dp[v[0]] += 1
    else:
        l_dp = 6 - len(str(dp[v[0]] + 1))
        for j in range(l_dp):
            s += '0'
        s += str(dp[v[0]] + 1)
        dp[v[0]] += 1
    k = str(v[0]) + ' ' + str(v[1])
    ans_d[k] = s

for i in A:
    m = str(i[0]) + ' ' + str(i[1])
    k = 6 - len(str(i[0]))
    s = ''
    for j in range(k):
        s += '0'
    s += str(i[0])
    print(s + ans_d[m])

Solution (Python):
def main():
    n,m=map(int,input().split())
    l=[tuple(map(int,input().split())) for _ in range(m)]
    py=sorted(l, key=lambda x: (x[0],x[1]))
    d={}
    i = 1
    prev=0
    for p,y in py:
        if prev != p:
            i = 1
            prev = p
        d[(p,y)] = "{:0>6}".format(p)+"{:0>6}".format(i)
        i += 1
    for x in l:
        print(d[x])

if __name__ == "__main__":
    main()

Solution (Python):
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
b = [[] for _ in range(n+1)]
for i in range(m):
    b[a[i][0]].append((a[i][1],i+1))

for i in range(1,n+1):
    b[i].sort()
ans = ["."]*m
for i in range(1,n+1):
    for j in range(len(b[i])):
        ans[b[i][j][1]-1] = "0"*(6-len(str(i))) + str(i) + "0"*(6-len(str(j+1))) + str(j+1)
print(*ans, sep="\n")

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

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

t = 1
tmp = sorted(lis)[0][0]

nlis =[]

for i in sorted(lis):
    if tmp == i[0]:
        left = str(i[0]).zfill(6)
        right = str(t).zfill(6)
        t += 1
    else:
        t = 1
        tmp = i[0]
        left = str(i[0]).zfill(6)
        right = str(t).zfill(6)
        t += 1
    
    nlis.append([i[2],left+right])

for j in sorted(nlis):
    print(j[1])

Solution (Python):
import bisect
N, M = map(int, input().split())
l_1 = [[] for i in range(N+1)]
l_2 = []
for i in range(M):
  p, y = map(int, input().split())
  l_1[p].append(y)
  l_2.append([p, y])
  
for i in range(N+1):
  l_1[i].sort()
    
for i in range(M):
  c = l_2[i]
  n = bisect.bisect_left(l_1[c[0]], c[1]) + 1
  ans = str(c[0]).zfill(6) + str(n).zfill(6)
  print(ans)

Solution (Python):
def resolve():
    '''
    code here
    '''
    N, M = [int(item) for item in input().split()]
    PY = [[int(item) for item in input().split()] for _ in range(M)]

    memo = [[] for _ in range(N+1)]

    for p, y in PY:
        memo[p] += [y]

    res_list = []
    for lst in memo:
        lst.sort()
        temp_dic = dict(zip(lst, range(1,len(lst)+1)))
        res_list.append(temp_dic)

    for p, y in PY:
        pi = str(p).zfill(6)
        x = str(res_list[p][y]).zfill(6)
        print(pi+x)


if __name__ == "__main__":
    resolve()

Solution (Python):
N, M = map(int,input().split())
pyi = [[] for n in range(N)]
for i in range(M):
    p, y = map(int,input().split())
    pyi[p-1].append([y,i])
    


ans = []
for i in range(N):
    pyi[i].sort()  
    for j in range(len(pyi[i])): 
        ans.append([(6-len(str(i+1)))*"0" + str(i+1) + (6-len(str(j+1)))*"0" + str(j+1),pyi[i][j][1]])
        
ans.sort(key=lambda x:x[1])
for m in range(M):
    print(ans[m][0])

Solution (Python):
from collections import defaultdict
import bisect

pre = defaultdict(list)
ori = []
n, m = map(int, input().split())
for _ in range(m):
    x, y = map(int, input().split())
    pre[x].append(y)
    ori.append([x, y])

for key, val in pre.items():
    val.sort()

for i in range(m):
    l = pre[ori[i][0]]
    idx = bisect.bisect(l, ori[i][1])
    print(f'{ori[i][0]:06}{idx:06}')

Solution (Python):
import bisect
N,M = map(int,input().split())
A = [[] for _ in range(N)] 
original = []
for i in range(M):
  a,b = map(int,input().split())
  a-=1 
  A[a].append(b)
  original.append((a,b))
for X in A:
  X.sort()

for i in range(M):
  ken,now = original[i]
  ID = bisect.bisect_left(A[ken],now)
  ken += 1; ID+=1
  ans = "0"*(6-len(str(ken)))+str(ken)+"0"*(6-len(str(ID)))+str(ID)
  print(ans)

Solution (Python):
"""
M <= 10 ** 5
なので全探索しても間に合いそう。
"""
N, M = map(int, input().split())
input_li = []   
p_dict = {}     
ans_dict = {}   


for _ in range(M):
    p, y = map(int, input().split())
    input_li.append([p, y])
    if p not in p_dict:
        li = [y]
        p_dict[p] = li
    else:
        p_dict[p].append(y)


for p in p_dict:
    li = sorted(p_dict[p])
    ans_dict[p] = {}
    for i in range(len(li)):
        p_id = '0' * (6 - len(str(p))) + str(p)
        c_id = '0' * (6 - len(str(i + 1))) + str(i + 1)
        ans_dict[p][li[i]] = p_id + c_id


for p, y in input_li:
    print(ans_dict[p][y])

Solution (Python):
N, M = map(int, input().split())
input_li = []
p_dict = {}
ans_dict = {}
for _ in range(M):
    p, y = map(int, input().split())
    input_li.append([p, y])
    if p not in p_dict:
        s = [y]
        p_dict[p] = s
    else:
        p_dict[p].append(y)
for p in p_dict:
    li = sorted(p_dict[p])
    ans_dict[p] = {}
    for i in range(len(li)):
        p_id = '0' * (6 - len(str(p))) + str(p)
        c_id = '0' * (6 - len(str(i + 1))) + str(i + 1)
        ans_dict[p][li[i]] = p_id + c_id
for p, y in input_li:
    print(ans_dict[p][y])

Solution (Python):
def pad(n):
  n = str(n)
  n = '0'*(6-len(n))+n
  return n

N,M=map(int,input().split())
py = [tuple(map(int,input().split())) for _ in range(M)]

py = sorted(enumerate(py),key=lambda x: x[1])

pref=0
count=0
new_py = []
for i in range(M):
  j,(p,y)=py[i]
  if p==pref:
    count += 1
  else:
    count = 1
  new_py.append((j,pad(p)+pad(count)))
  pref = p
  
new_py = sorted(new_py)
for i in range(M):
  print(new_py[i][1])

Solution (Python):
N,M = list(map(int,input().split()))
PY = []
for i in range(M):
    PY.append(list(map(int,input().split())))
    PY[-1].append(i)

PY_sorted = sorted(PY, key=lambda x: x[1])
PY_sorted2 = sorted(PY_sorted, key=lambda x: x[0])

PY = PY_sorted2
p = 0
y = 1
for i in range(M):
    if p != PY[i][0]:
        y = 1
    p = PY[i][0]
    identityString = str(PY[i][0]).zfill(6) + str(y).zfill(6)
    PY[i].append(identityString)
    y += 1

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

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

Solution (Python):
from bisect import bisect_left as bt
n,m = map(int,input().split())
dm,ct = [[] for _ in range(n+1)],[]
for _ in range(m):
  a,b = map(int,input().split())
  dm[a].append(b); ct.append((a,b))
for i in range(1,n+1):
  dm[i].sort()
for c in ct:
  v,f = str(c[0]),str(bt(dm[c[0]],c[1])+1)
  print('0'*(6-len(v))+v+'0'*(6-len(f))+f)

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

arr = [[] for _ in range(n)] 

p = [0] * m
y = [0] * m

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

for i in range(n):
    arr[i].sort()

import bisect
for i in range(m):
    num = bisect.bisect_left(arr[p[i]-1], y[i]) + 1
    a = str(p[i])
    b = str(num)
    print(a.zfill(6) + b.zfill(6))

Solution (Python):
n,m = map(int,input().split())
py = [list(map(int,input().split())) for i in range(m)]
c = [0]*n
sort_py = sorted(py,key=lambda x:x[1])
ans = dict()
for p,y in sort_py:
    c[p-1] += 1
    ans[p,y] = str(p).zfill(6)+str(c[p-1]).zfill(6)

for p,y in py:
    print(ans[p,y])

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

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

ans = []
for p, l in dic.items():
    l.sort()
    for i, x in enumerate(l):
        ans.append([x[1], str(p).zfill(6) + str(i + 1).zfill(6)])
ans.sort()

for x in ans:
    print(x[1])

Solution (Python):
N,M = map(int, input().split())
P = [list(map(int, input().split())) for m in range(M)]
C = (N+1)*[0]
D = {}

for p,y in sorted(P,key=lambda x: x[1]):
  C[p]+= 1
  D[y]="%06d%06d" % (p,C[p])

for p,y in P:
  print(D[y])

Solution (Python):
N,M = (int(T) for T in input().split())
List = [[] for T in range(0,M)]
for T in range(0,M):
    List[T] = [T]+[int(T) for T in input().split()]

CitySort = sorted(List,key=lambda List:(List[1],List[2]))
Disp = [[] for T in range(0,M)]
Rece = 0
for T in range(0,M):
    if CitySort[T][1]!=Rece:
        Rece = CitySort[T][1]
        Count = 1
        Disp[CitySort[T][0]] = str(Rece).zfill(6)+str(Count).zfill(6)
    else:
        Count += 1
        Disp[CitySort[T][0]] = str(Rece).zfill(6)+str(Count).zfill(6)
        
for T in range(0,M):
    print(Disp[T])

Solution (Python):
from bisect import bisect_left 
n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)]

k = [[] for i in range(n)]
for j,h in l:
  k[j-1].append(h)
k_so = [[] for i in range(n)]
for i in range(n):
  a = k[i]
  k_so[i] = sorted(a)

for j,h in l:
  first = "{:0=6}".format(j)
  t = bisect_left(k_so[j-1], h)
  second = "{:0=6}".format(t+1)
  print(first+second)

Solution (Python):
N,M = map(int,input().split())
ls = []
for i in range(M):
    P,Y = map(int,input().split())
    ls.append([P,Y,i])
ls.sort()
num = 1
city = ls[0][0]
for i in range(M):
    if ls[i][0] == city:
        ls[i][1] = num
        num += 1
    else:
        num = 1
        ls[i][1] = num
        city = ls[i][0]
        num += 1
ls.sort(key=lambda x:x[2])
for i in range(M):
    print('{0:06d}'.format(ls[i][0])+'{0:06d}'.format(ls[i][1]))

Solution (Python):
n,m=map(int,input().split())
import bisect
l=[[] for _ in range(n)]
l2=[]

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

for m in l:
  m.sort()
for m in l2:
  print("{:06d}".format(m[0]) +"{:06d}".format(bisect.bisect_left(l[m[0]-1],m[1])+1))

Solution (Python):
n,m=map(int,input().split())
import bisect
l=[[] for _ in range(n)]
l2=[]

for i in range(m):
  p,y=map(int,input().split())
  bisect.insort_left(l[p-1],y)
  l2.append([p,y])

for m in l2:
  print("{:06d}".format(m[0]) +"{:06d}".format(bisect.bisect_left(l[m[0]-1],m[1])+1))

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

V = [[] for _ in range(N)]
for i in range(M):
    p, y = map(int, input().split())
    V[p-1].append((y, i))

ans = [0] * M
for i, v in enumerate(V, start=1):
    v.sort()
    for j, (y, k) in enumerate(v, start=1):
        ans[k] = format(str(i), "0>6") + format(str(j), "0>6")

for a in ans:
    print(a)

Solution (Python):
from collections import defaultdict

N, M = map(int, input().split())
iPY = []
D = defaultdict(list)
E = defaultdict(int)

for i in range(M):
  P, Y = map(int, input().split())
  iPY.append((i, P, Y))

iPY.sort(key = lambda x: x[2])

for i, P, Y in iPY:
  D[P].append(Y)

for P, Ys in D.items():
  for i, Y in enumerate(Ys):
    E[Y] = "000000"+str(i+1)

iPY.sort()

for i, P, Y in iPY:
  U = "000000"+str(P)
  L = E[Y]
  print(U[-6:]+L[-6:])

Solution (Python):
N, M = map(int, input().split())
V = [[] for _ in range(N)]
ans = [0] * M

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

for i, v in enumerate(V, start=1):
    v.sort()
    for k, (y, j) in enumerate(v, start=1):
        ans[j] = format(str(i), "0>6") + format(str(k), "0>6")

for a in ans:
    print(a)

Solution (Python):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n, m = map(int, input().split())
    from bisect import insort_left as il
    pref = [[] for _ in range(n)]
    for i in range(m):
        p, y = map(int, input().split())
        p -= 1
        il(pref[p], (y, i))
    
    def tostr(x):
        return '0'*(6-len(str(x+1)))+str(x+1)

    ans = [0]*m    
    for i in range(n):
        x = pref[i]
        for j in range(len(x)):
            ans[x[j][1]] = tostr(i)+tostr(j)
    
    for x in ans:
        print(x)

    
if __name__ == '__main__':
    main()

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi



import string

from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    
    n, m = [int(x) for x in input().split()]
    ans = [0] * m
    a = defaultdict(list)
    for i in range(m):
        p, y = [int(x) for x in input().split()]
        a[p].append((y, i))

    for p in a:
        r = a[p]
        r.sort()
        for x, (y, i) in enumerate(r):
            ans[i] = f'{p:06}{x+1:06}'
    for r in ans:
        print(r)

t = 1

for case in range(1,t+1):
    ans = solve()


"""
a b a
d c d
a b a
"""

Solution (Python):
n,m=map(int,input().split())
py1=[]
for i in range(m):
    py1.append(list(map(int,input().split()))+[i+1])
py=sorted(py1)

number_list=[]
number_list.append([str(0)]*(6-(len(list(str(py[0][0])))))+list(str(py[0][0]))+[str(0)]*(6-(len(list(str(1)))))+list(str(1))+[str(py[0][-1])])
k=2
for j in range(1,m):
    if py[j][0]==py[j-1][0]:
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str((py[j][-1]))])    
        k+=1
    else:
        k=1
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str(py[j][-1])])
        k+=1
     
number_list_sort=sorted(number_list,key=lambda x:int(x[-1]))
for l in range(m):
    print(''.join(number_list_sort[l][:-1]))

Solution (Python):

import sys
input = sys.stdin.readline  
Ken_n,City_n = (int(i) for i in input().split())
city ={i:[] for i in range(1,Ken_n+1)}
for i in range(1,City_n+1):
    p,y = (int(i) for i in input().split())
    city[p].append((y,i))

city_ID ={i:0 for i in range(1,City_n +1)}
for i in range(1,Ken_n +1):
    city[i].sort()
    
    for j in range(len(city[i])):
        city_ID[city[i][j][1]] = "{0:06d}".format(i) +"{0:06d}".format(j+1)

for i in range(1,City_n +1):
    print(city_ID[i])

Solution (Python):
import bisect

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

dic = [[0] for i in range(n+1)]
city = []
for i in range(m):
    p,y = map(int,input().split())
    city.append((p,y))
    idx = bisect.bisect_left(dic[p],y)
    dic[p].insert(idx,y)

num = "000000"
for i in city:
    p,y = i[0],i[1]
    if len(str(p)) < 6:
        kami = num[:6-len(str(p))] + str(p)
    else:
        kami = str(p)
    simo = bisect.bisect_left(dic[p],y)
    if len(str(simo)) < 6:
        simo = num[:6-len(str(simo))] + str(simo)
    else:
        simo = str(simo)
    print(kami + simo)

Solution (Python):
n, m = map(int, input().split())
PY = [list(map(int, input().split())) + [i] for i in range(m)]
PY = sorted(PY, key=lambda x: x[1])
PC = [1] * (n+1)

anss = []
for p, y, i in PY:
    anss.append((i, p, PC[p]))
    PC[p] += 1
anss = sorted(anss, key=lambda x: x[0])
for i, p, c in anss:
    print('{:06}{:06}'.format(p, c))

Solution (Python):
import copy
from collections import defaultdict

N, M = map(int, input().split())
org_arr = [list(map(int, input().split())) for _ in range(M)]
arr = copy.copy(org_arr)
arr.sort(key=lambda x:x[1])
arr.sort(key=lambda x:x[0])

count = 1
dic = {}
for i in range(len(arr)):
    dic[arr[i][1]] = count
    if i == len(arr)-1:
        break
    if arr[i][0] == arr[i+1][0]:
        count += 1
    else:
        count =1


for i in org_arr:
    ans = str(i[0]).zfill(6)+str(dic[i[1]]).zfill(6)
    print(ans)

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



PY = []



Y_to_i = dict()

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


PY.sort()

ID_list = [""] * M

temp_p = PY[0][0]

idx = 1

for p, y in PY:

    
    if p != temp_p:
        idx = 1

    
    temp_p = p

    
    ID_list[Y_to_i[y]] = str(p).zfill(6) + str(idx).zfill(6)

    
    idx += 1


for a in ID_list:
    print(a)

Solution (Python):
import sys
import math
from collections import deque
import heapq as hq

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, M = NMI()
    C = [[0, 0, 0]] + [[i+1]+NLI() for i in range(M)]
    D = {i: [] for i in range(N+1)}
    names = {}
    for c in C[1:]:
        D[c[1]].append([c[2], c[0]])
    for p, YI in D.items():
        YI.sort()
        t = 1
        for y, i in YI:
            names[i] = str(p).zfill(6) + str(t).zfill(6)
            t += 1
    for i in range(1, M+1):
        print(names[i])



if __name__ == "__main__":
    main()

Solution (Python):
from heapq import heappush, heappop
n,m=map(int,input().split())
data=[]
pn=[0 for _ in range(n)]
for i in range(m):
  p,y=map(int,input().split())
  heappush(data,(y,p,i))
data2=[]
while data:
  y,p,i=heappop(data)
  pn[p-1]+=1
  cid=str(p).zfill(6)+str(pn[p-1]).zfill(6)
  data2.append((i,cid))
for i,cid in sorted(data2):
  print(cid)

Solution (Python):
N, M = map(int,input().split())
array = []
dic = {}
for i in range(M):
    p, y = map(int,input().split())
    array.append((p,y))
    dic[y]=i
array.sort()
ans = ['']*M
now_p = array[0][0]
idx = 1
for p, y in array:
    if p != now_p:
        idx = 1
    now_p = p
    ans[dic[y]]=str(p).zfill(6)+str(idx).zfill(6)
    idx+=1
for a in ans:
    print(a)

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

sortpy = sorted(pyo, key=lambda x:x[1])

yy = [0]*(n+1)
ans = [""]*m
for i, j, k in sortpy:
    pp = str(i).zfill(6)
    yy[i] += 1
    ans[k] = pp + str(yy[i]).zfill(6)

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

Solution (Python):
N, M = map(int, input().split())
PY = []
Y_to_i = dict()
for i in range(M):
    p, y = map(int, input().split())
    PY.append((p, y))
    Y_to_i[y] = i
PY.sort()
ans = [""]*M
now_p = PY[0][0]
idx = 1
for p, y in PY:
    if p != now_p:
        idx = 1
    now_p = p
    ans[Y_to_i[y]] = str(p).zfill(6) + str(idx).zfill(6)
    idx += 1
for a in ans:
    print(a)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, m = LI()
lst = [[] for _ in range(n)]

for i in range(m):
    p, y = LI()
    lst[p-1].append([y, i])

for i in lst:
    i.sort()

ans = []
for i in range(n):
    for idx, [j, k] in enumerate(lst[i]):
        s = "0" * 6 + str(i+1)
        s = s[-6:]
        t = "0" * 6 + str(idx+1)
        t = t[-6:]
        ans.append([k, s+t])
ans.sort()
for i, j in ans:
    print(j)

Solution (Python):


import sys

def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    y_dict = {}
    ken_dict = {}
    for i in range(m):
        p_i, y_i = map(int, input().split())
        y_dict[y_i] = []
        y_dict[y_i].append(p_i)

        if not p_i in ken_dict:
            ken_dict[p_i] = []
            ken_dict[p_i].append(y_i)
        else:
            ken_dict[p_i].append(y_i)


    for key in ken_dict.keys():
        ken_dict[key].sort()
        for i,value in enumerate(ken_dict[key]):
            i += 1
            y_dict[value].append(i)
    
    for value in y_dict.values():
        print(str(value[0]).zfill(6) + str(value[1]).zfill(6))
    
    return


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline()).split())

n,m=nii()

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

for i in range(m):
  p,y=nii()
  list[p].append([y,i])

ans=[]
for i in range(1,n+1):
  tl=list[i]
  s_tl=sorted(tl,key=lambda x:x[0])
  for j in range(len(tl)):
    town=s_tl[j][1]
    s1=str(i).zfill(6)
    s2=str(j+1).zfill(6)
    s=s1+s2
    ans.append([town,s])

ans.sort(key=lambda x:x[0])
for i,j in ans:
  print(j)

Solution (Python):
n,m=map(int,input().split())
city=[[0,0,0,0] for _ in range(m)]
for i in range(m):
    p,y=map(int,input().split())
    city[i][0]=p
    city[i][1]=y
    city[i][2]=i
city=sorted(city, key=lambda x:(x[0], x[1]))

cnt=1
for j in range(m):
    ans=''
    ans+='{:06}'.format(city[j][0])
    ans+='{:06}'.format(cnt)
    city[j][3]=ans
    if j==m-1:
        continue
    elif city[j][0]==city[j+1][0]:
        cnt+=1
    else:
        cnt=1
city=sorted(city, key=lambda x:(x[2]))
for k in range(m):
    print(city[k][3])

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

PY.sort()

pnow = PY[0][0]
c = 1

ans = [-1 for i in range(M)]

for i in range(M):
    if pnow != PY[i][0]:
        c = 1
        pnow = PY[i][0]
    ans[PY[i][2]] = str(PY[i][0]).zfill(6) + str(c).zfill(6)
    c += 1

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

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

PY.sort()

pnow = PY[0][0]
c = 1

ans = [-1 for i in range(M)]

for i in range(M):
    if pnow != PY[i][0]:
        c = 1
        pnow = PY[i][0]
    ans[PY[i][2]] = str(PY[i][0]).zfill(6) + str(c).zfill(6)
    c += 1

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

Solution (Python):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

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

PY = [list(map(int,readline().split())) + [i] for i in range(M)]

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

ans = [None]*M
nowp = 1
cnt = 1
for i in range(M):
    if PY[i][0] != nowp:
        cnt = 1
        nowp = PY[i][0]
    ans[PY[i][2]] = [nowp,cnt]
    cnt += 1

for i in range(M):
    print(str(ans[i][0]).zfill(6) + str(ans[i][1]).zfill(6))

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
lis = [[] for _ in range(N)]

plis = []
for _ in range(M):
    p, y = mapint()
    lis[p-1].append(y)
    plis.append((p, y))

for i in range(N):
    lis[i].sort()
    
from bisect import bisect_left
for p, y in plis:
    idx = bisect_left(lis[p-1], y)
    print('{:06}{:06}'.format(p, idx+1))

Solution (Python):
N, M = map(int,input().split())
py = []
for i in range(M):
  py.append(list(map(int,input().split())))
  py[i].append(i)
sorted_py = sorted(py, key=lambda x: x[1])
P = [0]*N
p_num = 0
num = 0
output = ''
output2 = []
outputs = []
for i in range(M):
  P[sorted_py[i][0]-1] += 1
  p_num = sorted_py[i][0]
  num = P[sorted_py[i][0]-1]
  output = str(p_num).zfill(6) + str(num).zfill(6)
  output2 = [output, sorted_py[i][2]]
  outputs.append(output2)
sorted_outputs = sorted(outputs, key=lambda x: x[1])
for out in sorted_outputs:
  print(out[0])

Solution (Python):
from collections import defaultdict
dic = defaultdict(int)
N,M = map(int,input().split())
A = []
for i in range(M):
  a,b = map(int,input().split())
  A.append((a,b,i))
A.sort()

ans = [-1 for _ in range(M)]
for i in range(M):
  dic[A[i][0]] += 1
  
  temp = "0"*(6-len(str(A[i][0])))+str(A[i][0])+"0"*(6-len(str(dic[A[i][0]])))+str(dic[A[i][0]])
  ans[A[i][2]] = temp
  
for t in ans:
  print(t)

Solution (Python):
def main():
    N, M = (int(i) for i in input().split())
    PY = [([int(i) for i in input().split()], j) for j in range(M)]
    dic = {i: [] for i in range(N)}  
    A = sorted(PY, key=lambda p: p[0][1])
    for py, i in A:
        dic[py[0]-1].append(i)

    ans = []
    for p in range(N):  
        for x, i in enumerate(dic[p], start=1):
            
            upper = "{:>06}".format(str(PY[i][0][0]))
            lower = "{:>06}".format(str(x))
            ans.append((upper+lower, i))
    ans.sort(key=lambda p: p[1])
    for a, _ in ans:
        print(a)


if __name__ == '__main__':
    main()

Solution (Python):
def solve():
  N, M = map(int, input().split())
  A = [list(map(int, input().split()))+[i] for i in range(M)]

  A.sort(key=lambda x:(x[0],x[1]))
  ans = [0]*M
  before = -1
  for p,y,i in A:
    if p!=before:
      year = 1
    else:
      year += 1
    ans[i] = '0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(year)))+str(year)
    before = p
  return ans
print(*solve(),sep='\n')

Solution (Python):
n,m=map(int,input().split())
e=[[]for _ in range(n)]
py=[]
for _ in range(m):
  p,y=map(int,input().split())
  py.append((p,y))
  e[p-1].append(y)
for i in range(n):e[i].sort()
xy=lambda x,y:y*1000000+x
d={}
for i in range(n):
  for j in range(len(e[i])):
    d[xy(i+1,e[i][j])]=str(i+1).zfill(6)+str(j+1).zfill(6)
for p,y in py:
  print(d[xy(p,y)])

Solution (Python):
import bisect

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

li = [[] for _ in range(n+1)]
num = []

for _ in range(m):
    p,y = map(int,input().split())
    li[p].append(y)
    num.append((p,y))

for i in range(n+1):
    li[i].sort()

for i,j in num:
    print(str(i).zfill(6)+str(bisect.bisect_left(li[i],j)+1).zfill(6))

Solution (Python):
import bisect

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

li = [[] for _ in range(n+1)]
num = []

for _ in range(m):
    p,y = map(int,input().split())
    li[p].append(y)
    num.append((p,y))

for i in range(n+1):
    li[i].sort()

for i,j in num:
    print(str(i).zfill(6)+str(bisect.bisect_left(li[i],j)+1).zfill(6))

Solution (Python):
n, m = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(m)]
pysort = sorted(py, key=lambda val: val[1])

pcnt, ans_d = [0] * (10 ** 5 + 1), {}
for i, j in pysort:
    pcnt[i] += 1
    ans_d[j] = str(pcnt[i])

for i, j in py:
    print(str(i).zfill(6) + ans_d[j].zfill(6))

Solution (Python):
import bisect
import collections
N,M = map(int, input().split())
q = [[int(j) for j in input().split()] for i in range(M)]
li = collections.defaultdict(list)

for i,j in sorted(q):
    li[i].append(j)

for p,y in q:
    z = bisect.bisect(li[p],y)
    print("{:0=6}".format(p) + "{:0=6}".format(z))

Solution (Python):
import bisect
N,M = map(int, input().split())
q = [[int(j) for j in input().split()] for i in range(M)]
li = [[] for k in range(N+1)]

for i,j in sorted(q):
    li[i].append(j)

for p,y in q:
    z = bisect.bisect(li[p],y)
    print("{:0=6}".format(p) + "{:0=6}".format(z))

Solution (Python):
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
p = [[i]+LIST() for i in range(m)]
q = [0]*(n+1)

p.sort(key=itemgetter(2))
for x in p:
    q[x[1]] += 1
    x.append(q[x[1]])

p.sort(key=itemgetter(0))
for x in p:
    print(str(x[1]).zfill(6)+str(x[3]).zfill(6))