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())
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
for i in range(M):
  L[i].append(i)
cnt = [0]*N
L = sorted(L, key = lambda x:x[1])
for i in range(M):
  L[i].append(cnt[L[i][0]-1])
  cnt[L[i][0]-1] += 1
L = sorted(L, key = lambda x:x[2])
for i in range(M):
  ID = str(L[i][0]).zfill(6)+str(L[i][3]+1).zfill(6)
  print(ID)

Submission status: Accepted

Solution code:
# 答案
from operator import itemgetter

N,M = map(int,input().split())
ｌ = []
for i in range(M):
    array = [i, 0, 0, '']
    array[1], array[2] = map(int, input().split())
    l.append(array)
tmp = 0 

# 県->年でソート
l = sorted(l, key=itemgetter(1,2))
# 識別番号をつける
for ctr in range(M):
    if l[ctr-1][1] != l[ctr][1]:
        tmp = 0
    tmp += 1
    l[ctr][3] = str(l[ctr][1]).zfill(6) + str(tmp).zfill(6)
l = sorted(l, key=itemgetter(0))

for ctr in range(M):
    print(l[ctr][3])

Submission status: Accepted

Solution code:
#nm=list(map(int,input().split()))
#n=nm[0]
#m=nm[1]
n,m=map(int,input().split())
#py=[]
y=[]
#py=[[[]]*m]
py=[[]]*m
#y=[[]]*n
#print(py)
#for i in range(m):
#    py.append([])
for i in range (n):
    y.append([])
for i in range(m):
    py[i]=list(map(int,input().split()))
    y[py[i][0]-1].append(py[i][1])#yの初期化を＊でするとyの要素全てにappendされてしまう
for i in range(n):
    y[i].sort()
#print(py)
#print(y)
d_y={}
for i in range(n):
    for j in range(len(y[i])):
        d_y[y[i][j]]=j+1
