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 sys

def main():
    n, m = map(int, input().split())
    lines = sys.stdin.readlines()

    cities = {}
    for i in range(m):
        p, y = map(int, lines[i].split())
        if p in cities:
            cities[p].append((i, y))
        else:
            cities[p] = [(i, y)]

    outputs = [None] * m
    for pref, city_list in cities.items():
        city_list.sort(key=lambda x: x[1])
        
        city_no = 1
        for city in city_list:
            outputs[city[0]] = "{:06d}{:06d}".format(pref, city_no)
            city_no += 1

    for output in outputs:
        print(output)
    return


main()

Solution (Python):
n,m=map(int, input().split())
prefecture=[]
for i in range(m):
    pk,yk=map(int, input().split())
    prefecture.append([pk,yk,i])

prefecture.sort(key=lambda x:(x[0],x[1])) 
p_num=prefecture[0][0]
city_num=1
for i in range(m):
    if(prefecture[i][0]!=p_num):
        p_num=prefecture[i][0]
        city_num=1

    prefecture[i].append(city_num)
    city_num+=1

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

for i in range(m):
    print('{0:06d}{1:06d}'.format(prefecture[i][0], prefecture[i][3]))

Solution (Python):


if __name__ == '__main__':
    n, m = map(int, raw_input().split())
    cities = []
    for i in range(0, m):
        p, y = map(int, raw_input().split())
        cities.append((y, p, i))
    cities.sort()

    city_codes = [0] * (n + 1)
    postal_codes = [""] * m
    for j in range(0, m):
        y, p, i = cities[j]
        city_codes[p] += 1
        postal_codes[i] = "%06d%06d"%(p, city_codes[p])
    for postal_code in postal_codes:
        print postal_code

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

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

result_list = [0] * M
for i, py in enumerate(range_list):
    py.sort()
    for j, (y, p) in enumerate(py):
        result_list[p] = "%06d%06d" % (i+1, j+1)

print('\n'.join(result_list))

Solution (Python):
n, m = map(int, input().split())
l = []
for i in range(m):
    l.append([i] + list(map(int, input().split())))
l.sort(key=lambda x: (x[1], x[2]))
ans = []
pref = -1
for i in l:
    if pref != i[1]:
        cnt = 1
    pref = i[1]
    ans.append((i[0], i[1], cnt))
    cnt += 1
ans.sort()
for _, a, b in ans:
    print(str(a).zfill(6)+str(b).zfill(6))

Solution (Python):
N,M = map(int, input().split())
grid = []
for i in range(M):
    array = list(map(int, input().strip().split(' ')))
    grid.append([i+1,array[0],array[1]])
grid.sort(key=lambda x:x[2])

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

for arrays in grid:
  arrays.append(arrays[1]*1000000+dic[arrays[1]])
  dic[arrays[1]] += 1
  
grid.sort(key=lambda x:x[0])

for arrays in grid:
  s = str(arrays[3])
  print('0'*(12-len(s))+s)

Solution (Python):
N, M =map(int, input().split())
ls = []
pcount =[]
for i in range(N):
    pcount.append(0)
for i in range(M):
    p, y = map(int, input().split())
    ls.append([i, p, y])
ls.sort(key = lambda x:x[2])

for l in ls:
    pcount[l[1]-1] += 1
    l.append(pcount[l[1]-1])
ls.sort(key = lambda x:x[0])
for l in ls:
    print(str(l[1]).zfill(6) + str(l[3]).zfill(6))

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

for i in range(M):
    p,y = map(int, input().split())
    O.append([i+1, p, y])
O.sort(key=lambda x:x[2])
count=[0 for i in range(N)]

ans = []
for o in O:
    count[o[1]-1]+=1
    ans.append([o[0], o[1], count[o[1]-1]])
ans.sort(key=lambda x:x[0])

for v in ans:
    a1 = str(v[1])
    s = (6 - len(a1)) * "0"
    s += a1
    a2 = str(v[2])
    s += (6 - len(a2)) * "0"
    s += a2
    print( s )

