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())
ipyx=[]
for _ in range(m):
  p_,y_ = map(int,input().split())
  ipyx.append([_+1,p_,y_,0])
"""
2 3
1 32
2 63
1 12
->
000001000002
000002000001
000001000001

2 3
2 5
2 77
2 99
->
000002000001
000002000002
000002000003
"""

A=[1]*(n+1)
ipyx.sort(key=lambda x:x[2])
for j in ipyx:
  j[3] = A[j[1]]
  A[j[1]] += 1
ipyx.sort(key=lambda x:x[0])
for j in ipyx:
  print(('00000'+str(j[1]))[-6:]+('00000'+str(j[3]))[-6:])

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

for i in range(M):
  pyi.append(list(map(int, input().split())))
  pyi[i].append(i)
  
N_cnt = [0] * N

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

for i in range(M):
  p = pyi[i][0]
  N_cnt[p-1] += 1
  pyi[i][0] = str(p).zfill(6)
  pyi[i][1] = str(N_cnt[p-1]).zfill(6)
  
pyi = sorted(pyi, key=lambda x:x[2])

for i in range(M):
  print(pyi[i][0] + pyi[i][1])

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

for i in range(M):
    P_Y_I[i].append(i+1)

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

N_count = [0 for k in range(N)]
for i in range(M):
    p = P_Y_I[i][0]
    N_count[p-1] += 1
    P_Y_I[i][0] = str(p).zfill(6)
    P_Y_I[i][1] = str(N_count[p-1]).zfill(6)

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

for i in range(M):
    print(P_Y_I[i][0]+P_Y_I[i][1])

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from bisect import bisect_left as bl

def main():
    n, m = MII()
    py = [tuple(MII()) for _ in range(m)]
    py_dict = dict(zip(range(10**5+1), [[0] for _ in range(10**5+1)]))
    for p, y in py: py_dict[p].append(y)
    for p, yy in py_dict.items():
        if yy != [0]: yy.sort()
    for p, y in py:
        idx = bl(py_dict[p], y)
        print(str(p).zfill(6)+str(idx).zfill(6))

if __name__ == '__main__':
    main()

Solution (Python):

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

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

for i in range(N):
  if Y[i]:
    Y[i].sort(key=lambda x: x[0])

ans=[]
for i in range(N):
  for j,L in enumerate(Y[i]):
    p,y,n=i+1, L[0],L[1]
    ans.append((n,p,j+1))
ans=sorted(ans)
for n,p,y in ans:
  a=(6-len(str(p)))*"0"+str(p)+(6-len(str(y)))*"0"+str(y)
  print(a)

Solution (Python):
n,m = map(int,input().split())
pref_year = [[] for _ in range(n+1)]
for i in range(1,m+1):
    p,y = map(int,input().split())
    pref_year[p].append((y,i))
ans = []
for p,li in enumerate(pref_year):
    if li:
        li.sort()
        for num,j in enumerate(li):
            ans.append((j[1],str(p).zfill(6)+str(num+1).zfill(6)))
ans.sort()
for i in ans:
    print(i[1])

Solution (Python):
n,m = map(int,input().split())
base_1 = []
key = {}
ans_str = []
ans_n = []

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

for i in range(m):
  p_str = str(base_1[i][0])
  len_p = len(list(p_str))
  temp = "p"+p_str
  
  if temp not in key:
    key[temp] = 1
    count = str(1)
  else :
    a = key[temp]
    key[temp] = a + 1
    count = str(key[temp])
    
  len_count = len(list(count))
  
  for j in range(6-len_p):
    p_str = "0" + p_str
    
  for j in range(6-len_count):
    count = "0" + count
    
  base_1[i].append(p_str + count)
    
base_1.sort(key = lambda x:x[2])

for i in range(m):
  print(base_1[i][3])

Solution (Python):
n, m = map(int, input().split())
a = []
b = [[] for i in range(n)]
for i in range(m):
	p, y = map(int, input().split())
	a.append([p,y])
	b[p-1].append(y)
dic = {}
for i in range(n):
	b[i].sort()
	for j,k in enumerate(b[i]):
		dic[k] = j+1

for i, j in a:
	print ("{:06d}".format(i) + "{:06d}".format(dic[j]))

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

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


prefecture=[[] for _ in range(N)]
for el in PY:
    p, y, num = el
    prefecture[p-1].append((y, num))


