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
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)

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

for i in range(M):
	p, y = map(int, input().split())
	city_list[p - 1].append(y)
	P[i] = p
	Y[i] = y
	
for i in range(N):
	city_list[i].sort()
	
for i in range(M):
	print('{:06}{:06}'.format(P[i], bisect.bisect_right(city_list[P[i] - 1], Y[i])))

Solution (Python):
from operator import itemgetter

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


City = sorted(City, key=itemgetter(2))
City = sorted(City, key=itemgetter(1))

ans = []
pre = 1
seq = 0
for c in City:
    y = c[1]
    if y > pre:
        seq = 1
        pre = y
    else:
        seq += 1
    ans.append([c[0], y, seq])

ans.sort(key=itemgetter(0))
for a in ans:
    pre = str(a[1])
    seq = str(a[2])
    print('0'*(6-len(pre)) + pre + '0'*(6-len(seq)) + seq)

Solution (Python):
n, m = map(int, input().split())
ls = [[0 for i in range(3)] for j in range(m)]
ans = [""] * m
for i in range(m):
    ls[i][0], ls[i][1] = map(int, input().split())
    ls[i][2] = i
a = sorted(ls, key=lambda x:x[1])
a = sorted(ls)
prefi = ""
cityi = "000001"
for i in range(6 - len(str(a[0][0]))):
    prefi += "0"
prefi += str(a[0][0])
ans[a[0][2]] = prefi + cityi
city = 2
for i in range(1, m):
    prefId = str(a[i][0])
    ansId = a[i][2]
    if(a[i-1][0] != a[i][0]):
        city = 1
    prefi = ""
    cityi = ""
    for i in range(6 - len(str(a[i][0]))):
        prefi += "0"
    prefi += prefId
    for i in range(6 - len(str(city))):
        cityi += "0"
    cityi += str(city)
    ans[ansId] = prefi+cityi
    city += 1
for i in ans:
    print(i)

Solution (Python):



from operator import itemgetter
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)
py.sort(key = itemgetter(1))
py.sort(key = itemgetter(0))

x = py[0][0]
c = 0
for i in range(m):
    if x != py[i][0]:
        c = 1
        x = py[i][0]
    else:
        c += 1
    py[i].append(c)
py.sort(key = itemgetter(2))
for i in range(m):
    front = '00000'+str(py[i][0])
    back = '00000'+str(py[i][3])
    print(front[-6:]+back[-6:])

Solution (Python):
n,m=map(int,input().split())
py=[]
for i in range(m):
    q=[int(j) for j in input().split()]
    py.append(q+[i])
from operator import itemgetter
py.sort(key=itemgetter(1))
py.sort(key=itemgetter(0))
ans=[]
q=0
c=2
for i,j,k in py:
    p=str(i).rjust(6,'0')
    if q==i:
        y=str(c).rjust(6,'0')
        c+=1
    else:
        y="000001"
        q=i
        c=2   
    ans.append([p+y,k])
from operator import itemgetter
ans.sort(key=itemgetter(1))
for i,j in ans:
    print(i)

Solution (Python):
from collections import defaultdict
from operator import itemgetter

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

d = defaultdict(list)
for query_idx in range(m):
    pref_idx, year = map(int, input().split())
    d[pref_idx].append((year, query_idx))

ans = [None] * m
for pref_idx in d.keys():
    d[pref_idx].sort(key=itemgetter(0))
    
    for city_idx, (year, query_idx) in enumerate(d[pref_idx], 1):
        ans[query_idx] = '{:0>6}{:0>6}'.format(pref_idx, city_idx)
print(*ans, sep='\n')

Solution (Python):
class City:
    def __init__(self, index: int, prefecture: int, year: int):
        self.index = index
        self.prefecture = prefecture
        self.year = year
        self.id = ''

    def __lt__(self, other):
        if self.prefecture != other.prefecture:
            return self.prefecture < other.prefecture
        return self.year < other.year

    def __repr__(self):
        return '({}, {})'.format(self.prefecture, self.year)


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

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