Solution (Python):
import bisect

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

Indexs = {}
Syuturyoku = []
vp = []
vy = []

for j in range(N):
	P.append([0])


for i in range(M):
	p,y = map(int,input().split())
	vp.append(p)
	vy.append(y)

	P[p-1].append(y)
	Indexs[y] = i
	Syuturyoku.append(0)

for i in range(len(P)):
	P[i].sort()

for si in range(M):
	x = bisect.bisect_left(P[vp[si] - 1], vy[si])
	print('{:06}{:06}'.format(vp[si], x))

Solution (Python):

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

import sys
c = 0
d = {}
for line in sys.stdin:
    p, r = [int(x) for x in line.strip().split(" ")]
    if p not in d:
        d[p] = []
    d[p].append((c, r)) 
    c += 1
rs = [""] * M
for key in d:
    tt = sorted(d[key], key = lambda x : x[1])
    for i, t in enumerate(tt):
        rs[t[0]] = "{:06d}{:06d}".format(key, i+1)

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

Solution (Python):
from operator import itemgetter
N,M=map(int,input().split(" "))
d={}
for i in range(M):
    r=list(map(int,input().split(" ")))
    if r[0] in d:
        d[r[0]].append((i,r[1]))
    else:
        d[r[0]]=[(i,r[1])]
for i in d:
    d[i]=sorted(d[i],key=lambda x:x[1])
r=[]
for i in d:
    for j in range(len(d[i])):
        r.append((i,j,d[i][j][0]))
r=sorted(r,key=lambda x:x[2])
for i in r:
    print("{0:06d}{1:06d}".format(i[0],i[1]+1))

Solution (Python):
import copy
n, m = map(int, input().split())
s = []
for i in range(m):
    s.append([int(i) for i in input().split()])
    
t = s[:]
t.sort()
t.sort(key=lambda x:(x[0], x[1]))
co = 1
for i in range(m):
    if i != 0:
        if t[i][0] != t[i - 1][0]:
            co = 1
    if t[i][0] <10:
        moji1 = "00000" + str(t[i][0])
    elif t[i][0] <100:
        moji1 = "0000" + str(t[i][0])
    elif t[i][0] <1000:
        moji1 = "000" + str(t[i][0])
    elif t[i][0] <10000:
        moji1 = "00" + str(t[i][0])
    elif t[i][0] <100000:
        moji1 = "0" + str(t[i][0])
    else:
        moji1 = str(t[i][0])

    if co <10:
        moji2 = "00000" + str(co)
    elif co <100:
        moji2 = "0000" + str(co)
    elif co <1000:
        moji2 = "000" + str(co)
    elif co <10000:
        moji2 = "00" + str(co)
    elif co <100000:
        moji2 = "0" + str(co)
    else:
        moji2 = str(co)
    t[i].append(moji1 + moji2)
    co += 1

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

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

shi_map = []

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

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

result = {}
shi_count = {}
for i, p, y in shi_map:

    if p in shi_count:
        c = shi_count[p]
        count = c + 1
        shi_count[p] = count
    else:
        shi_count[p] = 1
        count = 1
    result[i] = [p, count]
result = list(sorted(result.items(), key=lambda x: x[0]))

for i, p in result:

    p2 = str(p[0]).zfill(6)

    y = str(p[1]).zfill(6)
    r = p2+y
    print(r)

Solution (Python):
from operator import itemgetter


N, M = map(int, input().split(' '))
data = []
for i in range(M):
    Pi, Yi = map(int, input().split(' '))
    data.append([i,Pi,Yi])

sorted_data = sorted(data, key=itemgetter(1,2))

codes = []
prev_p = 0
for i,p,y in sorted_data:
    if p!=prev_p:
        x = 1
        prev_p = p
    else:
        x+=1

    code = '{0:06d}{1:06d}'.format(p,x)
    codes.append([i,code])

sorted_codes = sorted(codes, key = itemgetter(0))

for code in sorted_codes:
    print(code[1])

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

Indexs = {}
Syuturyoku = []