ans=[None]*M
for j, p in enumerate(prefecture):
    for i, city in enumerate(p):
        ans[city[1]] = str(j+1).zfill(6) + str(i+1).zfill(6)

for val in ans:
    print(val)

Solution (Python):
from collections import namedtuple, defaultdict
from bisect import bisect

City = namedtuple('City', 'y p')

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

cities = []
cities_by_P = defaultdict(list)

for _ in range(M):
  p, y = map(int, input().split())
  city = City(y, p)
  cities.append(city)
  cities_by_P[p].append(city)
  
for p in cities_by_P.keys():
  cities_by_P[p].sort()


for city in cities:
  i = bisect(cities_by_P[city.p], city)
  print('%06d' % city.p + '%06d' % i)

Solution (Python):
N,M=map(int,input().split())
PY=[]
for i in range(M):
  p,y=map(int,input().split())
  PY.append([i,p,y])
ans=['']*M
PY1=sorted(PY,key=lambda x:x[2])
dict={}
for i in range(M):
  ans[PY1[i][0]]+=str(PY1[i][1]).zfill(6)
  if not (PY1[i][1] in dict):
    ans[PY1[i][0]]+='1'.zfill(6)
    dict[PY1[i][1]]=1
  else:
    ans[PY1[i][0]]+=str(int(dict[PY1[i][1]])+1).zfill(6)
    dict[PY1[i][1]]+=1
for i in range(M):
  print(ans[i])

Solution (Python):
N,M = map(int,input().split())
d=[0]*M
res = []
for i in range(M):
    P,Y = map(int,input().split())
    res.append((P,Y,i))
c=0
res.sort()
t = str(res[0][0])
for i in res:
    x = str(i[0])
    if x == t:
        c+=1
    else:
        c=1
        t = x
    d[i[2]] = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)

for i in d:
    print(i)

Solution (Python):
N,M = map(int,input().split())
d=[0]*M
res = []
for i in range(M):
    P,Y = map(int,input().split())
    res.append((P,Y,i))
c=0
res.sort()
t = str(res[0][0])
for i in res:
    x = str(i[0])
    tmp = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)
    if x == t:
        c+=1
    else:
        c=1
        t = x
    d[i[2]] = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)

for i in d:
    print(i)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n,m = map(int, input().split())
    py = [list(map(int, input().split())) for _ in range(m)]
    
    l = [[] for _ in range(n+1)]
    for p, y in py:
        l[p].append(y)
    for i in range(n+1):
        l[i].sort()
    for p, y in py:
        a = bisect_left(l[p], y) + 1
        print('{:06d}{:06d}'.format(p, a))



if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n,m = map(int, input().split())
    py = [list(map(int, input().split())) for _ in range(m)]
    
    l = [[] for _ in range(n+1)]
    for p, y in py:
        l[p].append(y)
    for i in range(n+1):
        l[i].sort()
    for p, y in py:
        a = bisect_left(l[p], y) + 1
        print('{:06d}{:06d}'.format(p, a))



if __name__ == '__main__':
    main()

Solution (Python):
import bisect
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(m)]
ls = sorted(l,key=lambda x:x[1])
dict = {}
for i in ls:
    p,y = i
    if not p in dict.keys():
        dict[p] = []
        dict[p].append(y)
    else:
        dict[p].append(y)
for j in l:
    p,y = j
    print('{:0=6}'.format(p)+'{:0=6}'.format(bisect.bisect_left(dict[p],y) + 1))

Solution (Python):
from collections import deque
from collections import Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect



import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, m = map(int, readline().split())
  py = [[int(x) for x in readline().split()] for _ in range(m)]
  p_to_y = defaultdict(set)
  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}{:06}'.format(p,p_to_y[p][y]))
  
  
  
  
if __name__ == '__main__':
  main()

Solution (Python):
import bisect
n, m = [int(x) for x in input().split()]
city = [[int(x) for x in input().split()] for i in range(m)]
city_sd = sorted(city, key=lambda y:y[1])
dict = {}
for c in city_sd:
  p, y = c
  if not p in dict.keys():
    dict[p] = []
    dict[p].append(y)
  else:
    dict[p].append(y)
for c in city:
  p, y = c
  print('{:0=6}'.format(p)+'{:0=6}'.format(bisect.bisect_left(dict[p], y) + 1))

Solution (Python):
n, m = map(int, input().split())
ans = [0] * m
G = [[] for _ in range(n + 1)]
for i in range(m):
    p, y = map(int, input().split())
    G[p].append([y, i])