for i in range(m):
    if py[i][0]<10:
        print("00000"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif  py[i][0]<100:
        print("0000"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif py[i][0]<1000:
        print("000"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif py[i][0]<10000:
        print("00"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif py[i][0]<100000:
        print("0"+str(py[i][0]*10**6+d_y[py[i][1]]))
    else:
        print(str(py[i][0]*10**6+d_y[py[i][1]]))

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
c = [0 for i in range(M)]
for i in range(M):
    p,y = map(int, input().split())
    c[i] = [i,p,y]
c = sorted(c, key = lambda x: x[2])

l = [1 for i in range(N)]
for i in c:
    i.append(l[i[1]-1])
    l[i[1]-1] += 1

c = sorted(c, key=lambda x:x[0])
for i in c:
    print(str(i[1]).zfill(6) + str(i[3]).zfill(6))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
buf = [None] * m
cnt = {k: [] for k in range(n+1)}
for i in range(m):
  p, y = map(int, input().split())
  cnt[p].append((y, i))
for p, l in cnt.items():
  if not l:
    continue
  l.sort()
  for j, (y,i) in enumerate(l):
    buf[i] = "{:06d}{:06d}".format(p, j+1)
print("\n".join(buf))

Submission status: Accepted

Solution code:
from operator import itemgetter

n,m = map(int,input().split())
py = []
pyy = []

npy = []

for i in range(m):

    pyy=list(map(int,input().split()))
    pyy.append(i)
    py.append(pyy)

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


num = 1

npy.append([str(10**12+py[0][0]*(10**6)+num)[1:13],py[0][2]])


for i in range(m-1):
    if py[i+1][0] == py[i][0]:
        num = num + 1
        npy.append([str(10**12+py[i+1][0]*(10**6)+num)[1:13],py[i+1][2]])
    else:
        num = 1
        npy.append([str(10**12+py[i+1][0]*(10**6)+num)[1:13],py[i+1][2]])

npy.sort(key=itemgetter(1))

for j in range(m):
    print(npy[j][0])

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
N, M = 0, 0
P, Y = [], []


def set_inputs():
    global N, M, P, Y
    N, M = get_li()
    P, Y = get_data(M, [int, int])
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    prefecture = defaultdict(list)
    lst = [""] * M
    for i, (p, y) in enumerate(zip(P, Y)):
        prefecture[p].append((i, y))
    for k in prefecture.keys():
        prefecture[k].sort(key=operator.itemgetter(1))
        for i, (n, y) in enumerate(prefecture[k]):
            lst[n] = "{:06d}{:06d}".format(k, i + 1)
    for v in lst:
        print(v)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
L = [[i] + list(map(int, input().split()))+[0] for i in range(M)]
L.sort(key=lambda x: (x[1], x[2]))
c = 1
d = 0
for i in range(M):
    if d == L[i][1]:
        c += 1
        L[i][3] = c
    else:
        L[i][3] = 1
        c = 1
        d = L[i][1]
L.sort()
[print(str(L[i][1]).zfill(6) + str(L[i][3]).zfill(6)) for i in range(M)]

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
tp = []
L = []
for i in range(M):
    tp = [i] + list(map(int, input().split())) + [0]
    L.append(tp)
L.sort(key=lambda x: (x[1], x[2]))
c = 1
d = 0
for i in range(M):
    if d == L[i][1]:
        c += 1
        L[i][3] = c
    else:
        L[i][3] = 1
        c = 1
        d = L[i][1]
L.sort()
[print(str(L[i][1]).zfill(6) + str(L[i][3]).zfill(6)) for i in range(M)]

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
tp = [0,0,0,""]
L = []
for i in range(M):
    tp = [i] +list(map(int,input().split())) +[0]
    L.append(tp)
#print(L)
L.sort(key=lambda x:(x[1],x[2]))
c = 1
d = 0
for i in range(M):
    if d == L[i][1]:
        c += 1
        L[i][3] = c
    else:
        L[i][3] = 1
        c = 1
        d = L[i][1]

#print(L)

L.sort()
#print(L)
for i in range(M):
    print(str(L[i][1]).zfill(6)+str(L[i][3]).zfill(6))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[]
grp=[[] for i in range(n)]
for i in range(m):
    l.append(list(map(int,input().split())))
    grp[l[i][0]-1].append(l[i][1])
ydic={}
for i in range(n):
    grp[i].sort()
    for j in range(len(grp[i])):
        ydic[grp[i][j]]=j+1
for i in l:
    print(str(i[0]).zfill(6)+str(ydic[i[1]]).zfill(6))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
id_ = [1] * (N+1)
city = []
for i in range(M):
    P, Y = map(int, input().split())
    city.append([P, Y, i, 0])

city.sort(key=lambda t: t[1])
for i in range(len(city)):
    city[i][3] = str(city[i][0]).zfill(6) + str(id_[city[i][0]]).zfill(6)
    id_[city[i][0]] += 1

city.sort(key=lambda c: c[2])

for c in city:
    print(c[3])

Submission status: Accepted

Solution code:
N,M = map(int,input().split(' '))
#PY = [list(map(int,input().split(' '))) for i in [0]*M]

l = []
for i in range(M):
	P,Y = map(int,input().split(' '))
	l.append([P,Y,i])

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

num = [1]*N

for s in l:
	s[1] = num[s[0]-1]
	num[s[0]-1]+=1

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

for s,n,_ in l:
	print(str(s).zfill(6)+str(n).zfill(6))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [''] * M
P = [[] for _ in range(N)]
for i in range(M):
    pi, yi = map(int, input().split())
    P[pi-1].append((yi, i))

for j, pref in enumerate(P):
    pref = sorted(pref, key=lambda x: x[0])
    for k, (yi, i) in enumerate(pref):
        A[i] += str(j+1).zfill(6) + str(k+1).zfill(6)
        
for a in A:
    print(a)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
PY = [list(map(int,input().split()))+[0] for i in range(m)]
X = sorted(PY,key = lambda x:x[1])
city = {}
for x in X:
    p = x[0]
    y = x[1]
    if p in city:
        city[p] += 1
    else:
        city[p] = 1
    x[2] = city[p]
for p,y,z in PY:
    print(str(p).zfill(6)+str(z).zfill(6))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
sort_PY = sorted(PY, key = lambda x: x[1])

city = {}
for i in range(M):
  p, y = sort_PY[i][0], sort_PY[i][1]
  if p in city:
    city[p] += 1
  else:
    city[p] = 1
  sort_PY[i][2] = city[p]
for p, y, z in PY:
  print(str(p).zfill(6)+str(z).zfill(6))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
sort_PY = sorted(PY, key = lambda x: x[1])

city = {}
for i in range(M):
  p, y = sort_PY[i][0], sort_PY[i][1]
  if p in city:
    city[p] += 1
  else:
    city[p] = 1
  sort_PY[i][2] = city[p]
for p, y, z in PY:
  print(str(p).zfill(6)+str(z).zfill(6))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
# i は 通し番号
cities = sorted(([list(map(int, input().split())) + [i] for i in range(m)]))
pref = cities[0]
counter = 1
for city in cities:
    if pref != city[0]:
        counter = 1
    pref = city[0]
    rank = counter
    number = str(pref).zfill(6) + str(rank).zfill(6)
    city.append(number)
    counter += 1
for i in sorted(cities, key=lambda x: x[2]):
    print(i[3])

Submission status: Accepted

Solution code:
import sys
import bisect
n,m=map(int,input().split())
l=[[int(i) for i in l.split()] for l in sys.stdin]
s=[[0] for i in range(10**5+1)]
for i in l:
  s[i[0]].append(i[1])
for i in range(len(s)):
  s[i].sort()
for i in l:
  print('{:06}{:06}'.format(i[0],bisect.bisect_left(s[i[0]],i[1])))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
sort_PY = sorted(PY, key = lambda x: x[1])
city = {}
for i in range(M):
  p, y = sort_PY[i][0], sort_PY[i][1]
  if p in city:
    city[p] += 1
  else:
    city[p] = 1
  sort_PY[i][2] = city[p]
for p, y, z in PY:
  print(str(p).zfill(6)+str(z).zfill(6))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
py = []
for i in range(m):
    p,y = map(int,input().split())
    py.append([p,y,i])
ans = ['0'] * m
py.sort()
#print(py)
j = 0
for i in range(m):
    if j!= py[i][0]:
        j = py[i][0]
        c=1
    ans[py[i][2]] = str(py[i][0]).zfill(6) + str(c).zfill(6)
    c += 1
for i in range(m):
    print(ans[i])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = [[] for i in range(n+1)]

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

for i in range(1, len(l)):

  temp = sorted(l[i], key=lambda x: x[1])

  for j in range(len(temp)):
    temp[j] = [str(temp[j][0]).zfill(6), str(j+1).zfill(6), temp[j][2]]
  
  l[i] = temp

ans = []

for item in l:
  ans += item

for item in sorted(ans, key=lambda x: x[2]):
  print(item[0] + item[1])

Submission status: Accepted

Solution code:
from collections import defaultdict, OrderedDict

n, m = [int(x) for x in raw_input().split()]
r = defaultdict(list)
s = OrderedDict()
for i in range(m):
	p, y = [int(x) for x in raw_input().split()]
	s[(p, y)] = 0
	r[p].append(y)
for p, v in r.iteritems():
	v.sort()
	for i in range(len(v)):
		s[(p, v[i])] = i + 1

for t in s:
	print "%06d%06d"% (t[0], s[t])

Submission status: Accepted

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

n, m = [int(x) for x in raw_input().split()]
ret = []
pos = {}
pp = []
for i in xrange(m):
	p, y = [int(x) for x in raw_input().split()]
	ret.append((p, y, i))
	pp.append(p)

ret.sort()

last = 0
rank = 0
for p, y, i in ret:
	if last != p:
		rank = 0
		last = p
	rank += 1
	pos[i] = rank

for i in xrange(m):
	print '%06d%06d' % (pp[i], pos[i])

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
P, Y = [], []
for _ in range(M):
  p, y = list(map(int, input().split()))
  P.append(p)
  Y.append(y)
  
num = ['']*M

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

for i, c in enumerate(zip(P,Y)):
  pref_dict[c[0]].append([i+1, c[1]]) #市i+1, 年Y
  
for p, l in pref_dict.items():
  for i, c in enumerate(sorted(l, key=lambda x:x[1])):
    num[c[0]-1] = '{:06}{:06}'.format(p,i+1)
        
for n in num:
  print(n)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
py=[]
for i in range(m):
    p,y=map(int, input().split())
    py.append([i,p,y])
#py = [list(map(int, input().split())) for i in range(m)]
py.sort(key=lambda x:(x[1],x[2]))
sorted_py = py
num = 1
prev_p = str(sorted_py[0][1])
for i in range(m):
    p = str(sorted_py[i][1])
    if prev_p != p:
        num = 1
        prev_p = p
    str_num = str(num)
    if len(p)!=6:
        p = '0'*(6-len(p))+p
    if len(str_num)!=6:
        str_num = '0'*(6-len(str_num))+str_num
    sorted_py[i].append(p+str_num)
    num+=1
sorted_py.sort()
for i in range(m):
    print(sorted_py[i][3])

Submission status: Accepted

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

N=[1]*n
D=[]
for i in range(m):
    p, y = map(int, input().split())
    D.append([i,p,y])

D.sort(key= lambda x:x[2] )
for i in range(m):
    D[i].append(N[D[i][1]-1])
    N[D[i][1]-1]+=1

D.sort()
for d in D:
    print("{:0>6}{:0>6}".format(d[1],d[3]))

Submission status: Accepted

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

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

ans = [None]*M

for j,list_p in enumerate(list):
    list_p.sort()
    for k,(p,y) in enumerate(list_p):
        ans[y] = '%06d%06d' % (j+1,k+1)

print(*ans,sep='\n')

Submission status: Accepted

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

for i in range(M):
    j,k = map(int,input().split())
    list[j-1].append((k,i))

ans = [None]*M

for i,j in enumerate(list):
    j.sort()
    for k,(l,m) in enumerate(j):
        ans[m] = "%06d%06d" % (i+1,k+1)

print(*ans, sep='\n')

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int,input().split())
P_Y_list = np.array([input().split() for _ in range(0, M)], dtype='int')
counts = (np.zeros(N+1)).astype(int)
id_list = []

sort_ind = np.argsort(P_Y_list[:,1])
sorted_P_Y = P_Y_list[sort_ind]

for p, y in sorted_P_Y:
    counts[p] += 1
    id_list.append(str(p).zfill(6) + str(counts[p]).zfill(6))
id_list = np.array(id_list)
id_list = id_list[np.argsort(sort_ind)]
for id in id_list:
    print(id)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
pyidx = []
for i in range(m):
    py_tmp = list(map(int, (input()).split() + [str(i)]))
    pyidx += [py_tmp]

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

counter = [1] * n

ans = []
for i, pyx in enumerate(pyidx):
    p, y, idx = pyx[0], pyx[1], pyx[2]
    x_new = counter[p-1]
    counter[p-1] += 1
    ans.append([str(p).zfill(6) + str(x_new).zfill(6), idx])

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = [tuple(map(int,input().split())) for _ in range(m)]
d = [list() for _ in range(n)]
dic = [dict() for _ in range(n)]
for x in l:
  d[x[0]-1].append(x[1])
for r in range(n):
  d[r].sort()
  dic[r] = dict(zip(d[r],range(1,len(d[r])+1)))
for x in l:
  p = x[0]
  y = dic[x[0]-1][x[1]]
  print("{:06}{:06}".format(p,y))

Submission status: Accepted

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

City2 = sorted(City,key = lambda x:(x[1],x[2]))
x = 1
cur_P = 0
for i,row in enumerate(City2):
    if cur_P != row[1]:
        x = 1
        cur_P = row[1]
    else:
        x += 1
    City2[i][3] = ("000000"+str(cur_P))[-6:] + ("000000"+str(x))[-6:]
for row in City:
    print(row[3])

Submission status: Accepted

Solution code:
debug = 0
"""
N: state num
M: city num
"""


if debug:
    N = 2
    m = 10
else:
    (N, M) = list(map(int, input().split()))

if debug:
    p_y_list = [
        [1, 30]
        ,[1, 20]
        ,[1, 10]
        ,[1, 3]
        ,[2, 63]
        ,[2, 33]
        ,[2, 23]
        ,[3, 21]
        ,[3, 7]
    ]

city_id_list = []
for num, z in enumerate(range(M)):
# for num, (P, Y) in enumerate(p_y_list):
    
    if not debug:
        (P, Y) = list(map(int, input().split()))

    city_id_list.append([Y, P, num])
    
city_id_list = sorted( city_id_list, key= lambda x: x[0])

state_cnt = {}
tmp_list = []
for (Y, P, num) in city_id_list:
    
    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    tmp_id = str(P).zfill(6) + str(state_cnt[P]).zfill(6)
    
    tmp_list.append([num, tmp_id])
    
for cid in sorted(tmp_list, key=lambda x: x[0]):
    print(cid[1])

Submission status: Accepted

Solution code:
N, M = map ( int, input ( ).split ( ) )# N,Mを取得
#初期化
lists = [ ]
#listに要素を追加　後で並び変えるため並び替える前の順番を示すキーを第三要素に挿入しておく
for i in range ( M ):
    lists.append ( list ( map ( int, input ( ).split ( ) ) ) + [ i ] )
#第一要素に昇順で並び替えた後、第二要素で昇順に並び替える
lists.sort ( key=lambda x: x[ 1 ] )
lists.sort ( key=lambda x: x[ 0 ] )
# befは前回の第一要素　stateは第一要素での順位
bef = 0
state = 0
retstr = ''
triple = [ ]#第四要素に識別番号を追加したリストの初期化
for i in lists:
    if (i[ 0 ] != bef):
        bef = i[ 0 ]
        state = 1
        triple.append ( [ i[ 0 ], i[ 1 ], i[ 2 ], str ( i[ 0 ] ).rjust ( 6, '0' ) + str ( state ).rjust ( 6, '0' ) ] )
    else:
        state += 1
        triple.append ( [ i[ 0 ], i[ 1 ], i[ 2 ], str ( i[ 0 ] ).rjust ( 6, '0' ) + str ( state ).rjust ( 6, '0' ) ] )
 
triple.sort ( key=lambda x: x[ 2 ] )#第三要素で並び替えて、元の入力に対応した式ベンツ番号の順番に戻す
for i in triple:
    print ( i[ 3 ] )#識別番号の出力

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
py = [list(map(int, input().split())) for i in range(M)]
PY = sorted(py, key=lambda x: x[1])
pydict = defaultdict(lambda: 0)
ans = {}
for i in PY:
    pydict[i[0]] += 1
    ans[str(i[0]) + str(i[1])] = "{:0=6}".format(i[0]) + "{:0=6}".format(pydict.get(i[0]))

for i in py:
    print(ans.get(str(i[0]) + str(i[1])))

Submission status: Accepted

Solution code:
import math

def A():
    x, a, b = [int(x) for x in input().split()]
    if abs(x-a) < abs(x-b):
        print('A')
    else:
        print('B')
def B():
    S = input()
    alphabet = [False for x in range(26)]
    for char in S:
        i = ord(char) - ord('a')
        alphabet[i] = True
    printed = False
    for i in range(len(alphabet)):
        if alphabet[i] == False:
            print(chr(ord('a')+i))
            printed = True
            break
    if printed == False:
        print("None")
def C():
    pass

def E():
    n, m = [int(x) for x in input().split()]
    P = [[] for i in range(n)]
    for j in range(m):
        p, y = [int(x) for x in input().split()]
        P[p-1].append([y, ('000000'+str(p))[-6:], j])

    for i in range(n):
        P[i] = sorted(P[i], key=lambda x:x[0])
        for j in range(len(P[i])):
            P[i][j][1] += (('000000'+str(j+1))[-6:])
    P = [e for inner_list in P for e in inner_list]
    P = sorted(P, key=lambda x:x[2])
    for p in P:
        print(p[1])
E()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n,m = LI()
    v = LIR(m)
    for i in range(m):
        v[i] = [v[i][0],v[i][1],i]
    v.sort(key = lambda x:x[1])
    f = [0 for i in range(n+1)]
    ans = [None for i in range(m)]
    for p,y,i in v:
        f[p] += 1
        s = "{:0>6}".format(p)
        t = "{:0>6}".format(f[p])
        ans[i] = s+t
    for i in ans:
        print(i)
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
p_list = []
for i in range(m):
    p_list.append(list(int(i) for i in input().split()))
a = sorted(p_list)
tmp = 0
b = {}
for (i,j) in a:
    if i != tmp:
        count = 1
        tmp = i
        b[(i,j)] = "0"*(6-len(str(i))) + str(i) + "0"*(6-len(str(count))) + str(count)
    else:
        count += 1
        b[(i,j)] = "0"*(6-len(str(i))) + str(i) + "0"*(6-len(str(count))) + str(count)
for (i,j) in p_list:
    print(b[(i,j)])

Submission status: Accepted

Solution code:
n,m=[int(i) for i in input().split()]
id=[[int(i) for i in input().split()]+[j] for j in range(m)]
pre_num=[0]*(n+1)
ans=[""]*m
id.sort(key=lambda x:x[1])
for p,y,i in id:
    pre_num[p]+=1
    ans[i]=str(p).zfill(6)+str(pre_num[p]).zfill(6)
print("\n".join(ans))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
li=[[list(map(int,input().split())),i] for i in range(M)]
li=sorted(li, key=lambda x:x[0][1])
counter=[0]*N
li_id=[]

for j in li:
    counter[int(j[0][0])-1]+=1
    x=str(j[0][0])
    y=str(counter[int(j[0][0])-1])
    ID=('0'*(6-len(x)))+x+('0'*(6-len(y)))+y
    li_id.append([j[1],ID])
li_id=sorted(li_id)
for k in li_id:
    print(k[1])

Submission status: Accepted

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

from operator import itemgetter
I = [0]*(n+1)
Ans = [""]*m

PY.sort(key = itemgetter(1))
for py in PY:
    I[py[0]] += 1
    Ans[py[2]] = str(format(py[0],"06d"))+str(format(I[py[0]],"06d"))
print(*Ans,sep="\n")

Submission status: Accepted

Solution code:
from sys import exit
N,M = [int(n) for n in input().split()]
P = [0]*M
Y = [0]*M
l = [0]*M
dic = dict(zip(range(1,N+1),[0]*N))
for i in range(M):
    P[i], Y[i] = [int(n) for n in input().split()]
    l[i] = [i,P[i], Y[i], str(P[i]).zfill(6)]

l = sorted(l,key=lambda x:x[2])
for i in range(M):
    dic[l[i][1]]+=1
    l[i][3]+=str(dic[l[i][1]]).zfill(6)
l = sorted(l,key=lambda x:x[0])
for i in range(M):
    print(l[i][3])
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
anses = [0] * M
pre = [0] * N
 
for idx in range(M):
    p, y = (int(x) for x in input().split())
    anses[idx] = [idx, p, y, 0]

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

for ans in anses:
    pre[ans[1]-1] += 1
    ans[3] = pre[ans[1]-1]

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

for ans in anses:
    print('{:0=6}{:0=6}'.format(ans[1], ans[3]))

Submission status: Accepted

Solution code:
def main113my():
    N, M = (int(x) for x in input().split())

    answer = [0] * M
    pre = [0] * N

    for m in range(M):
        p, y = (int(x) for x in input().split())
        answer[m] = [m, p, y, 0]

    answer = sorted(answer, key=lambda x: x[2])  #  誕生した年でソート

    for a in answer:
        pre[a[1]-1] += 1
        a[3] = pre[a[1]-1]

    answer = sorted(answer, key=lambda x: x[0])  #  市の番号順にソート

    for a in answer:
        print("{:06d}{:06d}".format(a[1], a[3]))

main113my()

Submission status: Accepted

Solution code:
from operator import itemgetter

N, M = [int(_) for _ in input().split()]
PY = [[__] + [int(_) for _ in input().split()] for __ in range(M)]
PY.sort(key=itemgetter(1, 2))

p = 0
x = 1
for i in PY:
    if p != i[1]:
        p = i[1]
        x = 1
    i.append('{:06}{:06}'.format(p, x))
    x += 1

for i in sorted(PY):
    print(i[3])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

p.sort()
cnt = 0
pre = -1

for city in p:
    if city[0] == pre:
        cnt = cnt + 1
    else:
        pre = city[0]
        cnt = 1

    city.append("{:0>6}{:0>6}".format(city[0], cnt))

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

for city in p:
    print(city[3])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
py = ['' for _ in range(M)]
for i in range(M):
    py[i] = list(map(int, input().split())) + [i] + [0]

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

p = 0
for i in range(M):
    if py[i][0] != p:
        cnt = 1
        p = py[i][0]
    else:
        cnt += 1
    py[i][3] = str(p).zfill(6) + str(cnt).zfill(6)

py.sort(key = lambda x: x[2])
for i in range(M):
    print(py[i][3])

Submission status: Accepted

Solution code:
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]))
cur = [0 for _ in range(N)]
ans_list = []
for i in range(M):
    ans = '0'*(6-len(str(PY[i][1]))) + str(PY[i][1])
    cur[PY[i][1]-1] += 1
    ans += '0'*(6-len(str(cur[PY[i][1]-1]))) + str(cur[PY[i][1]-1])
    ans_list.append([PY[i][0], ans])

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