for j in range(N):
	P.append([0])


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

	P[p-1].append(y)
	Indexs[y] = i
	Syuturyoku.append(0)

for i in range(len(P)):
	P[i].sort()
	


for i in range(N):
	if (len(P[i]) > 1):
		for j in range(len(P[i])-1):
			atai = P[i][j+1]
			si = i+1
			
			x = j+1
			
			
			
			
			
			
			
			
			
			
			

			
			
			
			
			
			

			a = Indexs[atai]
			Syuturyoku[a] = (si, x)

for i in range(M):
	print('{0:06}{1:06}'.format(Syuturyoku[i][0], Syuturyoku[i][1]))

Solution (Python):
N,M=map(int,input().split())
city=[]
c=1
for i in range(M):
    a,b=map(int,input().split())
    city.append([a,b,c]) 
    c+=1
city.sort(key=lambda x:(x[0],x[1]))
i=0
k=1
count=1
while i < M:
    if city[i][0]==k:
        city[i].append('{:0=6}'.format(k)+'{:0=6}'.format(count))
        count+=1
        i+=1
    else:
        count=1
        k+=1
city.sort(key=lambda x:x[2])
for i in range(M):
    print(city[i][3])

Solution (Python):
N, M = (int(i) for i in input().split())
P_Y = {}
for i in range(M):
    P_Y[i] = [int(i) for i in input().split()]

sorted_city = {}
count = [1 for i in range(N)]
S = sorted(P_Y.values())

for j, v in S:
    sorted_city[v] = str(j).zfill(6) \
    + str(count[j-1]).zfill(6)
    count[j-1] += 1

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

Solution (Python):
from collections import defaultdict as dd
 
d=dd(int)
n,m=map(int,input().split())
l=[[i]+list(map(int,input().split()))+[0] for i in range(m)]
 
o=sorted(l,key=lambda x:x[2])
for i,j in enumerate(o):
  d[j[1]]+=1
  o[i][3]=d[j[1]]
 
for i in sorted(o):
  print('{0:06d}'.format(i[1])+'{0:06d}'.format(i[3]))

Solution (Python):
import math
n,m = map(int, input().split())
a = []
for i in range(m):
  pk,yk = map(int,input().split())
  b = [pk,yk,i]
  a.append(b)
a.sort(key=lambda x:(x[0],x[1]))
b = a[0][0]
c = 0
for i in range(len(a)):
  if a[i][0] != b:
    b = a[i][0]
    c = 1
  else:
    c += 1
  a[i].append(c)
a.sort(key=lambda x:x[2])
for i in range(len(a)):
  a[i].append(math.floor(math.log10(a[i][0])+1.0))
  a[i].append(math.floor(math.log10(a[i][3])+1.0))
  print(str("0"*(6-a[i][4]))+str(a[i][0])+str("0"*(6-a[i][5]))+str(a[i][3]))

Solution (Python):
N, M = [int(_) for _ in input().split()]
PYI = [[int(_) for _ in input().split()] + [i] for i in range(M)]
PYI.sort(key = lambda x: x[1])
P_count = [0 for _ in range(N + 1)]
Ans = ['' for _ in range(M)]
for i in range(M):
    P_count[PYI[i][0]] += 1
    Ans[PYI[i][2]] = str(PYI[i][0]).zfill(6) + str(P_count[PYI[i][0]]).zfill(6)
print('\n'.join(Ans))

Solution (Python):
N,M = map(int,input().split())
cnt = [0 for i in range(N+1)]
A = []
for i in range(M):
	P,val = map(int,input().split())
	A.append( (val,P,i) )
A.sort()

B = []
for val,P,i in A:
	cnt[P] += 1
	B.append( (i,"{:06}{:06}".format(P,cnt[P]))  )
B.sort()

for i ,b in B:
	print(b)

Solution (Python):
import bisect

N, M = map(int, input().split())
PY = []
array = [[] for _ in range(N)]

for _ in range(M):
    P, Y = map(int, input().split())
    PY.append([P, Y])
    array[P-1].append(Y)
    