cities.sort()

p = 0
cnt = 1
for i in range(M):
    if p != cities[i].prefecture:
        p = cities[i].prefecture
        cnt = 1

    cities[i].id = '{:06d}'.format(p) + '{:06d}'.format(cnt)
    cnt += 1

cities.sort(key=lambda c: c.index)

for c in cities:
    print(c.id)

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

order=[1]*n
ans=[""]*m
PY=[]
for i in range(m):
    p,y=map(int,input().split())
    PY.append((y,p,i))

PY.sort()
for y,p,i in PY:
    s_p=str(p).zfill(6)
    y_p=str(order[p-1]).zfill(6)
    order[p-1]+=1

    ans[i]=s_p+y_p

for i in ans:
    print(i)

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.sort(key=lambda x:x[1])
py.sort(key=lambda x:x[0])
x = py[0][0]
j=0
for i in range(m):
    if x != py[i][0]:
        j = 1
        x = py[i][0]
    else:
        j+=1
    s = str(py[i][0]).zfill(6) + str(j).zfill(6)
    py[i].append(s)
py.sort(key=lambda x:x[2])
for i in range(m):
    print(py[i][3])

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

city = [[] for i in range(M)]
city_id = ["" for i in range(M)]
count = [0] * N

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

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

for i in range(M):
     ken, year, num = city[i]
     count[ken-1] += 1
     city_id[num] = "{:0=6}{:0=6}".format(ken, count[ken-1])

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

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


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


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

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


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


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

Solution (Python):
from operator import itemgetter
n, m = list(map(int, input().split()))
pyl = [tuple(map(int, input().split())) for _ in range(m)]

pyd = {pyl[i]:i for i in range(m)}
pyl.sort(key=itemgetter(1))
pref = {i+1:1 for i in range(n)}

ids = [["", 0] for _ in range(m)]
for i in range(m) :
    py = pyl[i]
    ids[i] = ["{:0=6}".format(py[0])+"{:0=6}".format(pref[py[0]]),
              pyd[py]]
    pref[py[0]] += 1

ids.sort(key=itemgetter(1))
for anid in ids :
    print(anid[0])

Solution (Python):
n,m,*py=map(int,open(0).read().split())
py = list(zip(py[::2],py[1::2],range(m)))
py.sort()
p = 0
c = 0
for i in range(m):
    if py[i][0] == p:
        c += 1
        py[i] += tuple([c])
    else:
        c = 1
        p = py[i][0]
        py[i] += tuple([1])
py.sort(key=lambda x:x[2])
[print("{:06}{:06}".format(i[0],i[3])) for i in py]

Solution (Python):
a, b = map(int, input().split())
c = []
for i in range(b):
    d, e = map(int, input().split())
    c.append([i, d, e, 0])
c = sorted(c, key=lambda x: x[2], reverse=False)
d = [0] * a
for i in range(b):
    d[c[i][1]-1] += 1
    c[i][3] = d[c[i][1]-1]
c.sort()
for i in range(b):
    print(("000000" + str(c[i][1]))[-6:] + ("000000" + str(c[i][3]))[-6:])

Solution (Python):
N, M = map(int, input().split())
py = [list(map(int, input().split())) + [i + 1] for i in range(M)]
py_sort = sorted(py)
py_sort[0][1] = 1
j = 2
for i in range(1, M):
    if py_sort[i - 1][0] != py_sort[i][0]:
        j = 1
    py_sort[i][1] = j
    j += 1
py = sorted(py_sort, key=lambda x: x[2])
for i in range(M):
    print(str(py[i][0]).zfill(6) + str(py[i][1]).zfill(6))

Solution (Python):
n, m = map(int, raw_input().split())
prefecs = [[] for i in range(n+1)]
queries = []
for _ in range(m):
    p, y = map(int, raw_input().split())
    queries.append((p, y))
    prefecs[p].append(y)
for i in range(1, n+1):
    prefecs[i].sort()
