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:
import bisect

n, m = map(int, input().split())
cities = [[] for _ in range(n)]
ans = [None] * m
idxMap = {}

for i in range(m):
    p, y = map(int, input().split())
    # idx = bisect.bisect_left(cities[p-1], y)
    # cities[p-1].insert(idx, y)
    bisect.insort_left(cities[p-1], y)
    idxMap[y] = i

    # ans.append(str(p).zfill(6) + str(idx+1).zfill(6))
    # py.append(list(map(int, input().split())))

for i in range(n):
    for j in range(len(cities[i])):
        year = cities[i][j]
        idx = idxMap[year]
        ans[idx] = str(i+1).zfill(6) + str(j+1).zfill(6)

# print(cities)
for i in range(len(ans)):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
import bisect

n, m = map(int, input().split())
cities = [[] for _ in range(n)]
ans = [None] * m
idxMap = {}

for i in range(m):
    p, y = map(int, input().split())
    idx = bisect.bisect_left(cities[p-1], y)
    cities[p-1].insert(idx, y)
    idxMap[y] = i

    # ans.append(str(p).zfill(6) + str(idx+1).zfill(6))
    # py.append(list(map(int, input().split())))

for i in range(n):
    for j in range(len(cities[i])):
        year = cities[i][j]
        idx = idxMap[year]
        ans[idx] = str(i+1).zfill(6) + str(j+1).zfill(6)

# print(cities)
for i in range(len(ans)):
    print(ans[i])

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)

C = zip(P, Y)
C = sorted(C)
P_, Y_ = zip(*C)
P_ = list(P_)
Y_ = list(Y_)

for i in range(m):
    begin = P[i]
    end = Y_[P_.index(begin):].index(Y[i])+1
    print('{:06}{:06}'.format(begin, end))

Submission status: Time Limit Exceeded

Solution code:
def my_index(l, x, default=False):
    return l.index(x) if x in l else default


def main():
    n,m = map(int, input().split())
    PY = [list(map(int, input().split())) for _ in range(m)]
    P = [x[0] for x in PY]
    Y = [x[1] for x in PY]

    PY = sorted(PY, key=lambda x:(x[0],x[1]))
    P_sorted = [x[0] for x in PY]
    Y_sorted = [x[1] for x in PY]
    for i in range(m):
        x = my_index(Y_sorted, Y[i])+1 - my_index(P_sorted,P[i])
        print(str(P[i]).rjust(6,'0')+str(x).rjust(6,'0'))


if __name__ == '__main__':
    main()
    # test()

Submission status: Time Limit Exceeded

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

# for i in range(M):
#     P_num,Y_num = map(int,input().split(" "))
#     P.append(P_num)
#     Y.append(Y_num)

Py = [input().split(" ") for i in range(M)]
P = [int(Py[i][0]) for i in range(len(Py))]
Y = [int(Py[i][1]) for i in range(len(Py))]

#辞書を作成
city = []

for i in range(M):
    city.append({"prefecture":P[i], "year":Y[i]})

#識別番号を作成

#県iのの市のデータのみを集める
order = []
calc_city_num = {}
for i in range(1,N+1):
    for j in range(len(city)):
        if city[j]["prefecture"] == i:
            calc_city_num.setdefault(j,city[j]["year"])


    #この中で創設時期が早い順に並べ替え、つまり、yearを並び替え
    order.append(sorted(calc_city_num.items(), key=lambda x:x[1]))
    calc_city_num.clear()


#県iの市の番号を作成する
for i in range(1,len(order)+1):
    for j in range(len(order[i-1])):
        result = str(str(i).zfill(6) + str(j+1).zfill(6))
        city[int(order[i-1][j][0])].setdefault("num",result)

for i in range(M):
    print(city[i]["num"])

Submission status: Time Limit Exceeded

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

for i in range(N):
    P_lines.append([])

for i in range(M):
    P, Y = map(int, input().split()) 
    P_lines_2.append({i+1:(str(P)+' '+str(Y))})
    for j in range(N):
        if j+1 == P:
            P_lines[j].append(Y)
            
            
            
