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()))
prefecture = {}
out = [[] for i in range(m)]

for i in range(m): # p=県 y=年
  p, y = list(map(int,input().split()))
  prefecture[str(i)] = [y, p]
sorted_prefecture2 = sorted(prefecture.items(), key=lambda x: x[1][0])
for i in range(n):
    if len(['x' for y in range(m) if sorted_prefecture2[y][1][1]==i+1])>=1:
        count = 0
        for y in range(m):
            if sorted_prefecture2[y][1][1]==i+1:
                count += 1
                out[int(sorted_prefecture2[y][0])] = ('{}{}'.format((6-len(str(sorted_prefecture2[y][1][1])))*'0'+str(sorted_prefecture2[y][1][1]),(6-len(str(count)))*'0'+str(count)))
for i in range(m):
    print(out[i])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from scipy.stats import rankdata
n, m = map(int, input().split())
citys = []

for i in range(m):
    citys.append(list(map(int, input().split())))

# print(list(citys))
ids = []
for i in range(m):
    ids.append([])
# print(ids)
for i in range(1, n + 1):
    rank = [[], []]
    for j in range(m):
        if citys[j][0] == i:
            rank[0].append(citys[j][1])
            rank[1].append(j)
    ranken = rankdata(rank[0])
    for j in range(len(ranken)):
        ids[rank[1][j]] = int(ranken[j])
# print(ids)

for i in range(len(ids)):
    zero1 = 6 - len(str(citys[i][0]))
    # print(zero1)
    zero2 = 6 - len(str(ids[i]))
    print('0'*zero1+str(citys[i][0])+'0'*zero2+str(ids[i]))

Submission status: Time Limit Exceeded

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

Prenum = [[] for i in range(N)]
PreYear = []
PY = [input().split(' ') for i in range(M)]

for i in range(M):
    Pi, Yi = map(int,PY[i])
    Prenum[Pi-1].append(i)

    count = 1
    for i in range(len(Prenum[Pi-1])-1):
        if int(PY[Prenum[Pi-1][i]][1]) > Yi:
            PreYear[Prenum[Pi-1][i]] += 1
        elif int(PY[Prenum[Pi-1][i]][1]) < Yi:
            count +=1 
    PreYear.append(count)

for i in range(M):
    Pi, Yi = map(int,PY[i])
    print('{0:06d}{1:06d}'.format(Pi,PreYear[i]))

Submission status: Time Limit Exceeded

Solution code:
a = input().split()
b = []
for i in range(int(a[1])):
  c = input().split()
  b.append(c)

for i, j in b:
    posi = 1
    for k, l in b:
        if int(i) == int(k):
            if int(j) > int(l):
                posi+=1
    print(i.zfill(6) + str(posi).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import bisect
N, M = map(int, input().split())
P, Y = [], []
pref = [[] for _ in range(N+1)] # non-0-indexed
for m in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
    bisect.insort(pref[p], y)

ans = []   
for p,y in zip(P,Y):
    a = "{:0>6}".format(p)
    i = bisect.bisect(pref[p], y)
    a += "{:0>6}".format(i)
    ans.append(a)

for a in ans:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
import copy

N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]
S = copy.deepcopy(L)
S.sort()
A = [[] for i in range(N)]
k = 0
j = 1
while (k < M):
  if (S[k][0] == j):
    A[j-1].append(S[k][1])
    k += 1
  else:
    j = S[k][0]
    A[j-1].append(S[k][1])
    k += 1     
for i in range(M):
  if (L[i][1] in A[L[i][0]-1]):
    print(str('0'*(6-len(str(L[i][0]))))+str(L[i][0])+str('0'*(6-len(str(A[L[i][0]-1].index(L[i][1])+1))))+str(A[L[i][0]-1].index(L[i][1])+1))

Submission status: Time Limit Exceeded

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

prefecture=[[] for j in range(n)]
for i in range(m):
    prefecture[p[i]-1].append(y[i])

for j in range(n):
    prefecture[j].sort()

# for j in range(n):
#     city=[] # number
#     for i in range(m):
#         if(p[i]==j+1):
#             city.append(y[i])
#     city.sort()
#     prefecture.append(city)

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

Submission status: Time Limit Exceeded

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

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

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

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

for p2 in pp:
    p2.sort()

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

