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:
import sys
 
s2nn = lambda s: [int(c) for c in s.split(' ')]
 
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
 
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
 
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
 
def main(N, M, PYm):
    # 県番号pと市誕生年yから認識番号を得られる辞書
    # dic[p][y] -> 認識番号
    dic = {}
    # 県ごとに、市誕生年を昇順ソートし、認識番号を1,2,...と対応づける
    # dic2[p] -> [(1, sorted_y1), (2, sorted_y2), ...]
    # dic2tmp[p] -> [y1, y2, ...]
    #dic2 = {}
    dic2tmp = {}
    for p in range(N+1):
        dic[p] = {}
        #dic2[p] = []
        dic2tmp[p] = []
    for p, y in PYm:
        dic2tmp[p].append(y)
    for p in range(N+1):
        dic2tmp[p].sort()
        nby = [(i+1, y) for i, y in enumerate(dic2tmp[p])]
        #dic2[p] = nby
        for nb, y in nby:
            dic[p][y] = nb
    # 表示
    for p, y in PYm:
        nb = dic[p][y]
        print('%06d%06d' % (p, nb))

N, M = i2nn()
PYs = ss2nnn(ii2ss(M))
main(N, M, PYs)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
l=[list(map(int,input().split()))+[i] for i in range(M)]
l=sorted(l,key=lambda x:x[0]*1000000000+x[1])
cnt=0
for i,x in enumerate(l):
    if x[0]!=l[i-1][0]:cnt=0
    cnt+=1
    l[i][1]=cnt
for x in sorted(l,key=lambda x:x[2]):
    print("{:06}{:06}".format(x[0],x[1]))

Submission status: Accepted

Solution code:
from operator import itemgetter

n, m= map(int, (input().split()))
pyi = [list(map(int, (input().split()))) + [i] for i in range(m)]
pyi.sort(key=itemgetter(1))
pyi.sort(key=itemgetter(0))
cityflag = 0
ans = []
for rep in range(m):
    if pyi[rep][0] != pyi[rep - 1][0]:
        cityflag = 0

    cityflag += 1
    ans += [[pyi[rep][0] , cityflag, pyi[rep][2]]]

for i in sorted(ans, key=itemgetter(2)):
    print(str(i[0]).zfill(6) + str(i[1]).zfill(6))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
PY = []
for i in range(M):
    PY.append(list(map(int, input().split())) + [i])
    
PY.sort(key = lambda x:x[1])
PY.sort(key = lambda x:x[0])
    
bef = 0
state = 0
retstr = ''
triple = []
for i in PY:
    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())
years = defaultdict(list)
Q = []
for i in range(M):
    P, Y = map(int, input().split())
    years[P].append(Y)
    Q.append((P, Y))

rev_list = {}
for P, Y in years.items():
    Y.sort()
    rev_list[P] = {}
    for i in range(len(Y)):
        rev_list[P][Y[i]] = i + 1

for q in Q:
    print('{:06}{:06}'.format(q[0], rev_list[q[0]][q[1]]))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
py = {}
for i in range(m):
    p,y = map(int,input().split())
    py[i] = [p,y]
ans = sorted(py.items(),key=lambda x:x[1])
#print(ans)
#print(ans[0][1])
count = 1
ans[0][1].append(count)
#print(ans)
for i in range(1,m):
    if ans[i][1][0] == ans[i-1][1][0]:
        count += 1
    else:
        count = 1
    ans[i][1].append(count)
