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 = map(int, input().split())
order = []
result = {}
city = {}
for i in range(M):
    P, Y = map(int, input().split())
    order.append(Y)
    if P in city:
        city[P].append(Y)
    else:
        city[P] = [Y]

for v in city.values():
    v.sort()

for k, v in city.items():
    i = 1
    for e in v:
        order[order.index(e)] = str(k).zfill(6) + str(i).zfill(6)
        i += 1

for r in order:
    print(r)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
order = []
result = {}
city = {}
for i in range(M):
    P, Y = map(int, input().split())
    order.append(Y)
    if P in city:
        city[P].append(Y)
    else:
        city[P] = [Y]

s_city = dict(sorted(city.items()))
for v in s_city.values():
    v.sort()

for k, v in city.items():
    i = 1
    for e in v:
        order[order.index(e)] = str(k).zfill(6) + str(i).zfill(6)
        i += 1

for r in order:
    print(r)

Submission status: Time Limit Exceeded

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

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

   
for i in range(m):
    first_num="000000"
    last_num="000000"
    
    chushutsu_list=[j for j in X if j[0]==X[i][0]]
    chushutsu_list.sort(key=lambda x:x[1])
    
    count=chushutsu_list.index(X[i])+1
    
    
    first_num=first_num[:6-len(str(X[i][0]))]+str(X[i][0])
    last_num=last_num[:6-len(str(count))]+str(count)
    print(first_num+last_num)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
dic = {}
raw = []
dic[1] = []
for i in range(M):
  P, Y = map(int, input().split())
  raw.append([P, Y])
  dic.setdefault(P, list())
  dic[P].append(Y)
for i in dic.keys():
    dic[i].sort()
for i in range(M):
  P, Y = raw[i]
  ind = dic[P].index(Y)
  P = "{0:06d}".format(P)
  Y = "{0:06d}".format(ind+1)
  print(P+Y)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
dic = {}
raw = []
dic[1] = []
for i in range(M):
  P, Y = map(int, input().split())
  raw.append([P, Y])
  dic.setdefault(P, list())
  dic[P].append(Y)
for i in dic.keys():
  try:
    dic[i].sort()
  except:
    continue
for i in range(M):
  P, Y = raw[i]
  ind = dic[P].index(Y)
  P = "{0:06d}".format(P)
  Y = "{0:06d}".format(ind+1)
  print(P+Y)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
dic = {}
raw = []
dic[1] = []
for i in range(M):
  P, Y = map(int, input().split())
  raw.append([P, Y])
  dic.setdefault(P, list())
  dic[P].append(Y)
for i in range(1, N+1):
  try:
    dic[i].sort()
  except:
    continue
for i in range(M):
  P, Y = raw[i]
  ind = dic[P].index(Y)
  P = "{0:06d}".format(P)
  Y = "{0:06d}".format(ind+1)
  print(P+Y)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
dic = {}
raw = []
dic[1] = []
for i in range(M):
  P, Y = map(int, input().split())
  raw.append([P, Y])
  if not dic.get(P):
    dic[P] = list() 
  dic[P].append(Y)
for i in range(1, N+1):
  try:
    dic[i].sort()
  except:
    continue
for i in range(M):
  P, Y = raw[i]
  ind = dic[P].index(Y)
  P = "{0:06d}".format(P)
  Y = "{0:06d}".format(ind+1)
  print(P+Y)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
from collections import defaultdict

n,m = input().split()
n = int(n)
m = int(m)
P,Y = [],[]
for _ in range(m):
	p,y = input().split()
	P.append(p)
	Y.append(y)

P = [int(p) for p in P]
Y = [int(y) for y in Y]

sorted = defaultdict(list)

for i in range(m):
	sorted[P[i]].append(Y[i])

for k in sorted.keys():
	sorted[k].sort()

for i in range(m):
	print("{0:06}{1:06}".format(P[i], sorted[P[i]].index(Y[i])+1))

Submission status: Time Limit Exceeded

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	x,y = map(int,input().split())	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# 3
# hoge
# foo
# bar
# n=int(input())
# string_list=[input() for i in range(n)]
# N, M = map(int,input().split())

