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:
from itertools import chain
import numpy as np
import pandas as pd


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

P = [0] * N

I = list(range(M))

Q = [None] * M
Y = [None] * M

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

D = zip(I, Q, Y)
D = sorted(D, key=lambda x: [x[1], x[2]])
I, Q, Y = map(list, zip(*D))

print(P)

P = list(chain.from_iterable([list(range(1, p+1)) for p in P]))

print(P)

D = zip(I, Q, Y, P)
D = sorted(D, key=lambda x: x[0])
I, Q, Y, P = map(list, zip(*D))

print(P)

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

Submission status: Runtime Error

Solution code:
from itertools import chain
import numpy as np
import pandas as pd


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

P = [0] * N
Q = [None] * M

for m in range(M):
    p, y    = map(int, input().split())
    P[p-1] += 1
    Q[m]    = p, y

D = pd.DataFrame(Q)
D = D.sort_values(by=[0, 1])

D[2] = list(chain.from_iterable([list(range(1, p+1)) for p in P]))

D = D.sort_index()

X = D[0].values.tolist()
Y = D[2].values.tolist()

for i in range(M):
    print('%06d%06d' % (X[i], Y[i]))

Submission status: Runtime Error

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

l1 = [[] for i in range(n)]
l2 = []

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

for p in range(n):
    l1[p].sort()

for i in range(m):
    p = l2[i][0]
    k = bisect.right(l1[p-1],l2[i][1])
    p = str(p)
    k = str(k)
    ans = "0"*(6-len(p))+p+"0"*(6-len(k))+k
    print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
i=1
id_list=[]
y_list=[]
id_list2=[]
before=""
after=""
while n>0:
    id_list.append([0])
    n=n-1 
while i<=m:
    p,y=map(int,input().split())
    y_list.append((p,y))
    id_list[p-1].append(y)
    i+=1
for i in range(N):
    id_list[i].sort()
for item in y_list:
    before=str(item[0])
    while len(before)<6:
        before="0"+before
    after=str(id_list[item[0]-1].index(item[1]))
  
    while len(after)<6:
        after="0"+after
    id_list2.append(before+after)
for idx in id_list2:
    print(idx)

Submission status: Runtime Error

Solution code:
s=input().split()
n,m=int(s[0]),int(s[1])
l=[[] for i in range(100001)]
d=[{} for i in range(100001)]
inp=[]
for i in range(m):
    s=input().split()
    p,y=int(s[0]),int(s[1])
    inp.append((p,y))
    l[p].append(y)
for i in range(100001):
    l[i].sort()
for i in range(100001):
    cnt=1
    for j in l[i]:
        d[i][j]=cnt
        cnt+=1
for pa in inp:
    print(str(pa[0]).zfill(6)+str(d[pa[0]-1][pa[1]]).zfill(6))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
cnt = [0 for i in range(n + 1)] 
check = []
ans = []

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

check.sort()

for y, p, i in check:
    cnt[p] += 1
    ans.append((i,str(p).zfill(6)+str(cnt[p]).zfill(6)))

ans.sort()

for aa, bb in ans:
    print(bb)

Submission status: Runtime Error

Solution code:
I=lambda:list(map(int,input().split()))[::-1];m,n=I();l=[I()+[i]for i in range(m)];c=[0]*-~n;a=[0]*m
for y,p,i in sorted(l):c[p]+=1;a[i]='%06d'%p+'%06d'%c[p]
print('\n'.join(t))

Submission status: Runtime Error