dic_list = [{} for i in range(n+1)]
for i in range(1, n+1):
    for j in range(len(prefecs[i])):
        dic_list[i][prefecs[i][j]] = j+1
for p, y in queries:
    print "%06d%06d" % (p, dic_list[p][y])

Solution (Python):
from operator import itemgetter
N, M = map(int, input().split())
PY = [list(map(int, input().split()))+[i] for i in range(M)]
PY.sort()
now = 1
cnt = 1
for j in range(M):
    if now != PY[j][0]:
        cnt = 1
        now = PY[j][0]
        PY[j].append(cnt)
    else:
        PY[j].append(cnt)
    cnt += 1
PY.sort(key=itemgetter(2))
for i in range(M):
    print(str(PY[i][0]).zfill(6) + str(PY[i][3]).zfill(6))

Solution (Python):
import itertools
import math

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

prefs = []
ids = {}

for i in range(n):
    prefs.append({})

for i in range(m):
    pref_num, year = map(int, input().split())
    prefs[pref_num-1].setdefault(i, year)

for i in range(n):
    sorted_cities = sorted(prefs[i].items(), key=lambda x: x[1])
    for j, city in enumerate(sorted_cities):
        ids.setdefault(city[0], (i, j))


sorted_ids = sorted(ids.items())

for data in sorted_ids:
    print(str(data[1][0]+1).zfill(6)+str(data[1][1]+1).zfill(6))

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

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

nums = [0] * N
ans = [''] * M

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

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

for a in ans:
    print(a)

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.sort(key=lambda x:x[1])
py.sort(key=lambda x:x[0])
x = py[0][0]
j=0
for i in range(m):
    if x != py[i][0]:
        j = 1
        x = py[i][0]
    else:
        j+=1
    s = str(py[i][0]).zfill(6) + str(j).zfill(6)
    py[i].append(s)
py.sort(key=lambda x:x[2])
for i in range(m):
    print(py[i][3])

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

PY.sort()

l = []
t = 0
for i in range(M):
    if t != PY[i][0]:
        t = PY[i][0]
        cnt = 1
    l.append([str(t).zfill(6) + str(cnt).zfill(6), PY[i][2]])
    cnt += 1

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

for i in range(M):
    print(l[i][0])

Solution (Python):
N, M = map(int, input().split())
city = [0]*M
for i in range(M):
    city[i] = [i] * 4
    prefecture, year = map(int, input().split())
    city[i][0], city[i][1] = year, prefecture

city = sorted(city)

ite = [1] * (N+1)
for k in range(M):
    city[k][3] = ite[city[k][1]]
    ite[city[k][1]] += 1
city = sorted(city, key=lambda x: x[2])
for j in range(M):
    print("{:0=12}".format(city[j][1]*1000000+city[j][3]))

Solution (Python):
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

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

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

N, M = list(map(int, sys.stdin.readline().split()))
P, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(M)]))

prefs = defaultdict(list)
for p, y in zip(P, Y):
    prefs[p].append(y)

for ys in prefs.values():
    ys.sort()

for p, y in zip(P, Y):
    idx = bisect.bisect_left(prefs[p], y) + 1
    print('{:06d}{:06d}'.format(p, idx))

Solution (Python):
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

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

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

N, M = list(map(int, sys.stdin.readline().split()))
P, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(M)]))

nums = defaultdict(int)
ans = [''] * M
for i in np.lexsort((Y, P)):
    nums[P[i]] += 1
    ans[i] = '{:06d}{:06d}'.format(P[i], nums[P[i]])
print('\n'.join(map(str, ans)))

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(key=lambda x:(x[0],x[1]))
ans = ["" for i in range(M)]
p = -1
y = 1
for a in A:
    if p!=a[0]:
        y = 1
        p = a[0]
    b = str(a[0]).rjust(6,"0")+str(y).rjust(6,"0")
    ans[a[2]] = b
    y+=1
