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

a = {}
y = []
for mi in range(m):
    pi, yi = [int(i) for i in input().split()]
    if pi in a:
        a[pi].append(yi)
    else:
        a[pi] = [yi]
    y.append(yi)

for av in a.values():
    av.sort()

for yi in y:
    for ak, av in a.items():
        if yi in av:
            print(str(ak).zfill(6) + str(av.index(yi) + 1).zfill(6))
            break

Submission status: Time Limit Exceeded

Solution code:
import collections

n, m = [int(i) for i in input().split()]
s = [tuple(int(i) for i in input().split()) for j in range(m)]

d = collections.defaultdict(lambda: [0])
for si in s:
    d[si[0]] += [si[1]]

def pcod(a, b):
    c = 6-len(str(a))
    d = 6-len(str(b))
    return ('0'*c + str(a) + '0'*d + str(b))

def order(si, dc):
    dso = sorted(dc[si[0]])
    return dso.index(si[1])

for si in s:
    print(pcod(si[0], order(si, d)))

Submission status: Time Limit Exceeded

Solution code:
n, m = [int(i) for i in input().split()]
s = [tuple(int(i) for i in input().split()) for j in range(m)]

d = dict(s)
for i in d.keys():
    d[i] = [0]
for si in s:
    d[si[0]] += [si[1]]

def pcod(a, b):
    c = 6-len(str(a))
    d = 6-len(str(b))
    return ('0'*c + str(a) + '0'*d + str(b))

def order(si, dc):
    dso = sorted(dc[si[0]])
    return dso.index(si[1])

for si in s:
    print(pcod(si[0], order(si, d)))

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter
import sys

input = sys.stdin.readline
n,m = map(int,input().split())

in_p = []
in_y = []
p = []

for _ in range(n):
    p.append([0])

for i in range(m):
    a,b = map(int,input().split())
    in_p.append(a)
    in_y.append(b)
    p[a-1].append(b)  

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

for i in range(m):
    year=str(in_p[i]).zfill(6)
    a = p[in_p[i]-1].index(in_y[i]) 
    num=str(a).zfill(6)
    print("{0}{1}".format(year,num))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())

in_p = []
in_y = []
p = []

for _ in range(n):
    p.append([])

for i in range(m):
    a,b = map(int,input().split())
    in_p.append(a)
    in_y.append(b)
    p[a-1].append(b)  

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

for i in range(m):
    year=str(in_p[i]).zfill(6)
    a = p[in_p[i]-1].index(in_y[i]) + 1
    num=str(a).zfill(6)
    print("{0}{1}".format(year,num))

Submission status: Time Limit Exceeded

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

in_p = []
in_y = []
p = []

for _ in range(n):
    p.append([])

for i in range(m):
    a,b = map(int,input().split())
    in_p.append(a)
    in_y.append(b)
    p[a-1].append(b)  

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

for i in range(m):
    year=str(in_p[i]).zfill(6)
    a = p[in_p[i]-1].index(in_y[i]) + 1
    num=str(a).zfill(6)
    print("{0}{1}".format(year,num))

Submission status: Time Limit Exceeded

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

in_p = []
in_y = []
p = []

for i in range(n):
    p.append([])

for i in range(m):
    a,b = map(int,input().split())
    in_p.append(a)
    in_y.append(b)
    p[a-1].append(b)  

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

for i in range(m):
    year=str(in_p[i]).zfill(6)
    a = p[in_p[i]-1].index(in_y[i]) + 1
    num=str(a).zfill(6)
    print("{0}{1}".format(year,num))

Submission status: Time Limit Exceeded

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

in_p = []
in_y = []

p = []
for i in range(n):
    p.append([])

for i in range(m):
    a,b = map(int,input().split())
    in_p.append(a)
    in_y.append(b)
    p[a-1].append(b)  

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


for i in range(m):
    year=str(in_p[i]).zfill(6)
    a = p[in_p[i]-1].index(in_y[i]) + 1
    num=str(a).zfill(6)
    print("{0}{1}".format(year,num))

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split(" "))
ar = [[] for i in range(a)]
br = []
for i in range(b):
    l = list(map(int,input().split(" ")))
    br.append(l)
    ar[l[0]-1].append(l[1])
    ar[l[0]-1].sort()
