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())
py = []
od = [[]*1 for i in range(n)]

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

for i in range(0,n):
    od[i].sort()

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

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

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

Submission status: Time Limit Exceeded

Solution code:
a,b = [[int(x)] for x in input().split()]

list = [1for i in range(b[0])]

c = []
d = []


for i in range(b[0]):
    e,f = [[int(x)] for x in input().split()]

    c.append(e[0])
    d.append(f[0])

for i in range(b[0]):
    for q in range(i):
        if c[q] == c[i]:
            if d[q] > d[i]:
                list[q] += 1
            else:
                list[i] += 1


for i in range(b[0]):
    print(str(c[i]).zfill(6)+str(list[i]).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
a,b = [[int(x)] for x in input().split()]

list = [1for i in range(b[0])]

c = []
d = []


for i in range(b[0]):
    e,f = [[int(x)] for x in input().split()]

    c.append(e[0])
    d.append(f[0])

for i in range(b[0]):
    for q in range(i):
        if c[q] == c[i]:
            if d[q] > d[i]:
                list[q] += 1
            else:
                list[i] += 1


for i in range(b[0]):
    print(str(c[i]).rjust(6, '0')+str(list[i]).rjust(6, '0'))

Submission status: Time Limit Exceeded

Solution code:
a,b = [[int(x)] for x in input().split()]

list = [1for i in range(b[0])]

c = []
d = []

i = 0
while i < b[0]:
    e,f = [[int(x)] for x in input().split()]

    c.append(e[0])
    d.append(f[0])

    q = 0
    while q < i:
        if c[q] == c[i]:
            if d[q] > d[i]:
                list[q] += 1
            else:
                list[i] += 1

        q += 1
    i += 1

for i in range(b[0]):
    print(str(c[i]).rjust(6, '0')+str(list[i]).rjust(6, '0'))

Submission status: Time Limit Exceeded

Solution code:
a,b = [[int(x)] for x in input().split()]

list = [1for i in range(b[0])]

c = []
d = []

for i in range(b[0]):
    e,f = [[int(x)] for x in input().split()]

    c.append(e[0])
    d.append(f[0])

    for q in range(i):
        if c[q] == c[i]:
            if d[q] > d[i]:
                list[q] += 1
            else:
                list[i] += 1

for i in range(b[0]):
    print(str(c[i]).rjust(6, '0')+str(list[i]).rjust(6, '0'))

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int, input().split())

list = [1for i in range(b)]

c = []
d = []

for i in range(b):
    e,f = map(int, input().split())
    c.append(e)
    d.append(f)

    for q in range(i):
        if c[q] == c[i]:
            if d[q] > d[i]:
                list[q] += 1
            else:
                list[i] += 1

for i in range(b):
    print(str(c[i]).rjust(6, '0')+str(list[i]).rjust(6, '0'))

Submission status: Time Limit Exceeded

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    if not b+1:
        return 0
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    if arr[b]<x:
        return b+1
    elif arr[a]>x:
        return a
    return b

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

citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])
    y[0]=10**12+y[0]*10**6

for city in citys:
    if len(city)!=0:
        for i in range(len(city)):
            dic[city[i]]=i+1
    
for y in ys:
    number=str(y[0]+dic[y[1]])[-12:]
    print(number)

Submission status: Time Limit Exceeded

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    if not b+1:
        return 0
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    if arr[b]<x:
        return b+1
    elif arr[a]>x:
        return a
    
    return b

N,M=map(int,input().split(' '))
ys=[tuple(map(int,input().split(' '))) for i in range(M)]

citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])

for city in citys:
    if len(city)!=0:
        for i in range(len(city)):
            dic[city[i]]=i+1
        
for y in ys:
    number=str(10**12+y[0]*10**6+dic[y[1]])[-12:]
    print(number)

Submission status: Time Limit Exceeded

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    if not b+1:
        return 0
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    if arr[b]<x:
        return b+1
    elif arr[a]>x:
        return a
    
    return b

N,M=map(int,input().split(' '))
ys=[tuple(map(int,input().split(' '))) for i in range(M)]

citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])

for city in citys:
    for i in range(len(city)):
        dic[city[i]]=i+1
        
