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: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
query = []
for i in range(m):
    query.append(list(map(int, input().split())))
result =  [[] for i in range(n)]
 
for city in query:
    result[city[0]-1].append(city[1])
 
for i in result:
    i.sort()
 
for city in query:
    rank = result[city[0]-1].index(city[1])+1
    resultStr = "{}{}".format(str(city[0]).zfill(6), str(rank).zfill(6))
    print(resultStr)

Submission status: Time Limit Exceeded

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

for city in query:
    result[city[0]-1].append(city[1])

for i in result:
    i.sort()

for city in query:
    rank = result[city[0]-1].index(city[1])+1
    resultStr = "{}{}".format(str(city[0]).zfill(6), str(rank).zfill(6))
    print(resultStr)

Submission status: Time Limit Exceeded

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

for city in query:
    result[city[0]-1].append(city[1])

for i in result:
    i.sort()

for city in query:
    rank = result[city[0]-1].index(city[1])+1
    resultStr = "{}{}".format("0"*(6-len(str(city[0]))) + str(city[0]), "0"*(6-len(str(rank))) + str(rank))
    print(resultStr)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
query = []
for i in range(m):
    qList = list(map(int, input().split()))
    query.append(qList)
result = [[] for i in range(n)]
 
for city in query:
    result[city[0]-1].append(city[1])
 
for i in range(n):
    result[i].sort()
 
for city in query:
    rank = result[city[0]-1].index(city[1])+1
    prefStr = "0"*(6-len(str(city[0]))) + str(city[0])
    rankStr = "0"*(6-len(str(rank))) + str(rank)
    resultStr = "{}{}".format(prefStr, rankStr)
    print(resultStr)

Submission status: Time Limit Exceeded

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

cities = []
ps = {}

def to_id(x):
  return '0' * (6 - len(str(x))) + str(x)

for i in range(m):
  p, y = map(int, input().split())
  cities.append([p, y])
  if p in ps.keys():
    ps[p].append(y)
  else:
    ps[p] = [y]
  
years = {}
for p in ps.keys():
  years[p] = sorted(ps[p])

for i in range(m):
  p = cities[i][0]
  y = years[p].index(cities[i][1]) + 1
  print(to_id(p) + to_id(y))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
py = [list(map(int,input().split())) for i in range(m)]
list = sorted(py,key=lambda x:x[1])
dic={}
for i in range(m):
    dic.setdefault(list[i][0],[]).append(list[i][1])
a = b = 0
for i in range(m):
    a = py[i][0]
    b = dic[py[i][0]].index(py[i][1])+1
    a = str(a).zfill(6)
    b = str(b).zfill(6)
    print(a+b)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
dic = {}
li = [[] for i in range(n+1)]
pyli = []
for i in range(m):
    p, y = na()
    li[p].append(y)
    pyli.append([p, y])
for yyy in li:
    yyy.sort()