Solution code:
I=lambda:list(map(int,input().split()));n,m=I();l=[I()+[i]for i in range(M)];c=[0]*-~N;a=[0]*M
for p,y,i in sorted(l,key=lambda x:x[1]):c[p]+=1;a[i]='%06d'%p+'%06d'%c[p]
for t in a:print(t)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
    int N, M; cin >> N >> M;

    vector< pair<int, int> > rawInput(M);
    vector<vector<int> > prifList(N);
    map<pair<int, int>, int> answer;

    for(int i = 0; i < M; ++i)
    {
        int P, Y; cin >> P >> Y;
        rawInput.at(i) = make_pair(P, Y);
        prifList.at(P - 1).push_back(Y);
        answer[make_pair(P, Y)] = 0;
    }

    for(int i = 0; i < N; ++i)
    {
        sort(prifList.at(i).begin(), prifList.at(i).end());
        for(int j = 0; j < prifList.at(i).size(); ++j)
        {
            answer[make_pair(i+1, prifList[i][j])] = j + 1;
        }
    }
    for(int i = 0; i < M; ++i)
    {
        cout << setw(6) << setfill('0') << rawInput.at(i).first;
        cout << setw(6) << setfill('0') << answer[rawInput.at(i)] << '\n';
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np

N, M = map(int, input().split())
P = [None] * (N+1)
Y = [None] * (N+1)
for i in range(M):
    p, y = map(int, input().split())
    P[i] = p
    Y[i] = y
P = np.array(P)
Y = np.array(Y)
PY = np.c_[P, Y]
sort_ind = np.argsort(Y)
PY_sort = PY[sort_ind]
count = [0] * (N+1)
id_list = [None] * (N+1)
for i, py in enumerate(PY_sort):
    count[py[0]] += 1
    id_list[i] = (str(py[0]).zfill(6) + str(count[py[0]]).zfill(6))
id_list = np.array(id_list)
id_list = id_list[np.argsort(sort_ind)]
for city_id in id_list:
    print(city_id)

Submission status: Runtime Error

Solution code:
"""
import numpy as np
N, M = map(int, input().split())
cities = {}
Y = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = p
    Y[i] = y

ans = {}
sorted_Y = sorted(Y.items(), key=lambda x:x[1])
P_i = np.zeros(N)
for i,y in sorted_Y:
    p = cities[i]
    P_i[p-1] += 1
    ans[i] = (p, int(P_i[p-1]))

for i in range(M):
    print('{0:06}{1:06}'.format(ans[i][0], ans[i][1]))
"""

n, m = map(int,input().split())
pys = []
for i in range(m):
    x = map(int, input().split())
    x = [x[0],x[1],i]
    pys.append(x)

pys.sort()
pp = -1
lid = 0
ans = []
for i in range(m):
    if pp == pys[i][0]:
        lid += 1
    else:
        lid = 1
        pp = pys[i][0]
    ans.append(pp*10**6+lid)

for v in ans:
    print(':012d'.format(v))

Submission status: Runtime Error

Solution code:
    n, m = map(int,input().split())
    list = [input().split() for i in range(m)]
     
    list2 = [list[i][0] for i in range(m)]
     
    l = [sorted([list[i][1] for i in range(m) if int(list[i][0]) == j+1]) for j in range(n)]
     
    y = [l[int(list[i][0])-1].index(list[i][1])+1 for i in range(m)]
     
    for i in range(m):
        print((list2[i].zfill(6))+(str(y[i]).zfill(6)))

Submission status: Runtime Error

Solution code:
import numpy as np

n, m = list(map(int, input().split()))
mat = np.zeros((m, 2))
for i in range(m):
	mat[i, 0], mat[i, 1] = list(map(int, input().split()))
mat = np.c_[mat, np.array(range(m))]
mat = mat[mat[:, 1].argsort()]
cnt = np.zeros(m)
res = []
for i in mat[:, 0]:
	i = int(i)
	cnt[i] += 1
	res.append('{0:06d}{1:06d}'.format(i, int(cnt[i])))

for i in np.argsort(mat[:, 2]):
	print(res[int(i)])

Submission status: Runtime Error

Solution code:
import numpy as np

n, m = list(map(int, input().split()))
mat = np.zeros((m, 2))
for i in range(m):
	mat[i, 0], mat[i, 1] = list(map(int, input().split()))
mat = np.c_[mat, np.array(range(m))]
mat = mat[mat[:, 1].argsort()]
cnt = np.zeros(m)
res = []
for i, in mat[:, 0]:
	i = int(i)
	cnt[i] += 1
	res.append('{0:06d}{1:06d}'.format(i, int(cnt[i])))

for i in np.argsort(mat[:, 2]):
	print(res[int(i)])

Submission status: Runtime Error

Solution code:
import numpy as np

n, m = list(map(int, input().split()))
mat = np.zeros((m, 2))
for i in range(m):
	mat[i, 0], mat[i, 1] = list(map(int, input().split()))
mat = np.c_[mat, np.array(range(m))]
mat = mat[mat[:, 1].argsort()]
cnt = np.zeros(m)
res = []
for i, j in mat[:, :2]:
	i = int(i)
	cnt[i] += 1
	res.append('{0:06d}{1:06d}'.format(i, int(cnt[i])))

for i in np.argsort(mat[:, 2]):
	print(res[int(i)])

Submission status: Runtime Error

Solution code:
import numpy as np

n, m = list(map(int, input().split()))
mat = np.zeros((m, 2))
for i in range(m):
	mat[i, 0], mat[i, 1] = list(map(int, input().split()))
mat = np.c_[mat, np.array(range(m))]
mat = mat[mat[:, 1].argsort()]
cnt = np.zeros(m)
res = []
print(cnt[2])
for i, j in mat[:, :2]:
	i = int(i)
	cnt[i] += 1
	res.append('{0:06d}{1:06d}'.format(i, int(cnt[i])))
#print(res)
#print(list(mat_[:, 2]))
for i in np.argsort(mat[:, 2]):
	print(res[int(i)])
#res_ = res[np.argsort(mat_[:, 2])]
#for r in res_:
#	print(r)

Submission status: Runtime Error

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

import math

N, M = map(int, input().split())
P = [None] * M
Y = [None] * M
for i in range(M):
    p, y = map(int, input().split())
    P[i] = p
    Y[i] = y

ken = [None] * N
for i in range(N):
    ken[i] = []

for i in range(M):
    ken[P[i] - 1].append(Y[i])


# < M * log(N)
for i in range(N):
    ken[i] = sorted(ken[i])


def close_twopower(n):
    output = 2
    while output < n:
        output = output * 2
    return output


def comp(tr, node, x, i):
    if tr[i] is None:
        return i
    elif x < tr[i][0]:
        return comp(tr, node, x, 2 * i + 1)
    else:
        return comp(tr, node, x, 2 * i + 2)


# 木構造
def create_bitree(a):
    # a = [[int, hoge, ...], ...]
    n = len(a)
    output = [None] * int(math.pow(2, n))

    for i in range(n):
        # output = comp(output, a[i], a[i][0], 0)
        output[comp(output, a[i], a[i][0], 0)] = a[i]

    return output


city_info = [None] * M
k = 0

# count M
while(k < M):
    for l in range(N):
        for m in range(len(ken[l])):
            # ken[l][m]の値によって二分木を作る
            # create_bitree()

            city_info[k] = [ken[l][m], l + 1, m + 1]
            k += 1

bi_city_info = create_bitree(city_info)


def create_id(p, x):
    output_p = str(p)
    output_x = str(x)
    p_len = len(output_p)
    x_len = len(output_x)
    while p_len < 6:
        output_p = "0" + output_p
        p_len += 1
    while x_len < 6:
        output_x = "0" + output_x
        x_len += 1

    return output_p + output_x


def comp2(tr, x, i):
    if tr[i][0] == x:
        return i
    elif x < tr[i][0]:
        return comp2(tr, x, 2 * i + 1)
    else:
        return comp2(tr, x, 2 * i + 2)

    return 0  # dummy


def bi_search(tr, x):
    # tr is [[int. hoge, ...]
    return comp2(tr, x, 0)


# 律速
# M^2
for i in range(M):
    # Y[i]を探してきてprint
    j = bi_search(bi_city_info, Y[i])
    print(create_id(bi_city_info[j][1], bi_city_info[j][2]))

Submission status: Runtime Error

Solution code:
import numpy as np

N,M=map(int,input().split())
F=np.zeros((N+1,10**7+1),dtype=bool)
PY=[]
 
for _ in range(M):
    p,y=map(int,input().split())
    PY.append([p,y])
    F[p][y]=True

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

Submission status: Runtime Error

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

  
corresp = {}
for n in range(1, N+1):
    data_n = []
    for i in range(M):
        if data[i][0] == n:
            data_n.append(data[i])
    sort_n = sorted(data_n, key=lambda data_n_i: data_n_i[1])
    for k in range(len(sort_n)):
        corresp.update({str(sort_n[k]):k+1})
    

for i in range(M):
    print('{0:012d}'.format(data[i][0]*100000+corresp[str(data[i])]))

Submission status: Runtime Error

Solution code:
import numpy as np

N,M=map(int,input().split())
F=np.zeros((N+1,10**9+1),dtype=bool)
PY=[]
 
for _ in range(M):
    p,y=map(int,input().split())
    PY.append([p,y])
    F[p][y]=True

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

Submission status: Runtime Error

Solution code:
import numpy as np

N,M=map(int,input().split())
F=np.zeros((N+1,10**9+1),dtype=bool)
PY=[]
 
for _ in range(M):
    p,y=map(int,input().split())
    PY.append([p,y])
    F[p][y]=True
 
for [p,y] in PY:
    print('{0:06d}'.format(p)+'{0:06d}'.format(F[p,:y].sum()+1))

Submission status: Runtime Error

Solution code:
n, m = list(map(int, input().split(" ")))
p = m*[0]
y = m*[0]
ken = [[0] for i in range(n)]
for i in range(m):
    p[i], y[i] = list(map(int, input().split(" ")))
    ken[p[i]-1].append(y[i])

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

for i in range(m):
    print("%06d%06d" %(p[i], ken[p[i]-1].index(y[i])))

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())
cities = {}
P = {}
Y = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = p
    Y[i] = y