#print(number)
ans = sorted(ans)
#print(ans)
for i in range(m):
    a = "{0:06d}".format(ans[i][1][0])
    b = "{0:06d}".format(ans[i][1][2])
    print(a,end="")
    print(b)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[[]for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  l[a-1]+=[[i,a,b]]
for a in range(n):
  l[a].sort(key=lambda x:x[2])
  for i in range(len(l[a])):
    l[a][i][2]=i+1
ll=[]
for i in range(n):
  ll+=l[i]
ll.sort(key=lambda x:x[0])
for i,a,b in ll:
  print("0"*(6-len(str(a)))+str(a)+"0"*(6-len(str(b)))+str(b))

Submission status: Accepted

Solution code:

N,M = map(int,input().split())
PY = [list(map(int,input().split()))+ [i] for i in range(M)]
    
def create(x):
    a = str(x)
    a = list(a)
    n = len(a)
    s = ['0'] * (6-n) + a
    s = ''.join(s)
    return s

ans = [0] * M
PY.sort()
idx = 1
flag = False
for i in range(M):
    if i > 0 and PY[i][0] != PY[i-1][0] : idx = 1
    ans[PY[i][2]] = create(PY[i][0]) + create(idx)
    idx += 1
    
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
y = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
    y[i].insert(0, i)
y.sort(key=itemgetter(2))
y.sort(key=itemgetter(1))
ans = []
tmp = 0
for i in range(M):
    if y[i][1] != y[i-1][1]:
        tmp = 0
    tmp += 1
    shita = str(tmp).zfill(6)
    ue = str(y[i][1]).zfill(6)
    ans.append([y[i][0], ue + shita])
ans.sort(key=itemgetter(0))
for i in range(M):
    print(ans[i][1])

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)
  
PY.sort(key=lambda x:x[1])
pcount = {i:0 for i in range(1,N+1)}
ID = {i:"" for i in range(1,M+1)}

for i in range(M):
  pcount[PY[i][0]] += 1
  PY[i].append("{:0=6}".format(PY[i][0]) + "{:0=6}".format(pcount[PY[i][0]]))
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())
ans = [ "" for i in range(m) ]
data = []
for i in range(m):
    a,b = map(int,input().split())
    data.append([b,a,i])
data = sorted(data)
cnt = [ 1 for i in range(n+1) ]
for i in data:
    a = "0"*(6-len(str(i[1]))) + str(i[1]) + "0" * (6-len(str(cnt[i[1]]))) + str(cnt[i[1]])
    ans[i[2]] = a
    cnt[i[1]] += 1

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
from operator import itemgetter
import collections
import math
import sys
import itertools
N,M = map(int,input().split())
nums = []
for i in range(M):
    P,Y = map(int,input().split())
    nums.append([P,Y,i])
nums.sort(key=itemgetter(1))
counter = collections.defaultdict(int)
anss= []
for i in nums:
    counter[i[0]]+=1
    ans = str(i[0]).zfill(6)+str(counter[i[0]]).zfill(6)
    anss.append([ans,i[2]])
anss.sort(key=itemgetter(1))
for ans in anss:
    print(ans[0])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
pys = [list(map(int, input().split())) for _ in range(m)]
map_ = {}
for i, (p, y) in enumerate(pys):
    map_.setdefault(p, [])
    map_[p].append(i)

for val in map_.values():
    val.sort(key=lambda i: pys[i][1])

ans = [None] * m
for key, val in map_.items():
    for num, i in enumerate(val):
        ans[i] = '{:06d}'.format(key) + '{:06d}'.format(num + 1)
for a in ans:
    print(a)

Submission status: Accepted

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

for i in range(m):
    if i==0 or p[i][0] != p[i-1][0]:
        cnt=1
    else:
        cnt+=1
    p[i].append(cnt)

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