for p, y in pyli:
    i = li[p].index(y)
    shi = str(p)
    num = str(i + 1)
    print(shi.zfill(6) + num.zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
dic = {}
li = []
for i in range(m):
    p, y = na()
    li.append([p,y])
    if p not in dic.keys():
        dic[p] = [y]
    else:
        dic[p].append(y)
for v in dic.values():
    v.sort()
for p, y in li:
    i = dic[p].index(y)
    shi = str(p)
    num = str(i + 1)
    print(shi.zfill(6) + num.zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
dic = {}
li = []
for i in range(m):
    p, y = na()
    li.append([p,y])
    if p not in dic.keys():
        dic[p] = [y]
    else:
        dic[p].append(y)
for v in dic.values():
    v.sort()
for p, y in li:
    i = dic[p].index(y)
    shi = str(p)
    num = str(i + 1)
    pad = 6 - len(shi)
    shi = '0' * pad + shi
    pad = 6 - len(num)
    num = '0' * pad + num
    print(shi + num)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
dic = {}
li = []
for i in range(m):
    p, y = na()
    li.append([p,y])
    if p not in dic.keys():
        dic[p] = [y]
    else:
        dic[p].append(y)
for v in dic.values():
    v.sort()
for p, y in li:
    for i, n in enumerate(dic[p]):
        if n == y:
            shi = str(p)
            num = str(i + 1)
            pad = 6 - len(shi)
            shi = '0' * pad + shi
            pad = 6 - len(num)
            num = '0' * pad + num
            print(shi + num)
            break

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
dic = {}
li = []
for i in range(m):
    p, y = na()
    li.append([p,y])
    if p not in dic.keys():
        dic[p] = [y]
    else:
        dic[p].append(y)
for v in dic.values():
    v.sort()
for p, y in li:
    for i, n in enumerate(dic[p]):
        if n == y:
            shi = str(p)
            num = str(i + 1)
            pad = 6 - len(shi)
            shi = '0' * pad + shi
            pad = 6 - len(num)
            num = '0' * pad + num
            print(shi + num)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
py = []
for i in range(m):
	p,y = map(int,input().split())
	py.append([i,p,y])
spy = sorted(py,key=lambda x: (x[1],x[2]))
c=0
for i in range(1,n+1):
	for j in spy:
		if j[1] == i:
			c += 1
			j.append(c)
	c = 0

sspy = sorted(spy,key=lambda x: x[0])

for i in sspy:
	print(str(i[1]).zfill(6) + str(i[3]).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(m)]
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: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
input_list = [tuple(map(int, input().split())) for _ in range(m)]
py_dict = {}

for p, y in input_list:
    if p not in py_dict:
        py_dict[p] = []
    py_dict[p].append(y)

for p in py_dict:
    py_dict[p].sort()

for p, y in input_list:
    index = py_dict[p].index(y) + 1
    print(str(p).zfill(6) + str(index).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, m = map(int, input().split())
    input_list = []
    py_dict = {}

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

    for p in py_dict:
        py_dict[p].sort()

    for p, y in input_list:
        index = py_dict[p].index(y) + 1
        print(str(p).zfill(6) + str(index).zfill(6))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

from collections import defaultdict

N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
dd = defaultdict(list)

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

    dd[p].append(y)

for k, v in dd.items():
    v.sort()
    dd[k] = v

#print(dd)

for i in range(M):
    p = P[i]
    y = Y[i]

    print('{0:06d}'.format(p), end='')
    x = dd[p].index(y) +1
    print('{0:06d}'.format(x))

Submission status: Time Limit Exceeded

Solution code:
#ID
n,m=map(int,input().split())
p=[0]
y=[0]
z=[0]
for i in range(1,m+1):
    P,Y=map(int,input().split())
    p.append(P)
    y.append(Y)
    z.append(i)
for i in range(2,m+1):
    k=i
    for j in range(i-1):
        if y[k]<y[k-1]:
            y[k],y[k-1]=y[k-1],y[k]
            z[k],z[k-1]=z[k-1],z[k]
            p[k],p[k-1]=p[k-1],p[k]
            k-=1
        else:
            break
t=[1]*(n+1)
ID=[0]*(m+1)
for i in range(1,m+1):
    ID[z[i]]=str(p[i]*(10**6)+t[p[i]]).zfill(12)
    t[p[i]]+=1
for i in range(1,m+1):
    print(ID[i])

Submission status: Time Limit Exceeded

Solution code:
import bisect
import collections

n, m = map(int, input().split())
py_dict = collections.defaultdict(list)
cityi_by_year = []
for i in range(m):
  p, y = map(int, input().split())
  py_dict[p].insert(bisect.bisect_left(py_dict[p],y),y)
  cityi_by_year.append([p,y])
  
for p, y in cityi_by_year:
  idx = bisect.bisect_left(py_dict[p],y)
  print('0'*(6-len(str(p))) + str(p) + '0'*(6-len(str(idx+1))) + str(idx+1))

Submission status: Time Limit Exceeded

Solution code:
import bisect

n, m = map(int, input().split())
py_dict = {}
cityi_by_year = []
for i in range(m):
  p, y = map(int, input().split())
  if p not in py_dict:py_dict[p] = [y]
  else:py_dict[p].insert(bisect.bisect_left(py_dict[p],y),y)
  cityi_by_year.append([p,y])
  
for p, y in cityi_by_year:
  idx = py_dict[p].index(y)
  print('0'*(6-len(str(p))) + str(p) + '0'*(6-len(str(idx+1))) + str(idx+1))

Submission status: Time Limit Exceeded

Solution code:
import bisect

n, m = map(int, input().split())
py_dict = {}
cityi_by_year = []
for i in range(m):
  p, y = map(int, input().split())
  if p not in py_dict:py_dict[p] = [y]
  else:py_dict[p].insert(bisect.bisect_left(py_dict[p],y),y)
  cityi_by_year.append([p,y])
  
for p, y in cityi_by_year:
  idx = bisect.bisect_left(py_dict[p],y)
  print('0'*(6-len(str(p))) + str(p) + '0'*(6-len(str(idx+1))) + str(idx+1))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
py_dict = {}
cityi_by_year = []
for i in range(m):
  p, y = map(int, input().split())
  if p not in py_dict:py_dict[p] = [y]
  else:py_dict[p].append(y)
  cityi_by_year.append(y)

ans = [-1 for _ in range(m)]
for p in sorted(py_dict.keys()):
  p_str = '0'*(6-len(str(p))) + str(p)
  cnt = 0
  for y in sorted(py_dict[p]):
    cnt += 1
    ans[cityi_by_year.index(y)] = p_str + '0'*(6-len(str(cnt))) + str(cnt)
[print(id) for id in ans]

Submission status: Time Limit Exceeded

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

books = [[] for _ in range(N + 1)]
years = []

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

for p, y in years:
    books[p].append(y)

for i in range(N + 1):
    books[i].sort()

for p, y in years:
    ind = books[p].index(y) + 1
    s = ''
    s += '{:06d}'.format(p)
    s += '{:06d}'.format(ind)
    print(s)

Submission status: Time Limit Exceeded

Solution code:
pre_n, city_n = map(int, input().split())
cities = [list(map(int, input().split())) for x in range(city_n)]

history = {}

A = {}

for x in sorted(cities):
    pref = str(x[0])
    if pref not in history:
        history[pref] = '1'

    A[str(x)] = '0'*(6-len(pref)) + pref + '0'*(6-len(history[pref])) + history[pref]

    history[pref] = str(int(history[pref]) + 1)

for x in cities:
    print(A[str(x)])

Submission status: Time Limit Exceeded

Solution code:
pre_n, city_n = map(int, input().split())
cities = [list(map(int, input().split())) for x in range(city_n)]

history = {}

A = {}

for x in sorted(cities):
    pref = str(x[0])
    if pref not in history:
        history[pref] = '1'

    A.setdefault(str(x), '0'*(6-len(pref)) + pref + '0'*(6-len(history[pref])) + history[pref])

    history[pref] = str(int(history[pref]) + 1)

for x in cities:
    print(A[str(x)])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

for i in range(m):
    s,t = map(int,input().split())
    city[s].append(t)
    arr.append((s,t))

for i in range(1,n+1):
    city[i].sort()
    
for i in range(m):
    x = str(arr[i][0])
    y = str(city[int(x)].index(arr[i][1]) + 1)
    print(x.rjust(6, "0") + y.rjust(6,"0"))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
prefecture = [[] for i in range(N+1)]
ans = []
for i in range(M):
    p,y = map(int,input().split())
    prefecture[p].append([y,i])
    prefecture[p].sort()
for i in range(1,N+1):#iは県の番号   
    for j in range(1,len(prefecture[i])+1):#jは何番目か，すなわちx
        ans.append([prefecture[i][j-1][1],i,j])
ans.sort()
for i in range(len(ans)):
    print('{:06}{:06}'.format(ans[i][1],ans[i][2]))

Submission status: Time Limit Exceeded

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())
    tmp = [0,0]
    tmp[0] = year
    tmp[1] = i
    town[place-1].append(tmp)
 
# print(town)
 
ans = []
 
for item in town:
    index = town.index(item)
    # 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)
 
ans.sort()
for item in ans:
    print(item[1])

Submission status: Time Limit Exceeded

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 p, y in PY_list:
    print('{:06}{:06}'.format(p+1, lst[p].index(y)+1))

Submission status: Time Limit Exceeded

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)
sort = [sorted(lst[i]) for i in range(N)]
for p, y in PY_list:
    print('{:06}{:06}'.format(p+1, sort[p].index(y)+1))

Submission status: Time Limit Exceeded

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 i in range(N):
    lst[i] = sorted(lst[i])
for p, y in PY_list:
    print('{:06}{:06}'.format(p+1, lst[p].index(y)+1))

Submission status: Time Limit Exceeded

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 i, Ys in enumerate(lst):
    lst[i] = sorted(Ys)
for p, y in PY_list:
    print('{:06}{:06}'.format(p+1, lst[p].index(y)+1))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
prefecture = [[] for i in range(N+1)]
ans = []
for i in range(M):
    p,y = map(int,input().split())
    prefecture[p].append([y,i])
    prefecture[p].sort()
for i in range(1,N+1):#iは県の番号
    tmp_p = str(i)
    while(len(tmp_p)!=6):
         tmp_p = '0'+tmp_p
    for j in range(1,len(prefecture[i])+1):#jは何番目か，すなわちx
        tmp_x = str(j)
        while (len(tmp_x)!=6):
            tmp_x = '0'+tmp_x
        ans.append([prefecture[i][j-1][1],tmp_p+tmp_x])
ans.sort()
for i in range(len(ans)):
    print(ans[i][1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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(ken_year_map[ken], year)))
    print('{:06}{:06}'.format(ken,ken_year_map[ken].index(year)+1))

Submission status: Time Limit Exceeded

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())
    tmp = [0,0]
    tmp[0] = year
    tmp[1] = i
    town[place-1].append(tmp)