for i in range(N):
    array[i].sort()

for p, y in PY:
    n = bisect.bisect_left(array[p-1], y) + 1
    print('%06d%06d' % (p, n))

Solution (Python):
def con(var):
    var=str(var)
    while(len(var)<6):
        var="0"+var
    return var


def run():
    N,M=map(int,input().split())
    P=[-1]*M
    Y=[-1]*M
    arr=[]
    for i in range(M):
        P[i],Y[i]=map(int,input().split())
        P[i]=P[i]-1
        arr.append([P[i],Y[i],i])
    arr=sorted(arr,key=lambda x:x[1])
    ans=[0]*M
    cnt=[0]*N
    for i in range(M):
        cnt[arr[i][0]]=cnt[arr[i][0]]+1
        ans[arr[i][2]]=con(arr[i][0]+1)+con(cnt[arr[i][0]])
    for i in range(M):
        print(ans[i])
run()

Solution (Python):
def con(var):
    var=str(var)
    while(len(var)<6):
        var="0"+var
    return var
 
 
def run():
    N,M=map(int,input().split())
    P=[-1]*M
    Y=[-1]*M
    arr=[]
    for i in range(M):
        P[i],Y[i]=input().split()
        P[i]=int(P[i])-1
        Y[i]=int(Y[i])
        arr.append([P[i],Y[i],i])
    arr=sorted(arr,key=lambda x:x[1])
    ans=[0]*M
    cnt=[0]*N
    for i in range(M):
        cnt[arr[i][0]]=cnt[arr[i][0]]+1
        ans[arr[i][2]]=con(arr[i][0]+1)+con(cnt[arr[i][0]])
    for i in range(M):
        print(ans[i])
run()

Solution (Python):
N,M = map(int,input().split())
city = []
count = 1
for i in range(M):
    p,y = map(int,input().split())
    city.append([p,y])
city_sorted = sorted(city)
for i in range(M):
    if city_sorted[i][0] == city_sorted[i-1][0] and i != 0:
        count += 1
    else:
        count = 1
    city_sorted[i][1] = count
for i in range(M):
    number_f = "0"*(6-len(str(city[i][0]))) + str(city[i][0])
    number_b = "0"*(6-len(str(city[i][1]))) + str(city[i][1])
    print(number_f + number_b)

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

cities = []
for i in range(m):
    (p, y) = map(int, input().split())
    cities.append((p, y))
data = {}
for i, v in enumerate(cities):
    if not v[0] in data:
        data[v[0]] = []
    data[v[0]].append([i, v, ''])

for k, v in data.items():
    v.sort(key=lambda x: x[1][1])
    for i, j in enumerate(v):
        j[2] = "{0:06d}".format(j[1][0]) + "{0:06d}".format(i + 1)

codes = [''] * len(cities)
for k, v in data.items():
    for i in v:
        codes[i[0]] = i[2]

for code in codes:
    print(code)

Solution (Python):
import numpy as np
N, M = map(int, input().split())
cities = {}
P = {}
Y = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = p
    Y[i] = y

ans = {}
sorted_Y = sorted(Y.items(), key=lambda x:x[1])
P_i = np.zeros(N)
for i,y in sorted_Y:
    p = cities[i]
    P_i[p-1] += 1
    ans[i] = (p, int(P_i[p-1]))

for i in range(M):
    print('{0:06}{1:06}'.format(ans[i][0], ans[i][1]))

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

PY = []
P_Y = [[] for i in range(N)]

p_count = [0 for i in range(N)]

for i in range(M):
    p,y = list(map(int,input().split()))
    P_Y[p-1].append(y)
    p_count[p-1]+=1
    PY.append([p,y])
    
import numpy as np

P_Y_arg = []
for i in range(N):
    P_Y_arg.append(np.array(P_Y[i]).argsort().argsort())

    
p_count = [0 for i in range(N)]

for i in range(M):
    ps = str(1000000+PY[i][0])
    ys = str(1000000+int(P_Y_arg[PY[i][0]-1][p_count[PY[i][0]-1]])+1)
    p_count[PY[i][0]-1]+=1
    print(ps[1:]+ys[1:])