Submission status: Time Limit Exceeded

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

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

for i in range(M):
    p, y = map(int, input().split())
    p_list.append(p)
    y_list.append(y)
    if p in shi_map:
        shi_map[p].append(y)
    else:
        shi_map[p] = [y]
shi_map2 = {}
for k, v in shi_map.items():
    v = sorted(v)
    shi_map2[k] = v

for i in range(M):
    p = p_list[i]
    y = y_list[i]
    j = shi_map2[p].index(y)
    p_str = str(p).zfill(6)
    j_str = str(j+1).zfill(6)
    print(p_str + j_str)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
cities = {}
P = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = (p,y)
    if not p in P:
        P[p] = [y]
    else:
        P[p].append(y)

sorted_P = {p:sorted(P[p]) for p in P}

for i in range(M):
    city_p, city_y = cities[i]
    x = sorted_P[city_p].index(city_y)+1
    print('{0:06}{1:06}'.format(city_p, x))

Submission status: Time Limit Exceeded

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

for i in range(M):
    tmp[F[i][0]-1].append(F[i][1])

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

Submission status: Time Limit Exceeded

Solution code:
N, M =map(int, input().split())
Ps =[]
Ys =[]
dic = {}
for i in range(M):
    p, y = map(int, input().split())
    Ps.append(p)
    Ys.append(y)
    ls = dic.get(p, [])
    ls.append(y)
    dic[p] = ls
for i in range(M):
    p = Ps[i]
    y = Ys[i]
    ls = dic[p]
    ls.sort()
    number = ls.index(y) + 1
    strp = str(p)
    strn = str(number)
    print(strp.zfill(6) + strn.zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
import collections
import itertools
a = list(map(int,input().split()))
n = a[0]
m = a[1]
li = []
results = {}
for i in range(m):
    l = list(map(int,input().split()))
    results.setdefault(l[0], []).append(l[1])
    li.append(l)
re = {}
for key, value in results.items():
    re[key] = sorted(value)
for i in li:
    years = re[i[0]]
    co = 0
    for j in years:
        co += 1
        if j == i[1]:
            print("{0:06d}".format(i[0]) + "{0:06d}".format(co))

Submission status: Time Limit Exceeded

Solution code:


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

PY = []
P_Y = [[] for i in range(N)]


for i in range(M):
    p,y = list(map(int,input().split()))
    P_Y[p-1].append(y)
    PY.append([p,y])
    
import numpy as np

P_Y_arg = [[] for i in range(N)]
for i in range(N):
    pys=list(np.sort(P_Y[i]))
    for y in P_Y[i]:
        
        P_Y_arg[i].append(pys.index(y))
    
p_count = [0 for i in range(N)]

for i in range(M):
    ps = str(1000000+PY[i][0])
    ys = str(1000000+P_Y_arg[PY[i][0]-1][p_count[PY[i][0]-1]] + 1)
    p_count[PY[i][0]-1]+=1
    print(ps[1:]+ys[1:])

Submission status: Time Limit Exceeded

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

P=[]
Y=[]
for i in range(M):
	P_tmp,Y_tmp = map(int, raw_input().split())
	P.append(P_tmp)
	Y.append(Y_tmp)

S={}

for i in Y:
	key = str(P[Y.index(i)]) + "_"
	#print "key: "+key
	try:
		S[key]
	except:
		S[key]=[]
	S[key].append(i)

for i in S.keys():
	S[i]=sorted(S[i])

#print S

for i in Y:
	key = str(P[Y.index(i)]) + "_"
	print "{0:06d}".format(P[Y.index(i)]) + "{0:06d}".format(S[key].index(i)+1)

Submission status: Time Limit Exceeded

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

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

_P = list(map(lambda x: sorted(x), _P))

for x in range(M):
	n = _P[P[x]-1].index(Y[x])
	print( str('{0:06d}'.format(P[x]))+str('{0:06d}'.format(n+1)) )

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, raw_input().split())
D = []
SD = {}
for i in range(M):
	p, y = map(int, raw_input().split())
	D.append([p, y, i])
	if not p in SD.keys():
		SD[p] = []
	SD[p].append([y, i])