ans = []
sorted_Y = sorted(Y.items(), key=lambda x:x[1])
P_i = np.zeros(N)
for i,y in sorted_Y:
    p = cities[i]
    P_i[p] += 1
    ans.append(p,P_i[p])

for p,x in ans:
    print('{0:06}{1:06}'.format(p, x))

Submission status: Runtime Error

Solution code:
n, m = list(map(int, input().split()))
tmp = [[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()))
    tmp[p].append(y)
    pys.append([p, y])

ttmp = [[0 for i in range(1)] for j in range(m)]

for i in range(m):
    ttmp[i] = sorted(tmp[i])

for py in pys:
    p, y = py
    yindex = ttmp[p].index(y)
    print('{:06}'.format(p) + '{:06}'.format(yindex))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
data = []
for m in range(M):
  data.append(int, input().split())
  
corresp = {}
for n in range(1, N+1):
    data_n = []
    for i in range(M):
        if data[i][0] == n:
            data_n.append(data[i])
    sort_n = sorted(data_n, key=lambda data_n_i: data_n_i[1])
    for k in range(len(sort_n)):
        corresp.update({str(sort_n[k]):k+1})
    

for i in range(M):
    print('{0:012d}'.format(data[i][0]*100000+corresp[str(data[i])]))

Submission status: Runtime Error