Solution (Python):
n, m = map(int,input().split())
xs = [0]*m
pre = [0]*m
for x in range(m):
    xs[x] = list(list(map(int,input().split())) + [x] + [x])
xs.sort()

skip = 0
for p in range(1,n+1):
    cnt = 1
    flag = 0
    for x in range(skip,len(xs)):
        if xs[x][0] <= p:
            xs[x][3] = cnt
            cnt += 1
            skip += 1
        else:
            flag = 1
        if flag:
            break


for x in sorted(xs, key=lambda x:x[2]):
    print('{0:06d}'.format(x[0]) + '{0:06d}'.format(x[3]))

Solution (Python):
import numpy as np
N, M = map(int, input().split())
p_dict = {}
p = [0 for i in range(M)]
y = [0 for i in range(M)]
i_in_p = [0 for i in range(M)]
 
for i in range(M):
    p[i], y[i] = map(int, input().split())
    if p[i] not in p_dict:
        i_in_p[i] = 0
        p_dict[p[i]] = [y[i]]
        continue
    i_in_p[i] = len(p_dict[p[i]])
    p_dict[p[i]].append(y[i])
for key in p_dict.keys():
    p_dict[key] = np.array(p_dict[key]).argsort().argsort() + 1
for i in range(M):
    print('{:06d}{:06d}'.format(p[i], p_dict[p[i]][i_in_p[i]]))

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

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

ans = []
for pre_id, info in enumerate(Info):
    info = sorted(info)
    for i in range(len(info)):
        ans.append((info[i][1], str(pre_id).rjust(6, '0'), str(i + 1).rjust(6, '0')))

ans.sort()
for i, x, y in ans:
    print(str(x) + str(y))

Solution (Python):
import sys

array = list(map(int, input().strip().split(' ')))

N = array[0]
M = array[1]


if N < 1:
    sys.exit()
if N > 10**5:
    sys.exit()

if M < 1:
    sys.exit()
if M > 10**5:
    sys.exit()

list_t = []

for i in range(M):

    array1 = list(map(int, input().strip().split(' ')))
    P = array1[0]
    Y = array1[1]

    if P < 1:
        sys.exit()
    if P > N:
        sys.exit()

    if Y < 1:
        sys.exit()
    if Y > 10**9:
        sys.exit()
    
    list_t.append([i,P,Y])



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



test_P = list_t[0][1]

list_t[0][2] = 1

bango = 1


for j in range(1, M):


    test_P_next = list_t[j][1]

    if test_P == test_P_next:
        bango=bango+1
        list_t[j][2] = bango


    else:
        bango = 1
        list_t[j][2] = bango
        test_P = test_P_next

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


for k in range(M):


    out1 = str(list_t[k][1])

    out_zero1 = out1.zfill(6)
    
    print(out_zero1,end='')

    out2 = str(list_t[k][2])

    out_zero2 = out2.zfill(6)
    
    print(out_zero2)

Solution (Python):


"""Describe
"""
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    data = []
    for i in range(m):
        p, y = map(int, input().split())
        data.append([p, y, i])
    
    data_sorted = sorted(data, key=itemgetter(0, 1))
    

    p, y, i = 0, 0, 0
    p_prev = 0 
    x = 1 
    codes = []
    for p, y, i in data_sorted:
        
        if p != p_prev:
            x = 1
        else:
            x += 1
        code = '{:06d}{:06d}'.format(p, x)
        codes.append([i, code])
        p_prev = p
    

    codes_sorted = sorted(codes, key=itemgetter(0))
    

    for i, code in codes_sorted:
        print(code)
        
main()

Solution (Python):