# P, Y = [], []
# for _ in range(M):
#     P_i, Y_i = = map(int,input().split())
#     P.append(P_i)
#     Y.append(Y_i)

N, M = map(int, input().split())
py = {}
all_py = []
for _ in range(M):
  p, y = map(int, input().split())
  if not p in py:
    py[p] = []
  py[p].append(y)
  all_py.append([p, y])

sort_p = {}
for k, v in all_py:
  if not k in sort_p:
    sort_p[k] = sorted(py[k])
  print("{}{}".format(str(k).zfill(6), str((sort_p[k]).index(v)+1).zfill(6)))

Submission status: Time Limit Exceeded

Solution code:
n, m = [int(i) for i in input().split()]
pre = []
year = []
year_order = [0 for i in range(m)]
each_arr = [[] for i in range(n)]
each_sort = [[] for i in range(n)]

for i in range(m):
    p, y = [int(i) for i in input().split()]
    pre.append(p)
    year.append(y)


for i in range(m):
    each_arr[pre[i]-1].append(year[i])

for j in range(n):
    each_sort[j] = sorted(each_arr[j])

for i in range(m):
    year_order[i] = each_sort[pre[i]-1].index(each_arr[pre[i]-1][0])+1
    each_arr[pre[i]-1].remove(each_arr[pre[i]-1][0])

for i in range(m):
    print("{0:06d}".format(pre[i])+"{0:06d}".format(year_order[i]))

Submission status: Time Limit Exceeded

Solution code:
n, m = [int(i) for i in input().split()]
pre = []
year = []
year_order = [0 for i in range(m)]
each_arr = [[] for i in range(n)]
each_sort = [[] for i in range(n)]

for i in range(m):
    p, y = [int(i) for i in input().split()]
    pre.append(p)
    year.append(y)


for i in range(m):
    each_arr[pre[i]-1].append(year[i])

for j in range(n):
    each_sort[j] = sorted(each_arr[j])

for i in range(m):
    year_order[i] = each_sort[pre[i]-1].index(each_arr[pre[i]-1][0])+1
    each_arr[pre[i]-1].remove(each_arr[pre[i]-1][0])

pre = [format(str(i), '0>6') for i in pre]
year_order = [format(str(i), '0>6') for i in year_order]

for i in range(m):
    print(pre[i]+year_order[i])

Submission status: Time Limit Exceeded

Solution code:
n, m = [int(i) for i in input().split()]
pre = []
year = []
year_order = [0 for i in range(m)]
each_arr = [[] for i in range(n)]
each_sort = [[] for i in range(n)]
each_order = [[] for i in range(n)]

for i in range(m):
    p, y = [int(i) for i in input().split()]
    pre.append(p)
    year.append(y)


for i in range(m):
    each_arr[pre[i]-1].append(year[i])

for j in range(n):
    each_sort[j] = sorted(each_arr[j])
    each_order[j] = [each_sort[j].index(i)+1 for i in each_arr[j]]

for i in range(m):
    year_order[i] = each_order[pre[i]-1][0]
    each_order[pre[i]-1].remove(each_order[pre[i]-1][0])

pre = [format(str(i), '0>6') for i in pre]
year_order = [format(str(i), '0>6') for i in year_order]

for i in range(m):
    print(pre[i]+year_order[i])

Submission status: Time Limit Exceeded

Solution code:
n, m = (int(i) for i in input().split())
yl = []
[yl.append([]) for _ in range(n)]
dl = []

for _ in range(m):
    p, y = (int(i) for i in input().split())
    yl[p-1].append(y)
    dl.append((p, y))

[yl[i].sort() for i in range(n)]

for p, y in dl:
    print("{:0>6}{:0>6}".format(p, yl[p-1].index(y)+1))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int,input().split())
l = []
for i in range(m):
    l.append(list(map(int,input().split())))
l2 = l.copy()
l2.sort()
p = 0
l3 = []
for i in l2:
    if i[0] != p:
        p = i[0]
        x = 1
    else:
        x += 1
    l3.append(str(i[0]).zfill(6)+ str(x).zfill(6))
for i in l:
    print(l3[l2.index(i)])

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
p = []
tmp = [[] for i in range(n+1)]
for i in range(m):
  p.append(list(map(int, input().split())))
  tmp[p[i][0]].append(p[i][1])