for i in ans:
    print(i)

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(key=lambda x:(x[0],x[1]))
ans = ["" for i in range(M)]
p = -1
y = 1
for a in A:
    if p!=a[0]:
        y = 1
        p = a[0]
    b = "0"*(6-len(str(a[0])))+str(a[0])+"0"*(6-len(str(y)))+str(y)
    ans[a[2]] = b
    y+=1
for i in ans:
    print(i)

Solution (Python):
n,m = map(int, input().split())
l = [[] for _ in range(n)]
for i in range(m):
    p,y = map(int, input().split())
    l[p-1].append((y, i))
ans = [None]*m
for i,pre in enumerate(l):
    pre.sort()
    for j,(a,b) in enumerate(pre):
        ans[b] = "{:0>6}{:0>6}".format(i+1,j+1)
print("\n".join(ans))

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

for i in range(m):
    a,b = map(int,input().split())
    ls[a].append((b,i))
ans = [None]*m
for i,l in enumerate(ls):
    l.sort()
    for j,(a,b) in enumerate(l):
        ans[b]= "{:06d}{:06d}".format(i,j+1)
for i in range(m):
    print(ans[i])

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)

dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())


N, M = mi()
PYs = []
for i in range(M):
  p, y = mi()
  p -= 1 
  PYs.append((y, p, i)) 
PYs = sorted(PYs) 

PREFs = [0] * N 

for i, (eachy, eachp, eachi) in enumerate(PYs):
  PREFs[eachp] += 1
  PYs[i] = [eachp+1, PREFs[eachp], eachi] 




from operator import itemgetter
PYs = sorted(PYs, key=itemgetter(2)) 
for p, num, i in PYs:
  print('{:06}{:06}'.format(p, num))

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):
n,m = map(int,input().split())
li = [0]*m
for i in range(m):
  li[i] = list(map(int,input().split()))
  li[i].append(i)
  li[i].append(0)
li = sorted(li,key=lambda x:x[1])
li = sorted(li,key=lambda x:x[0])
pre = 0
conti = 0
for i in range(m):
  if pre != li[i][0]:
    pre = li[i][0]
    conti = 0
    li[i][3] = str(pre).zfill(6) + str(1).zfill(6)
  else:
    conti += 1
    li[i][3] = str(pre).zfill(6) + str(conti+1).zfill(6)
li = sorted(li,key = lambda x:x[2])
for i in range(m):
  print(li[i][3])

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

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

ans = [''] * m
p_prev = 0
k = 1
for j in range(m):
    p, y, i = city[j]
    ans[i] += '0' * (6 - len(str(p))) + str(p)
    if p == p_prev:
        k += 1
    else:
        k = 1
        p_prev = p
    ans[i] += '0' * (6 - len(str(k))) + str(k)

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

Solution (Python):
import bisect

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

vals = [[] for i in range(N)]

for i in range(M):
    p, y = table[i]
    vals[p-1].append(y)

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

for i in range(M):
    p, y = table[i]
    s = bisect.bisect_left(vals[p-1], y)+1
    print('%06d'%p + '%06d'%s)

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

C = []
for i in range(M):
    l = [i]
    x,y = map(int,input().split())
    l.append(x)
    l.append(y)
    C.append(l)

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

counter = [1 for i in range(N)]

for i in range(M):
    C[i][2] = counter[C[i][1]-1]
    counter[C[i][1]-1] += 1

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

for i in range(M):
    for j in range(6-len(str(C[i][1]))):
        print(0,end = "")
    print(C[i][1],end = "")
    for j in range(6-len(str(C[i][2]))):
        print(0,end = "")
    print(C[i][2])

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

PY = []
cnt = [0]*N

for i in range(M):
    p, y = map(int, input().split())
    PY.append([i, p, y])
    cnt[p-1] += 1
    
PY = sorted(PY, key=lambda x: x[1])

ans = []

for i in range(N):
    temp_shi = []
    for j in range(cnt[i]):
        temp_shi.append(PY[len(ans)+len(temp_shi)])
    
    temp_shi = sorted(temp_shi, key=lambda x: x[2])
    
    for j in range(cnt[i]):
        ans.append([temp_shi[j][0], str(i+1).zfill(6) + str(j+1).zfill(6)])

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

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

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


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