"""Describe
"""
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    data = []
    for i in range(m):
        p, y = map(int, input().split())
        data.append([p, y, i])
    
    data_sorted = sorted(data, key=itemgetter(0, 1))
    

    p, y, i = 0, 0, 0
    p_prev = 0 
    x = 1 
    codes = []
    for p, y, i in data_sorted:
        
        if p != p_prev:
            x = 1
        else:
            x += 1
        code = '{:06d}{:06d}'.format(p, x)
        codes.append([i, code])
        p_prev = p
    

    codes_sorted = sorted(codes, key=itemgetter(0))
    

    for i, code in codes_sorted:
        print(code)
        
main()

Solution (Python):
def main():
    N, M = map(int, input().split())
    Lw = []
    T = []
    for _ in range(M):
        pi, yi = [int(i) for i in input().split()]
        T.append(pi)
        T.append(yi)
        Lw.append(T)
        T = []
    temp_dict = {}
    answer_dict = {}
    L = Lw.copy()
    L.sort(key=lambda x: x[1])
    for i in range(N):
        temp_dict[str(i+1)] = 1
    for l in L:
        answer_dict[str(l[1])] = temp_dict[str(l[0])]
        temp_dict[str(l[0])] += 1

    for lw in Lw:
        print(str(lw[0]).zfill(6) + str(answer_dict[str(lw[1])]).zfill(6))


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
N, M = list(map(int, input().split()))
PYs = []
for _ in range(M):
    PYs.append(list(map(int, input().split())))
PYs = np.asarray(PYs)
indx = np.argsort(PYs[:,1])
ans = [" " for _ in range(M)]
city = [1 for _ in range(N)]
for i in indx:
    ans[i] = str(PYs[i, 0]).zfill(6) + str(city[PYs[i, 0]-1]).zfill(6)
    city[PYs[i, 0]-1] += 1
for a in ans:
    print(a)

Solution (Python):
n,m = map(int,input().split())
city = [{} for i in range(n)]
for i in range(m):
    p,y = map(int,input().split())
    city[p-1][i] = y
all_dict = {}
for j in range(n):
    temp_dict = sorted(city[j].items(),key=lambda x:x[1])
    for i in range(len(temp_dict)):
        all_dict[temp_dict[i][0]] = str(j+1).zfill(6)+str(i+1).zfill(6)
for k in range(len(all_dict)):
    print(all_dict[k])

Solution (Python):
N, M = map(int, input().split(" "))
cityList = []
preList = [0] * N

class City:
    def __init__(self, id, pre, year):
        self.id = id
        self.pre = pre
        self.year = year
        self.number = 0

for i in range(M):
    P, Y = map(int, input().split(" "))
    city = City(i+1, P, Y)
    cityList.append(city)

cityList.sort(key=lambda x:x.year)
cityList.sort(key=lambda x:x.pre)

num = cityList[0].pre
count = 1
for city in cityList:
    if(city.pre != num):
        num = city.pre
        count = 1
    city.number = str(city.pre).zfill(6) + str(count).zfill(6)
    count += 1

cityList.sort(key=lambda x:x.id)
for city in cityList:
    print(city.number)

Solution (Python):
n,m = map(int,input().split())
ken = []
for i in range(m):
    p,y = map(int,input().split())
    ken.append([p,y,i+1])
 
k = sorted(ken)
a = []
cnt = 1
for i in range(m):
    if i >= 1:
        if k[i][0] == k[i-1][0]:
            cnt += 1
        else:
            cnt = 1
    a.append([k[i][-1],k[i][0],cnt])

aa = sorted(a)
for i in range(m):
    print("{0:06d}".format(aa[i][1]) + "{0:06d}".format(aa[i][2]))

Solution (Python):
def con(var):
    var=str(var)
    while(len(var)<6):
        var="0"+var
    return var



def run():
    N,M=input().split()
    N=int(N)
    M=int(M)
    P=[-1]*M
    Y=[-1]*M
    arr=[]
    for i in range(M):
        P[i],Y[i]=input().split()
        P[i]=int(P[i])-1
        Y[i]=int(Y[i])
        arr.append([P[i],Y[i],i])
    arr=sorted(arr,key=lambda x:x[1])
    ans=[0]*M
    cnt=[0]*N
    for i in range(M):
        cnt[arr[i][0]]=cnt[arr[i][0]]+1
        ans[arr[i][2]]=con(arr[i][0]+1)+con(cnt[arr[i][0]])
    for i in range(M):
        print(ans[i])