for i in range(M):
  PY.append([i, list(map(int,input().split())), 'x'])

PY.sort(key=itemgetter(1,2))
cnt_pref = {}

for i in range(M):  
  p, y = PY[i][1][0], PY[i][1][1]
  if (p in cnt_pref):
    cnt_pref[p] += 1
  else:
    cnt_pref[p] = 1
  PY[i][2] = str(p).zfill(6) + str(cnt_pref[p]).zfill(6)

PY.sort(key=itemgetter(0))
for i in PY:
  print(i[2])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
iPYx = []
for i in range(M):
  P, Y = map(int, input().split())
  iPYx.append([i, P, Y])

iPYx.sort(key = lambda x: (x[1], x[2]))
cnt = 0
for i in range(M):
  if i == 0 or iPYx[i][1] != iPYx[i - 1][1]:
    cnt = 1
  else:
    cnt += 1
  iPYx[i].append(cnt)
iPYx.sort(key = lambda x: x[0])
for i in range(M):
  print("{:06}{:06}".format(iPYx[i][1], iPYx[i][3]))

Submission status: Accepted

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

ids, ps, ys = [], [], []
for i in range(m):
  p, y = [int(item) for item in input().split()]
  ids.append(i)
  ps.append(p)
  ys.append(y)

city_num = [0] * (n+1)
ids, ps, ys = zip(*sorted(zip(ids, ps, ys) ,key = lambda x : x[2]))
names = []

