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 = list(map(int, input().split()))
temp = [list(map(int, input().split())) for i in range(M)]
temp = list(zip(*temp))
P, Y = temp
#print(P, Y)
data = dict()
for p, y in zip(P, Y):
  if p not in data:
    data[p] = [y]
  else:
    data[p].append(y)
    
for i in data.keys():
  data[i] = sorted(data[i])
  
for p, y in zip(P, Y):
  print("{:06}{:06}".format(p, data[p].index(y)+1))

Submission status: Time Limit Exceeded

Solution code:
# coding : UTF-8
N,M = map(int,input().split())

PM_list = [ input() for _ in range(M) ]
PM_list = [ list(map(int,_.split(" "))) for _ in PM_list]
PM_dict = {}

for i in PM_list:
    if i[0] in PM_dict:
        PM_dict[i[0]].append(i[1])
    else:
        PM_dict[i[0]] = [i[1]]

for j in PM_dict:
    PM_dict[j].sort()

for k in PM_list:
    print("{}{}".format(str(k[0]).zfill(6),str(PM_dict[k[0]].index(k[1])+1).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8
from copy import deepcopy
def main():
	N, M = map(int, input().split())
	p_list = []
	p_dict = {}
	for i in range(M):
		p, y = map(int, input().split())
		p_list.append([p, y])
		if p not in p_dict.keys():
			p_dict[p] = [y]
		else:
			p_dict[p].append(y)
	for p in p_dict.keys():
		p_dict[p].sort()
	for i in range(M):
		s1 = p_list[i][0]	
		#s1 = str(p_list[i][0])
		s2 = p_dict[p_list[i][0]].index(p_list[i][1])
		print("{:06d}{:06d}".format(s1, s2+1))
		#print("0" * (6 - len(str(s1))) + str(s1) + "0" * (6 - len(str(s2))) + str(s2 + 1))
	#print(p_dict)
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

prefs_list = []
prefs_dict = {}
for i in range(m):
  p, y = map(int, input().split())
  prefs_list.append([p,y])
  if p in prefs_dict:
    prefs_dict[p].append(y)
  else:
    prefs_dict[p] = [y]

for key in prefs_dict:
  prefs_dict[key].sort()

for pref in prefs_list:
  print(str(pref[0]).zfill(6) + str(prefs_dict[pref[0]].index(pref[1])+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    for i in range(M):
        city_list.append(list(map(int, input().split())))
    pref = {}
    pref_sort = {}
    for i in range(N):
        pref[str(i+1)] = []
        pref_sort[str(i+1)] = []
    for i in range(M):
        pref[str(city_list[i][0])].append(city_list[i][1])
    for i in range(N):
        pref[str(i+1)].sort()
    for i in range(M):
        key = city_list[i][0]
        val = city_list[i][1]
        output = str(key).zfill(6) + str(pref[str(key)].index(val)+1).zfill(6)
        print(output)

Submission status: Time Limit Exceeded

Solution code:
def makeID(p, y):
    p_s = str(p)
    while len(p_s) < 6:
        p_s = '0' + p_s
    y_s = str(y+1)
    while len(y_s) < 6:
        y_s = '0' + y_s

    print(p_s + y_s)

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

P = [0]*M
Y = [0]*M
ID = [[] for i in range(N)]
indx = [[0, 0] for i in range(M)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    ID[P[i] - 1].append(Y[i])
    indx[i][0] = P[i]
    indx[i][1] = Y[i]



for i in range(N):
    ID[i].sort()

for i in range(M):
    makeID(indx[i][0], ID[indx[i][0]-1].index(indx[i][1]))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
City = []
for i in range(M):
	c = list(map(int, input().split()))
	c.append(0)
	City.append(c)
for i in range(N):
	yrs = []
	for j in City:
		if j[0] == i + 1:
			yrs.append(j[1])
	yrs.sort()
	for j in City:
		if j[0] == i + 1:
			j[2] = yrs.index(j[1]) + 1
for i in City:
	ID = ("0" * 6 + str(i[0]))[-6:] + ("0" * 6 + str(i[2]))[-6:]
	print(ID)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
City = []
for i in range(M):
	c = list(map(int, input().split()))
	c.append(0)
	City.append(c)
for i in range(N):
	l = []
	for j in City:
		if j[0] == i + 1:
			l.append(j[1])
	l.sort()
	for j in City:
		if j[0] == i + 1:
			j[2] = l.index(j[1]) + 1
for i in City:
	ID = ("0" * 6 + str(i[0]))[-6:] + ("0" * 6 + str(i[2]))[-6:]
	print(ID)

Submission status: Time Limit Exceeded

Solution code:
import sys

r=int(input().split()[0])
l=[x.strip() for x in sys.stdin.readlines()]

cty=[{"p":int(x.split()[0]),"y":int(x.split()[1])} for x in l]
for i in range(len(cty)):
    cty[i]["n"]=i
    
ans=[]
ap=set([x["p"] for x in cty])

for n in ap:
    prf=[x for x in cty if x["p"]==n]
    if prf:
        p=sorted(prf, key=lambda x: x["y"])
        num=0
        for i in p:
        
            num+=1
            ans.append([i["n"],"{0}{1}".format(str(n).zfill(6),str(num).zfill(6))])


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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

r=int(input().split()[0])
l=[x.strip() for x in sys.stdin.readlines()]

cty=[{"p":int(x.split()[0]),"y":int(x.split()[1])} for x in l]
for i in range(len(cty)):
    cty[i]["n"]=i
    
ans=[]
    
for n in range(r):
    prf=[x for x in cty if x["p"]==n+1]
    if prf:
        p=sorted(prf, key=lambda x: x["y"])
        num=0
        for i in p:
        
            num+=1
            ans.append([i["n"],"{0}{1}".format(str(i["p"]).zfill(6),str(num).zfill(6))])

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

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

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
cs = []
ps = {}
for _ in range(m):
  p, y = map(int, input().split())
  cs.append([y, p])
css = sorted(cs)
for c in css:
  if c[1] in ps:
    ps[c[1]].append(c[0])
  else:
    ps[c[1]] = [c[0]]
[print('{:06}{:06}'.format(c[1], ps[c[1]].index(c[0])+1))for c in cs]

Submission status: Time Limit Exceeded

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

pref_list = list()
jyunban = list()

for i in range(n):
    pref_list.append(list())
    
for i in range(m):
    p,y = map(int,input().split())
    pref_list[p-1].append(y)
    jyunban.append([p,y])
    
for pref in pref_list:
    pref.sort()

for pref,year in jyunban:
    index = pref_list[pref-1].index(year) + 1
    pref = str(pref).rjust(6,'0')
    index = str(index).rjust(6,'0')
    print(pref+index)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(list(map(int,input().split())))
asd=a[:]
asd.sort(key=lambda x:x[1])
asd.sort(key=lambda x:x[0])
keep,ki=0,1
for i in asd:
    if keep==i[0]:ki+=1
    else:keep,ki=i[0],1
    a[a.index(i)]=str(i[0]).zfill(6)+str(ki).zfill(6)
for i in a:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
PY = []
for i in range(M):
    PY.append(list(map(int, input().split())))
    
def kansu(a, ans):
    if a in ans:
        temp = int(a[6:])
        temp += 1
        temp = str(temp).zfill(6)
        b = a[:6] + temp
        response = kansu(b, ans)
    else:
        response = a
    return response
    
    
sort_PY = sorted(PY, key=lambda x: x[1])
ans = [""] * M
for i, j in enumerate(sort_PY):
    
    for k, l in enumerate(PY):
        if sort_PY[i][1] == PY[k][1]:
            index = k
        
    a = str(sort_PY[i][0]).zfill(6) + str(1).zfill(6)
    response = kansu(a, ans)
    ans[index] = response
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
PY = []
C = []
D = []

for i in range(1,M+1):
    A = list(map(int, input().split()))
    A.append(i)
    PY.append(A)
# PY = [[P1,Y1,1],[P2,Y2,2],[P3,Y3,3],...,[Pn,Yn,n]]

for i in range(1,N+1):
    B = []
    for j in range(M):
        if PY[j][0] == i:
            XYZ = PY[j][1:]+[i]
            B.append(XYZ)
    B = sorted(B)
    len_b = len(B)
    for x in range(len_b):
        B[x].append(x+1)
    P = str(i)
    len_P = len(P)
    a = 6-len_P
    for k in range(len_b):
        order = str(k+1)
        len_o = len(order)
        b = 6-len_o
        C = [B[k][1],"0"*a+P+"0"*b+order]
        D.append(C)
D = sorted(D)
for i in range(M):
    print(D[i][1])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
PY = [[int(i) for i in input().split()]for i in range(M)]
l = [[] for i in range(N+1)]
for p,y in PY:
    l[p].append(y)
for i in range(N+1):
    l[i].sort()
for p,y in PY:
    print(str(p).zfill(6),end="")
    print(str(l[p].index(y)+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
pys = [list(map(int, input().split())) for _ in range(m)]
map_ = {}
for i, (p, y) in enumerate(pys):
    map_.setdefault(p, [])
    for j in range(len(map_[p])):
        if y < pys[map_[p][j]][1]:
            map_[p].insert(j, i)
            break
    else:
        map_[p].append(i)
ans = [None] * m
for key, val in map_.items():
    for num, i in enumerate(val):
        ans[i] = '{:06d}'.format(key) + '{:06d}'.format(num + 1)
for a in ans:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
prefecture, city = map(int, input().split(' '))
dic_cities = {}
born_ls = []
for i in range(1, prefecture + 1):
    dic_cities[i] = list()
for i in range(0, city):
    pre, born = map(int, input().split(' '))
    born_ls.append([pre, born])
    dic_cities[pre].append(born)
    
for i in dic_cities.keys():
    dic_cities[i] = sorted(dic_cities[i])

for input_info in born_ls:
    for i in range(0, len(dic_cities[input_info[0]])):
        if dic_cities[input_info[0]][i] == input_info[1]:
            print("{:06}{:06}".format(input_info[0], i + 1))

Submission status: Time Limit Exceeded

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

for i in range(M):
  y_index = P_Y[P[i]].index(Y[i])
  p = str(str(P[i]+1).zfill(6))
  y = str(str(y_index+1).zfill(6))
  ans = p+y
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
Ps = []
Ys = []
l = [[] for _ in range(N)]
for _ in range(M):
    P_i, Y_i = map(int, input().split())
    Ps.append(P_i)
    Ys.append(Y_i)
    l[P_i-1].append(Y_i)
for i in range(N):
    l[i].sort()
for i in range(M):
    print("{:012}".format(Ps[i] * 1000000 + l[Ps[i]-1].index(Ys[i]) + 1))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis)
i = 1
flag = 0
for _ in lis_sort:
    if flag != _[0]:
        flag = _[0]
        i = 1
    ans_lis[lis.index(_)] = str(i)
    i += 1
for x,y in zip(lis,ans_lis):
    print('0'*(6-len(str(x[0]))),x[0],'0'*(6-len(y)),y,sep='')

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis)
i = 1
flag = 0
for _ in range(len(lis_sort)):
    if flag != lis_sort[_][0]:
        flag = lis_sort[_][0]
        i = 1
    ans_lis[lis.index(lis_sort[_])] = str(i)
    i += 1
for x,y in zip(lis,ans_lis):
    print('0'*(6-len(str(x[0]))),x[0],'0'*(6-len(y)),y,sep='')

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
flag = 0
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_pra_lis = []
ans_beh_lis = [0] * M
lis_sort = sorted(lis)
for _ in lis:
    s = str(_[0])
    ans_pra_lis.append(s)
i = 1
for _ in range(len(lis_sort)):
    if flag != lis_sort[_][0]:
        flag = lis_sort[_][0]
        i = 1
    ans_beh_lis[lis.index(lis_sort[_])] = str(i)
    i += 1
for x,y in zip(ans_pra_lis,ans_beh_lis):
    print('0'*(6-len(x)),x,'0'*(6-len(y)),y,sep='')

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
flag = 0
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_pra_lis = []
ans_beh_lis = [0] * M
lis_sort = sorted(lis)
for _ in lis:
    s = str(0)*(6-len(str(_[0]))) + str(_[0])
    ans_pra_lis.append(s)
i = 1
for _ in range(len(lis_sort)):
    if flag != lis_sort[_][0]:
        flag = lis_sort[_][0]
        i = 1
    ans_beh_lis[lis.index(lis_sort[_])] = str(0)*(6-len(str(i))) + str(i)
    i += 1
for x,y in zip(ans_pra_lis,ans_beh_lis):
    print(x,end = '')
    print(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)]
PYorder = sorted(PY)
p = 1
y = 1
List = []
for i in range(M):
  if PYorder[i][0] == p:
    List.append(p * 10 ** 6 + y)
    y += 1
  else:
    p = PYorder[i][0]
    y = 1
    List.append(p * 10 ** 6 + y)
    y += 1

for i in range(M):
  x = PYorder.index(PY[i])
  ans = List[x]
  print("{0:012d}".format(ans))

Submission status: Time Limit Exceeded

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

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())

certificate = [[] for _ in range(n)]

for i in range(m):
    certificate[p[i]-1].append(y[i])

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

for i in range(m):
    number = ""
    number += str(p[i]).zfill(6)
    number += str(certificate[p[i]-1].index(y[i])+1).zfill(6)
    print(number)

Submission status: Time Limit Exceeded

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

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())

certificate = [[] for _ in range(n)]

for i in range(m):
    for j in range(1,n+1):
        if p[i] == j:
            certificate[j-1].append(y[i])

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

for i in range(m):
    number = ""
    number += str(p[i]).zfill(6)
    number += str(certificate[p[i]-1].index(y[i])+1).zfill(6)
    print(number)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
p = []
y = []
d = {}
for n_ in range(n):
    d[n_ + 1] = []
for i in range(m):
    p_, y_ = map(int, input().split())
    p.append(p_)
    y.append(y_)
    d[p_].append(y_)
for i in d.keys():
    d[i] = sorted(d[i])
for i in range(m):
    print('{:06d}{:06d}'.format(p[i], d[p[i]].index(y[i]) + 1))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
p = []
y = []
d = {}
for i in range(m):
    p_, y_ = map(int, input().split())
    p.append(p_)
    y.append(y_)
    if p_ not in d.keys():
        d[p_] = [y_]
    else:
        d[p_].append(y_)
for i in d.keys():
    d[i] = sorted(d[i])
for i in range(m):
    print('{:06d}{:06d}'.format(p[i], d[p[i]].index(y[i]) + 1))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P_X = [None] * M
for _ in range(M):
  p, x = input().split()
  p, x = int(p), int(x)
  P_X[_] = (p, x)
  dic[p].append(x)
for key in dic:
  dic[key].sort()
for i in range(M):
  print(str(P_X[i][0]).zfill(6) + str((dic[P_X[i][0]].index(P_X[i][1]) + 1)).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P_X = []
for _ in range(M):
  p, x = map(int, input().split())
  P_X.append((p, x))
  dic[p].append(x)
for key in dic:
  dic[key] = sorted(dic[key])
for i in range(M):
  print(str(P_X[i][0]).zfill(6) + str((dic[P_X[i][0]].index(P_X[i][1]) + 1)).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())  # 複数数値入力
L = [[] for i in range(N)]
P = list()
Y = list()

for i in range(M):
    p, y = map(int, input().split())  # 複数数値入力
    P.append(p)
    Y.append(y)
    L[p - 1].append(y)

for i in range(N):
    L[i].sort()

for i in range(M):
    print('{:06}'.format(P[i]), end="")
    print('{:06}'.format(L[P[i]-1].index(Y[i])+1))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())  # 複数数値入力
L = [[] for i in range(N)]
P = list()
Y = list()

for i in range(M):
    p, y = map(int, input().split())  # 複数数値入力
    P.append(p)
    Y.append(y)
    L[p - 1].append(y)
    L[p-1].sort()

# for i in range(N):
#     L[i].sort()

for i in range(M):
    print('{:06}'.format(P[i]), end="")
    print('{:06}'.format(L[P[i]-1].index(Y[i])+1))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
ms = []
#m_id = []
for i in range(M):
    pi, mi = map(int, input().split())
    ms.append([pi, mi, i])
    #m_id.append(i)
    
ms = sorted(sorted(ms, key=lambda x: x[1]), key=lambda y: y[0])
#m_id = sorted(sorted(m_id, key=lambda x: ms[x][1]), key=lambda y: ms[y][0])

ans_list = []
cnt = 0
for j in range(M):
    if j == 0 or ms[j][0] == ms[j - 1][0]:
        cnt += 1
    else:
        cnt = 1
    num = str(ms[j][0]).zfill(6) + str(cnt).zfill(6)
    ans_list.append(num)
    
id_order = [i[2] for i in ms]
ans_list = sorted(ans_list, key=lambda z: id_order[ans_list.index(z)])

for ans in ans_list:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
cities = ([list(map(int, input().split())) for _ in range(m)])
for city in cities:
    pref = str(city[0]).zfill(6)
    same_pref = sorted([i[1] for i in cities if i[0] == city[0]])
    rank = str(same_pref.index(city[1]) + 1).zfill(6)
    print(pref + rank)

Submission status: Time Limit Exceeded

Solution code:
import sys
n,m=map(int,input().split())
l=[[int(i) for i in l.split()] for l in sys.stdin]
s=[[0] for i in range(10**5+1)]
for i in l:
  s[i[0]].append(i[1])
for i in range(len(s)):
  if len(s[i])>2:
    s[i].sort()
for i in l:
  print('{:06}{:06}'.format(i[0],s[i[0]].index(i[1])))

Submission status: Time Limit Exceeded

Solution code:
import sys
n,m=map(int,input().split())
l=[[int(i) for i in l.split()] for l in sys.stdin]
s=[[0] for i in range(10**5+1)]
for i in l:
  s[i[0]].append(i[1])
for i in range(len(s)):
  if len(s[i])>2:
    s[i].sort()
for i in l:
  print('{:0>6}{:0>6}'.format(str(i[0]),str(s[i[0]].index(i[1]))))

Submission status: Time Limit Exceeded

Solution code:
import sys
n,m=map(int,input().split())
l=[[int(i) for i in l.split()] for l in sys.stdin]
s=[[0] for i in range(10**5+1)]
for i in l:
  s[i[0]].append(i[1])
for i in range(len(s)):
  s[i].sort()
for i in l:
  print('{:0>6}{:0>6}'.format(str(i[0]),str(s[i[0]].index(i[1]))))

Submission status: Time Limit Exceeded

Solution code:
N,M = (int(x) for x in input().split())
P,Y=[],[]
ID = [0 for i in range(M)]
for i in range(M):
    p,y = (int(x) for x in input().split())
    P.append(p)
    Y.append(y)

Ys = sorted(Y)
num = [1 for i in range(N)]

for i in range(M):
    ind = Y.index(Ys[i])
    Pi = P[ind]
    ID[ind] = str(Pi).zfill(6) + str(num[Pi-1]).zfill(6)
    num[Pi-1] += 1

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

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

for i in range(1, len(l)):

  temp = sorted(l[i], key=lambda x: x[1])

  for j in range(len(temp)):
    temp[j] = [str(temp[j][0]).zfill(6), str(j+1).zfill(6), temp[j][2]]
  
  l[i] = temp

ans = reduce(lambda x, y: x + y, l[1:])

for item in sorted(ans, key=lambda x: x[2]):
  print(item[0] + item[1])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n, m = [int(x) for x in raw_input().split()]
r = defaultdict(list)
s = []
for i in range(m):
	p, y = [int(x) for x in raw_input().split()]
	s.append((p, y))
	r[p].append(y)
for _, v in r.iteritems():
	v.sort()

for t in s:
	h = r[t[0]].index(t[1]) + 1
	print "%06d%06d"% (t[0], h)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n, m = [int(x) for x in raw_input().split()]
r = defaultdict(list)
s = []
for i in range(m):
	p, y = [int(x) for x in raw_input().split()]
	s.append((p, y))
	r[p].append(y)
for k, v in r.iteritems():
	v.sort()

for t in s:
	for j in range(len(r[t[0]])):
		if r[t[0]][j] == t[1]:
			q = "0" * (6 - len(str(t[0]))) + str(t[0])
			h = "0" * (6 - len(str(j+1))) + str(j+1)
			print q + h

Submission status: Time Limit Exceeded

Solution code:
#sys.stdin.readline()
import sys
input = sys.stdin.readline

N,M = map(int,input().split())
P,Y = [],[]
P_Y = [[]*N for _ in range(N)]

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

for i in range(M):
  ID1 = "{0:06d}".format(P[i]+1)
  tmp = P_Y[P[i]].index(Y[i])
  ID2 = "{0:06d}".format(tmp + 1)
  print(ID1 + ID2)

Submission status: Time Limit Exceeded

Solution code:
#sys.stdin.readline()
import sys
input = sys.stdin.readline

N,M = map(int,input().split())
P,Y = [[0]]*M,[[0]]*M
P_Y = [[]*N for _ in range(N)]

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

for i in range(M):
  ID1 = "{0:06d}".format(P[i]+1)
  tmp = P_Y[P[i]].index(Y[i])
  ID2 = "{0:06d}".format(tmp + 1)
  print(ID1 + ID2)

Submission status: Time Limit Exceeded

Solution code:
#sys.stdin.readline()
import sys
input = sys.stdin.readline

N,M = map(int,input().split())
P = []
Y = []
P_Y = [[]*N for _ in range(N)]

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

for i in range(M):
  ID1 = "{0:06d}".format(P[i]+1)
  tmp = P_Y[P[i]].index(Y[i])
  ID2 = "{0:06d}".format(tmp + 1)
  print(ID1 + ID2)

Submission status: Time Limit Exceeded

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

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

for i in range(M):
  ID1 = "{0:06d}".format(P[i]+1)
  tmp = P_Y[P[i]].index(Y[i])
  ID2 = "{0:06d}".format(tmp + 1)
  print(ID1 + ID2)

Submission status: Time Limit Exceeded

Solution code:
from itertools import chain

n, m = map(int, input().split())
data = [ tuple(chain(list(map(int, input().split())), [i])) for i in range(m) ]

# print(data)
tmpID = [ "" for _ in range(m) ]

for i in range(n):
	tmpData = filter(lambda a: a[0] == i+1, data)
	sortByYear = sorted(tmpData, key=lambda a: a[1])

	for j, (_, _, index) in enumerate(sortByYear):
		tmpID[index] = "%06d%06d" % (i+1, j+1)


for ID in tmpID:
	print(ID)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = map(int,input().split())
P_Y_list = np.array([input().split() for _ in range(0, M)], dtype='int')
col_1 = P_Y_list[:,0]
years = [np.sort(P_Y_list[np.where(col_1==i)][:,1]) for i in set(col_1)]
for l in P_Y_list:
    #left = str(l[0]).zfill(6)
    #right = str(np.where(years[list(set(col_1)).index(l[0])]==l[1])[0][0]+1).zfill(6)
    print((str(l[0]).zfill(6))+(str(np.where(years[list(set(col_1)).index(l[0])]==l[1])[0][0]+1).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = map(int,input().split())
P_Y_list = np.array([input().split() for _ in range(0, M)], dtype='int')
years = [np.sort(P_Y_list[np.where(P_Y_list[:,0]==i)][:,1]) for i in set(P_Y_list[:, 0])]
for l in P_Y_list:
    left = str(l[0]).zfill(6)
    right = str(np.where(years[list(set(P_Y_list[:,0])).index(l[0])]==l[1])[0][0]+1).zfill(6)
    print(left+right)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
l = [tuple(map(int,input().split())) for _ in range(m)]
d = [list() for _ in range(n)]
for x in l:
  d[x[0]-1].append(x[1])
for r in d:
  r.sort()
for x in l:
  p = x[0]
  y = d[x[0]-1].index(x[1]) + 1
  print("{:06}{:06}".format(p,y))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
for i in a:
    s_a = [x for x in sorted(a) if x[0] == i[0]]
    print(str(i[0]).zfill(6) + str(s_a.index(i)+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n, m = LI()
    py = LIR(m)
    city = [[] for i in range(n)]
    for p, y in py:
        city[p-1].append(y)
        city[p-1].sort()
    for p, y in py:
        a = "00000" + str(p)
        a = a[-6:]
        b = "00000" + str(bisect.bisect_left(city[p-1],y) + 1)
        b = b[-6:]
        print(a+b)    
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n, m = LI()
    py = LIR(m)
    city = [[] for i in range(n)]
    for p, y in py:
        city[p-1].append(y)
        city[p-1].sort()
    for p, y in py:
        a = "00000" + str(p)
        a = a[-6:]
        b = "00000" + str(city[p-1].index(y) + 1)
        b = b[-6:]
        print(a+b)    
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
dic = defaultdict(list)
P, X = [], []
for _ in range(M):
  p, x = map(int, input().split())
  P.append(p)
  X.append(x)
  dic[p].append(x)
for key in dic:
  dic[key] = sorted(dic[key])
for i in range(M):
  print(str(P[i]).zfill(6) + str((dic[P[i]].index(X[i]) + 1)).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def to_str(id_1, id_2):
    s_id_1 = str(id_1)
    s_id_2 = str(id_2)
    if len(s_id_1)<6:
        s_id_1 = (6-len(s_id_1))*'0' + s_id_1
    if len(s_id_2)<6:
        s_id_2 = (6-len(s_id_2))*'0' + s_id_2
    return s_id_1+ s_id_2

N, M = map(int, input().split())
mat = [list(map(int, [i]+list(input().split()))) for i in range(M)]
mat_sort = sorted(mat, key=lambda x:x[2])
# 昇順
P_uni = sorted(list(set([x[1] for x in mat])))
count = [int(1) for i in P_uni]
id_list = [0 for i in mat_sort]
for i, mat_ in enumerate(mat_sort):
    id_1 = count[P_uni.index(mat_[1])]
    count[P_uni.index(mat_[1])] += 1
    id_list[i] = to_str(mat_[1], id_1)
id_list = np.array(id_list)
mat_sort_arr = np.array(mat_sort)
id_list = id_list[np.argsort(mat_sort_arr[:, 0])]
for id_ in id_list:
    print(id_)

Submission status: Time Limit Exceeded

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

n, m = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(m)]

pre = [[] for _ in range(n)]

for city in p:
    pre[city[0]-1].append(city[1])

for item in pre:
    item.sort()

for city in p:
    y = pre[city[0] - 1].index(city[1]) + 1
    print("{:0>6}{:0>6}".format(city[0],y))

Submission status: Time Limit Exceeded

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

n, m = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(m)]

pre = [[] for _ in range(n)]

for city in p:
    pre[city[0]-1].append(city[1])

for city in p:
    pref = "{:0>6}".format(city[0])

    years = pre[city[0] - 1]
    years.sort()
    y = years.index(city[1]) + 1

    year = "{:0>6}".format(y)
    print(pref + year)

Submission status: Time Limit Exceeded

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

n, m = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(m)]

pre = [[] for _ in range(n)]

for i in range(m):
    pre[p[i][0] - 1].append(p[i][1])

for i in range(m):
    pref = "{:0>6}".format(p[i][0])

    years = pre[p[i][0] - 1]
    years.sort()

    y = years.index(p[i][1]) + 1
    year = "{:0>6}".format(y)
    print(pref + year)