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 = (int(i) for i in input().split(' '))
py=[]
p =[]

# 全都市を配列に代入
for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)

# 全N個の県について調べる
Npy = []
for i in range(1,N+1):
    # 県i
    pyi = [j for j in py if j[1] == i] # 県iの市リスト
    pyi.sort(key=lambda x: x[2]) # 県iの市を生まれた年でソート
    l = len(pyi)
    cnt = 0
    for k in range(1,l+1):
        pyi[k-1][2] = k
    Npy.extend(pyi)

Npy.sort(key=lambda x: x[0])

for t in Npy:
    print('{0:0>6}{1:0>6}'.format(t[1],t[2]))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int, input().split())
lis=[]
for i in range(M):
    lis.append(list(map(int,input().split())))
l_2=sorted(lis, key=lambda x: x[1])
dic={}
for i,j in l_2:
    dic[i]=dic.get(i,0)+1
    res='{:0=6}{:0=6}'.format(i,dic[i])
    lis[lis.index([i,j])]=res
for i in lis:print(i)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
p=[[0 for i in range(1)] for j in range(100005)]
x=[0]*m;y=[0]*m
for i in range(m):
    x[i],y[i]=map(int,input().split())
    p[x[i]].append(y[i])
for i in range(1,n+1):
    p[i].sort()
for i in range(m):
    for j in range(len(p[x[i]])):
        if p[x[i]][j]==y[i]:
            print('%06d'%x[i],end="")
            print('%06d'%(j))

Submission status: Time Limit Exceeded

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

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

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

array = [list(map(int, input().split())) for i in range(M)]
myset = set()

for i in range(M):
    array[i][0] = '%06d' % array[i][0]
    myset.add(array[i][0])

for i in myset:
    array2 = [array[j][1] for j in range(M) if array[j][0] == i]
    array2 = sorted(array2)
    for j in range(M):
        for k in range(len(array2)):
            if array[j][0] == i and array[j][1] == array2[k]:
                array[j][1] = '%06d' % (k + 1)
for i in range(M):
    print(str(array[i][0]) + str(array[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=sorted(l1)
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:
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())

pref =[[] for j in range(n)]


#prefにデータを入れる
for i in range(m):
    for j in range(n):
        if p[i] == j+1:
            pref[j].append([i, y[i]])



#pref[n]をy順にソート
for j in range(n):
    pref[j].sort(key=lambda x:x[1])



#codeをつける
for j in range(n):
    for i in range(len(pref[j])):
        pref[j][i] = [pref[j][i][0], str(j+1).zfill(6) + str(i+1).zfill(6)]

ans = []

#[入力したタイミング、コード]のリストを作る
for j in range(n):
    ans.extend(pref[j])

#ansを入力順にsortする
ans.sort()

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

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())
a = []
for i in range(m):
    x,y=[int(i) for i in input().split()]
    a.append([x,y])
for s in range(m):
	counter = 1
	for t in range(m):
		if a[s][0] == a[t][0] and a[s][1] > a[t][1]:
			counter += 1
	print(str("{0:06d}".format(a[s][0])) + str("{0:06d}".format(counter)))

Submission status: Time Limit Exceeded

Solution code:
# C

from operator import itemgetter
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)]
arr = []
arr.append(ids)
arr.append(pp)
arr.append(yy)
# print(arr)
ids_=[]
yy_=sorted(yy)
pp_=[]
ans =[]
for y in yy_:
    ids_.append(ids[yy.index(y)])
    p_=pp[yy.index(y)]
    x = str(p_).rjust(6,'0') + str(pp_.count(p_)+1).rjust(6,'0')
    pp_.append(p_)
    ans.append(x)
for i in ids:
    print(ans[ids_.index(i)])

# ans = [ans[ids_.index(id)] for id in ids]
    
# print(ids_)
# print(pp_)
# print(yy_)
# print(ans)

Submission status: Time Limit Exceeded

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

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

