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:
def main():
    n, m = map(int, input().split())
    p = [0] * m
    y = [0] * m
    dic = {}
    cities = [[] for _ in range(n)]
    x = [0] * m
    for i in range(m):
        p[i], y[i] = map(int, input().split())
        cities[p[i] - 1].append(y[i])
        dic[y[i]] = i
    for index, i in enumerate(cities):
        for ind, j in enumerate(sorted(i), 1):
            x[dic[j]] = ind
    for i in range(m):
        print(f"{p[i]:06}{x[i]:06}")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(n)]
t = [[] for _ in range(n)]
for p, y in data:
  t[p - 1].append(y)
for i in range(n):
  t[i].sort()
for p, y in data:
  nth = t[p - 1].index(y) + 1
  print("%06d%06d" % (p, nth))

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
n, m = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(n)]
t = [[] for _ in range(n)]
for p, y in data:
  t[p - 1].append(y)
for i in range(n):
  t[i].sort()
for p, y in data:
  nth = bisect_left(t[p - 1], y) + 1
  print("%06d%06d" % (p, nth))

Submission status: Runtime Error

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

sortPy = sorted(py, key = lambda x : (x[0], x[1]))
 
d = {}
for i, (p, y, n) in enumerate(sortPy):
  if p in d:
    d[p] += 1
  else:
    d[p] = 1
  sortPy[i][2] = d[p]
 
for p, y, n in py:
  print(str(p).zfill(6) + str(n).zfill(6))

Submission status: Runtime Error

Solution code:
n, m = map(int, stdin.readline().split())
py = []
for _ in range(m):
  py.append(list(map(int, stdin.readline().split())) + [0])

sortPy = sorted(py, key = lambda x : (x[0], x[1]))
 
d = {}
for i, (p, y, n) in enumerate(sortPy):
  if p in d:
    d[p] += 1
  else:
    d[p] = 1
  sortPy[i][2] = d[p]

for p, y, n in py:
  print(str(p).zfill(6) + str(n).zfill(6))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:(x[0],x[1]))
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1
def plus0(s):
  while len(s)<6:
    ''.join(list(s).insert(0,'0'))
for k in range(m):
  print(plus0(str(lst[k][0]))+plus0(str(lst[k][1])))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:(x[0],x[1]))
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1

for k in range(m):
  print(plus0(str(lst[k][0]))+plus0(str(lst[k][1])))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:(x[0],x[1]))
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1
def plus0(s):
  while len(s)<6:
    s='0'+s
for k in range(m):
  print(plus0(str(lst[k][0]))+plus0(str(lst[k][1])))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:x[0])
lst.sort(key=lambda x:x[1])
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1
def plus0(s):
  while len(s)<6:
    s='0'+s
for k in range(m):
  lst[k][0]=plus0(str(lst[k][0]))
  lst[k][1]=plus0(str(lst[k][1]))
  print(''.join(lst[k]))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:(x[0],x[1]))
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1
def plus0(s):
  while len(s)<6:
    s='0'+s
for k in range(m):
  lst[k][0]=plus0(str(lst[k][0]))
  lst[k][1]=plus0(str(lst[k][1]))
  print(''.join(lst[k]))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  P,Y=map(int,input().split())
  lst.append([P,Y])
lst.sort(key=lambda x:(x[0],x[1]))
lst[0][1]=1
for j in range(m-1):
  if lst[j][0]==lst[j+1][0]:
    lst[j+1][1]=lst[j][1]+1
  else:
    lst[j+1][1]=1
def plus0(s):
  while len(s)<6:
    s.insert(0,'0')
for k in range(m):
  lst[k][0]=plus0(str(lst[k][0]))
  lst[k][1]=plus0(str(lst[k][1]))
  print(''.join(lst[k]))

Submission status: Runtime Error

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


ans = "Yes"
ma = -1
for i in range(n):
    if (ma <= List[i]):
        if List[i] - ma == 1:
            ma = List[i] - 1
        else:
            ma = List[i]
    else:
        ans = "No"
        break