for i in range(n):
  tmp[i+1].sort()
for i in range(m):
  print('{:0=6}{:0=6}'.format(p[i][0], tmp[p[i][0]].index(p[i][1])+1))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
 
N, M = (int(i) for i in input().split())
input_list = [[int(i) for i in input().split()] for i in range(M)] 
 
m_list = [[] for j in range(N+1)]
 
for inputs in input_list:
    m_list[inputs[0]].append(inputs[1])
 
for arr in m_list:
    arr.sort()
 
for inputs in input_list:
    num = m_list[inputs[0]].index(inputs[1]) + 1
    print(str(inputs[0]).zfill(6) + str(num).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
 
N, M = (int(i) for i in input().split())
input_list = [[int(i) for i in input().split()] for i in range(M)] 
 
m_list = [[0] for j in range(N+1)]
 
for inputs in input_list:
    m_list[inputs[0]].append(inputs[1])
 
for arr in m_list:
    arr.sort()
 
for inputs in input_list:
    num = m_list[inputs[0]].index(inputs[1])
    print(str(inputs[0]).zfill(6) + str(num).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
 
N, M = (int(i) for i in input().split())
input_list = [[int(i) for i in input().split()] for i in range(M)] 
 
m_list = [[] for j in range(N+1)]
 
for inputs in input_list:
    m_list[inputs[0]].append(inputs[1])
 
for arr in m_list:
    arr.sort()
    arr.insert(0,-10000)
 
for inputs in input_list:
    num = m_list[inputs[0]].index(inputs[1])
    print(str(inputs[0]).zfill(6) + str(num).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import sys
 
input = sys.stdin.readline
 
N, M = (int(i) for i in input().split())
input_list = [[int(i) for i in input().split()] for i in range(M)] 
 
m_list = [[] for j in range(N)]
 
for inputs in input_list:
    m_list[inputs[0]-1].append(inputs[1])
 
for arr in m_list:
    arr.sort()
 
for inputs in input_list:
    num = m_list[inputs[0]-1].index(inputs[1]) + 1
    print(str(inputs[0]).zfill(6) + str(num).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

input = sys.stdin.readline

N, M = (int(i) for i in input().split())
input_list = [[int(i) for i in input().split()] for i in range(M)] 

m_list = [[] for j in range(N)]

for inputs in input_list:
    m_list[inputs[0]-1].append(inputs[1])

for arr in m_list:
    arr.sort()

for inputs in input_list:
    num = m_list[inputs[0]-1].index(inputs[1]) + 1
    print(str(inputs[0]).zfill(6) + str(num).zfill(6))

Submission status: Time Limit Exceeded

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

m_list = [[] for j in range(N)]

for inputs in input_list:
    m_list[inputs[0]-1].append(inputs[1])

for arr in m_list:
    arr.sort()

for inputs in input_list:
    num = m_list[inputs[0]-1].index(inputs[1]) + 1
    print(str(inputs[0]).zfill(6) + str(num).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
p = []
y = []
out = []
for _ in range(m):
    pi, yi = map(int, input().split())
    p.append(pi)
    y.append(yi)
    out.append(-1)

for i in range(n):
    index_list = []
    for j in range(len(p)):
        if p[j] == i+1:
            index_list.append([y[j], y.index(y[j])])
    index_list.sort()
    for k in range(len(index_list)):
        out[index_list[k][1]] = str(i+1).zfill(6) + str(k+1).zfill(6)

for i in range(len(out)):
    print(out[i])

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
index = 0
listForL = []
listForL2 = []
while index < m:
    p, y = map(int, input().split())
    listForL.append([p, y])
    listForL2.append([p, y])
    index+=1

listForL2.sort()
listForId=[]
index2 =0
count = 0
before=0
while index2 < len(listForL2):
    if before!=listForL2[index2][0]:
        count=1
        before = listForL2[index2][0]
    else:
        count+=1
    mojiR=str(listForL2[index2][0])
    mojiL=str(count)
    index3=0
    if len(mojiR)==1:
        mojiR="00000"+mojiR
    elif len(mojiR)==2:
        mojiR = "0000"+mojiR
    elif len(mojiR)==3:
        mojiR = "000"+mojiR
    elif len(mojiR)==4:
        mojiR = "00"+mojiR
    elif len(mojiR)==5:
        mojiR = "0"+mojiR
    if len(mojiL) == 1:
        mojiL = "00000"+mojiL
    elif len(mojiL) == 2:
        mojiL = "0000"+mojiL
    elif len(mojiL) == 3:
        mojiL = "000"+mojiL
    elif len(mojiL) == 4:
        mojiL = "00"+mojiL
    elif len(mojiR) == 5:
        mojiL = "0"+mojiL
    index2+=1
    listForId.append(mojiR+mojiL)

index5=0
while index5 < len(listForL):
    targetI = listForL2.index(listForL[index5])
    print(listForId[targetI])
    index5+=1

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
index = 0
listForL = []
listForL2 = []
while index < m:
    p, y = map(int, input().split())
    listForL.append([p, y])
    listForL2.append([p, y])
    index+=1

listForL2.sort()
listForId=[]
index2 =0
count = 0
before=0
while index2 < len(listForL2):
    if before!=listForL2[index2][0]:
        count=1
        before = listForL2[index2][0]
    else:
        count+=1
    mojiR=str(listForL2[index2][0])
    mojiL=str(count)
    index3=0
    while index3 < 6:
        if len(mojiR)< 6:
            mojiR="0"+mojiR
        elif len(mojiR)==6:
            break
        index3+=1
    index4=0
    while index4 < 6:
        if len(mojiL)< 6:
            mojiL="0"+mojiL
        elif len(mojiL)==6:
            break
        index4+=1
    index2+=1
    listForId.append(mojiR+mojiL)

index5=0
while index5 < len(listForL):
    targetI = listForL2.index(listForL[index5])
    print(listForId[targetI])
    index5+=1

Submission status: Time Limit Exceeded

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

# ken = {p[0] for p in PY}
# ken_d = {k:[] for k in ken}
ken_d = [[] for _ in range(N+1)]

for p in PY:
    # print(p)
    ken_d[p[0]].append(p[1])

for k in range(N+1):
    ken_d[k].sort()

for p in PY:
    x = ken_d[p[0]].index(p[1]) + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))

Submission status: Time Limit Exceeded

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

# ken = {p[0] for p in PY}
# ken_d = {k:[] for k in ken}
ken_d = {k:[] for k in range(1, N+1)}

for p in PY:
    # print(p)
    ken_d[p[0]].append(p[1])

for k in ken_d.keys():
    ken_d[k].sort()

for p in PY:
    x = ken_d[p[0]].index(p[1]) + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))

Submission status: Time Limit Exceeded

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

ken = {p[0] for p in PY}
ken_d = {k:[] for k in ken}

for p in PY:
    # print(p)
    ken_d[p[0]].append(p[1])

for k in ken_d.keys():
    ken_d[k].sort()

for p in PY:
    x = ken_d[p[0]].index(p[1]) + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
PY = [list(map(int,input().split())) for i in range(M)]
ken = {p[0] for p in PY}
ken_d = {k:[p[1] for p in PY if p[0] == k] for k in ken}

for k in ken_d.keys():
    ken_d[k].sort()

for p in PY:
    x = ken_d[p[0]].index(p[1]) + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
PY = [list(map(int,input().split())) for i in range(M)]
ken = {p[0] for p in PY}
ken_d = {k:[]  for k in ken}

for p in PY:
    ken_d[p[0]].append(p[1])

for k in ken_d.keys():
    ken_d[k].sort()

for p in PY:
    x = ken_d[p[0]].index(p[1]) + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
PY = []
ken_d = {k:[]  for k in range(1, N+1)}

for i in range(M):
    p = list(map(int,input().split()))
    PY.append(p)
    ken_d[p[0]].append(p[1])

for k in ken_d.keys():
    ken_d[k].sort()

for p in PY:
    x = ken_d[p[0]].index(p[1]) + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))