for y in ys:
    number=str(10**12+y[0]*10**6+dic[y[1]])[-12:]
    print(number)

Submission status: Time Limit Exceeded

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    if b==-1:
        return 0
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    
    if arr[b]<x:
        return b+1
    elif arr[a]>x:
        return a
    
    return b

N,M=map(int,input().split(' '))
ys=[tuple(map(int,input().split(' '))) for i in range(M)]

citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])

for city in citys:
    for i in range(len(city)):
        dic[city[i]]=i+1
        
for y in ys:
    number=str(10**12+y[0]*10**6+dic[y[1]])[-12:]
    print(number)

Submission status: Time Limit Exceeded

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    if b==-1:
        return 0
    elif arr[b]<x:
        return b+1
    elif arr[a]>x:
        return a
    
    return b

N,M=map(int,input().split(' '))
ys=[tuple(map(int,input().split(' '))) for i in range(M)]

citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])

for city in citys:
    for i in range(len(city)):
        dic[city[i]]=i+1
        
for y in ys:
    number=str(10**12+y[0]*10**6+dic[y[1]])[-12:]
    print(number)

Submission status: Time Limit Exceeded

Solution code:
def ins(arr, x):
    b=len(arr)-1
    a=0
    while (b-a)>1:
        m=int((a+b)/2)
        if x>=arr[m]:
            a=m
        else:
            b=m      
    if b==-1:
        return 0
    elif arr[b]<x:
        return b+1
    elif arr[a]>x:
        return a
    
    return b

N,M=map(int,input().split(' '))
ys=[tuple(map(int,input().split(' '))) for i in range(M)]

citys=[[] for i in range(N)]
dic={}
for y in ys:
    ci=y[0]-1
    index=ins(citys[ci], y[1])
    citys[ci].insert(index, y[1])

for city in citys:
    for i in range(len(city)):
        dic[city[i]]=i+1
        
for y in ys:
    number=str(10**6+y[0])[-6:]+str(10**6+dic[y[1]])[-6:]
    print(number)

Submission status: Time Limit Exceeded

Solution code:
nums = list(map(int, input().split()))
n = nums[0]
m = nums[1]

codes = []
prefectures = []


class Prefecture:
    def __init__(self, id, list):
        self.id = id
        self.list = list


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

for code in codes:
    exist = False
    for prefecture in prefectures:
        if code[0] == prefecture.id:
            prefecture.list.append(code[1])
            exist = True
            break
    if not exist:
        prefectures.append(Prefecture(code[0], [code[1]]))

for prefecture in prefectures:
    prefecture.list = sorted(prefecture.list)

for code in codes:
    for prefecture in prefectures:
        if code[0] == prefecture.id:
            for i in range(len(prefecture.list)):
                if code[1] == prefecture.list[i]:
                    print(str(code[0]).zfill(6) + str(i+1).zfill(6))
                    break
            break

Submission status: Time Limit Exceeded

Solution code:
nums = list(map(int, input().split()))
n = nums[0]
m = nums[1]

codes = []
prefectures = []


class Prefecture:
    def __init__(self, id, list):
        self.id = id
        self.list = list


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

for code in codes:
    exist = False
    for prefecture in prefectures:
        if code[0] == prefecture.id:
            prefecture.list.append(code[1])
            exist = True
            break
    if not exist:
        prefectures.append(Prefecture(code[0], [code[1]]))

for prefecture in prefectures:
    prefecture.list = sorted(prefecture.list)

for code in codes:
    for prefecture in prefectures:
        if code[0] == prefecture.id:
            for i in range(len(prefecture.list)):
                if code[1] == prefecture.list[i]:
                    print(str(code[0]).zfill(6) + str(i+1).zfill(6))
            break

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

def main():
    N, M = map(int, input().split())
    PY = [tuple(map(int, input().split())) for _ in range(M)]
    d = defaultdict(list)
    for p, y in PY:
        d[p].append(y)
    D = dict()
    for p in d:
        D[p] = dict()
        seq = sorted(d[p])
        index = [seq.index(v) for v in d[p]]
        for _p, i in zip(d[p], index):
            D[p][_p] = i
    for p, y in PY:
        print(str(p).zfill(6) + str(D[p][y] + 1).zfill(6))



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

