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:
import numpy as np
from sys import stdin
s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()
N, M = ds_in()
info_list = []
for _ in range(M):
    info_list.append(ds_in())
info_list = np.array(info_list)
ordered = np.argsort(info_list[:, 1])
pref_count = np.zeros(N)
ans_list = ['' for _ in range(M)]
for i in ordered:
    pref = info_list[i, 0]
    pref_count[pref - 1] += 1
    ans_list[i] = '%06d%06d' % (pref, pref_count[pref - 1])
for a in ans_list:
    print(a)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
l=[[] for i in range(n)]
for i in range(m):
    p,y=input().split()
    l[int(p)-1].append(y.zfill(6)+str(i).zfill(6))
for i in range(n):
    l[i].sort()
s=[0]*m
for i in range(n):
    for j in range(len(l[i])):
        s[int(l[i][j][6:12])]=str(i+1).zfill(6)+str(j+1).zfill(6)
for i in s:
    print(i)

Submission status: Runtime Error

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

out = [[0, 0] for i in range(m)]
hash = [[] for i in range(10**5)]
for i in range(m):
    p[i], y[i] = [int(i) for i in input().split()]
    hash[p[i]].append([y[i], i])

for i in range(len(hash)):
    hash[i] = sorted(hash[i])
    for j in range(len(hash[i])):
        out[hash[i][j][1]] = i, j+1
for i in range(len(out)):
    print("{}{}".format(str(out[i][0]).zfill(6), str(out[i][1]).zfill(6)))

Submission status: Runtime Error

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

p_y_list = [0]*N
y_count = [1]*(M+1)

for i in range(N):
    p,y = (int(x) for x in input().split())
    p_y_list[i] = [p,y,i]
p_y_list.sort(key = lambda x:x[1])

for i in p_y_list:
    i[1] = y_count[i[0]]
    y_count[i[0]] += 1

p_y_list.sort(key = lambda x:x[2])
for i in p_y_list:
    print(str(i[0]).rjust(6,"0") + str(i[1]).rjust(6,"0"))

Submission status: Runtime Error

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

p_y_list = [0]*M
y_count = [1]*(M+1)

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

for i in p_y_list:
    i[1] = y_count[i[0]]
    y_count[i[0]] += 1

p_y_list.sort(key = lambda x:x[2])
for i in p_y_list:
    print(str(i[0]).rjust(6,"0") + str(i[1]).rjust(6,"0"))

Submission status: Runtime Error

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

p_y_list = []
y_count = [1]*(M+1)

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

for i in p_y_list:
    i[1] = y_count[i[0]]
    y_count[i[0]] += 1

p_y_list.sort(key = lambda x:x[2])
for i in p_y_id_list:
    print(str(i[0]).rjust(6,"0") + str(i[1]).rjust(6,"0"))

Submission status: Runtime Error

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

p_y_list = []
y_count = [1]*(M+1)

for i in range(M):
    p_y_list.append([int(x) for x in input().split()])
    p_y_list[i].append(i)
p_y_list.sort(key = lambda x:x[1])

for i in p_y_list:
    i[1] = y_count[i[0]]
    y_count[i[0]] += 1

p_y_list.sort(key = lambda x:x[2])
for i in p_y_id_list:
    print(str(i[0]).rjust(6,"0") + str(i[1]).rjust(6,"0"))

Submission status: Runtime Error

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

p_y_list = []
y_count = [1]*(M+1)
for i in range(M):
    p_y_list.append([int(x) for x in input().split()])
    p_y_list[i].append(i)
p_y_list.sort(key = lambda x:x[1])
p_y_id_list = []
for i in p_y_list:
    p_y_id_list.append([i[0],y_count[i[0]],i[2]])
    y_count[i[0]] += 1
p_y_id_list.sort(key = lambda x:x[2])
for i in p_y_id_list:
    print(str(i[0]).rjust(6,"0") + str(i[1]).rjust(6,"0"))

Submission status: Runtime Error

Solution code:
N,M = map(int, input().split())
piys = [[] for _ in range(M)] 
for i in range(M):
    p, y = map(int, input().split())
    piys[p-1].append((y,i))
    
