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())
PY=[list(map(int,input().split())) for _ in range(m)]

order=[list() for _ in range(n)]
ans=['']*m
for i,py in enumerate(PY):
  p,y=py[0],py[1]
  order[p-1].append((i,y))
  ans[i]+=str(p).zfill(6)
for o in order:
  o.sort(key=lambda x:x[1])
  for i in range(len(o)):
    ans[o[i][0]]+=str(i+1).zfill(6)
for a in ans:
  print(a)

Solution (Python):
n,m = map(int,input().split())
A = [[i,list(map(int,input().split()))] for i in range(m)]
B = []
i = 0
x = 0
for a in sorted(A,key=lambda l:(l[1][0],l[1][1])):
    if i==a[1][0]:
        x += 1
        B.append([a[0],str(a[1][0]).zfill(6)+str(x).zfill(6)])
    else:
        x = 1
        B.append([a[0],str(a[1][0]).zfill(6)+str(x).zfill(6)])
        i = a[1][0]
for b in sorted(B):
    print(b[1])

Solution (Python):
N,M = map(int, input().split())
city, ID = [[] for _ in range(N+1)], [0 for _ in range(M)]
for i in range(M):
    P, Y = map(int, input().split())
    city[P].append([Y,i])
for i in range(1, N+1):
    city[i].sort()
    for j in range(len(city[i])):
        ID[city[i][j][1]] = str(i).zfill(6) + str(j+1).zfill(6)
for x in ID:    print(x)

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

for i in range(m):
    p, y = map(int, input().split())
    order[p-1].append((i, y))
    ans[i] += str(p).zfill(6)

for o in order:
    o.sort(key=lambda x: x[1])
    for i in range(len(o)):
        ans[o[i][0]] += str(i+1).zfill(6)

for a in ans: print(a)

Solution (Python):
n,m=map(int,input().split())
Y=[[] for i in range(n+1)]
C=[]
ans={}

for city in range(m):
    p,y=map(int,input().split())
    Y[p].append((y,city))
    C.append(p)
    
for lis in Y:
    lis.sort()
    num=1
    for tup in lis:
        ans[tup[1]]=num
        num+=1

for res in range(m):
    
    print('{:0=6}'.format(C[res])+'{:0=6}'.format(ans[res]))

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

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

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

O = [None for _ in range(M)]
for p, yis in enumerate(pyi):
    for j, yi in enumerate(yis):
        y, i = yi
        O[i] = (p+1, j+1)

for p, i in O:
    p = ('000000' + str(p))[-6:]
    i = ('000000' + str(i))[-6:]
    print(p+i)

Solution (Python):
def main():
    from collections import defaultdict
    dd = defaultdict(str)

    n, m = map(int, input().split())
    keys = []
    atcoder = [[] for _ in range(n)]
    for i in range(m):
        p, y = map(int, input().split())
        key_p = str(p).zfill(6)
        key_y = str(y).zfill(10)
        keys.append(key_p + key_y)
        p -= 1
        atcoder[p].append(y)
    for i in range(n):
        atcoder[i].sort()
        key_i = str(i + 1).zfill(6)
        for index, j in enumerate(atcoder[i]):
            key_index = str(index + 1).zfill(6)
            key_j = str(j).zfill(10)
            dd[key_i + key_j] = key_i + key_index
    for k in keys:
        print(dd[k])


if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict
dd = defaultdict(str)

n, m = map(int, input().split())
keys = []
atcoder = [[] for _ in range(n)]
for i in range(m):
    p, y = map(int, input().split())
    key_p = str(p).zfill(6)
    key_y = str(y).zfill(10)
    keys.append(key_p + key_y)
    p -= 1
    atcoder[p].append(y)
for i in range(n):
    atcoder[i].sort()
    key_i = str(i + 1).zfill(6)
    for index, j in enumerate(atcoder[i]):
        key_index = str(index + 1).zfill(6)
        key_j = str(j).zfill(10)
        dd[key_i + key_j] = key_i + key_index
for k in keys:
    print(dd[k])

Solution (Python):
import sys
readline = sys.stdin.readline
n,m = list(map(int, readline().split()))
py = []
for _ in range(m):
    py.append(list(map(int, readline().split())))

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