print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(m)]
def make_id(num):
  s = len(str(num))
  add_zero = '0'*(6-s)
  return add_zero + str(num)

P = [[] for _ in range(m)]
for i in range(len(PY)):
  P[PY[i][0]-1].append(PY[i][1])
  P[PY[i][0]-1].sort()
for i in range(len(PY)):
  p,y=PY[i][0],PY[i][1]
  ord = P[p-1].index(y)+1
  print(make_id(p)+make_id(ord))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(m)]
def make_id(num):
  s = len(str(num))
  add_zero = '0'*(6-s)
  return add_zero + str(num)

P = [[] for _ in range(m)]
for i in range(len(PY)):
  P[PY[i][0]-1].append(PY[i][1])
  P[PY[i][0]-1].sort()
print(P)
for i in range(len(PY)):
  p,y=PY[i][0],PY[i][1]
  ord = P[p-1].index(y)+1
  print(make_id(p)+make_id(ord))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(m)]
def make_id(num):
  s = len(str(num))
  add_zero = '0'*(6-s)
  return add_zero + str(num)

P = [[] for _ in range(m)]
ans = []
sort_P = []
for i in range(len(PY)):
  P[PY[i][0]-1].append(PY[i][1])
for i in range(len(P)):
  sort_P.append(sorted(P[i]))
for i in range(len(PY)):
  p,y=PY[i][0],PY[i][1]
  ord = sort_P[p-1].index(y)+1
  print(make_id(p)+make_id(ord))

Submission status: Runtime Error

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

for i in range(len(pLst)):
    pLst[i].append(i)
nLst = [''] * N

for i in range(N):
    nLst[i] = str(i + 1).zfill(6)
tLst = sorted(pLst, key=lambda x: (x[0], x[1]))
ansLst = [''] * M
tmp = nLst[tLst[i][0] - 1]
index = 1

Submission status: Runtime Error

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

for i in range(len(pLst)):
    pLst[i].append(i)
nLst = [''] * N

for i in range(N):
    nLst[i] = str(i + 1).zfill(6)
tLst = sorted(pLst, key=lambda x: (x[0], x[1]))
ansLst = [''] * M
tmp = nLst[tLst[i][0] - 1]
index = 1
for i in range(M):
    if tmp == nLst[tLst[i][0] - 1]:
        ansLst[tLst[i][2]] = nLst[tLst[i][0] - 1] + str(index).zfill(6)
        index += 1
    else:
        index = 1
        tmp == nLst[tLst[i][0] - 1]
        ansLst[tLst[i][2]] = nLst[tLst[i][0] - 1] + str(index).zfill(6)

for i in ansLst:
    print(i)

Submission status: Runtime Error

Solution code:
def format_(st):
    st = str(st)
    return '0' * (6 - len(st)) + st

n, m = map(int, input().split())
cities = sorted([*map(int, input().split()), i] for i in range(m))
p = 0
for city in cities:
    if city[0] != p:
        p = city[0]
        i = 1
    city[1] = i
    i += 1
ids = [[city[2], format_(city[0]) + format_(city[1])] for city in cities]
ids.sort(key=lambda x: x[0])
for id in ids:
    print(id[1])

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
cities = sorted([*map(int, input().split()), i] for i in range(m))
p = 0
for city in cities:
    if city[0] != p:
        p = city[0]
        i = 1
    city[1] = i
    i += 1
ids = [[city[2], format(city[0], '06') + format(city[1], '06')] for city in cities]
ids.sort(key=lambda x: x[0])
for id in ids:
    print(id[1])

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
cities = sorted([*map(int, input().split()), i] for i in range(m))
p = 0
for city in cities:
    if city[0] != p:
        p = city[0]
        i = 1
    city[1] = i
    i += 1