for p in ps:
  city_num[p] += 1
  names.append("{0:06d}".format(p) + "{0:06d}".format(city_num[p]))
  
names, _ = zip(*sorted(zip(names, ids), key=lambda x:x[1]))
for name in names:
  print(name)

Submission status: Accepted

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

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

belongs = [0 for _ in range(N)]

for i, (p, y, n) in enumerate(city):
    belongs[p-1] += 1
    city[i].append(belongs[p-1])
    
city = sorted(city, key=lambda x: x[2])

for p, y, n, n_city in city:
    print('{:06d}{:06d}'.format(p, n_city))

Submission status: Accepted

Solution code:
(n, m) = map(int, input().split())
cities = []
for _ in range(m):
    cities.append(list(map(int, input().split())))

city_dict = {}
for i, city in enumerate(cities):
    if not city[0] in city_dict:
        city_dict[city[0]] = []
    city_dict[city[0]].append([i, city[1], ""])

ans = []
for key, value in city_dict.items():
    value.sort(key=lambda x: x[1])
    for i, v in enumerate(value):
        v[2] = "{}{}".format(str(key).zfill(6), str(i+1).zfill(6))
    ans.extend(value)
ans.sort(key=lambda x:x[0])
for a in ans:
    print(a[2])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
py = [list(map(int,input().split())) for i in range(m)]
for i in range(m):
    py[i].append(i)