Y = {}
for i in range(m):
    Y[spy[i][1]] = 0

P = [0 for _ in range(n+1)]

for i in range(m):
    P[spy[i][0]] += 1
    Y[spy[i][1]] = P[spy[i][0]]

for i in range(m):
    print(str(py[i][0]).zfill(6) + str(Y[py[i][1]]).zfill(6))

Solution (Python):
N,M=map(int,input().split())
PY=[[0,0,0] for i in range(M)] 
for i in range(M):
  P,Y=map(int,input().split())
  PY[i]=[P,Y,i]
PY.sort(key=lambda x:x[1])
PY.sort(key=lambda x:x[0])
prev=0
for i in range(M):
  if PY[i][0] != prev:
    count = 1
  else:
    count+=1
  prev=PY[i][0]
  ans=["0" for i in range(6 - len(str(prev)))]
  temp=["0" for i in range(6 - len(str(count)))]
  ans+=list(str(prev))+temp+list(str(count))
  PY[i][0]="".join(ans)
PY.sort(key=lambda x:x[2])
for i in range(M):
  print(PY[i][0])

Solution (Python):
N, M = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(M)]
pyi = []
for i, x in enumerate(py):
    x.append(i)
    pyi.append(x)
pyi.sort()

dic = {}
number_list = []
for p, y, i in pyi:
    w = ''
    w = "0" * (6 - len(str(p))) + str(p)

    if p in dic:
        dic[p] += 1
    else:
        dic[p] = 1
    w += "0" * (6 - len(str(dic[p]))) + str(dic[p])
    number_list.append([i, w])
number_list.sort()
for i in range(len(number_list)):
    print(number_list[i][1])

Solution (Python):




from operator import itemgetter

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

l=[[-1]*3 for i in range(M)]

for i in range(M):
    p,y=map(int,input().split())
    l[i]=[i,10**10*p+y]

l.sort(key=itemgetter(1))

pre_n=l[0][1]//10**10
count=0
for i in range(M):
    n=int(l[i][1]//(10**10))
    if n==pre_n:
        count+=1
        l[i][1]=n*10**6+count
        
    else:
        pre_n=n
        count=1
        l[i][1]=n*10**6+count
l.sort()

for i in range(M):
    s=str(l[i][1])
    print("0"*(12-len(s))+s)

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

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

c_num = 0
for i, c in enumerate(city):
    if c_num != c[1]:
        p_num = 1
        c_num = c[1]
    else:
        p_num += 1
    city[i].append(str(c[1]).zfill(6) + str(p_num).zfill(6))

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

for c in city:
    print(c[3])

Solution (Python):
import bisect
import collections

N, M = map(int, input().split())
PM = [[int(j) for j in input().split()] for i in range(M)]
A = collections.defaultdict(list)
for x, y in sorted(PM):
    A[x] += [y]
for x, y in PM:
    z = bisect.bisect(A[x], y)
    print('%06d%06d'%(x,z))

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

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


n=1
for i in range(M):
  if i>0:
    n = 1 if PY[i][0]!=PY[i-1][0] else n
  PY[i][3]="0"*(6-len(str(n)))+str(n)
  n+=1
  PY[i][3]="0"*(6-len(str(PY[i][0])))+str(PY[i][0])+PY[i][3]

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


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

Solution (Python):
from operator import itemgetter
N,M =[int(x) for x in input().split()]
ans = []
for i in range(M):
  p,y = [int(x) for x in input().split()]
  ans1 = [p,y,i]
  ans += [ans1]
ans = sorted(ans,key=itemgetter(1))
ans = sorted(ans,key=itemgetter(0))
cnt = 0
pcnt = 1
a = ans[0][0]
for i in range(M):
  if a == ans[i][0]:
    cnt += 1
    a = ans[i][0]
    ans[i][0] = "{:06d}".format(ans[i][0])+ "{:06d}".format(cnt)
  else:
    a = ans[i][0]
    cnt = 1
    ans[i][0] = "{:06d}".format(ans[i][0])+ "{:06d}".format(cnt)
ans = sorted(ans,key=itemgetter(2))
for i in range(M):
	print(ans[i][0])

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

py.sort()
ans = {}
cnt = 1
for i in range(len(py)):
  if i == 0:
    cnt = 1
  elif py[i][0] == py[i-1][0]:
    cnt += 1
  else:
    cnt = 1
  l = str(py[i][0])
  temp = '0' * (6-len(l))+l
  sc = str(cnt)
  sc = '0' * (6-len(sc)) + sc
  ans[py[i][2]] =temp+sc
  
for i in range(m):
  print(ans[i])

Solution (Python):
n, m = [int(i) for i in input().split()]
py = []
for j in range(m):
    py.append([j]+[int(i) for i in input().split()])
py.sort(key=lambda x:x[2])
b = [1] * n
c=[]
for i in py:
    c.append([str(i[1]).zfill(6) + str(b[i[1]-1]).zfill(6), i[0]])
    b[i[1]-1] += 1
c.sort(key=lambda x:x[1])
for i in c:
    print(i[0])

Solution (Python):
def main():
  n, m = map(int, input().split())
  buf = [None] * m
  cnt = {k: [] for k in range(n + 1)}
  for i in range(m):
      p, y = map(int, input().split())
      cnt[p] += [(y, i)]
  for p, l in cnt.items():
      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))