ids = [[city[2], '{:06}'.format(city[0]) + '{:06}'.format(city[1])] for city in cities]
ids.sort(key=lambda x: x[0])
for id in ids:
    print(id[1])

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
p, y = [0] * m, [0] * m
sort_year = [0] * m
initial_index, count_city = [0] * n, [0] * n
tmp_counter = [0] * n 
for i in range(m):
    p[i], y[i] = map(int, input().split())
    count_city[p[i] - 1] += 1
for j in range(1, n):
  	initial_index[j] = initial_index[j] + count_city[j - 1]
for i in range(m):
    sort_year[initial_index[p[i] - 1] + tmp_counter[p[i] - 1]] = y[i]
    tmp_counter[p[i] - 1] += 1
for j in range(n):
    sort_year[initial_index[j] : initial_index[j] + count_city[j - 1]].sort()
for i in range(m):
    x = sort_year.index(y[i]) - initial_index[p[i] - 1] + 1
    print(str(p[i]).zfill(6) + str(x).zfill(6))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
p, y = [0] * m, [0] * m
sort_year = [0] * m
initial_index, count_city = [0] * n, [0] * n
tmp_counter = [0] * n 
for i in range(m):
    p[i], y[i] = map(int, input().split())
    count_city[p[i] - 1] += 1
for j in range(1, n):
  	initial_index[j] = initial_index[j] + count_city[j - 1]
for i in range(m):
    sort_year[initial_index[p[i] - 1] + tmp_counter[p[i] - 1]] = y[i]
    tmp_counter[p[i] - 1] += 1
for j in range(n):
    sort_year[initial_index[j] : initial_index[j] + count_city[j - 1]].sort()
for i in range(m):
    x = sort_year.index(y[i]) - initial_index[p[i] - 1] + 1
    print(str(p[i]).zfill(8) + str(x).zfill(8))

Submission status: Runtime Error

Solution code:
N, M = [int(x) for x in input().split()]
PY_list = [[int(x)-1 for x in input().split()] for _ in range(M)]
lst = [[] for _ in range(N)] 
for P, Y in PY_list:
    lst[P].append(Y)
for l in lst:
    l.sort()
for i in range(N):
    p, y = PY_list[i]
    print('{:06}{:06}'.format(p+1, lst[p].index(y)+1))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
town = [[] for _ in range(N)]
for i in range(Q):
    place, year = map(int, input().split())
    town[place-1].append([year,i])

# print(town)

ans = []
index = 0
for item in town:
    # print(item)
    item.sort()
    index += 1
    index = str(index)
    while len(index) < 6:
        index = '0' + index
    for i in range(len(item)):
        num = i + 1
        num = str(num)
        while len(num) < 6:
            num = '0' + num
        xxx = index + num
        tmp = []
        tmp.append(item[i][1])
        tmp.append(xxx)
        ans.append(tmp)
    index += 1

ans.sort()
for item in ans:
    print(item[1])

Submission status: Runtime Error

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

N_ken,M_si = map(int,input().split())
ken_year_map = {}
for i in range(1,N_ken+1):ken_year_map[i]=[]

ken_list = [0]*M_si
year_list = [0]*M_si

for si in range(M_si):
    ken_list[si],year_list[si] = map(int,input().split())
    ken_year_map[ken_list[si]] += [year_list[si]]
        
for i in ken_year_map:
    ken_year_map[i].sort()

for ken,year in zip(ken_list,year_list):
    print('{:06}{:06}'.format(ken,bisect.bisect_right(d[ken], year)))

Submission status: Runtime Error

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

N_ken,M_si = map(int,input().split())
ken_year_map = {}
for i in range(1,N_ken+1):ken_year_map[i]=[]

ken_list = [0]*M_si
year_list = [0]*M_si

for si in range(M_si):
    ken_list[si],year_list[si] = map(int,input().split())
    ken_year_map[ken_list[si]] += [year_list[si]]
        
for i in ken_year_map:
    ken_year_map[i].sort()

for ken,year in zip(ken_list,year_list):
    print('{:06}{:06}'.format(ken,bisect.bisect_right(d[ken], year)))

Submission status: Runtime Error

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