run()

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

for i in range(M):
    P, Y = map(int, input().split())
    cities.append((i, P, Y, ))

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

c = 1
res = []
for i in range(len(cities)):
    cur = cities[i]
    code = '{0:06d}{1:06d}'.format(cur[1], c)
    if i + 1 < M:
        nxt = cities[i + 1]
        c = 1 if cur[1] != nxt[1] else c + 1
    res.append((cur[0], code, ))

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

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

Solution (Python):
import numpy as np
N, M = map(int, input().split())
p_dict = {}
p = [0 for i in range(M)]
y = [0 for i in range(M)]
i_in_p = [0 for i in range(M)]

for i in range(M):
    p[i], y[i] = map(int, input().split())
    if p[i] not in p_dict:
        i_in_p[i] = 0
        p_dict[p[i]] = [y[i]]
        continue
    i_in_p[i] = len(p_dict[p[i]])
    p_dict[p[i]].append(y[i])
for key in p_dict.keys():
    p_dict[key] = np.array(p_dict[key]).argsort().argsort() + 1
for i in range(M):
    print('{:06d}{:06d}'.format(p[i], p_dict[p[i]][i_in_p[i]]))

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

pdic = {i:[] for i in range(N)}
ppdic = {i:[] for i in range(N)}
outidx = {}
pl = []

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

for i in range(N):
    if len(pdic[i]) ==0:
        continue

    pdic[i] = sorted(pdic[i])
    ppdic[i] = {jj : j for j, jj in enumerate(pdic[i])}


for i, j in enumerate(pl):
    
    ii = ppdic[j][outidx[i]]
    
    print('{:06}{:06}'.format(1+j, ii+1))

Solution (Python):
n,m = map(int,input().split())
city = [[] for _ in range(n+1)]
ret = ["" for _ in range(m)]
def createSix(s):
    while len(s) != 6:
        s = "0" + s
    return s
for i in range(m):
    a,b = map(int, input().split())
    city[a].append((b, i))
for i in range(n+1):
    city[i].sort()
for i in range(n+1):
    for j in range(len(city[i])):
        ret[city[i][j][1]] = createSix(str(i)) + createSix(str(j+1))
for i in ret:
    print(i)

Solution (Python):
N, M = map(int, input().split())
YL = [[int(i) for i in input().split()] + [j] for j in range(M)]
YL.sort()
ct = 1
for i in range(M):
    if YL[i][0] != YL[i-1][0]:
        ct = 1
    YL[i].append('{:0=6}'.format(YL[i][0]))
    YL[i].append('{:0=6}'.format(ct))
    ct += 1
YL.sort(key=lambda x:x[2])
for i in YL:
    print('%s%s' % (i[3], i[4]))

Solution (Python):

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

Solution (Python):
from operator import itemgetter
n,m = map(int, input().split())
py = []
for i in range(m):
  p,y = map(int, input().split())
  py.append([p,y,i])
py.sort(key=itemgetter(1))
num = [1]*n
for i in range(m):
  zen = py[i][0]
  koh = num[py[i][0]-1]
  zenhan = str(zen)
  kouhan = str(koh)
  z = 6 - len(zenhan)
  k = 6 - len(kouhan)
  zenkan = '0' * z
  koukan = '0' * k
  zenkan += zenhan
  koukan += kouhan
  py[i] = py[i] + [zenkan + koukan]
  num[py[i][0]-1] = num[py[i][0]-1] +1
py.sort(key=itemgetter(2))
for i in range(m):
  pri = py[i][3]
  print(pri)

Solution (Python):
def sixprint(s):
    l = len(str(s))

    return str(0)*(6-l) + str(s)

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

l = []
dic = {}
for i in range(M):
    pp,yy = map(int,input().split())
    lis = [i,pp,yy]
    l.append(lis)
    dic[pp] = 1

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