ans = [None]*M
for p,iys in enumerate(piys):
    iys.sort()
    for k,(y,i) in enumerate(iys):
        ans[i] = "%06d%06d" % (p+1,k+1)

for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
import numpy as np

N,M = map(int, input().split())
piys = [[] for _ in range(M)] 
for i in range(M):
    p, y = map(int, input().split())
    piys[p-1].append((y,i))
    
ans = [None]*M
for p,iys in enumerate(piys):
    iys.sort()
    for k,(y,i) in enumerate(iys):
        ans[i] = "%06d%06d" % (p+1,k+1)

for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
import numpy as np

N,M = map(int, input().split())
piys = [[] for _ in range(M)] 
for i in range(M):
    p, y = map(int, input().split())
    piys[p-1].append((y,i))
    
ans = [None]*M
for p,iys in enumerate(piys):
    iys.sort(key=lambda x:x[0])
    for k,(y,i) in enumerate(iys):
        ans[i] = "%06d%06d" % (p+1,k+1)

for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
dic = {}
for i in range(n): # TODO: 辞書の初期化のやり方を調べる。
    dic[i+1] = []
 
cities = []

    
def insert(list, item):
    for i,v in enumerate(list):
        if v < item:
            list.insert(i, item)

for _ in range(m):
    i = input()
    cities.append(i)
    pi, mi = map(int, i.split())
    insert(dic[pi], mi)

 
# 県の数だけ
for i in range(n):
    dic[i+1].sort() # listを更新する。戻り値はnone
 
 
# 都市の数だけ
for i in range(m):
    p, m = map(int, cities[i].split())
    print(str(p).zfill(6)+str(dic[p].index(m)+1).zfill(6))
    # print("としIは", p, "に", dic[p].index(m)+1,"ばんめ")

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
p = list()
d = dict()
for i in range(M):
    inp = map(int, input().split())
    p.append(inp)
    if inp[0] in d:
        d[inp[0]].append(inp[1])
    else:
        d[inp[0]] = [inp[1]]
for i in d:
    d[i].sort()
for i, j in p:
    print("{:06d}{:06d}".format(i, d[i].index(j)+1))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
p = list()
y = list()
d = dict()
for i in range(N):
    inp_p, inp_y = map(int, input().split())
    p.append(inp_p)
    y.append(inp_y)
    if p in d:
        d[p].append(y)
    else:
        d[p] = [y]
for i in d:
    d[i] = sorted(d[i])
for i, j in zip(p, y):
    print("{:06d}{:06d}".format(i, d[i].index(j)+1))

Submission status: Runtime Error

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

P = [0]*M
Y = [0]*M

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

A = [0]*M
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = Y[i]*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))

Submission status: Runtime Error

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

P = [0]*M
Y = [0]*M

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

A = [0]*M
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = Y[i]*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))

Submission status: Runtime Error

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

P = []
Y = []

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

A = [0]*M
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = Y[i]*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    if d < 0:
        print(0)
        exit()
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))

Submission status: Runtime Error

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

P = []
Y = []

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

A = [0]*M
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = Y[i]*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    b = B[i] // 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))

Submission status: Runtime Error

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

P = []
Y = []

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

A = [0]*M
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = (Y[i]-1)*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    b = B[i] // 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))

Submission status: Runtime Error

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

P = []
Y = []

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

A = [0]*M
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = (Y[i]-1)*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    b = B[i] // 100000
    k = P[d]

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))

Submission status: Runtime Error

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

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

# I = [[0, 0] for i in range(M)]
I = []
Num = [0]*M

for i in range(M):
    P = C[i][1]
    # I[i] = [C[i][0], "%06d%06d" % (P, Num[P-1] + 1)]
    I.append([C[i][0], "%06d%06d" % (P, Num[P-1] + 1)])
    Num[P-1] += 1

I.sort(key=lambda x: x[0])
for i in range(M):
    print(I[i][1])

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
C = [[0, 0, 0] for i in range(M)] # Cities
for i in range(M):
    P, Y = map(int, input().split())
    C[i] = [i, P, Y]

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

