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
inf = 10**15
mod = 10**9+7
n, m = map(int, input().split())
ken = [[] for i in range(n)]
py = [list(map(int, input().split())) for i in range(m)]
for i in range(m):
    p, y = py[i]
    bisect.insort_left(ken[p-1], y)
for i in range(m):
    p, y = py[i]
    ind = bisect.bisect_left(ken[p-1], y)
    print('{ans:06}{anse:06}'.format(ans=p, anse=ind+1))

Submission status: Time Limit Exceeded

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

tmpsort = [[0]for i in range(n)]
p_list = []
y_list = []

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

for i in range(n):
    tmpsort[i].sort()
for i in range(len(p_list)):
    idx = tmpsort[p_list[i]-1].index(y_list[i])
    print((str(p_list[i]).zfill(6) + str(idx).zfill(6)))

Submission status: Time Limit Exceeded

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

tmp_list = [[0]for i in range(n)]
p_list = []
y_list = []

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

import copy
tmpsort = copy.deepcopy(tmp_list)
for i in range(len(tmp_list)):
    tmpsort[i].sort()
for i in range(len(p_list)):
    idx = tmpsort[p_list[i]-1].index(y_list[i])
    print((str(p_list[i]).zfill(6) + str(idx).zfill(6)))

Submission status: Time Limit Exceeded

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

tmp_list = [[0]for i in range(n)]
p_list = []
y_list = []

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

import copy
tmpsort = copy.deepcopy(tmp_list)
for i in range(len(tmp_list)):
    tmpsort[i].sort()
for i in range(len(p_list)):
    idx = tmpsort[p_list[i]-1].index(y_list[i])
    print((6-len(str(p_list[i])))*'0' + str(p_list[i]) + (6-len(str(idx)))*'0' + str(idx))

Submission status: Time Limit Exceeded

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

m = {}
ans = []
for i in range(M):
	p, y = map(int, input().split(" "))
	ans.append((p,y))
	m[p] = m.get(p, []) + [y]

l = {}
for k,v in m.items():
	for i, v in enumerate(sorted(v)):
		l[(k, v)]  = "{:0>6}{:0>6}".format(k, i+1)

for k in ans:
	print(l[k])

Submission status: Time Limit Exceeded

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

m = {}
ans = []
for i in range(M):
	p, y = map(int, input().split(" "))
	ans.append((p,y))
	m[p] = m.get(p, []) + [y]

l = {}
for k,v in m.items():
	for i, v in enumerate(sorted(v)):
		l[k, v]  = "{:0>6}{:0>6}".format(k, i+1)

for k in ans:
	print(l[k])

Submission status: Time Limit Exceeded

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

m = {}
ans = []
for i in range(1, N + 1):
	m[i] = []
for i in range(M):
	p, y = map(int, input().split(" "))
	ans.append((p,y))
	m[p] = m[p] + [y]

l = {}
for k,v in m.items():
	for i, v in enumerate(sorted(v)):
		l[k, v]  = "{:0>6}{:0>6}".format(k, i+1)

for k in ans:
	print(l[k])

Submission status: Time Limit Exceeded

Solution code:
import heapq 
[N, M] = [int(x) for x in  input().rstrip().split()]
Ps = []
Ys = []

year_map = {}
for i in range(M):
    [p, y] = [int(x) for x in  input().rstrip().split()]
    Ps.append(p)
    Ys.append(y)
    year_map[y] = i

# 1=<N<10^5
# 1=<M<10^5

aa_map = {}
junban_array = [0 for _ in range(M+1)]


for i in range(M):
    #print(i,Ps[i],Ys[i],aa_map)
    if Ps[i] in aa_map.keys():
        #print(aa_map[Ps[i]],aa_map, Ps[i])
        heapq.heappush(aa_map[Ps[i]],Ys[i])
    else:
        aa_map[Ps[i]] = []
        heapq.heappush(aa_map[Ps[i]],Ys[i])

