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())
ken=[1 for i in range(n+1)]
inf=[[] for i in range(m)]
def f(x):
    m=0
    while x>0:
        m+=1
        x=x//10
    return m

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

for i in range(m):
    inf[i].append(ken[inf[i][1]])
    ken[inf[i][1]]+=1
inf=sorted(inf)


for i in range(m):
    ans=""
    p=inf[i][1]
    y=inf[i][3]
    for j in range(6-f(p)):
        ans+="0"
    ans=ans+str(p)
    
    for j in range(6-f(y)):
        ans=ans+"0"
    ans=ans+str(y)
    print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
city = [list(map(int, input().split())) for _ in range(m)]
pref = [[] for _ in range(n+1)]

ans = []

for i, c in enumerate(city):
    pref[c[0]].append([i, c[1]])

for i in range(n):
    pref[i + 1].sort(key=lambda x: x[1])
    for j in range(len(pref[i + 1])):
        ans.append([pref[i+1][j][0], str(i+1).zfill(6) + str(j+1).zfill(6)])

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

for c in ans:
    print(c[1])

Submission status: Accepted

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

S={}
T=[0]*(N+1)
F=[0]*M
for i in range(M):
    P,Y=map(int,input().split())
    F[i]=(P,Y)
    S[(P,Y)]=i
    T[P]+=1

U=[0]*(N+1)
X=[[0]*T[i] for i in range(N+1)]

for P,Y in F:
    X[P][U[P]]=Y
    U[P]+=1

H=[""]*M

for i in range(N+1):
    X[i].sort()

    for j in range(T[i]):
        g=S[(i,X[i][j])]
        H[g]=str(i).zfill(6)+str(j+1).zfill(6)
        j+=1
print("\n".join(H))

Submission status: Accepted