I = [[0, 0] for i in range(M)]
Num = [0]*M

for i in range(M):
    P = C[i][1]
    I[i] = [C[i][0], "%06d%06d" % (P, Num[P-1] + 1)]
    Num[P-1] += 1

I.sort(key=lambda x: x[0])
for i in range(M):
    print(I[i][1])

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
C = [[0, 0, 0] for i in range(M)] # Cities
for i in range(M):
    P, Y = map(int, input().split())
    C[i][:] = [i, P, Y]

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

I = [[0, 0] for i in range(M)]
Num = [0]*M

for i in range(M):
    P = C[i][1]
    I[i][:] = [C[i][0], "%06d%06d" % (P, Num[P-1] + 1)]
    Num[P-1] += 1

I.sort(key=lambda x: x[0])
for i in range(M):
    print(I[i][1])

Submission status: Runtime Error

Solution code:

N, M = map(int,input().split())
P=[]
Y=[]
cities=[]
for i in range(M):
    try:
        s = input()
        p,y = s.split()
        city=(p,y)
        cities.append(city) 
        P.append(p)
        Y.append(y)

    except:
        break
sort_city=sorted(cities,key=lambda x:(x[0],x[1]))
prefs = sorted(set(P))

address=[]
res=[]
for i in range(len(sort_city)): 
    address=str(sort_city[i][0]).rjust(6,'0')+str(i+1).rjust(6,'0')
    res.append((sort_city[i],address))

print(res[1][0])
for i in range(len(cities)):
    for j in range(len(res)):
        if cities[i] == res[j][0]:
            print(res[j][1])

Submission status: Runtime Error

Solution code:
#M num of prefecture
#N num of city
N, M = map(int,input().split())
#P pref
#Y year
P=[]
Y=[]
cities=[]
for i in range(M):
    try:
        s = input()
        p,y = s.split()
        city=(p,y)
        cities.append(city) 
        P.append(p)
        Y.append(y)
    except:
        break

sort_city=sorted(cities,key=lambda x:(x[0],x[1]))
prefs = sorted(set(P))

address=[]
res=[]
for i in range(len(sort_city)): 
    address=str(sort_city[i][0]).rjust(6,'0')+str(i+1).rjust(6,'0')
    res.append((sort_city[i],address))

print(res[1][0])
for i in range(len(cities)):
    for j in range(len(res)):
        if cities[i] == res[j][0]:
            print(res[j][1])
            break

Submission status: Runtime Error

Solution code:
#M num of prefecture
#N num of city
N, M = map(int,input().split())
#P pref
#Y year
P=[]
Y=[]
cities=[]
for i in range(M):
    try:
        s = input()
        p,y = s.split()
        city=(p,y)
        cities.append(city) 
        P.append(p)
        Y.append(y)
    except:
        break

sort_city=sorted(cities,key=lambda x:(x[0],x[1]))
prefs = sorted(set(P))

address=[]
res=[]
for i in range(len(sort_city)): 
    address=str(sort_city[i][0]).rjust(6,'0')+str(i+1).rjust(6,'0')
    res.append((sort_city[i],address))

print(res[1][0])
for i in range(len(cities)):
    for j in range(len(res)):
        if cities[i] == res[j][0]:
            print(res[j][1])

Submission status: Runtime Error

Solution code:
#M num of prefecture
#N num of city
N, M = map(int,input().split())
#P pref
#Y year
P=[]
Y=[]
cities=[]
for i in range(M):
    try:
        s = input()
        p,y = s.split()
        city=(p,y)
        cities.append(city) 
        P.append(p)
        Y.append(y)
    except:
        break

sort_city=sorted(cities,key=lambda x:(x[0],x[1]))
prefs = sorted(set(P))

address=[]
res=[]
for i in range(len(sort_city)):
    pref_n =prefs.index(sort_city[i][0])
    address=str(pref_n+1).rjust(6,'0')+str(i+1).rjust(6,'0')
    res.append((sort_city[i],address))

