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()))
p, y = [], []

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

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

    p_city_yrs[a[0] - 1].append(a[1])
    p_city_yrs[a[0] - 1].sort()

for i in range(m):
    order = p_city_yrs[p[i] - 1].index(y[i]) + 1
    output = '%06d%06d' % (p[i], order)
    print(output)

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(atai)
			Syuturyoku[a] = (si, x)
for i in range(M):
	print('{0:06}{1:06}'.format(Syuturyoku[i][0], Syuturyoku[i][1]))

Submission status: Time Limit Exceeded

Solution code:
import bisect

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 p, y in PY:
    n = bisect.bisect_left(sorted(array[p-1]), y) + 1
    print('%06d%06d' % (p, n))

Submission status: Time Limit Exceeded

Solution code:
import sys

ary = [x.strip("\n") for x in sys.stdin.readlines()]
ary.pop(0)
pref = [int(x.split()[0]) for x in ary]
year = [int(x.split()[1]) for x in ary]

c_ids = [0] * len(pref)
pref_uniq = list(set(pref))
for p in pref_uniq:
    c_in_p = [1 if x == p else 0 for x in pref]
    c_in_p_year = [x * y for (x, y) in zip(c_in_p, year)]
    c_in_p_year_nonz = sorted([ x for x in sorted(c_in_p_year) if x != 0 ])
    c_in_p_no = [ c_in_p_year_nonz.index(x)+1 if x != 0 else 0 for x in c_in_p_year]
    for n, c in enumerate(c_in_p_no):
        if c_in_p[n] != 0:
            c_ids[n] = str(format(pref[n], '06d')) + str(format(c_in_p_no[n], '06d'))

for id in c_ids:
    print(str(id))

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)
ls = [ [] for _ in range(max(P))]
ls_idx = [ [] for _ in range(max(P))]
for p,y in zip(P,Y):
    ls[p-1].append(y)
    ls_idx[p-1].append(len(ls_idx[p-1]))
ls_dict = []
new_dict = {}
for i,line in enumerate(ls):
    arg_line = argsort_p1(line)
    for arg in arg_line:
        new_dict[str(i+1)+"/"+str(sorted(line)[arg-1])]=str(i+1).zfill(6)+str(arg).zfill(6)
for p,y in zip(P,Y):
    print (new_dict[str(p)+"/"+str(y)])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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


P = []
Y = []

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

#P = np.array(P)
Y = np.array(Y)

inds = np.argsort(Y)


result = {}
result2 = {}

for num, ind in enumerate(inds):
    if P[ind] not in result:
        result[P[ind]] = [ind]
    else:
        result[P[ind]].append(ind)

    result2[ind] = "{:0=6}".format(P[ind]) + "{:0=6}".format(result[P[ind]].index(ind)+1)


for key in range(M):
    print(result2[key])

Submission status: Time Limit Exceeded

Solution code:
import copy

n, m = input().strip().split(' ')
n, m = [int(n), int(m)]

p = []
y = []

for i in range(m):
    a, b = input().strip().split(' ')
    a, b = [int(a), int(b)]
    p.append(a)
    y.append(b)

z = copy.deepcopy(y)

for i in range(len(z)):
    for j in range(len(z)-1):
        if z[j] > z[j + 1]:
            tmp = z[j]
            z[j] = z[j + 1]
            z[j + 1] = tmp

min = []
order = []
for i in range(n):
    min.append(0)
    
for i in range(m):
    order.append(0)
    
for i in range(m):
    for j in range(m):
        if z[i] == y[j]:
            min[p[j] - 1] += 1
            order[j] = min[p[j] - 1]

def addzero(a):
    str = ''
    for i in range(6 - len(a)):
        str += '0'
    return str

for i in range(m):
    print(addzero(str(p[i])) + str(p[i]) + addzero(str(order[i])) + str(order[i]))

Submission status: Time Limit Exceeded

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

PreYear = [[] for i in range(N)]
PY = [input().split(' ') for i in range(M)]
for i in range(M):
    Pi, Yi = PY[i]
    PreYear[int(Pi)-1].append(int(Yi))
order = []
for i in range(N):
    order.append(sorted(PreYear[i]))

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

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 p, y in PY:
    print('%06d%06d' % (p, sorted(array[p-1]).index(y)+1))

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))]
ls_idx = [ [] for _ in range(max(P))]
#print (ls)
for p,y in zip(P,Y):
    ls[p-1].append(y)
    ls_idx[p-1].append(len(ls_idx[p-1]))