from collections import defaultdict

def main():
    N, M = map(int, input().split())
    PY = [tuple(map(int, input().split())) for _ in range(M)]
    d = defaultdict(list)
    for p, y in PY:
        d[p].append(y)
    for p in d:
        seq = sorted(d[p])
        d[p] = seq
    for p, y in PY:
        print(str(p).zfill(6) + str(d[p].index(y) + 1).zfill(6))



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

for i in range(m):
    myset.add(array[i][0])


for i in myset:
    array_temp = [[array[j][0], array[j][1], j] for j in range(m) if array[j][0] == i]
    array_temp = sorted(array_temp, key=lambda x: x[1])
    for j in range(len(array_temp)):
        array_temp[j][1] = j + 1
    array_ans.extend(array_temp)

array_ans = sorted(array_ans, key=lambda x: x[2])


for i in range(m):
    out = '%06d' % array_ans[i][0] + '%06d' % array_ans[i][1]
    print(out)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N, M = map(int, input().split())

    p_and_y = list()
    prefMap = {}
    for i in range(M):
        P, Y = map(int, input().split())

        p_and_y.append((P, Y))

        if P in prefMap:
            prefMap[P].append(Y)
        else:
            prefMap[P] = [Y]

    for shiList in prefMap.values():
        shiList.sort()

    for P, Y in p_and_y:
        left = str(P).zfill(6)

        right = prefMap[P].index(Y) + 1
        right = str(right).zfill(6)

        print(left + right)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
P = []
Y = []
D = {}
for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    if p not in D:
        D[p] = [(i, y)]
    else:
        D[p].append((i, y))

for p in P:
    D[p].sort(key=lambda p: p[1])

ans = []
for p, pairs in D.items():
    for x, pair in enumerate(pairs):
        x += 1
        i = pair[0]
        y = pair[1]
        out = "{0:06d}{1:06d}".format(p, x)
        ans.append((i, out))
ans.sort(key=lambda p: p[0])
for an in ans:
    print(an[1])

Submission status: Time Limit Exceeded

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

N, M = map(int, input().split())
inputs, cities = [], [[] for _ in range(N)]
for i in range(M):
    P, Y = map(int, input().split())
    inputs.append((P, Y))
    cities[P - 1].append(Y)

cities = list(map(sorted, cities))

for i in range(M):
    P, Y = inputs[i]
    idx = cities[P - 1].index(Y)
    print('%06d' % P + '%06d' % (idx + 1))

Submission status: Time Limit Exceeded

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

N, M = map(int, input().split())
inputs, cities = [], [[] for _ in range(N)]
for i in range(M):
    P, Y = map(int, input().split())
    inputs.append((P, Y))
    cities[P - 1].append(Y)

cities = [sorted(city) for city in cities]

for i in range(M):
    P, Y = inputs[i]
    idx = cities[P - 1].index(Y)
    print('%06d' % P + '%06d' % (idx + 1))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
inputs, cities = [], [[] for _ in range(N)]
for i in range(M):
    P, Y = map(int, input().split())
    inputs.append((P, Y))
    cities[P - 1].append(Y)

cities = [sorted(city) for city in cities]

for i in range(M):
    P, Y = inputs[i]
    idx = cities[P - 1].index(Y)
    print('%06d' % P + '%06d' % (idx + 1))

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter
import copy

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

cities = [[int(j) for j in input().split()] for i in range(M)]
# print(cities)
original_cities = copy.deepcopy(cities)
city_idies = [0] * len(original_cities)


# 最初のキー:県でソート
sorted_cities = sorted(cities)

for i in range(1, N+1):
    i_cities = []
    cp_sorted_cities = copy.deepcopy(sorted_cities)
    for idx, city in enumerate(cp_sorted_cities):
        if city[0] == i:
            i_cities.append(city)
            sorted_cities.remove(city)
        else:
            break
    # i県の市i_citiesを2つ目のキー:市の誕生年でソート
    sorted_i_cities = sorted(i_cities, key=itemgetter(1))
    # print(sorted_i_cities)
    for idx, city in enumerate(sorted_i_cities):
        city_idx = "{:0=6}{:0=6}".format(i, idx+1)
        city_idies[original_cities.index(city)] = city_idx


