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: Runtime Error

Solution code:
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(m)]
dic = {}
q = p.copy()
q.sort(key=lambda x: x[1])
cnt = [0 for i in range(n+1)]
for i in range(m):
    cnt[q[i][0]] += 1
    dic[q[i][1]] = cnt[q[i][0]]
for i in range(m):
    print(str(p[i][0]).zfill(6)+str(dic[p[i][1]]).zfill(6))

Submission status: Runtime Error

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

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

ls = [''] * M
for p in range(N):
    s = ss[p]
    s.sort(key=lambda g: g[1])
    for d, (i, y) in enumerate(s):
        ps = str(p+1).zfill(6)
        ds = str(d+1).zfill(6)
        ls[i] = ps+ds

for l in ls:
    print(l)

Submission status: Runtime Error

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

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

ls = [''] * M
for p in range(N):
    s = ss[p]
    s.sort(key=lambda g: g[1])
    for d, (i, y) in enumerate(s):
        ps = str(p+1).zfill(6)
        ds = str(d+1).zfill(6)
        ls[i] = f"{ps}{ds}"

for l in ls:
    print(l)

Submission status: Runtime Error

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

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

ls = [''] * M
for j in range(N):
    s = ss[j]
    s.sort(key=lambda g: g[1])
    for d, (i, y) in enumerate(s):
        ps = str(j+1).zfill(6)
        ys = str(d+1).zfill(6)
        ls[i] = f"{ps}{ys}"

for l in ls:
    print(l)

Submission status: Runtime Error

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

cities = {}
output = []
for i in range(M):
    x, y = map(int, input().split())
    cities[i+1] = [x,y]
    output.append(y)

ID = {}
county_old = 0
sorted_counties_years = sorted(cities.values())
for county,year in sorted_counties_years:
    if county_old == 0:
        county_old = county
        count = 1
        ID[year] = f'{county:06}{count:06}'
        count += 1
        continue
    elif county_old == county:
        ID[year] = f'{county:06}{count:06}'
        count += 1
    else:
        county_old = county
        count = 1
        ID[year] = f'{county:06}{count:06}'
        count += 1
for i in output:
    print(ID[i])

Submission status: Runtime Error

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

cities = {}
output = []
for i in range(M):
    x, y = map(int, input().split())
    cities[i+1] = [x,y]
    output.append(y)

ID = {}
county_old = 0
sorted_counties_years = sorted(cities.values())
for county,year in sorted_counties_years:
    if county_old == 0:
        county_old = county
        count = 1
        ID[year] = f'{county:06}{count:06}'
        count += 1
        continue
    elif county_old == county:
        ID[year] = f'{county:06}{count:06}'
        count += 1
    else:
        county_old = county
        count = 1
        ID[year] = f'{county:06}{count:06}'
        count += 1
for i in output:
    print(ID[i])

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from itertools import *
from operator import itemgetter

def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):
    sorted_list = [(P[i], Y[i]) for i in range(M)]
    sorted_list.sort()

    group_list = dict((key, list(map(lambda x: x[1], items))) for key, items in groupby(sorted_list, key = itemgetter(0)))
    for i in range(N + 1):
        key = P[i]
        rank = group_list[P[i]].index(Y[i]) + 1
        print('{0:06d}'.format(key, rank) + '{0:06d}'.format(rank))

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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: Runtime Error

Solution code:
from collections import defaultdict

n, m = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(m)]
ypi = sorted((y, p) for i, (p, y) in enumerate(PY))
d = defaultdict(lambda: 0)

ans = [None]*m