Solution code:
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

h, w, k = list(map(int, input().split(" ")))

if(w == 1):
    print(1)
    exit()

ans = 0
for i in range(h+1):
    if((k - 1) <= i and (k - 1 + i) % 2 == 0):
        if(h - i != 0):
            tmp = 0
            for j in range(h-i+1):
                tmp += combinations_count(h, j)
            ans += combinations_count(h, i) * tmp
        else:
            ans += combinations_count(h, i)

    
    if((k - 1) <= i and (k - 1 + i) % 4 == 0 and w >= 4):
        if(h - i != 0):
            tmp = 0
            for j in range(h-i+1):
                tmp += combinations_count(h, j)
                if(j != 0): tmp -= combinations_count(h-1, j-1)
            ans += combinations_count(h, i) * tmp
        else:
            ans += combinations_count(h-1, i)


    if((k - 1) <= i and (k - 1 + i) % 6 == 0 and w >= 6):
        if(h - i != 0):
            tmp = 0
            for j in range(h-i+1):
                tmp += combinations_count(h, j)
                if(j != 0): tmp -= combinations_count(h-1, j-1)
                if(j >= 2): tmp -= combinations_count(h-2, j-2)
            ans += combinations_count(h, i) * tmp
        else:
            ans += combinations_count(h-1, i)

    if((k - 1) <= i and (k - 1 + i) % 8 == 0 and w >= 8):
        if(h - i != 0):
            tmp = 0
            for j in range(h-i+1):
                tmp += combinations_count(h, j)
                if(j != 0): tmp -= combinations_count(h-1, j-1)
                if(j >= 2): tmp -= combinations_count(h-2, j-2)
                if(j >= 3): tmp -= combinations_count(h-3, j-3)
            ans += combinations_count(h, i) * tmp
        else:
            ans += combinations_count(h-1, i)
            