for idx in city_idies:
    print(idx)

Submission status: Time Limit Exceeded

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

li2 = []
li3 = []

for i in range(m):
    li2.append(li[i][0]*10**6)

for i in range(1,n+1):
    for j in range(m):
        if li[j][0] == i:
            li3.append(li[j][1])
    li3.sort()
    for j in range(m):
        for k in range(len(li3)):
            if li[j][1] == li3[k]:
                li2[j] += k+1
    li3.clear()

for i in li2:
    if i % 10**10 != i:
        i = "0" + str(i)
        print(i)
    elif i % 10**9 != i:
            i = "00" + str(i)
            print(i)
    elif i % 10**8 != i:
        i = "000" + str(i)
        print(i)
    elif i % 10**7 != i:
        i = "0000" + str(i)
        print(i)
    elif i % 10**6 != i:
        i = "00000" + str(i)
        print(i)
    else:
        print(i)

Submission status: Time Limit Exceeded

Solution code:
import copy
N,M = map(int,input().split())
p_list = []
y_list = []
for i in range(M):
  p,y = map(int,input().split())
  p_list.append(p)
  y_list.append(y)
p_list_sorted = []
y_list_sorted = []
  
  

for i in range(max(p_list)):
  y_tmp = []
  for j in range(M):
    if i+1 == p_list[j]:
      p_list_sorted.append(i+1)
      y_tmp.append(y_list[j])
  y_tmp.sort()
  for k in range(len(y_tmp)):
    y_list_sorted.append(y_tmp[k])
    
for i in range(M):
  N = p_list.count(p_list[i])
  ind = p_list_sorted.index(p_list[i])
  for j in range(N):
    if y_list[i] == y_list_sorted[j+ind]:
      y = str(j+1).zfill(6)
      break
  p = str(p_list[i]).zfill(6)
  print(p+y)

Submission status: Time Limit Exceeded

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


kens = [[]for i in range(n)]
for dat in data:
    index = dat[0]
    kens[index-1].append(dat[1])

for i in range(n):
    kens[i] = sorted(kens[i])


for dat in data:
    ken = dat[0]
    year = dat[1]
    rank = kens[ken-1].index(year)+1
    leng1 = 6 - len(str(ken))
    leng2 = 6 - len(str(rank))
    st = ''
    st2 = ''
    for i in range(leng1):
        st += '0'
    for i in range(leng2):
        st2 += '0'
    st+= str(ken)
    st2 += str(rank)
    print(st + st2)

Submission status: Time Limit Exceeded

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

def st(a):
	b = list(str(a))
	while len(b) <= 5:
		b.insert(0,'0')
	c= ''.join(b)
	return c

for y in arr:
	k = 1
	for j in arr:
		if y[0] == j[0] and y[1] > j[1]:
			k += 1
	print('{}{}'.format(st(y[0]), st(k)))

Submission status: Time Limit Exceeded

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

def st(a):
	b = list(str(a))
	while len(b) <= 5:
		b.insert(0,'0')
	c= ''.join(b)
	return c

for y in arr:
	k = 1
	for j in arr:
		if y[0] == j[0] and y[1] > j[1]:
			k += 1
			
	print('{}{}'.format(st(y[0]), st(k)))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
p = list()
d = dict()
for i in range(M):
    inp = list(map(int, input().split()))
    p.append(inp)
    if inp[0] in d:
        d[inp[0]].append(inp[1])
    else:
        d[inp[0]] = [inp[1]]
for i in d:
    d[i].sort()
for i, j in p:
    print("{:06d}{:06d}".format(i, d[i].index(j)+1))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
p = list()
d = dict()
for i in range(M):
    inp = [int(i) for i in input().split()]
    p.append(inp)
    if inp[0] in d:
        d[inp[0]].append(inp[1])
    else:
        d[inp[0]] = [inp[1]]
for i in d:
    d[i] = sorted(d[i])
for i, j in p:
    print("{:06d}{:06d}".format(i, d[i].index(j)+1))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