for i in range(m):
    print("{:06}{:06}".format(p[i][0],p[i][3]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import defaultdict
from operator import itemgetter
INF = float("inf")


def solve(N: int, M: int, iPY):
    d = defaultdict(list)
    iPY.sort(key=itemgetter(2))
    for i, p, y in iPY:
        d[p].append([i, p, y])
    ans = []
    for k in d:
        for j, (i, p, y) in enumerate(d[k]):
            ans.append([i, "{0:06d}{1:06d}".format(p, j+1)])
    ans.sort()
    for a in ans:
        print(a[1])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    iPY = [[]] * (M)
    for i in range(M):
        iPY[i] = [i, int(next(tokens)), int(next(tokens))]
    solve(N, M, iPY)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    PY[i].append(i)
PY.sort(key=lambda x:x[1])
ans = [0]*M
num = [0]*N
for p,y,i in PY:
    ans[i] = str(p).zfill(6) + str(num[p-1]+1).zfill(6)
    num[p-1] += 1
for s in ans:print(s)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

class Prefecture():
    def __init__(self, i, P, Y):
        self.i = i
        self.P = P
        self.Y = Y
    
    def make_id(self, x):
        upper = str(self.P)
        while len(upper) < 6:
            upper = "0" + upper
        lower = str(x)
        while len(lower) < 6:
            lower = "0" + lower
        self.id = upper + lower            


def solve():
    N, M = list(map(int, input().split(" ")))
    prefectures = [None for i in range((N+1))]
    for i in range(M):
        p, y = list(map(int, input().split(" ")))
        if prefectures[p] is None:
            prefectures[p] = []
            prefectures[p].append(Prefecture(i, p, y))
        else:
            prefectures[p].append(Prefecture(i, p, y))

    # ID作成
    ans = []
    for i in range(1, N+1):
        if prefectures[i] is None:
            continue

        prefectures[i].sort(key=lambda x: x.Y)
        for j in range(len(prefectures[i])):
            prefectures[i][j].make_id(j+1)
            ans.append(prefectures[i][j])
    
    # iでソートして出力
    ans.sort(key=lambda x: x.i)

    for prefecture in ans:
        print(prefecture.id)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
from bisect import bisect_left

def main():
	N, M = map(int, input().split(" "))
	data_org = []
	for _ in  range(M):
		p, y = map(int, input().split(" "))
		data_org.append((y, p))
		
	data_tmp = copy.copy(data_org)
	data_tmp.sort()
	
	counts = [0 for _ in range(N)]
	ans = []
	for i, val in enumerate(data_tmp):
		y, p = val
		p_zero = str(p).zfill(6)
		no = counts[p-1] + 1
		no_zero = str(no).zfill(6)
		counts[p-1] += 1
		
		ans.append(p_zero + no_zero)
		
	for i, val in enumerate(data_org):
		y, p = val
		tmp = bisect_left(data_tmp, (y, p))
		print(ans[tmp])
	
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

PY = [[0,0,0,0] for i in range(M)] #index,p,y,number

for m in range(M):
    PY[m][0] = m
    PY[m][1],PY[m][2] = map(int,input().split())

PY.sort(key=lambda x:x[2])
cnt = [0]*(N+1)

for m in range(M):
    cnt[PY[m][1]] += 1
    PY[m][3] = cnt[PY[m][1]]

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

for m in range(M):
    print(str(PY[m][1]).zfill(6) + str(PY[m][3]).zfill(6))

Submission status: Accepted

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

py = []
for i in range(M):
    py.append(list(map(int, input().split())))
    py[i].append(i)

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

number = []
for i in range(M):
    if i == 0:
        ct = 1
        number.append((str(py[i][0]).zfill(6) + str(ct).zfill(6), py[i][2]))
    else:
        if py[i-1][0] == py[i][0]:
            ct += 1
            number.append((str(py[i][0]).zfill(6) + str(ct).zfill(6), py[i][2]))
        else:
            ct = 1
            number.append((str(py[i][0]).zfill(6) + str(ct).zfill(6), py[i][2]))

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

for i in number:
    print(i[0])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
py = []
for _ in range(M):
    py.append(list(map(int, input().split())))
d = {}
now = 0
num = 0
for p, y in sorted(py):
    if now != p:
        now = p
        num = 1
    d[(p, y)] = num
    num += 1
for p, y in py:
    print('{:06d}{:06d}'.format(p, d[(p, y)]))

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-1,y,i])
#n次元リストのソート
#普通にsort()をつけると1番目の要素でソート
#1番目の要素が同じ場合は2番目の要素の大小によってソートされる
P_Y.sort() 

ans_P_Y = [] 
count = 1
for i in range(M):
  if(i != 0):
    if(P_Y[i-1][0] == P_Y[i][0]): count += 1
    else: count = 1
  ans_P_Y.append([P_Y[i][2],P_Y[i][0]+1,count])
ans_P_Y.sort()

for i in range(M):
  ans = str(ans_P_Y[i][1]).zfill(6) + str(ans_P_Y[i][2]).zfill(6)
  print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
py = [list(map(int, input().split())) + [0] for _ in range(m)]
py_sorted = sorted(py, key=lambda x: x[1])
d = {}

for pyi in py_sorted:
    if pyi[0] not in d:
        d[pyi[0]] = 1
    else:
        d[pyi[0]] += 1
    pyi[2] = d[pyi[0]]

for pyi in py:
    print(str(pyi[0]).zfill(6) + str(pyi[2]).zfill(6))

Submission status: Accepted

Solution code:
import operator
def makecode(n):
	m = n
	s = str(n)
	while m < 100000:
		s = '0' + s
		m = m * 10
	return s
