Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(' '))

PreYear = [[] for i in range(N)]
PY = [input().split(' ') for i in range(M)]
for i in range(M):
    Pi, Yi = PY[i]
    PreYear[int(Pi)-1].append(int(Yi))
order = []
for i in range(N):
    order.append(sorted(PreYear[i]))

for i in range(M):
    Pi, Yi = map(int,PY[i])
    count = order[Pi-1].index(Yi)
    count+=1
    print('{0:06d}{1:06d}'.format(Pi,count))


Fixed submission:
from operator import itemgetter


N, M = map(int, input().split(' '))
data = []
for i in range(M):
    Pi, Yi = map(int, input().split(' '))
    data.append([i,Pi,Yi])

sorted_data = sorted(data, key=itemgetter(1,2))

codes = []
prev_p = 0
for i,p,y in sorted_data:
    if p!=prev_p:
        x = 1
        prev_p = p
    else:
        x+=1

    code = '{0:06d}{1:06d}'.format(p,x)
    codes.append([i,code])

sorted_codes = sorted(codes, key = itemgetter(0))

for code in sorted_codes:
    print(code[1])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(' '))

Prenum = [[] for i in range(N)]
PreYear = [1 for i in range(M)]
PY = [input().split(' ') for i in range(M)]
P = [PY[i][0] for i in range(M)]
Y = [PY[i][1] for i in range(M)]

for i in range(M):
    Pi, Yi = map(int,PY[i])

    count = 1
    for j in range(i):
        if P[j] == str(Pi):
            if int(Y[j]) > Yi:
                PreYear[j] = PreYear[j]+1
            else:
                count +=1 
    PreYear[i] = count

for i in range(M):
    Pi, Yi = map(int,PY[i])
    print('{0:06d}{1:06d}'.format(Pi,PreYear[i]))

Fixed submission:
from operator import itemgetter


N, M = map(int, input().split(' '))
data = []
for i in range(M):
    Pi, Yi = map(int, input().split(' '))
    data.append([i,Pi,Yi])

sorted_data = sorted(data, key=itemgetter(1,2))

codes = []
prev_p = 0
for i,p,y in sorted_data:
    if p!=prev_p:
        x = 1
        prev_p = p
    else:
        x+=1

    code = '{0:06d}{1:06d}'.format(p,x)
    codes.append([i,code])

sorted_codes = sorted(codes, key = itemgetter(0))

for code in sorted_codes:
    print(code[1])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(' '))

Prenum = [[] for i in range(N)]
PreYear = [1 for i in range(M)]
PY = [input().split(' ') for i in range(M)]

for i in range(M):
    Pi, Yi = map(int,PY[i])
    Prenum[Pi-1].append(i)

    count = 1
    for j in range(len(Prenum[Pi-1])-1):
        if int(PY[Prenum[Pi-1][j]][1]) > Yi:
            PreYear[Prenum[Pi-1][j]] = PreYear[Prenum[Pi-1][j]]+1
        elif int(PY[Prenum[Pi-1][j]][1]) < Yi:
            count +=1 
    PreYear[i] = count

for i in range(M):
    Pi, Yi = map(int,PY[i])
    print('{0:06d}{1:06d}'.format(Pi,PreYear[i]))

Fixed submission:
from operator import itemgetter


N, M = map(int, input().split(' '))
data = []
for i in range(M):
    Pi, Yi = map(int, input().split(' '))
    data.append([i,Pi,Yi])

sorted_data = sorted(data, key=itemgetter(1,2))

codes = []
prev_p = 0
for i,p,y in sorted_data:
    if p!=prev_p:
        x = 1
        prev_p = p
    else:
        x+=1

    code = '{0:06d}{1:06d}'.format(p,x)
    codes.append([i,code])

sorted_codes = sorted(codes, key = itemgetter(0))

for code in sorted_codes:
    print(code[1])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(' '))

Prenum = [[] for i in range(N)]
PreYear = []
PY = [input().split(' ') for i in range(M)]

for i in range(M):
    Pi, Yi = map(int,PY[i])
    Prenum[Pi-1].append(i)

    count = 1
    for i in range(len(Prenum[Pi-1])-1):
        if int(PY[Prenum[Pi-1][i]][1]) > Yi:
            PreYear[Prenum[Pi-1][i]] += 1
        elif int(PY[Prenum[Pi-1][i]][1]) < Yi:
            count +=1 
    PreYear.append(count)

for i in range(M):
    Pi, Yi = map(int,PY[i])
    print('{0:06d}{1:06d}'.format(Pi,PreYear[i]))

Fixed submission:
from operator import itemgetter


N, M = map(int, input().split(' '))
data = []
for i in range(M):
    Pi, Yi = map(int, input().split(' '))
    data.append([i,Pi,Yi])

sorted_data = sorted(data, key=itemgetter(1,2))

codes = []
prev_p = 0
for i,p,y in sorted_data:
    if p!=prev_p:
        x = 1
        prev_p = p
    else:
        x+=1

    code = '{0:06d}{1:06d}'.format(p,x)
    codes.append([i,code])

sorted_codes = sorted(codes, key = itemgetter(0))

for code in sorted_codes:
    print(code[1])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(' '))

PreYear = [[] for i in range(N)]
PY = [input().split(' ') for i in range(M)]
for i in range(M):
    Pi, Yi = PY[i]
    PreYear[int(Pi)-1].append(int(Yi))
order = []
for i in range(N):
    order.append(sorted(PreYear[i]))

for i in range(M):
    Pi, Yi = map(int,PY[i])
    count = order[Pi-1].index(Yi)
    count+=1
    print('{0:06d}{1:06d}'.format(Pi,count))

Fixed submission:
from operator import itemgetter


N, M = map(int, input().split(' '))
data = []
for i in range(M):
    Pi, Yi = map(int, input().split(' '))
    data.append([i,Pi,Yi])

sorted_data = sorted(data, key=itemgetter(1,2))

codes = []
prev_p = 0
for i,p,y in sorted_data:
    if p!=prev_p:
        x = 1
        prev_p = p
    else:
        x+=1

    code = '{0:06d}{1:06d}'.format(p,x)
    codes.append([i,code])

sorted_codes = sorted(codes, key = itemgetter(0))

for code in sorted_codes:
    print(code[1])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(' '))

PreYear = [[] for i in range(N)]
PY = [input().split(' ') for i in range(M)]
for i in range(M):
    Pi, Yi = PY[i]
    PreYear[int(Pi)-1].append(int(Yi))


for i in range(M):
    Pi, Yi = map(int,PY[i])
    count = 0
    for j in range(len(PreYear[int(Pi)-1])):
        if PreYear[int(Pi)-1][j] <= Yi:
            count+=1
    print('{0:06d}{1:06d}'.format(Pi,count))

Fixed submission:
from operator import itemgetter


N, M = map(int, input().split(' '))
data = []
for i in range(M):
    Pi, Yi = map(int, input().split(' '))
    data.append([i,Pi,Yi])

sorted_data = sorted(data, key=itemgetter(1,2))

codes = []
prev_p = 0
for i,p,y in sorted_data:
    if p!=prev_p:
        x = 1
        prev_p = p
    else:
        x+=1

    code = '{0:06d}{1:06d}'.format(p,x)
    codes.append([i,code])

sorted_codes = sorted(codes, key = itemgetter(0))

for code in sorted_codes:
    print(code[1])