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):
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])

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))

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
input = sys.stdin.readline

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

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


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


ans = [0] * M

count = 0
tmp = 0 
for p, y, i in lst:
    if tmp == p:
        count += 1
    else:
        count = 1
        tmp = p
    tmp_ans = str(p).zfill(6) + str(count).zfill(6)
    ans[i] = tmp_ans

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

Solution (Python):
from operator import itemgetter


n, m = map(int, input().split())
info = [list(map(int, input().split())) + [i] for i in range(m)]

info = sorted(info, key=itemgetter(1))
ans = [0] * m

cnt_ind = [1] * (n + 1)
for i in range(m):
    p, y, ind = info[i]
    cnt = cnt_ind[p]
    cnt_ind[p] += 1
    ans[ind] = ("0000000"+str(p))[-6:] + ("0000000"+str(cnt))[-6:]
for i in ans:
    print(i)

Solution (Python):
n,m =map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
for i in range(m):
    lis[i].append(i)
lis.sort()
cnt = 1
ans = []
ans.append([lis[0][-1],format(lis[0][0]).zfill(6)+format(1).zfill(6)])
for i in range(m-1):
    if lis[i][0] == lis[i+1][0]:
        cnt += 1
        ans.append([lis[i+1][-1],format(lis[i+1][0]).zfill(6)+format(cnt).zfill(6)])
    else:
        cnt = 1
        ans.append([lis[i+1][-1],format(lis[i+1][0]).zfill(6)+format(cnt).zfill(6)])
ans.sort(key = lambda x:x[0])
for i,x in ans:
    print(x)

Solution (Python):
def main():
    n, m = map(int, input().split())
    group = {i: [] for i in range(1, n + 1)}
    for i in range(m):
        p, y = map(int, input().split())
        group[p].append([y, i])
    answer = ["" for _ in range(m)]
    for i in range(1, n + 1):
        group[i].sort(key=lambda x: x[0])
    for i in range(1, n + 1):
        for j, yi in enumerate(group[i]):
            y, k = yi
            answer[k] = str(i).zfill(6) + str(j + 1).zfill(6)
    print("\n".join(answer))


if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
def solve(N,M):
    pref = [[] for _ in range(N)]
    P = [0]*M
    Y = [0]*M
    for i in range(M):
        P[i],Y[i] = map(int, input().split())
        pref[P[i]-1].append(Y[i])
    for i in range(N):
        pref[i].sort()
    ans = []
    for i in range(M):
        ind = bisect_left(pref[P[i]-1],Y[i])
        ans.append('0'*(6-len(str(P[i])))+str(P[i])+'0'*(6-len(str(ind+1)))+str(ind+1))
    return ans
print(*solve(N,M),sep='\n')

Solution (Python):
N,M=map(int, input().split())
PY=[tuple(map(int, input().split()))for _ in range(M)]
ans=[None]*M
I=sorted(range(M),key=lambda i: PY[i][1])
C=[0]*(N+1)
for i in I:
    p=PY[i][0]
    C[p]+=1
    ans[i]=(p,C[p])
def f(x):
    s=str(x)
    return "0"*(6-len(s))+s
for p,c in ans:
    print(f(p)+f(c))

Solution (Python):
N,M = map(int,input().split())
PY = [tuple(map(int,input().split())) for i in range(M)]
ypi = sorted((y,p,i) for i,(p,y) in enumerate(PY))

from collections import defaultdict
d = defaultdict(lambda: 0)
ans = [None] * M
for y,p,i in ypi:
    d[p] += 1
    ans[i] = str(p).zfill(6) + str(d[p]).zfill(6)
print(*ans, sep='\n')

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

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

for i in range(N):
    dic[i].sort()

for j in range(M):
    p, y = shi[j]
    print('{:06}{:06}'.format(p, bisect_right(dic[p-1], y)))

Solution (Python):
f=lambda:map(int,input().split())
_,m=f()
d,t,c={},0,0
for p,y,i in sorted(list(f())+[i] for i in range(m)):
  if p>t: t,c=p,1
  else: c+=1
  d[i]=str(p).zfill(6)+str(c).zfill(6)