N, M = map(int, raw_input().split())
data = []
serial = []
for i in range(0, N):
	data.append([])
for i in range(0, M):
	P, Y = map(int, raw_input().split())
	data[P-1].append([i+1, Y])
for i in range(0, N):
	data[i].sort(key=operator.itemgetter(1))
for i in range(0, N):
	for j in range(0, len(data[i])):
		s = makecode(i+1) + makecode(j+1)
		serial.append([data[i][j][0], s])
serial.sort(key=operator.itemgetter(0))
for i in range(0, M):
	print serial[i][1]

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split()))
PY = []
DD = [0 for i in range(N+1)]
for i in range(M):
    P,Y = list(map(int,input().split()))
    PY.append((P,Y,i,""))
PY.sort()
DY = []
for i in PY:
    DY.append((i[2],str(i[0]).zfill(6) + str(DD[i[0]]+1).zfill(6)))
    DD[i[0]] = DD[i[0]] + 1
DY.sort()
for i in DY:
    print(i[1])

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]


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

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

pref = {}

for i in range(M):

    if P[i] not in pref:
        pref[P[i]] = []

    pref[P[i]].append({
        'city': i,
        'year': Y[i],
    })

for key in pref:
    pref[key].sort(key=lambda x: x['year'])

# print(pref)

city = {}

for key in pref:
    for i in range(len(pref[key])):
        city[pref[key][i]['city']] = {'order': i + 1}

# print(pref)

# output
for i in range(M):
    print(format(P[i], '06d') + format(city[i]['order'], '06d'))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
write = sys.stdout.write

N, M = map(int,input().split())
cities = []
for i in range(M):
    p, y = map(int,readline().split())
    temp = [p, y, i]
    cities.append(temp)
id = [1 for i in range(N)] #国i+1の都市に対して次に割り振るべきID
sortedcities = sorted(cities, key=lambda x:x[1])
for i in range(M):
    sortedcities[i].append(id[sortedcities[i][0]-1])
    id[sortedcities[i][0]-1] += 1
originalcities = sorted(sortedcities, key=lambda x:x[2])
for i in range(M):
    write(str(originalcities[i][0]).zfill(6) + str(originalcities[i][3]).zfill(6) + "\n")

Submission status: Accepted

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

for i in range(M):
    Ken_index[P_Y_i[i][0] - 1].append(P_Y_i[i])
for i in range(N):
    if len(Ken_index[i]) != 0:
        Ken_index[i].sort(key=lambda x: x[1])

Ken_Update = []
for Ken in Ken_index:
    for i in range(len(Ken)):
        Ken_Update.append(['{0:06d}'.format(Ken[i][0]) + '{0:06d}'.format(i+1), Ken[i][2]])

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

for i in range(len(Ken_Update)):
    print(Ken_Update[i][0])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis,key =lambda x:(x[0],x[1]))
flag = lis_sort[0][0]
i = 1
for x in lis_sort:
    if x[0] != flag:
        flag = x[0]
        i=1
    x[1] = '0'*(6-len(str(i)))+str(i)
    i+=1
for x in lis:
    print('0'*(6-len(str(x[0]))),str(x[0]),x[1],sep='')

Submission status: Accepted

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

city.sort(key = lambda x: (x[0], x[1]))
prev_P = 0
count = 0
for i in city:
  if prev_P == i[0]:
    count += 1
  else:
    count = 1
  id[i[2]] = str(i[0]).zfill(6) + str(count).zfill(6)
  prev_P = i[0]

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
py_list = []
d = dict()
for i in range(M):
    p,y = map(int,input().split())
    py_list.append([p,y])
py_sorted =  sorted(py_list)
p_temp = py_sorted[0][0]
count = 1
for p,y in py_sorted:
    if p_temp != p:
        p_temp = p
        count = 1
    d[(p,y)] = count
    count += 1

for i in range(M):
    s = d[(py_list[i][0],py_list[i][-1])]
    s = str(s)
    ss = str(py_list[i][0]).zfill(6) + s.zfill(6)
    print(ss.strip())

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(m)]
sPY = sorted(PY, key=lambda x:(x[0], x[1]))

ans = {}
key, cnt = 1, 1
for p, y in sPY:
    if p != key:
        key = p
        cnt = 1
    ans[y] = cnt
    cnt += 1