if __name__ == '__main__':
  main()

Solution (Python):
def main():
    N,M = map(int,input().split())
    X = [list(map(int,input().split())) for _ in range(M)]
    for i in range(M):
        X[i].append(i)

    X.sort(key=lambda X:(X[0],X[1]))
    anslist = [[0,0] for _ in range(M)]
    tmp = 0
    count = 1
    for i in range(M):
        if tmp != X[i][0]:
            tmp = X[i][0]
            count = 1
            anslist[i][0] = "0"*(6-len(str(X[i][0])))+str(X[i][0])+"0"*(6-len(str(count)))+str(count)
            anslist[i][1] = X[i][2]
        else:
            count += 1
            anslist[i][0] = "0"*(6-len(str(X[i][0])))+str(X[i][0])+"0"*(6-len(str(count)))+str(count)
            anslist[i][1] = X[i][2]
            
    anslist.sort(key=lambda X:X[1])
    for i in range(M):
        print(anslist[i][0])

if __name__ == "__main__":
    main()

Solution (Python):
import collections
import bisect

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

ans = collections.defaultdict(list)

for p, y in sorted(P):
    ans[p] += [y]
for p, y in P:
    print("%06d%06d"%(p, bisect.bisect(ans[p], y)))

Solution (Python):
import collections
import bisect
n,m = map(int, input().split())
p = [list(map(int,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:
  print("%06d%06d"%(x,bisect.bisect(a[x],y)))

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, m = LI()
L = LIR(m)
for i in range(m):
    L[i] = [i, str(L[i][0]).zfill(6), L[i][1]]


L.sort(key=lambda x:x[1:])
cnt = 1
L[0][2] = str(1).zfill(6)
for i in range(1, m):
    if L[i][1] != L[i-1][1]:
        cnt = 1
    else:
        cnt += 1
    L[i][2] = str(cnt).zfill(6)



L.sort(key=lambda x:x[0])
for i in L:
    print(i[1] + i[2])

Solution (Python):
N, M = map(int, input().split())
P = {(p+1):[] for p in range(N)}
ans = []
Q  = []

for i in range(M):
    p, y = map(int,input().split())
    P[p].append({'index':i, 'prefecture':p, 'year':y, 'rank':None})

for i in range(1, N+1):
    p = sorted(P[i], key=lambda x: x['year'])
    for s, j in enumerate(p, start=1):
        j['rank'] = s
    Q += p
Q = sorted(Q, key=lambda x: x['index'])
for q in Q:
    a = str(q['prefecture'])
    a = '0'*(6-len(a)) + a
    b = str(q['rank'])
    b = '0'*(6-len(b)) + b
    print(a+b)

Solution (Python):
N,M, *V = map(int, open(0).read().split())
P = V[0::2]
Y = V[1::2]

table = dict()

for i in range(len(P)):
  if(P[i] in table):
    table[P[i]].append(Y[i])
  else:
    table[P[i]] = []
    table[P[i]].append(Y[i])

for key in table.keys():
  table[key] = sorted(table[key])

sr_table = dict()

for key in table.keys():
  sr_table[key] = dict()
  for i in range(len(table[key])):
    sr_table[key][table[key][i]] = i+1

for i in range(len(P)):
  order = sr_table[P[i]][Y[i]]
  pre  = '{:0=6}'.format(P[i])
  post = '{:0=6}'.format(order)
  print(str(pre) + str(post))

Solution (Python):


import bisect

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

dct = {}
for i in range(m):
    if py[i][0] in dct.keys():
        dct[py[i][0]].append(py[i][1])
    else:
        dct[py[i][0]] = [py[i][1]]

for key in dct.keys():
    dct[key].sort()

for i in range(m):
    print("{:06}{:06}".format(py[i][0], bisect.bisect(dct[py[i][0]], py[i][1])))

Solution (Python):
from bisect import bisect_right
n,m = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(m)]
l2 = sorted(l,key = lambda x:(x[0],x[1]))
t = [[] for _ in range(n)]

for p,y in l2:
    t[p-1].append(y)
    
for i in l:
    order = bisect_right(t[i[0]-1],i[1])
    print(str(i[0]).zfill(6)+str(order).zfill(6))

Solution (Python):
from bisect import bisect_left
n,m = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(m)]
l2 = sorted(l,key = lambda x:(x[0],x[1]))
t = [[] for _ in range(n)]

for p,y in l2:
    t[p-1].append(y)
    
for i in l:
    order = bisect_left(t[i[0]-1],i[1])
    print(str(i[0]).zfill(6)+str(order+1).zfill(6))

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

prev = 0
count = 0
res = []
for city in cities:
    if city[0] != prev:
        count = 0
        prev = city[0]
    count += 1
    res.append(['{:06d}{:06d}'.format(city[0], count), city[2]])
res = sorted(res, key=lambda x: x[1])

for x in res:
    print(x[0])

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

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

y_dict = {}
tmps = []
for i, ypi in enumerate(sorted(yp)):
    if ypi[1] in y_dict.keys():
        y_dict[ypi[1]] += 1
    else:
        y_dict[ypi[1]] = 1
    tmps.append([ypi[2], str(ypi[1]).zfill(6)+str(y_dict[ypi[1]]).zfill(6)])

for tmp in sorted(tmps):
    print(tmp[1])

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

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


PY.sort(key=lambda x: (x[0],x[1]))
ans = []
num = 1
for i in range(M):
    if i>0 and PY[i][0] != PY[i-1][0]:
        num = 1
    ken = str(PY[i][0]).zfill(6)
    shi = str(num).zfill(6)
    ans.append([PY[i][2],ken+shi])
    num+=1
ans.sort()
for i in range(M):
    print(ans[i][1])

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

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


PY.sort(key=lambda x: (x[0],x[1]))
ans = []
num = 1
for i in range(M):
    if i>0 and PY[i][0] != PY[i-1][0]:
        num = 1
    ken = str(PY[i][0]).zfill(6)
    shi = str(num).zfill(6)
    ans.append([PY[i][2],ken+shi])
    num+=1
ans.sort()
for i in range(M):
    print(ans[i][1])

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())
T = [[] for i in range(N+1)]
for i in range(M):
    p,y = map(int,input().split())
    T[p].append([y, i])