idx = List[0][0]
id_lst = []
n = 0
for i in range(M):
    if idx==List[i][0]:
        n+=1
        id_lst.append([format(idx, '06')+format(n, '06'), List[i][2]])
    else:
        idx = List[i][0]
        n=1
        id_lst.append([format(idx, '06')+format(n, '06'), List[i][2]])
        
id_lst = sorted(id_lst, key=lambda x:x[1])

for j in range(M):
    print(id_lst[j][0])

Solution (Python):
def main():
    N, M = map(int, input().split())
    answer = [0] * M
    pref = {}
    for i in range(M):
        P, Y = map(int, input().split())
        if P not in pref:
            pref[P] = []
        pref[P].append((i, Y))
    for p, arr in pref.items():
        arr.sort(lambda a: a[1])
        for i in range(1, len(arr)+1):
            item = arr[i-1]
            answer[item[0]] = ("0" * 5 + str(p))[-6:]
            answer[item[0]] += ("0" * 5 + str(i))[-6:]
    for i in range(M):
        print(answer[i])


if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
A=[]
count=[1]*1000000
ans=[]
for i in range(M):
    a, b, = map(int, input().split())
    A.append([b, a, i])

A.sort()

for i in range(M):
    number=A[i][1]*1000000+count[int(A[i][1])]
    ans.append([A[i][2],str(number).zfill(12)])
    count[int(A[i][1])] +=1
ans.sort()

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

Solution (Python):
n, m = list(map(int, input().split()))
ipy = []
num = [1 for i in range(n+1)]
ans = ["" for i in range(m)]
for i in range(m):
  p, y = list(map(int, input().split()))
  ipy.append([i, p, y])
ipy.sort(key=lambda x: x[2])
for i in range(m):
  ans[ipy[i][0]] = str(ipy[i][1]).zfill(6)+str(num[ipy[i][1]]).zfill(6)
  num[ipy[i][1]] += 1
for e in ans:
  print(e)

Solution (Python):



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

spy = list(sorted(py+[[p,0] for p in range(n+1)]))

zaatu = {(p,y):i for i, (p,y) in enumerate(spy)}


for p,y in py:
    print(format(p, '06')+format(zaatu[(p,y)]-zaatu[(p,0)], '06'))

Solution (Python):


from bisect import bisect_left


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

spy = list(sorted(py))

for p,y in py:
    l2 = bisect_left(spy,[p,y])
    l1 = bisect_left(spy,[p,0])
    print(format(p, '06')+format(l2-l1+1, '06'))

Solution (Python):
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 = []
P = [0] * (n + 1)
for p, y, i in py:
    P[p] += 1
    tmp = str(p).zfill(6) + str(P[p]).zfill(6)
    ans.append([i,tmp])
ans.sort()
for i,a in ans:
    print(a)

Solution (Python):
n, m = [int(i) for i in input().split()]
city = []
pref = [0 for i in range(n)]
for i in range(m):
    p, y = [int(_) for _ in input().split()]
    pref[p-1] += 1
    city.append([p,y,i])

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

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    ans = [""] * m
    arr = []
    cnt = 1
    for i in range(m):
        p, y = list(map(int, input().split()))
        arr += [(p, y, i)]
    arr = sorted(arr)

    ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
    for i in range(1, m):
        if arr[i - 1][0] == arr[i][0]:
            cnt += 1
        else:
            cnt = 1
        ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

    for i in ans:
        print(i)


if __name__ == "__main__":
    main()

Solution (Python):
N,M = map(int,input().split())
para = []
for i in range(M):
    a,b = map(int,input().split())
    para.append([a,b,i])
para.sort(key = lambda x:(x[0],x[1]))
ans = []
memo = [-1 for i in range(N+1)]
for i in range(M):
    if memo[para[i][0]] == -1 :
        cnt = 1
        a = format(para[i][0]).zfill(6) + format(cnt).zfill(6)
        ans.append([a,para[i][2]]) 
        memo[para[i][0]] = 0
    else : 
        cnt += 1
        a = format(para[i][0]).zfill(6) + format(cnt).zfill(6)
        ans.append([a,para[i][2]]) 