for _,v in sorted(d.items()): print(v)

Solution (Python):
import sys
f=lambda:map(int,sys.stdin.readline().split())
_,m=f()
d,t,c={},0,0
for p,y,i in sorted(list(f())+[i] for i in range(m)):
  if p>t: t,c=p,1
  else: c+=1
  d[i]=str(p).zfill(6)+str(c).zfill(6)
for _,v in sorted(d.items()): print(v)

Solution (Python):
import sys
f=lambda:map(int,sys.stdin.readline().split())
n,m=f()
lt=[]
for i in range(m):
  p,y=f()
  lt+=[(p,y,i)]
lt.sort()
d={}
t=c=0
for p,y,i in lt:
  if p>t: t,c=p,1
  else: c+=1
  d[i]=str(p).zfill(6)+str(c).zfill(6)
for _,v in sorted(d.items()): print(v)

Solution (Python):
N, M = map(int,input().split())
Cities = []
for _ in range(M):
    Cities.append(list(map(int,input().split())))
L = [[] for i in range(N+1)]
for P, Y in Cities:
    L[P].append(Y)
for i in range(N+1):
    L[i].sort()
D = [{} for _ in range(N+1)]
for i in range(1, N+1):
    for val, key in enumerate(L[i], 1):
        D[i][key] = val

for P, Y in Cities:
    left = str(P).zfill(6)
    right = str(D[P][Y]).zfill(6)
    print(left + right)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


def numberlize(n):
    k="000000"
    u=6-len(str(n))
    return k[0:u]+str(n)

    
    
n,m=MI()
lis=[[]for i in range(n)]
for i in range(m):
    a,b=MI()
    lis[a-1].append([i+1,b])

for j in range(n):
    lis[j]=sorted(lis[j],key=lambda x:x[1])
    for k in range(len(lis[j])):
        lis[j][k][1]=k+1


ans=[0 for i in range(m)]
for j in range(n):
    for s in lis[j]:
        ans[s[0]-1]=[j+1,s[1]]

for a in ans:
    print(numberlize(a[0])+numberlize(a[1]))

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

def resolve():
    N,M=pin()
    PY=[[]for i in range(N)]
    
    for m in range(M):
        p,y=pin()
        PY[p-1].append([y,m])
    
    ANS=[]
    for i in range(N):
        PY[i].sort(key=lambda x:x[0])
        for n,py in enumerate(PY[i]):
            py[0]=n+1
            ANS.append([i+1]+py)
    
    ANS.sort(key=lambda x:x[2])
    
    
    
    PY=ANS
    for k in range(M):
        x,y,z=PY[k]
        X,Y=str(x),str(y)
        t,s=6-len(X),6-len(Y)
        if t>0:
            X="0"*t+X
        if s>0:
            Y="0"*s+Y
        print(X+Y)


resolve()

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

now = q[0][0]
cou = 1
for a , b , c in q:
    if now != a:
        now = a
        cou = 1
        ans[c] = str(a).rjust(6,'0') + str(cou).rjust(6,'0')
        cou += 1
    elif now == a:
        ans[c] = str(a).rjust(6,'0') + str(cou).rjust(6,'0')
        cou += 1
        
for i in ans:
    print(i)

Solution (Python):
import bisect
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    N, M = map(int, input().split())
    d = [[] for _ in range(N + 1)]
    PY = []
    for _ in range(M):
        p, y = map(int, input().split())
        d[p].append(y)
        PY.append((p, y))

    for i in range(N + 1):
        if not d[i]:
            continue
        d[i] = sorted(set(d[i]))

    for p, y in PY:
        order = bisect.bisect_left(d[p], y)
        print(str(p).zfill(6) + str(order + 1).zfill(6))


if __name__ == "__main__":
    main()

Solution (Python):
n,m = map(int,input().split())
py = []
p_y = [[] for i in range(n)]
for _ in range(m):
    p,y = map(int,input().split())
    py.append((p,y))
    p_y[p-1].append(y)