Submission status: Time Limit Exceeded

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

ken_d = {k:[]  for k in range(1, N+1)}

for p in PY:
    ken_d[p[0]].append(p[1])

for k in ken_d.keys():
    ken_d[k].sort()

for p in PY:
    x = ken_d[p[0]].index(p[1]) + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))

Submission status: Time Limit Exceeded

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

ken_d = {k:[]  for k in range(1, N+1)}

for p in PY:
    ken_d[p[0]].append(p[1])

for k in ken_d.keys():
    ken_d[k].sort()

for p in PY:
    x = ken_d[p[0]].index(p[1]) + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))

Submission status: Time Limit Exceeded

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

for i in range(M):
    ans_list[P_list[i]].append(Y_list[i])
for i in range(N + 1):
    ans_list[i].sort()

for i in range(M):
    print('0' * (6 - len(str(P_list[i]))), end = "")
    print(P_list[i], end = "")
    print('0' * (6 - len(str(ans_list[P_list[i]].index(Y_list[i]) + 1))), end="")
    print(ans_list[P_list[i]].index(Y_list[i]) + 1)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
Data_dict = {}
for i in range(M):
  City, Year = input().split()
  Data = [int(Year), i]
  if list(Data_dict.keys()).count(City) == 0:
    Data_dict[City] = [Data]
  else:
    Data_dict[City].append(Data)
