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())
a=dict()
b=[]
for i in range(m):
    p,y=map(int,input().split())
    b.append((p,y))
    if p not in a:
        a[p]=[y]
    else:
        a[p]+=[y]
for i,l in a.items():
    a[i]=sorted(l)
for p,y in b:
    index=bisect.bisect_left(a[p],y)+1
    a1=str(p).zfill(6)
    a2=str(index).zfill(6)
    print(a1+a2)

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

p = []
for i in range(m):
  x = str(i)+' '+input()
  p.append(list(map(int,x.split())))

p.sort(key=lambda x:x[2]) 
c = [1]*(n+1)
for i in range(m):
  p[i][2] = c[p[i][1]]
  c[p[i][1]] += 1
p.sort()
for i in range(m):
  print( str(p[i][1]).zfill(6) + str(p[i][2]).zfill(6))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    PY = {}
    for i in range(1, M+1):
        p, y = map(int,input().split())
        if p not in PY.keys():
            PY[p] = []
        PY[p].append((y, i))
    numbers = [0] * (1+M)
    for p in PY.keys():
        PY[p].sort(reverse=True)
        rank = 1
        while PY[p]:
            year, i = PY[p].pop()
            num = str(p).zfill(6) + str(rank).zfill(6)
            rank += 1
            numbers[i] = num
            
    for i in range(1, M+1):
        print(numbers[i])


main()

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)
py=sorted(py,key= lambda x:(x[0],x[1]))

for i in range(m):
    if i==0:
        py[i][1]=1
    else:
        if py[i][0]==py[i-1][0]:
            py[i][1]=py[i-1][1]+1
        else:
            py[i][1]=1
py=sorted(py,key=lambda x:(x[2]))

for i in range(m):
    temp1="0"*(6-len(str(py[i][0])))+str(py[i][0])
    temp2="0"*(6-len(str(py[i][1])))+str(py[i][1])
    print(temp1+temp2)

Solution (Python):
N,M = map(int,input().split())
digit = 'zero padding: {:0=6}'
dic = [[] for _ in range(N+1)]

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

for p in dic:
    p.sort()

ans = [None for _ in range(M)]
for k in range(1,N+1):
    p = dic[k]
    for j in range(len(p)):
        i = p[j][1]
        ID = str(k).zfill(6)+str(j+1).zfill(6)
        ans[i] = ID

for a in ans:
    print(a)

Solution (Python):
N,M=map(int,input().split())
P=[list(map(int,input().split())) for _ in range(M)]
for i in range(M):
  P[i].append(i)
P.sort()
j=1
k=0
for i in range(M):
  k+=1
  if P[i][0]!=j:
    j=P[i][0]
    k=1
  s=str(j)
  while len(s)!=6:
    s='0'+s
  t=str(k)
  while len(t)!=6:
    t='0'+t
  P[i].append(s+t)
P.sort(key=lambda x:x[2])
for i in range(M):
  print(P[i][3])

Solution (Python):
N, M = map(int, input().split())
ls = []
for i in range(M):
    p, y = map(int, input().split())
    ls.append([i, p, y])
ls.append([float('inf'), float('inf'), 1])
ls.sort(key=lambda x: x[1])
rem = []
ans = []
cur_p = -1
for i in range(M+1):
    if ls[i][1] == float('inf'):
        rem.sort(key=lambda x: x[2])
        for j in range(len(rem)):
            rem_j = rem[j][:]
            rem_j.append('0'*(6-len(str(rem_j[1]))) + str(rem_j[1]) + '0'*(6-len(str(j+1))) + str(j+1))
            ans.append(rem_j)
        break
    if cur_p != ls[i][1]:
        if len(rem) != 0:
            rem.sort(key=lambda x: x[2])
            for j in range(len(rem)):
                rem_j = rem[j][:]
                rem_j.append('0'*(6-len(str(rem_j[1]))) + str(rem_j[1]) + '0'*(6-len(str(j+1))) + str(j+1))
                ans.append(rem_j)
            cur_p = ls[i][1]
            rem = []
            rem.append(ls[i])
        else:
            rem.append(ls[i])
            cur_p = ls[i][1]
    else:
        rem.append(ls[i])
ans.sort(key=lambda x: x[0])
for x in ans:
    print(x[-1])

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

G = list(map(sorted, G))
for p in range(N):
    for m, (y, i) in enumerate(G[p], 1):
        res[i] += (p + 1) * 10 ** 6 + m