Solution code:
import sys
from collections import deque


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n, m = nm()
    Y = [deque() for _ in range(n)]
    Y_id = []
    order = []
    for i in range(m):
        p, y = nm()
        Y[p - 1].append(y)
        order.append(p)

    for y in Y:
        d = {}
        for i, y_s in enumerate(sorted(y)):
            d[y_s] = i + 1
        Y_id += [d]

    for o in order:
        print('{:06}'.format(o) +
              '{:06}'.format(Y_id[o - 1][Y[o - 1].popleft()]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

(n, m), *q = [[*map(int, i.split())] for i in sys.stdin]
d = defaultdict(list)
for k, v in q:
    d[k].append(v)
c = defaultdict(dict)
for k, v in d.items():
    for i, j in enumerate(sorted(v)):
        c[k][j] = i + 1
for p, y in q:
    print("{:0>6}{:0>6}".format(p, c[p][y]))

Submission status: Accepted

Solution code:
from collections import defaultdict
(n, m), *q = [[*map(int, i.split())] for i in open(0)]
d = defaultdict(list)
for k, v in q:
    d[k].append(v)
c = defaultdict(dict)
for k, v in d.items():
    for i, j in enumerate(sorted(v)):
        c[k][j] = i + 1
for p, y in q:
    print("{:0>6}{:0>6}".format(p, c[p][y]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
(n, m), *q = [[*map(int, i.split())] for i in open(0)]
s = sorted(q)
d = {}
for k, v in s:
    if k not in d:
        d[k] = []
    d[k].append(v)
c = {}
for k, v in d.items():
    i = 0
    if k not in c:
        c[k] = {}
    while i < len(v):
        i += 1
        c[k][v[~-i]] = str(i)
for p, y in q:
    pn = "00000" + str(p)
    cn = "00000" + c[p][y]
    print(pn[-6:] + cn[-6:])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
py=[list(map(int,input().split()))for _ in range(M)]
epy=list(enumerate(py))
P=[[]for _ in range(N+1)]
for x in epy:
    P[x[1][0]].append(x)

i=1
ans=[]
while i<=N:
    L=P[i]
    L.sort(key=lambda x:x[1])
    j=0
    while j<len(L):
        L[j][1][1]=j+1
        ans.append(L[j])
        j+=1
    i+=1
ans.sort()

for e,py in ans:
    p,y=map(str,py)
    p='0'*(6-len(p))+p
    y='0'*(6-len(y))+y
    print(p+y)

Submission status: Accepted

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

no = {}
ken = [[] for i in range(N)]
for i in range(M):
    p, y = map(int, input().split())
    no[i] = str(p)+'_'+str(y)
    ken[p-1].append(y)

ans = {}
for i in range(N):
    ken[i].sort()
    for j in range(len(ken[i])):
        ans[str(i+1)+'_'+str(ken[i][j])] = str(i+1).zfill(6) + str(j+1).zfill(6)

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
x=[]
y=[]
for i in range(m):
    a,b=map(int,input().split())
    x.append([a,b,i])
x.sort()
s=1
for i in range(m):
    c=x[i][0]
    a=6-len(str(x[i][0]))
    b=["0"]*a
    for j in range(len(str(x[i][0]))):
        b.append(str(x[i][0])[j])
    x[i][0]="".join(b)
    a=6-len(str(s))
    b=["0"]*a
    for j in range(len(str(s))):
        b.append(str(s)[j])
    x[i].append("".join(b))
    if i<m-1:
        if c==x[i+1][0]:
            s+=1
        else:
            s=1
for i in range(m):
    y.append([x[i][2],x[i][0],x[i][3]])
y.sort()
for i in range(m):
    print(y[i][1]+y[i][2])

Submission status: Accepted

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

p_y.sort()
# print(p_y)

res = [0] * m
order = 0
for i in range(m):
    ken, _, index = p_y[i]
    if ken != p_y[i - 1][0] and i > 0:
        order = 1
    else:
        order += 1
    res[index] = [ken, order]


# print(res)

for i in range(m):
    ken = str(res[i][0]).zfill(6)
    order = str(res[i][1]).zfill(6)
    print(ken + order)

Submission status: Accepted

Solution code:
import numpy as np

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

l=[[] for n in range(N)]
for m in range(M):
    l[PY[m,0]-1].append(PY[m,1])

dp={}
for n in range(N):
    if l[n]:
        l[n].sort()
        for i in range(len(l[n])):
            city="000000"+str(n+1)
            num="000000"+str(i+1)
            dp[(n,l[n][i]-1)]=str(city[-6:]+num[-6:])
for m in range(M):
    print(dp[(PY[m,0]-1,PY[m,1]-1)])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	n,m = map(int,input().split())

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

	#各内部配列でソートする
	B = sorted(A,key=lambda x:(x[0],x[1]))

	no = 1
	tmp = 0
	for b in B:
		if tmp == b[0]:
			no += 1
		else:
			tmp = b[0]
			no = 1

		#市通番
		cityno = str(b[0]).zfill(6) + str(no).zfill(6)
		b[3] = cityno

	#再ソートする
	C = sorted(B,key=lambda x:(x[2]))
	
	for c in C:
		print(c[3])

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


def run():
    N,M, *PY = map(int, read().split())
    PY = [(PY[2 * i + 1], PY[2 * i], i) for i in range(M)]

    count_town = [0] * (N+1)
    ans = [''] * M
    PY = sorted(PY)
    for y, p, i in PY:
        count_town[p] += 1
        right = count_town[p]
        left = p
        right = (6- len(str(right))) * '0' + str(right)
        left = (6 - len(str(left))) * '0' + str(left)
        ans[i] = left + right

    for a in ans:
        print(a)






if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
P = [list(map(int,input().split())) for i in range(M)]
for i in range(M):
    P[i].append(i)
P.sort(key=lambda x: x[1])
B = [1]*N

for i in range(M):
    P[i] += "0"*(6 - len(str(P[i][0]))) + str(P[i][0]) + "0"*(6 - len(str(B[P[i][0]-1]))) + str(B[P[i][0]-1]),
    B[P[i][0]-1] += 1
    
P.sort(key=lambda x: x[2])
for i in range(M):
    print(P[i][3])

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    N,M = map(int,input().split())
    PY = [[i]+list(map(int,input().split())) for i in range(M)]

    PY = sorted(PY,key = lambda x:(x[1],x[2]))
    
    ans_li = ['0'*12]*M
    town_dict = {}

    for idx,p,y in PY:
        x = town_dict.get(p,1)

        id_ = ('{:6d}'.format(p)+'{:6d}'.format(x)).replace(' ','0')
        ans_li[idx] = id_

        town_dict[p] = town_dict.get(p,1)+1

    print('\n'.join(ans_li))
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
L = []
A = []
for _ in range(M):
    p, y = map(int, input().split())
    L.append([p, y])
    A.append([p, y])

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

ans_d = defaultdict()
dp = [0] * (N + 1)
for i, v in enumerate(L):
    # k = 6 - len(str(v[0]))
    s = ''
    if (dp[v[0]] != 0):
        l_dp = 6 - len(str(dp[v[0]] + 1))
        for j in range(l_dp):
            s += '0'

        s += str(dp[v[0]] + 1)
        dp[v[0]] += 1
    else:
        l_dp = 6 - len(str(dp[v[0]] + 1))
        for j in range(l_dp):
            s += '0'
        s += str(dp[v[0]] + 1)
        dp[v[0]] += 1
    k = str(v[0]) + ' ' + str(v[1])
    ans_d[k] = s

for i in A:
    m = str(i[0]) + ' ' + str(i[1])
    k = 6 - len(str(i[0]))
    s = ''
    for j in range(k):
        s += '0'
    s += str(i[0])
    print(s + ans_d[m])

Submission status: Accepted

Solution code:
def main():
    n,m=map(int,input().split())
    l=[tuple(map(int,input().split())) for _ in range(m)]
    py=sorted(l, key=lambda x: (x[0],x[1]))
    d={}
    i = 1
    prev=0
    for p,y in py:
        if prev != p:
            i = 1
            prev = p
        d[(p,y)] = "{:0>6}".format(p)+"{:0>6}".format(i)
        i += 1
    for x in l:
        print(d[x])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
b = [[] for _ in range(n+1)]
for i in range(m):
    b[a[i][0]].append((a[i][1],i+1))
#print(b)
for i in range(1,n+1):
    b[i].sort()
ans = ["."]*m
for i in range(1,n+1):
    for j in range(len(b[i])):
        ans[b[i][j][1]-1] = "0"*(6-len(str(i))) + str(i) + "0"*(6-len(str(j+1))) + str(j+1)
print(*ans, sep="\n")

Submission status: Accepted

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

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

t = 1
tmp = sorted(lis)[0][0]

nlis =[]

for i in sorted(lis):
    if tmp == i[0]:
        left = str(i[0]).zfill(6)
        right = str(t).zfill(6)
        t += 1
    else:
        t = 1
        tmp = i[0]
        left = str(i[0]).zfill(6)
        right = str(t).zfill(6)
        t += 1
    
    nlis.append([i[2],left+right])

for j in sorted(nlis):
    print(j[1])

Submission status: Accepted

Solution code:
import bisect
N, M = map(int, input().split())
l_1 = [[] for i in range(N+1)]
l_2 = []
for i in range(M):
  p, y = map(int, input().split())
  l_1[p].append(y)
  l_2.append([p, y])
  
for i in range(N+1):
  l_1[i].sort()
    
for i in range(M):
  c = l_2[i]
  n = bisect.bisect_left(l_1[c[0]], c[1]) + 1
  ans = str(c[0]).zfill(6) + str(n).zfill(6)
  print(ans)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N, M = [int(item) for item in input().split()]
    PY = [[int(item) for item in input().split()] for _ in range(M)]

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

    for p, y in PY:
        memo[p] += [y]

    res_list = []
    for lst in memo:
        lst.sort()
        temp_dic = dict(zip(lst, range(1,len(lst)+1)))
        res_list.append(temp_dic)

    for p, y in PY:
        pi = str(p).zfill(6)
        x = str(res_list[p][y]).zfill(6)
        print(pi+x)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
pyi = [[] for n in range(N)]#県ごとの配列
for i in range(M):
    p, y = map(int,input().split())
    pyi[p-1].append([y,i])
    #最終的にはinput順より誕生年と順番組にして保存
#print(pyi)

ans = []#出力用配列
for i in range(N):
    pyi[i].sort()  #県ごとに誕生した年順に
    for j in range(len(pyi[i])): #県の中での出力準備
        ans.append([(6-len(str(i+1)))*"0" + str(i+1) + (6-len(str(j+1)))*"0" + str(j+1),pyi[i][j][1]])
        
ans.sort(key=lambda x:x[1])
for m in range(M):
    print(ans[m][0])

Submission status: Accepted

Solution code:
from collections import defaultdict
import bisect

pre = defaultdict(list)
ori = []
n, m = map(int, input().split())
for _ in range(m):
    x, y = map(int, input().split())
    pre[x].append(y)
    ori.append([x, y])

for key, val in pre.items():
    val.sort()

for i in range(m):
    l = pre[ori[i][0]]
    idx = bisect.bisect(l, ori[i][1])
    print(f'{ori[i][0]:06}{idx:06}')

Submission status: Accepted

Solution code:
import bisect
N,M = map(int,input().split())
A = [[] for _ in range(N)] #重複がある場合にはsetにする？
original = []
for i in range(M):
  a,b = map(int,input().split())
  a-=1 #県を0indexに直す
  A[a].append(b)
  original.append((a,b))
for X in A:
  X.sort()
#print(A)
for i in range(M):
  ken,now = original[i]
  ID = bisect.bisect_left(A[ken],now)
  ken += 1; ID+=1
  ans = "0"*(6-len(str(ken)))+str(ken)+"0"*(6-len(str(ID)))+str(ID)
  print(ans)

Submission status: Accepted

Solution code:
"""
M <= 10 ** 5
なので全探索しても間に合いそう。
"""
N, M = map(int, input().split())
input_li = []   # 入力[p, y]の組み合わせを格納する二次元リスト
p_dict = {}     # pごとのyのリストを格納する辞書
ans_dict = {}   # キーp, yを指定することでIDが取り出せる辞書

# 入力をinput_liに詰めつつp_dictを作っていく
for _ in range(M):
    p, y = map(int, input().split())
    input_li.append([p, y])
    if p not in p_dict:
        li = [y]
        p_dict[p] = li
    else:
        p_dict[p].append(y)

# p_dictを元にans_dictを作っていく
for p in p_dict:
    li = sorted(p_dict[p])
    ans_dict[p] = {}
    for i in range(len(li)):
        p_id = '0' * (6 - len(str(p))) + str(p)
        c_id = '0' * (6 - len(str(i + 1))) + str(i + 1)
        ans_dict[p][li[i]] = p_id + c_id

# input_li順にIDを出力していく
for p, y in input_li:
    print(ans_dict[p][y])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
input_li = []
p_dict = {}
ans_dict = {}
for _ in range(M):
    p, y = map(int, input().split())
    input_li.append([p, y])
    if p not in p_dict:
        s = [y]
        p_dict[p] = s
    else:
        p_dict[p].append(y)
for p in p_dict:
    li = sorted(p_dict[p])
    ans_dict[p] = {}
    for i in range(len(li)):
        p_id = '0' * (6 - len(str(p))) + str(p)
        c_id = '0' * (6 - len(str(i + 1))) + str(i + 1)
        ans_dict[p][li[i]] = p_id + c_id
for p, y in input_li:
    print(ans_dict[p][y])

Submission status: Accepted

Solution code:
def pad(n):
  n = str(n)
  n = '0'*(6-len(n))+n
  return n

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

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

pref=0
count=0
new_py = []
for i in range(M):
  j,(p,y)=py[i]
  if p==pref:
    count += 1
  else:
    count = 1
  new_py.append((j,pad(p)+pad(count)))
  pref = p
  
new_py = sorted(new_py)
for i in range(M):
  print(new_py[i][1])

Submission status: Accepted

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

PY_sorted = sorted(PY, key=lambda x: x[1])
PY_sorted2 = sorted(PY_sorted, key=lambda x: x[0])

PY = PY_sorted2
p = 0
y = 1
for i in range(M):
    if p != PY[i][0]:
        y = 1
    p = PY[i][0]
    identityString = str(PY[i][0]).zfill(6) + str(y).zfill(6)
    PY[i].append(identityString)
    y += 1

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

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

Submission status: Accepted

Solution code:
from bisect import bisect_left as bt
n,m = map(int,input().split())
dm,ct = [[] for _ in range(n+1)],[]
for _ in range(m):
  a,b = map(int,input().split())
  dm[a].append(b); ct.append((a,b))
for i in range(1,n+1):
  dm[i].sort()
for c in ct:
  v,f = str(c[0]),str(bt(dm[c[0]],c[1])+1)
  print('0'*(6-len(v))+v+'0'*(6-len(f))+f)

Submission status: Accepted

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

arr = [[] for _ in range(n)] 

p = [0] * m
y = [0] * m

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

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

import bisect
for i in range(m):
    num = bisect.bisect_left(arr[p[i]-1], y[i]) + 1
    a = str(p[i])
    b = str(num)
    print(a.zfill(6) + b.zfill(6))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
py = [list(map(int,input().split())) for i in range(m)]
c = [0]*n
sort_py = sorted(py,key=lambda x:x[1])
ans = dict()
for p,y in sort_py:
    c[p-1] += 1
    ans[p,y] = str(p).zfill(6)+str(c[p-1]).zfill(6)

for p,y in py:
    print(ans[p,y])

Submission status: Accepted

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

dic = dict()
for i in range(m):
    p, y = map(int, input().split())
    if not p in dic:
        dic[p] = []
    dic[p].append((y, i+1))

ans = []
for p, l in dic.items():
    l.sort()
    for i, x in enumerate(l):
        ans.append([x[1], str(p).zfill(6) + str(i + 1).zfill(6)])
ans.sort()

for x in ans:
    print(x[1])

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
P = [list(map(int, input().split())) for m in range(M)]
C = (N+1)*[0]
D = {}

for p,y in sorted(P,key=lambda x: x[1]):
  C[p]+= 1
  D[y]="%06d%06d" % (p,C[p])

for p,y in P:
  print(D[y])

Submission status: Accepted

Solution code:
N,M = (int(T) for T in input().split())
List = [[] for T in range(0,M)]
for T in range(0,M):
    List[T] = [T]+[int(T) for T in input().split()]

CitySort = sorted(List,key=lambda List:(List[1],List[2]))
Disp = [[] for T in range(0,M)]
Rece = 0
for T in range(0,M):
    if CitySort[T][1]!=Rece:
        Rece = CitySort[T][1]
        Count = 1
        Disp[CitySort[T][0]] = str(Rece).zfill(6)+str(Count).zfill(6)
    else:
        Count += 1
        Disp[CitySort[T][0]] = str(Rece).zfill(6)+str(Count).zfill(6)
        
for T in range(0,M):
    print(Disp[T])

Submission status: Accepted

Solution code:
from bisect import bisect_left 
n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)]
#print(l)
k = [[] for i in range(n)]
for j,h in l:
  k[j-1].append(h)
k_so = [[] for i in range(n)]
for i in range(n):
  a = k[i]
  k_so[i] = sorted(a)
#print(k_so)
for j,h in l:
  first = "{:0=6}".format(j)
  t = bisect_left(k_so[j-1], h)
  second = "{:0=6}".format(t+1)
  print(first+second)

Submission status: Accepted

Solution code:
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()
num = 1
city = ls[0][0]
for i in range(M):
    if ls[i][0] == city:
        ls[i][1] = num
        num += 1
    else:
        num = 1
        ls[i][1] = num
        city = ls[i][0]
        num += 1
ls.sort(key=lambda x:x[2])
for i in range(M):
    print('{0:06d}'.format(ls[i][0])+'{0:06d}'.format(ls[i][1]))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
import bisect
l=[[] for _ in range(n)]
l2=[]

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

for m in l:
  m.sort()
for m in l2:
  print("{:06d}".format(m[0]) +"{:06d}".format(bisect.bisect_left(l[m[0]-1],m[1])+1))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
import bisect
l=[[] for _ in range(n)]
l2=[]

for i in range(m):
  p,y=map(int,input().split())
  bisect.insort_left(l[p-1],y)
  l2.append([p,y])

for m in l2:
  print("{:06d}".format(m[0]) +"{:06d}".format(bisect.bisect_left(l[m[0]-1],m[1])+1))

Submission status: Accepted

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

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

ans = [0] * M
for i, v in enumerate(V, start=1):
    v.sort()
    for j, (y, k) in enumerate(v, start=1):
        ans[k] = format(str(i), "0>6") + format(str(j), "0>6")

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
from collections import defaultdict

N, M = map(int, input().split())
iPY = []
D = defaultdict(list)
E = defaultdict(int)

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

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

for i, P, Y in iPY:
  D[P].append(Y)

for P, Ys in D.items():
  for i, Y in enumerate(Ys):
    E[Y] = "000000"+str(i+1)

iPY.sort()

for i, P, Y in iPY:
  U = "000000"+str(P)
  L = E[Y]
  print(U[-6:]+L[-6:])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
V = [[] for _ in range(N)]
ans = [0] * M

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

for i, v in enumerate(V, start=1):
    v.sort()
    for k, (y, j) in enumerate(v, start=1):
        ans[j] = format(str(i), "0>6") + format(str(k), "0>6")

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n, m = map(int, input().split())
    from bisect import insort_left as il
    pref = [[] for _ in range(n)]
    for i in range(m):
        p, y = map(int, input().split())
        p -= 1
        il(pref[p], (y, i))
    
    def tostr(x):
        return '0'*(6-len(str(x+1)))+str(x+1)

    ans = [0]*m    
    for i in range(n):
        x = pref[i]
        for j in range(len(x)):
            ans[x[j][1]] = tostr(i)+tostr(j)
    
    for x in ans:
        print(x)

    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    n, m = [int(x) for x in input().split()]
    ans = [0] * m
    a = defaultdict(list)
    for i in range(m):
        p, y = [int(x) for x in input().split()]
        a[p].append((y, i))

    for p in a:
        r = a[p]
        r.sort()
        for x, (y, i) in enumerate(r):
            ans[i] = f'{p:06}{x+1:06}'
    for r in ans:
        print(r)

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""
a b a
d c d
a b a
"""

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
py1=[]
for i in range(m):
    py1.append(list(map(int,input().split()))+[i+1])
py=sorted(py1)

number_list=[]
number_list.append([str(0)]*(6-(len(list(str(py[0][0])))))+list(str(py[0][0]))+[str(0)]*(6-(len(list(str(1)))))+list(str(1))+[str(py[0][-1])])
k=2
for j in range(1,m):
    if py[j][0]==py[j-1][0]:
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str((py[j][-1]))])    
        k+=1
    else:
        k=1
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str(py[j][-1])])
        k+=1
     
number_list_sort=sorted(number_list,key=lambda x:int(x[-1]))
for l in range(m):
    print(''.join(number_list_sort[l][:-1]))

Submission status: Accepted

Solution code:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
Ken_n,City_n = (int(i) for i in input().split())
city ={i:[] for i in range(1,Ken_n+1)}
for i in range(1,City_n+1):
    p,y = (int(i) for i in input().split())
    city[p].append((y,i))

city_ID ={i:0 for i in range(1,City_n +1)}
for i in range(1,Ken_n +1):
    city[i].sort()
    
    for j in range(len(city[i])):
        city_ID[city[i][j][1]] = "{0:06d}".format(i) +"{0:06d}".format(j+1)

for i in range(1,City_n +1):
    print(city_ID[i])

Submission status: Accepted

Solution code:
import bisect

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

dic = [[0] for i in range(n+1)]
city = []
for i in range(m):
    p,y = map(int,input().split())
    city.append((p,y))
    idx = bisect.bisect_left(dic[p],y)
    dic[p].insert(idx,y)

num = "000000"
for i in city:
    p,y = i[0],i[1]
    if len(str(p)) < 6:
        kami = num[:6-len(str(p))] + str(p)
    else:
        kami = str(p)
    simo = bisect.bisect_left(dic[p],y)
    if len(str(simo)) < 6:
        simo = num[:6-len(str(simo))] + str(simo)
    else:
        simo = str(simo)
    print(kami + simo)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
PY = [list(map(int, input().split())) + [i] for i in range(m)]
PY = sorted(PY, key=lambda x: x[1])
PC = [1] * (n+1)

anss = []
for p, y, i in PY:
    anss.append((i, p, PC[p]))
    PC[p] += 1
anss = sorted(anss, key=lambda x: x[0])
for i, p, c in anss:
    print('{:06}{:06}'.format(p, c))

Submission status: Accepted

Solution code:
import copy
from collections import defaultdict

N, M = map(int, input().split())
org_arr = [list(map(int, input().split())) for _ in range(M)]
arr = copy.copy(org_arr)
arr.sort(key=lambda x:x[1])
arr.sort(key=lambda x:x[0])

count = 1
dic = {}
for i in range(len(arr)):
    dic[arr[i][1]] = count
    if i == len(arr)-1:
        break
    if arr[i][0] == arr[i+1][0]:
        count += 1
    else:
        count =1


for i in org_arr:
    ans = str(i[0]).zfill(6)+str(dic[i[1]]).zfill(6)
    print(ans)

Submission status: Accepted

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

# (Pi,Yi)のようなタプルの形で保存する
# Yiでソートしたいので、別のリストで管理するのは非効率
PY = []

# keyはYi、valueはi
# i順に出力するためのメモ用辞書
Y_to_i = dict()

for i in range(M):
    p, y = map(int, input().split())
    # タプルは後で変更できない（良く言えば「保持される」）
    PY.append((p, y))
    # yに対するiを記録、ここでyはuniqueであることが問題で保証されている
    Y_to_i[y] = i

# 第一引数(=県の番号)で大雑把にソート、同じ県内では、第二引数(=誕生年)で細かくソート
PY.sort()

ID_list = [""] * M

temp_p = PY[0][0]

idx = 1

for p, y in PY:

    # 県が変わったらidxは1に初期化
    if p != temp_p:
        idx = 1

    # 上のifをやるために現在のpをtemp_pとして記録しておく
    temp_p = p

    # ID_listには、最初に受け取った「市の番号」順に結果を格納
    ID_list[Y_to_i[y]] = str(p).zfill(6) + str(idx).zfill(6)

    # 次のためにidxをincrement
    idx += 1

# 市の番号順に入っているのでそのまま出力するだけ
for a in ID_list:
    print(a)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
import heapq as hq

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, M = NMI()
    C = [[0, 0, 0]] + [[i+1]+NLI() for i in range(M)]
    D = {i: [] for i in range(N+1)}
    names = {}
    for c in C[1:]:
        D[c[1]].append([c[2], c[0]])
    for p, YI in D.items():
        YI.sort()
        t = 1
        for y, i in YI:
            names[i] = str(p).zfill(6) + str(t).zfill(6)
            t += 1
    for i in range(1, M+1):
        print(names[i])



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
n,m=map(int,input().split())
data=[]
pn=[0 for _ in range(n)]
for i in range(m):
  p,y=map(int,input().split())
  heappush(data,(y,p,i))
data2=[]
while data:
  y,p,i=heappop(data)
  pn[p-1]+=1
  cid=str(p).zfill(6)+str(pn[p-1]).zfill(6)
  data2.append((i,cid))
for i,cid in sorted(data2):
  print(cid)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
array = []
dic = {}
for i in range(M):
    p, y = map(int,input().split())
    array.append((p,y))
    dic[y]=i
array.sort()
ans = ['']*M
now_p = array[0][0]
idx = 1
for p, y in array:
    if p != now_p:
        idx = 1
    now_p = p
    ans[dic[y]]=str(p).zfill(6)+str(idx).zfill(6)
    idx+=1
for a in ans:
    print(a)

Submission status: Accepted

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

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

yy = [0]*(n+1)
ans = [""]*m
for i, j, k in sortpy:
    pp = str(i).zfill(6)
    yy[i] += 1
    ans[k] = pp + str(yy[i]).zfill(6)

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
PY = []
Y_to_i = dict()
for i in range(M):
    p, y = map(int, input().split())
    PY.append((p, y))
    Y_to_i[y] = i
PY.sort()
ans = [""]*M
now_p = PY[0][0]
idx = 1
for p, y in PY:
    if p != now_p:
        idx = 1
    now_p = p
    ans[Y_to_i[y]] = str(p).zfill(6) + str(idx).zfill(6)
    idx += 1
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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()
lst = [[] for _ in range(n)]

for i in range(m):
    p, y = LI()
    lst[p-1].append([y, i])

for i in lst:
    i.sort()

ans = []
for i in range(n):
    for idx, [j, k] in enumerate(lst[i]):
        s = "0" * 6 + str(i+1)
        s = s[-6:]
        t = "0" * 6 + str(idx+1)
        t = t[-6:]
        ans.append([k, s+t])
ans.sort()
for i, j in ans:
    print(j)