KeyList = list(Data_dict.keys())
Data_list = []
for key in KeyList:
  Data_dict[key] = sorted(Data_dict[key], key=lambda x: x[0])
  for i in range(len(Data_dict[key])):
    Data_dict[key][i].append(i + 1)
    Data = [int(key)] + Data_dict[key][i]
    Data_list.append(Data)
Data_sorted = sorted(Data_list, key=lambda x:x[2])
for Data in Data_sorted:
  ans = '{city:06}{i:06}'.format(city=Data[0], i=Data[3])
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

prefecture_d = defaultdict(list)

prefecture_num,data_num = map(int,input().split())
py_data = []
for _ in range(data_num):
    prefecture,year = map(int,input().split())
    py_data.append([prefecture,year])
    prefecture_d[prefecture].append(year)
for data in py_data:
    prefecture,year = data
    id = sorted(prefecture_d[prefecture]).index(year) + 1
    print("0"*(6-len(str(prefecture))) + str(prefecture) +"0"*(6-len(str(id))) + str(id))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
py = []
for i in range(m):
    py.append(list(map(int, input().split())))
check = [[] for i in range(n)]
for i in py:
    check[i[0]-1].append(i[1])
for i in range(len(check)):
    check[i] = sorted(check[i])
for i in py:
    x = (check[i[0]-1].index(i[1]) + 1)
    ans = str(i[0]).zfill(6) + str(x).zfill(6)
    print(ans)

Submission status: Time Limit Exceeded

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

dict = {}
for i in range(m):
    if not p[i] in dict.keys():
        dict[p[i]] = [(y[i],i)]
    else:
        dict[p[i]].append((y[i],i))

for k,v in dict.items():
  dict[k] = sorted(v)

for i in range(m):
  for k,v in dict.items():
    for j in range(len(v)):
        if i == v[j][1]:
            id = '0'*(6-len(str(k)))+str(k)
            id = id + '0'*(6-len(str(j)))+str(j+1)
            print(id)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
pys = []
pdict = {}
for _ in range(m):
    py = list(map(int, input().split()))
    pys.append(py)
    if py[0] not in pdict:
        pdict[py[0]] = []
    pdict[py[0]].append(py[1])

for l in pdict.values():
    l.sort()

for py in pys:
    p = '{0:06d}'.format(py[0])
    index = pdict[py[0]].index(py[1]) + 1
    i = '{0:06d}'.format(index)
    print(p+i)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
pys = []
for _ in range(m):
    pys.append(list(map(int, input().split())))
 
pdict = {}
for py in pys:
    if py[0] not in pdict:
        pdict[py[0]] = []
    pdict[py[0]].append(py[1])
    pdict[py[0]].sort()
 
for py in pys:
    index = pdict[py[0]].index(py[1]) + 1
    print('{0:06d}'.format(py[0])+'{0:06d}'.format(index))

Submission status: Time Limit Exceeded

Solution code:
import bisect

n, m = map(int, input().split())
pys = []
pdict = {}
for _ in range(m):
    py = list(map(int, input().split()))
    pys.append(py)
    if py[0] not in pdict:
        pdict[py[0]] = []
    bisect.insort(pdict[py[0]], py[1])