N_ken,M_si = map(int,input().split())
ken_year_map = {}
ken_list = []
year_list = []

for si in range(1,M_si+1):
    ken,year = map(int,input().split())
    ken_list.append(ken)
    year_list.append(year)
    ken_year_map[ken] += [year]
        
for i in ken_year_map:
    ken_year_map[i].sort()

for ken,year in zip(ken_list,year_list):
    print((str(ken*1000000 + ken_year_map[ken].index(year)+1)).zfill(12))

Submission status: Runtime Error

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

N_ken,M_si = map(int,input().split())
ken_year_map = {}
ken_list = []
year_list = []

for si in range(1,M_si+1):
    ken,year = map(int,input().split())
    ken_list.append(ken)
    year_list.append(year)
    if ken in ken_year_map:
        ken_year_map[ken].append(year)
    else:
        ken_year_map[ken] = [year]
for i in ken_year_map:
    ken_year_map[i].sort()

for ken,year in zip(ken,year):
    print((str(ken*1000000 + ken_year_map[ken].index(year)+1)).zfill(12))

Submission status: Runtime Error

Solution code:
import sys
input sys.stdin.readline

N_ken,M_si = map(int,input().split())
ken_year_map = {}
ken_year_list = []

for si in range(1,M_si+1):
    ken,year = map(int,input().split())
    ken_year_list.append([ken,year])
    if ken in ken_year_map:
        ken_year_map[ken].append(year)
    else:
        ken_year_map[ken] = [year]
for i in ken_year_map:
    ken_year_map[i].sort()

for ken,year in ken_year_list:
    print((str(ken*1000000 + ken_year_map[ken].index(year)+1)).zfill(12))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
yp = [list(map(int, input().split())) for _ in range(m)]
yp=[(x[1], x[0]) for x in yp]
yp.sort()
pref_counter = [0]*(n+1) # 県 1～n
xp = [[0,0]]*m

for i in range(m):
    y, p = yp[i]
    pref_counter[p] += 1
    xp[i] = [pref_counter[p], p]
    s = format(p, '06d') + format(pref_counter[i], '06d')
    print(s)

Submission status: Runtime Error

Solution code:
import numpy as np
 
N, M = map(int, input().split())
base = [[int(l) for l in input().split()] for i in range(M)]
sort_target = np.sort(base, axis=0).tolist()
 
prefecture_index = sort_target[0][0]
i=0
result = []
for target in sort_target:
  i = i + 1 if prefecture_index == target[0] else 1
  prefecture_index = target[0]
  result.append([base.index(target), "{:0=6}{:0=6}".format(target[0], i)])
sorted_result = sorted(result)
 
for result in sorted_result:
  print(result[1])

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
s = []
r = []
for n in range(n):
    s.append(list(map(int,input().split())))
for i in range(n):
    rank = 1
    for j in range(n):
        if s[i][0] == s[j][0] and s[i][1] > s[j][1]:
            rank += 1
    prefString = str(s[i][0])
    rankString = str(rank)
    Number1st = "0" * (6-len(prefString)) + prefString 
    Number2nd = "0" * (6-len(rankString)) + rankString
    print(Number1st+Number2nd)

Submission status: Runtime Error

Solution code:
import pandas as pd

n,m = map(int,input().split())

df = pd.DataFrame([list(map(int,input().split())) for i in range(m)], columns=["p", "y"])
df['rank'] = df.groupby('p')['y'].rank().astype(int)
df.apply(lambda s: print(f'{s["p"]:06}{s["rank"]:0=6}'), axis=1)

Submission status: Runtime Error

Solution code:
import bisect
N, M = map(int, input().split())
city = []
table = [0]*M
count = [0]*M
for i in range(M):
  P, Y = map(int, input().split())
  P -= 1
  city.append((i,P,Y))
city.sort(key=lambda x:x[2])
for i, P, Y in city:
  count[P] += 1
  x = str(count[P])
  P = str(P+1)
  ans = P.zfill(6)+x.zfill(6)
  table[i] = ans