ans = {}
for i, tmp in enumerate(p_y):
    cnt = 1
    p_y[i] = tmp.sort()
    for j, jj in enumerate(tmp):
 
        ans[(i+1, jj)] = str(i+1).zfill(6) + str(j+1).zfill(6)
 
 
for i, tmp in enumerate(py):
    print(ans[tmp])

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

citys = []
for i in range(m):
    p, y = map(int, input().split())
    citys.append([p, y, i])
    
citys.sort(key=lambda x: x[1])
citys.sort()

ans = [[str("{:06}".format(citys[0][0])) + str("{:06}".format(1)), citys[0][2]]]
num = 2
for i in range(1, m):
    if citys[i - 1][0] != citys[i][0]:
        num = 1
    
    ans.append([str("{:06}".format(citys[i][0])) + str("{:06}".format(num)), citys[i][2]])
    
    num += 1

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

Solution (Python):
n,m = map(int,input().split())
py = []
for i in range(m):
    num = i+1
    p,y = map(int,input().split())
    py.append([num,p,y])
py = sorted(py, key = lambda x:x[1]*10**10+x[2])
x = 0
b = '000000'
ans = []
for pyi in py:
    if pyi[1] != x:
        x = pyi[1]
        cnt = 1
    else:
        cnt += 1
    ans.append([pyi[0], (b+str(pyi[1]))[-6:], (b+str(cnt))[-6:]])
ans = sorted(ans, key = lambda x: x[0])
for ansi in ans:
    print(ansi[1]+ansi[2])

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

ans = [None]*M  
for p,iys in enumerate(piys):  
    iys.sort()  
    for k,(y,i) in enumerate(iys):  
        ans[i] = "%06d%06d" % (p+1,k+1)  

for i in ans:  
    print(i)

Solution (Python):
import bisect
inf = 10**15
mod = 10**9+7
n, m = map(int, input().split())
ken = [[] for i in range(n)]
py = [list(map(int, input().split())) for i in range(m)]
for i in range(m):
    p, y = py[i]
    ken[p-1].append(y)
for tmp in ken:
    tmp.sort()
for i in range(m):
    p, y = py[i]
    ind = bisect.bisect_left(ken[p-1], y)
    print('{ans:06}{anse:06}'.format(ans=p, anse=ind+1))

Solution (Python):
N, M = map(int, input().split())
city = [[] for _ in range(N + 1)]
for i in range(M):
    p, y = map(int, input().split())
    city[p].append([y, i + 1])
ans = [-1 for _ in range(M + 1)]
for k in range(1, N + 1):
    tmp = city[k]
    if len(tmp) > 0:
        for j, t in enumerate(sorted(tmp)):
            name = str(k).zfill(6) + str(j + 1).zfill(6)
            ans[t[1]] = name
print("\n".join(ans[1:]))

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

py.sort()

strr=[""]*m
pyi=0
for i in range(m):
    if py[i][0]==pyi:
        strp=str(py[i][0])
        strq="0"*(6-len(strp))+strp        
        qi+=1
        strp=str(qi)
        strq=strq+"0"*(6-len(strp))+strp
    else:
        strp=str(py[i][0])
        pyi=py[i][0]
        strq="0"*(6-len(strp))+strp        
        qi=1
        strp=str(qi)
        strq=strq+"0"*(6-len(strp))+strp
    strr[py[i][2]]=strq

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

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[0], x[1]))
k=1
PY[0][1]=k
for i in range(1,M):
  if PY[i][0]!=PY[i-1][0]:
    k=1
  else:
    k+=1
  PY[i][1]=k
PY = sorted(PY, key=lambda x:x[2])
for p,y,_ in PY:
  print('{0:06}{1:06}'.format(p,y))

Solution (Python):
from operator import itemgetter, attrgetter

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

pym = [None] * m
for i in range(m):
    pym[i] = [i] + list(map(int, input().split(' ')))

pyms = sorted(pym, key=itemgetter(1, 2))

x = 1
pyms[0].append(x)

for i in range(1, m):
    if pyms[i - 1][1] != pyms[i][1]:
        x = 1
    else:
        x += 1
    pyms[i].append(x)
    