for y, p in ypi:
    d[p] += 1
    ans[i] = str(p).zfill(6) + str(d[p]).zfill(6)

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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, M = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    tot=[[] for _ in range(N+1)]
    ys=[]
    for i in range(M):
        P, Y = map(int, input().split())
        tot[P].append(Y)
        ys.append(Y)
    tset=[]
    tseti=[]
    for i in range(N+1):
        t1=tot[i]
        if len(t1)<1:continue
        p=str(i)
        if len(p)<6:
            p='0'*(6-len(p))+p
            t1.sort()
            for j,t in enumerate(t1):
                tx=str(j+1)
                if len(tx)<6:
                    tx='0'*(6-len(tx))+tx
                tset.append(p+tx)
                tseti.append(t)
    for y in ys:
        i=tseti.index(y)
        print(tset[i])





if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
prefectures = [[] for _ in range(10 ** 5)]

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

ans = [''] * m
for p in range(10 ** 5):
    prefecture = prefectures[p]
    prefecture.sort(key=lambda x: x[0])
    for i in range(len(prefecture)):
        ans[prefecture[i][1]] = '{:006}{:006}'.format(p, i + 1)

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

Submission status: Runtime Error

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

l = [[] for _ in range(M)]
m = []
for _ in range(M):
  P, Y = map(int, input().split())
  m.append((P, Y))
  l[P-1].append(Y)

for i, x in enumerate(m):
  l[i].sort()
  c = l[x[0]-1].index(x[1])
  s = '{:0=6}'.format(x[0])
  s += '{:0=6}'.format(c+1)
  print(s)

Submission status: Runtime Error

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

l = [[] for _ in range(M)]
m = []
for _ in range(M):
  P, Y = map(int, input().split())
  m.append((P, Y))
  l[P-1].append(Y)

for x in l:
  x.sort()

for i, x in enumerate(m):
  c = l[x[0]-1].index(x[1])
  s = '{:0=6}'.format(x[0])
  s += '{:0=6}'.format(c+1)
  print(s)

Submission status: Runtime Error

Solution code:
n,m =map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
for i in range(n):
    lis[i].append(i)
lis.sort()
cnt = 1
ans = []
ans.append([lis[0][-1],format(lis[0][0]).zfill(6)+format(1).zfill(6)])
for i in range(m-1):
    if lis[i][0] == lis[i+1][0]:
        cnt += 1
        ans.append([lis[i+1][-1],format(lis[i+1][0]).zfill(6)+format(cnt).zfill(6)])
    else:
        cnt = 1
        ans.append([lis[i+1][-1],format(lis[i+1][0]).zfill(6)+format(cnt).zfill(6)])
ans.sort(key = lambda x:x[0])
for i,x in ans:
    print(x)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
py=[[0]*3 for _ in range(m)]
for i in range(m):
    p,y=map(int,input().split())
    py[i][0],py[i][1],py[i][2]=p,y,i
py.sort()
ans=[[''] for _ in range(m)]
cnt=[0]*m
for p,y,i in py:
    cnt[p]+=1
    ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
py=[[0]*3 for _ in range(m)]
for i in range(m):
    p,y=map(int,input().split())
    py[i][0],py[i][1],py[i][2]=p,y,i
py.sort()
ans=[[''] for _ in range(m)]
cnt=[0]*m
for p,y,i in py:
    cnt[p]+=1
    ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
ans.sort()
for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
import numpy as np
n, m = map(int, input().split())

p = np.empty(m, dtype=int)
y = np.empty(m, dtype=int)
for i in range(m):
    p[i], y[i] = map(int, input().split())
max_y = max(y)
index = np.unique(p)
code = []
for i in index:  # i = 1
    y2 = y[p == i]
    for j in range(len(y2)):
        suf = np.argmin(y2)
        y2[suf] = max_y + 1
        #print(f"suf = {suf}  y2 = {y2}")
        code.append(f"{i:06d}{suf+1:06d}")
print(*sorted(code), sep="\n")

Submission status: Runtime Error

Solution code:
import copy

n,m = map(int,input().split())
city_max_number=0
ab = []
for _ in range(m):
    a, b = (int(x) for x in input().split())
    city_max_number = max(city_max_number,b)
    ab.append([a, b])