for pref in aa_map.keys():
    #aa_map[pref].sort()
    Nn = len(aa_map[pref])
    for j in range(1,Nn+1):
        #city_num = year_map[aa_map[pref][j-1]]
        city_num = year_map[heapq.heappop(aa_map[pref])]
#        print(city_num)
        junban_array[city_num] = j

for i in range(M):
    pref_num = Ps[i]
    pref_str = ""
    for j in range(6-len(str(pref_num))):
        pref_str+="0"
    pref_str += str(pref_num)

    bangou = junban_array[i]
    bangou_str = ""
    for j in range(6-len(str(bangou))):
        bangou_str+="0"
    bangou_str += str(bangou)

    print(pref_str+bangou_str)

Submission status: Time Limit Exceeded

Solution code:
[N, M] = [int(x) for x in  input().rstrip().split()]
Ps = []
Ys = []

year_map = {}
for i in range(M):
    [p, y] = [int(x) for x in  input().rstrip().split()]
    Ps.append(p)
    Ys.append(y)
    year_map[y] = i

# 1=<N<10^5
# 1=<M<10^5

aa_map = {}
junban_array = [0 for _ in range(M+1)]


for i in range(M):
    if Ps[i] in aa_map.keys():
        aa_map[Ps[i]].append(Ys[i])
    else:
        aa_map[Ps[i]] = [Ys[i]]

for pref in aa_map.keys():
    aa_map[pref].sort()
    for j in range(1,len(aa_map[pref])+1):
        city_num = year_map[aa_map[pref][j-1]]
        junban_array[city_num] = j

for i in range(M):
    pref_num = Ps[i]
    pref_str = ""
    for j in range(6-len(str(pref_num))):
        pref_str+="0"
    pref_str += str(pref_num)

    bangou = junban_array[i]
    bangou_str = ""
    for j in range(6-len(str(bangou))):
        bangou_str+="0"
    bangou_str += str(bangou)

    print(pref_str+bangou_str)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
c  = [list(map(int,input().split())) for _ in range(m)]
a = [[] for _ in range(n)]
for i in range(m):
    a[c[i][0]-1].append(c[i][1])
for lis in a:
    lis.sort()
for i in range(m):
    upper_len = len(str(c[i][0]))
    if upper_len < 6:
        upper = '0'*(6-upper_len) + str(c[i][0])
    else:
        upper = str(c[i][0])
    index = a[c[i][0]-1].index(c[i][1]) + 1
    lower_len = len(str(index))
    if lower_len < 6:
        lower = '0'*(6-lower_len) + str(index)
    else:
        lower = str(index)
    print(upper+lower)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import numpy as np
# from itertools import *
# from collections import *

# S = input().split()
# N = int(input().split())
# K, N = [int(x) for x in input().split()]

N, M = [int(x) for x in input().split()]
city = []
for n in range(M):
    P, Y = [int(x) for x in input().split()]
    city.append([Y, P, n, 1])

city = np.array(city)
city2 = []

for n in range(N):
    s = np.sort(city[city[:, 1] == n+1][:, 0])
    for ss, nn in zip(s, range(1, len(s)+1)):
        l = list(city[city[:, 0] == ss][0, 0:3])
        l.append(nn)
        city2.append(l)
city2 = np.array(city2)

city2 = city2[np.argsort(city2[:, 2])]

for c in city2:
    print(str(c[1]).zfill(6) + str(c[3]).zfill(6))

Submission status: Time Limit Exceeded

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

def print12(LIST):
    for i in range(12):
        print(LIST[i], end = "")
    print("")