ans.sort(key=lambda x:x[1])
for i in range(M):
    print(ans[i][0])

Solution (Python):
n,m = map(int,input().split())
a = []
for i in range(m):
    array = list(map(int,input().split()))+[i+1]
    a.append(array)
lst = sorted(a)
num_city = 0
num_prf_old = lst[0][0]
ans_arr = []
for i in range(m):
    num_prf = lst[i][0]
    id_prf = str(num_prf).zfill(6)
    if num_prf != num_prf_old:num_city = 0
    num_city += 1
    id_city = str(num_city).zfill(6)
    num_prf_old = num_prf
    arr = [id_prf+id_city,lst[i][2]]
    ans_arr.append(arr)
lst_ans = sorted(ans_arr, key=lambda x: x[1])
for i in range(m):
    print(lst_ans[i][0])

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

birth.sort(key=lambda x:(x[1],x[2]))

birth[0].append(0)
cnt=0
for i in range(M-1):
    if birth[i][1]==birth[i+1][1]:
        cnt+=1
    else:
        cnt=0
    birth[i+1].append(cnt)

birth.sort(key=lambda x:x[0])
for i in range(M):
    ans=str(birth[i][1]).zfill(6)+str(birth[i][3]+1).zfill(6)
    print(ans)

Solution (Python):
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())



table = {}
for i in range(M):
    p = P[i]
    y = Y[i]
    data = (i, y)
    if p not in table:
        table[p] = [data]
    else:
        table[p].append(data)



for t in table:
    table[t].sort(key=lambda x: x[1])



ans = {}
for t in table:
    data = table[t]
    for i in range(len(data)):
        d = data[i]
        ans[d[0]] = (P[d[0]], i + 1)



for i in ans:
    a = ans[i]
    print('{:06d}{:06d}'.format(a[0], a[1]))

Solution (Python):
from collections import defaultdict
p_to_y = defaultdict(set)

N,M = map(int,input().split())
PY = [[int(x) for x in input().split()] for _ in range(M)]
for p,y in PY:
  p_to_y[p].add(y)

def set_to_rank_dict(se):
  return {x:i for i,x in enumerate(sorted(se), 1)}

p_to_y = {p:set_to_rank_dict(se) for p,se in p_to_y.items()}
for p,y in PY:
  print('{:06g}{:06g}'.format(p,p_to_y[p][y]))

Solution (Python):



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

sortPY=sorted(PY,key=lambda x: x[1])

city={}

for i in range(m):
	p=sortPY[i][0]
	if p in city:
		city[p]+=1
	else:
		city[p]=1
	sortPY[i][2]=city[p]