ls_dict = []
new_dict = {}
for i,line in enumerate(ls):
    #arg_line = np.argsort(line)+1
    arg_line = argsort_p1(line)
    #print (arg_line)
    temp_dict = dict(zip(line, arg_line))
    ls_dict.append(temp_dict)
    for arg in arg_line:
        #print (line[arg-1])
        new_dict[str(i+1)+"/"+str(sorted(line)[arg-1])]=str(i+1).zfill(6)+str(arg).zfill(6)
#print (new_dict)
#print (ls_dict)
for p,y in zip(P,Y):
#    print (str(p).zfill(6)+str(ls_dict[p-1][y]).zfill(6))
    print (new_dict[str(p)+"/"+str(y)])

Submission status: Time Limit Exceeded

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

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


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

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]
d = sorted(a)
for i in range(m):
    x = d.index(a[i])
    print('0'*(6-len(str(a[i][0]))) + str(a[i][0])\
    +'0'*(6-len(str(x-f[a[i][0]-1]+1)))\
    +str(x-f[a[i][0]-1]+1))

Submission status: Time Limit Exceeded

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

X=[]
for _ in range(M):
    a,b = input().split()
    a=int(a)
    b=int(b)
    L[a-1].append(b)
    X.append({a:b})
Y=[ (sorted(L[_])) for _ in range(N) ]
for i in range(M) :
    for k,v in X[i].items():
        z='%06d' % (Y[k-1].index(v)+1)
        Z='%06d' % k
        print(Z+z)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = map(int, input().split())
P = []
Y = []
for i in range(M):
    p, y = map(int, input().split())
    P += [p]
    Y += [y]
Y = np.array(Y)
for i in range(N):
    pos = np.array([m for m in range(M) if P[m] == i+1])
    if len(pos) != 0:
        Z = Y[pos]
        X = np.argsort(Z)
        pos = pos[X]
        for k in range(len(pos)):
            P[pos[k]] = str(P[pos[k]]).zfill(6) + str(k+1).zfill(6)
for i in range(M):
    print(P[i])

Submission status: Time Limit Exceeded

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

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

for i in range(M):
    Pi, Yi = map(int,PY[i])

    count = 1
    for j in range(i):
        if P[j] == str(Pi):
            if int(Y[j]) > Yi:
                PreYear[j] = PreYear[j]+1
            else:
                count +=1 
    PreYear[i] = 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:
n,m=map(int,input().split())
lst=list(list(map(int,input().split())) for i in range(m))
l=sorted(lst,key =lambda x:x[1])
l=sorted(l,key =lambda x:x[0])
i=0
b=lst[0][0]
for e in l:
    if b==e[0]:
        i+=1
    else:
        i=1
    e.append("%06d"%e[0]+"%06d"%i)
    b=e[0]
for a in lst:
    for b in l:
        if a[1]==b[1]:
            print(b[2])
            continue
            continue

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int, input().split())
L=[ [] for _ in range(N)]
Y=[]
X=[]
for _ in range(M):
    a,b =map(int, input().split())
    L[a-1].append(b)
    X.append({a:b})
for _ in range(N) :
    Y.append(sorted(L[_]))
for i in range(M) :
    for k,v in X[i].items():
        z='%06d' % (Y[k-1].index(v)+1)
        Z='%06d' % k
        print(Z+z)

Submission status: Time Limit Exceeded

Solution code:
l = {}
p_list = []
rem = []
n, m = [int(_) for _ in input().split()]
for i in range(m):
    p, y = [int(_) for _ in input().split()]
    rem.append([p,y])
    if p not in l:
        l[p] = [y]
    else:
        l[p].append(y)
    if p not in p_list:
        p_list.append(p)
for j in range(len(p_list)):
    l[p_list[j]].sort()
for k in range(m):
    p = rem[k][0]
    y = rem[k][1]
    idx = l[p].index(y) + 1
    p_zero = '{0:06d}'.format(p)
    idx_zero = '{0:06d}'.format(idx)
    str = p_zero + idx_zero
    print(str)

Submission status: Time Limit Exceeded

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

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:
        tmp = shi_map[p]
        tmp.append(y)
        tmp.sort()
        shi_map[p] = tmp

    else:
        shi_map[p] = [y]


