Buggy python submission (verdict: Runtime Error):
# coding: utf-8

N, M = map(int, input().split())
p_dict = {}
for i in range(M):
	p, y = map(int, input().split())
	if p not in p_dict.keys():
		p_dict[p] = [[y, p, i]]
    else:
		# yとp元の順番を入れとく
		p_dict[p].append([y, p, i])
ans = []
for p in p_dict.keys():
    p_dict[p].sort()
    for i in range(len(p_dict[p])):
        # 昇順で並べたときの順番を入れとく
        p_dict[p][i].append(i+1)
        ans.append(p_dict[p][i])
# ans = [y, p, input_index, sorted_index]
ans.sort(key=lambda x: x[2])
for y, p, oi, si in ans:
    print("{:06d}{:06d}".format(p, si))


Fixed submission:
#coding: utf-8
from copy import deepcopy


def main():
    N, M = map(int, input().split())
    p_dict = {}
    for i in range(M):
        p, y = map(int, input().split())
        if p not in p_dict.keys():
            p_dict[p] = [[y, p, i]]
        else:
            #yとp元の順番を入れとく
            p_dict[p].append([y, p, i])
    ans = []
    for p in p_dict.keys():
        p_dict[p].sort()
        for i in range(len(p_dict[p])):
            #昇順で並べたときの順番を入れとく
            p_dict[p][i].append(i+1)
            ans.append(p_dict[p][i])
    #ans = [y, p, input_index, sorted_index]
    ans.sort(key=lambda x: x[2])
    for y, p, oi, si in ans:
        print("{:06d}{:06d}".format(p, si))
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#coding: utf-8
from copy import deepcopy
def main():
	N, M = map(int, input().split())
	p_list = []
	p_dict = {}
	for i in range(M):
		p, y = map(int, input().split())
		p_list.append([p, y])
		if p not in p_dict.keys():
			p_dict[p] = [y]
		else:
			p_dict[p].append(y)
	for p in p_dict.keys():
		p_dict[p].sort()
	for i in range(M):
		s1 = p_list[i][0]	
		#s1 = str(p_list[i][0])
		s2 = p_dict[p_list[i][0]].index(p_list[i][1])
		print("{:06d}{:06d}".format(s1, s2+1))
		#print("0" * (6 - len(str(s1))) + str(s1) + "0" * (6 - len(str(s2))) + str(s2 + 1))
	#print(p_dict)
if __name__ == "__main__":
	main()

Fixed submission:
#coding: utf-8
from copy import deepcopy


def main():
    N, M = map(int, input().split())
    p_dict = {}
    for i in range(M):
        p, y = map(int, input().split())
        if p not in p_dict.keys():
            p_dict[p] = [[y, p, i]]
        else:
            #yとp元の順番を入れとく
            p_dict[p].append([y, p, i])
    ans = []
    for p in p_dict.keys():
        p_dict[p].sort()
        for i in range(len(p_dict[p])):
            #昇順で並べたときの順番を入れとく
            p_dict[p][i].append(i+1)
            ans.append(p_dict[p][i])
    #ans = [y, p, input_index, sorted_index]
    ans.sort(key=lambda x: x[2])
    for y, p, oi, si in ans:
        print("{:06d}{:06d}".format(p, si))
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#coding: utf-8
from copy import deepcopy
def main():
	N, M = map(int, input().split())
	p_list = []
	p_dict = {}
	for i in range(M):
		p, y = map(int, input().split())
		p_list.append([p, y])
		if p not in p_dict.keys():
			p_dict[p] = [y]
		else:
			p_dict[p].append(y)
	for p in p_dict.keys():
		p_dict[p].sort()
	for i in range(M):
		s1 = p_list[i][0]	
		#s1 = str(p_list[i][0])
		s2 = p_dict[p_list[i][0]].index(p_list[i][1])
		print("{:06d}{:06d}".format(s1, s2+1))
		#print("0" * (6 - len(str(s1))) + str(s1) + "0" * (6 - len(str(s2))) + str(s2 + 1))
	#print(p_dict)
if __name__ == "__main__":
	main()

Fixed submission:
#coding: utf-8
from copy import deepcopy


def main():
    N, M = map(int, input().split())
    p_dict = {}
    for i in range(M):
        p, y = map(int, input().split())
        if p not in p_dict.keys():
            p_dict[p] = [[y, p, i]]
        else:
            #yとp元の順番を入れとく
            p_dict[p].append([y, p, i])
    ans = []
    for p in p_dict.keys():
        p_dict[p].sort()
        for i in range(len(p_dict[p])):
            #昇順で並べたときの順番を入れとく
            p_dict[p][i].append(i+1)
            ans.append(p_dict[p][i])
    #ans = [y, p, input_index, sorted_index]
    ans.sort(key=lambda x: x[2])
    for y, p, oi, si in ans:
        print("{:06d}{:06d}".format(p, si))
if __name__ == "__main__":
    main()