for r in res:
    print(str(r)[1:])

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

G = list(map(sorted, G))
for p in range(N):
    for m, (y, i) in enumerate(G[p], 1):
        res[i] = 10 ** 12 + (p + 1) * 10 ** 6 + m

for r in res:
    print(str(r)[1:])

Solution (Python):
n, m = map(int, input().split())
d = [[] for _ in range(n)]
for i in range(m):
    p, y = map(int, input().split())
    d[p-1].append((y, i))
d = list(map(sorted, d))
ans = [0] * m
for p in range(n):
    for x, (y, i) in enumerate(d[p], 1):
        ans[i] = (p + 1) * 10 ** 6 + x
for a in ans:
    print(str(a + 10 ** 12)[1:])

Solution (Python):
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,datetime,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

N,M = inpl()
prefe = defaultdict(list)
for i in range(M):
    p,m = inpl()
    prefe[p].append((m,i+1))

anls = [[] for _ in range(M)]
for a,item in prefe.items():
    item.sort()
    jyun = []
    for b in item:
        ind = bisect.bisect_left(item,b) + 1
        jyun.append([ind,b[1]])
    for item2 in jyun:
        anls[item2[1]-1].append((a,item2[0]))

for item3 in anls:
    print(str(item3[0][0]).zfill(6) + str(item3[0][1]).zfill(6))

Solution (Python):
from bisect import bisect_right

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

Ps, Ys, vals = [], [], {}
for i in range(M):
  P, Y = map(int, input().split())
  Ps.append(P)
  Ys.append(Y)

  if P not in vals:
    vals[P] = []
  vals[P].append(Y)

for P in vals:
  vals[P].sort()

for i in range(M):
  pref = str(Ps[i]).zfill(6)
  city = str(bisect_right(vals[Ps[i]], Ys[i])).zfill(6)
  print(pref + city)

Solution (Python):
from bisect import bisect_right
n,m=map(int,input().split())
p,y=[],[]
l={}
for i in range(m):
 p_,y_=map(int,input().split())
 p.append(p_)
 y.append(y_)
 if not p_ in l:l[p_] = []
 l[p_].append(y_)
for i in l:
 l[i].sort()
for i in range(m):
 print(str(p[i]).zfill(6)+str(bisect_right(l[p[i]],y[i])).zfill(6))

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=[0]*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):
import heapq

N, M = map(int, input().split())
P_list = []
ans = []

for i in range(N+1):
    P_list.append([])

for i in range(M):
    P, Y = map(int, input().split())
    Y = Y * 10 ** 6 + i
    P_list[P].append(Y)

for i in range(N+1):
    P_list[i].sort()
    for j, k in enumerate(P_list[i]):
        tmp = (k % 10**6 + 1) * 10**12 + i * 10**6 + j + 1
        ans.append(tmp)

heapq.heapify(ans)

for i in range(M):
    pr = heapq.heappop(ans)
    ans_pr = str(pr % 10**12)
    print(ans_pr.zfill(12))

Solution (Python):
from bisect import bisect_right

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

Ps, Ys, vals = [], [], {}
for i in range(M):
  P, Y = map(int, input().split())
  Ps.append(P)
  Ys.append(Y)

  if P not in vals:
    vals[P] = []
  vals[P].append(Y)

for P in vals:
  vals[P].sort()

for i in range(M):
  pref = str(Ps[i]).zfill(6)
  city = str(bisect_right(vals[Ps[i]], Ys[i])).zfill(6)
  print(pref + city)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N,M = I()
C = [[] for _ in range(N+1)]
for i in range(M):
    p,y = I()
    C[p].append([y,i])
ans = ['a']*M
for i in range(1,len(C)):
    c = C[i]
    if c:
        c.sort()
        for j in range(len(c)):
            y,b = c[j]
            ans[b] = str(i).zfill(6)+str(j+1).zfill(6)
for a in ans:
    print(a)

Solution (Python):
(N, M, _), *PY = [list(map(int, s.split())) + [i] for i, s in enumerate(open(0))]
prev_p = 0
city_cnt = 1
PY.sort()
for i in range(M):
    p, y, _ = PY[i]
    if p != prev_p:
        city_cnt = 1
        prev_p = p
    PY[i].append(str(p).zfill(6) + str(city_cnt).zfill(6))
    city_cnt += 1