dic = {}
for i in range(n): # TODO: 辞書の初期化のやり方を調べる。
    dic[i+1] = []

cities = []
for _ in range(m):
    i = input()
    cities.append(i)
    pi, mi = map(int, i.split())
    dic[pi].append(mi)

# 県の数だけ
for i in range(n):
    dic[i+1].sort() # listを更新する。戻り値はnone


# 都市の数だけ
for i in range(m):
    p, m = map(int, cities[i].split())
    print(str(p).zfill(6)+str(dic[p].index(m)+1).zfill(6))
    # print("としIは", p, "に", dic[p].index(m)+1,"ばんめ")

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
p = list()
y = list()
d = dict()
for i in range(M):
    inp_p, inp_y = map(int, input().split())
    p.append(inp_p)
    y.append(inp_y)
    if inp_p in d:
        d[inp_p].append(inp_y)
    else:
        d[inp_p] = [inp_y]
# for i in d:
#     d[i] = sorted(d[i])
for i, j in zip(p, y):
    d[i] = sorted(d[i])
    print("{:06d}{:06d}".format(i, d[i].index(j)+1))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
p = list()
y = list()
d = dict()
for i in range(M):
    inp_p, inp_y = map(int, input().split())
    p.append(inp_p)
    y.append(inp_y)
    if inp_p in d:
        d[inp_p].append(inp_y)
    else:
        d[inp_p] = [inp_y]
for i in d:
    d[i] = sorted(d[i])
for i, j in zip(p, y):
    print("{:06d}{:06d}".format(i, d[i].index(j)+1))

Submission status: Time Limit Exceeded

Solution code:
p_y = []
p_y_dict = {}

N, M = map(int, input().split())
for i in range(M):
  p, y = map(int, input().split())
  p_y.append([p, y])
  p_y_dict.setdefault(p, []).append(y)

sorted_py_dict = {p: sorted(y) for p, y in p_y_dict.items()}