print(ans % 1000000007)

Submission status: Runtime Error

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

n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
#print(l)
li=[[]*n for _ in range(n)]
lis=sorted(l)
for i in lis:
    li[i[0]-1].append(i[1])
    print(li)
for i in l:
    a=li[i[0]-1].index(i[1])
    print(str('%06d'%i[0])+str('%06d'%(a+1)))

Submission status: Runtime Error

Solution code:
n,m =map(int,input().split())
a = [list(map(int,input().split())) for i in range(m)]
b = ['']*m
e = [0]*(n+1)
g = [0]*m
for i in range(m):
    g[i] = a[i][0]
for i in range(n):
    e[i+1] = g.count(i+1)
f = [0]*(n+1)
for i in range(1,n+1):
    for j in range(i):
        f[i] += e[j+1]
d = sorted(a)
for i in range(m):
    x = d.index(a[i])
    print('0'*(6-len(str(a[i][0]))) + str(a[i][0])\
    +'0'*(6-len(str(x)-f[a[i][0]-1]+1))\
    +str((x)-f[a[i][0]-1]+1))

Submission status: Runtime Error

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

N,M = (int(i) for i in input().split())

pp = [[] for _ in range(N)]

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

clist = sorted(clist, key=itemgetter(1))

for p, y in clist:
    pp[p-1].append(y)

for p, y in clist:
    num = pp[p-1].index(y) + 1
    print('%06d' % p + '%06d' % num)

Submission status: Runtime Error

Solution code:
n,m =map(int,input().split())
a = [list(map(int,input().split())) for i in range(m)]
b = ['']*m
e = [0]*(n+1)
g = [0]*m
for i in range(m):
    g[i] = a[i][0]
for i in range(n):
    e[i+1] = g.count(i+1)
f = [0]*(n+1)
for i in range(1,n+1):
    for j in range(i):
        f[i] += e[j+1]
d = sorted(a)
for i in range(m):
    x = d.index(a[i])
    print('0'*(6-len(str(a[i][0]))) + str(a[i][0])\
    +'0'*(6-len(str(x)-f[a[i][0]-1]+1)))\
    +str((x)-f[a[i][0]-1]+1)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
data = []
for m in range(M):
  data.append(input().split())
  
corresp = {}
for n in range(1, N+1):
    data_n = []
    for i in range(M):
        if data[i][0] == n:
            data_n.append(data[i])
    sort_n = sorted(data_n, key=lambda data_n_i: data_n_i[1])
    for k in range(len(sort_n)):
        corresp.update({str(sort_n[k]):k+1})
    

for i in range(M):
    print('{0:012d}'.format(data[i][0]*100000+corresp[str(data[i])]))

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
F=[[False]*(10**7+1) for _ in range(N+1)]
PY=[]

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
N,M = map(int,input().split())
P = []
Y = []
index = range(1,M+1)
for i in range(M):
 a,b= map(int,input().split())
 P.append(a)
 Y.append(b)
print(P)
print(Y)
for i in range(1,N+1):
 a = [j for j, x in enumerate(P) if x == i]
 for p in range(1,len(a)+1):
  print({0:04d}.format(i){0:04d}".format(p))

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())
cities = {}
P = {}
Y = []
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = (p,y)
    Y.append(y)

sorted_Y = sorted(Y)
sorted_P = {p:sorted(P[p].items(), key=lambda x:x[1]) for p in P}

P_i = np.zeros(N)
ans = {}
for i in sorted_Y:
    city = Y.index(i)+1
    ans[city] = i

for i in ans:
    p,y = cities[i]
    print('{0:06}{1:06}'.format(p, i))

Submission status: Runtime Error

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