copy_ab = copy.deepcopy(ab)

copy_ab = sorted(ab, key=lambda x: x[0])
copy_ab = sorted(ab, key=lambda x: x[1])

city = [0]*(city_max_number+1)

count = 1
for i in range(m):
    city[copy_ab[i][1]] = count
    if i == m-1:
        break
    elif copy_ab[i][0] == copy_ab[i+1][0]:
        count += 1
    else:
        count = 1

for i, j in ab:
    i = str(i)
    city_number = (6-len(i))*'0'+i
    ID = str(city[j])
    ID = (6-len(ID))*'0'+ID
    print(city_number+ID)

Submission status: Runtime Error

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

tmpsort = [[0]for i in range(n)]
p_list = []
y_list = []

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

for i in range(m):
    tmpsort[i].sort()
for i in range(len(p_list)):
    idx = tmpsort[p_list[i]-1].index(y_list[i])
    print((str(p_list[i]).zfill(6) + str(idx).zfill(6)))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split(" "))
 
l = []
for i in range(M):
	p, y = map(int, input().split(" "))
	l.append((p,y,i))
l.sort(key=lambda x: x[1])
 
ans = [0]*(N+1)
indexs = [0] * (M+1)
for p, y , i in l:
	index = indexs[p] + 1
	indexs[p] = index
	ans[i]  = "{:0>6}{:0>6}".format(p, index)
 
for k in ans:
	print(k)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split(" "))
 
l = []
for i in range(M):
	p, y = map(int, input().split(" "))
	l.append((p,y,i))
l.sort(key=lambda x: x[1])
 
ans = [0]*(N+1)
indexs = [0] * M
for p, y , i in l:
	index = indexs[p] + 1
	indexs[p] = index
	ans[i]  = "{:0>6}{:0>6}".format(p, index)
 
for k in ans:
	print(k)

Submission status: Runtime Error

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

l = []
for i in range(M):
	p, y = map(int, input().split(" "))
	l.append((p,y,i))
l.sort(key=lambda x: x[1])

ans = [0]*(N+1)
indexs = [0] * M
for p, y , i in l:
	index = indexs[p] + 1
	indexs[p] = index
	ans[i]  = "{:0>6}{:0>6}".format(p, index)

for k in ans:
	print(k)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n,m = map(int,input().split())
city = [list(map(int,input().split())) for _ in range(m)]
d = defaultdict(list)
for k,v in city:
    d[k].append(v)
lis = [[] for _ in range(10**5+1)]
for i in d.keys():
    d[i].sort()
for i in d.keys():
    for j in range(len(d[i])):
        lis[d[i][j]].append(i)
        lis[d[i][j]].append(j+1)
for i in range(m):
    upper,lower = lis[city[i][1]][0], lis[city[i][1]][1]
    uplen,lolen = len(str(upper)),len(str(lower))
    if uplen<6:
        upper = '0'*(6-uplen)+str(upper)
    else:
        upper = str(upper)
    if lolen<6:
        lower = '0'*(6-lolen) + str(lower)
    else:
        lower = str(lower)
    print(upper+lower)

Submission status: Runtime Error

Solution code:
def print12(LIST):
    for i in range(12):
        print(LIST[i], end = "")
    print("")

I = input().split()
N = int(I[0])
M = int(I[1])
"""
const N: 県の数
const M: 市の数
"""
Y = [0 for i in range(M)]
P = [0 for i in range(M)]
ANS = [[0 for i in range(12)] for j in range(M)]
"""
list Y: 1~M市の誕生年のリスト
list P: 1~M市の所属県のリスト
2dim_list ANS: 答えの1~M市を表す12桁の数
"""
# 県リスト、年リストに値を入力し、ANSの上6桁も入力
for i in range(M):
    I = input().split()
    P[i] = int(I[0])
    Y[i] = int(I[1])
    Pi = int(I[0])
    for j in range(6):
        ANS[i][5-j] = Pi % 10
        Pi //= 10