for py in pys:
    p = str(py[0]).zfill(6)
    index = pdict[py[0]].index(py[1]) + 1
    i = str(index).zfill(6)
    print("{p}{i}".format(p=p, i=i))

Submission status: Time Limit Exceeded

Solution code:
import bisect

n, m = map(int, input().split())
pys = []
pdict = {}
for _ in range(m):
    py = list(map(int, input().split()))
    pys.append(py)
    if py[0] not in pdict:
        pdict[py[0]] = []
    bisect.insort(pdict[py[0]], py[1])

for py in pys:
    p = str(py[0]).zfill(6)
    index = pdict[py[0]].index(py[1]) + 1
    i = str(index).zfill(6)
    print(p+i)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

pdict = {}
for py in pys:
    if py[0] not in pdict:
        pdict[py[0]] = []
    bisect.insort(pdict[py[0]], py[1])

for py in pys:
    p = str(py[0]).zfill(6)
    index = pdict[py[0]].index(py[1]) + 1
    i = str(index).zfill(6)
    print(p+i)

Submission status: Time Limit Exceeded

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

pdict = {}
for py in pys:
    if py[0] not in pdict:
        pdict[py[0]] = []
    pdict[py[0]].append(py[1])
    pdict[py[0]].sort()

for py in pys:
    p = str(py[0]).zfill(6)
    index = pdict[py[0]].index(py[1]) + 1
    i = str(index).zfill(6)
    print(p+i)

Submission status: Time Limit Exceeded

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

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

    pref_sorted = sorted(enumerate(pref), key=lambda x: x[1])

    res = ['' for _ in range(M)]
    for i in range(1, N + 1):
        c = 1
        for j, (p, y) in pref_sorted:
            if i == p:
                res[j] = str(p).zfill(6) + str(c).zfill(6)
                c += 1
    for r in res:
        print(r)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect
L = list(map(int,input().split()))
N = L[0]
M = L[1]
P = list()
Y = list()
S = list()
for x in range(0,N):
    S.append(list())
for x in range(0,M):
    X = list(map(int,input().split()))
    P.append(X[0])
    Y.append(X[1])
    S[X[0]-1].append(X[1])
    S[X[0]-1] = sorted(S[X[0]-1])
for y in range(0,M):
    n = 0
    n = bisect(S[P[y]-1],Y[y])
    nstr = str(n)
    Pstr = str(P[y])
    while len(nstr) < 6:
        nstr = '0' + nstr
    while len(Pstr) < 6:
        Pstr = '0' + Pstr
    number = Pstr + nstr
    print(number)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jan  4 20:10:14 2019

@author: Yamazaki Kenichi
"""
import bisect

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

a = [[] for i in range(N)]
for j in range(M):
    a[C[j][0]-1].append(C[j][1])

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

ans = []
for j in range(M):
    l = '0'*(6-len(str(C[j][0])))+str(C[j][0])
    r1 = a[C[j][0]-1].index(C[j][1])+1
    r = '0'*(6-len(str(r1)))+str(str(r1))
    ans = l + r 
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#C
def zeros(n): return [0 for i in range(n)]

N, M = [int(x) for x in input().split()]
city = []
for i in range(M):  
    pref, year = [int(x) for x in input().split()]
    city.append([pref, year, i, ''])

#print(N, M) #
#print(city) #
city.sort()
#print(city) #

nth = zeros(N+1)
for i in range(M):
    pref, year, seq, id = [x for x in city[i]]
    nth[pref] += 1
    city[i][3] = '%06d%06d' % (pref, nth[pref])
    #for j in range(4): print(city[i][j],end=',') #
for i in range(M):
    for j in range(M):
        if city[j][2]==i: print(city[j][3])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jan  4 20:10:14 2019

@author: Yamazaki Kenichi
"""

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

#P,Y = [input().split() for i in range(M)]
#P = [int(P[i]) for i in range(M)]
#Y = [int(Y[i]) for i in range(M)]

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

#counta = [0]*N
a = [[] for i in range(N)]
for j in range(M):
#    for i in range(1,N+1):
#        if C[j][0] == i:
#            counta[i-1] +=1
    a[C[j][0]-1].append(C[j][1])

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