for r in br:
    c = str(r[0])
    d = str(ar[r[0]-1].index(r[1])+1)
    for i in range(6-len(c)):
        c = "0" + c
    for i in range(6-len(d)):
        d = "0" + d
    print(c+d)

Submission status: Time Limit Exceeded

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

def func(l,x):
    return [i for i,_x in enumerate(l) if _x == x]

p = []
y = []
number = []


for i in range(m):
    a,b = map(int,input().split())
    c=1
    for j in func(p,a):
        if y[j] < b:
            c+=1
        else:
            number[j] += 1
    p.append(a)
    y.append(b)
    number.append(c)

for i in range(m):
    year=str(p[i]).zfill(6)
    num=str(number[i]).zfill(6)
    print("{0}{1}".format(year,num))

Submission status: Time Limit Exceeded

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

inputs = []
sorted_inputs = {}

for _ in range(M):
    P, Y = map(int, input().split())
    inputs.append((P, Y))
    if sorted_inputs.get(P) is None:
        sorted_inputs[P] = [Y]
    else:
        sorted_inputs[P].append(Y)

for input in sorted_inputs:
    sorted_inputs[input].sort()

for input in inputs:
    first = str(input[0]).rjust(6, '0')
    latter = str(sorted_inputs[input[0]].index(input[1])+1).rjust(6, '0')
    print(first + latter)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
P=[[] for i in range(N+1)]
Y=[0 for i in range(M)]
id=[0 for i in range(M)]
for i in range(M):
    a,b=map(int,input().split())
    P[a].append(b)
    Y[i]=b
for i in range(N+1):
    P[i].sort()
for i in range(1,N+1):
    j=1
    for p in P[i]:
        id[Y.index(p)]=str(i*1000000+j)
        j+=1
for i in range(M):
    print(id[i].zfill(12))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
P=[[] for i in range(N+1)]
Y=[]
id=[0 for i in range(M)]
for i in range(M):
    a,b=map(int,input().split())
    P[a].append(b)
    Y.append(b)
for i in range(N+1):
    P[i].sort()
for i in range(1,N+1):
    j=1
    for p in P[i]:
        id[Y.index(p)]=str(i*1000000+j)
        j+=1
for i in range(M):
    print(id[i].zfill(12))

Submission status: Time Limit Exceeded

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

for val in range(m):
	num=1
	mae=str(p[val]).zfill(6)
	for val2 in range(m):
		if val==val2:
			continue
		elif p[val]==p[val2]:
			if y[val]<y[val2]:
				continue
			else:
				num+=1
	usiro=str(num).zfill(6)
	print(mae+usiro)

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
PY = [list(map(int, input().split())) for i in range(M)] 
d = {}
for i in sorted(PY, key=lambda x: x[1]):
    if i[0] in d:
        d[i[0]].append(i[1])
    else:
        d[i[0]] = [i[1]]
