Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
city_nums = [[] for i in range(n)]
city_list = []
numbers = []

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_nums[pm-1].append(ym)
    city_list.append([pm,ym])
for i in range(n):
    city_nums[i].sort()
    
for i in range(m):
    cindex = city_nums[city_list[i][0]-1].index(city_list[i][1])
    
    print("{:0=6}{:0=6}".format(city_list[i][0], cindex+1))

Fixed submission:
n, m = list(map(int, input().split()))
city_list = []

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list.append([i,pm,ym])

city_count = {}
city = {}

for i,p,y in sorted(city_list, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 1
    else:
        city_count[p] += 1
    city[i,p] = city_count[p]

for i,p,y in city_list:
    print("{:0=6}{:0=6}".format(p, city[i,p]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
city_nums = [[] for i in range(n)]
city_list = []
numbers = []

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_nums[pm-1].append(ym)
    city_list.append([pm,ym])
for i in range(m):
    cindex = len([1 for x in city_nums[city_list[i][0]-1] if x<city_list[i][1]])
    print("{:0=6}{:0=6}".format(city_list[i][0], cindex+1))

Fixed submission:
n, m = list(map(int, input().split()))
city_list = []

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list.append([i,pm,ym])

city_count = {}
city = {}

for i,p,y in sorted(city_list, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 1
    else:
        city_count[p] += 1
    city[i,p] = city_count[p]

for i,p,y in city_list:
    print("{:0=6}{:0=6}".format(p, city[i,p]))

Buggy python submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
city_list = [[] for i in range(n)]

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list[pm-1].append(ym)

for i in range(n):
    city_list_copied[i].sort()
    for j in range(len(city_list[i])):
        cindex = sum(x <= city_list[i][j] for x in city_list[i])
        print("{:0=6}{:0=6}".format(i+1, cindex))


Fixed submission:
n, m = list(map(int, input().split()))
city_list = []

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list.append([i,pm,ym])

city_count = {}
city = {}

for i,p,y in sorted(city_list, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 1
    else:
        city_count[p] += 1
    city[i,p] = city_count[p]

for i,p,y in city_list:
    print("{:0=6}{:0=6}".format(p, city[i,p]))

Buggy python submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
city_list = [[] for i in range(n)]

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list[pm-1].append(ym)
city_list_copied = copy.deepcopy(city_list)

for i in range(n):
    city_list_copied[i].sort()
    for j in range(len(city_list[i])):
        cindex = sum(x <= city_list[i][j] for x in city_list[i])
        print("{:0=6}{:0=6}".format(i+1, cindex))


Fixed submission:
n, m = list(map(int, input().split()))
city_list = []

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list.append([i,pm,ym])

city_count = {}
city = {}

for i,p,y in sorted(city_list, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 1
    else:
        city_count[p] += 1
    city[i,p] = city_count[p]

for i,p,y in city_list:
    print("{:0=6}{:0=6}".format(p, city[i,p]))