I = input().split()
N = int(I[0])
M = int(I[1])
"""
const N: 県の数
const M: 市の数
"""
Y = [0 for i in range(M)]
P = [0 for i in range(M)]
ANS = [[0 for i in range(12)] for j in range(M)]
"""
list Y: 1~M市の誕生年のリスト
list P: 1~M市の所属県のリスト
2dim_list ANS: 答えの1~M市を表す12桁の数
"""
# 県リスト、年リストに値を入力し、ANSの上6桁も入力
for i in range(M):
    I = input().split()
    P[i] = int(I[0])
    Y[i] = int(I[1])
    Pi = int(I[0])
    for j in range(6):
        ANS[i][5-j] = Pi % 10
        Pi //= 10

Dict_ListP = [{} for i in range(N)]
"""
list Dict_ListP: 県数分、辞書を要素に持つリスト
"""
# Dict_ListP[P[i] - 1] [Y[i]] = iとして
# 県の辞書に年をキーとして市を値に渡したい。
for i in range(M):
    (Dict_ListP[P[i] - 1])[Y[i]] = i


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

for i in range(N):
    Dict_ListP_sorted[i] = sorted(Dict_ListP[i].items())
    for count, j in enumerate(Dict_ListP_sorted[i]):
    #j[0]でキー(年)を取得できる
    #j[1]で市の番号を取得できる
        Rank = count + 1
        for m in range(6):
            ANS[j[1]][11-m] = Rank % 10
            Rank //= 10

for i in range(M):
    print12(ANS[i])

Submission status: Time Limit Exceeded

Solution code:
def print12(LIST):
    for i in range(12):
        print(LIST[i], end = "")
    print("")

I = input().split()
N = int(I[0])
M = int(I[1])
"""
const N: 県の数
const M: 市の数
"""
Y = [0 for i in range(M)]
P = [0 for i in range(M)]
ANS = [[0 for i in range(12)] for j in range(M)]
"""
list Y: 1~M市の誕生年のリスト
list P: 1~M市の所属県のリスト
2dim_list ANS: 答えの1~M市を表す12桁の数
"""
# 県リスト、年リストに値を入力し、ANSの上6桁も入力
for i in range(M):
    I = input().split()
    P[i] = int(I[0])
    Y[i] = int(I[1])
    Pi = int(I[0])
    for j in range(6):
        ANS[i][5-j] = Pi % 10
        Pi //= 10

Dict_ListP = [{} for i in range(N)]
"""
list Dict_ListP: 県数分、辞書を要素に持つリスト
"""
# Dict_ListP[P[i] - 1] [Y[i]] = iとして
# 県の辞書に年をキーとして市を値に渡したい。
for i in range(M):
    (Dict_ListP[P[i] - 1])[Y[i]] = i


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

for i in range(N):
    Dict_ListP_sorted[i] = sorted(Dict_ListP[i].items())
    for count, j in enumerate(Dict_ListP_sorted[i]):
    #j[0]でキー(年)を取得できる
    #j[1]で市の番号を取得できる
        Rank = count + 1
        for m in range(6):
            ANS[j[1]][11-m] = Rank % 10
            Rank //= 10

for i in range(M):
    print12(ANS[i])

Submission status: Time Limit Exceeded

Solution code:
import bisect as bi
n,m = map(int,input().split())
dic={}
P,Y = [],[]
for i in range(m):
  p,y = map(int,input().split())
  P.append(p)
  Y.append(y)
  target = dic.get(p) if dic.get(p)!=None else []
  target.append(y)
  dic[p] = target

def fill_zero(num):
  s = str(num)
  dif = 6-len(s)
  return '0'*dif+s
  
for i in range(m):
  li = sorted(dic[P[i]])
  #ord = li.index(Y[i])+1
  ord = bi.bisect_left(li, Y[i])+1
  print(fill_zero(P[i])+fill_zero(ord))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
dic={}
P,Y = [],[]
for i in range(m):
  p,y = map(int,input().split())
  P.append(p)
  Y.append(y)
  target = dic.get(p) if dic.get(p)!=None else []
  target.append(y)
  dic[p] = target

def fill_zero(num):
  s = str(num)
  dif = 6-len(s)
  return '0'*dif+s
  