for i in range(M):
    p = p_list[i]
    y = y_list[i]
    j = shi_map[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:
import numpy as np

nm = input()
n,m = nm.split()
n = int(n)
m = int(m)
cities = [i for i in range(m)]
prefs = [[] for i in range(n)]

for i in range(m):
    temp = input()
    temp = temp.split()
    temp[0] = int(temp[0])
    temp[1] = int(temp[1])
    prefs[temp[0]-1].append(temp[1])
    cities[i] = temp[0]

for i in range(len(prefs)):
    prefs[i] = np.argsort(prefs[i])
    prefs[i] = np.argsort(prefs[i])

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

for i in range(len(cities)):
    ids = 1000000000000 + 1000000*cities[i] + prefs[cities[i]-1][count[cities[i]-1]]+1
    count[cities[i]-1] = count[cities[i]-1] + 1
    ids = str(ids)
    print(ids[1:])

Submission status: Time Limit Exceeded

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

import sys

if __name__ == '__main__':
    n, m = map(int, raw_input().split())
    cities = []
    city_lst = {}
    for i in range(0, m):
        p, y = map(int, raw_input().split())
        cities.append((p, y))
        if not p in city_lst:
            city_lst[p] = [y]
        else:
            city_lst[p].append(y)
    for key in city_lst.keys():
        city_lst[key].sort()
    for city in cities:
        print str('%06d' % city[0]) + str('%06d' % (int(city_lst[city[0]].index(city[1]) + 1)))
        sys.stdout.flush()

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 = str(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(X)) + X)

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()
    i.reverse()


for i in d:
    p = (len(da[i[0]-1]) - da[i[0]-1].index(i[1])-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:
N, M =map(int, input().split())
Ps =[]
Ys =[]
ls = []
for i in range(N):
    ls.append([])
for i in range(M):
    p, y = map(int, input().split())
    Ps.append(p)
    Ys.append(y)
    ls[p-1].append(y)
for l in ls:
    l.sort()
for i in range(M):
    p = Ps[i]
    y = Ys[i]
    number = ls[p-1].index(y) + 1
    strp = str(p)
    strn = str(number)
    print(strp.zfill(6) + strn.zfill(6))

Submission status: Time Limit Exceeded

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

c_array = []
mdic = {}

for i in range(M):
    p,y=map(int, raw_input().split())
    c_array.append([p, y])
    if p in mdic.keys():
        tmp = mdic[p]
        tmp[y] = 1
        mdic[p] = tmp
    else:
        mdic[p] = {y:1}

#    print mdic

#print c_array, mdic

for p in range(1,N+1):
    if p in mdic.keys():
        tmp = sorted(mdic[p].keys())
        for i,t in enumerate(tmp):
            mdic[p][t] = i+1
#        print i, mdic[p][t]

    else:
        pass

for c in c_array:
    p = c[0]
    num = mdic[p][c[1]]
    print '{n:06}{m:06}'.format(n=p, m=num)

Submission status: Time Limit Exceeded

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

Prenum = [[] for i in range(N)]
PreYear = [1 for i in range(M)]
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 j in range(len(Prenum[Pi-1])-1):
        if int(PY[Prenum[Pi-1][j]][1]) > Yi:
            PreYear[Prenum[Pi-1][j]] = PreYear[Prenum[Pi-1][j]]+1
        elif int(PY[Prenum[Pi-1][j]][1]) < Yi:
            count +=1 
    PreYear[i] = 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:
n, m = list(map(int,input().split()))
prefecture = {}
out = [[] for i in range(m)]

for i in range(m):
  prefecture[str(i)] = list(map(int,input().split()))

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

Submission status: Time Limit Exceeded

Solution code:

from scipy.stats import rankdata
N,M = list(map(int,input().split()))

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

p_count = [0 for i in range(N)]

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

P_Y_arg = []
for i in range(N):
    P_Y_arg.append(rankdata(np.array(P_Y[i])))

    
p_count = [0 for i in range(N)]

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

Submission status: Time Limit Exceeded

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

P=[PY_pairs[i][0] for i in range(M)]
Y=[PY_pairs[i][1] for i in range(M)]

sorted_Y=sorted(Y)

P_table=[[]]*N

for i in range(M):
	P_table[P[Y.index(sorted_Y[i])]-1]=P_table[P[Y.index(sorted_Y[i])]-1]+[Y.index(sorted_Y[i])]

for i in range(M):
	for y, row in enumerate(P_table):
		try:
			pos = (y, row.index(i))
			break
		except ValueError:
			pass
	i_pad="%06d" % (pos[0]+1)
	j_pad="%06d" % (pos[1]+1)
	print(i_pad+j_pad)


#answer=[0]*M
#for i in range(N):
#	i_pad="%06d" % (i+1)
#	for j in range(len(P_table[i])):
#		j_pad="%06d" % (j+1)
#		answer[P_table[i][j]]=i_pad+j_pad

#for i in range(M):
#	print(answer[i])

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int, input().split())
L=[ [] for _ in range(N)]
Y=[]
X=[]
for _ in range(M):
    a,b = input().split()
    a=int(a)
    b=int(b)
    L[a-1].append(b)
    X.append({a:b})