for i in range(m):
	print(str(PY[i][0]).zfill(6)+str(PY[i][2]).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 = [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):
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

groups = [[] for _ in range(N + 1)]
for p, y in PY:
	groups[p] += [y]

for i, g in enumerate(groups):
	g.sort()
	cities = {}
	for j, t in enumerate(g):
		cities[t] = j + 1
	groups[i] = cities

for p, y in PY:
	print("{:06d}{:06d}".format(p, groups[p][y]))

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

for num in range(m):
  tp = tuple(map(int,input().split()))
  query.append(tp)
  lis[tp[0]-1].append((tp[1],num))  

ans = [[0,0] for i in range(m)]

for num_p , pref in enumerate(lis):
  pref.sort(key = lambda tp:tp[0])
  for i,tp_city in enumerate(pref):
    ans[tp_city[1]][0] = num_p
    ans[tp_city[1]][1] = i+1

for item in ans:
  print("{:06}{:06}".format(item[0]+1,item[1]))

Solution (Python):
from heapq import heappush, heappop
N,M = map(int, input().split())
A = {}
prefs = []
years = []
for i in range(M):
    p,y = input().split()
    prefs.append(p)
    years.append(y)
    if p not in A:
        A[p] = [int(y)]
    else:
        heappush(A[p], int(y))
res = {}
for k,v in A.items():
    for i in range(len(v)):
        res[k+str(heappop(v))] = str(i+1)
for p,y in zip(prefs, years):
    print(p.zfill(6) + res[p+y].zfill(6))

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

ans = [None] * M
for i, c in enumerate(city):
    c.sort()
    for j, (y, k) in enumerate(c):
        ans[k] = str(i+1).zfill(6) + str(j+1).zfill(6)

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

Solution (Python):
n, m = [int(x) for x in input().split()]

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

res = [None] * m
for i, ms in enumerate(ps):
    ms.sort()
    for j, x in enumerate(ms):
        res[x[1]] = str(i+1).zfill(6) + str(j+1).zfill(6)

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

Solution (Python):
from collections import defaultdict

N, M = map(int, input().split())
YPID = [[0, 0, 0, ''] for _ in range(M)]
import sys
input = sys.stdin.readline
for i in range(M):
    pp, mm = map(int, input().split())
    YPID[i][0] = mm
    YPID[i][1] = pp
    YPID[i][2] = i
YPID.sort()
ID = defaultdict(int)

for ypid in YPID:
    ID[ypid[1]] += 1
    ypid[3] = str(ypid[1]).zfill(6) + str(ID[ypid[1]]).zfill(6)

YPID.sort(key=lambda x: x[2])
for ypid in YPID:
    print(ypid[3])

Solution (Python):
N, M = map(int, input().split())
D = [[] for i in range(N)]
for i in range(M):
  p, y = map(int, input().split())
  D[p-1].append((y, i)) 
ans = [None]*M
for i, d in enumerate(D): 
  d.sort()
  for k, (y, j) in enumerate(d): 
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6) 
print(*ans, sep = '\n')

Solution (Python):
import bisect
n,m = map(int,input().split())
d = {}
for i in range(1,n+1):
    d[i] = []
c = []
l = []
for _ in range(m):
    x,y = map(int,input().split())
    c.append([x,y])
    l.append([x,y])
c = sorted(c)
for i in range(len(c)):
    d[c[i][0]].append(c[i][1])
for i in range(len(l)):
    p = '0'*(6-len(str(l[i][0])))+str(l[i][0])
    o = bisect.bisect_left(d[l[i][0]],l[i][1])
    q = '0'*(6-len(str(o+1)))+str(o+1)
    print(p+q)

Solution (Python):
import math
import fractions
import copy
import numpy as np

def j(q):
    if q==1: print("POSSIBLE")
    elif q == 0:print("IMPOSSIBLE")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)



n,m= (int(i) for i in input().split())       











a = []
for i in range(m):
    b = [int(i) for i in input().split()]
    b.append(i)
    a.append(b)
a.sort()
city = a[0][0]
ct = 0
c = []
for i in range(m):
    if city != a[i][0]:
        city = a[i][0]
        ct =1
    else:ct+=1
    cna = str(city)
    cnb = str(ct)
    cna = cna.zfill(6)
    cnb = cnb.zfill(6)
    name = ''.join([cna,cnb])
    c.append([a[i][2],name])
c.sort()
for i in range(m):
    print(c[i][1])

Solution (Python):
n,m=list(map(int,input().split()))
city=[]
for i in range(m):
    city.append(list(map(int,input().split()))+[i])
city.sort()
ans=[]
count=0
precity=city[0][0]
for i in city:
    if i[0]==precity:
        count+=1
    else:
        precity=i[0]
        count=1
    ans.append([i[2],str(i[0]).zfill(6)+str(count).zfill(6)])
ans.sort()
for i in ans:
    print(i[1])

Solution (Python):
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 = []
P = [0] * (N + 1)
for p, y, i in PY:
    P[p] += 1
    tmp = str(p).zfill(6) + str(P[p]).zfill(6)
    ans.append([i, tmp])
ans.sort()
for i, a in ans:
    print(a)