result = [0] * M
for i in range(1, N+1):
    t = T[i]
    t.sort()
    if len(t) == 0:
        continue
    for j in range(len(t)):
        result[t[j][1]] =  str('{0:06}'.format(i)) + str('{0:06}'.format(j+1))
for ans in result:
    print(ans)

Solution (Python):
n,m = map(int,input().split())
Cities = [list(map(int,input().split())) for i in range(m)]
city = 0
for City in Cities:
  City += [city]
  city += 1
Cities.sort()
Cities[0][1] = 1
order = 1
for i in range(1,m):
  if Cities[i][0] == Cities[i-1][0]:
    order += 1
  else:
    order = 1
  Cities[i][1] = order
Cities.sort(key=lambda x:x[2])
for City in Cities:
  print(str(City[0]).zfill(6) + str(City[1]).zfill(6))

Solution (Python):

import sys
input = sys.stdin.readline

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

py_list = \
    [list(map(int, input().split()))+[i] for i, m in enumerate(range(m))]
py_list.sort(key=lambda x: x[1])

cursor_p = 1
currents = [0] * n
city = None
addresses = []
for py in py_list:
    p = py[0]
    y = py[1]
    idx = py[2]

    if p == cursor_p:
        currents[cursor_p - 1] += 1
    else:
        cursor_p = p
        currents[cursor_p - 1] += 1
    city = str(currents[cursor_p - 1]).zfill(6)
    pref = str(cursor_p).zfill(6)

    addresses.append((idx, pref + city))

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