print(res[1][0])
for i in range(len(cities)):
    for j in range(len(res)):
        if cities[i] == res[j][0]:
            print(res[j][1])

Submission status: Runtime Error

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

ans = [None for _ in range(m)]

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

for p in range(1, n + 1):
    t = sorted(pys[p], key=lambda x: x[0])
    for j, [y, i] in enumerate(t, 1):
        ans[i] = f'{p:06}{j:06}'

print('\n'.join(ans))

'''
zero padding: 
f'{i:03}'
002etc
'''

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
data = [[] for i in range(M)]
ans = [""] * (M+1)
num = [0] * (M+1)
for i in range(M):
    ken, year = map(int, input().split())
    data[i] = [ken, year, i]
    
data.sort(key=lambda x:x[1])

for p, y, i in data:
    num[p-1] += 1
    ans[i] = str(p).zfill(6) + str(num[p-1]).zfill(6)

for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
data = [[] for i in range(M)]
ans = [""] * M
num = [0] * M
for i in range(M):
    ken, year = map(int, input().split())
    data[i] = [ken, year, i]
    
data.sort(key=lambda x:x[1])

for p, y, i in data:
    num[p-1] += 1
    ans[i] = str(p).zfill(6) + str(num[p-1]).zfill(6)

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
data = [[] for i in range(M)]
ans = [""] * M
num = [0] * M
for i in range(M):
    ken, year = map(int, input().split())
    data[i] = [ken, year, i]
    
data.sort(key=lambda x:x[1])

for p, y, i in data:
    num[p-1] += 1
    ans[i] = str(p).zfill(6) + str(num[p-1]).zfill(6)

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
data = [[] for i in range(M)]
ans = [""] * M
num = [0] * M
for i in range(M):
    ken, year = map(int, input().split())
    data[i] = [ken, year, i]
    
data.sort(key=lambda x:x[1])

for p, y, i in data:
    num[p-1] += 1
    ans[i] = (str(p).zfill(6) + str(num[p-1]).zfill(6))

for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
data = [[] for i in range(M)]
ans = [""] * M
num = [0] * M
for i in range(M):
    ken, year = map(int, input().split())
    data[i] = [ken, year, i]
    
data.sort(key=lambda x:x[1])

for p, y, i in data:
    num[p-1] += 1
    ans[i] = (str(p).zfill(6) + str(num[p]).zfill(6))

for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
data = [[] for i in range(M)]
ans = [""] * M
num = [0] * (M+1)
for i in range(M):
    ken, year = map(int, input().split())
    data[i] = [ken, year, i]
    
data.sort(key=lambda x:x[1])

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

for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
data = [[] for i in range(M)]
ans = [""] * M
num = [0] * M
for i in range(M):
    ken, year = map(int, input().split())
    data[i] = [ken, year, i]
    
data.sort(key=lambda x:x[1])

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

for i in ans:
    print(i)

Submission status: Runtime Error

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

for i in range(m):
	j,k=map(int,input().split())
	li[j].append(k)

for i in range(1,m):
	li[i].sort()
	for j in li[i]:
		print(str(i).zfill(6)+str(j).zfill(6))

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

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

P = []
Y = []
PY = [[] for _ in range(N+1)]

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

for i in range(M+1):
    PY[i].sort()