C = [1] * (M + 1)
P = {}
for pref in SD.keys():
	sd = sorted(SD[pref], key = lambda x: x[0])
	for year, city in sd:
		if not pref in P.keys():
			P[pref] = 1
		else:
			P[pref] += 1
		C[city] = P[pref]
for i in range(M):
	print "%06d%06d" % (D[i][0], C[i])

Submission status: Time Limit Exceeded

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

Indexs = []
Syuturyoku = []


for j in range(N):
	P.append([0])


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

	P[p-1].append(y)
	Indexs.append(y)
	Syuturyoku.append(("0","0"))

for i in range(len(P)):
	P[i].sort()
	P[i] = list(map(str,P[i]))


for i in range(len(P)):
	if(len(P[i])>1):
		for j in range(len(P[i])-1):
			atai = P[i][j+1]
			si = i+1
			si = str(si)
			x = j+1
			x = str(x)
			bangou = list(map(str,si))
			bangou_len = int(len(bangou))
			bangou_ushiro = list(map(str,x))
			bangou_ushiro_len = int(len(bangou_ushiro))
			if(len(bangou)<6):
				for zero in range(6-bangou_len):
					bangou.insert(0,'0')
			if(len(bangou_ushiro)<6):
				for zero in range(6-bangou_ushiro_len):
					bangou_ushiro.insert(0,'0')

			mojiretsu = ''
			for k in bangou:
				mojiretsu += k
			mojiretsu2 = ''
			for k2 in bangou_ushiro:
				mojiretsu2 += k2

			a = Indexs.index(int(atai))
			Syuturyoku[a] = (mojiretsu,mojiretsu2)
for i in range(M):
	print(Syuturyoku[i][0]+Syuturyoku[i][1])

Submission status: Time Limit Exceeded

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

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

for i in range(M):
    p, y = map(int, input().split())
    p_list.append(p)
    y_list.append(y)
    if p in shi_map:
        shi_map[p].append(y)
    else:
        shi_map[p] = [y]
shi_map = sorted(shi_map.items(), key=lambda x: x[0])
shi_map = dict(shi_map)
shi_map2 = {}
for k, v in shi_map.items():
    v = sorted(v)
    shi_map2[k] = v

for i in range(M):
    p = p_list[i]
    y = y_list[i]
    j = shi_map2[p].index(y)
    p_str = str(p).zfill(6)
    j_str = str(j+1).zfill(6)
    print(p_str + j_str)

Submission status: Time Limit Exceeded

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

for pi,pj in e:
    t = [yj for pj,yj in e if(pj == pi)]
    t.sort()
    print('{0:06d}'.format(pi)+'{0:06d}'.format(t.index(pj)+1))

Submission status: Time Limit Exceeded

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

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

for o in O:
    o.sort()

for i,p in enumerate(P):
    s = (6 - len(str(p))) * "0"
    s += str(p)
    s += (6 - len(str((O[p-1].index(Y[i])) + 1))) * "0"
    s += str((O[p-1].index(Y[i])) + 1)
    print( s )

Submission status: Time Limit Exceeded

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

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

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

for i in da:
    i.sort()

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

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

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

    print(n+m)

Submission status: Time Limit Exceeded

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

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

pp = []
for _ in range(N):
    pp.append([])

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

for p2 in pp:
    p2.sort()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
#import numpy as np
def argsort_p1(ls):
    return [sorted(ls).index(t)+1 for t in ls]

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

for m in range(M):
    p,y = list(map(int,input().split()))
    P.append(p)
    Y.append(y)
#print (P,Y)
ls = [ [] for _ in range(max(P))]
temp = [ [] for _ in range(max(P))]
ls_idx = []
#print (ls)
for p,y in zip(P,Y):
    ls[p-1].append(y)
    ls_idx.append(len(temp[p-1]))
    temp[p-1].append(len(temp[p-1]))
#print (ls_idx)
#ls_dict = []
# ls_arg_line = []
# for line in ls:
#
#     ls_arg_line.append(argsort_p1(line))
ls_arg_line = [argsort_p1(line) for line in ls]
for i,(p,y) in enumerate(zip(P,Y)):
    #print (i,p,y)
    print (str(p).zfill(6)+str(ls_arg_line[p-1][ls_idx[i]]).zfill(6))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

P=[]
Y=[]
for i in range(M):
	P_tmp,Y_tmp = map(int, raw_input().split())
	P.append(P_tmp)
	Y.append(Y_tmp)