for i in range(M):
    P_line = P_lines_2[i][i+1]
    P_line = P_line.split()
    for j in range(len(P_line)):
        P_line[j] = int(P_line[j])
    test_line = P_lines[P_line[0]-1]
    test_line.sort()
    index = test_line.index(P_line[1]) + 1
    number_ken = str(P_line[0])
    while len(number_ken) < 6:
        number_ken = str(0) + number_ken
    while len(str(index)) < 6:
        index = str(0) + str(index)
    result = number_ken + index

    print(result)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
input = sys.stdin.readline
dic_pref = {}
list_city =[]

def add_city(pno,year):
    if pno not in dic_pref:
        dic_pref[pno] = [year]
    else:
        bisect.insort(dic_pref[pno],year)

N,M = map(int,input().split())
for _ in range(M):
    P,Y = map(int,input().split())
    add_city(P,Y)
    list_city.append([P,Y])

for city in list_city:
    pref = city[ 0 ]
    year = city[ 1 ]
    order = bisect.bisect_left(dic_pref[pref], year)+1
    print("{0:06}{1:06}".format(pref,order))

Submission status: Time Limit Exceeded

Solution code:
import bisect
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
d = {}

for p, y in PY:
  if p not in d:
    d[p] = [y]
  else:
    #d[p] = (d[p] + [y])
    index = bisect.bisect_left(d[p], y)
    d[p].insert(index, y)

#for x in d:
 # d[x].sort()