Dict_ListP = [{} for i in range(N)]
"""
list Dict_ListP: 県数分、辞書を要素に持つリスト
"""
# Dict_ListP[P[i] - 1] [Y[i]] = iとして
# 県の辞書に年をキーとして市を値に渡したい。
for i in range(M):
    (Dict_ListP[P[i] - 1])[Y[i]] = i


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

for i in range(N):
    Dict_ListP_sorted[i] = sorted(Dict_ListP[i].items())
    for count, j in enumerate(Dict_ListP_sorted[i]):
    #j[0]でキー(年)を取得できる
    #j[1]で市の番号を取得できる
        Rank = count + 1
        for m in range(6):
            ANS[j[1]][11-m] = Rank % 10
            Rank //= 10

for i in range(3):
    print12(ANS[i])

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
py = []
mli = [0]*m
li = [""]*m

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

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

for p,y,i in py:
    mli[p-1] += 1
    pi = str(p).zfill(6)
    yi = str(mli[p-1]).zfill(6)
    li[i] = pi+yi

for i in li:
    print(i)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
py = []
mli = [0]*m
li = [""]*m

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

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

for p,y,i in py:
    mli[p-1] += 1
    pi = '{0:06d}'.format(p)
    yi = '{0:06d}'.format(mli[p-1])
    li[i] = str(pi)+str(yi)

for i in li:
    print(i)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
py = []
mli = [0]*m
li = [""]*m

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

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

for p,y,i in py:
    mli[p] += 1
    pi = '{0:06d}'.format(p)
    yi = '{0:06d}'.format(mli[p])
    li[i] = str(pi)+str(yi)

for i in li:
    print(i)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
py = []
mli = [0]*m
li = [""]*m

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

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

for p,y,i in py:
    mli[p] += 1
    pi = '{0:05d}'.format(p)
    yi = '{0:05d}'.format(mli[p])
    li[i] = str(pi)+str(yi)

for i in li:
    print(i)

Submission status: Runtime Error

Solution code:
inputs = open(0).readlines()
n, m = map(int, inputs[0].split())
PY = [map(int, x.split()) for x in inputs[1:]]
A = [[] for _ in range(m)]
B = []
for i, (p, y) in enumerate(PY):
    A[p-1].append([y, i])
    B.append('{:06}'.format(p))
for a in A:
    a.sort()
    for i in range(len(a)):
        B[a[i][1]] += '{:06}'.format(i+1)
print(*B, sep='\n')

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from scipy.stats import rankdata

p_list = []
y_dict = defaultdict(list)


N = int(input())
M = int(input())

for i in range(M):
    p_i = int(input())
    y_i = int(input())
    p_list.append(p_i - 1)
    y_dict[p_i - 1].append(y_i)

for i in range(N):
    y_dict[i] = rankdata(y_dict[i]).astype(int).tolist()

for i in range(M):
    print(str(p_list[i] + 1).zfill(6) + str(y_dict[p_list[i]].pop(0)).zfill(6))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
py=[list(map(int,input().split()))]
l=[1]*n
for i in range(m):
    py[i].append(i+1)
py.sort()
for i in range(m):
    py[i].append( str(py[i][0]).zfill(6) + str(l[py[i][0]-1]).zfill(6))
    l[py[i][0]-1]+=1
py.sort(key=lambda x:x[2])
for i in range(m):
    print(py[i][-1])

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
py = []
p_y = [[0] * (10**5) for i in range(n)]
for _ in range(m):
    p,y = map(int,input().split())
    py.append((p,y))
    p_y[p-1][y-1] = 1

for i, tmp in enumerate(p_y):
    cnt = 1
    for j in range(len(tmp)):
        if tmp[j] == 0:
            continue
        else:
            p_y[i][j] = cnt
            cnt += 1