for i in range(m):
  li = sorted(dic[P[i]])
  ord = li.index(Y[i])+1
  print(fill_zero(P[i])+fill_zero(ord))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
dic={}
P,Y = [],[]
for i in range(m):
  p,y = map(int,input().split())
  P.append(p)
  Y.append(y)
  target = dic.get(p) if dic.get(p)!=None else []
  target.append(y)
  dic[p] = target

def fill_zero(num):
  s = str(num)
  dif = 6-len(s)
  return '0'*dif+s
  
for i in range(m):
  li = sorted(dic[P[i]])  
  ord = li.index(Y[i])+1
  print(fill_zero(P[i])+fill_zero(ord))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
all_li = []
ma = {}
for _ in range(m):
    p,y = map(int,input().split())
    all_li.append((p,y))
    if p in ma:
        ma[p].append(y)
    else:
        ma[p] = [y]
#print(all_li)
#[[1, 32], [2, 63], [1, 12]]
#print(ma)
# {1: [32, 12], 2: [63]}
sorted_li = [[] for _ in range(n)]
for k,v in ma.items():
    sorted_li[k-1] = list(sorted(v))
#print(ma)
for a in all_li:
    count = sorted_li[a[0]-1].index(a[1]) + 1
    print(str(a[0]).zfill(6)+str(count).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
all_li = []
ma = {}
for _ in range(m):
    p,y = map(int,input().split())
    all_li.append((p,y))
    if p in ma:
        ma[p].append(y)
    else:
        ma[p] = [y]
#print(all_li)
#[[1, 32], [2, 63], [1, 12]]
#print(ma)
# {1: [32, 12], 2: [63]}
sorted_li = [[] for _ in range(n)]
for k,v in ma.items():
    sorted_li[k-1] = list(sorted(v))
#print(ma)
for a in all_li:
    count = sorted_li[a[0]-1].index(a[1]) + 1
    print(str(a[0]).zfill(6)+str(count).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
all_li = []
ma = {}
for _ in range(m):
    p,y = map(int,input().split())
    all_li.append([p,y])
    if p in ma:
        ma[p].append(y)
    else:
        ma[p] = [y]
#print(all_li)
#[[1, 32], [2, 63], [1, 12]]
#print(ma)
# {1: [32, 12], 2: [63]}
sorted_li = [[] for _ in range(n)]
for k,v in ma.items():
    sorted_li[k-1] = list(sorted(v))
#print(ma)
for a in all_li:
    count = sorted_li[a[0]-1].index(a[1]) + 1
    print(str(a[0]).zfill(6)+str(count).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
all_li = []
ma = {}
for _ in range(m):
    p,y = map(int,input().split())
    all_li.append([p,y])
    if p in ma:
        ma[p].append(y)
    else:
        ma[p] = [y]
#print(all_li)
#[[1, 32], [2, 63], [1, 12]]
#print(ma)
# {1: [32, 12], 2: [63]}
sorted_ma = {}
for k,v in ma.items():
    sorted_ma[k] = list(sorted(v))
#print(ma)
for a in all_li:
    count = sorted_ma[a[0]].index(a[1]) + 1
    print(str(a[0]).zfill(6)+str(count).zfill(6))

Submission status: Time Limit Exceeded

Solution code:

N,M = list(map(int, input().split()))
P = []
Y = []
for _ in range(M):
    p,y = list(map(int, input().split()))
    P.append(p)
    Y.append(y)
ans = [[0]*1 for _ in range(N+1)]
data = [[p,y,i] for p,y,i in zip(P,Y,range(1,M+1))]

data.sort(key=lambda x: x[1])

for i in range(M):
    ans[data[i][0]].append(data[i][2])

for j in range(1,M+1):
    a = P[j-1]
    b = ans[a].index(j)
    print(str(a*(10**6)+b).zfill(12))

Submission status: Time Limit Exceeded

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

def main():
    N, M =  [int(i) for i in input().split()]
    cities = []
    for i in range(M):
        p, y = map(int, input().split())
        cities.append([p, y])

    dict = {}
    for p,y in cities:
        if p not in dict.keys():
            dict[p] = [y]
        else:
            dict[p].append(y)
    for p, y in cities:
        s = str(p).zfill(6) + str(sorted(dict[p]).index(y)+1).zfill(6)
        print(s)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from scipy.stats import rankdata
import sys

p_list = []
y_dict = defaultdict(list)


N, M = map(int, sys.stdin.readline().split())

for i in range(M):
    p_i, y_i = map(int, sys.stdin.readline().split())
    p_list.append(p_i - 1)
    y_dict[p_i - 1].append(y_i)

for i in range(N):
    y_dict[i] = rankdata(y_dict[i]).astype(int).tolist()

for i in range(M):
    print(str(p_list[i] + 1).zfill(6) + str(y_dict[p_list[i]].pop(0)).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from scipy.stats import rankdata

p_list = []
y_dict = defaultdict(list)


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

for i in range(M):
    p_i, y_i = map(int, input().split()) 
    p_list.append(p_i - 1)
    y_dict[p_i - 1].append(y_i)

for i in range(N):
    y_dict[i] = rankdata(y_dict[i]).astype(int).tolist()

for i in range(M):
    print(str(p_list[i] + 1).zfill(6) + str(y_dict[p_list[i]].pop(0)).zfill(6))

Submission status: Time Limit Exceeded

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

si = [[0]for i in range(n+1)]
a = []


import bisect

for i in range(m):
    p,y = map(int,input().split())
    a.append([p,y])
    bisect.insort_left(si[p],y)




for i in range(m):
    ans = bisect.bisect_right(si[a[i][0]],a[i][1]) - 1
    print('0'*(6-len(str(a[i][0]))) + str(a[i][0]) + '0'*(6-len(str(ans))) + str(ans))

Submission status: Time Limit Exceeded

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

si = [[0]for i in range(n+1)]
a = []


import bisect

for i in range(m):
    p,y = map(int,input().split())
    a.append([p,y])
    bisect.insort_left(si[p],y)




for i in range(m):
    ans = bisect.bisect_right(si[a[i][0]],a[i][1]) - 1
    print('0'*(6-len(str(a[i][0]))) + str(a[i][0]) + '0'*(6-len(str(ans))) + str(ans))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
n, m = map(int, input().split())
l = []
dic = defaultdict(list)
for i in range(m):
    p, y = map(int, input().split())
    dic[p].append(y)
    l.append([p, y])
for key, value in dic.items():
    dic[key] = sorted(value)
for p, y in l:
    print(str(p).zfill(6)+str(dic[p].index(y)+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right
import sys

readline = sys.stdin.readline
n, m = map(int, readline().split())
ken = [list() for _ in range(n)]
PY = []
for _ in range(m):
    p, y = map(int, readline().split())
    PY.append((p, y))
    ken[p-1].append(y)
for i in range(n):
    ken[i].sort()
for p, y in PY:
    print(str(p).zfill(6) + str(ken[p-1].index(y)+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

res = []

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

for ar in pref:
    ar.sort()

for pre, year in res:
    p = str(pre + 1)
    p_zero = p.zfill(6)
    y = str(pref[pre].index(year) + 1)
    y_zero = y.zfill(6)
    print(p_zero + y_zero)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
anslist = [[0]*3for i in range(m)]
for i in range(m):
  p,y = map(int,input().split())
  anslist[i][0] = p
  anslist[i][2] = y
  cnt = 0
  if i >= 1:
    for j in range(i):
      if anslist[j][0] == p and anslist[j][2] > y:
        anslist[j][1] += 1
      elif anslist[j][0] == p and anslist[j][2] < y:
        cnt += 1
    else:anslist[i][1] = cnt + 1
  else:
    anslist[i][1] = 1
for i in range(m):
  #print(anslist[i][0],anslist[i][1])
  print('0'*(6-len(str(anslist[i][0])))+str(anslist[i][0])+'0'*(6-len(str(anslist[i][1])))+str(anslist[i][1]))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import bisect
x,y=map(int,input().split())
citylist=deque([deque() for x in range(x)])
inputlist=deque()
arucity=deque()
old=0
for a in range(y):
    s,t=map(int,input().split())
    citylist[s-1].append(t)
    inputlist.append(s)
    inputlist.append(t)
    if old != s:
        arucity.append(s)
        old = s

for a in arucity:
    citylist[a-1]=sorted(citylist[a-1])
for b in range(y):
    e=inputlist.popleft()
    print("%06d%06d" %(e,(bisect.bisect(citylist[e-1],inputlist.popleft()))))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import bisect
x,y=map(int,input().split())
citylist=deque([deque() for x in range(x)])
inputlist=deque()
arucity=deque()
old=0
for a in range(y):
    s,t=map(int,input().split())
    citylist[s-1].append(t)
    inputlist.append(s)
    inputlist.append(t)
    if old != s:
        arucity.append(s)
        old = s

for a in arucity:
    citylist[a-1]=sorted(citylist[a-1])
for b in range(y):
    e=inputlist.popleft()
    print("{:06}{:06}".format(e,(bisect.bisect(citylist[e-1],inputlist.popleft()))))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
x,y=map(int,input().split())
citylist=deque([deque() for x in range(x)])
inputlist=deque()
arucity=deque()
old=0
for a in range(y):
    s,t=map(int,input().split())
    citylist[s-1].append(t)
    inputlist.append(s)
    inputlist.append(t)
    if old != s:
        arucity.append(s)
        old = s

for a in arucity:
    citylist[a-1]=sorted(citylist[a-1])
for b in range(y):
    e=inputlist.popleft()
    print("{:06}{:06}".format(e,(citylist[e-1].index(inputlist.popleft())+1)))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
x,y=map(int,input().split())
citylist=deque([deque() for x in range(x)])
inputlist=deque()
arucity=set()
for a in range(y):
    s,t=map(int,input().split())
    citylist[s-1].append(t)
    inputlist.append(s)
    inputlist.append(t)
    arucity.add(s)
for a in arucity:
    citylist[a-1]=sorted(citylist[a-1])
for b in range(y):
    e=inputlist.popleft()
    print("{:06}{:06}".format(e,(citylist[e-1].index(inputlist.popleft())+1)))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
x,y=map(int,input().split())
citylist=deque([[] for x in range(x)])
inputlist=deque()
arucity=set()
for a in range(y):
    s,t=map(int,input().split())
    citylist[s-1].append(t)
    inputlist.append(s)
    inputlist.append(t)
    arucity.add(s)
for a in arucity:
    citylist[a-1].sort()
for b in range(y):
    e=inputlist.popleft()
    print("{:06}{:06}".format(e,(citylist[e-1].index(inputlist.popleft())+1)))

Submission status: Time Limit Exceeded

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

N_count = [[] for k in range(N)]
ans = []
for i in range(M):
    p = P_Y[i][0]
    y = P_Y[i][1]
    p_zero = str(p).zfill(6)
    N_count[p-1].append(y)
    ans.append(p_zero)

for k in range(N):
    N_count[k].sort()

for i in range(M):
    p = P_Y[i][0]
    t = N_count[p-1].index(P_Y[i][1]) + 1
    t_zero = str(t).zfill(6)
    print(ans[i]+t_zero)

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort_left
N, M=map(int, input().split())
A=[]
Y=[[] for _ in range(N)] #県
for i in range(M):
  p,y=map(int, input().split())
  A.append((p,y))
  Y[p-1].append(y)

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

for i in range(M):
  p,y=A[i]
  y=str(Y[p-1].index(y)+1)
  p=str(p)
  ans="0"*(6-len(p))+p+"0"*(6-len(y))+y
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort_left
N, M=map(int, input().split())
A=[]
Y=[[] for _ in range(N)] #県
for i in range(M):
  p,y=map(int, input().split())
  A.append((p,y))
  Y[p-1].append(y)
  Y[p-1].sort()


for i in range(M):
  p,y=A[i]
  y=str(Y[p-1].index(y)+1)
  p=str(p)
  ans="0"*(6-len(p))+p+"0"*(6-len(y))+y
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort_left
N, M=map(int, input().split())
A=[]
Y=[[] for _ in range(N)] #県
for i in range(M):
  p,y=map(int, input().split())
  A.append((p,y))
  insort_left(Y[p-1],y)

for i in range(M):
  p,y=A[i]
  y=str(Y[p-1].index(y)+1)
  p=str(p)
  ans="0"*(6-len(p))+p+"0"*(6-len(y))+y
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M=map(int, input().split())
A=[]
Y=[[] for _ in range(N)] #県
for i in range(M):
  p,y=map(int, input().split())
  A.append((p,y))
  Y[p-1].append(y)

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

for i in range(M):
  p,y=A[i]
  y=str(Y[p-1].index(y)+1)
  p=str(p)
  ans="0"*(6-len(p))+p+"0"*(6-len(y))+y
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M=map(int, input().split())
A=[]
Y=[[] for _ in range(N)] #県
for i in range(M):
  p,y=map(int, input().split())
  A.append((p,y))
  Y[p-1].append(y)
  
for i in range(M):
  p,y=A[i]
  y=str(sorted(Y[p-1]).index(y)+1)
  p=str(p)
  ans="0"*(6-len(p))+p+"0"*(6-len(y))+y
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
base = []
base_1 = []
key = {}
ans_str = []
ans_n = []

for i in range(m):
  p,y = map(int,input().split())
  base.append([p,y])
  base_1.append([p,y])
  
base_1.sort(key = lambda x:x[1])

for i in range(m):
  p_str = str(base_1[i][0])
  len_p = len(list(p_str))
  temp = "p"+p_str
  
  if temp not in key:
    key[temp] = 1
    count = str(1)
  else :
    a = key[temp]
    key[temp] = a + 1
    count = str(key[temp])
    
  len_count = len(list(count))
  
  for j in range(6-len_p):
    p_str = "0" + p_str
    
  for j in range(6-len_count):
    count = "0" + count
    
  ans_str.append(p_str + count)
  ans_n.append(base_1[i])

for i in range(m):
  print(ans_str[ans_n.index(base[i])])

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a = []
b = [[] for i in range(n)]
for i in range(m):
	p, y = map(int, input().split())
	a.append([p,y])
	b[p-1].append(y)
dic = {}
for i in range(n):
	b[i].sort()
	for j,k in enumerate(b[i]):
		dic[k] = j+1

for i, j in a:
	x = b[i-1].index(j)
	print ("{:06d}".format(i) + "{:06d}".format(dic[j]))

Submission status: Time Limit Exceeded

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

for i, j in a:
	b[i-1].sort()
	x = b[i-1].index(j)
	print ("{:06d}".format(i) + "{:06d}".format(x+1))

Submission status: Time Limit Exceeded

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

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

for i, j in a:
	x = b[i-1].index(j)
	p = "00000" + str(i)
	p = p[-6:]
	y = "00000" + str(x+1)
	y = y[-6:]
	print (p+y)
	#print ("{:06d}".format(i) + "{:06d}".format(x+1))

Submission status: Time Limit Exceeded

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

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

for i, j in a:
	x = b[i-1].index(j)
	print ("{:06d}".format(i) + "{:06d}".format(x+1))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
py = [list(map(int,input().split())) for i in range(m)]
pref = [[0] for i in range(n)]

for i in py:
    pref[i[0]-1].append(i[1])
for i in range(n):
    pref[i].sort()
for i in py:
    print("{0:06}{1:06}".format(i[0],pref[i[0]-1].index(i[1])))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
py = [list(map(int,input().split())) for i in range(m)]
pref = [[0] for i in range(n)]
# print(pref)
# print(py)

for i in py:
    pref[i[0]-1].append(i[1])
for i in range(n):
    pref[i].sort()
# print(pref)
for i in py:
    print("{0:06}{1:06}".format(i[0],pref[i[0]-1].index(i[1])))
    # print(i[0],pref[i[0]-1].index(i[1]))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
d=[0]*M
res = []
for i in range(M):
    P,Y = map(int,input().split())
    res.append((P,Y,i))
c=1
for i in sorted(res):
    x = str(i[0])
    tmp = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)
    if(tmp in d):
        c+=1
    else:
        c = 1
    d[i[2]] = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)

for i in d:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
d=[0]*M
res = []
for i in range(M):
    P,Y = map(int,input().split())
    res.append((P,Y,i))
c=1
for i in sorted(res):
    x = str(i[0])
    y = str(i[1])
    tmp = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)
    if(tmp in d):
        c+=1
        d[i[2]] = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)
    else:
        c = 1
        d[i[2]] = (6-len(x))*'0'+x+(6-len(str(c)))*'0'+str(c)

for i in d:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import bisect
    n, m, *py = map(int, open(0).read().split())
    d = [[] for _ in range(n + 1)]
    for i, j in zip(*[iter(py)] * 2):
        bisect.insort_left(d[i], j)

    ans = ''
    for i, j in zip(*[iter(py)] * 2):
        k = bisect.bisect_right(d[i], j)
        id = str(i).zfill(6) + str(k).zfill(6)
        ans += id + '\n'

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import bisect
    n, m, *py = map(int, open(0).read().split())
    d = [[] for _ in range(n + 1)]
    for i, j in zip(*[iter(py)] * 2):
        d[i].append(j)

    for i in d:
        i.sort()

    ans = ''
    for i, j in zip(*[iter(py)] * 2):
        k = bisect.bisect_right(d[i], j)
        id = str(i).zfill(6) + str(k).zfill(6)
        ans += id + '\n'

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, m, *py = map(int, open(0).read().split())
    d = [[] for _ in range(n+1)]
    for i,j in zip(*[iter(py)]*2):
        d[i].append(j)
        d[i].sort()

    ans = ''
    for i, j in zip(*[iter(py)] * 2):
        k = d[i].index(j) + 1
        id = str(i).zfill(6) + str(k).zfill(6)
        ans += id + '\n'

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, m, *py = map(int, open(0).read().split())
    d = [[] for _ in range(n+1)]
    for i,j in zip(*[iter(py)]*2):
        d[i].append(j)

    for i in d:
        i.sort()

    ans = ''
    for i, j in zip(*[iter(py)] * 2):
        k = d[i].index(j) + 1
        id = str(i).zfill(6) + str(k).zfill(6)
        ans += id + '\n'

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

for i in range(M):
    p, y = ite[i]
    #print(P[p])
    num = P[p].index(y)+1
    idx = '{}{}'.format(str(p).zfill(6), str(num).zfill(6))
    print(idx)

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

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

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


for i in range(m):
    tmp = arr[p[i]-1]
    index = 1
    for l in tmp:
        if l == y[i]:
            break
        else:
            index += 1
    s_p = str(p[i]).zfill(6)
    y_p = str(index).zfill(6)
    print(s_p + y_p)

Submission status: Time Limit Exceeded

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

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

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


for i in range(m):
    tmp = arr[p[i]-1]
    index = 1
    for j in range(len(tmp)):
        if tmp[j] == y[i]:
            break
        else:
            index += 1
    s_p = str(p[i]).zfill(6)
    y_p = str(index).zfill(6)
    print(s_p + y_p)