for _ in range(N) :
    Y.append(sorted(L[_]))
for i in range(M) :
    for k,v in X[i].items():
        z='%06d' % (Y[k-1].index(v)+1)
        Z='%06d' % k
        print(Z+z)

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]
d = sorted(a)
for i in range(m):
    print('0'*(6-len(str(a[i][0]))) + str(a[i][0])\
    +'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))

Submission status: Time Limit Exceeded

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

sorted=[ [] for i in range(N+1) ]
for i in range(M):
    cities.append(list(map(int,input().split())))
    sorted[cities[i][0]].append(cities[i][1])

for s in sorted:
  s.sort()
for p,y in cities:
  i = 0
  while(sorted[p][i]!= y):
    i+=1
  print('{0:06d}{1:06d}'.format(p,i+1))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from collections import deque
from queue import PriorityQueue

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

out = [0]*CITIES

for p in pref:
    order = 1
    while not pref[p].empty():
        c, i = pref[p].get()
        out[i] = str(p).zfill(6) + str(order).zfill(6)
        order += 1

for o in out:
    print(o)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
P=[]
Y=[]
for i in range(m):
    p,y=map(int,input().split())
    P.append(p)
    Y.append(y)
T=[]
U=[]
for i in range(m):
    if len(str(P[i]))<6:
        s='0'*(6-len(str(P[i])))+str(P[i])
        T.append(s)
    else:
        T.append(str(y))    
c=1
for i in range(m):
    c=1
    for j in range(m):
        if P[i]==P[j]:
            if Y[i]>Y[j]:
                c+=1
    U.append(c) 
X=[]       
for i in range(m):
    if len(str(U[i]))<6:
        u='0'*(6-len(str(U[i])))+str(U[i])
        X.append(u)            
    else:
        X.append(str(U[i]))

for i in range(m):
    print(T[i]+X[i])

Submission status: Time Limit Exceeded

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

for _ in range(M):
    P, Y = map(int, input().split())
    PY.append([P, Y])
    if P in array1:
        array2[array1.index(P)].append(Y)
    else:
        array1.append(P)
        array2.append([Y])

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

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 =[0 for i in range(m)]
ids_ = [ids[yy.index(y)] for y in yy_]
for y in yy_:
    i=yy.index(y)
    p_=pp[i]
    pp_[p_-1]+=1
    x = str(p_).rjust(6,'0') + str(pp_[p_-1]).rjust(6,'0')
    ans[i]=x

for x in ans:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
dic={}
PY=[]
 
for _ in range(M):
    p,y=map(int,input().split())
    PY.append([p,y])
    if p in dic.keys():
        dic[p].append(y)
    else: dic[p]=[y]
    
for k in dic.keys():
    dic[k].sort()
        
for i in range(M):
    PY[i][1]=dic[PY[i][0]].index(PY[i][1])+1
 
for [p,y] in PY:
    print('{0:06d}'.format(p)+'{0:06d}'.format(y))

Submission status: Time Limit Exceeded

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

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

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

def f0(num):
    if 10>num:
        return "00000"+str(num)
    elif 100>num:
        return "0000"+str(num)
    elif 1000>num:
        return "000"+str(num)
    elif 10000>num:
        return "00"+str(num)
    elif 100000>num:
        return "0"+str(num)
    else:
        return str(num)

N,M = map(int,input().split(" "))
py = []
aaa = []
bbb = []
ccc = []
for i in range(M):
    p,y = map(int,input().split(" "))
    py.append([p,y])
    if p not in aaa:
        aaa.append(p)
        bbb.append([y])
    else:
        bbb[aaa.index(p)].append(y)
for i in range(len(aaa)):
    BBB = copy.deepcopy(bbb[i])
    BBB.sort()
    ccc.append(BBB)
for i in range(M):
    p,y = py[i]
    ans1 = aaa.index(p)
    ans2 = ccc[ans1].index(y)
    print(f0(p)+f0(ans2+1))

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(x) for x in input().split()]
prefectures = {}
for i in range(N):
    prefectures[i+1] = []