for p, y in PY:
    a = str(p).zfill(6)
    b = str(ans[y]).zfill(6)
    print("{}{}".format(a, b))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(M)]
 
now = 0
num = 0
d = dict()
for p, y in sorted(data):
    if now != p:
        now = p
        num = 1
    d[(p,y)] = num
    num += 1
 
for p, y in data:
    print('{:06d}{:06d}'.format(p, d[(p,y)]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
for i in range(m):
	a.append([int(n) for n in input().split()])
	a[i].append(i)
a = sorted(a)
b = []
counter = 0
counter1 = 1
for i in range(m):
	c = ""
	if a[i][0] < 100000:
		getlen = len(str(a[i][0]))
		c = "0" * (6 - getlen) + str(a[i][0])
	else:
		c = str(a[i][0])
	if i == 0:
		c += "000001"
		counter = a[0][0]
	elif a[i][0] == counter:
		getlen = len(str(counter1 + 1))
		c += "0" * (6 - getlen) + str(counter1 + 1)
		counter1 += 1
	else:
		counter1 = 1
		c += "000001"
		counter = a[i][0]
	a[i].append(c)

for i in range(m):
	a[i][2], a[i][0] = a[i][0], a[i][2]
a = sorted(a)
for i in range(m):
	print(a[i][3])

Submission status: Accepted

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

now = 0
num = 0
d = dict()
for p, y in sorted(data):
    if now != p:
        now = p
        num = 1
    d[(p,y)] = num
    num += 1

for p, y in data:
    print('{:06d}{:06d}'.format(p, d[(p,y)]))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]
sPY = sorted(PY, key=lambda py: (py[0],py[1]))

i = 1
bp = 1
d = {}
for p, y in sPY:
    if p != bp:
        i = 1
        bp = p
    d[y] = i
    i += 1

for p, y in PY:
    i = d[y]
    print("{0:06}{1:06}".format(p, i))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]
sPY = sorted(PY, key=lambda py: (py[0],py[1]))

i = 1
bp = 1
d = {}
for p, y in sPY:
    if p != bp:
        i = 1
        bp = p
    d[y] = i
    i += 1

for p, y in PY:
    print("{0:06}{1:06}".format(p, d[y]))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
pyi = []
exists = [0] * N
for i in range(M):
    p, y = map(int, input().split())
    pyi.append([p, y, i])
pyi.sort(key = lambda x: x[1])
iid = []
for i in range(M):
    p = pyi[i][0]
    div = pyi[i][2]
    exists[p - 1] += 1
    iid.append([div, str(p).zfill(6)+str(exists[p - 1]).zfill(6)])
iid.sort()
for i in range(M):
    print(iid[i][1])

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
p_li = []
y_li = []
for i in range(m):
    p, y = list(map(int, input().split()))
    p_li.append(p)
    y_li.append(y)
num = list(range(m))
zip_li = zip(p_li, y_li, num)
from operator import itemgetter
zip_li = sorted(zip_li, key=itemgetter(1))
p_li, y_li, num = zip(*zip_li)
ans = []
f_num = [0 for i in range(n)]
for p in p_li:
    p -= 1
    f_num[p] += 1
    f_n = f_num[p]
    p+=1
    ans.append(str(p).zfill(6) + str(f_n).zfill(6))
zip_li = zip(num, ans)
zip_li = sorted(zip_li, key=itemgetter(0))
num, ans = zip(*zip_li)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
def generate_id(p, x):
    return str(p).zfill(6) + str(x).zfill(6)

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

A = []
B = {}
C = {}

for _ in range(M):
    a = tuple(map(int, input().split()))
    A.append(a)

    if a[0] in B:
        t = B[a[0]]
        t.append(a[1])
        B[a[0]] = t
    else:
        B[a[0]] = [a[1]]

for k, vs in B.items():
    vs = sorted(vs)
    for i, v in enumerate(vs):
        C[(k, v)] = i + 1

for a in A:
    print(generate_id(a[0], C[a]))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
P = {}
for i in range(1, M+1):
    _p, _y = map(int, input().split())
    if _p not in P: 
        P[_p] = []
    P[_p].append((i, _y))

# P_i rank
numbers = {}