for p, y in PY:
  print('{}{}'.format(str(p).zfill(6), str(d[p].index(y) + 1).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
d = {}

for p, y in PY:
  if p not in d:
    d[p] = [y]
  else:
    d[p] = (d[p] + [y])

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

for p, y in PY:
  print('{}{}'.format(str(p).zfill(6), str(d[p].index(y) + 1).zfill(6)))

Submission status: Time Limit Exceeded

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

f = []
r = [[] for i in range(N)]

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

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


for i in f:
    p, y = [int(i) for i in i.split()]
    p1 = str(p).zfill(6)
    p2 = str(r[p - 1].index(y) + 1).zfill(6)
    print('%s%s' % (p1, p2))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as ct
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]

l_p=set([x[0] for x in l])
p={}
for x in l_p:
  p[x]=0

for x in sorted(l,key=lambda x:x[1]):
  p[x[0]]+=1
  l[l.index(x)].append(p[x[0]])
for x in l:
  print(str(x[0]).zfill(6)+str(x[2]).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
queue = []
sort_list = [[10**10] for i in range(n)]
for i in range(m):
    a, b = input().split()
    queue.append([int(a), int(b)])
    sort_list[int(a) - 1].append(int(b))

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

for data in queue:
    k, v = map(int, data)   

    num_index = sort_list[k -1].index(v)

    print(str(k).zfill(6) + str(num_index + 1).zfill(6))

Submission status: Time Limit Exceeded

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

sort_list = [[10**10] for i in range(n)]
for data in queue:
    k, v = map(int, data)
    sort_list[k - 1].append(v)

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

for data in queue:
    k, v = map(int, data)   

    num_index = sort_list[k -1].index(v)

    print(str(k).zfill(6) + str(num_index + 1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
def main():
	N,M = map(int,input().split())
	array = []
	array2 = [[] for i in range(N)]
	for i in range(M):
	    array.append(list(map(int,input().split())))
	    array2[array[i][0]-1].append(array[i][1])

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

	for i in range(M):
	    pnum = str(array[i][0])
	    cnum = str(array2[array[i][0]-1].index(array[i][1])+1)
	    print('0'*(6-len(pnum)) + pnum + '0'*(6-len(cnum)) + cnum)
main()

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
array = []
array2 = [[] for i in range(N)]
for i in range(M):
    array.append(list(map(int,input().split())))
    array2[array[i][0]-1].append(array[i][1])

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

for i in range(M):
    pnum = str(array[i][0])
    cnum = str(array2[array[i][0]-1].index(array[i][1])+1)
    print('0'*(6-len(pnum)) + pnum + '0'*(6-len(cnum)) + cnum)

Submission status: Time Limit Exceeded

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

all_cities = []
p_list = []
for i in range(M):
    p, y = [int(j) for j in input().split()]
    city = [i, p, y]
    p_list.append(p)
    all_cities.append(city)
    
p_set = set(p_list)

sorted_all_cities = []
for p in p_set:
    pref_city_list = []
    for city in all_cities:
        if city[1] == p:
            pref_city_list.append(city)
            
    sorted_pref_city_list = sorted(pref_city_list, key=lambda x: x[2])
    
    for c, city in enumerate(sorted_pref_city_list):
        city[2] = c + 1
        sorted_all_cities.append(city)
    
re_sorted_all_cities = sorted(sorted_all_cities, key=lambda x: x[0])

for city in re_sorted_all_cities:
    prefcode = "{0:06d}".format(city[1])
    citycode = "{0:06d}".format(city[2])
    print(prefcode+citycode)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N,M,*P = map(int,open(0).read().split())
d = defaultdict(list)
Z = set()
for n,m in zip(*[iter(P)]*2):
    d[n].append(m)
    Z.add(n)
for z in Z:
    d[z].sort()
for n,m in zip(*[iter(P)]*2):
    print(str(n).zfill(6)+str(d[n].index(m)+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
array=[]
for i in range(M):
    P,Y = list(map(int,input().split()))
    array.append([P,Y])
array2 = sorted(array)
arraysorted1 = []
j = 1
k = 0
while j != N+1:
    array3=[]
    while k <= M-1:
        if array2[k][0] == j:
            array3.append(array2[k][1])
        k += 1
    array3= sorted(array3)
    arraysorted1.append(array3)
    k = len(arraysorted1[j-1])
    j += 1
for n in range(M):
    for m in range(len(arraysorted1[array[n][0]-1])):
        if array[n] == [array[n][0], arraysorted1[array[n][0]-1][m]]:
            lenf = 6-len(str(array[n][0]))
            lenl = 6-len(str(m+1))
            
            print('0'*lenf +str(array[n][0])+'0'*lenl + str(m+1))

Submission status: Time Limit Exceeded

Solution code:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

N,M = MAP()
Y = [0]*(10**5)
P = [0]*(10**5)
yd =[[] for _ in range(N)]
for i in range(M):
    p,y = MAP()
    P[i] = p-1
    Y[i] = y
    yd[p-1].append(y)

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import bisect

n,m = (int(i) for i in input().split())

d = defaultdict(list)
a = [0]*m
for i in range(m) :
  p,y = (int(i) for i in input().split())
  a[i] = (p,y)

  bisect.insort(d[p],y)
  
for p,y in a :
  print(str(p).zfill(6)+str(bisect.bisect_left(d[p],y)+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import bisect

n,m = (int(i) for i in input().split())

d = defaultdict(list)
a = []
for i in range(m) :
  p,y = (int(i) for i in input().split())
  a.append((p,y))
  #d[p].append(y)
  bisect.insort(d[p],y)
  
#for key,value in d.items() :
#  d[key] = sorted(value)

  
for p,y in a :
  print(str(p).zfill(6)+str(bisect.bisect_left(d[p],y)+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n,m = (int(i) for i in input().split())

d = defaultdict(list)
a = []
for i in range(m) :
  p,y = (int(i) for i in input().split())
  a.append((p,y))
  d[p].append(y)
  
for key,value in d.items() :
  d[key] = sorted(value)

  
for p,y in a :
  print(str(p).zfill(6)+str(d[p].index(y)+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter 
n,m = map(int,input().split())
list1 = []
#[input番号,県番号,年,県における順番]
for i in range(m):
    list1.append([i+1] + list(map(int,input().split())))
list1.sort(key=itemgetter(1,2))
list1[0].append(0)
for i in range(1,m):
    if list1[i-1][1] == list1[i][1]:
        list1[i].append(list1[i-1][3]+1)
    else:
        list1[i].append(0)
for i in range(m):
    list1.sort(key=itemgetter(0))

#int型
def zeropadding(s):
    padding = 6 #何桁揃えにするか入力
    return ("{0:0"+str(padding)+"d}").format(s)
    #returnはstr型なので注意！

for i in range(m):
    print(zeropadding(list1[i][1])+zeropadding(list1[i][3]+1))

Submission status: Time Limit Exceeded

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

list2 = [[] for i in range(n)]
#int型
def zeropadding(s):
    padding = 6 #何桁揃えにするか入力
    return ("{0:0"+str(padding)+"d}").format(s)
    #returnはstr型なので注意！

for i in range(m):
    list2[list1[i][0]-1].append(list1[i][1])
for i in range(n):
    list2[i].sort()

for i in range(m):
    print(zeropadding(list1[i][0])+zeropadding(list2[list1[i][0]-1].index(list1[i][1])+1))

Submission status: Time Limit Exceeded

Solution code:
import copy
n,m = map(int,input().split())
list1 = [list(map(int,input().split())) for i in range(m)]

list2 = copy.deepcopy(list1)
#int型
def zeropadding(s):
    padding = 6 #何桁揃えにするか入力
    return ("{0:0"+str(padding)+"d}").format(s)
    #returnはstr型なので注意！

#空の多次元リスト
list3 = [[] for i in range(n+1)]

list2.sort()

for i in range(m):
    list3[list2[i][0]].append(list2[i][1])

for i in range(m):
    print(zeropadding(list1[i][0])+zeropadding(list3[list1[i][0]].index(list1[i][1])+1))

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
input = sys.stdin.readline

N, M = [int(x) for x in input().strip().split()]
NL = [deque([]) for n in range(10 ** 5)]

IN = [0] * M
for m in range(M):
    IN[m] = tuple([int(x) for x in input().strip().split()]) 

for p, y in IN:
    NL[p-1].append(y)

for i, nl in enumerate(NL):
    NL[i] = sorted(nl)

for p, y in IN:
    print('{:06d}{:06d}'.format(p, NL[p-1].index(y) + 1))

Submission status: Time Limit Exceeded

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

N, M = [int(x) for x in input().strip().split()]
NL = [[] for n in range(10 ** 5)]

IN = [0] * M
for m in range(M):
    IN[m] = tuple([int(x) for x in input().strip().split()]) 

for p, y in IN:
    NL[p-1].insert(bisect.bisect_left(NL[p-1], y), y)

for p, y in IN:
    print('{:06d}{:06d}'.format(p, NL[p-1].index(y) + 1))

Submission status: Time Limit Exceeded

Solution code:
import sys
from operator import itemgetter


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

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

    sorted_p_y = sorted(p_y, key=itemgetter(0, 1))

    for row in p_y:
        count = 0
        for sorted_row in sorted_p_y:
            if row[0] == sorted_row[0]:
                count += 1

            if row[0] == sorted_row[0] and row[1] == sorted_row[1]:
                print(str(row[0]).zfill(6), str(count).zfill(6), sep="")
                break


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from operator import itemgetter

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

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

sorted_p_y = sorted(p_y, key=itemgetter(0, 1))

for row in p_y:
    count = 0
    for sorted_row in sorted_p_y:
        if row[0] == sorted_row[0]:
            count += 1

        if row[0] == sorted_row[0] and row[1] == sorted_row[1]:
            print(str(row[0]).zfill(6), str(count).zfill(6), sep="")
            break

Submission status: Time Limit Exceeded

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

p_y = []
for _ in range(m):
    p_y.append(list(map(int, input().split())))

sorted_p_y = sorted(p_y, key=lambda x: (x[0], x[1]))

for row in p_y:
    count = 0
    for sorted_row in sorted_p_y:
        if row[0] == sorted_row[0]:
            count += 1

        if row[0] == sorted_row[0] and row[1] == sorted_row[1]:
            print(str(row[0]).zfill(6), str(count).zfill(6), sep="")
            break

Submission status: Time Limit Exceeded

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

p_y = []
for _ in range(m):
    p_y.append(list(map(int, input().split())))

sorted_p_y = sorted(p_y, key=lambda x: (x[0], x[1]))

for row in p_y:
    count = 0
    for sorted_row in sorted_p_y:
        if row[0] == sorted_row[0]:
            count += 1

        if row[0] == sorted_row[0] and row[1] == sorted_row[1]:
            print(str(row[0]).zfill(6), str(count).zfill(6), sep="")
            break

Submission status: Time Limit Exceeded

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

p_y = []
for _ in range(m):
    p_y.append(list(map(int, input().split())))

sorted_p_y = sorted(p_y, key=lambda x: (x[0], x[1]))

for i in range(m):
    count = 0
    for j in range(m):
        if p_y[i][0] == sorted_p_y[j][0]:
            count += 1

        if p_y[i][0] == sorted_p_y[j][0] and p_y[i][1] == sorted_p_y[j][1]:
            print(str(p_y[i][0]).zfill(6), str(count).zfill(6), sep="")

Submission status: Time Limit Exceeded

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

p_y = []
for _ in range(m):
    p_y.append(list(map(int, input().split())))

sorted_p_y = sorted(p_y, key=lambda x: (x[0], x[1]))

for row in p_y:
    count = 0
    for sorted_row in sorted_p_y:
        if row[0] == sorted_row[0]:
            count += 1

        if row[0] == sorted_row[0] and row[1] == sorted_row[1]:
            print(str(row[0]).zfill(6), str(count).zfill(6), sep="")

Submission status: Time Limit Exceeded

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

p_y = []
for _ in range(m):
    p_y.append(list(map(int, input().split())))

p_y_tmp = sorted(p_y, key=lambda x: x[0])
sorted_p_y = sorted(p_y_tmp, key=lambda x: x[1])

for row in p_y:
    count = 0
    for sorted_row in sorted_p_y:
        if row[0] == sorted_row[0]:
            count += 1

        if row[0] == sorted_row[0] and row[1] == sorted_row[1]:
            print(str(row[0]).zfill(6), str(count).zfill(6), sep="")

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

Plist = defaultdict(list)

for p, y in PY:
    Plist[p].append(y)

for p, l in Plist.items():
    l.sort()

for p, y in PY:
    idx = Plist[p].index(y)
    print("{:06}{:06}".format(p, idx+1))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from bisect import bisect_right
def main():
    N,M = map(int,input().split())
    Marray=[(0,0)] * M
    P={}
    for i in range(M):
        s = input().split()
        p=int(s[0])
        y=s[1]
        #print(s)
        if p in P.keys():
            P[p]+=y+","
        else:
            P[p]=y+","
        Marray[i]=(p,int(y))
        #print(P[p])
        
    for key in P:
        string=P[key]
        
       # print(str)
        sp=string.split(",")
        de=len(sp)-1
        del sp[de]
        #print(sp)
        tmp=sorted(sp,key=int)
        int_list=list(map(int,tmp))
        P[key]=int_list
        
        #print(P[key])
    
    for index,value in Marray:
        List=P[index]
        
        #print(list)
        result=bisect_right(List,value)
        result=str(result)
        index=str(index)
        index_zero = index.zfill(6)
        result_zero = result.zfill(6)
        print(index_zero,result_zero,sep='')



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from bisect import bisect_right
def main():
    N,M = map(int,input().split())
    Marray=[(0,0)] * M
    P={}
    for i in range(M):
        s = input().split()
        p=int(s[0])
        y=s[1]
        #print(s)
        if p in P.keys():
            P[p]+=y+","
        else:
            P[p]=y+","
        Marray[i]=(p,int(y))
        #print(P[p])
        
    for key in P:
        string=P[key]
        
       # print(str)
        sp=string.split(",")
        de=len(sp)-1
        del sp[de]
        #print(sp)
        tmp=sorted(sp,key=int)
        list = [int(s) for s in tmp]
        P[key]=list
        
        #print(P[key])
    
    for index,value in Marray:
        list=P[index]
        
        #print(list)
        result=bisect_right(list,value)
        result=str(result)
        index=str(index)
        index_zero = index.zfill(6)
        result_zero = result.zfill(6)
        print(index_zero,result_zero,sep='')



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:


import sys
import math
from bisect import bisect_right
def main():
    N,M = map(int,input().split())
    Marray=[(0,0)] * M
    P={}
    for i in range(M):
        s = input().split()
        p=int(s[0])
        y=s[1]
        #print(s)
        if p in P.keys():
            P[p]+=y+","
        else:
            P[p]=y+","
        Marray[i]=(p,int(y))
        #print(P[p])
        
    for key in P:
        string=P[key]
        
       # print(str)
        sp=string.split(",")
        de=len(sp)-1
        del sp[de]
        #print(sp)
        tmp=sorted(sp,key=int)
        P[key]=tmp
        
        #print(P[key])
    
    for index,value in Marray:
        list=P[index]
        list = [int(s) for s in list]
        #print(list)
        result=bisect_right(list,value)
        result=str(result)
        index=str(index)
        index_zero = index.zfill(6)
        result_zero = result.zfill(6)
        print(index_zero,result_zero,sep='')









if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
ken = [[] for _ in range(N)]
shi = [tuple(map(int, input().split())) for _ in range(M)]
for s1, s2 in shi:
    ken[s1-1].append(s2)
for k in ken:
    k.sort()
for s1, s2 in shi:
    print("{:06}{:06}".format(s1, ken[s1-1].index(s2)+1))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
ken = [[] for _ in range(N)]
shi = []
for _ in range(M):
    P, Y = map(int, input().split())
    ken[P-1].append(Y)
    shi.append((P, Y))
for k in ken:
    k.sort()
for s1, s2 in shi:
    print("{:06}{:06}".format(s1, ken[s1-1].index(s2)+1))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
ken = [[] for _ in range(N)]
shi = []
for _ in range(M):
    P, Y = map(int, input().split())
    ken[P-1].append(Y)
    shi.append((P, Y))
for k in ken:
    k.sort()
for s in shi:
    print("{:06}{:06}".format(s[0], ken[s[0]-1].index(s[1])+1))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
ken = [[] for _ in range(N)]
shi = []
for _ in range(M):
    P, Y = map(int, input().split())
    ken[P-1].append(Y)
    shi.append((P, Y))
for k in ken:
    k.sort()
for s in shi:
    print("{:06}{:06}".format(s[0], ken[s[0]-1].index(s[1])+1))

Submission status: Time Limit Exceeded

Solution code:
n,m=[int(i) for i in input().split()]
dic={}
all_list=[]
lst=[]
for i in range(m):
    lst.append([int(i) for i in input().split()])
    if(lst[i][0] in dic.keys()):
        dic[lst[i][0]].append(lst[i][1])
        dic[lst[i][0]].sort()
    else:
        dic[lst[i][0]]=[lst[i][1]]

for i in lst:
    s=str(i[0])
    ind=str(dic[i[0]].index(i[1])+1)
    print(s.zfill(6)+ind.zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n,m=[int(i) for i in input().split()]
dic={}
all_list=[]
for i in range(m):
    lst=[int(i) for i in input().split()]
    all_list.append(lst)
    if(lst[0] in dic.keys()):
        dic[lst[0]].append(lst[1])
        dic[lst[0]].sort()
    else:
        dic[lst[0]]=[lst[1]]

for i in all_list:
    s=str(i[0])
    ind=str(dic[i[0]].index(i[1])+1)
    print(s.zfill(6)+ind.zfill(6))

Submission status: Time Limit Exceeded

Solution code:
# 2019-11-11 14:35:02(JST)
import sys
from collections import deque
import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 
from copy import deepcopy

def main():
    n, m = (int(x) for x in sys.stdin.readline().split())
    PY = [[int(x) for x in sys.stdin.readline().split()] for _ in range(m)]

    py = deque(sorted(deepcopy(PY)))

    ids = dict((j,dict()) for j in set(py[i][0] for i in range(m)))
    for _ in range(m): # max time of loops
        if py:
            for i in range(len(py)):
                p, y, x = py[i][0], py[i][1], i + 1
                if x >= 2 and not ids[p]:
                    for j in range(i): # deque では del [:i] (slice)が使えない
                        py.popleft()
                    break
                id_i = '0' * (6 - (math.floor(math.log10(p)) + 1)) + str(p) + '0' * (6 - (math.floor(math.log10(x)) + 1)) + str(x)
                ids[p][y] = id_i
        else:
            break
    
    for i in range(m):
        p, y = PY[i][0], PY[i][1]
        print(ids[p][y])


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
dic_pref = {}
list_city =[]
 
def add_city(pno,year):
    if pno not in dic_pref:
        dic_pref[pno] = [year]
    else:
        bisect.insort(dic_pref[pno],year)
 
N,M = map(int,input().split())
for _ in range(M):
    P,Y = map(int,input().split())
    add_city(P,Y)
    list_city.append([P,Y])
 
for city in list_city:
    pref = city[ 0 ]
    year = city[ 1 ]
    order = bisect.bisect_left(dic_pref[pref], year)+1
    print("{0:06}{1:06}".format(pref,order))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
from collections import defaultdict as dd
from bisect import insort
PY = dd(lambda:[0])
IMP = [[]] * m
for i in range(m):
  p, y = map(int, input().split())
  Year_lis = PY[p]
  insort(Year_lis, y)
  PY[p] = Year_lis
  IMP[i] = [p, y]
#print(PY)
#for key in PY.keys():
#  PY[key] = sorted(PY[key])
for imp in IMP:
  print("{:0=6}".format(imp[0]), end="")
  pos = PY[imp[0]].index(imp[1])
  print("{:0=6}".format(pos))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
from collections import defaultdict as dd
PY = dd(lambda:[])
IMP = [[]] * m
for i in range(m):
  p, y = map(int, input().split())
  PY[p] += [y]
  IMP[i] = [p, y]
#print(PY)
for key in PY.keys():
  PY[key] = sorted(PY[key])
for imp in IMP:
  print("{:0=6}".format(imp[0]), end="")
  pos = PY[imp[0]].index(imp[1])
  print("{:0=6}".format(pos+1))

Submission status: Time Limit Exceeded

Solution code:
number_of_prefecture, number_of_cities = [int(x) for x in input().split(' ')]

city_list = []

import bisect
import collections
city_dict = collections.defaultdict(list)

for i in range (number_of_cities):
    prefecture_id, year_of_establishment = [int(x) for x in input().split(' ')]
    index = bisect.bisect_left(city_dict[prefecture_id], year_of_establishment)
    city_dict[prefecture_id].insert(index, year_of_establishment)
    city_list.append([prefecture_id, year_of_establishment])

for j in city_list:
    prefecture = j[0]
    year = j[1]
    city_number = bisect.bisect(city_dict[prefecture],year)
    front_string = '0'*(6 - len(str(prefecture))) + str(prefecture)
    back_string = '0'*(6 - len(str(city_number))) + str(city_number)
    print(front_string+back_string)

Submission status: Time Limit Exceeded

Solution code:
number_of_prefecture, number_of_cities = [int(x) for x in input().split(' ')]

city_list = []

import bisect
import collections
city_dict = collections.defaultdict(list)

for i in range (number_of_cities):
    prefecture_id, year_of_establishment = [int(x) for x in input().split(' ')]
    index = 0
    for k in city_dict[prefecture_id]:
        if year_of_establishment > k:
            index += 1
        else:
            break
    city_dict[prefecture_id].insert(index, year_of_establishment)
    city_list.append([prefecture_id, year_of_establishment])

for j in city_list:
    prefecture = j[0]
    year = j[1]
    city_number = bisect.bisect(city_dict[prefecture],year)
    front_string = '0'*(6 - len(str(prefecture))) + str(prefecture)
    back_string = '0'*(6 - len(str(city_number))) + str(city_number)
    print(front_string+back_string)

Submission status: Time Limit Exceeded

Solution code:
number_of_prefecture, number_of_cities = [int(x) for x in input().split(' ')]

city_list = []

import collections
city_dict = collections.defaultdict(list)

for i in range (number_of_cities):
    prefecture_id, year_of_establishment = [int(x) for x in input().split(' ')]
    index = 0
    for k in city_dict[prefecture_id]:
        if year_of_establishment > k:
            index += 1
        else:
            break
    city_dict[prefecture_id].insert(index, year_of_establishment)
    city_list.append([prefecture_id, year_of_establishment])

for j in city_list:
    prefecture = j[0]
    year = j[1]
    city_number = city_dict[prefecture].index(year) + 1
    front_string = '0'*(6 - len(str(prefecture))) + str(prefecture)
    back_string = '0'*(6 - len(str(city_number))) + str(city_number)
    print(front_string+back_string)