PY.sort(key=lambda x: x[2])
[print(x[-1]) for x in PY]

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

N, M = map(int, input().split())
PY = [map(int, input().split()) for i in range(M)]
PYI = sorted((p, y, i+1) for i, (p, y) in enumerate(PY))
def gen():
  pre = -1
  count = -1
  for p, y, i in PYI:
    if p == pre:
      count += 1
      yield (i, str(1*10**12+p*10**6+count)[1:])
    else:
      count = 1
      yield (i, str(1*10**12+p*10**6+count)[1:])
      pre = p
print('\n'.join(i[1] for i in sorted(gen())))

Solution (Python):
n,m = map(int,input().split())
p = [0]*m
V = [[] for i in range(n+1)]
for i in range(m):
    p[i] = list(map(int,input().split())) + [i]
    V[p[i][0]].append(p[i][1:])
W = []
for i in range(n+1):
    if V[i] == []:
        pass
    else:
        V[i].sort(key= lambda val : val[0])
        for j in range(len(V[i])):
            K = ["0"]*(6 - len(str(i))) + list(str(i)) + ["0"]*(6 - len(str(j+1))) + list(str(j+1))
            W.append(["".join(K),V[i][j][1]])
W.sort(key= lambda val : val[1])
for ans in W:
    print(ans[0])

Solution (Python):
n,m = map(int,input().split())
p = [0]*m
V = [[] for i in range(n+1)]
for i in range(m):
    p[i] = list(map(int,input().split())) + [i]
    V[p[i][0]].append(p[i][1:])
W = []
for i in range(n+1):
    if V[i] == []:
        pass
    else:
        V[i].sort(key= lambda val : val[0])
        for j in range(len(V[i])):
            K = ["0"]*(6 - len(str(i))) + list(str(i)) + ["0"]*(6 - len(str(j+1))) + list(str(j+1))
            W.append(["".join(K),V[i][j][1]])
W.sort(key= lambda val : val[1])
for ans in W:
    print(ans[0])

Solution (Python):
import itertools
def main():
    n, m = list(map(int, input().split()))
    A = [[] for _ in range(n)]
    for i in range(m):
        p, y = list(map(int, input().split()))
        A[p - 1].append([i, y])
    for i, a in enumerate(A):
        a.sort(key = lambda x: x[1])
        for j in range(len(a)):
            a[j] = [a[j][0], '{:06}{:06}'.format(i + 1, j + 1)]
    A = list(itertools.chain.from_iterable(A))
    A.sort(key = lambda x: x[0])
    for a in A:
        print(a[1])

if __name__ == '__main__':
    main()

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

def main():
    n, m = map(int, input().split())
    
    def readlines():
        for i in range(m):
            p, y = map(int, input().split())
            yield p, y, i

    cityies = sorted(readlines())

    def convert():
        prev = 0
        now = 1
        for p, y, i in cityies:
            if p == prev:
                now += 1
            else:
                now = 1
            yield i, "{:06}{:06}".format(p, now)

            prev = p

    print("\n".join(number for i, number in sorted(convert())))


main()

Solution (Python):
n,m = map(int,input().split())
pyl = [list(map(int,input().split())) for nesya in range(m)]
predic = dict()
ydic = dict()
spyl = sorted(pyl,key = lambda x:x[1])
for py in spyl:
  p = py[0]
  y = py[1]
  if p in predic:
    predic[p] += 1
  else:
    predic[p] = 1
  ydic[y] = (str(p).zfill(6))+(str(predic[p]).zfill(6))
for hoge in pyl:
  print(ydic[hoge[1]])

Solution (Python):
para_line = list(map(int,input().split(' ')))
city = []
for i in range(para_line[1]):
    line = list(map(int,input().split(' ')))
    city.append(line+[i])
city.sort(key = lambda a: a[1])
city_cnt = [0 for k in range(para_line[0])]
for n in range(para_line[1]):
    city_cnt[city[n][0]-1] += 1
    city[n].append(str(city[n][0]).zfill(6)+str(city_cnt[city[n][0]-1]).zfill(6))
city.sort(key = lambda b: b[2])
for j in city:
    print(j[3])

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint


INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n,m = MI()
py = LI(m)

py_new = []
no = 0
for i in range(m):
    no += 1
    p = py[i][0]
    y = py[i][1]
    py_new.append([no,p,y])

py_new = mysort(py_new,2,False)

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