pym = sorted(pyms, key=itemgetter(0, ))

for i in range(m):
    city_id = str(pym[i][1]).zfill(6) + str(pym[i][3]).zfill(6)
    print(city_id)

Solution (Python):
N,M=map(int,input().split())
A=[]
for i in range(M):
    P,Y=map(int,input().split())
    A.append([P,Y,i])
A.sort()
a=str(A[0][0])
n="0"*(6-len(a))+a+"0"*5+"1"
A[0].append(n)
no=1
for i in range(1,M):
    if A[i][0]==A[i-1][0]:
        no=no+1
    else:
        no=1
    a=str(A[i][0])
    b=str(no)
    n="0"*(6-len(a))+a+"0"*(6-len(b))+b
    A[i].append(n)
A.sort(key=lambda x:x[2])
for i in range(M):
    print(A[i][3])

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m=map(int,input().split())
    A=[]
    for i in range(m):
        p,y=map(int,input().split())
        A.append((p,y,i))
    A.sort()
    cunt,pre,ans=0,0,[]
    for a in A:
        s1=str(a[0])
        if pre!=a[0]:
            cunt=1
            pre=a[0]
        s2=str(cunt)
        ans.append((a[2],s1.zfill(6)+s2.zfill(6)))
        cunt+=1
    ans.sort()
    for s in ans:
        print(s[1])

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m=map(int,input().split())
    A=[]
    for i in range(m):
        p,y=map(int,input().split())
        A.append((p,y,i))
    A.sort()
    cunt,pre,ans=0,0,[]
    for a in A:
        s1=str(a[0])
        if pre!=a[0]:
            cunt=1
            pre=a[0]
        s2=str(cunt)
        ans.append((a[2],s1.zfill(6)+s2.zfill(6)))
        cunt+=1
    ans.sort()
    for s in ans:
        print(s[1])

if __name__=='__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, m = MI()
    dct = {}
    for i in range(m):
        p, y = MI()
        dct.setdefault(p, [])
        dct[p].append((i, y))
    

    ans = ['' for _ in range(m)]
    for key, value in dct.items():
        st = sorted(value, key=lambda x: x[1])
        
        for idx, (i, year) in enumerate(st):
            id = str(key).zfill(6) + str(idx+1).zfill(6)
            
            ans[i] = id

    for iid in ans:
        print(iid)

if __name__ == '__main__':
    solve()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, m = MI()
    dct = {}
    for i in range(m):
        p, y = MI()
        dct.setdefault(p, [])
        dct[p].append((i, y))
    

    ans = ['' for _ in range(m)]
    for key, value in dct.items():
        st = sorted(value, key=lambda x: x[1])
        
        for idx, (i, year) in enumerate(st):
            id = str(key).zfill(6) + str(idx+1).zfill(6)
            
            ans[i] = id

    for iid in ans:
        print(iid)

if __name__ == '__main__':
    solve()

Solution (Python):
n, m = map(int, input().split())
cnt = [[] for _ in range(n + 1)]
for i in range(m):
    p, y = map(int, input().split())
    cnt[p].append((y, i))
buf = [None] * m
for p, l in enumerate(cnt):
    if not l:
        continue
    l.sort()
    for j, (y, i) in enumerate(l):
        buf[i] = '{:06d}{:06d}'.format(p, j + 1)
print('\n'.join(buf))

Solution (Python):
import collections
import bisect
n,m = map(int,input().split())
p = [[int(j) for j in input().split()] for i in range(m)]
a = collections.defaultdict(list)
for x,y in sorted(p):
  a[x] += [y]
for x,y in p:
  z = bisect.bisect(a[x],y)
  print("%06d%06d"%(x,z))

Solution (Python):
n,m=map(int,input().split())
py=[list(map(int,(str(_+1)+' '+input()).split())) for _ in range(m)]
py.sort(key=lambda x:x[1]*10**10+x[2])
pi=0
x=0
b='000000'
ans=[]
for pyi in py:
  if pyi[1]!=pi:
    x=1
    pi=pyi[1]
  else:
    x+=1
  ans.append([pyi[0],(b+str(pyi[1]))[-6:]+(b+str(x))[-6:]])