S={}

for i in Y:
	key = str(P[Y.index(i)]) + "_"
	#print "key: "+key
	try:
		S[key]
	except:
		S[key]=[]
	S[key].append(i)

for i in S.keys():
	S[i]=sorted(S[i])

#print S

for i in Y:
	key = str(P[Y.index(i)]) + "_"
	print "{0:06d}".format(P[Y.index(i)]) + "{0:06d}".format(S[key].index(i)+1)

Submission status: Time Limit Exceeded

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

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

_P = [[] for i in range(N)]
for i, p in enumerate(P):
	_P[p-1].append(Y[i])

_P = list(map(lambda x: sorted(x), _P))

for x in range(M):
	n = _P[P[x]-1].index(Y[x])
	print( str('{0:06d}'.format(P[x]))+str('{0:06d}'.format(n+1)) )

Submission status: Time Limit Exceeded

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

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

for i in PY:
    print('{:06}'.format(i[0]), end='')
    print('{:06}'.format(sorted(array[i[0]-1]).index(i[1])+1))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, M = map(int, input().split())
    P = []
    Y = []
    for _ in range(M):
        pi, yi = [int(i) for i in input().split()]
        P.append(pi)
        Y.append(yi)
    temp_dict = {}
    for i in range(N):
        temp_list = [Y[k] for k, x in enumerate(P) if x == i+1]
        temp_list.sort()
        for i in range(len(temp_list)):
            temp_dict[str(temp_list[i])] = i+1

    for i in range(M):
        print(str(P[i]).zfill(6) + str(temp_dict[str(Y[i])]).zfill(6))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
YL = [[int(i) for i in input().split()] + [j] for j in range(M)]
SORT = sorted(YL)

for i in range(1,N+1):
    ct = 1
    for j in SORT:
        if j[0] == i:
            j.append('{:0=6}'.format(i))
            j.append('{:0=6}'.format(ct))
            ct += 1
        else:
            continue
SORT.sort(key=lambda x:x[2])
for i in SORT:
    print('%s%s' % (i[3], i[4]))

Submission status: Time Limit Exceeded

Solution code:
import bisect
N, M = map(int, input().split())
P, Y = [], []
pref = [[] for _ in range(N+1)] # non-0-indexed
for m in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
    bisect.insort(pref[p], y)

    
for p,y in zip(P,Y):
    ans = "{:0>6}".format(p)
    i = bisect.bisect(pref[p], y)
    ans += "{:0>6}".format(i)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from queue import PriorityQueue

PREFEC, CITIES = list(map(int, stdin.readline().split()))
pref = {key: PriorityQueue() for key in range(1, PREFEC+1)}
city = dict()
out = [0] * CITIES
for i in range(CITIES):
    p, c = list(map(int, stdin.readline().split()))
    pref[p].put(c)
    dic = str(p) + '0' + str(c)
    city[dic] = i

for i in pref:
    pref_index = 1
    while not pref[i].empty():
        sp = str(i)
        si = str(pref[i].get())
        sy = str(pref_index)
        temp = sp + '0' + si
        index = city[temp]

        out[index] = sp.zfill(6) + sy.zfill(6)

        pref_index += 1

for o in out:
    print(o)

Submission status: Time Limit Exceeded

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

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

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

pp = []
for o in range(N):
    pp.append([])

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

for p2 in pp:
    p2.sort()

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

Submission status: Time Limit Exceeded

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

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

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

for prefecture, year in tmp:
    text = ""
    text += "%06d" % prefecture
    text += "%06d" % (PY[prefecture].index(year) + 1)
    print(text)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict as dict
d = dict(int)

N, M = map(int,input().split())
A = [list(map(int,input().split())) for z in range(M)]
a = sorted(A)
b = [[0, 0] for z in range(M + 1)]
for i in range(1, M + 1):
    x, y = a[i - 1]
    if b[i - 1][0] != x:
        cnt = 1

    b[i] = [x, str(x).zfill(6) + str(cnt).zfill(6)]
    cnt += 1

for j in range(M):
    print(b[a.index(A[j]) + 1][1])

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a = [[] for _ in range(n)]
b = []
for i in range(m):
    s, t = map(int, input().split())
    a[s-1].append(t)
    a[s-1].sort()
    b.append((s, t))