for i in range(1, n + 1):
    g = G[i]
    g.sort()
    for j in range(len(g)):
        f = g[j]
        s = ["0"] * (6 - len(str(i))) + [str(i)]
        t = ["0"] * (6 - len(str(j + 1))) + [str(j + 1)]
        ans[f[1]] = "".join(s + t)
for i in ans:
    print(i)

Solution (Python):
mod = 10 ** 9 + 7
mod2 = 2**61+1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

def iip(listed=True):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iip_ord():
    return [ord(i) - ord("a") for i in input()]


def main():
    ans = solve()
    if ans is not None:
        print(ans)

def solve():
    N, M = iip(False)


    data = []
    for i in range(M):
        p, y = iip()
        data.append((p, y, i))

    nn = {}
    data.sort(key=lambda x:x[1])
    for i in data:
        nn[i[0]] = 0

    result = []
    for i in data:
        nn[i[0]] += 1
        a = i[0] * 10**6 + nn[i[0]]
        a = str(a).zfill(12)
        result.append((a, i[2]))

    result.sort(key=lambda x:x[1])
    result = [i[0] for i in result]
    split_print_enter(result)





def fprint(s):
    for i in s:
        print(i)

def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Solution (Python):
n,m=(int(i) for i in input().split())
p=[[int(i) for i in input().split()] for i in range(m)]
c=[0]*(n)
i={}
for pe,pk in sorted(p, key=lambda x: x[1]):
  c[pe-1]+= 1
  i[pk]='%06d%06d' % (pe, c[pe-1])
for _,pk in p:
  print(i[pk])

Solution (Python):
n,m=map(int,input().split())
py=[[0,0,0]]*m
for i in range(m):
  py[i]=list(map(int,input().split()))+[i]
ans=['']*m
a=sorted(py)
j=0
for i in range(len(a)):
  if i>0 and a[i-1][0]<a[i][0]:
    j=1
  else:
    j+=1
  ans[a[i][2]]='{:06}'.format(a[i][0])+'{:06}'.format(j)
for i in range(m):
  print(ans[i])

Solution (Python):
N,M=map(int,input().split())
ids=[]
x=[]
numofpref=1
for i in range(M):
    p,y=map(int,input().split())
    ids.append([p,y,i,0])

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

for i in range(M):
    if i==0:
        x[i][3]="".join((str(x[i][0]).zfill(6),str(numofpref).zfill(6)))
        numofpref=numofpref+1
    else:
        if x[i][0]!=x[i-1][0]:
            numofpref=1
        x[i][3]="".join((str(x[i][0]).zfill(6),str(numofpref).zfill(6)))
        numofpref=numofpref+1
x.sort(key=lambda x:x[2])
for i in range(M):
    print(x[i][3])

Solution (Python):
def main():
    import bisect
    n, m, *py = map(int, open(0).read().split())
    d = [[] for _ in range(n+1)]
    for i,j in zip(*[iter(py)]*2):
        d[i].append(j)

    for i in d:
        i.sort()

    ans = ''
    for i, j in zip(*[iter(py)] * 2):
        k = bisect.bisect_right(d[i], j)
        ans += str(i).zfill(6) + str(k).zfill(6) + '\n'

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import bisect
    n, m, *py = map(int, open(0).read().split())
    d = [[] for _ in range(n + 1)]
    for i, j in zip(*[iter(py)] * 2):
        d[i].append(j)

    for i in d:
        i.sort()

    ans = ''
    for i, j in zip(*[iter(py)] * 2):
        k = bisect.bisect_right(d[i], j)
        id = str(i).zfill(6) + str(k).zfill(6)
        ans += id + '\n'

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):


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

n,m = LI()
py = [LI()+[i] for i in range(m)]

py.sort(key = lambda x:(x[0],x[1]))
ans = []
flag = True
cnt = 0
for p,y,i in py:
    s = '0'*6
    t = '0'*6
    if flag:
        cnt += 1
        tmp = p
        flag = False
    elif tmp == p:
        cnt += 1
    else:
        cnt = 1
        tmp = p
    s += str(p)
    s = s[-6:]
    t += str(cnt)
    t = t[-6:]
    ans.append([s+t,i])
ans.sort(key = lambda x:x[1])
for i,j in ans:
    print(i)

Solution (Python):


import numpy as np




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