for _p in P:
    for j, t in enumerate(sorted(P[_p], key=lambda x: x[1])):
        numbers[t[0]] = "{:06d}{:06d}".format(_p, j+1)

for i in range(1, M+1):
    print(numbers[i])

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter as ig
input=sys.stdin.readline

m,n=map(int,input().split())
dt=[]
for i in range(n):
    p,y = map(int, input().split())
    dt+=[[i,p,y,0]]
dt.sort(key=ig(1,2))
pi=1
prep=0
for x in dt:
    if prep==x[1]:
        pi+=1
    else:
        pi=1
    x[3]=pi
    prep=x[1]
dt.sort()
for x in dt:
    print(str(x[1]).zfill(6)+str(x[3]).zfill(6))

Submission status: Accepted

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

m,n=map(int,input().split())
dt=[]
for i in range(n):
    p,y = map(int, input().split())
    dt+=[[i,p,y,0]]
dt.sort(key=lambda x:(x[1],x[2]))
pi=1
prep=0
for x in dt:
    if prep==x[1]:
        pi+=1
    else:
        pi=1
    x[3]=pi
    prep=x[1]
dt.sort()
for x in dt:
    print(str(x[1]).zfill(6)+str(x[3]).zfill(6))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
p = [list(map(int, input().split())) + [i] for i in range(M)]
p.sort()
i = 0
for n in range(1, N + 1):
    count = 1
    while not(i >= M or p[i][0] != n):
        p[i] += [str(n).zfill(6) + str(count).zfill(6)]
        i += 1
        count += 1
p.sort(key=lambda x: x[2])
for a in p:
    print(a[3])

Submission status: Accepted

Solution code:
pref_num, city_num = map(int, input().split())
py = sorted([list(map(int, input().split())) + [i] for i in range(city_num)], key=lambda py: py[1])

city_num_in_prefs = [0 for _ in range(pref_num)]

city_nums = []
for pref, year, i in py:
    city_num_in_prefs[pref-1] += 1
    city_num = "{:06}{:06}".format(pref, city_num_in_prefs[pref-1])
    city_nums.append([city_num, i])

city_nums.sort(key=lambda x: x[1])
for num, index in city_nums:
    print(num)

Submission status: Accepted

Solution code:
m,n=map(int,input().split())
dt=[]
for i in range(n):
    p,y = map(int, input().split())
    dt+=[[i,p,y,0]]
dt.sort(key=lambda x:(x[1],x[2]))
pi=1
prep=0
for x in dt:
    if prep==x[1]:
        pi+=1
    else:
        pi=1
    x[3]=pi
    prep=x[1]
dt.sort()
for x in dt:
    print(str(x[1]).zfill(6)+str(x[3]).zfill(6))

Submission status: Accepted

Solution code:
from operator import itemgetter

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

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

ci.sort(key=itemgetter(1,2))
for c in ci:
    pi[c[1]-1] += 1
    prestr = str(c[1]).zfill(6)
    bhstr = str(pi[c[1]-1]).zfill(6)
    c.append(''.join([prestr, bhstr]))

ci.sort()
for c in ci:
    print(c[3])

Submission status: Accepted

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


def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):
    tmp = []
    for i in range(M):
        p = P[i]
        y = Y[i]
        tmp.append([i, p, y, ''])
    tmp.sort(key=lambda x: x[2])
    count = [0] * (N + 1)
    for t in tmp:
        p = t[1]
        count[p] += 1
        t[3] = '%06d%06d' % (p, count[p])
    tmp.sort(key=lambda x: x[0])
    for t in tmp:
        print(t[3])
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]" 
    Y = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]

sPY = sorted(PY, key=lambda py: (py[0], py[1]))

i = 1
bp = 1
d = {}
for p, y in sPY:
    if p != bp:
        i = 1
        bp = p
    d[(p, y)] = i
    i += 1

for p, y in PY:
    i = d[(p, y)]
    print("{0:06}{1:06}".format(p, i))

Submission status: Accepted

Solution code:
from collections import defaultdict

N,M = map(int,input().split())
question = []
number = {}
counts = defaultdict(int)
for i in range(M):
    city,value = map(int,input().split())
    question.append([i,city,value])
sorted_question = sorted(question,key=lambda x: x[2])
for i,city,value in sorted_question:
    counts[city] += 1
    number[i] = "{:06}{:06}".format(city,counts[city])