no = 0
py_now = []
for i in range(m):
    no = py_new[i][0]
    p = py_new[i][1] - 1
    y = py_new[i][2]
    x = len(g[p]) + 1
    py_now.append([no,p,y,x])
    g[p].append(y)

py_now = mysort(py_now,0,False)

for i in range(m):
    p = str( py_now[i][1] + 1 )
    x = str( py_now[i][3] )
    p = p.zfill(6)
    x = x.zfill(6)
    a = p + x
    print(a)
exit()

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint


INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n,m = MI()
py = LI(m)

py_new = []
no = 0
for i in range(m):
    no += 1
    p = py[i][0]
    y = py[i][1]
    py_new.append([no,p,y])

py_new_sorted = mysort(py_new,2,False)

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

no = 0
py_now = []
for i in range(m):
    no = py_new_sorted[i][0]
    p = py_new_sorted[i][1] - 1
    y = py_new_sorted[i][2]
    x = len(g[p]) + 1
    py_now.append([no,p,y,x])
    g[p].append(y)

py_now = mysort(py_now,0,False)

for i in range(m):
    p = str( py_now[i][1] + 1 )
    x = str(py_now[i][3])
    p = p.zfill(6)
    x = x.zfill(6)
    a = p + x
    print(a)

Solution (Python):


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

C = {}
for i in range(N):
    C[i+1] = 0

D = {}

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

ret = {}
for y, p in sorted(D.items(), key=lambda x: x[0]):
    C[p[0]] += 1
    ret[p[1]] = str(p[0]).zfill(6) + str(C[p[0]]).zfill(6)
    
for i, r in sorted(ret.items(), key=lambda x: x[0]):
    print(r)

Solution (Python):
import bisect
from collections import defaultdict
n, m = map(int, input().split())
dic = defaultdict(lambda : [])
cities = []
for _ in range(m):
    p, y = map(int, input().split())
    cities.append((p, y))
    dic[p].append(y)
for key, vals in dic.items():
    dic[key] = sorted(vals)
for p, y in cities:
    pos = bisect.bisect_right(dic[p], y)
    print('{:06}{:06}'.format(p, pos))

Solution (Python):
n,m=map(int,input().split())
pys=[0]*m
for i in range(m):
	p,y=map(int,input().split())
	pys[i]=(p,y,i)
pys.sort(key=lambda x:x[1])

num=[0]*n
ans=[0]*m
for p,y,i in pys:
	num[p-1]+=1
	ans[i]=str(p).zfill(6)+str(num[p-1]).zfill(6)

for a in ans:
	print(a)

Solution (Python):
import sys
from operator import itemgetter

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    iPY = [[0] * 3 for _ in range(M)]
    for i in range(M):
        iPY[i][0] = i
        iPY[i][1:] = map(int, input().split())

    iPY.sort(key=itemgetter(2))

    p_count = [0] * (N + 1)
    ans = [""] * M
    for i, P, Y in iPY:
        p_count[P] += 1
        ans[i] = "".join([
            str(P).zfill(6),
            str(p_count[P]).zfill(6)
        ])

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


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n, m = map(int, input().split())
    py = [list(map(int, input().split())) for _ in range(m)]
    x = sorted(py, key=lambda x:x[1])
    d = {}
    for p, y in x:
        if type(d.get(p)) != dict:
            d[p]  = {}
        d[p][y] = len(d[p]) + 1
    for p, y in py:
        print('{:0=6}{:0=6}'.format(p, d[p][y]))
         
    
if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left
N, M = map(int, input().split())
G = [[] for _ in range(N)]
P = [0]*M
Y = [0]*M
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    G[P[i]-1].append(Y[i])

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

for i in range(M):
    right = bisect_left(G[P[i]-1], Y[i])+1
    print(str(P[i]).rjust(6, '0')+str(right).rjust(6, '0'))

Solution (Python):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
l2=sorted(l,key=lambda x:x[1])
d=dict()
for p,y in l2:
    if not p in d.keys():
        d[p]=dict()
    d[p][y]=len(d[p])+1
for p,y in l:
    print('{}'.format(p).zfill(6)+'{}'.format(d[p][y]).zfill(6))

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

N,M = map(int,readline().split())
from collections import defaultdict
PY = defaultdict(list)
for i in range(M):
  p,y = map(int,readline().split())
  PY[p].append([y,i])