for address in addresses:
    print(address[1])

Solution (Python):
N,M = map(int,input().split())
arr = [list(map(int,input().split()))+[i] for i in range(M)]
arr = sorted(arr)
new_arr = []
former_p = 1
cnt = 0
for p,y,index in arr:
  if p == former_p:
    cnt += 1
  else:
    cnt = 1
  new_arg = [index, str(p).zfill(6) + str(cnt).zfill(6)]
  new_arr.append(new_arg)
  former_p = p
  
new_arr = sorted(new_arr)
for i in new_arr:
  print(i[1])

Solution (Python):
N, M = map(int, input().split())
PYs = []
G = {}
for i in range(M):
  P, Y = map(int, input().split())
  PYs.append((P, Y))
  if not(P in G):
    G[P] = []
  G[P].append(Y)
D = {}
for P in G:
  L = sorted(G[P])
  d = {}
  for i in range(len(L)):
    Y = L[i]
    d[Y] = i
  D[P] = d
for P, Y in PYs:
  r = format(P, "0>6")+format(D[P][Y]+1, "0>6")
  print(r)

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

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

j = 0
city = 0

for i, value in enumerate(PY):
    if value[1] != city:
        j = 0
    j += 1
    value.append(j)
    city = value[1]



PY.sort(key=lambda val: val[0])

for i in PY:
    ans = str(i[1]).zfill(6)+str(i[3]).zfill(6)
    print(ans)

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

PY = [[i] for i in range(1,M+1)]

for i in range(M):
    temp1, temp2 = map(int, input().split())
    PY[i].append(temp1)
    PY[i].append(temp2)


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

PY.sort(key=lambda val: val[1])

city = 0

for i, value in enumerate(PY):
    if value[1] != city:
        j = 0
    j += 1
    value.append(j)
    city = value[1]

PY.sort(key=lambda val:val[0])



for i in PY:
    ans = str(i[1]).zfill(6)+str(i[3]).zfill(6)
    print(ans)

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

N, M = map(int, input().split())
arr = [[i] for i in range(1,M+1)]
for i in range(M):
    temp1, temp2 = map(int, input().split())
    arr[i].append(temp1)
    arr[i].append(temp2)
arr.sort(key=lambda x:x[2])
arr.sort(key=lambda x:x[1])
city = 0
for i, value in enumerate(arr):
    if value[1] != city:
        j = 0
    j += 1
    value.append(j)
    city = value[1]
arr.sort(key=lambda x:x[0])
for value in arr:
    left = str(value[1]).zfill(6)
    right = str(value[3]).zfill(6)
    print(left + right)

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

prefectures = []

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

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

answers.sort()

for i, answer in answers:
    print(answer)

Solution (Python):
from collections import deque
q = deque()
N, M = map(int, input().split())

pref = [[0] for i in range(N+1)]
for i in range(M):
    p, y = map(int, input().split())
    pref[p].append(y)
    q.append((p, y))
for p in pref:
    p.sort()
import bisect
for p, y in q:
    print('%06d%06d'%(p, bisect.bisect_left(pref[p], y)))

Solution (Python):
n,m = map(int,input().split())
C = [[i]+list(map(int,input().split())) for i in range(m)]
C.sort(key=lambda c:c[1:])
prev = 0
count = 0
for c in C:
    if prev==c[1]: count+=1
    else: count=1
    c.append(format(c[1],'0>6')+format(count,'0>6'))
    prev=c[1]

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

Solution (Python):
import bisect
a,b = map(int,input().split())

c = [[] for i in range(a)]
z = []
for _ in range(b):
  f,g = map(int,input().split())
  c[f - 1].append(g)
  z.append([f,g])