for i in range(M):
    print(number[i])

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = map(int, input().split())

counts = defaultdict(int)
numbers = {}

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

sorted_cities = sorted(cities, key=lambda x: x[2])
for city in sorted_cities:
    i, p, y = city
    counts[p] += 1
    numbers[i] = '{:06}{:06}'.format(p, counts[p])

for city in cities:
    print(numbers[city[0]])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a=[[i]+list(map(int,input().split())) for i in range(M)]
a.sort(key=lambda x:(x[1],x[2]))

j=0
for i in range(M):
    if j!=a[i][1]:
        j=a[i][1]
        k=1
    s=format(a[i][1],'0>6') + format(k,'0>6')
    a[i].append(s)
    k+=1

a.sort()
for i in range(M):
    print(a[i][3])

Submission status: Accepted

Solution code:
from bisect import bisect_right
n, m = map(int, input().split())
p = []
y = []
d = {i + 1: [] for i in range(n)}
for i in range(m):
    p_, y_ = map(int, input().split())
    p.append(p_)
    y.append(y_)
    d[p_].append(y_)
for i in d.keys():
    d[i] = sorted(d[i])
for i in range(m):
    print('{:06d}{:06d}'.format(p[i], bisect_right(d[p[i]], y[i])))

Submission status: Accepted

Solution code:
import numpy as np
from bisect import bisect_right
# from time import time
# start = time()
n, m = map(int, input().split())
p = []
y = []
d = {i + 1: [] for i in range(n)}
# n, m = 10**5, 10**5
# p = [10**5]*m
# y = [i + 1 for i in range(m)]
for i in range(m):
    p_, y_ = map(int, input().split())
    # p_, y_ = p[i], y[i]
    p.append(p_)
    y.append(y_)
    d[p_].append(y_)
for i in d.keys():
    d[i] = sorted(d[i])
for i in range(m):
    # print('{:06d}{:06d}'.format(p[i], d[p[i]].index(y[i]) + 1))
    print('{:06d}{:06d}'.format(p[i], bisect_right(d[p[i]], y[i])))
#
# print(time() - start)

Submission status: Accepted

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

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

for i, j in enumerate(P_Y):
    datalist.append([i, j[0], j[1], 0])

datalist = sorted(datalist, key=lambda x: (x[1], x[2]))
num = 1
city = datalist[0][1]
datalist[0][3] = num

for i in range(1, M):
    if datalist[i][1] == datalist[i-1][1]:
        num += 1
        datalist[i][3] = num
    else:
        num = 1
        datalist[i][3] = num

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

Submission status: Accepted

Solution code:
from sys import stdin
N,M=[int(x) for x in stdin.readline().rstrip().split()]
data=[ [] for _ in range(N)]
for i in range(M):
    P,Y=[int(x) for x in stdin.readline().rstrip().split()]
    data[P-1].append((Y,i))
ans=[0]*(M)
for ind_pre,j in enumerate(data):
    for ind_cit,k in enumerate(sorted(j)):
        ans[k[1]] = str(ind_pre+1).zfill(6) + str(ind_cit+1).zfill(6)
for l in ans:
  print(l)

Submission status: Accepted

Solution code:
from operator import attrgetter
class City:
    def __init__(self, city, pref, year):
        self.city = city
        self.pref = pref
        self.year = year
        self.number = 0

def main():
    N, M = map(int, input().split())
    prefcount = [0] * (N + 1)
    PY = [City(0, 0, 0)]
    for i in range(M):
        P, Y = map(int, input().split())
        PY.append(City(i + 1, P, Y))
    PY.sort(key=attrgetter("year"))
    for i in PY:
        i.number = str(i.pref * 1000000 + (prefcount[i.pref] + 1)).zfill(12)
        prefcount[i.pref] += 1
    PY.sort(key=attrgetter("city"))
    for i in range(1, M + 1):
        print(PY[i].number)
main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import bisect as bs
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P_X = [None] * M
for _ in range(M):
  p, x = input().split()
  p, x = int(p), int(x)
  P_X[_] = (p, x)
  dic[p].append(x)
for key in dic:
  dic[key].sort()
for i in range(M):
  print(str(P_X[i][0]).zfill(6) + str(bs.bisect_left(dic[P_X[i][0]], P_X[i][1]) + 1).zfill(6))