res = []
for key,value in PY.items():
  value = sorted(value, key = lambda x:x[0])
  for i in range(len(value)):
    res.append([key,i + 1,value[i][1]])

res = sorted(res, key = lambda x:x[2])
for r in res:
  print(str(r[0]).zfill(6) + str(r[1]).zfill(6))

Solution (Python):
from operator import itemgetter
N,M=map(int, input().split())
PY = []
for i in range(M):
    P,Y=map(int, input().split())
    PY.append([P,Y,i])
PY.sort(key=lambda x:x[1])
PY.sort(key=lambda x:x[0])
ANS = []
beforeP = PY[0][0]
x = 1
for i in range(M):
    if beforeP != PY[i][0]:
        x = 1
    ANS.append([PY[i][2],'{:0=6}'.format(PY[i][0]) + '{:0=6}'.format(x)])
    beforeP = PY[i][0]
    x += 1

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

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

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

ID = {}
i, p = 1, PY_sort[0][0]
for v in PY_sort:
    if v[0] != p:
        i, p = 1, v[0]
    id = "%06d%06d"%(p, i)
    ID[v[1]] = id
    i += 1

for p, y in PY:
    print(ID[y])

Solution (Python):
n,m=map(int,input().split())
pys=[0]*m
for i in range(m):
    p,y=map(int,input().split())
    pys[i]=(p,y,i)
pys.sort(key=lambda x: x[1])

cnt=[0]*n
ans=[0]*m
for p,y,i in pys:
    cnt[p-1]+=1
    ans[i]=str(p).zfill(6)+str(cnt[p-1]).zfill(6)

for i in ans:
    print(i)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


N, M = MAP()
PY = [LIST() for _ in range(M)]
PY_ = deepcopy(PY)
PY_.sort(key = lambda x: (x[0],x[1]))

tmp = 0
i = 0
lis = []
dic = {}
for p, y in PY_:
	if p == tmp:
		i += 1
	else: 
		lis.append([])
		tmp = p
		i = 1
	dic[str(p)+"_"+str(y)] = str(p).zfill(6)+str(i).zfill(6)

for p, y in PY:
	print(dic[str(p)+"_"+str(y)])

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


N, M = MAP()
PY = [LIST() for _ in range(M)]

for i in range(M):
	PY[i].append(i)

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

tmp = 0
cnt = 0
for i in range(M):
	if PY[i][0] != tmp:
		cnt = 1
		tmp = PY[i][0]
	else:
		cnt += 1
	PY[i].append(str(PY[i][0]).zfill(6)+str(cnt).zfill(6))

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

print(*[PY[i][3] for i in range(M)], sep = "\n")

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

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

nums = [0] * N
ans = [''] * M
pys.sort(key=lambda x:x[1])

for p, y, i in pys:
    nums[p-1] += 1
    ans[i] = str(p).zfill(6) + str(nums[p-1]).zfill(6)

for an in ans:
    print(an)

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

for p, y in sorted(py, key = lambda x: x[1]):
    c[p] += 1
    id[y] =  format(p, "06") + format(c[p], "06")

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

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

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

l.sort()

l[0][1] = 1

for i in range(1, m):
    if l[i][0] == l[i - 1][0]:
        l[i][1] = l[i - 1][1] + 1
    else:
        l[i][1] = 1

sortthird = lambda val: val[2]
l.sort(key = sortthird)

for i in l:
    ans = "0"*(6 - len(i[0])) + i[0] + "0"*(6 - len(str(i[1]))) + str(i[1])
    print(ans)

Solution (Python):
import bisect

N, M = map(int, input().split())  
birth_list = []  
pref_year_list = {}
for i in range(M):
    pi, yi = map(int, input().split())  
    birth_list.append((pi, yi))
    if pi in pref_year_list:
        pref_year_list[pi].append(yi)
    else:
        pref_year_list[pi] = [yi]
for k in pref_year_list.keys():
    pref_year_list[k] = list(sorted(pref_year_list[k]))


for pi, yi in birth_list:
    
    year_list = pref_year_list[pi]
    i = bisect.bisect(year_list, yi)
    print("%06d%06d" % (pi, i))

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

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

KEN = [0]*N
SHIs = []

for i in range(M):
    P = PY[i][0]
    ind = PY[i][2]
    KEN[P-1] += 1
    X = KEN[P-1]
    S = str(P).zfill(6) + str(X).zfill(6)
    SHIs.append([S,ind])