for i in range(a):
    if c[i] != []:
        c[i].sort()

x =''
y = ''
for j in range(b):                    
    x = str(z[j][0])
    x = '0' * (6 - len(x)) + x
    y = str(bisect.bisect(c[z[j][0] - 1], z[j][1]))
    y = '0' * (6 - len(y)) + y
    print(x + y)

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

pref_lst = [[] for _ in range(N)]

i = 0
for print_order in range(M):
	pref, year = map(int, input().split())
	pref_lst[pref - 1].append([i, year])
	i += 1
	
ret_lst = []

for i in range(N):
	pref_lst[i] = sorted(pref_lst[i], key = lambda x : x[1])
	for j in range(len(pref_lst[i])):
		p = str(i + 1).zfill(6)
		y = str(j + 1).zfill(6)
		pref_lst[i][j].append(p + y)
	ret_lst.extend(pref_lst[i])
		
ret_lst = sorted(ret_lst, key = lambda x : x[0])

for elm in ret_lst:
	print(elm[2])

Solution (Python):
import sys
input=sys.stdin.readline
 
N,M = map(int, input().split())
 
pref = [[0] for i in range(N+1)]
import collections
q = collections.deque()
 
for i in range(M):
    p,y = map(int, input().split())
    pref[p].append(y)
    q.append((p,y))
for p in pref:
    p.sort()
 
import bisect
for p,y in q:
    print("%06d%06d" %(p, bisect.bisect_left(pref[p], y)))

Solution (Python):
N,M = map(int, input().split())
 
pref = [[0] for i in range(N+1)]
q=[]

for i in range(M):
    p,y = map(int, input().split())
    pref[p].append(y)
    q.append([p,y])
for p in pref:
    p.sort()
 
import bisect
for p,y in q:
    print("%06d%06d" %(p, bisect.bisect_left(pref[p], y)))

Solution (Python):
import sys
input=sys.stdin.readline
 
N,M = map(int, input().split())
 
pref = [[0] for i in range(N+1)]
import collections
q = collections.deque()
 
for i in range(M):
    p,y = map(int, input().split())
    pref[p].append(y)
    q.append((p,y))
for p in pref:
    p.sort()
 
import bisect
for p,y in q:
    print("%06d%06d" %(p, bisect.bisect_left(pref[p], y)))

Solution (Python):
from operator import itemgetter
 
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
for i in range(M):
    P[i], Y[i] = map(int, input().split())
n = [i for i in range(M)]
 
P, Y, n = zip(*sorted(zip(P, Y, n), key=itemgetter(0, 1)))
 
count = 1
ans = []
ans.append(str(P[0]).zfill(6) + str(count).zfill(6))
 
for i in range(M - 1):
    if P[i + 1] == P[i]:
        count += 1
    else:
        count = 1
    ans.append(str(P[i + 1]).zfill(6) + str(count).zfill(6))
 
n, ans = zip(*sorted(zip(n, ans), key=itemgetter(0)))
 
for i in ans:
    print(i)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    N,M = map(int, input().split())
    PY = [list(map(int, input().split())) for i in range(M)]
    for i in range(M):
        PY[i].append(i)
    PY = sorted(PY, key=lambda x:x[1])
    PY = sorted(PY, key=lambda x:x[0])
    
    now = PY[0][0]
    num = 0
    for i in range(M):
        if PY[i][0] == now:
            num += 1
        else:
            now = PY[i][0]
            num = 1
        P = str(PY[i][0])
        stnum = str(num)
        ID = "0"*(6 - len(P)) + P + "0"*(6 - len(stnum)) + stnum
        PY[i].append(ID)
    PY = sorted(PY, key=lambda x:x[2])
    
    for i in range(M):
        print(PY[i][3])
    
    
    
    
    
    
main()

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

l = [0]*(n)
for i in range(m):
  l[PY[i][0]-1]+=1
  PY[i].append(l[PY[i][0]-1])

  
PY.sort(key = lambda x:x[2])
for i in range(m):
  print('{:0=6}'.format(PY[i][0])+'{:0=6}'.format(PY[i][3]))

Solution (Python):
import sys
input = lambda: sys.stdin.readline()[:-1]
n,m=map(int,input().split())
data=[list(map(int,input().split())) for i in range(m)]
for i in range(m):
	data[i].append(i)