ans.sort(key=lambda x:x[0])
for ansi in ans:
  print(ansi[1])

Solution (Python):
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    PY = [il() for _ in range(M)]
    k = {}
    sortPY = sorted(PY, key=lambda x: (x[0], x[1]))

    tmp = 0
    cnt = 1
    for p, y in sortPY:
        if p != tmp:
            cnt = 1
            tmp = p
        else:
            cnt += 1

        k[y] = cnt

    for p, y in PY:
        print(str(p).zfill(6) + str(k[y]).zfill(6))


if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict
import bisect
N, M = map(int, input().split())

cities = defaultdict(list)
p = [[int(j) for j in input().split()] for i in range(M)]

for x, y in sorted(p):
    cities[x].append(y)

for x, y in p:
    z = bisect.bisect(cities[x], y)
    print("%06d%06d" % (x, z))

Solution (Python):
from bisect import bisect_right
n,m=map(int,input().split())
k=[[] for i in range(n+1)]
p,y=[0]*m,[0]*m
for i in range(m):
    p[i],y[i]=map(int,input().split())
    k[p[i]].append(y[i])
for i in range(n+1):
    k[i].sort()
for i in range(m):
    x=bisect_right(k[p[i]],y[i])
    ans1=str(p[i])
    while len(ans1)<6:
        ans1="0"+ans1
    ans2=str(x)
    while len(ans2)<6:
        ans2="0"+ans2
    print(ans1+ans2)

Solution (Python):
def main(): 
  n,m=map(int,input().split())
  py=[list(map(int,input().split()))+[i+1] for i in range(m)]
  py.sort(key=lambda x:(x[0],x[1],x[2]))
  py[0].append(1)
  cnt=1
  for i in range(1,m):
    cnt=cnt+1 if py[i][0]==py[i-1][0] else 1
    py[i].append(cnt)
  py.sort(key=lambda x:x[-2])
  for a,b,c,d in py:
    print(str(a).zfill(6)+str(d).zfill(6))
if __name__=='__main__':
  main()

Solution (Python):


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

ans = [0] * m
cities = []
for i in range(m):
    p, y = map(int, input().split())
    cities.append((i, p, y))
prefec = [[] for _ in range(n)]
cities.sort(key=lambda x: x[2]) 

for i, p, y in cities:
    prefec[p - 1].append((i))

for i in range(len(prefec)):
    pre = prefec[i]
    for j in range(len(pre)):
        index = pre[j]
        head = '000000' + str(i + 1)
        head = head[-6:]
        tail = '000000' + str(j + 1)
        tail = tail[-6:]
        ans[index] = head + tail

for r in ans:
    print(r)

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

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

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

sorted_pylst = sorted(pylst)

for y, p, i in sorted_pylst:
    py[p].append([y, i])

ans = [0]*M

for i, lst in enumerate(py):
    cnt = 1
    for j, k in lst:
        ans[k] = '{0:06d}{1:06d}'.format(i, cnt)
        cnt += 1
for i in ans:
    print(i)

Solution (Python):
n , m = map(int, input().split())
id =[]
ch = 1
for i in range(m):
    p , y = map(int, input().split())
    id.append([p,y,i])
id.sort(key = lambda x:(x[0],x[1]))
id.append(['X','X','X'])
for i in range(m):
    id[i][1]=str(ch).zfill(6)
    if id[i][0]==id[i+1][0]:
        ch+=1
    else:
        ch=1
id.pop()
id.sort(key = lambda x:x[2])
for i in range(m):
    s = str(id[i][0]).zfill(6)+id[i][1]
    print(s)

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

for i in range(m):
    py[i].append(i+1)

py.sort()


now=py[0][0]
co=0

for j in range(m):
    t=py[j][0]
    if t==now:
        co+=1
        py[j][1]=co
    else:
        now=py[j][0]
        co=1
        py[j][1]=co



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


for a,b,c in py:
    print(str(a).rjust(6,'0')+str(b).rjust(6,'0'))