PY = np.array(PY)
cn = np.array([np.arange(np.shape(PY)[0])])
cc = np.array([np.zeros(np.shape(PY)[0], dtype=int)])

city_list = np.hstack([cn.T, PY, cc.T])
cl_ysort = city_list[np.argsort(city_list[:, 2])]
city_count = np.zeros(N+1, dtype=int)
for i, cinfo in enumerate(cl_ysort):
    pref = cinfo[1]
    city_count[pref] += 1
    cl_ysort[i, 3] = city_count[pref]

cl_idsort = cl_ysort[np.argsort(cl_ysort[:, 0])]

[print('{:06d}{:06d}'.format(cl[1], cl[3])) for cl in cl_idsort]

Solution (Python):
N,M = map(int,input().split())
PYlist = []
for i in range(M):
    PYlist_ele = list(map(int,input().split()))
    PYlist_ele.append(i+1)
    PYlist.append(PYlist_ele)
PYlist.sort()
check = 0
count = 0
P_id = []
for i in range(M):
    if check == PYlist[i][0]:
        count +=1
    else:
        count = 1
        check = PYlist[i][0]
    idup = '{:06}'.format(PYlist[i][0])
    iddown = '{:06}'.format(count)
    P_id.append([str(idup)+str(iddown),PYlist[i][2]])
P_id.sort(key=lambda x: x[1])
for ans in P_id:
    print(ans[0])

Solution (Python):
import copy
n,m = map(int,input().split())
a = []
ans = dict()
for i in range(m):
    p,y = map(int,input().split())
    a.append((p,y))
adc = copy.deepcopy(a)
a.sort()
cnt = 1
for i in range(m-1):
    num = str(a[i][0]).zfill(6) + str(cnt).zfill(6)
    ans[a[i]] = num
    if a[i+1][0] != a[i][0]:
        cnt = 1
    else:
        cnt += 1
num = str(a[-1][0]).zfill(6) + str(cnt).zfill(6)
ans[a[-1]] = num
for i in range(m):
    print(ans[(adc[i][0], adc[i][1])])

Solution (Python):
n, m = map(int, input().split())
p_y_num_list = sorted([list(map(int, input().split())) + [i] for i in range(m)])
now = p_y_num_list[0][0]
num = 1
for pyn in p_y_num_list:
    if pyn[0] != now:
        num = 1
        now = pyn[0]
        pyn.append(num)
    else:
        pyn.append(num)
    num += 1
p_y_num_list.sort(key=lambda x: x[2])
for p, y, i, n in p_y_num_list:
    print("{:06}{:06}".format(p, n))

Solution (Python):
import bisect as bis
n, m = map(int, input().split())
p, y = [], []
idx = lambda x: x-1
for _ in range(m):
    p_, y_ = map(int, input().split())
    p.append(p_)
    y.append(y_)
val = [[] for _ in range(n)]
for i in range(m):
    val[idx(p[i])].append(y[i])
for i in range(n):
    val[i].sort()
for i in range(m):
    v = p[i]
    id = bis.bisect_right(val[idx(v)], y[i])
    print(str(v).zfill(6) + str(id).zfill(6))

Solution (Python):
import bisect as bis
n, m = map(int, input().split())
idx = lambda x: x-1
p, y = [], []
for _ in range(m):
    p_, y_ = map(int, input().split())
    p.append(p_)
    y.append(y_)
val = [[] for _ in range(n)]
for i, j in zip(p, y):
    val[idx(i)].append(j)
for i in range(n):
    val[i].sort()
for i in range(m):
    v = p[i]
    id = bis.bisect_right(val[idx(v)], y[i])
    print(str(v).zfill(6) + str(id).zfill(6))

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

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

liss = sorted(lis)
dic = {}
cnt = [0] * n

for i in range(m):
    x, y = liss[i]
    cnt[x - 1] += 1
    xx, yy, cc = str(x), str(y), str(cnt[x - 1])
    id = "0" * (6-len(xx)) + xx + "0" * (6-len(cc)) + cc
    dic[xx + "_" + yy] = id

for x, y in lis:
    xx, yy = str(x), str(y)
    print(dic[xx + "_" + yy])

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

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

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