SHIs.sort(key=lambda x:x[1],reverse=False)
for s in SHIs:
    print(s[0])

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

from collections import defaultdict
dict = defaultdict(list)
for i, (p, d) in enumerate(pd):
    dict[p].append((d, i))

ans = ['' for _ in range(m)]
for key in dict:
    v = dict[key]
    v.sort()

    for i, (y, idx) in enumerate(v):
        tmp = str(key).zfill(6) + str(i + 1).zfill(6)
        ans[idx] = tmp

for a in ans:
    print(a)

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


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

x = 1
A[0].append(x)
for i in range(1, m):
    if A[i][0] == A[i - 1][0]:
        x += 1
    else:
        x = 1
    A[i].append(x)
A.sort(key = lambda x: x[2])

for a in A:
    p, x = a[0], a[3]
    print(format(p, "06") + format(x, "06"))

Solution (Python):
n, m = map(int, input().split())
ans = ['']*m
mat = [list(map(int, input().split())) for _ in range(m)]
d = {}
for idx in range(m):
    p, y = mat[idx]
    y = (y, idx)
    ans[idx] += str(p).zfill(6)
    if p in d:
        d[p].append(y)
    else:
        d[p] = [y]

for v in d.values():
    v.sort(key=lambda x: x[0])
    for i, (_, idx) in enumerate(v):
        i += 1
        ans[idx] += str(i).zfill(6)

for a in ans:
    print(a)

Solution (Python):
import bisect

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

PY = []
PYd = {i:[] for i in range(1, N+1)}

for i in range(M):
    x, y = [int(i) for i in input().split()]
    PYd[x].append(y)
    PY.append((x,y))
    
for i in PYd.keys():
    PYd[i].sort()
    
for p,y in PY:
    str_p = str(p).zfill(6)
    index = str(bisect.bisect(PYd[p], y)).zfill(6)
    print(str_p+index)

Solution (Python):
from collections import defaultdict
import bisect

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

PY = []
PYd = defaultdict(list)

for i in range(M):
    x, y = [int(i) for i in input().split()]
    PYd[x].append(y)
    PY.append((x,y))
    
for i in PYd.keys():
    PYd[i].sort()
    
for p,y in PY:
    str_p = str(p).zfill(6)
    index = str(bisect.bisect(PYd[p], y)).zfill(6)
    print(str_p+index)

Solution (Python):






from collections import deque



n,m=map(int,input().split())
j=0
l=[[] for _ in range(n)]
ans=[0]*m
for i in range(m):
    p,y=map(int,input().split())
    l[p-1].append((i,y,p))
for i in range(n):
    l[i].sort(key=lambda x:x[1])
for i in range(n):
    for j in range(len(l[i])):
        ans[l[i][j][0]]='%012d' %(l[i][j][2]*10**6+j+1)
print(*ans)

Solution (Python):
import sys
import collections
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, M = ZZ()
    a = collections.defaultdict(list)
    id = [''] * (M+1)
    for i in range(M):
        p, y = ZZ()
        a[p].append([y, i+1])
    for key in a.keys():
        a[key].sort()
        for j, al in enumerate(a[key], 1):
            y, i = al
            id[i] = '{:0=6}'.format(key) + '{:0=6}'.format(j)
    for i in range(1, M+1): print(id[i])

    return

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.buffer.readline

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

for i in range(M):
    a, b = map(int,input().split())
    town[a-1].append((b,i))

for i in range(N):
    town[i].sort()
    for k in range(len(town[i])):
        index = town[i][k][1]
        t = town[i][k][0]
        ans[index] = str(i+1).zfill(6) + str(k+1).zfill(6)

for i in ans:
    print(i)

Solution (Python):
import sys
input = sys.stdin.buffer.readline

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

for i in range(M):
    a, b = map(int,input().split())
    town[a-1].append((b,i))

for i in range(N):
    town[i].sort()
    for k in range(len(town[i])):
        index = town[i][k][1]
        t = town[i][k][0]
        ans[index] = str(i+1).zfill(6) + str(k+1).zfill(6)

for i in ans:
    print(i)

Solution (Python):
n,m=map(int, input().split())
a=[list(map(int, input().split())) for _ in range(m)]
c=[0]*-~n
id={}
for p,y in sorted(a,key=lambda x:x[1]):
    c[p]+=1
    id[y]=str(p).zfill(6)+str(c[p]).zfill(6)
for _,y in a:
    print(id[y])