Solution (Python):



import numpy as np







N, M = [int(x) for x in input().split()]
city = []

for n in range(M):
    P, Y = [int(x) for x in input().split()]
    city.append([n, P, Y])
city = np.array(city)
city = city[np.argsort(city[:, 2])]
counts = np.array([1]*N)

city2 = []

for n in range(M):
    city2.append([city[n, 0], city[n, 1], city[n, 2], counts[city[n, 1]-1]])
    counts[city[n, 1]-1] += 1

city2 = np.array(city2)
city2 = city2[np.argsort(city2[:, 0])]
for c in city2:
    print(str(c[1]).zfill(6) + str(c[3]).zfill(6))

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

T.sort(key=lambda x:(x[1],x[2]))
for i,item in enumerate(T):
  if i==0:
    item.append(1)
  else:
    if T[i][1]==T[i-1][1]:
      item.append(T[i-1][3]+1)
    else:
      item.append(1)
      
T.sort(key=lambda x:(x[0],x[3]))

for item in T:
  city = str(item[1])
  city = (6-len(city))*"0"+city
  order =  str(item[3])
  order = (6-len(order))*"0"+order
  print(city+order)

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
cur = [1] * (N+1)  
PY = [lr() + [i] for i in range(M)]
PY.sort(key=lambda x: x[1])
answer = [None] * M  
for p, y, i in PY:
    x = str(p).zfill(6) + str(cur[p]).zfill(6)
    answer[i] = x
    cur[p] += 1

for a in answer:
    print(a)

Solution (Python):
n, m = map(int, input().split())
py = []
mli = [0]*n
li = [""]*m

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

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

for p,y,i in py:
    mli[p-1] += 1
    pi = str(p).zfill(6)
    yi = str(mli[p-1]).zfill(6)
    li[i] = pi+yi

for i in li:
    print(i)

Solution (Python):
from collections import defaultdict
from bisect import bisect_left

n, m = map(int, input().split())
years = defaultdict(list)
sorted_years = defaultdict(list)
PY = []
for i in range(m):
    prefecture, year = map(int, input().split())
    years[prefecture].append(year)
    PY.append((prefecture, year))

for prefecture, year_list in years.items():
    temp = year_list
    temp.sort()
    sorted_years[prefecture] = temp

for pair in PY:
    p, y = pair
    years[p]
    num = 1 + bisect_left(sorted_years[p], y)
    print(str(p).zfill(6) + str(num).zfill(6))

Solution (Python):
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N,M = LMIIS()
    prefectures = [[]*M for _ in range(N)]
    for i in range(M):
        p, y = LMIIS()
        prefectures[p-1].append((y,i))
    dbg(prefectures)
    for p in prefectures:
        p.sort()
    dbg(prefectures)
    cities = [0]*M
    for i,p in enumerate(prefectures):
        for j,(y,k) in enumerate(p):
            cities[k] = '{:06d}{:06d}'.format(i+1,j+1)
    for s in cities:
        print(s)

        
        


if __name__ == '__main__':
    main()