# for i in range(1, N + 1):
#     PY_sorted[i] = sorted(PY[i])

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:
from operator import itemgetter

def main():
    N,M = list(map(int, input().split()))
    lst = []
    anslst = []
    for i in range(M):
        P,Y = list(map(int, input().split()))
        lst.append({'city_id':i, 'pref':P, 'year':Y})
    lst = sorted(lst, key = itemgetter('year'))
    for i in range(N):
        tmp = [ d for d in lst if d['pref'] == i+1]
        for j in range(len(tmp)):
            city_id = tmp[j]['city_id']
            pref = tmp[j]['pref']
            year = tmp[j]['year']
            id = '{0:06d}'.format(pref) + '{0:06d}'.format(j+1)
            anslst.append({'city_id':city_id, 'pref':pref, 'year':year, 'id':id})
    anslst = sorted(anslst, key = itemgetter('city_id'))
    for i in range(len(anslst)):
        print(anslst[i]['id'])

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]

d = {}

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

for k in d:
    d[k].sort()

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:
import copy as cp

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)
#print(N,M,P,Y)

C_lst = [[] for _ in range(N)]
for i in range(M):
    C_lst[P[i]-1].append(Y[i])
#print(N,M,P,Y,C_lst)
C_cp = cp.deepcopy(C_lst)
for i in range(N):
    C_cp[i].sort()
for i in range(M):
    ans = "0"*(6-len(str(P[i]))) + str(P[i])
    idx = C_cp[P[i]-1].index(Y[i]) + 1
    ans += "0"*(6-len(str(idx))) + str(idx)
    print(ans)

Submission status: Time Limit Exceeded

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

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

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 numpy as np

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

dic_p = {i: np.array([]) for i in range(1, N + 1)}
order = []

for _ in range(M):
    p, y = map(int, input().split())
    dic_p[p] = np.append(dic_p[p], y)
    order.append((p, y))

for i in range(1, N + 1):
    dic_p[i] = sorted(dic_p[i])

for p, y in order:
    prefecture = '{:0=6}'.format(p)
    city = '{:0=6}'.format(dic_p[p].index(y) + 1)
    print(prefecture + city)

Submission status: Time Limit Exceeded

Solution code:
n,p=map(int,input().split())
arr=[]
arr1=[[] for i in range(100001)]
for i in range(p):
    arr.append(list(map(int,input().split())))
    arr1[arr[i][0]].append(arr[i][1])
for i in range(100001):
    if(len(arr1[i])>1):
        arr1[i].sort()
for i in range(p):
    print("%06d%06d"%(arr[i][0],arr1[arr[i][0]].index(arr[i][1])+1))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
X=[[] for x in range(N+1)]
city=[]
for i in range(M):
    P,Y=map(int,input().split())
    city.append((P,Y))
    X[P].append(Y)
S=[0]*(N+1)
for p,y in city:
    if S[p]==0:
        X[p].sort()
        S[p]=1
    num=X[p].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)]
PY_sorted = [[] 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_sorted[i] = sorted(PY[i])

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ken = [None] * N
for i in range(N):
    ken[i] = []

for i in range(M):
    ken[P[i] - 1].append(Y[i])

for i in range(N):
    ken[i] = sorted(ken[i])

city_info = [None] * M

k = 0

while(k < M):
    for l in range(N):
        for m in range(len(ken[l])):
            city_info[k] = [ken[l][m], l + 1, m + 1]
            k += 1


def createID(p, x):
    output_p = str(p)
    output_x = str(x)
    p_len = len(output_p)
    x_len = len(output_x)
    while p_len < 6:
        output_p = "0" + output_p
        p_len += 1
    while x_len < 6:
        output_x = "0" + output_x
        x_len += 1

    return output_p + output_x


for i in range(M):
    # Y[i]を探してきてprint
    for j in range(M):
        if city_info[j][0] == Y[i]:
            print(createID(city_info[j][1], city_info[j][2]))
            break

Submission status: Time Limit Exceeded

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

Y_s = sorted(Y)
count = [1]*(N+1)
ans = [0]*M
for i in range(M):
    j = Y.index(Y_s[i])
    ans[j] = str(P[j]).zfill(6) + str(count[P[j]]).zfill(6)
    count[P[j]] = count[P[j]] +1

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

Submission status: Time Limit Exceeded

Solution code:
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)
    pref[p].append(y)

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