for i in range(M):
    x = bisect_left(PY[P[i]], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

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

P = []
Y = []
PY = [[] for _ in range(M+1)]

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

for i in range(M+1):
    PY[i].sort()

for i in range(M):
    x = bisect_left(PY[P[i]], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

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

P = []
Y = []
PY = [[] for _ in range(M)]

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

for i in range(M):
    PY[i].sort()

for i in range(M):
    x = bisect_left(PY[P[i]-1], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Submission status: Runtime Error

Solution code:
def index_bin(l, x):
    n = len(l)
    b = 0
    e = n - 1
    while(b != e):
        if x > l[(b+e)//2]:
            b = (b+e)//2 + 1
        else:
            e = (b+e)//2
    return b


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

P = []
Y = []
PY = [[] for _ in range(M)]


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

for i in range(M):
    PY[i].sort()

for i in range(M):
    x = index_bin(PY[P[i]-1], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Submission status: Runtime Error

Solution code:
def index_bin(l, x):
    n = len(l)
    b = 0
    e = n
    while(b != e):
        if x > l[(b+e)//2]:
            b = (b+e)//2 + 1
        else:
            e = (b+e)//2
    return b


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

P = []
Y = []
PY = [[] for _ in range(M)]


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

for i in range(M):
    PY[i+1].sort()

for i in range(M):
    x = index_bin(PY[P[i]-1], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Submission status: Runtime Error

Solution code:
def index_bin(l, x):
    n = len(l)
    b = 0
    e = n
    while(b != e):
        if x > l[(b+e)//2]:
            b = (b+e)//2 + 1
        else:
            e = (b+e)//2
    return b


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

P = []
Y = []
PY = [[] for _ in range(M)]


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

for i in range(M):
    PY[i].sort()

for i in range(M):
    x = index_bin(PY[P[i]-1], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Submission status: Runtime Error

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

P = []
Y = []
PY = [[] for _ in range(M)]

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

for i in range(M):
    PY[i].sort()

for i in range(M):
    x = PY[P[i]-1].index(Y[i])
    print("%06d%06d" % (P[i], x + 1))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N,M=map(int, input().split())
L=[ [] for _ in range(N)]

X=[]
for _ in range(M):
    a,b = input().split()
    a=int(a)
    b=int(b)
    L[a-1].append(b)
    X.append({a:b})
Y=[ (sorted(L[_])) for _ in range(N) ]
for i in range(M) :
    for k,v in X[i].items():
        z='%06d' % 
        Z='%06d' % k
        print('%06d%06d' % (k,(Y[k-1].index(v)+1)))

Submission status: Runtime Error

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

def prefecturesort(i):
    return i[0]

def yearsort(i):
    return i[1]

W=[0 for i in range(n)]
Z=[]

for i in range(m):
    P[i].append(i)
    W[P[i][0]]+=1

P.sort(key=prefecturesort)
P_c=[]
sum=0
for i in range(n):
    c=W[i]
    if c==0:
        P_c.append([])
    else:
        P_c.append(P[sum:c+sum])
    sum+=c
    P_c[i].sort(key=yearsort)
for x in P_c:
    for j in range(len(x)):
        X=str("{0:06d}".format(x[j][0]))
        Y=str("{0:06d}".format(j+1))
        Z.append([X+Y,x[j][2]])
Z.sort(key=yearsort)
for i in range(m):
    print(Z[i][0])

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split( ))
ans = ""
ls_a = []
ls_b = [[] for i in range(n)]
for i in range(m):
    p,y = map(int,input().split( ))
    ls_a.append([p,y])
    ls_b[p-1].append(y)
for i in range(n):
    if len(b[i]) !=0:
        ls_b[i].sort()
for i in range(m):
    ans += str(ls_a[i][0]).zfill(6) + str(ls_b[ls_a[i][0]-1].index(ls_a[i][1])+1).zfill(6)+"\n"
print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split( ))
ls_a = []
ls_b = [[] for i in range(n)]
for i in range(m):
    p,y = map(int,input().split( ))
    ls_a.append([p,y])
    ls_b[p-1].append(y)
for i in range(n):
    if len(b[i]) !=0:
        ls_b[i].sort()
for i in range(m):
    print(str(ls_a[i][0]).zfill(6) + str(ls_b[ls_a[i][0]-1].index(ls_a[i][1])+1).zfill(6))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split( ))
ls_a = []
ls_b = [[] for i in range(n)]
for i in range(m):
    p,y = map(int,input().split( ))
    ls_a.append([p,y])
    ls_b[p-1].append(y)
for i in range(n):
    if len(a[i]) !=0:
        ls_b[i].sort()
for i in range(m):
    print(str(ls_a[i][0]).zfill(6) + str(ls_b[ls_a[i][0]-1].index(ls_a[i][1])+1).zfill(6))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split( ))
ls_a = []
ls_b = [[] for i in range(n)]
for i in range(M):
    p,y = map(int,input().split( ))
    ls_a.append([p,y])
    ls_b[p-1].append(y)
for i in range(n):
    ls_b[i].sort()
for i in range(m):
    print(str(ls_a[i][0]).zfill(6) + str(ls_b[ls_a[i][0]-1].index(ls_a[i][1])+1).zfill(6))

Submission status: Runtime Error

Solution code:
import sys,io

ws = sys.stdin.readline().strip().split()
n = int(ws[0])
m = int(ws[1])
ls_a = []
ls_b = [[] for i in range(n)]
for i in range(M):
    p,y = map(int, sys.stdin.readline().strip().split())
    ls_a.append([p,y])
    ls_b[p-1].append(y)
for i in range(n):
    ls_b[i].sort()
for i in range(m):
    print(str(ls_a[i][0]).zfill(6) + str(ls_b[ls_a[i][0]-1].index(ls_a[i][1])+1).zfill(6))

Submission status: Runtime Error

Solution code:
import sys
def solve():
    ws = sys.stdin.readline().strip().split()
    n = int(ws[0])
    m = int(ws[1])
    ls_a = []
    ls_b = [[] for i in range(n)]
    for i in range(M):
        p,y = map(int, sys.stdin.readline().strip().split())
        ls_a.append([p,y])
        ls_b[p-1].append(y)
    for i in range(n):
        ls_b[i].sort()
    for i in range(m):
        print(str(ls_a[i][0]).zfill(6) + str(ls_b[ls_a[i][0]-1].index(ls_a[i][1])+1).zfill(6))
solve()

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
PY=[list(map(int,input().split()))+[i] for i in range(M)] #定義終了

PY.sort(key= lambda x:x[1])
num=[0]*N
w=[""]*M

for p,y,i in PY:
	num[p-1]+=1
	w[i]=str(p).zfill(6)+str(num[p-1]).zfill(6)

for a in range(M):
	print(w)

Submission status: Runtime Error

Solution code:
import sys
def solve(n,m,a):
    bb = {i+1:[] for i in range(n)}
    for [s1,s2] in a:
        bb[s1].append(s2)
    b = [i for i in bb.values()]
    for i in range(len(b)):
        b[i].sort()
    c = {s2:s1 for [s1,s2] in a}
    d = [s2 for [s1,s2] in a]

    ans = ""
    for i in range(m):

        ken = str(c[d[i]])
        ban = str(b[c[d[i]]-1].index(d[i])+1)

        zero = ""
        for i in range(6-len(ken)):
            zero += "0"
        ans += zero
        ans += ken
        zero = ""
        for i in range(6-len(ban)):
            zero += "0"
        ans += zero
        ans += ban
        ans += "\n"
    
    return ans 
def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    M = int(ws[1])
    ls_PY = [list(map(int, sys.stdin.readline().strip().split())) for j in range(N+1)]
    return (N, M, ls_PY)

def main():
    N, M, ls_PY = readQuestion()
    answer = solve(N, M, ls_PY)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def solve(N, M, PYs):
    Ys = {i + 1: 1 for i in range(M)}
    ret = {}
    for p, y in sorted(PYs, key=lambda x: x[1]):
        ret[(p, y)] = "{:06d}{:06d}".format(p, Ys[p])
        Ys[p] += 1
    return [ret[(p, y)] for (p, y) in PYs]

if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    PYs = [tuple(map(int, input().split(" "))) for _ in range(M)]
    print("\n".join(solve(N, M, PYs)))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
li = [[] for _ in range(N+1)]
for i in range(M):
    p, y = map(int, input().split())
    li[p].append([i, y])
ans = [0 for _ in range(M)]
for i in range(1, N+1):
    iy = li[i]
    iy.sort(key=lambda x: x[1])
    for j in range(len(iy)):
        ans[iy[j][0]] = (i, j+1)
for shi in ans:
    print(f'{shi[0]:06}{shi[1]:06}')

Submission status: Runtime Error

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

C = []
for i in range(N+1) :
    C.append([])

for i, (p,y) in enumerate(L) :
    C[p].append([y,i])

for p in range(N+1) :
    for i,(y,_) in enumerate(sorted(C[p])) :
        ans[_] = str(p).zfill(6) + str(i+1).zfill(6)
for i in range(N+1) :
    print(ans[i])

Submission status: Runtime Error

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

C = []
for i in range(N+1) :
    C.append([])

for i, (p,y) in enumerate(L) :
    C[p].append([y,i])

for p in range(N+1) :
    for i,(y,_) in enumerate(sorted(C[p])) :
        ans[_] = str(p).zfill(6) + str(i+1).zfill(6)
for i in range(N+1) :
    print(ans[i])

Submission status: Runtime Error

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

def prefecturesort(i):
    return i[0]

def yearsort(i):
    return i[1]

W=[]
Z=[]

for i in range(m):
    P[i].append(i)
    W.append(P[i][0])

P.sort(key=prefecturesort)
P_c=[]
sum=0
for i in range(n):
    P_c.append(P[sum:W.count(i+1)+sum])
    sum+=c
    P_c[i].sort(key=yearsort)
for x in P_c:
    for j in range(len(x)):
        X=str("{0:06d}".format(x[j][0]))
        Y=str("{0:06d}".format(j+1))
        Z.append([X+Y,x[j][2]])
Z.sort(key=yearsort)
for i in range(m):
    print(Z[i][0])

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
p = []
y = []
data = dict()
ans = dict()
for i in range(1,n+1):
    data[i] = []
for i in range(m):
    ptemp,ytemp = map(int,input().split())
    data[ptemp].append(ytemp)
    p.append(ptemp)
    y.append(ytemp)
    ans[ytemp] = []

for i in data:
    data[i].sort()

for i in data:
    for k in range(len(data[i])):
        moji = []
        for j in range(6-len(str(i))):
            moji.append("0")
        moji.append(str(i))
        for j in range(6-len(str(k+1))):
            moji.append("0")
        moji.append(str(k+1))
        ans[data[i][k]].append(moji)
for i in range(m):
    for k in range(12):
        if k != 11:
            print(ans[y[i]][0][k],end="")
        else:
            print(ans[y[i]][0][k])

Submission status: Runtime Error

Solution code:
import numpy as np
N,M = map(int,input().split())
dtype=[('id',int),('p',int),('y',int)]
py = np.array([1]*M,dtype=dtype)
for i in range(M):
    py[i][0] = i
    py[i][1],py[i][2] = map(int,input().split())
py = np.sort(py,order=("p",'y'))
ans= ["1"]*M
h = 1
f = -1
for t in py:
    if f != int(t[1]):
        f = int(t[1])
        h = 1
    else:
        h += 1
    ans[t[0]] = "0"*(6-(f//10+1))+str(f)+"0"*(6-(h//10+1))+str(h)
for st in ans:
    print(st)

Submission status: Runtime Error

Solution code:
import bisect
N, M = map(int, input().split())
P, Y = [], []
pref = [[] for _ in range(N+1)] # non-0-indexed
for m in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
for i in len(pref):
	pref[i].sort()
    
for p,y in zip(P,Y):
    ans = "{:0>6}".format(p)
    i = bisect.bisect(pref[p], y)
    ans += "{:0>6}".format(i)
    print(ans)

Submission status: Runtime Error

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

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

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

num = [0] * (n+1)
ans = []*m

for p, y, x in pyxs:
    ans[i] = '{:06}'.format(p) + '{:06}'.format(num[p]+1)
    num[p] += 1

for s in ans:
    print(s)

Submission status: Runtime Error

Solution code:
n, m = list(map(int, input().split()))
tmps = [[0 for i in range(1)] for j in range(m)]
pys = []
for i in range(0, m):
    p, y = list(map(int, input().split()))
    tmps[p].append(y)
    pys.append([p, y])
    
for i in range(m):
    tmps[i].sort()
 
for py in pys:
    p, y = py
    yindex = tmps[p].index(y)
    print('{:06}'.format(p) + '{:06}'.format(yindex))