ans = []
for j in range(M):
        
    l = '0'*(6-len(str(C[j][0])))+str(C[j][0])
    r1 = a[C[j][0]-1].index(C[j][1])+1
    r = '0'*(6-len(str(r1)))+str(str(r1))
    ans = l + r 
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jan  4 20:10:14 2019

@author: Yamazaki Kenichi
"""

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

#P,Y = [input().split() for i in range(M)]
#P = [int(P[i]) for i in range(M)]
#Y = [int(Y[i]) for i in range(M)]

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

counta = [0]*N
a = [[] for i in range(N)]
for j in range(M):
    for i in range(1,N+1):
        if C[j][0] == i:
            counta[i-1] +=1
            a[i-1].append(C[j][1])

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

ans = []
for j in range(M):
        
    l = '0'*(6-len(str(C[j][0])))+str(C[j][0])
    r1 = a[C[j][0]-1].index(C[j][1])+1
    r = '0'*(6-len(str(r1)))+str(str(r1))
    ans = l + r 
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left


def index(a, x):
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError

py = [ [] for _ in range(10**5+10)]
p=[]
y=[]
n,m = map(int,input().split())
for _ in range(m):
        pp,yy = map(int,input().split())
        p.append(pp)
        y.append(yy)
        py[pp-1].append(yy)

for i in range(m):
        py[p[i]-1].sort()

for i in range(m):
        id = index(py[p[i]-1],y[i]) + 1
        print("{0:06d}{1:06d}".format(p[i],id))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(' '))
prefectures, years =[0] * (M+1), [0] * (M+1)
for m in range(1, M+1):
    prefectures[m], years[m] = map(int, input().split(' '))

X = []
for m in range(N+1):
    X.append([0])

for m in range(1, M+1):
    X[prefectures[m]].append(years[m])

for n in range(1, N+1):
    X[n].sort()

for m in range(1, M+1):
    pre_id = str(prefectures[m]).zfill(6)
    suf_id = str(X[prefectures[m]].index(years[m])).zfill(6)
    city_id = pre_id + suf_id
    print(city_id)

Submission status: Time Limit Exceeded

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

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

for i in range(M):
    P[i], Y[i] = map(int, input().split())
    PM1[i] = P[i] * 10000000000 + Y[i]

PM2 = sorted(PM1)

# first = [0 for i in range(N)]
# for i in range(N):
#     for j in range(M):
#         if PM2[j] >= (i + 1) * 10000000000:
#             first[i] = j + 1
#             break

first = [0 for i in range(N)]
for i in range(N):
    if i == 0:
        start = 0
    else:
        start = first[i - 1] - 1
    for j in range(start, M):
        if PM2[j] >= (i + 1) * 10000000000:
            first[i] = j + 1
            break

for i in range(M):
    print(str(P[i]).zfill(6) + str(PM2.index(PM1[i])
          + 1 - (first[P[i] - 1] - 1)).zfill(6))

Submission status: Time Limit Exceeded

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

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

for i in range(M):
    P[i], Y[i] = map(int, input().split())
    PM1[i] = P[i] * 10000000000 + Y[i]

PM2 = sorted(PM1)

first = [0 for i in range(N)]
for i in range(N):
    for j in range(M):
        if PM2[j] >= (i + 1) * 10000000000:
            first[i] = j + 1
            break

for i in range(M):
    print(str(P[i]).zfill(6) + str(PM2.index(PM1[i])
          + 1 - (first[P[i] - 1] - 1)).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
li_input = list()
cities = dict()

for i in range(m):
    li_input.append(list(map(int, input().split())))

for pref in {i[0] for i in li_input}:
    t_city = list(filter(lambda x: x[0] == pref, li_input))
    for idx, city in enumerate(sorted(t_city, key=lambda x: x[1]), start=1):
        cities[str(city[1])] = idx

for c in li_input:
    print('{0:06}{1:06}'.format(c[0], cities[str(c[1])]))

Submission status: Time Limit Exceeded

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

a = {}
py = []
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]
    py.append((pi, yi))

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

for pyi in py:
    sp = str(pyi[0]).zfill(6)
    sy = str(a[pyi[0]].index(pyi[1]) + 1).zfill(6)
    print(sp + sy)