a_dict = {}
for pi,yi in e:
    if(pi not in a_dict):
        a_dict[pi] = [yj]
    else:
        a_dict[pi] +=[yj]

for pi,yi in e:
    print('{0:06d}'.format(pi)+'{0:06d}'.format(a_dict[pi].index(yi)+1))

Submission status: Runtime Error

Solution code:
y = list()
p = list()
n,m = map(int, input().split( ))
c = int(1)
for i in range(n+1):
    pp,yy = map(int, input().split( ))
    p.insert(i+1,"{0:06d}".format(pp))
    y.insert(i+1,"{0:06d}".format(yy))
y,p = zip(*sorted(zip(y, p)))
y = list(y)
p = list(p)
for k in range(n+1):
    if c == 1:
        y[k] == k+1
    if 
for j in range(n+1):
    print(p[j],end ="")
    print(y[j])

Submission status: Runtime Error

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

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list[pm-1].append(ym)

for i in range(n):
    city_list_copied[i].sort()
    for j in range(len(city_list[i])):
        cindex = sum(x <= city_list[i][j] for x in city_list[i])
        print("{:0=6}{:0=6}".format(i+1, cindex))

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())
l = [i for i in range(m)]
for i in range(m):
    l[i] = [i, p[i],y[i]]

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

count = [1]*n
ans = [[]]*m
for i in range(m):
    ans[i] = [l[i][0], str(l[i][1]).zfill(6) + str(count[(l[i][0])]).zfill(6)]
    count[(l[i][0])] = count[(l[i][0])] + 1



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

Submission status: Runtime Error

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

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list[pm-1].append(ym)
city_list_copied = copy.deepcopy(city_list)

for i in range(n):
    city_list_copied[i].sort()
    for j in range(len(city_list[i])):
        cindex = sum(x <= city_list[i][j] for x in city_list[i])
        print("{:0=6}{:0=6}".format(i+1, cindex))

Submission status: Runtime Error

Solution code:
import numpy as np
N,M = map(int,input().split())
prefs = np.zeros([M,3])
srts = np.zeros([N,M])
for i in range(M):
  P,Y = map(int,input().split())
  prefs[i,:] = [P,Y,0]
for i in range(1,N+1):
  target = prefs[prefs[:,0]==i]
  junind = np.argsort(target[:,1])
  srts[i-1,:len(junind)]= junind
ks = np.zeros(N)
for i in range(M):
  p = prefs[i,0] - 1
  prefs[i,2] = int(srts[int(p)][int(ks[p])] + 1)
  ks[p] += 1
  print("{:>06d}".format(int(prefs[i,0]))+"{:>06d}".format(int(prefs[i,2])))

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
F=[[False]*(10**9+1) for _ in range(N+1)]
PY=[]

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

for [p,y] in PY:
    print('{0:06d}'.format(p)+'{0:06d}'.format(F[p][:y].count(True)+1))

Submission status: Runtime Error

Solution code:
for i in range(M):
    array=list(map(int,input().strip().split()))
    PY.append(array)

PY.sort()
city=0
order=0
for i in range(M):
    newcity=PY[i][0]
    if(newcity!=city):
        city=newcity
        order=1
    strcity=str(PY[i][0])
    strorder=str(order)
    upper='0'*(6-len(strcity))+strcity
    lower='0'*(6-len(strorder))+strorder
    order=order+1
    print(upper+lower)

Submission status: Runtime Error

Solution code:
    import numpy as np
N,M = map(int,input().split())
prefs = np.zeros([M,3])
srts = np.zeros([N,M])
for i in range(M):
  P,Y = map(int,input().split())
  prefs[i,:] = [P,Y,0]

for i in range(1,N+1):
  target = prefs[prefs[:,0]==i]
  junind = np.argsort(target[:,1])
  srts[i-1,:len(junind)]= junind

ks = np.zeros(N)
for i in range(M):
  p = prefs[i,0] - 1
  prefs[i,2] = int(srts[int(p)][int(ks[p])] + 1)
  ks[p] += 1
  print("{:>06d}".format(int(prefs[i,0]))+"{:>06d}".format(int(prefs[i,2])))