for i, tmp in enumerate(py):
    s = ''
    s += str(tmp[0]).zfill(6)
    s += str(p_y[tmp[0]-1][tmp[1]-1]).zfill(6)
    print(s)

Submission status: Runtime Error

Solution code:
import sys

def fill(s): return '0' * (6 - len(s)) + s
def create_id(p, o): return fill(str(p)) + fill(str(o))

n, m, *py = map(int, sys.stdin.read().split())
pyi = sorted(zip(*[iter(py)] * 2, range(m)))

def main():
    res = [None] * m
    prev = j = None
    for p, y, i in pyi:
        j = j + 1 if p == prev else 1
        res[i] = create_id(p, j)
        prev = p
    print(*res, sep='\n')
    
if __name__ ==  '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

def fill(s): while len(s) < 6: s = '0' + s; return s
def create_id(p, o): return fill(str(p)) + fill(str(o))

n, m, *py = map(int, sys.stdin.read().split())
pyi = sorted(zip(zip(*[iter(py)] * 2), range(m)))

def main():
    res = [None] * m
    prev = j = None
    for (p, y), i in pyi:
        j = j + 1 if p == prev else 1
        res[i] = create_id(p, j)
        prev = p
    print(*res, sep='\n')
    
if __name__ ==  '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict

N, M = map(int, input().split())
P, Y = [], []
ylist = defaultdict(list)
pset = set()
for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    ylist[p].append(y)
    pset.add(p)

cdict = defaultdict(dict)
for p in pset:
    syear = sorted(ylist[p])
    for i, y in enumerate(syear):
        cdict[p][y] = i + 1

for i in range(M):
    p = P[i]
    y = Y[i]
    rank = cdict[p][y]
    print(f'{p:06}{rank:06}')

Submission status: Runtime Error

Solution code:
from collections import defaultdict

N, M = map(int, input().split())
P, Y = [], []
ylist = defaultdict(list)
pset = set()
for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    ylist[p].append(y)
    pset.add(p)
assert len(pset) == N

cdict = defaultdict(dict)
for p in pset:
    syear = sorted(ylist[p])
    for i, y in enumerate(syear):
        cdict[p][y] = i + 1

for i in range(M):
    p = P[i]
    y = Y[i]
    rank = cdict[p][y]
    print(f'{p:06}{rank:06}')

Submission status: Runtime Error

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

import numpy as np

# line1 = "2 3"
# line2 = ['1 32', '2  63', '1 12']

N, M = map(int,  input().split())
prefinfo = [input() for i in range(N)]
PY = [list(map(int, line.split())) for line in prefinfo]

PY = np.array(PY)
cn = np.array([np.arange(np.shape(PY)[0])])
cc = np.array([np.zeros(np.shape(PY)[0], dtype=int)])

city_list = np.hstack([cn.T, PY, cc.T])
cl_ysort = city_list[np.argsort(city_list[:, 2])]
city_count = np.zeros(N+1, dtype=int)
for i, cinfo in enumerate(cl_ysort):
    pref = cinfo[1]
    city_count[pref] += 1
    cl_ysort[i, 3] = city_count[pref]

cl_idsort = cl_ysort[np.argsort(cl_ysort[:, 0])]

[print('{:06d}{:06d}'.format(cl[1], cl[3])) for cl in cl_idsort]

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
py = [[int(i) for i in input().split()] for _ in range(m)]
py_ = [[] for _ in range(m)]
for pi, yi in py:
    py_[pi-1].append(yi)
for i in range(m):
    py_[i].sort()
for pi, yi in py:
    print(str(pi).zfill(6) + str(py_[pi-1].index(yi) + 1).zfill(6))

Submission status: Runtime Error

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

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

cities = [i[0] for i in l]
years = [i[1] for i in l]

years_every_city = [[] for i in range(m)]

for i in l:
    years_every_city[i[0]-1].append(i[1])

sorted_years = [sorted(i) for i in years_every_city]