for i in range(M):
  print(table[i])

Submission status: Runtime Error

Solution code:
n,m=map(int, input().split())
p=[1]*(n+1)
c=[]
for i in range(m):
  pi,x =map(int, input().split())
  c.append([i+1, pi, x, 0])
  #p[pi].append(x)
#for i in range(n):
# p[i]=sorted(p[i])
x_order = sorted(c, key=lambda e: e[2])
for e in range(x_order):
  e[3] = p[pi]
  p[pi] += 1

i_order = sorted(x_order)
for e in i_order:
  id=e[1]*1000000+e[3]
  print(str(id).zfill(12))

Submission status: Runtime Error

Solution code:
n,m=map(int, input().split())
p=[[] for i in range(n+1)]
c=[]
for i in range(m):
  pi,x =map(int, input().split())
  c.append((pi,x))
  p[pi].append(x)
for i in range(n):
  p[i]=sorted(p[i])
for e in c:
  id=e[0]*1000000+p[e[0]].index(e[1])+1
  proud(str(id).zfill(12))

Submission status: Runtime Error

Solution code:
#C-ID
n,m=map(int,input().split())
L={}
lp=[[] for _ in range(n)]#preごとのまとめの準備
for cn in range(m):
  p,y=map(int,input().split())
  lp[p-1].append([y,cn])
  lp[p-1]=sorted(lp[p-1])
for pre in range(n):
  k=len(lp[pre])
  if k>0:
    for d in range(k):
      cn=lp[pre][k][1]
      ans="0"*(6-len(str(pre)))+str(pre)+"0"*(6-len(str(d+1)))+str(d+1)
      L[cn]=ans
for h in range(m):
  print(L[h])

Submission status: Runtime Error

Solution code:
def c_id():
    from collections import defaultdict
    N, M = map(int, input().split())
    City = [[s] + [int(i) for i in input().split()] for s in range(M)]

    # 同じ県に属する市を誕生年の早い順に並べ、順序付けする
    city_dict = defaultdict(list)
    for k, p, y in City:
        city_dict[p].append([k, p, y])
    for p in city_dict.keys():
        city_dict[p].sort(key=lambda x: x[2])
        for i in range(len(city_dict[p])):
            city_dict[p][i][2] = i + 1

    # 変換は終わった。通し番号順に並べる
    ans = sorted([e for v in city_dict.values() for e in v])
    return '\n'.join([f'{p:06d}{num:06d}' for _, p, num in ans])  # 通し番号は不要

print(c_id())

Submission status: Runtime Error

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

dict_a = {}
list_a =[]
def seiti(arg_num):
    if len(str(arg_num))==6:
        pass
    else :
        ret_num = str(arg_num).zfill(6)
    return ret_num

for i in range(1,M+1):
    P,Y =map(int,input().split())
    dict_b = {}
    dict_b = dict(id = i,ken = P,year = Y)
    list_a.append(dict_b)
list_a.sort(key=lambda x: x['year'])

for j in range(1,N+1):
    cnt =1
    for k in list_a:
        if  k.get('ken') ==j:
            k['shi_id'] =cnt
            cnt +=1
        else :
            pass
list_a.sort(key=lambda x: x['id'])
for l in list_a:
    aaa = seiti(l.get('ken'))
    bbb = seiti(l.get('shi_id'))
    print(aaa+bbb)

Submission status: Runtime Error

Solution code:
# N: 県の個数
# M: 市の個数
N,M = map(int,input().split())

dict_a = {}

# P: 県の番号
# Y: 市の誕生年(ID)
# リスト内に辞書を挿入
list_a =[]

# 辞書リストを生成する
# [{'id': 1, 'ken': 1, 'year': 32}, {'id': 2, 'ken': 2, 'year': 63}, {'id': 3, 'ken': 1, 'year': 12}]

# 整地する関数
def seiti(arg_num):
    if len(str(arg_num))==6:
        pass
    else :
        ret_num = str(arg_num).zfill(6)
    return ret_num