Submission status: Time Limit Exceeded

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

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]

        while len(sp) != 6:
            sp = '0' + sp
        while len(sy) != 6:
            sy = '0' + sy

        out[index] = sp + sy

        pref_index += 1

for o in out:
    print(o)

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)
    b.append((s, t))
for i in range(n):
    a[i].sort()

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

Submission status: Time Limit Exceeded

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

d = {}

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

for k in d:
    d[k].sort()

for py in PY:
    s1 = str(py[0])
    s1 = ("0"*(6-len(s1)))+s1
    s2 = str(d[py[0]].index(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())
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 c:
    i.sort()
for i in a:
    s = '{0:06d}'.format(i[0])
    s += '{0:06d}'.format(c[i[0]].index(i[1])+1)
    print(s)

Submission status: Time Limit Exceeded

Solution code:
n,p=map(int,input().split())
arr=[]
arr1=[[] for i in range(100001)]
for i in range(p):
    arr.append(list(map(int,input().split())))
    arr1[arr[i][0]].append(arr[i][1])
for i in range(100001):
    arr1[i].sort()
for i in range(p):
    print("%06d%06d"%(arr[i][0],arr1[arr[i][0]].index(arr[i][1])+1))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
d={}
pl=[]
yl=[]
#for i in range(N+1):
#    d[i]=[]
for i in range(M):
    P, Y = map(int, input().split())
    pl.append(P)
    yl.append(Y)
    if (P in d)==False:
        d[P]=[Y]
    else:
        d[P].append(Y)
    
for i in d:
    d[i].sort()

for i in range(M):
    pi='{0:06d}'.format(pl[i])
    x='{0:06d}'.format(d[pl[i]].index(yl[i])+1)
    print(pi+x)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

PY_list = defaultdict(list)
for i in range(len(PY)):
    PY_list[PY[i][0]].append([i, PY[i][1]])
#print(PY_list)

for pyl in PY_list.values():
    #print(pyl)
    pyl.sort(key = lambda x: x[1])
#print(N, M, PY)
#print(PY_list)
#print(PY[0][0])
for i in range(len(PY)):
    n = PY_list[PY[i][0]].index([i, PY[i][1]])
    print("{:06d}{:06d}".format(PY[i][0], n + 1))

Submission status: Time Limit Exceeded

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

P = []
Y = []
a = {}
for m in range(M):
    p, y = (int(i) for i in input().split())
    if p in a.keys():
        a[p].append(y)
    else:
        a[p] = [y]
    P.append(p)
    Y.append(y)


sa = {}
for k, v in a.items():
    V = sorted(v)
    sa[k] = V

cnt = 0
for i, a in enumerate(P):
    print('%06d' % a + '%06d' % (sa[a].index(Y[i]) + 1))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
X=[[] for x in range(N+1)]
city=[]
for i in range(M):
    P,Y=map(int,input().split())
    city.append((P,Y))
    X[P].append(Y)
X=[sorted(i) for i in X]
for p,y in city:
    num=X[p].index(y)+1
    print("%06d"%p+"%06d"%num)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

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 range(a):
    da[i].sort()

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

    n = str(d[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(' '))

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


for i in range(M):
    Pi, Yi = map(int,PY[i])
    count = 0
    for j in range(len(PreYear[int(Pi)-1])):
        if PreYear[int(Pi)-1][j] <= 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 = [tuple(map(int, input().split())) for _ in range(m)]

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

for p, y in py:
  t[p-1].append(y)

for ti in t:
  ti.sort()
  
for p, y in py:
  kami = p
  shimo = t[p-1].index(y) + 1
  print('{0:06d}{1:06d}'.format(kami, shimo))

Submission status: Time Limit Exceeded

Solution code:
n_m = input()
N_M = n_m.split()
N = int(N_M[0])
M = int(N_M[1])
L = [[] for i in range(0,M)]

for i in range(0,M):
    p_y = input()
    P_Y = p_y.split()
    P_Y[0] = int(P_Y[0])
    P_Y[1] = int(P_Y[1])
    L[i] = P_Y

for j in range(0,M):
    count = 1
    for k in range(0,M):
        if j != k:
            if L[j][0] == L[k][0] and L[j][1] > L[k][1]:
                count += 1
    n = L[j][0]*1000000 + count
    number = '000000' + str(n)
    print(number[len(number)-12:])

Submission status: Time Limit Exceeded

Solution code:
n,p=map(int,input().split())
arr=[]
arr1=[[] for i in range(100001)]
for i in range(p):
    arr.append(list(map(int,input().split())))
    arr1[arr[i][0]].append(arr[i][1])
for i in range(len(arr1)):
    arr1[i].sort()
for i in range(p):
    print("%06d%06d"%(arr[i][0],arr1[arr[i][0]].index(arr[i][1])+1))

Submission status: Time Limit Exceeded

Solution code:
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(" "))
P = []
Y = []
for i in range(M):
    p,y = map(int,input().split(" "))
    P.append(p)
    Y.append(y)
for i in range(M):
    ans = 1
    p,y = P[i],Y[i]
    for j in range(M):
        if (p == P[j])and(y > Y[j]):
            ans += 1
    print(f0(p)+f0(ans))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
inputs = []
indexs = []
nums = []
for i in range(n):
    inputs.append([])
    indexs.append([])
    nums.append([])
for i in range(m):
    p,y = map(int, input().split())
    inputs[p-1].append(y)
    indexs[p-1].append(i)
    nums[p-1].append("a")
for e,i in enumerate(inputs):
    j = sorted(i)
    for k in range(len(i)):
        pn = (6-len(str(e+1)))*"0"+str(e+1)
        yn = (6-len(str(j.index(i[k])+1)))*"0"+str(j.index(i[k])+1)
        nums[e][k] = pn+yn
i_ = []
n_ = []
for i in range(n):
    for j in range(len(indexs[i])):
       i_.append(indexs[i][j]) 
       n_.append(nums[i][j])
j_ = sorted(i_)
for i in j_:
    print(n_[i_.index(i)])

Submission status: Time Limit Exceeded

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

for i in range(M):
    cnt = 1
    for j in range(M):
        if P[i] == P[j] and Y[i] > Y[j]:
            cnt = cnt + 1
    print(str(P[i]).zfill(6)+str(cnt).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n,p=map(int,input().split())
arr=[]
arr1=[]
for i in range(100001):
    arr1.append([])
for i in range(p):
    arr.append(list(map(int,input().split())))
    arr1[arr[i][0]].append(arr[i][1])
for i in range(len(arr1)):
    arr1[i].sort()
for i in range(p):
    print("%06d%06d"%(arr[i][0],arr1[arr[i][0]].index(arr[i][1])+1))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
#print(l)
for i in l:
    a=1
    for j in l:
        if i[0]==j[0] and i[1]>j[1]:
            a+=1
    print(str('%06d'%i[0])+str('%06d'%a))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
d={}
pl=[]
yl=[]
for i in range(N+1):
    d[i]=[]
for i in range(M):
    P, Y = map(int, input().split())
    pl.append(P)
    yl.append(Y)
    d[P].append(Y)
    
for i in range(N+1):
    d[i].sort()

for i in range(M):
    pi='{0:06d}'.format(pl[i])
    x='{0:06d}'.format(d[pl[i]].index(yl[i])+1)
    print(pi+x)

Submission status: Time Limit Exceeded

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

dic_p = {i: [] for i in range(1, N + 1)}
order = []

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

for i in range(1, N + 1):
    # prefecture = '{:0=6}'.format(i)
    dic_p[i] = sorted(dic_p[i])
    # for index, _ in enumerate(dic_p[i]):
    #     city = '{:0=6}'.format(index + 1)
    #     print(prefecture + city)

for p, y in order:
    prefecture = '{:0=6}'.format(p)
    city = '{:0=6}'.format(dic_p[p].index(y) + 1)
    print(prefecture + city)

Submission status: Time Limit Exceeded

Solution code:
n,m=[int(s)for s in input().split()]
cit=[]
for _ in range(m):
    p,y=[int(s)for s in input().split()]
    cit.append((p,y))
pref={}
for c in cit:
    p,y=c
    if p not in pref:pref[p]=[]
    pref[p].append(y)
for p in pref:
    pref[p]=sorted(pref[p])
    for i in range(len(pref[p])):
        num="%06d%06d"%(p,i+1)
        ind=cit.index((p,pref[p][i]))
        cit[ind]=num
for s in cit:
    print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
def main():
    lines = sys.stdin.readlines()
    n, m = map(int, lines[0].split())
    cities={}
    mem_city = deque()
    for i in range(1, m+1):
        p, y = map(int, lines[i].split())
        mem_city.append((p, y))
        if p in cities:
            cities[p].append(y)
        else:
            cities[p] = [y]
    #print(cities)
    for key in cities:
        cities[key].sort()
    #print(cities)

    for p, y in mem_city:
        idx = cities[p].index(y) + 1
        print("{:06d}{:06d}".format(p, idx))
    return

main()

Submission status: Time Limit Exceeded

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

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

for i in range(M):
    num = country[P[i]].index(Y[i]) + 1
    line = str(P[i]).zfill(6) + str(num).zfill(6)
    print(line)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
X=[[] for x in range(N)]
city=[]
for i in range(M):
    P,Y=map(int,input().split())
    P-=1
    city.append((P,Y))
    X[P].append(Y)
X=[sorted(i) for i in X]
for p,y in city:
    num=X[p].index(y)+1
    p+=1
    print("%06d"%p+"%06d"%num)

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

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

answer=[0]*M

for i in range(1,N+1):
	Pi_list=[]
	for j in range(M):
		if PY_pairs[j][0]==i:
			Pi_list.append(PY_pairs[j][1])
	Pi_list.sort()
	i_pad="%06d" % i
	for j in range(len(Pi_list)):
		j_pad="%06d" % (j+1)
		answer[Y.index(Pi_list[j])]=i_pad+j_pad

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

Submission status: Time Limit Exceeded

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

n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
#print(l)
for i in range(m):
    n=1
    for j in range(m):
        if l[i][0]==l[j][0] and l[i][1]>l[j][1]:
            n+=1
    print(str('%06d'%l[i][0])+str('%06d'%n))

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:
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 range(a):
    da[i].sort()

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

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

    for j in range(6-len(n)):
        n = "0" + n
    for j in range(6-len(m)):
        m = "0" + m

    print(n+m)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
Pref = [[] for i in range(N)]
City = [N+1 for i in range(M)]
for i in range(M):
    p, y = map(int, input().split())
    Pref[p-1].append(y)
    City[i] = (p, y)
for i in range(N):
    Pref[i].sort()
for i in range(M):
    first = City[i][0]
    second = Pref[first-1].index(City[i][1])
    ans = "{0:06d}".format(first) + "{0:06d}".format(second+1)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, m = map(int, input().split())
    cities={}
    mem_city=[]
    for i in range(m):
        p, y = map(int, input().split())
        mem_city.append((p, y))
        if p in cities:
            cities[p].append(y)
        else:
            cities[p] = [y]
    #print(cities)
    for key in cities:
        cities[key].sort()
    #print(cities)

    for p, y in mem_city:
        idx = cities[p].index(y) + 1
        print("{:06d}{:06d}".format(p,idx))
    return

main()

Submission status: Time Limit Exceeded

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

for key in p_dict.keys():
    p_dict[key].sort()

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict

n, m = map(int, sys.stdin.readline().strip().split(" ", 2))
count_city = defaultdict(list)

for line in sys.stdin:
    p, y = map(int, line.strip().split(" ", 2))
    count_city[p].append(y)


for p, yl in count_city.iteritems():
    count_city[p] = sorted(yl)

    sys.stdin.seek(0)
    n, m = map(int, sys.stdin.readline().strip().split(" ", 2))

for line in sys.stdin:
    p, y = map(int, line.strip().split(" ", 2))
    print("{:0=6}{:0=6}".format(p, count_city[p].index(y) + 1))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
P = []
Y = []
for i in range(M):
  listA = list(map(int,input().split()))
  P.append(listA[0])
  Y.append(listA[1])
for i in range(M):
  num = 0
  for k in range(M):
    if P[i]==P[k] and Y[i]>=Y[k]:
      num+=1
  print(str(P[i]).rjust(6,'0')+str(num).rjust(6,'0'))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin,stdout
n,m = map(int,stdin.readline().split(' '))
arr = []
b = []
for _ in range(m):
	t = map(int,stdin.readline().split(' '))
	arr.append(t)
	b.append(t[1])
c=[None]*m
arr.sort(key = lambda x: (x[0],x[1]))
t = {i:1 for i in range(1,n+1)}
for i in arr:
		f = str(i[0]).zfill(6) + str(t[i[0]]).zfill(6)
		t[i[0]]=t[i[0]]+1
		c[b.index(i[1])]=f
for i in c:
	stdout.write(i+'\n')

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
d = {}
py = []
for i in range(1,m+1):
    p,y = map(int, input().split())
    py.append((p,y))
    if p not in d:
        d[p] = []
    d[p].append([y,i])

for k in d.keys():
    d[k] = sorted(d[k])

for p,y in py:
    idx = 0
    for i in range(len(d[p])):
        if d[p][i][0]==y:
            idx = i+1
            break
    print("{:06}{:06}".format(p,idx))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
p = [[] for _ in range(n)]
py = [list(map(int, input().split())) for _ in range(m)]
for _p, _y in py:
    p[_p-1].append(_y)
for i in range(n):
    p[i] = sorted(p[i])

for _p, _y in py:
    print("{:06}{:06}".format(_p, p[_p-1].index(_y) + 1))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,raw_input().split(' '))
arr = []
b = []
for _ in range(m):
	t = map(int,raw_input().split(' '))
	arr.append(t)
	b.append(t[1])
c=[None]*m
arr.sort(key = lambda x: (x[0],x[1]))
t = {i:1 for i in range(1,n+1)}
g = []
for i in arr:
		f = str(i[0]).zfill(6) + str(t[i[0]]).zfill(6)
		t[i[0]]=t[i[0]]+1
		c[b.index(i[1])]=f
for i in c:
	print i

Submission status: Time Limit Exceeded

Solution code:
import bisect
N, M = map(int, input().split())
py_list = [tuple(map(int, input().split())) for _ in range(M)]
records = [[0] for _ in range(N+1)]
for P, Y in py_list:
    bisect.insort(records[P], Y)

for P, Y in py_list:
    print("%06d%06d" % (P, records[P].index(Y)))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
Pref = [[] for i in range(N)]
City = [N+1 for i in range(M)]
for i in range(M):
    p, y = map(int, input().split())
    Pref[p-1].append((y, i))
    City[i] = (p, y)
for i in range(N):
    Pref[i].sort()
for i in range(M):
    first = City[i][0]
    second = Pref[first-1].index((City[i][1], i))
    ans = "{0:06d}".format(first) + "{0:06d}".format(second+1)
    print(ans)