Solution (Python):
'''
N  個の県があり、これらの県には合計で 
M 個の市が属しています。
市i が誕生したのは Yi 年であり、県 Pi に属しています。
それぞれの市に12 桁の認識番号を割り振ることとなりました。
市 i が 県 Pi に属する市の中で x 番目に誕生した市のとき、
市i の認識番号の上 6 桁は Pi、下 6 桁は x となります。

出力するのは県の番号とその県の中で何番目に誕生したかを
組み合わせたものになります。
したがって、まずは市を県ごとに分ける必要があります。
また、最終的にはもともとinputで受け取った順番で出力する
必要があるので、市ごとに配列に分けてそれぞれの配列に
誕生した年と初めのinputで受け取った順番を組にしたものをいれます。
このもとでそれぞれの県ごとの配列
'''
n,m=map(int,input().split())
pyi=[[] for i 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 i in range(m):
    print(ans[i][0])

Solution (Python):
inputs = open(0).readlines()
n, m = map(int, inputs[0].split())
PY = [map(int, x.split()) for x in inputs[1:]]
A = [[] for _ in range(n)]
B = [''] * m
for i, (p, y) in enumerate(PY):
    A[p-1].append([y, i])
    B[i] += '{:06}'.format(p)
for a in A:
    a.sort()
    for i in range(len(a)):
        B[a[i][1]] += '{:06}'.format(i+1)
print(*B, sep='\n')

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 bisect import bisect_right
n,m = map(int,input().split())
all_li = []
ma = {}
for _ in range(m):
    p,y = map(int,input().split())
    all_li.append((p,y))
    if p in ma:
        ma[p].append(y)
    else:
        ma[p] = [y]




sorted_li = [[] for _ in range(n)]
for k,v in ma.items():
    sorted_li[k-1] = list(sorted(v))

for a in all_li:
    
    count = bisect_right(sorted_li[a[0]-1],a[1],)
    
    print(str(a[0]).zfill(6)+str(count).zfill(6))

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

P = [0]*m
Y = [0]*m

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

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

for i in range(n):
  for j,(y,c) in enumerate(sorted(city[i])):
    Y[c] = j + 1

for p,y in zip(P,Y):
  print('{:0>6}'.format(p) + '{:0>6}'.format(y))

Solution (Python):
N, M = map(int, input().split())
py = []
d = {}
for i in range(M):
    p, y = map(int, input().split())
    py.append([p, y])
    if p not in d:
        d[p] = [y]
    else:
        d[p].append(y)
for key in d.keys():
    d[key].sort()
from bisect import bisect_left
for i in range(M):
    p, y = py[i]
    a = bisect_left(d[p], y)
    ans = '0' * (6 - len(str(p))) + str(p)
    ans += '0' * (6 - len(str(a + 1))) + str(a + 1)
    print(ans)

Solution (Python):
import itertools
from collections import Counter
N, M = list(map(int,input().split()))
city_list = [list(map(int,input().split())) +[i+1]  for i in range(M)]
city_list_sorted = sorted(city_list,key=lambda x: (x[0],x[1]) )
city_list_grouped = itertools.groupby(city_list_sorted,key=lambda x:x[0])
ans = []
for k, v in city_list_grouped:
  ans += [[v[2],format(k,'0>6')+format(i+1,'0>6')] for i,v in enumerate(v)]

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

Solution (Python):
import itertools
from collections import Counter
N, M = list(map(int,input().split()))
city_list = [list(map(int,input().split())) +[i+1]  for i in range(M)]
city_list_sorted = sorted(city_list,key=lambda x: (x[0],x[1]) )
city_list_grouped = itertools.groupby(city_list_sorted,key=lambda x:x[0])
ans = [None for i in range(M)]
m =0
for k, v in city_list_grouped:
  counter1 = 1
  for x1 in v:
    ans[m] = [x1[2],format(k,'0>6')+format(counter1,'0>6')]
    counter1 += 1 
    m+=1

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

Solution (Python):

N,M = list(map(int, input().split()))
P = []
Y = []
for _ in range(M):
    p,y = list(map(int, input().split()))
    P.append(p)
    Y.append(y)
count = [0]*(N+1)
ans = [0]*(M+1)
data = [[p,y,i] for p,y,i in zip(P,Y,range(1,M+1))]

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

for i in range(M):
    count[data[i][0]] += 1
    ans[data[i][2]] = count[data[i][0]]


for j in range(1,M+1):
    a = P[j-1]
    b = ans[j]
    print(str(a*(10**6)+b).zfill(12))

Solution (Python):

N,M = list(map(int, input().split()))
P = []
Y = []
for _ in range(M):
    p,y = list(map(int, input().split()))
    P.append(p)
    Y.append(y)
count = [0]*(N+1)
ans = [0]*(M+1)
data = [[p,y,i] for p,y,i in zip(P,Y,range(1,M+1))]

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

for i in range(M):
    count[data[i][0]] += 1
    ans[data[i][2]] = count[data[i][0]]


for j in range(1,M+1):
    a = P[j-1]
    b = ans[j]
    print(str(a*(10**6)+b).zfill(12))