# print(town)

ans = []

for item in town:
    index = town.index(item)
    # 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)

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

Submission status: Time Limit Exceeded

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((str(ken*1000000 + ken_year_map[ken].index(year)+1)).zfill(12))

Submission status: Time Limit Exceeded

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())
    tmp = []
    tmp.append(year)
    tmp.append(i)
    town[place-1].append(tmp)

ans = []

for item in town:
    index = town.index(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)

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

Submission status: Time Limit Exceeded

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,year = map(int,input().split())
    ken_list[si] = ken
    year_list[si] = 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: Time Limit Exceeded

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 = []
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: Time Limit Exceeded

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

ans = []

for item in town:
    index = town.index(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)

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

Submission status: Time Limit Exceeded

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)
    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_list,year_list):
    print((str(ken*1000000 + ken_year_map[ken].index(year)+1)).zfill(12))

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
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: Time Limit Exceeded

Solution code:
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).zfill(6))+(str(ken_year_map[ken].index(year)+1)).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
cnt = {}
by = {}

for i in range(m):
  p, y = map(int, input().split())
  cnt[i] = [p, y]
  if p in by:
    s = by[p]
    s.append(y)
    s.sort()
    by[p] = s
  else:
    by[p] = [y]

for i in range(m):
  print(str(cnt[i][0]*1000000 + (list(by[cnt[i][0]]).index(cnt[i][1]))+1).zfill(12))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