for i in PY:
    print(str(i[0]).zfill(6) + str(d[i[0]].index(i[1]) + 1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
PY = [list(map(int, input().split())) for i in range(M)]
PYS = sorted(PY, key=lambda x: (x[0], x[1]))
d = {}
for i in PYS:
    if i[0] in d:
        d[i[0]].append(i[1])
    else:
        d[i[0]] = [i[1]]
for i in PY:
    print(str(i[0]).zfill(6) + str(d[i[0]].index(i[1]) + 1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
PY = [list(map(int, input().split())) for i in range(M)]
d = {}
for i in PY:
    if i[0] in d:
        d[i[0]].append(i[1])
    else:
        d[i[0]] = [i[1]]
for k, v in d.items():
    v.sort()
for i in PY:
    print(str(i[0]).zfill(6) + str(d[i[0]].index(i[1]) + 1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
n, m = map(int, input().split())

city_to_pref, city_to_birth, pref_to_birth_list = {}, {}, defaultdict(list)
for i in range(m):
    pref, birth = map(int, input().split())
    city_to_pref[i] = pref
    city_to_birth[i] = birth
    pref_to_birth_list[pref].append(birth)


def get_city_index(i):
    pref = city_to_pref[i]
    birth = city_to_birth[i]
    years = pref_to_birth_list[pref]
    return years.index(birth)


def give_id(i):
    p = city_to_pref[i]
    x = get_city_index(i) + 1
    return '{:0=6}{:0=6}'.format(p, x)


for pref, births in pref_to_birth_list.items():
    pref_to_birth_list[pref] = sorted(births)

for i in range(m):
    print(give_id(i))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = [None] * M
    pref_dec = {}
    for m in range(M):
        p, y = map(int, input().split())
        city_list[m] = (p, y)
        if p not in pref_dec:
            pref_dec[p] = []
        pref_dec[p].append(y)

    for p in set(pref_dec.keys()):
        pref_dec[p].sort()

    for m in range(M):
        p_id = city_list[m][0]
        y_id = pref_dec[p_id].index(city_list[m][1]) + 1
        print(str(p_id).zfill(6) + str(y_id).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    pref_dec = {}
    for m in range(M):
        p, y = map(int, input().split())
        city_list.append((p, y))
        if p not in pref_dec:
            pref_dec[p] = []
        pref_dec[p].append(y)

    for p in set(pref_dec.keys()):
        pref_dec[p].sort()

    for m in range(M):
        p_id = city_list[m][0]
        y_id = pref_dec[p_id].index(city_list[m][1]) + 1
        print(str(p_id).zfill(6) + str(y_id).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    pref_dec = {}
    for m in range(M):
        p, y = map(int, input().split())
        city_list.append((p, y))
        if p not in pref_dec:
            pref_dec[p] = []
        pref_dec[p].append(y)

    for p in pref_dec.keys():
        pref_dec[p].sort()

    for m in range(M):
        p_id = city_list[m][0]
        y_id = pref_dec[p_id].index(city_list[m][1]) + 1
        print(str(p_id).zfill(6) + str(y_id).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
city_nums = [[] for i in range(n)]
city_list = []
numbers = []

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_nums[pm-1].append(ym)
    city_list.append([pm,ym])
for i in range(n):
    city_nums[i].sort()
    
for i in range(m):
    cindex = city_nums[city_list[i][0]-1].index(city_list[i][1])
    
    print("{:0=6}{:0=6}".format(city_list[i][0], cindex+1))

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
city_nums = [[] for i in range(n)]
city_list = []
numbers = []

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_nums[pm-1].append(ym)
    city_list.append([pm,ym])
for i in range(m):
    cindex = len([1 for x in city_nums[city_list[i][0]-1] if x<city_list[i][1]])
    print("{:0=6}{:0=6}".format(city_list[i][0], cindex+1))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(m)]
city = [[0] for _ in range(n)]
for i in range(m):
	city[py[i][0]-1].append(py[i][1])
for i in range(n):
	city[i].sort()
for i in range(m):
	id = ""
	for j in range(6-len(str(py[i][0]))):
		id += "0"
	id += str(py[i][0])
	for j in range(6-len(str(city[py[i][0]-1].index(py[i][1])))):
		id += "0"
	id += str(city[py[i][0]-1].index(py[i][1]))
	print(id)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8


def main():
    n, m = map(int, input().split())
    li1 = []
    li2 = []
    for _ in range(n+1):
        li2.append([])
    for _ in range(m):
        tmplist = list(map(int, input().split()))
        li1.append(tmplist)
        li2[tmplist[0]].append(tmplist[1])

    for i in range(n+1):
        li2[i].sort()

    for ken, shi in li1:
        i = li2[ken].index(shi) + 1
        print('{0:0=6}{1:0=6}'.format(ken, i))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8


def main():
    n, m = map(int, input().split())
    li1 = []
    li2 = []
    for _ in range(n+1):
        li2.append([])
    for _ in range(m):
        tmplist = list(map(int, input().split()))
        li1.append(tmplist)
        li2[tmplist[0]].append(tmplist[1])

    for i in range(n+1):
        li2[i] = sorted(li2[i])

    for ken, shi in li1:
        i = li2[ken].index(shi) + 1
        print('{0:0=6}{1:0=6}'.format(ken, i))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
L = [list(map(int, input().split())) + [i] for i in range(M)]
for c in range(1, N + 1):
    for i, v in enumerate(sorted(list(filter(lambda x: x[0] == c, L)))):
        L[v[2]].append(i + 1)
for i in range(M):
    print(str(L[i][0]).zfill(6) + str(L[i][3]).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

A=defaultdict(list)
Q=[]

for i in range(M):
  P,Y=map(int,input().split())
  Q.append([P,Y])
  A[P].append(Y)
  
for a,b in A.items():
  A[a].sort()

for l in Q:
  s=str(l[0]).zfill(6)
  num=A[l[0]].index(l[1])
  s+=str(num+1).zfill(6)
  print(s)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

A=defaultdict(list)
Q=[]

for i in range(M):
  P,Y=map(int,input().split())
  Q.append([P,Y])
  A[P].append(Y)
  
for a,b in A.items():
  A[a].sort()

for l in Q:
  s=str(l[0]).zfill(6)
  num=A[l[0]].index(l[1])
  s+=str(num+1).zfill(6)
  print(s)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
cities = []
for _ in range(m):
  cities.append(list(map(int, input().split())))
  sort_cities = sorted(cities, key=lambda x:x[1])
pre = [0 for _ in range(n)]
ans = {}
for city in sort_cities:
  pre[city[0]-1]+=1
  ans[(6-len(str(city[0])))*'0'+str(city[0])+str(city[1])] = (6-len(str(city[0])))*'0'+str(city[0])+(6-len(str(pre[city[0]-1])))*'0'+str(pre[city[0]-1])
for a in cities:
  print(ans[(6-len(str(a[0])))*'0'+str(a[0])+str(a[1])])

Submission status: Time Limit Exceeded

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

for i in range(M):
    P,Y=map(int,input().split())
    A[P-1].append(Y)
    L.append([P-1,Y])
#print(A)
#print(L)

for j in range(N):
    A[j].sort()
#print(A)

for k in range(len(L)):
    ans1=str((L[k][0]+1)+1000000)
    ans1=ans1[1:]
    ans2=A[L[k][0]].index(L[k][1])
    ans2=str(ans2+1+1000000)
    ans2=ans2[1:]
    print(ans1+ans2)

Submission status: Time Limit Exceeded

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = list(map(int, input().split()))
P =[]
Y = []
for i in range(M):
    P.append(0)
    Y.append(0)
    P[i], Y[i] = list(map(int, input().split()))

dic = {}
for i in range(M):
    dic[P[i]] = [Y[i]] if not P[i] in dic else dic[P[i]] + [Y[i]]
    dic[P[i]] = sorted(dic[P[i]])

# print(dic)
import numpy as np
for i in range(M):
    num = dic[P[i]].index(Y[i]) + 1
    # num = sorted(dic[P[i]]).index(Y[i]) + 1
    print("{0:06d}{1:06d}".format(P[i], num))

Submission status: Time Limit Exceeded

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = list(map(int, input().split()))
P =[]
Y = []
for i in range(M):
    P.append(0)
    Y.append(0)
    P[i], Y[i] = list(map(int, input().split()))

dic = {}
for i in range(M):
    dic[P[i]] = [Y[i]] if not P[i] in dic else dic[P[i]] + [Y[i]]

# print(dic)
import numpy as np
for i in range(M):
    num = sorted(dic[P[i]]).index(Y[i]) + 1
    print("{0:06d}{1:06d}".format(P[i], num))

Submission status: Time Limit Exceeded

Solution code:

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

# 同じ年に誕生した市は存在しないので，誕生年を識別値にする
city = {}
ord_list = []

for m in range(M):
	pf, ordr = map(int, input().split(" "))

	if pf not in city:
		city[pf] = []

	city[pf].append(ordr)
	ord_list.append(ordr)

for i in ord_list:
	for k, vs in city.items():
		# 順序づけ
		vs = sorted(vs, key=lambda v: int(v))
		for index, v in enumerate(vs):
			if v == i:
				
				ans_city = [x for x in reversed(list(str(k)))]
				while len(ans_city) < 6:
					ans_city.append('0')
				
				ans_ord = [x for x in reversed(list(str(index + 1)))]
				while len(ans_ord) < 6:
					ans_ord.append('0')

				
				ans = ans_ord + ans_city
				print("".join(reversed(ans)))

Submission status: Time Limit Exceeded

Solution code:
def multi_input():
    string = input()
    res = []
    for s in string.split(" "):
        res.append(int(s))
    return res

def padding(num):
    string = str(num)
    zero_str = '0'*(6-len(string))
    return zero_str+string

N, M = multi_input()
pairs = []
Y = {}

for i in range(M):
    p, y = multi_input()
    pairs.append((p, y))
    if p-1 in Y:
        Y[p-1].append(y)
    else:
        Y[p-1] = [y]

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

for pair in pairs:
    p, y = pair
    id = padding(p)
    id = id + padding(Y[p-1].index(y)+1)
    print(id)

Submission status: Time Limit Exceeded

Solution code:
def multi_input():
    string = input()
    res = []
    for s in string.split(" "):
        res.append(int(s))
    return res

def padding(num):
    string = str(num)
    zero_str = '0'*(6-len(string))
    return zero_str+string

N, M = multi_input()
pairs = []
Y = []
for i in range(N):
    Y.append([])

for i in range(M):
    p, y = multi_input()
    pairs.append((p, y))
    Y[p-1].append(y)

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

for pair in pairs:
    p, y = pair
    id = padding(p)
    id = id + padding(Y[p-1].index(y)+1)
    print(id)

Submission status: Time Limit Exceeded

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

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

answer_list = [0] * M
prefectures = [0] * (M+1)
data_set = [[0]] * (N+1)

data_set_dict = {}

for i in range(M):
	P, Y = map(int, input().split())
	data_set_dict[i] = Y
	if data_set[P] == [0]:
		data_set[P] = [Y]
	else:
		data_set[P].append(Y)

for n in range(N):
	data_set[n].sort()

for i in range(M):
	a = data_set_dict[i]
	for n in range(1, N+1):
		answer = ''
		if a not in data_set[n]:
			pass
		else:
			for j in range(6-len(list(str(n)))):
				answer += '0'

			answer += str(n)

			for j in range(6-len(list(str(data_set[n].index(a)+1)))):
				answer += '0'

			answer += str(data_set[n].index(a)+1)
			print(answer)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

n,m = list(map(int,input().split()))
a = [[0] for i in range(n)]
b = [None]*m
for i in range(m):
    p,s = list(map(int,input().split()))
    p-=1
    a[p].append(s)
    b[i] = [p,s]
for i in range(len(a)):
    a[i].sort()
for i in range(len(b)):
    ken = b[i][0]
    si = a[ken].index(b[i][1])
    si = bisect_left(a[ken], b[i][1])
    ken = str(ken+1).zfill(6)
    si = str(si).zfill(6)
    print("".join([ken,si]))

Submission status: Time Limit Exceeded

Solution code:
n,m = list(map(int,input().split()))
a = [[0] for i in range(n)]
b = [None]*m
for i in range(m):
    p,s = list(map(int,input().split()))
    p-=1
    a[p].append(s)
    b[i] = [p,s]
for i in range(len(a)):
    a[i].sort()
for i in range(len(b)):
    ken = b[i][0]
    si = a[ken].index(b[i][1])
    ken = str(ken+1).zfill(6)
    si = str(si).zfill(6)
    print("".join([ken,si]))

Submission status: Time Limit Exceeded

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

for i in range(n+1):
    a[i].sort()

for i in range(m):
    ken = b[i][0]
    si = a[ken].index(b[i][1]) +1
    ken = str(ken).zfill(6)
    si = str(si).zfill(6)
    print("".join([ken,si]))

Submission status: Time Limit Exceeded

Solution code:
import sys as sys

lines =  input().split()
n = int(lines[0])
m = int(lines[1])

py = []
od = {}

lines = sys.stdin.readlines()

for i in range(0,m):

    l =  lines[i].split()
    p = int(l[0])
    y = int(l[1])
    py.append([p,y])     
    if p-1 in od :
        od[p-1].append(y)
    else:
        od[p-1] = [y]

#print(od)
for o in od.values() :
    o.sort()

for i in range(0,m):
    py0 = py[i][0] 
    r = od[py0-1].index(py[i][1])

    tmp = py0
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = tmp // 10
    
    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(py0,end="")

    tmp = r + 1
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = r // 10

    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(r+1)

Submission status: Time Limit Exceeded

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

data = []

for m in range(M):
    P[m], Y[m] = map(int, input().split())
    data.append([P[m], Y[m], 0, m])

results = []
for n in range(N):
    prefecture = []
    for m in range(M):
        if data[m][0] == n+1:
            prefecture.append(data[m])
        prefecture.sort(key=lambda x: x[1])
        for i in range(len(prefecture)):
            prefecture[i][2] = i + 1
    results += prefecture

results.sort(key=lambda x: x[3])

for result in results:
    print('{:06}{:06}'.format(result[0], result[2]))

Submission status: Time Limit Exceeded

Solution code:
lines =  input().split()
n = int(lines[0])
m = int(lines[1])

py = []
od = [[]*1 for i in range(n)]

for i in range(0,m):

    lines =  input().split()
    p = int(lines[0])
    y = int(lines[1])
    py.append([p,y])     
    od[p-1].append(y)

for o in od :
    o.sort()

for i in range(0,m):
    py0 = py[i][0] 
    r = od[py0-1].index(py[i][1])

    tmp = py0
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = tmp // 10
    
    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(py0,end="")

    tmp = r + 1
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = r // 10

    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(r+1)

Submission status: Time Limit Exceeded

Solution code:
#import time as time

lines =  input().split()
n = int(lines[0])
m = int(lines[1])
#n,m = map(int,input().split())

py = []
od = [[]*1 for i in range(n)]

#print ("create list: " + str(time.time() - s) )
#s = time.time()
for i in range(0,m):

    lines =  input().split()
    p = int(lines[0])
    y = int(lines[1])
    py.append([p,y])
       
    odlen = len(od[p-1])
    od[p-1].append(y)
    od[p-1].sort()
    """ if odlen >= 1 :

        low = 0
        high = odlen - 1
        mid = odlen >> 1

        while low <= high:
            mid = (low + high) >> 1
            guess = od[p-1][mid]
            if guess == y:
                break
            if guess > y :
                high = mid - 1
            else:
                low  = mid + 1
        od[p-1].insert(low,y)

    else:
        od[p-1].append(y) """

#print ("sort: " + str(time.time() - s) )
#exit(0)

#s = time.time()
for i in range(0,m):
    py0 = py[i][0] 
    r = od[py0-1].index(py[i][1])

    tmp = py0
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = tmp // 10
    
    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(py0,end="")

    tmp = r + 1
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = r // 10

    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(r+1)

#print ("index: " + str(time.time() - s) )

Submission status: Time Limit Exceeded

Solution code:
import time as time

s = time.time()

lines =  input().split()
n = int(lines[0])
m = int(lines[1])
#n,m = map(int,input().split())

py = []
od = [[]*1 for i in range(n)]

#print ("create list: " + str(time.time() - s) )

s = time.time()
for i in range(0,m):

    lines =  input().split()
    p = int(lines[0])
    y = int(lines[1])
    py.append([p,y])
       
    odlen = len(od[p-1])
    od[p-1].append(y)
    od[p-1].sort()
    """ if odlen >= 1 :

        low = 0
        high = odlen - 1
        mid = odlen >> 1

        while low <= high:
            mid = (low + high) >> 1
            guess = od[p-1][mid]
            if guess == y:
                break
            if guess > y :
                high = mid - 1
            else:
                low  = mid + 1
        od[p-1].insert(low,y)

    else:
        od[p-1].append(y) """

#print ("sort: " + str(time.time() - s) )
#exit(0)

#s = time.time()
for i in range(0,m):
    py0 = py[i][0]
    r = od[py0-1].index(py[i][1])

    tmp = py0
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = tmp // 10
    
    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(py0,end="")

    tmp = r + 1
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = r // 10

    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(r+1)

#print ("index: " + str(time.time() - s) )

Submission status: Time Limit Exceeded

Solution code:
import time as time

s = time.time()

lines =  input().split()
n = int(lines[0])
m = int(lines[1])
#n,m = map(int,input().split())

py = []
od = [[]*1 for i in range(n)]

#print ("create list: " + str(time.time() - s) )

#s = time.time()
for i in range(0,m):

    lines =  input().split()
    p = int(lines[0])
    y = int(lines[1])
    py.append([p,y])
       
    odlen = len(od[p-1])
    if odlen >= 1 :

        low = 0
        high = odlen - 1
        mid = odlen >> 1

        while low <= high:
            mid = (low + high) >> 1
            guess = od[p-1][mid]
            if guess == y:
                break
            if guess > y :
                high = mid - 1
            else:
                low  = mid + 1
        od[p-1].insert(low,y)

    else:
        od[p-1].append(y)

#print ("sort: " + str(time.time() - s) )

#s = time.time()
for i in range(0,m):
    py0 = py[i][0]
    r = od[py0-1].index(py[i][1])

    tmp = py0
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = tmp // 10
    
    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(py0,end="")

    tmp = r + 1
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = r // 10

    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(r+1)

#print ("index: " + str(time.time() - s) )

Submission status: Time Limit Exceeded

Solution code:
#import time as time

#s = time.time()

n,m = map(int,input().split())
py = []
od = [[]*1 for i in range(n)]

#print ("create list: " + str(time.time() - s) )

#s = time.time()
for i in range(0,m):
    p,y = map(int,input().split())
    py.append([p,y])
       
    odlen = len(od[p-1])
    if odlen >= 1 :

        low = 0
        high = odlen - 1
        mid = odlen//2

        while low <= high:
            mid = (low + high) >> 1
            guess = od[p-1][mid]
            if guess == y:
                break
            if guess > y :
                high = mid - 1
            else:
                low  = mid + 1

        od[p-1].insert(low,y)

    else:
        od[p-1].append(y)

#print ("sort: " + str(time.time() - s) )

#s = time.time()
for i in range(0,m):
    r = od[py[i][0]-1].index(py[i][1])

    tmp = py[i][0]
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = tmp // 10
    
    for j in range(6-digit):
        print('0',end="")
    print(py[i][0],end="")

    tmp = r + 1
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = r // 10

    for j in range(6-digit):
        print('0',end="")
    print(r+1)

#print ("index: " + str(time.time() - s) )

Submission status: Time Limit Exceeded

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

od = [[]*1 for i in range(n)]
rank = [[]*1 for i in range(n)]

for i in range(0,m):
    p,y = map(int,input().split())
    py.append([p,y])
       
    odlen = len(od[p-1])
    if odlen >= 1 :

        low = 0
        high = odlen - 1
        mid = odlen//2

        while low <= high:
            mid = (low + high) >> 1
            guess = od[p-1][mid]
            if guess == y:
                break
            if guess > y :
                high = mid - 1
            else:
                low  = mid + 1        

        od[p-1].insert(low,y)

    else:
        od[p-1].append(y)

for i in range(0,m):
    r = od[py[i][0]-1].index(py[i][1])

    tmp = py[i][0]
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = py[i][0] // 10
    
    for j in range(6-digit):
        print('0',end="")
    print(py[i][0],end="")

    tmp = r + 1
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = r // 10

    for j in range(6-digit):
        print('0',end="")
    print(r+1)

Submission status: Time Limit Exceeded

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

od = [[]*1 for i in range(n)]
rank = [[]*1 for i in range(n)]

for i in range(0,m):
    p,y = map(int,input().split())
    py.append([p,y])
       
    odlen = len(od[p-1])
    if odlen >= 1 :

        low = 0
        high = odlen - 1
        mid = odlen//2

        while low <= high:
            mid = (low + high) >> 1
            guess = od[p-1][mid]

            if guess == y:
                break
            if guess > y :
                high = mid - 1
            else:
                low  = mid + 1        

        od[p-1].insert(low,y)

        for j in range (len(rank[p-1])):
            if rank[p-1][j] >= low :
                rank[p-1][j] +=1

        for r in rank :
            r.append(0)
        rank[p-1][i] = low

    else:
        od[p-1].append(y)

        for r in rank :
            r.append(0)        
        rank[p-1][i] = 0

for i in range(0,m):
    r = rank[py[i][0]-1][i]

    tmp = py[i][0]
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = py[i][0] // 10
    
    for j in range(6-digit):
        print('0',end="")
    print(py[i][0],end="")

    tmp = r + 1
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = r // 10

    for j in range(6-digit):
        print('0',end="")
    print(r+1)