Submission status: Runtime Error

Solution code:
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    data = []
    for i in range(m):
        p, y = map(int, input().split())
        data.append([p, y, i])
    data_sorted = sorted(data, key=itemgetter(0, 1))

    p, y, i = 0, 0, 0
    p_prev = 0 
    x = 1 # initialize
    codes = []
    for p, y, i in data:
        # initialize if new prefecture, increment if not
        if p != p_prev:
            x = 1
        else:
            x += 1
        code = '{:06d}{:06d}'.format(p, x)
        codes.append([i, codes])
        p_prev = p

    for i, code in sorted(codes, key=itemgetter(0)):
        print code
        
main()

Submission status: Runtime Error

Solution code:
temp = input().rstrip().split(" ")
N = int(temp[0])#県の数
M = int(temp[1])#市の数

def zero(num):
    s = str(num)
    if len(s)==1:
        s = "00000"+s
    elif len(s)==2:
        s = "0000" +s
    elif len(s) ==3:
        s = "000" + s
    elif len(s) == 4:
        s = "00" +s
    elif len(s) == 5:
        s = "0" + s
    return s

finder = []
ans =  []
for i in range(N):
    temp = []
    for j in range(M):
        temp.append(100000)
    ans.append(temp)

for i in range(M):
    temp = input().rstrip().split(" ")
    P = int(temp[0])
    Y = int(temp[1])
    finder.append(Y)
    ans[P-1][i] = Y
for i in range(N):
    ans[i].sort()

for i in range(N):
    for j in range(M):
        if ans[i][j] == finder[i]:
            answercode = zero(i+1) + zero(j+1)
            print(answercode)

Submission status: Runtime Error

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

for i in range(M):
    A, B = map(int, input().split())
    tmp[A-1].append(B)

for i in range(N):
    tmp[i].sort()
    
for i in range(M):
    X = tmp[F[i][0]-1].index(F[i][1])+1
    print(('0'*(6-len(str(F[i][0]))) + str(F[i][0])) + '0'*(6-len(str(X))) + str(X))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
city = [[] for _ in range(n+1)]
ret = ["" for _ in range(m)]
def createSix(s):
    while len(s) != 6:
        s = "0" + s
    return s
for i in range(m):
    a,b = map(int, input().split())
    city[a].append((b, i))
for i in range(m):
    city[i].sort()
print(city)
for i in range(n+1):
    for j in range(len(city[i])):
        ret[city[i][j][1]] = createSix(str(i)) + createSix(str(j+1))
for i in ret:
    print(i)

Submission status: Runtime Error

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

N,M=map(int, input().split())
lis={}
ly=[]
for i in range(M):
    t1,t2 =list(map(int,input().split()))
    lis[t2]=t1
    ly.append(t2)