base = [[int(l) for l in input().split()] for i in range(M)]
sorted_target = sorted(base) 
  
prefecture_index = sorted_target[0][0]

i=0
result = {}

for target in sorted_target:
  if prefecture_index == target[0]:
    i+=1
  else:
    prefecture_index = target[0]
    i = 1
  result[base.index(target)] = [prefecture_index, i]

for i in range(M):
  print("{:0=6}{:0=6}".format(result[i][0], result[i][1]))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
base = [[int(l) for l in input().split()] for i in range(M)]
sorted_target = sorted(base) 
  
prefecture_index = sorted_target[0][0]

i=0
result = {}

for target in sorted_target:
  if prefecture_index == target[0]:
    i+=1
  else:
    prefecture_index = target[0]
    i = 1
  result[base.index(target)] = [target[0], i]

for i in range(M):
  print("{:0=6}{:0=6}".format(result[i][0], result[i][1]))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
base = [[int(l) for l in input().split()] for i in range(M)]
sort_target = sorted(base) 
  
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), target[0], i])

sorted_result = sorted(result) 
for result in sorted_result:
  print("{:0=6}{:0=6}".format(result[1], result[2]))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
base = [[int(l) for l in input().split()] for i in range(M)]
sort_target = sorted(base)
 
  
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: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
base = [[int(l) for l in input().split()] for i in range(M)]
sort_target = sorted(base)
 
  
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: Time Limit Exceeded