pysorted = sorted(py,key=lambda x:x[1])
#県の出現回数をカウント
appear = [1]*(n+1)
for i in range(m):
    pysorted[i].append(str(pysorted[i][0]).zfill(6) + str(appear[pysorted[i][0]]).zfill(6))
    appear[pysorted[i][0]] += 1
pyresorted = sorted(py,key=lambda x:x[2])
for i in range(m):
    print(py[i][3])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a=[]
for i in range(M):
    n,m=map(int,(input().split()))
    a.append([n,m,i])
ans=['0']*M
a.sort()
j=0
for i in range(M):
    if j!=a[i][0]:
        j=a[i][0]
        c=1
    ans[a[i][2]]=str(a[i][0]).zfill(6)+str(c).zfill(6)
    c+=1
for i in range(M):
    print(ans[i])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
PY=[list(map(int,input().split()))+[0] for _ in range(M)]
sort_PY=sorted(PY,key=lambda x:x[1])
c={}
for i in range(M):
    p=sort_PY[i][0]
    if(p in c):
        c[p]+=1
    else:
        c[p]=1
    sort_PY[i][2]=c[p]
for p,y,z in PY:
    print(str(p).zfill(6)+str(z).zfill(6))

Submission status: Accepted

Solution code:
from collections import defaultdict
def inpl(): return list(map(int,input().split()))

class increment:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

ui = defaultdict(increment())
plist = []
clists = []
Np = 0

N, M = inpl()
P = [0]*M
Y = [0]*M
for i in range(M):
    P[i], Y[i] = inpl()
    p = ui[P[i]]
    if p >= Np:
        plist.append(P[i])
        clists.append([[i,Y[i]]])
        Np += 1
    else:
        clists[p].append([i,Y[i]])

ids = ['']*M
for p in range(Np):
    clists[p].sort(key=lambda x: x[1])
    for c in range(len(clists[p])):
        cid = "{0:06d}".format(plist[p]) + "{0:06d}".format(c+1)
        ids[clists[p][c][0]] = cid

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