tmp_list = [0]*m
tmp_num = 1
for num,j in enumerate(city_list):
    if num == 0:
        tmp_list[j[2]] = str(j[0]).zfill(6)+str(tmp_num).zfill(6)
        j_tmp = j[0]
        tmp_num += 1
    else:
        if j[0] != j_tmp:
            j_tmp = j[0]
            tmp_num = 1
            tmp_list[j[2]] = str(j[0]).zfill(6)+str(tmp_num).zfill(6)
            tmp_num += 1
        else:
            tmp_list[j[2]] = str(j[0]).zfill(6)+str(tmp_num).zfill(6)
            tmp_num += 1

for k in tmp_list:
    print(k)

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

for i in range(M):
  P,Y=map(int,input().split())
  li.append([P,Y,i])
li.sort(key=lambda x:x[1])
li.sort(key=lambda x:x[0])
pre=li[0][0]
cnt=1
ans=[]

for p,y,i in li:
  if p==pre:
    ans.append([str(p).zfill(6)+str(cnt).zfill(6),i])
    cnt+=1
  else:
    pre=p
    ans.append([str(p).zfill(6)+str(1).zfill(6),i])
    cnt=2
ans.sort(key=lambda x:x[1])

for a,i in ans:
  print(a)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


class City:
    def __init__(self, id, p, y):
        self._id = id
        self._p = p
        self._y = y
        self._x = 0


def main():
    
    N, M = Scanner.map_int()
    cities = []
    for i in range(M):
        p, x = Scanner.map_int()
        cities.append(City(i, p, x))
    cities.sort(key=lambda c: c._y)
    M = defaultdict(int)
    for c in cities:
        M[c._p] += 1
        c._x = M[c._p]
    cities.sort(key=lambda c: c._id)
    for c in cities:
        print('{:0>6}{:0>6}'.format(c._p, c._x))


if __name__ == "__main__":
    main()

Solution (Python):
n,m=map(int,input().split())
l=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    l[a-1].append([b,i])
ans=[0]*m
for idx,i in enumerate(l,1):
    i.sort(key=lambda x:x[0])
    pref=''
    if len(str(idx))<6:
        diff=6-len(str(idx))
        pref=('0'*diff)+str(idx)
    else:
        pref=str(idx)
    
    for j,k in enumerate(i,1):
        suff=''
        if len(str(j))<6:
            diff=6-len(str(j))
            suff=('0'*diff)+str(j)
        else:
            suff=str(j)

        ans[k[1]]=pref+suff
for i in ans:
    print(i)

Solution (Python):
n,m = map(int,input().split())
li = []
for i in range(m):
    p,y = map(int,input().split())
    li.append([p,y,i])
li.sort(key= lambda x:x[1])
li.sort(key= lambda x:x[0])
pre = li[0][0]
cnt = 1
ans = []
for p,y,i in li:
    if p==pre:
        ans.append(   (str(p).zfill(6) + str(cnt).zfill(6) ,i))
        cnt+=1
    else:
        pre = p
        ans.append((str(p).zfill(6) + str(1).zfill(6),i))
        cnt=2
ans.sort(key=lambda x:x[1])
for a,i in ans:
    print(a)

Solution (Python):
n,m = map(int,input().split())
ls = []
for i in range(m):
    p,y = map(int,input().split())
    ls.append([p,y,i])
ls.sort(key= lambda x:x[1])
ls.sort(key= lambda x:x[0])
pre = ls[0][0]
cnt = 1
ans = []
for p,y,i in ls:
    if p==pre:
        ans.append(   (str(p).zfill(6) + str(cnt).zfill(6) ,i))
        cnt+=1
    else:
        pre = p
        ans.append((str(p).zfill(6) + str(1).zfill(6),i))
        cnt=2
ans.sort(key=lambda x:x[1])
for a,i in ans:
    print(a)

Solution (Python):
from sys import stdin

N, M = map(int, stdin.readline().split())
py = [list(map(int, stdin.readline().split())) for _ in range(M)]

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

py.sort()

px = []

ptmp = 0
xtmp = 1

for p, y, i in py:
    if p == ptmp:
        xtmp += 1
    else:
        ptmp = p
        xtmp = 1
    px.append([str(p).zfill(6) + str(xtmp).zfill(6), i])


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

for out, i in px:
    print(out)

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

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

dic = {}
for p in range(N+1):
    P[p] = sorted(P[p])
    for i, y in enumerate(P[p]):
        i += 1
        dic[y] = '{}{}'.format(str(p).zfill(6), str(i).zfill(6))

for i in range(M):
    p, y = ite[i]
    print(dic[y])