for a in p_y: 
  print(str(a[0]).zfill(6) + str(sorted_py_dict[a[0]].index(a[1]) + 1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
p_y = []
p_y_dict = {}

N, M = map(int, input().split())
for i in range(M):
  p, y = map(int, input().split())
  p_y.append([p, y])
  p_y_dict.setdefault(p, []).append(y)

sorted_py_dict = {p: sorted(y) for p, y in p_y_dict.items()}

for a in p_y: 
  #print(sorted_py_dict[1].index(a[1]))
  #print(sorted_py_dict[a[0]]a[1])
  print(('000000' + str(a[0]))[-6:] + ('000000' + str(sorted_py_dict[a[0]].index(a[1]) + 1))[-6:])

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int, input().split())
P=[]
Y=[]
Pre=[]
num={}
for i in range(N):
    Pre.append([])
for i in range(M):
    p,y=map(int, input().split())
    P.append(p)
    Y.append(y)
for i in range(M):
    Pre[P[i]-1].append(Y[i])
for j in range(N):
    Pre[j].sort()
for i in range(N):
    for j in range(len(Pre[i])):
        cell='{:0=6}'.format(i+1)+'{:0=6}'.format(j+1)
        num[Pre[i][j]]=cell
for i in Y:
    for j in num.keys():
        if i == j:
            print(num[j])

Submission status: Time Limit Exceeded

Solution code:
import sys

def solve(M,list_PY,list_Y):
    for i in range(M):
        ken = str(list_PY[i][0]).zfill(6)
        ban = str(list_Y[list_PY[i][0]-1].index(list_PY[i][1])+1).zfill(6)
        print(ken + ban)

def readQuestion():
    N,M = map(int, sys.stdin.readline().strip().split())
    list_PY = []#[[P1,Y1],[P2,Y2]...[Pn,Yn]]のリストを作る用
    list_Y = [[] for i in range(N)]#リストの中にN（県の数）個リストを作る
    
    for i in range(M):
        P,Y = map(int, sys.stdin.readline().strip().split())
        list_PY.append([P,Y])
        list_Y[P-1].append(Y)#「県の名前-1」を添え字にしてリストに入れる

    for i in range(N):
        if len(list_Y[i]) > 1:
            list_Y[i].sort()
            #print("sort",list_Y)
    return (M, list_PY, list_Y)

def main():
    M, list_PY, list_Y = readQuestion()
    answer = solve(M, list_PY, list_Y)
    return answer

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
NofPref, NofCity = map(int, input().split())
Prefs = [list() for i in range(NofPref + 1)]
Cities = [] * NofCity
for i in range(NofCity):
    Cities.append(list(map(int, input().split())))
    Prefs[Cities[i][0]].append(Cities[i][1])
for li in Prefs:
    li.sort()
for li in Cities:
    print(str(li[0]).zfill(6) + str(Prefs[li[0]].index(li[1])+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# N : 県の数, M: 市の数

N, M = map(int, input().split())
ps, ys = [], []

v = [ [] for _ in range(N+1) ]

for i in range(M):
    p, y = map(int, input().split())
    ps += [p]; ys += [y];
    v[p].append(y)

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

for i in range(M):
    print("{:06d}".format(ps[i]), end="")
    print("{:06d}".format(v[ps[i]].index(ys[i])+1))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N,M=map(int, input().split())
L=[ [] for _ in range(N)]
X=[]
for _ in range(M):
    a,b = map(int,input().split())
    L[a-1].append(b)
    X.append({a:b})
Y=[ (sorted(L[_])) for _ in range(N) ]
for i in range(M) :
    for k,v in X[i].items():
        print('%06d%06d' % (k,(Y[k-1].index(v)+1)))

Submission status: Time Limit Exceeded

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

X=[]
for _ in range(M):
    a,b = input().split()
    a=int(a)
    b=int(b)
    L[a-1].append(b)
    X.append({a:b})
Y=[ (sorted(L[_])) for _ in range(N) ]
for i in range(M) :
    for k,v in X[i].items():
        print('%06d%06d' % (k,(Y[k-1].index(v)+1)))

Submission status: Time Limit Exceeded

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

X=[]
for _ in range(M):
    a,b = input().split()
    a=int(a)
    b=int(b)
    L[a-1].append(b)
    X.append({a:b})
Y=[ (sorted(L[_])) for _ in range(N) ]
for i in range(M) :
    for k,v in X[i].items():
        z='%06d' % (Y[k-1].index(v)+1)
        Z='%06d' % k
        print(Z+z)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split( ))
ans = ""
ls_a = []
ls_b = [[] for i in range(n)]
for i in range(m):
    p,y = map(int,input().split( ))
    ls_a.append([p,y])
    ls_b[p-1].append(y)
for i in range(n):
    if len(ls_b[i]) !=0:
        ls_b[i].sort()
for i in range(m):
    ans += str(ls_a[i][0]).zfill(6) + str(ls_b[ls_a[i][0]-1].index(ls_a[i][1])+1).zfill(6)+"\n"
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split( ))
ls_a = []
ls_b = [[] for i in range(n)]
for i in range(m):
    p,y = map(int,input().split( ))
    ls_a.append([p,y])
    ls_b[p-1].append(y)
for i in range(n):
    if len(ls_b[i]) !=0:
        ls_b[i].sort()
for i in range(m):
    print(str(ls_a[i][0]).zfill(6) + str(ls_b[ls_a[i][0]-1].index(ls_a[i][1])+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split( ))
ls_a = []
ls_b = [[] for i in range(n)]
for i in range(m):
    p,y = map(int,input().split( ))
    ls_a.append([p,y])
    ls_b[p-1].append(y)
for i in range(n):
    ls_b[i].sort()
for i in range(m):
    print(str(ls_a[i][0]).zfill(6) + str(ls_b[ls_a[i][0]-1].index(ls_a[i][1])+1).zfill(6))

Submission status: Time Limit Exceeded

Solution code:
import sys
def solve(n,m,a,b):
    ans = ""
    #b = [[] for i in range(n)]
    #for s1,s2 in a:
    #    b[s1-1].append(s2)
    for i in range(len(b)):
        b[i].sort()
    for i in range(m):
        ans += str(a[i][0]).zfill(6) + str(b[a[i][0]-1].index(a[i][1])+1).zfill(6) + "\n"
    return ans

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    M = int(ws[1])
    ls_PY = []
    ls_b = [[] for i in range(N)]
    for i in range(M):
        p,y = map(int, sys.stdin.readline().strip().split())
        ls_PY.append([p,y])
        ls_b[p-1].append(y)
    #ls_PY = [list(map(int, sys.stdin.readline().strip().split())) for j in range(M)]
    return (N, M, ls_PY, ls_b)

def main():
    N, M, ls_PY, ls_b = readQuestion()
    answer = solve(N, M, ls_PY, ls_b)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
ken_shi_list = input().split()
ken_num = int(ken_shi_list[0])
shi_num = int(ken_shi_list[1])

shi_list = []
nen_list = [[] for i in range(ken_num) ]


for i in range(shi_num):
    shi_list.append(input().split())
    nen_list[int(shi_list[i][0])-1].append( int(shi_list[i][1]) )


for i in range(ken_num):
   nen_list[i-1].sort()


for i in range(shi_num):
    ken = int(shi_list[i][0])
    nen = int(shi_list[i][1])
    for j in range( len(nen_list[ken-1]) ):
        if nen == nen_list[ken-1][j] :
            print( str(ken).zfill(6) + str(j+1).zfill(6) )    
            break

Submission status: Time Limit Exceeded

Solution code:
import sys
def solve(n,m,a):
    ans = ""
    b = [[] for i in range(n)]
    for s1,s2 in a:
        b[s1-1].append(s2)
    for i in range(len(b)):
        b[i].sort()
    zero = ["00000","0000","000","00","0",""]
    for i in range(m):
        ken = str(a[i][0])
        ban = str(b[a[i][0]-1].index(a[i][1])+1)
        ans += zero[len(ken)-1] + ken + zero[len(ban)-1] + ban + "\n"
    
    return ans 
def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    M = int(ws[1])
    ls_PY = [list(map(int, sys.stdin.readline().strip().split())) for j in range(M)]
    return (N, M, ls_PY)

def main():
    N, M, ls_PY = readQuestion()
    answer = solve(N, M, ls_PY)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def solve(n,m,a):
    ans = ""
    b = [[] for i in range(n)]
    for s1,s2 in a:
        b[s1-1].append(s2)
    for i in range(len(b)):
        b[i].sort()
    for i in range(m):
        ans += str(a[i][0]).zfill(6) + str(b[a[i][0]-1].index(a[i][1])+1).zfill(6) + "\n"
    
    return ans 
def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    M = int(ws[1])
    ls_PY = [list(map(int, sys.stdin.readline().strip().split())) for j in range(M)]
    return (N, M, ls_PY)

def main():
    N, M, ls_PY = readQuestion()
    answer = solve(N, M, ls_PY)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def solve(n,m,a):
    ans = ""
    bb = {i+1:[] for i in range(n)}
    for [s1,s2] in a:
        bb[s1].append(s2)
    b = [i for i in bb.values()]
    for i in range(len(b)):
        b[i].sort()
    for i in range(m):
        ans += str(a[i][0]).zfill(6) + str(b[a[i][0]-1].index(a[i][1])+1).zfill(6) + "\n"
    
    return ans 
def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    M = int(ws[1])
    ls_PY = [list(map(int, sys.stdin.readline().strip().split())) for j in range(M)]
    return (N, M, ls_PY)

def main():
    N, M, ls_PY = readQuestion()
    answer = solve(N, M, ls_PY)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# import sys
 
# N:県, M:市
N, M = list(map(int, input().split()))

A = {}
# {ken: [(city_no, city_year)],...}

res = [None] * M

for i in range(M):
  k, y = list(map(int, input().split()))
  if k in A.keys():
    A[k].append((i, y))
  else:
    A[k] = [(i, y)]

# print(A)
# A: {県番号: {市1の年:市1のindex, 市2の年:市2のindex}}

for k, v in A.items():
  # sort by year
  c_list = sorted(v, key=lambda x: x[1])
  counter = 1
  for c in c_list:
    res[c[0]] = (k, counter)
    counter += 1

for x in res:
  print("{:0>6}{:0>6}".format(x[0], x[1]))