for city, year in l:
    print(str(city).zfill(6) + str(sorted_years[city-1].index(year)+1).zfill(6))

Submission status: Runtime Error

Solution code:
#「県ごとの市の「市番号(id)、誕生年(year)」リスト」と「市番号順の市の認識番号(tag)リスト」を用意する

class City:
    #市番号と誕生年を管理する
    def __init__(self,id,y):
        self.id = id
        self.year = y


def main():
    n,m = map(int,input().split())
    pre_lst = [[] for _ in range(n)]  #各県に含まれる市のリスト
    city_tags = [0 for _ in range(m)] #上記のリストから作った市の認識番号を格納するためのリスト

    for i in range(m):
        p,y = map(int,input().split())
        pre_lst[p-1].append(City(i,y))　#入力を受け取り、県ごとのリストを作る

    for pre_num,pre in enumerate(pre_lst):
        if len(pre) <= 0:
            continue
        pre.sort(key = lambda x:x.year) #各県ごとに誕生年順にソート

        counter = 0 #認識番号の右側、何番目に誕生した都市かを作るためのカウンター
        for city in pre:
            city_tags[city.id] = str(pre_num+1).zfill(6) + str(counter+1).zfill(6)
            counter += 1
    for tag in city_tags:
        print(tag)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

#![allow(dead_code)]
#![allow(unused_macros)]

// 入力マクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input! {
        n: usize, m: usize,
        towns: [(usize, usize); m],
    }
    let mut towns: Vec<(usize, usize, usize)> = towns.into_iter().enumerate().map(|(i, t)| (i, t.0, t.1)).collect();
    towns.sort_by_key(|t| (t.1, t.2));
    let mut out = vec![String::new(); m];
    let mut now_pre = towns[0].1;
    let mut order = 0;
    for (i, p, y) in &mut towns {
        if *p != now_pre { order = 1; now_pre = *p; }
        else { order += 1 }
        out[*i] = format!("{:06}{:06}", p, order);
    }

    for l in out {
        println!("{}", l);
    }
}

Submission status: Runtime Error

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

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

indices = [*range(len(PY))]
sorted_indices = sorted(indices, key=lambda i: PY[i])
PY.sort()

def calc(x):
    n = len(str(x))
    res = ""
    if n < 6:
        for i in range(6-n):
            res += "0"
    res += str(x)
    return res

before = 0
num = 1
ans = [0]*M
for i in range(M):
    if before != PY[i][0]:
        num = 1
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]
    else:
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]

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

Submission status: Runtime Error

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

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

result = [None]*m

for p,i in enumerate(input_list) :
  for n, (a,b) in enumerate(i):
    result[b] = str(p+1).zfill(6)+str(n+1).zfill(6)
    
print(*result, sep = '\n')

Submission status: Runtime Error

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

def six_digit(x):
    zero_number = 6 - len(x)
    y = '0' * zero_number

    return y

city_lst = [[]*n]
for i in range(m):
    prefecture = py_lst[i][0]
    city = py_lst[i][1]

    city_lst[prefecture-1].append(city)

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

number_lst = []
for i in range(m):
    prefecture = py_lst[i][0]
    city = py_lst[i][1]
    a = len(city_lst[prefecture-1])

    for j in range(a):
        if city_lst[prefecture-1][j]==city:
            number_lst.appenc(j+1)
            break

for i in range(m):
    prefecture = py_lst[i][0]
    number = number_lst[i]

    answer = six_digit(str(prefecture)) + six_digit(str(number))
    print(answer)

Submission status: Runtime Error

Solution code:

N,M=map(int,input().split())
PY=dict()
P=[]
Y=[]
for _ in range(M):
    Pi,Yi=map(int,input().split())
    P.append(Pi)
    Y.append(Yi)
    if((Pi in PY.keys())==False):
        PY[Pi]=[Yi]
    else:
        PY[Pi].append(Yi)

sor=[]
for n,i in enumerate(PY.keys()):
    sor.append(sorted(PY[i]))