historys = []
for _ in range(M):
    historys.append([int(x) for x in input().split()])

for P, Y in historys:
    prefectures[P].append(Y)
    prefectures[P].sort()

for P, Y in historys:
    idx = prefectures[P].index(Y)
    print("{:06d}{:06d}".format(P, idx+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)]

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

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

for i in range(n):
  ken = kuni[i]
  sorted_ken = copy.deepcopy(ken)
  sorted_ken.sort()
  sorted_kuni[i] = sorted_ken

for i in range(0, m):
  ken = p[i]
  num = 0
  for j in range(0, len(kuni[p[i] - 1])):
    if sorted_kuni[p[i] - 1][j] == y[i]:
      num = j
      break
  print(str(ken).zfill(6) + str(num + 1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int, input().split())
L=[ [] for _ in range(N)]
Y=[]
X=[]
for _ in range(M):
    a,b =map(int, input().split())
    L[a-1].append(b)
    X.append({a:b})
for _ in range(N) :
    Y.append(sorted(L[_]))
for i in range(M) :
    for k,v in X[i].items():
        z='%06d' % (Y[k-1].index(v)+1)
        Z='%06d' % k
        print(Z+z)

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 p in Ps:
    ls = dic[p]
    ls.sort()
    dic[p] = ls
for i in range(M):
    p = Ps[i]
    y = Ys[i]
    number = dic[p].index(y) + 1
    strp = str(p)
    strn = str(number)
    print(strp.zfill(6) + strn.zfill(6))

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)]) + "_"
	try:
		S[key]
	except:
		S[key]=[]
	S[key].append(i)

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

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 = map(int,input().split())
a = []
c =[[] for i in range(n+1)]
for i in range(m):
    b = list(map(int,input().split()))
    a.append(b)
    c[b[0]].append(b[1])

for i in a:
    s = '{0:06d}'.format(i[0])
    d = 1
    for j in c[i[0]]:
        if j<i[1]:
            d+= 1
    s += '{0:06d}'.format(d)
    print(s)

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]
def nams(arg):
    l3x="{0:06d}".format(arg[0])+"{0:06d}".format(x)
    l3.append(l3x)
for i in range(1,M):
   if l2[i-1][0]==l2[i][0]:
      x+=1
      nams(l2[i])
      
   else:
      x=1
      nams(l2[i])

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

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

a_dict = {}
for pi,yi in e:
    a_dict[pi] = sorted([yj for pj,yj in e if(pi == pj)])

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

Submission status: Time Limit Exceeded

Solution code:
def main():
	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)

	f = [0]*N

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

if __name__ == '__main__':
	main()

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]
def nams(arg):
    l3x="{0:06d}".format(arg[0])+"{0:06d}".format(x)
    l3.append(l3x)
for i in range(1,M):
   if l2[i-1][0]==l2[i][0]:
      x+=1
      nams(l2[i])
      
   else:
      x=1
      nams(l2[i])

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

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]
d = sorted(a)
for i in range(m):
    b[i] += '0'*(6-len(str(a[i][0]))) + str(a[i][0])\
    +'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:
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
    co = (years.index(i[1])+1)
    print("{0:06d}".format(i[0]) + "{0:06d}".format(co))

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]

for i in range(M):
    p = p_list[i]
    y = y_list[i]
    s_m = shi_map[p]
    s_m = sorted(s_m)
    j = s_m.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:
import numpy as np

A = [int(x) for x in input().split(' ')]
N = A[0]
M = A[1]
PY = []
for i in range(M):
    PY.append(input().split(' '))

PY = np.array(PY).astype(int)
P = [int(PY[i][0]) for i in range(M)]
#Y = [int(PY[i][1]) for i in range(M)]
P_list = set(P)

for x in P_list:
    Y = set(PY[(PY[:,0]==x),1])
    Y = sorted(Y)
    for i in range(len(Y)):
        PY[(PY[:,1]==Y[i]),1] = i+1

for i in range(M):
    print('%06d'%PY[i][0], end='')
    print('%06d'%PY[i][1])

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from collections import deque

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

for citi in city:
    p, c = citi
    index = sorted(pref[p]).index(c)
    left = str(p)
    right = str(index + 1)
    print(left.zfill(6) + right.zfill(6))