Solution code:
n,m=list(map(int,input().split()))
a=[]
b=[[] for _ in range(n)]
for _ in range(m):
  p,y=list(map(int,input().split()))
  a.append([p,y])
  b[p-1].append(y)
def sorttwo(x):
  x.sort()
  return x
b=list(map(sorttwo,b))
for i in a:
  print('{:0>6}'.format(i[0])+'{:0>6}'.format(b[i[0]-1].index(i[1])+1))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
s = []
r = []
for i in range(m):
    s.append(list(map(int,input().split())))
for i in range(m):
    rank = 1
    for j in range(m):
        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: Time Limit Exceeded

Solution code:

def main():
    n = list(map(int, input().split()))
    N, M = n[0], n[1]

    import numpy as np

    M_list = []
    y_array = np.array([[10000000000]*M]*N)
    for i in range(M):
        tmp = list(map(int, input().split()))
        M_list.append(tmp[0])
        y_array[tmp[0]-1,i] = tmp[1]

    num_array = np.zeros([N,M])
    ynum_array = np.ones([N,M])

    a = np.argsort(y_array, axis=1)
    for k in range(N):
        tmp = 1
        for l in a[k]:
            #print(int(y_array[k][l]))
            if int(y_array[k][l]) == 10000000000:
                #print('break')
                break
            ynum_array[k][l] = tmp
            tmp += 1

    for j in range(M):
        ac = (str(M_list[j]).zfill(6)) + (str(int(ynum_array[M_list[j]-1][j])).zfill(6))
        print(ac)
        
    #print(y_array)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
p = [0] * m
y = [0] * m

d = {}

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

    if not p[i] in d:
        d[p[i]] = []

    d[p[i]].append(y[i])

for v in d.values():
    v.sort()

for i in range(m):
    print("{:06}{:06}".format(p[i], d[p[i]].index(y[i]) + 1))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, m = (int(i) for i in input().split())
py = [[int(i) for i in input().split()] for j in range(m)]
pre = {}
for i in range(m):
    cur_p = py[i][0]
    curlist = pre.get(cur_p,[])
    curlist.append([py[i][1],i])
    curlist.sort()
    pre[cur_p] = curlist

city_nums = []
for i in range(m):
    p = py[i][0]
    x = 0
    p_list = pre[p]
    for j in range(len(p_list)):
        if p_list[j][1] == i:
            x = j+1
    ans = "{:0>6d}".format(p)+"{:0>6d}".format(x)
    city_nums.append(ans)
    
for c_n in city_nums:
    print(c_n)