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



Sample input:
2 3
1 32
2 63
1 12


Sample output:
000001000002
000002000001
000001000001

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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 )

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
import copy
n, m = map(int, input().split())
s = []
for i in range(m):#h:高さ
    s.append([int(i) for i in input().split()])
    #l2 = l[:]
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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()
	# P[i] = list(map(str,P[i]))


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
			# si = str(si)
			x = j+1
			# x = str(x)
			# bangou = list(map(str,si))
			# bangou_len = int(len(bangou))
			# bangou_ushiro = list(map(str,x))
			# bangou_ushiro_len = int(len(bangou_ushiro))
			# if(len(bangou)<6):
			# 	for zero in range(6-bangou_len):
			# 		bangou.insert(0,'0')
			# if(len(bangou_ushiro)<6):
			# 	for zero in range(6-bangou_ushiro_len):
			# 		bangou_ushiro.insert(0,'0')

			# mojiretsu = ''
			# for k in bangou:
			# 	mojiretsu += k
			# mojiretsu2 = ''
			# for k2 in bangou_ushiro:
			# 	mojiretsu2 += k2

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

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())#ken city
city=[]
c=1
for i in range(M):
    a,b=map(int,input().split())
    city.append([a,b,c]) #ken year count
    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])

Submission status: Accepted

Solution code:
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]])

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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:])

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]]))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""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])
    # print(data)
    data_sorted = sorted(data, key=itemgetter(0, 1))
    # print(data_sorted)

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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]]))

Submission status: Accepted

Solution code:
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])}
#print(ppdic)
#print(pdic)
for i, j in enumerate(pl):
    #print(pdic[j])
    ii = ppdic[j][outidx[i]]
    ##print(ii)
    print('{:06}{:06}'.format(1+j, ii+1))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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()
# print(result_list)

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

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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="")

Submission status: Accepted

Solution code:
import bisect

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

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

    dic[y] = ''

    PY.append((p,y))

PY = sorted(PY)
P  = sorted(P)
lenP = len(P)
left = 0
righ = 0
for i in range(1,N+1):

    t_list = []

    left = bisect.bisect_left(P,i,0,lenP)
    righ = bisect.bisect_right(P,i,0,lenP)

    # print(i,P)
    # print(left,righ)

    if i == P[left]:
        for j in range(left,righ):
            t_list.append(PY[j][1])
        t_list = sorted(t_list)
        for k in range(len(t_list)):
            y = t_list[k]
            dic[y] = str(i).zfill(6) + str(k+1).zfill(6)

    if lenP == righ:
        # print('break')
        break

for y in Y:
    print(dic[y])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
timeline = []
for i in range(M):
    P, Y = map(int, input().split())
    timeline.append((Y, P, i))
timeline.sort()
count = [0] * (N + 1)
number = [(0, 0)] * M
for y, p, i in timeline:
    count[p] += 1
    number[i] = (p, count[p])
for i in range(M):
    print('{:06}{:06}'.format(number[i][0], number[i][1]))

Submission status: Accepted

Solution code:
from operator import itemgetter

def main():
    N,M = list(map(int, input().split()))
    lst = [[] for i in range(N)]
    anslst = []

    for i in range(M):
        P,Y = list(map(int, input().split()))
        lst[P-1].append({'city_id':i, 'pref':P, 'year':Y})

    for i in range(N):
        tmp = lst[i]
        tmp = sorted(tmp, key = itemgetter('year'))
        for j in range(len(tmp)):
            city_id = tmp[j]['city_id']
            pref = tmp[j]['pref']
            year = tmp[j]['year']
            id = '{0:06d}'.format(pref) + '{0:06d}'.format(j+1)
            anslst.append({'city_id':city_id, 'pref':pref, 'year':year, 'id':id})

    anslst = sorted(anslst, key = itemgetter('city_id'))
    for i in range(len(anslst)):
        print(anslst[i]['id'])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter


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

    sorted_l = sorted(l, key=itemgetter(1, 2))
    # print(l)
    # print(sorted_l)

    n_nums = []
    pref = None
    for e in sorted_l:
        p = e[1]
        if (pref is None) or p != pref:
            pref = p
            c = 1
        p_str = str(p).zfill(6)
        c_str = str(c).zfill(6)
        nums = p_str + c_str
        n_nums.append((e[0], nums))
        c += 1

    for num in sorted(n_nums, key=itemgetter(0)):
        print(num[1])


if __name__ == '__main__':
    main()