for i in range(1,M+1):
    P,Y =map(int,input().split())
    dict_b = {}
    dict_b = dict(id = i,ken = P,year = Y)
    list_a.append(dict_b)

# yearをソートする
list_a.sort(key=lambda x: x['year'])

# N毎に、採番を行う。
# [{'id': 3, 'ken': 1, 'year': 12, 'shi_id': 1}, {'id': 1, 'ken': 1, 'year': 32, 'shi_id': 2}, {'id': 2, 'ken': 2, 'year': 63, 'shi_id': 1}]

for j in range(1,N+1):
    cnt =1
    for k in list_a:
        if  k.get('ken') ==j:
            k['shi_id'] =cnt
            cnt +=1
        else :
            pass

# print(list_a)

# id順にソートする
list_a.sort(key=lambda x: x['id'])


# 出力処理
for l in list_a:
    # 整地
    aaa = seiti(l.get('ken'))
    bbb = seiti(l.get('shi_id'))
    # 出力
    print(aaa+bbb)

Submission status: Runtime Error

Solution code:
#レート緑の半数が解ける問題らしい
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
pys = [[] for _ in range(N)]
#要素の日付ごとに格納
for py in PY:
    pys[py[0] - 1].append(py[1])

#日付をソート
for i in range(M):
    if pys[i]:
        pys[i].sort()

#出力
for i in range(M):
    #県番号
    number_ken = str(PY[i][0])
    #順番
    number_rank = str(pys[PY[i][0]-1].index(PY[i][1]) + 1)
    print(("0"*(6-len(number_ken))) + number_ken + ("0"*(6-len(number_rank))) + number_rank)

Submission status: Runtime Error

Solution code:
#レート緑の半数が解ける問題らしい
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
pys = [[] for _ in range(M)]
#要素の日付ごとに格納
for py in PY:
    pys[py[0] - 1].append(py[1])

#日付をソート
for i in range(M):
    if pys[i]:
        pys[i].sort()

#出力
for i in range(M):
    #県番号
    number_ken = str(PY[i][0])
    #順番
    number_rank = str(pys[PY[i][0]-1].index(PY[i][1]) + 1)
    print(("0"*(6-len(number_ken))) + number_ken + ("0"*(6-len(number_rank))) + number_rank)

Submission status: Runtime Error

Solution code:
#レート緑の半数が解ける問題らしい
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
pys = [[] for _ in range(3)]
#要素の日付ごとに格納
for py in PY:
    pys[py[0] - 1].append(py[1])

#日付をソート
for i in range(M):
    if pys[i]:
        pys[i].sort()

#出力
for i in range(M):
    #県番号
    number_ken = str(PY[i][0])
    #順番
    number_rank = str(pys[PY[i][0]-1].index(PY[i][1]) + 1)
    print(("0"*(6-len(number_ken))) + number_ken + ("0"*(6-len(number_rank))) + number_rank)

Submission status: Runtime Error

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

PY = sorted(PY)

ans = [0]*M
#print(PY)