for i in range(m):
    s, t = b[i][0], b[i][1]
    u = str(a[s-1].index(t)+1)
    print("0"*(6-len(str(s))) + str(s) + "0"*(6-len(u)) + u)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def zeroume(a, b):
    a, b = str(a), str(b)
    txt = ""
    for _ in range(6 - len(a)):
        txt += "0"
    txt += a
    for _ in range(6 - len(b)):
        txt += "0"
    txt += b
    return txt

if __name__ == "__main__":
    dum = list(map(int, input().split()))
    n, m = dum[0], dum[1]

    whole = [0. for _ in range(m)]
    keyset = set()
    keys = []
    values = []
    for i in range(m):
        dum = list(map(int, input().split()))
        whole[i] = dum

        n_dum, m_dum = dum[0], dum[1]
        if n_dum in keyset:
            num = keys.index(n_dum)
            values[num].append(m_dum)

        else:
            keyset.add(n_dum)
            keys.append(n_dum)
            values.append([m_dum])

    for i in range(len(values)):
        values[i] = sorted(values[i])

    for i in range(m):
        n_dum, m_dum = whole[i][0], whole[i][1]
        print(zeroume(n_dum, values[keys.index(n_dum)].index(m_dum)+1))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
N, M = map(int, input().split())
P_list = []
Y_list = []
num_list = []
for i in range(M):
    P, Y = map(int, input().split())
    P_list.append(P)
    Y_list.append(Y)

# print(P_list)
# print(Y_list)
for i in range(M):
    p = P_list[i]
    y = Y_list[i]
    list2 = [j for j, x in enumerate(P_list) if x == p] #県が同じ市のリスト
    # list2 = P_list.index(p)
    # print(list2)
    # same_pref = []
    # for j in range(len(list2)):
    #     same_pref.append(Y_list[list2[j]])
    same_pref = [Y_list[i] for i in list2]
    # print(same_pref) #県が同じ市の年のリスト
    same_pref_sort = sorted(same_pref) #昇順、古い順に並び替え
    # print(same_pref_sort)
    # print(y)
    num = same_pref_sort.index(y)+1 #何番目か
    # print(num)
    num_list.append(num)
    str1 = '{0:06d}'.format(P_list[i])
    str2 = '{0:06d}'.format(num)
    print(str(str1)+str(str2))

Submission status: Time Limit Exceeded

Solution code:
def solve(N, M, arr):
  ans = []
  P_dict = []
  for i in range(N):
    li = sorted(list(map(lambda n: n[1], list(filter(lambda n: n[0] == (i + 1), arr)))))
    P_dict.append({k: v for v, k in enumerate(li)})
  for i in range(M):
    P, Y = arr[i]
    pre = str(P).zfill(6)
    suf = str(P_dict[P-1].get(Y) + 1).zfill(6)
    ans.append(pre + suf)
  
  # Output according to format
  ans = '\n'.join(ans)
  return ans

# receive inputs
N, M = list(map(int, input().split()))
arr = [list(map(int, input().split())) for i in range(M)]

# print outputs
print(solve(N, M, arr))

Submission status: Time Limit Exceeded

Solution code:
N,M = input().strip().split(' ')
pairs=[]
answers=[]
for i in range(int(M)):
    pre,year = input().strip().split(' ')
    pairs.append([i,int(pre),int(year)])
    #print(pairs)

pairs_sort=sorted(pairs, key=lambda x:(x[1],x[2]))

for i in range(int(N)+1):
    count=1
    lst = [hoge for hoge in pairs_sort if hoge[1] == i]
    for j in range(len(lst)):
        answers.append([lst[j][0],'0'*(6-len(str(lst[j][1])))+str(lst[j][1]),'0'*(6-len(str(count)))+str(count)])
        count=count+1

answers_sort=sorted(answers, key=lambda x:x[0])
for hoge in answers_sort:
    print(hoge[1]+hoge[2])

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import insort,bisect_left
input_lines = sys.stdin.readlines()
N,M = map(int,input_lines[0].split())
PY = [list(map(int,input_lines[i+1].split())) for i in range(M)]

d = {}

for py in PY:
    tmp = d.get(py[0],[])
    insort(tmp,py[1])
    d[py[0]] = tmp

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

    print(s1+s2)