data.sort(key=lambda tup:(tup[0],tup[1]))
ansdata=[0]*m
now,count=0,0
for e in data:
	if now==e[0]:
		count+=1
		ansdata[e[2]]='0'*(6-len(str(now)))+str(now)+'0'*(6-len(str(count)))+str(count)
	else:
		now=e[0]
		count=1
		ansdata[e[2]]='0'*(6-len(str(now)))+str(now)+'0'*(6-len(str(count)))+str(count)

for i in ansdata:
	print(i)

Solution (Python):
def main():
    import bisect
    n, m = map(int, input().split())
    query = []
    result =  [[] for i in range(n)]
    for i in range(m):
        qList = list(map(int, input().split()))
        query.append(qList)
        result[qList[0]-1].append(qList[1])
 
    for i in result:
        i.sort()
 
    for city in query:
        rank = bisect.bisect_left(result[city[0]-1], city[1])
        ans = "%06d%06d"%(city[0],rank+1)
        print(ans)
 
if __name__ == "__main__":
    main()

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

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

    result = [sorted(i) for i in result]
 
    for city in query:
        rank = bisect.bisect_left(result[city[0]-1], city[1])
        ans = "%06d%06d"%(city[0],rank+1)
        print(ans)

main()

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):
def main():
    from sys import stdin
    from bisect import bisect_left

    readline = stdin.readline
    n, m = map(int, readline().split())
    data = [list(map(int, readline().split())) for _ in range(m)]
    t = [[] for _ in range(n)]

    for p, y in data:
        t[p - 1].append(y)

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

    for p, y in data:
        nth = bisect_left(t[p - 1], y) + 1
        print("%06d%06d" % (p, nth))

main()

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

PY1 = sorted(PY)


for i in range(M):
  X = str(PY1[i][0])
  if i >= 1:
    
    if PY1[i][0] == PY1[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY1[i][1] = str(X) + str(Y) 

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

for i in range(M):
  print(PY2[i][1])

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

cities = []
ps = {}

def to_id(x):
  return '0' * (6 - len(str(x))) + str(x)

for i in range(m):
  p, y = map(int, input().split())
  cities.append([p, y, ''])
  if p in ps.keys():
    ps[p].append([y, i])
  else:
    ps[p] = [[y, i]]
  
years = {}
ids = {}
for p in ps.keys():
  years[p] = sorted(ps[p], key=lambda x: x[0])
  for i, year in enumerate(years[p]):
    cities[year[1]][2] += to_id(p) + to_id(i+1)

for i in range(m):
  print(cities[i][2])

Solution (Python):
def main():
    n, m = map(int, input().split())
    p = [0] * m
    y = [0] * m
    dic = {}
    cities = [[] for _ in range(n)]
    x = [0] * m
    for i in range(m):
        p[i], y[i] = map(int, input().split())
        cities[p[i] - 1].append(y[i])
        dic[y[i]] = i
    for i in cities:
        for ind, j in enumerate(sorted(i), 1):
            x[dic[j]] = ind
    for i in range(m):
        print("{:06}{:06}".format(p[i],x[i]))


if __name__ == '__main__':
    main()

Solution (Python):
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce



def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList



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

datatmp = sorted(data, key=lambda x:int(x[1]))
dataSorted = sorted(datatmp, key=lambda x:x[0])

tmpCheck = -1
tmpNum = 0

for i in range(m):
    if dataSorted[i][0]==tmpCheck:
        tmpNum += 1
    else:
        tmpNum = 1
    dataSorted[i].append(tmpNum)
    tmpCheck = dataSorted[i][0]


for i in range(m):
    tmp = str(data[i][0])
    for j in range(6-len(tmp)):
        tmp = '0'+tmp

    tmp2 = str(data[i][2])
    for j in range(6-len(tmp2)):
        tmp2 = '0'+tmp2

    print(tmp+tmp2)

Solution (Python):
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n, m = na()
buf = [None] * m
cnt = {k: [] for k in range(n + 1)}
for i in range(m):
    p, y = na()
    cnt[p].append((y, i))
for p, l in cnt.items():
    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))