for i in range(M):
  X = str(PY[i][0])
  if i >= 1:
    #print(PY)
    if PY[i][0] == PY[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY[i][1] = X + Y
#print(PY)
PY = sorted(PY, 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())
db = {}
line = 0
while line < M:
    P, C = map(six, input().split())
    line += 1
    if P not in db:
      db[P] = [(P + C, line)]
    else:
      db[P].append([P + C, line])

ans = []

# melting dictionary
for p in db:
  for idx in range(len(db[p])):
     ans.append(db[p][idx])

# sorting by prefecture / city foundation year
ans.sort(key=lambda x:x[0])      

# converting city foundation year to id number
Prefecture = ans[0][0][:6]
cont = 0
for idx in range(M):
  new_Prefecture = ans[idx][0][:6]
  if new_Prefecture != Prefecture:
    cont = 1
  else:
    cont +=1
  ans[idx] = (ans[idx][0][:6] + six(cont), ans[idx][1])

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
db = []
line = 0
while line < M:
    P, C = map(int, input().split())
    line += 1
    db.append([line, P, C])

# sort by year    
db.sort(key=lambda x: x[2])
# sort by prefecture
db.sort(key=lambda x: x[1])

# ans list would be list whereby each element is [line, ID]
ans = []

cont = 0
P = db[0][1]

for idx in range(M):
  # create ID
  new_P = db[idx][1]
  digP = len(str(new_P))
  ID = '0' * (6 - digP) + str(new_P)
  
  if new_P == P:
    cont += 1
  else:
    cont = 1
  ID += '0' * (6 - len(str(cont))) + str(cont)
  
  ans.append([db[idx][0],ID])
  
  P = new_P

ans.sort(key=labmda x:x[0])  
  
for row in range(M):
  print(ans[row][1])

Submission status: Runtime Error

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

_number = []
P = []
Y = []
yp = [[] for i in range(N+1)]
_yp = []

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

# print(yp)

_l_yp = len(yp)

for i in range(_l_yp):
    yp[i].sort()


ans_yp = [[] for i in range(N+1)]

for i in range(_l_yp):
    nga_yp = len(yp[i])

    for j in range(nga_yp):
    #    print(i, j)
    #    print(yp[i][j][1])
       ans_yp[yp[i][j][1]].append(i)
       ans_yp[yp[i][j][1]].append(j+1)


__len = len(ans_yp)

for i in range(__len):
    buff = ''
    for d in range(2):
        ans = ''
        for j in range((6-len(str(ans_yp[i][d])))):
            ans += '0'

        buff += ans + str(ans_yp[i][d])

    print(buff)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
h = [list(map(int, input().split()))for i in range(M)]
for i in range(M):
    h[i].append(i)
h = sorted(h,key=lambda h:(h[0],h[1]))
k = 0
p = h[0][0]
for i in range(M):
    if h[i][0] == p:
        h[i].append(str(p).zfill(6)+str(k+1).zfill(6))
        k+=1
    else:
        p = h[i][0]
        k = 0
        h[i].append(str(p).zfill(6) + str(k + 1).zfill(6))
        break
h = sorted(h,key=lambda h:h[2])
# print(h)
for i in range(M):
    print(h[i][3])

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
h = [list(map(int, input().split()))for i in range(M)]
for i in range(M):
    h[i].append(i)
h = sorted(h,key=lambda h:(h[0],h[1]))
k = 0
p = h[0][0]
for i in range(M):
    if h[i][0] == p:
        h[i].append(str(p).zfill(6)+str(k+1).zfill(6))
        k+=1
    else:
        p += 1
        k = 0
        h[i].append(str(p).zfill(6) + str(k + 1).zfill(6))
        break
h = sorted(h,key=lambda h:h[2])
# print(h)
for i in range(M):
    print(h[i][3])

Submission status: Runtime Error

Solution code:
import bisect
n,m=map(int, input().split())
pl=[0]*m
yl=[0]*m
ol=[[] for i in range(n+1)]
for i in range(m):
    pl[i],yl[i] = map(int, input().split())
    ol[pl[i]].append(yl[i])
for i in range(n):
    ol[pl[i]] = sorted(ol[pl[i]])
for i in range(m):
    x = bisect.bisect_right(ol[pl[i]], yl[i])
    print("%06d%06d" % (pl[i], x))

Submission status: Runtime Error

Solution code:
n,m=map(int, input().split())
pl=[0]*m
yl=[0]*m
cl=[0]*(m+1)
ol=[[] for i in range(n+1)]
for i in range(m):
    pl[i],yl[i] = map(int, input().split())
    ol[pl[i]].append((pl[i], yl[i], i))
for i in range(n):
    cnt = 1
    for o in sorted(ol[pl[i]]):
        cl[o[2]] = cnt
        cnt+=1
for i in range(m):
    print("%06d%06d" % (pl[i], cl[i]))

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

p_ar = np.array(p_ls)
y_ar = np.array(y_ls)


# 市ごとに連続するようにする
sort_ind = p_ar.argsort()
p_sorted = p_ar[sort_ind]
y_sorted = y_ar[sort_ind]
x_ar = np.zeros(len(p_ls))
x_ar_sorted = np.zeros(len(p_ls))

ind = M-1

while ind >= 0:
    min_ind = p_sorted.argsort() 
    tmp_x = y_sorted[min_ind:ind+1].argsort()+min_ind
    x_ar_sorted[tmp_x] = np.array(range(len(tmp_x)))+1
    ind = min_ind-1

x_ar[sort_ind] = x_ar_sorted

for i in range(M):
    print('%06d'%p_ar[i] + '%06d'%x_ar[i])

Submission status: Runtime Error

Solution code:
import numpy as np

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

for _ in range(M):
    py_ls =[list(map(int,input().split(" "))) for _ in range(M)]
    
py_ar = np.array(py_ls)


# 市ごとに連続するようにする
py_T = py.T
sort_ind = py_T[0].argsort()
p_sorted = py_T[0][sort_ind]
y_sorted = py_T[1][sort_ind]
x_ar = np.zeros(len(p_ls))
x_ar_sorted = np.zeros(len(p_ls))

ind = 0

while ind < M:
    d = 0
    while ind+d < M-1 and p_sorted[ind] == p_sorted[ind+d+1]:
        d+=1
    tmp_x = y_sorted[ind:ind+d+1].argsort()+ind
    x_ar_sorted[tmp_x] = np.array(range(len(tmp_x)))+1
    ind = ind + d + 1

x_ar[sort_ind] = x_ar_sorted

for i in range(M):
    print('%06d'%py_T[0][i] + '%06d'%x_ar[i])

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

p_ar = np.array(p_ls)
y_ar = np.array(y_ls)


# 市ごとに連続するようにする
sort_ind = p_ar.argsort()
p_sorted = p_ar[sort_ind]
y_sorted = y_ar[sort_ind]
x_ar = np.zeros(len(p_ls))
x_ar_sorted = np.zeros(len(p_ls))

ind = 0

while ind < M:
    d = p_sorted.count(p_sorted[ind])
    tmp_x = y_sorted[ind:ind+d+1].argsort()+ind
    x_ar_sorted[tmp_x] = np.array(range(len(tmp_x)))+1
    ind = ind + d + 1

x_ar[sort_ind] = x_ar_sorted

for i in range(M):
    print('%06d'%p_ar[i] + '%06d'%x_ar[i])

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

p_ar = np.array(p_ls)
y_ar = np.array(y_ls)


# 市ごとに連続するようにする
p_ind = p_ar.sort()
p_sorted = p_ar[p_ind]
y_sorted = y_ar[p_ind]
x_ar_sorted = np.zeros(len(p_ls))


ind = 0

while ind < M:
    d = 0
    while ind+d < M-1 and p_sorted[ind] == p_sorted[ind+d+1]:
        d+=1
    tmp_x = y_sorted[ind:ind+d+1].argsort()+1
    x_ar_sorted[ind:ind+d+1] = tmp_x
    ind = ind + d + 1

for i in range(M):
    print('%06d'%p_ar[i] + '%06d'%x_ar_sorted[p_ind[i]])

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

p_ar = np.array(p_ls)
y_ar = np.array(y_ls)


# 市ごとに連続するようにする
p_ind = p_ar.sort()
p_sorted = p_ar[p_ind]
y_sorted = y_ar[p_ind]
x_ar_sorted = np.zeros(len(p_ls))


ind = 0

while ind < M:
    d = 0
    while ind+d < M-1 and p_[ind] == p_sorted[ind+d+1]:
        d+=1
    tmp_x = y_sorted[ind:ind+d+1].argsort()+1
    x_ar_sorted[ind:ind+d+1] = tmp_x
    ind = ind + d + 1

for i in range(M):
    print('%06d'%p_ar[i] + '%06d'%x_ar_sorted[p_ind[i]])