Submission status: Time Limit Exceeded

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

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

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

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

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

Submission status: Time Limit Exceeded

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

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

for i,p in enumerate(P):
    s = (6 - len(str(p))) * "0"
    s += str(p)
    s += (6 - len(str((O[p-1].index(Y[i])) + 1))) * "0"
    s += str((O[p-1].index(Y[i])) + 1)
    print( s )

Submission status: Time Limit Exceeded

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

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

pp = []
for o in range(N):
    pp.append([])

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

for p2 in pp:
    p2.sort()

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

Submission status: Time Limit Exceeded

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

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


for i in range(n):
  years[i].sort()

for i in range(m):
  print("{0:06d}".format(yearss[i][0]),"{0:06d}".format(int(years[yearss[i][0]-1].index(yearss[i][1]))+1),sep="")

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
list_p = [[] for i in range(1, N + 1)]
order = []
for _ in range(M):
    p, y = map(int, input().split())
    list_p[p-1].append(y)
    order.append((p, y))
list_p2 = [sorted(k) for k in list_p]
for p, y in order:
    print('{:0=6}'.format(p) + '{:0=6}'.format(list_p2[p-1].index(y) + 1))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

prefecture=[]
for j in range(n):
    city=[] # number
    for i in range(m):
        if(p[i]==j+1):
            city.append(y[i])
    city.sort()
    prefecture.append(city)

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

Submission status: Time Limit Exceeded

Solution code:
import copy

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


p = [0] * m
y = [0] * m

kuni = [[] for i in range(n)]
count = [0] * n

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

ids = [[] for i in range(n)]

for i in range(n):
  ken = kuni[i]
  sorted_ken = copy.deepcopy(ken)
  sorted_ken.sort()
  ken_id = [0] * len(ken)
  for j in range(0, len(ken)):
    for k in range(0, len(sorted_ken)):
      if ken[j] == sorted_ken[k]:
        ken_id[j] = k + 1

  ids[i] = ken_id

for i in range(0, m):
  ken = p[i]
  print(str(ken).zfill(6) + str(ids[ken - 1][count[ken - 1]]).zfill(6))
  count[ken - 1] += 1

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int,input().split())
xs = [0]*m
pre = [0]*m
for x in range(m):
    xs[x] = list(list(map(int,input().split())) + [x] + [x])
xs.sort()

for p in range(1,n+1):
    cnt = 1
    for x in xs:
        if x[0] == p:
            x[3] = cnt
            cnt += 1

for x in sorted(xs, key=lambda x:x[2]):
    print('{0:06d}'.format(x[0]) + '{0:06d}'.format(x[3]))

Submission status: Time Limit Exceeded

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

sum = 0
y_tmp = list([] for i in range(n))
y_sort = list([] for i in range(n))

for i in range(m):
    y_tmp[p[i]-1].append(y[i])
    sum+=1
    if sum == m:
        break

for i in range(n):
    y_sort[i] = sorted(y_tmp[i])


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

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
l1=list()
for i in range(M):
   l1x=list(map(int,input().split()))
   l1.append(l1x)
l2=l1.copy()
l2.sort()
x=1
l31="{0:06d}".format(l2[0][0])+"{0:06d}".format(x)
l3=[l31]
for i in range(1,M):
   if l2[i-1][0]==l2[i][0]:
      x+=1
      l3x="{0:06d}".format(l2[i][0])+"{0:06d}".format(x)
      l3.append(l3x)
      
   else:
      x=1
      l3x="{0:06d}".format(l2[i][0])+"{0:06d}".format(x)
      l3.append(l3x)

for i in range(M):
   li=l2.index(l1[i])
   print(l3[li])

Submission status: Time Limit Exceeded

Solution code:
ken_data = {}
inputShiList = []
inputYList = []

N, M =  [int(i) for i in input().split()]
for i in range(M) :
    Pi, Yi = [int(j) for j in input().split()]
    inputShiList.append((Pi, Yi))
    if Pi not in ken_data :
        ken_data[Pi] = []
    ken_data[Pi].append(Yi)


for key in ken_data :
    ken_data[key] = sorted(ken_data[key])
    
for shi in inputShiList :
    print('{:0=6}{:0=6}'.format(shi[0],ken_data[shi[0]].index(shi[1])+1))