for i in range(M):
    lll[i].append(dic[lll[i][1]])
    dic[lll[i][1]] += 1
llll = sorted(lll,key=lambda x:x[0])

for i in range(M):
    print(sixprint(llll[i][1]) + sixprint(llll[i][-1]))

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


p_buf = 0
p_index = 1
answer = []
for row in result_list:
    if p_buf != row[0]:
        p_index = 1
        answer.append([str(row[0]).rjust(6, '0')+str(p_index).rjust(6, '0'), row[2]])
        p_buf = row[0]
    else:
        p_index += 1
        answer.append([str(p_buf).rjust(6, '0')+str(p_index).rjust(6, '0'), row[2]])


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

Solution (Python):

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

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

k = sorted(ken)
a = []
cnt = 1
for i in range(m):
    if i >= 1:
        if k[i][0] == k[i-1][0]:
            cnt += 1
        else:
            cnt = 1
    a.append([k[i][-1],k[i][0],cnt])
    
aa = sorted(a)
b = []
for i in range(m):
    b.append([aa[i][1],aa[i][2]])

for i in range(m):
    print("{0:06d}".format(b[i][0]) + "{0:06d}".format(b[i][1]))

Solution (Python):

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

Solution (Python):

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

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

cities.sort(key=lambda x: (x[1], x[2]))
now_p = cities[0][1]

j = 1
for i, l in enumerate(cities):
    if now_p != l[1]:
        now_p = cities[i][1]
        j = 1

    l.append(j)
    j += 1

cities.sort(key=lambda x: x[0])
for city in cities:
    print(str(city[1]).zfill(6)+str(city[3]).zfill(6))

Solution (Python):
n,m=map(int,input().split())
p=[]
for i in range(m):
    p.append(list(map(int,input().split())))
    p[i].append(i)
p.sort(key=lambda x:x[1])
p.sort(key=lambda x:x[0])
count=0
j=0
for i in range(m):
    if p[i][0] != j:
        count = 1
        j=p[i][0]
    else:
        count += 1
    ans1 = '{0:06d}'.format(p[i][0])
    ans2 = '{0:06d}'.format(count)
    p[i].append(ans1 + ans2)
p.sort(key=lambda x: x[2])
for i in range(m):
    print(p[i][3])

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

cities.sort(key=lambda x: (x[1], x[2]))
now_p = cities[0][1]

j = 1
for i, l in enumerate(cities):
    if now_p != l[1]:
        now_p = cities[i][1]
        j = 1

    l.append(j)
    j += 1

cities.sort(key=lambda x: x[0])
for city in cities:
    print(str(city[1]).zfill(6)+str(city[3]).zfill(6))

Solution (Python):
def m():
    n, m = map(int, input().split())
    d = dict()
    yeard = dict()
    a = []
    b = []
    for i in range(m):
        p, y = map(int, input().split())
        a.append((p, y))
        b.append((p, y))

    a.sort(key=lambda x: x[1])
    for i in range(m):
        if d.get(a[i][0], 0) == 0:
            d[a[i][0]] = 1
            yeard[a[i][1]] = 1
        else:
            d[a[i][0]] += 1
            yeard[a[i][1]] = d[a[i][0]]

    for key, value in b:
        print(str(key).zfill(6)+str(yeard[value]).zfill(6))

m()

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

cities.sort(key=lambda x: (x[1], x[2]))
now_p = cities[0][1]

j = 1
for i, l in enumerate(cities):
    if now_p != l[1]:
        now_p = cities[i][1]
        j = 1

    l.append(j)
    j += 1

cities.sort(key=lambda x: x[0])
for city in cities:
    print(str(city[1]).zfill(6)+str(city[3]).zfill(6))

Solution (Python):
import bisect

n,m = map(int,input().split())
years = [[]for i in range(n)]
yearss = []

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


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

for i in range(m):
  print("{0:06d}".format(yearss[i][0]),"{0:06d}".format(bisect.bisect_right(years[yearss[i][0]-1],yearss[i][1])),sep="")

Solution (Python):

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

Solution (Python):

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