Solution (Python):
N,M = map(int,input().split())
PY = {n: [] for n in range(N + 1)}
ans = [0]*M
for i in range(M):
  p,y = map(int,input().split())
  PY[p].append((y, i))
for p,y in PY.items():
  y.sort()
  for j, (z, i) in enumerate(y):
    top_number = '0'*(6-len(str(p)))+str(p)
    under_number = '0'*(6-len((str(j+1))))+str(j+1)
    ans[i] = top_number + under_number
for i in range(M):
  print(ans[i])

Solution (Python):
n,m = map(int,input().split())
py = sorted([list(map(int,input().split()))+[i] for i in range(m)])
cnt = 1
ans_list = [['0'*(6 - len(str(py[0][0])))+str(py[0][0])+'000001',py[0][2]]]
for i in range(1,m):
  ans = '0'*(6 - len(str(py[i][0])))
  ans += str(py[i][0])
  if py[i-1][0] == py[i][0]:
    cnt += 1
  else:
    cnt = 1
  ans += '0'*(6 - len(str(cnt)))
  ans += str(cnt)
  ans_list.append([ans,py[i][2]])
ans_list = sorted(ans_list,key=lambda x:x[1])
for i in ans_list:
  print(i[0])

Solution (Python):
n, m = map(int, input().split())
y_inputs = []
dct = dict()
for _ in range(m):
  p, y = map(int, input().split())
  y_inputs.append(y)
  if dct.get(p) == None:
    dct[p] = [y]
  else:
    dct[p].append(y)

citycodes = dict()
for pref in sorted(dct.items()):
  pid = int(pref[0])
  years = sorted(pref[1])
  for i, y in enumerate(years):
    code = format(pid, '06') + format(i+1, '06')
    citycodes[y] = code

for y in y_inputs:
  print(citycodes[y])

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

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

class City():
    def __init__(self, i, p, y):
        self.i = i
        self.p = p
        self.y = y
        self.x = None
        self.id = None
        
for i, (p, y) in enumerate(A):
    city = City(i, p, y)
    P[p].append(city)
    
for p, cities in enumerate(P):
    cities.sort(key=lambda x: x.y)
    for x, city in enumerate(cities):
        city.id = ('000000'+str(p))[-6:] + ('000000'+str(x+1))[-6:]
        city.x = x+1

P = [city for cities in P for city in cities]
P.sort(key=lambda x: x.i)

for city in P:
    print(city.id)

Solution (Python):
import sys








from operator import attrgetter, itemgetter





readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))
    pyir = [[0] * 4 for _ in range(m)]

    for i in range(m):
        p, y = list(map(int, readline().split()))
        pyir[i][0] = p
        pyir[i][1] = y
        pyir[i][2] = i

    pyir.sort(key=itemgetter(0,1))

    x = 0
    pprev = pyir[0][0]

    for i in range(m):
        if pprev != pyir[i][0]:
            x = 0
        x += 1
        pyir[i][3] = str(pyir[i][0]).zfill(6) + str(x).zfill(6)
        pprev = pyir[i][0]

    pyir.sort(key=itemgetter(2))

    for i in range(m):
        print(pyir[i][3])

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from builtins import int, map, list, print
    from collections import defaultdict, deque
    from bisect import bisect_left
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number_list = (lambda: list(map(int, input_list())))

    N, M = input_number_list()
    pref = [[0] for i in range(N + 1)]
    q = deque()
    for i in range(M):
        p, y = map(int, input_number_list())
        pref[p].append(y)
        q.append((p, y))
    for p in pref:
        p.sort()
    for p, y in q:
        print('{:06}{:06}'.format(p, bisect_left(pref[p], y)))


if __name__ == '__main__':
    main()

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

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

dic = {}

for n in range(N):
  lists[n].sort()  

for n in range(N):
  l = lists[n]
  count = 1
  for i in l:
    dic[i] = count
    count+=1

for p, y in items:
  print("{:06g}{:06g}".format(p,dic[y]))

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

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

res = []
p, pp = 0, 0
cnt = 0
for i in range(m):
    idx, p, _ = city[i]
    if i == 0:
        cnt = 1
        pp = p
    elif pp == p:
        cnt += 1
    else:
        pp = p
        cnt = 1

    ID = str(p).rjust(6, '0') + str(cnt).rjust(6, '0')
    res.append([idx, ID])

res = sorted(res, key=lambda x: x[0])
for i in res:
    print(i[1])