for n in range(M):
    print('{:06}{:06}'.format(P[n],(sor[P[n]].index(Y[n]))+1))

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
PY=dict()
cnt=[]
for _ in range(M):
    P,Y=map(int,input().split())
    tmp=[P,Y]
    cnt.append(tmp)

for value in cnt:
    if((value[0] in PY.keys())==False):
        PY[value[0]]=[value[1]]
    else:
        PY[P].append(value[1])



for i in PY.keys():
    PY[i].sort()

for n in cnt:
    p,y=n[0],n[1]
    print('{:06}{:06}'.format(p,(PY[p].index(y))+1))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
ab = []
for _ in range(m):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])

cp = copy.copy(ab)

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

cost = [[] for _ in range(n+1)]

for i,j in cp:
    cost[i].append(j)

for i,j in ab:
    ID = cost[i].index(j)+1
    i = str(i)
    i = (6-len(i))*'0'+i
    ID = str(ID)
    ID = (6-len(ID))*'0'+ID
    print(i+ID)

Submission status: Runtime Error

Solution code:
import bisect

def main():
  N,M = map(int,input().split())
  pref = [[] for i in range(N)]
  id = [[]] * M
  
  for i in range(M):
    p,y = map(int,input().split())
    id[i] = [p,y]
    pref[p - 1].append(y)
    #pref[p - 1] = sorted(pref[p - 1])
  
  for i in range(N):
    pref[i] = sorted(pref[i])
  
  orders = [0] * N
  
  for i in range(M):
    p = id[i][0] - 1
    y = id[i][1]
    order = str(bisect.bisect_left(pref[p],y) + 1)
    city = str(p + 1)
    ID = ""
    ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order
    print(ID)

if __init__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
# ID
n,m=map(int,input().split())
s=[[] for _ in range(m)]
for i in range(m):
    p,y=map(int,input().split())
    s[p-1].append([y,i,''])

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

ans=[]
for i,ss in enumerate(s):
    for j,sss in enumerate(ss):
        if ss:
            if sss:
                id_no=''
                id_no+='0'*(6-len(str(i+1)))+str(i+1)
                id_no+='0'*(6-len(str(j+1)))+str(j+1)
                s[i][j][2]=id_no

for i,ss in enumerate(s):
    for j,sss in enumerate(ss):
        ans.append(s[i][j])
ans.sort(key=lambda x:x[1])
for aa in ans:
    print(aa[2])

Submission status: Runtime Error

Solution code:
# ID
n,m=map(int,input().split())
s=[[] for _ in range(m)]
for i in range(m):
    p,y=map(int,input().split())
    s[p-1].append([y,i])

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

ans=[]
for i,ss in enumerate(s):
    for j,sss in enumerate(ss):
        if ss:
            if sss:
                id_no=''
                id_no+='0'*(6-len(str(i+1)))+str(i+1)
                id_no+='0'*(6-len(str(j+1)))+str(j+1)
                s[i][j].append(id_no)

for i,ss in enumerate(s):
    for j,sss in enumerate(ss):
        ans.append(s[i][j])
ans.sort(key=lambda x:x[1])
for aa in ans:
    print(aa[2])

Submission status: Runtime Error

Solution code:
# ID
n,m=map(int,input().split())
s=[[] for _ in range(m)]
for i in range(m):
    p,y=map(int,input().split())
    s[p-1].append([y,i])

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

ans=[]
for i,ss in enumerate(s):
    for j,sss in enumerate(ss):
        id_no=''
        id_no+='0'*(6-len(str(i+1)))+str(i+1)
        id_no+='0'*(6-len(str(j+1)))+str(j+1)
        s[i][j].append(id_no)

for i,ss in enumerate(s):
    for j,sss in enumerate(ss):
        ans.append(s[i][j])
ans.sort(key=lambda x:x[1])
for aa in ans:
    print(aa[2])