d={}
for i in sorted(lis):
    d[lis[i]]=d.get(lis[i],0)+1
    ly[ly.index(i)]=[lis[i],d[lis[i]]



for i in ly:print('{:0=6}{:0=6}'.format(i[0],i[1]))

Submission status: Runtime Error

Solution code:
from bisect import bisect,bisect_left


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

d1 = {}
d2 = {}
for i in range(M):
    PY = list(map(int,input().split()))
    tmp = d1.get(PY[0],[])
    ins_pos = bisect(tmp,PY[1])
    tmp.insert(ins_pos,PY[1])
    d1[PY[0]] = tmp

for py in PY:
    s1 = str(py[0])
    s1 = ("0"*(6-len(s1)))+s1
    s2 = str(bisect_left(d[py[0]],py[1])+1)
    s2 = ("0"*(6-len(s2)))+s2

    print(s1+s2)

Submission status: Runtime Error

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

a,b = map(int,input().split())

da = [[] for i in range(a)]
d = []
for i in range(b):
    k,kk = map(int,input().split())
    da[k-1].append(kk)
    d.append([k, kk])


da.sort()

for i in d:
    p = da[i[0]-1].index(i[1])

    n = str(i[0])
    m = str(p+1)

    n = "0"*(6-len(n)) + n
    m = "0"*(6-len(m)) + m

    print(n+m)

Submission status: Runtime Error

Solution code:
from operator import itemgetter

N,M=map(int,input().split())
PY=[]
P=[[] for i in range(N)]
ans=[0 for i in range(M)]
for i in range(M):
    PYi=list(map(int,input().split()))
    PY.append(PYi)
    P[PYi[0]-1].append([i,PYi[1]])

for i in range(N):
    P[i]=sorted(P[i], key=itemgetter(1))

for i in range(N):
    for j in range(len(P[PY[i][0]-1])):
        ans[P[PY[i][0]-1][j][0]]=j+1

for i in range(M):
    a=format(PY[i][0],'06x')
    b=format(ans[i],'06x')
    print(a+b)

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
indexs = []
ps = []
ys = []
for i in range(n):
    indexs.append([])
for i in range(m):
    p,y = map(int, input().split())
    indexs[p-1].append(y)
    pn = (6-len(str(p)))*"0"+str(p)
    for i in range(len(ps)):
        if ps[i] == pn and indexs[p-1][i] > y:
            ys[i] += 1
    ps.append(pn)
    j = sorted(indexs[p-1]).index(y)
    ys.append(j)
for i in range(len(ps)):
    j = ys[i]
    yn = (6-len(str(j+1)))*"0"+str(j+1)
    print(ps[i]+yn)

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
indexs = []
ps = []
ys = []
for i in range(n):
    indexs.append([])
for i in range(m):
    p,y = map(int, input().split())
    indexs[p-1].append(y)
    pn = (6-len(str(p)))*"0"+str(p)
    for i in range(len(ps)):
        if ps[i] == pn and indexs[p-1][i] > y:
            ys[i] += 1
    ps.append(pn)
    j = sorted(indexs[p-1]).index(y)
    ys.append(j)
for i in range(len(ps)):
    j = ys[i]
    yn = (6-len(str(j)))*"0"+str(j)
    print(ps[i]+yn)

Submission status: Runtime Error

Solution code:
n,m = list(map(int, input().split()))
pp=[]
yy=[]
for i in range(m):
    p,y=list(map(int, input().split()))
    pp.append(p)
    yy.append(y)
ids = [x for x in range(m)]
ids_=[]
yy_=sorted(yy)
pp_=[0 for i in range(m)]
ans =[]
for y in yy_:
    ids_.append(ids[yy.index(y)])
    p_=pp[yy.index(y)]
    pp_[p_]+=1
    x = str(p_).rjust(6,'0') + str(pp_[p_]).rjust(6,'0')
    pp_.append(p_)
    ans.append(x)

for i in ids:
    print(ans[ids_.index(i)])

Submission status: Runtime Error

Solution code:
from operator import itemgetter

N,M=map(int,input().split())
PY=[]
P=[[] for i in range(N)]
Pk=[0 for i in range(N)]
ans=[0 for i in range(M)]
for i in range(M):
    PYi=list(map(int,input().split()))
    PY.append(PYi)
    P[PYi[0]-1].append([i,PYi[1]])
    Pk[PYi[0]-1]+=1

for i in range(N):
    P[i]=sorted(P[i], key=itemgetter(1))

for i in range(N):
    for j in range(Pk[PY[i][0]-1]):
        ans[P[PY[i][0]-1][j][0]]=j+1
        
for i in range(M):
    a=format(PY[i][0],'06x')
    b=format(ans[i],'06x')
    print(a+b)

Submission status: Runtime Error

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

p_list = []
y_list = []
shi_map = {}

for i in range(M):
    p, y = map(int, input().split())
    p_list.append(p)
    y_list.append(y)
    if p in shi_map:
        shi_map[p].append(y)
    else:
        shi_map[p] = [y]
shi_map = sorted(shi_map.items(), key=lambda x: x[0])
shi_map = dict(shi_map)
count_p = len(set(p_list))
shi_list = list(map(sorted, shi_map.values()))
for i in range(M):
    p = p_list[i]
    y = y_list[i]
    if p > count_p:
        s = shi_list[p - 2 - count_p]
    else:
        s = shi_list[p-1]
    j = s.index(y)
    p_str = str(p).zfill(6)
    j_str = str(j+1).zfill(6)
    print(p_str + j_str)