Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
p, y = [0 for _ in range(m)], [0 for _ in range(m)]
year_list = [[] for _ in range(n)]
for i in range(m):
    p[i], y[i] = map(int, input().split())
    year_list[p[i] - 1].append(y[i])
for j in range(n):
    year_list[j].sort()
for i in range(m):
    x = year_list[p[i] - 1].index(y[i]) + 1
    print(str(p[i]).zfill(6) + str(x).zfill(6))

Fixed submission:
import bisect
def index(alist, x):
    i = bisect.bisect_left(alist, x)
    if i != len(alist) and alist[i] == x:
        return i
    raise ValueError

n, m = map(int, input().split())
p, y = [0] * m, [0] * m
year_list = [[] for _ in range(n)]
for i in range(m):
    p[i], y[i] = map(int, input().split())
    year_list[p[i] - 1].append(y[i])
for j in range(n):
    year_list[j].sort()
for i in range(m):
    x = index(year_list[p[i] - 1], y[i]) + 1
    print(str(p[i]).zfill(6) + str(x).zfill(6))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
p, y = [0] * m, [0] * m
sort_year = [0] * m
initial_index, count_city = [0] * n, [0] * n
tmp_counter = [0] * n 
for i in range(m):
    p[i], y[i] = map(int, input().split())
    count_city[p[i] - 1] += 1
for j in range(1, n):
  	initial_index[j] = initial_index[j] + count_city[j - 1]
for i in range(m):
    sort_year[initial_index[p[i] - 1] + tmp_counter[p[i] - 1]] = y[i]
    tmp_counter[p[i] - 1] += 1
for j in range(n):
    sort_year[initial_index[j] : initial_index[j] + count_city[j - 1]].sort()
for i in range(m):
    x = sort_year.index(y[i]) - initial_index[p[i] - 1] + 1
    print(str(p[i]).zfill(6) + str(x).zfill(6))


Fixed submission:
import bisect
def index(alist, x):
    i = bisect.bisect_left(alist, x)
    if i != len(alist) and alist[i] == x:
        return i
    raise ValueError

n, m = map(int, input().split())
p, y = [0] * m, [0] * m
year_list = [[] for _ in range(n)]
for i in range(m):
    p[i], y[i] = map(int, input().split())
    year_list[p[i] - 1].append(y[i])
for j in range(n):
    year_list[j].sort()
for i in range(m):
    x = index(year_list[p[i] - 1], y[i]) + 1
    print(str(p[i]).zfill(6) + str(x).zfill(6))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
p, y = [0] * m, [0] * m
sort_year = [0] * m
initial_index, count_city = [0] * n, [0] * n
tmp_counter = [0] * n 
for i in range(m):
    p[i], y[i] = map(int, input().split())
    count_city[p[i] - 1] += 1
for j in range(1, n):
  	initial_index[j] = initial_index[j] + count_city[j - 1]
for i in range(m):
    sort_year[initial_index[p[i] - 1] + tmp_counter[p[i] - 1]] = y[i]
    tmp_counter[p[i] - 1] += 1
for j in range(n):
    sort_year[initial_index[j] : initial_index[j] + count_city[j - 1]].sort()
for i in range(m):
    x = sort_year.index(y[i]) - initial_index[p[i] - 1] + 1
    print(str(p[i]).zfill(8) + str(x).zfill(8))


Fixed submission:
import bisect
def index(alist, x):
    i = bisect.bisect_left(alist, x)
    if i != len(alist) and alist[i] == x:
        return i
    raise ValueError

n, m = map(int, input().split())
p, y = [0] * m, [0] * m
year_list = [[] for _ in range(n)]
for i in range(m):
    p[i], y[i] = map(int, input().split())
    year_list[p[i] - 1].append(y[i])
for j in range(n):
    year_list[j].sort()
for i in range(m):
    x = index(year_list[p[i] - 1], y[i]) + 1
    print(str(p[i]).zfill(6) + str(x).zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
p, y = [0] * m, [0] * m
year_list = [[] for _ in range(n)]
for i in range(m):
    p[i], y[i] = map(int, input().split())
    year_list[p[i] - 1].append(y[i])
for j in range(n):
    year_list[j].sort()
for i in range(m):
    x = year_list[p[i] - 1].index(y[i]) + 1
    print(str(p[i]).zfill(6) + str(x).zfill(6))

Fixed submission:
import bisect
def index(alist, x):
    i = bisect.bisect_left(alist, x)
    if i != len(alist) and alist[i] == x:
        return i
    raise ValueError

n, m = map(int, input().split())
p, y = [0] * m, [0] * m
year_list = [[] for _ in range(n)]
for i in range(m):
    p[i], y[i] = map(int, input().split())
    year_list[p[i] - 1].append(y[i])
for j in range(n):
    year_list[j].sort()
for i in range(m):
    x = index(year_list[p[i] - 1], y[i]) + 1
    print(str(p[i]).zfill(6) + str(x).zfill(6))