qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N,M = map(int,input().split())
list = [[] for i in range(N)]

for i in range(M):
    j,k = map(int,input().split())
    list[j-1].append((k,i))

ans = [None]*M

for i,j in enumerate(list):
    j.sort()
    for k,(l,m) in enumerate(j):
        ans[m] = "%06d%06d" % (i+1,k+1)

print(ans)


Fixed code:
N,M = map(int,input().split())
list = [[] for i in range(N)]

for i in range(M):
    j,k = map(int,input().split())
    list[j-1].append((k,i))

ans = [None]*M

for i,j in enumerate(list):
    j.sort()
    for k,(l,m) in enumerate(j):
        ans[m] = "%06d%06d" % (i+1,k+1)

print(*ans, sep='\n')
Buggy code:
N, M = map(int, input().split())
PList = [[] for _ in range(N+1)]

for i in range(M):
    P, Y = map(int, input().split())
    PList[P].append([i , Y])

#print(PList)

ans = [0] * M

for P, l in enumerate(PList):
    if not l:
        continue
    l.sort()
    for j, (i, Y) in enumerate(l):
        ans[i] = "{:06d}{:06d}".format(P, j+1)

#print(ans)

for i in range(M):
    print(ans[i])

Fixed code:
N, M = map(int, input().split())
PList = [[] for _ in range(N+1)]

for i in range(M):
    P, Y = map(int, input().split())
    PList[P].append([Y, i])

#print(PList)

ans = [0] * M

for P, l in enumerate(PList):
    if not l:
        continue
    l.sort()
    for j, (Y, i) in enumerate(l):
        ans[i] = "{:06d}{:06d}".format(P, j+1)

#print(ans)

print("\n".join(ans))
Buggy code:
n,m=[int(i) for i in input().split()]
id=[[int(i) for i in input().split()]+[j] for j in range(m)]

print(id)

pre_num=[0]*(n+1)
ans=[""]*m

id.sort(key=lambda x:x[1])

for p,y,i in id:
    pre_num[p]+=1
    ans[i]=str(p).zfill(6)+str(pre_num[p]).zfill(6)
    
print("\n".join(ans))


Fixed code:
n,m=[int(i) for i in input().split()]
id=[[int(i) for i in input().split()]+[j] for j in range(m)]

pre_num=[0]*(n+1)
ans=[""]*m

id.sort(key=lambda x:x[1])

for p,y,i in id:
    pre_num[p]+=1
    ans[i]=str(p).zfill(6)+str(pre_num[p]).zfill(6)

print("\n".join(ans))
Buggy code:
a,b=map(int,input().split())
L=[]
l=[]
ll=[]
u=0
for i in range(b):
    u+=1
    c=list(map(int,input().split()))
    c.append(u)
    L.append(c)
L.sort(key=lambda x:x[0])
for i in range(1,a+1):
    lll=[]
    for j in L:
        if j[0]==i:
            lll.append(j)
    ll.append(lll)
for i in ll:
    e=0
    for j in i:
        e+=1
        j.append(e)
q=[]
for w in ll:
   q.extend(w) 
q.sort(key=lambda x:x[2])
for r in range(b):
        print('0'*(6-len(str(q[r][0])))+str(q[r][0])+'0'*(6-len(str(q[r][3])))+str(q[r][3]))

Fixed code:
a,b=map(int,input().split())
L=[[] for i in range(a)]
u=0
for i in range(b):
    u+=1
    c=list(map(int,input().split()))
    c.append(u)
    L[int(c[0])-1].append(c)
for i in L:
    i.sort(key=lambda x:x[1])
for i in L:
    e=0
    for j in i:
        e+=1
        j.append(e)
q=[]
for w in L:
   q.extend(w) 
q.sort(key=lambda x:x[2])
for r in range(b):
        print('0'*(6-len(str(q[r][0])))+str(q[r][0])+'0'*(6-len(str(q[r][3])))+str(q[r][3]))
Buggy code:
from collections import defaultdict

N, M = map(int, input().split())
P, Y = [], []
ylist = defaultdict(list)
pset = set()
for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    ylist[p].append(y)
    pset.add(p)
assert len(pset) == N

cdict = defaultdict(dict)
for p in pset:
    syear = sorted(ylist[p])
    for i, y in enumerate(syear):
        cdict[p][y] = i + 1

for i in range(M):
    p = P[i]
    y = Y[i]
    rank = cdict[p][y]
    print(f'{p:06}{rank:06}')


Fixed code:
from collections import defaultdict

N, M = map(int, input().split())
P, Y = [], []
ylist = defaultdict(list)
pset = set()
for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    ylist[p].append(y)
    pset.add(p)

cdict = defaultdict(dict)
for p in pset:
    syear = sorted(ylist[p])
    for i, y in enumerate(syear):
        cdict[p][y] = i + 1

for i in range(M):
    p = P[i]
    y = Y[i]
    rank = cdict[p][y]
    print('{:06}{:06}'.format(p, rank))
Buggy code:
N,M = map(int,input().split())
A = [[] for i in range(N+1)]
B = []
d = {}
for i in range(M):
    p,y = map(int,input().split())
    B.append((p,y))
    A[p].append(y)
for i in range(N+1):
    A[i].sorted
    n = len(A[i])
    for j in range(n):
        d[A[i][j]] = j+1
for i in range(M):
    p,y = B[i]
    q = d[y]
    m = 6 - len(str(p))
    n = 6 - len(str(q))
    ans = "0"*m + str(p) + "0"*m + str(q)

Fixed code:
N,M = map(int,input().split())
A = [[] for i in range(N+1)]
B = []
d = {}
for i in range(M):
    p,y = map(int,input().split())
    B.append((p,y))
    A[p].append(y)
for i in range(N+1):
    A[i].sort()
    n = len(A[i])
    for j in range(n):
        d[A[i][j]] = j+1
for i in range(M):
    p,y = B[i]
    q = d[y]
    m = 6 - len(str(p))
    n = 6 - len(str(q))
    ans = "0"*m + str(p) + "0"*n + str(q)
    print(ans)
Buggy code:
"""
import numpy as np
N, M = map(int, input().split())
cities = {}
Y = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = p
    Y[i] = y

ans = {}
sorted_Y = sorted(Y.items(), key=lambda x:x[1])
P_i = np.zeros(N)
for i,y in sorted_Y:
    p = cities[i]
    P_i[p-1] += 1
    ans[i] = (p, int(P_i[p-1]))

for i in range(M):
    print('{0:06}{1:06}'.format(ans[i][0], ans[i][1]))
"""

n, m = map(int,input().split())
pys = []
for i in range(m):
    x = map(int, input().split())
    x = [x[0],x[1],i]
    pys.append(x)

pys.sort()
pp = -1
lid = 0
ans = []
for i in range(m):
    if pp == pys[i][0]:
        lid += 1
    else:
        lid = 1
        pp = pys[i][0]
    ans.append(pp*10**6+lid)

for v in ans:
    print(':012d'.format(v))


Fixed code:
"""
import numpy as np
N, M = map(int, input().split())
cities = {}
Y = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = p
    Y[i] = y

ans = {}
sorted_Y = sorted(Y.items(), key=lambda x:x[1])
P_i = np.zeros(N)
for i,y in sorted_Y:
    p = cities[i]
    P_i[p-1] += 1
    ans[i] = (p, int(P_i[p-1]))

for i in range(M):
    print('{0:06}{1:06}'.format(ans[i][0], ans[i][1]))
"""

n, m = map(int,input().split())
pys = []
for i in range(m):
    x = list(map(int, input().split()))
    x = [x[0],x[1],i]
    pys.append(x)

pys.sort()
pp = -1
lid = 0
ans = [0]*m
for i in range(m):
    if pp == pys[i][0]:
        lid += 1
    else:
        lid = 1
        pp = pys[i][0]
    ans[pys[i][2]] = pp*10**6+lid

for v in ans:
    print('{:012d}'.format(v))
Buggy code:
import numpy as np
N, M = map(int, input().split())
cities = {}
P = {}
Y = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = p
    Y[i] = y

ans = []
sorted_Y = sorted(Y.items(), key=lambda x:x[1])
P_i = np.zeros(N)
for i,y in sorted_Y:
    p = cities[i]
    P_i[p] += 1
    ans.append(p,P_i[p])

for p,x in ans:
    print('{0:06}{1:06}'.format(p, x))


Fixed code:
import numpy as np
N, M = map(int, input().split())
cities = {}
P = {}
Y = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = p
    Y[i] = y

ans = {}
sorted_Y = sorted(Y.items(), key=lambda x:x[1])
P_i = np.zeros(N)
for i,y in sorted_Y:
    p = cities[i]
    P_i[p-1] += 1
    ans[i] = (p, int(P_i[p-1]))

for i in range(M):
    print('{0:06}{1:06}'.format(ans[i][0], ans[i][1]))
Buggy code:
n,m=map(int,input().split())
li=[]
ans=[]
pre=1
cnt=1
for i in range(m):
    p,y=map(int,input().split())
    li.append([p,y,i])
li=sorted(li,key=lambda x:x[0])
li=sorted(li,key=lambda x:x[1])
for j in range(m):
    if li[j][0]==pre:
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])
        cnt+=1
        
    else:
        pre+=1
        cnt=1
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])

ans=sorted(ans,key=lambda x:x[1])
for k in range(m):
    print(ans[k][0])

Fixed code:
n,m=map(int,input().split())
li=[]
ans=[]
cnt=0
for i in range(m):
    p,y=map(int,input().split())
    li.append([p,y,i])
li=sorted(li,key=lambda x:x[1])
li=sorted(li,key=lambda x:x[0])
pre=li[0][0]
for j in range(m):
    if li[j][0]==pre:
        cnt+=1
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])
        
    else:
        pre=li[j][0]
        cnt=1
        ans.append([str(pre).zfill(6)+str(cnt).zfill(6),li[j][2]])

ans=sorted(ans,key=lambda x:x[1])
for k in range(m):
    print(ans[k][0])
Buggy code:
N,M = map(int,input().split())
#P = [list(map(int,input().split())) for i in range(M)]
D = [[] for i in range(N)]
#print(P.sort())
for i in range(M):
    p,y = map(int,input().split())
    D[p-1].append((y,i))
    

#D = [[(32,0),(12,2)],[(63,1)]]
#print(D)
submit = [0]*M
for i,d in enumerate(D):
    #print(d)
    d.sort()
    #print(i,d)
    for k, (y,j) in enumerate(d):
        #print(k,y,j)
        submit[j] = str(i+1).zfill(6)+str(k+1).zfill(6)
        
print(submit)
print(*submit,sep = '\n')

Fixed code:
N,M = map(int,input().split())
#P = [list(map(int,input().split())) for i in range(M)]
D = [[] for i in range(N)]
#print(P.sort())
for i in range(M):
    p,y = map(int,input().split())
    D[p-1].append((y,i))
    

#D = [[(32,0),(12,2)],[(63,1)]]
#print(D)
submit = [0]*M
for i,d in enumerate(D):
    #print(d)
    d.sort()
    #print(i,d)
    for k, (y,j) in enumerate(d):
        #print(k,y,j)
        submit[j] = str(i+1).zfill(6)+str(k+1).zfill(6)
        
#print(submit)
print(*submit,sep = '\n')
Buggy code:
n, m = [int(x) for x in input().split(' ')]

cities = list()
for i in range(m):
    pi, pm = [int(x) for x in input().split(' ')]
    cities.append((pi, pm))

p = [0] * (n+1)
for city in sorted(cities, key=lambda city: city[1]): # sort by year
    p[city[0]] += 1 # city birth order
    print('{:06d}{:06d}'.format(city[0], p[city[0]]))


Fixed code:
n, m = [int(x) for x in input().split(' ')]

cities = list()
for i in range(m):
    pi, pm = [int(x) for x in input().split(' ')]
    cities.append([pi, pm, i])

p = [0] * (n+1)
for c in sorted(cities, key=lambda city: city[1]): # sort by year
    p[c[0]] += 1 # city birth order
    c.append(p[c[0]])

for c in cities:
    print('{:06d}{:06d}'.format(c[0], c[3]))
Buggy code:
# https://atcoder.jp/contests/abc113/tasks/abc113_c
# C - ID

n, m = list(map(int, input().split()))
py_list = []

for _ in range(m):
    p, y = list(map(int, input().split()))
    py_list.append((p, y))

py_list = sorted(py_list, key=lambda x: (x[0], x[1]))

p_no = py_list[0][0]
y_index = 1
no_list = []

for i, py in enumerate(py_list):
    p, y = py

    if p != p_no:
        p_no = p
        y_index = 1

    no = str(p).zfill(6) + str(y_index).zfill(6)
    no_list.append(no)
    y_index += 1


ans = '\n'.join(no_list)
print(ans)


Fixed code:
# https://atcoder.jp/contests/abc113/tasks/abc113_c
# C - ID

n, m = list(map(int, input().split()))
py_list = []

for _ in range(m):
    p, y = list(map(int, input().split()))
    py_list.append((p, y))

sorted_py_list = sorted(py_list, key=lambda x: (x[0], x[1]))

p_no = sorted_py_list[0][0]
y_index = 1
no_dict = {}

for i, py in enumerate(sorted_py_list):
    p, y = py

    if p != p_no:
        p_no = p
        y_index = 1

    no = str(p).zfill(6) + str(y_index).zfill(6)
    no_dict[(p, y)] = no
    y_index += 1

print_list = []

for p, y in py_list:
    print_list.append(no_dict[(p, y)])

ans = '\n'.join(print_list)
print(ans)
Buggy code:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) + [i] for i in range(M)]
PY.sort(key=lambda x: [x[0], x[1]])
ans = []
P = [0] * (N + 1)
for p, y, i in PY:
    P[p] += 1
    tmp = str(p).zfill(8) + str(P[p]).zfill(8)
    ans.append([i, tmp])
ans.sort()
for i, a in ans:
    print(a)

Fixed code:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) + [i] for i in range(M)]
PY.sort(key=lambda x: [x[0], x[1]])
ans = []
P = [0] * (N + 1)
for p, y, i in PY:
    P[p] += 1
    tmp = str(p).zfill(6) + str(P[p]).zfill(6)
    ans.append([i, tmp])
ans.sort()
for i, a in ans:
    print(a)
Buggy code:
N, M = map(int, input().split())
PY = [[i,0] + list(map(int, input().split())) for i in range(M)]
# [index, nth city, pref num, birth year]

PY.sort(key=lambda x:(x[2],x[3]))

p = -1
for i,py in enumerate(PY):
  if p != py[3]:
    p = py[3]
    num = 1
    PY[i][1] = num
  else:
    num += 1
    PY[i][1] = num

PY.sort(key=lambda x:x[0])

for py in PY:
  print('{:0=6}{:0=6}'.format(py[2], py[1]))


Fixed code:
N, M = map(int, input().split())
PY = [[i,0] + list(map(int, input().split())) for i in range(M)]
# [index, nth city, pref num, birth year]

PY.sort(key=lambda x:(x[2],x[3]))

p = -1
num = 1
for i,py in enumerate(PY):
  if p != py[2]:
    p = py[2]
    num = 1
    PY[i][1] = num
  else:
    num += 1
    PY[i][1] = num

PY.sort(key=lambda x:x[0])

for py in PY:
  print('{:0=6}{:0=6}'.format(py[2], py[1]))
Buggy code:
n, m = map(int, input().split())
ipy = []

for i in range(m):
    p, y = map(int, input().split())
    ipy.append([i, p, y])
    
ipy = sorted(ipy, key=lambda x: x[2])

count = {}
order = {}

for i, p, y in ipy:
    if not p in count:
        count[p] = 1
    else:
        count[p] += 1
    order[i, p] = count[p]
    
for i, p, y in ipy:
    print('{:06}{:06}'.format(i, order[i, p]))

Fixed code:
n , m = map(int, input().split())
ipy = []

for i in range(m):
    p, y = map(int, input().split())
    ipy.append([i, p, y])

city_count = {}
order = {}

for i, p, y in sorted(ipy, key=lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 0
    city_count[p] += 1
    order[p, i] = city_count[p]
    
for i, p, y in ipy:
    print('{:06}{:06}'.format(p, order[p, i]))
Buggy code:
n,m = map(int,input().split())
base = []
base_1 = []
key = {}
ans_str = []
ans_n = []

for i in range(m):
  p,y = map(int,input().split())
  base.append([p,y])
  base_1.append([p,y])
  
base_1.sort(key = lambda x:x[1])

for i in range(m):
  p_str = str(base_1[i][0])
  len_p = len(list(p_str))
  temp = "p"+p_str
  
  if temp not in key:
    key[temp] = 1
    count = str(1)
  else :
    a = key[temp]
    key[temp] = a + 1
    count = str(key[temp])
    
  len_count = len(list(count))
  
  for j in range(6-len_p):
    p_str = "0" + p_str
    
  for j in range(6-len_count):
    count = "0" + count
    
  print(p_str + count)

Fixed code:
n,m = map(int,input().split())
base_1 = []
key = {}
ans_str = []
ans_n = []

for i in range(m):
  p,y = map(int,input().split())
  base_1.append([p,y,i])
  
base_1.sort(key = lambda x:x[1])

for i in range(m):
  p_str = str(base_1[i][0])
  len_p = len(list(p_str))
  temp = "p"+p_str
  
  if temp not in key:
    key[temp] = 1
    count = str(1)
  else :
    a = key[temp]
    key[temp] = a + 1
    count = str(key[temp])
    
  len_count = len(list(count))
  
  for j in range(6-len_p):
    p_str = "0" + p_str
    
  for j in range(6-len_count):
    count = "0" + count
    
  base_1[i].append(p_str + count)
    
base_1.sort(key = lambda x:x[2])

for i in range(m):
  print(base_1[i][3])
Buggy code:
n, m = map(int, input().split())
l = []

for i in range(m):
    p, y = input().split()
    l.append([p, y, m])

l.sort()

l[0][1] = 1

for i in range(1, m):
    if l[i][0] == l[i - 1][0]:
        l[i][1] = l[i - 1][1] + 1
    else:
        l[i][1] = 1

sortthird = lambda val: val[2]
l.sort(key = sortthird)


for i in l:
    ans = "0"*(6 - len(i[0])) + i[0] + "0"*(6 - len(str(i[1]))) + str(i[1])
    print(ans)

Fixed code:
n, m = map(int, input().split())
l = []

for i in range(m):
    p, y = input().split()
    l.append([p, int(y), i])

l.sort()

l[0][1] = 1

for i in range(1, m):
    if l[i][0] == l[i - 1][0]:
        l[i][1] = l[i - 1][1] + 1
    else:
        l[i][1] = 1

sortthird = lambda val: val[2]
l.sort(key = sortthird)

for i in l:
    ans = "0"*(6 - len(i[0])) + i[0] + "0"*(6 - len(str(i[1]))) + str(i[1])
    print(ans)
Buggy code:

n, m = map(int, input().split())
data = [[] for _ in range(n)]
for i in range(m):
    p, y = map(int, input().split())
    data[p - 1].append([y, i])

ans = [None] * m
for i in  range(n):
    data[i].sort()
    for j in range(len(data[i])):
        y, k = data[i][j]
        print(k)
        ans[k] = '0' * (6 - len(str(i + 1))) + str(i + 1) + '0' * (6 - len(str(j + 1))) + str(j + 1)

for i in range(len(ans)):
    print(ans[i])

Fixed code:

n, m = map(int, input().split())
data = [[] for _ in range(n)]
for i in range(m):
    p, y = map(int, input().split())
    data[p - 1].append([y, i])

ans = [None] * m
for i in  range(n):
    data[i].sort()
    for j in range(len(data[i])):
        y, k = data[i][j]
        ans[k] = '0' * (6 - len(str(i + 1))) + str(i + 1) + '0' * (6 - len(str(j + 1))) + str(j + 1)

for i in range(len(ans)):
    print(ans[i])
Buggy code:
N , M = map(int,input().split())
birth = []
for i in range(M):
    a , b = map(int,input().split())
    birth.append([a,b,i])
print(birth)
work_list = sorted(birth,key=lambda x: x[1])
work_list.sort()
#print(birth)
upper = 1
lower = 1
ans = []
for i in range(1,len(birth)):
    ans.append([work_list[i-1][2],str(work_list[i-1][0]).zfill(6) + str(lower).zfill(6)])
    if work_list[i][0] == work_list[i-1][0]:
        lower += 1
    else:
        lower = 1
        upper += 1
ans.append([work_list[M - 1][2],str(work_list[M-1][0]).zfill(6) + str(lower).zfill(6)])
ans.sort()
for val in ans:
    print(val[1])


Fixed code:
N , M = map(int,input().split())
birth = []
for i in range(M):
    a , b = map(int,input().split())
    birth.append([a,b,i])
#print(birth)
work_list = sorted(birth,key=lambda x: x[1])
work_list.sort()
#print(birth)
lower = 1
ans = []
for i in range(1,len(birth)):
    ans.append([work_list[i-1][2],str(work_list[i-1][0]).zfill(6) + str(lower).zfill(6)])
    if work_list[i][0] == work_list[i-1][0]:
        lower += 1
    else:
        lower = 1
ans.append([work_list[M - 1][2],str(work_list[M-1][0]).zfill(6) + str(lower).zfill(6)])
ans.sort()
for val in ans:
    print(val[1])
Buggy code:
N,M=map(int,input().split())
data=[]
for m in range(M):
    data.append(list(map(int,input().split())))
    data[m].append(m)
data.sort(key=lambda x:x[1])

pref=0
for m in range(M):
    if data[m][0]!=pref:
        count=1
    ID=('000000'+str(data[m][0]))[-6:]+('000000'+str(count))[-6:]
    data[m].append(ID)

data.sort(key=lambda x:x[2])

for m in range(M):
    print(data[m][3])

Fixed code:
N,M=map(int,input().split())
data=[]
for m in range(M):
    data.append(list(map(int,input().split())))
    data[m].append(m)

data.sort(key=lambda x:x[1])
data.sort(key=lambda x:x[0])

pref=0
count=0
for m in range(M):
    count+=1
    if data[m][0]!=pref:
        count=1
    pref=data[m][0]
    ID=('000000'+str(data[m][0]))[-6:]+('000000'+str(count))[-6:]
    data[m].append(ID)

data.sort(key=lambda x:x[2])

for m in range(M):
    print(data[m][3])
Buggy code:
N,M=map(int,input().split())
PY=[list(map(int,input().split())) for i in range(M)]

PYI=[PY[i]+[i] for i in range(M)]

PYI.sort(key=lambda x:x[1])

Nu=[1]*(N+1)
ANS=[None]*M

for p,y,i in PYI:
    ANS[i]=(p,Nu[p])
    Nu[p]+=1

print(ANS)

def numb(x,y):
    x=str(x)
    y=str(y)
    l=len(x)
    m=len(y)

    return (6-l)*"0"+x+(6-m)*"0"+y

for a,b in ANS:
    print(numb(a,b))

Fixed code:
N,M=map(int,input().split())
PY=[list(map(int,input().split())) for i in range(M)]

PYI=[PY[i]+[i] for i in range(M)]

PYI.sort(key=lambda x:x[1])

Nu=[1]*(N+1)
ANS=[None]*M

for p,y,i in PYI:
    ANS[i]=(p,Nu[p])
    Nu[p]+=1

#print(ANS)

def numb(x,y):
    x=str(x)
    y=str(y)
    l=len(x)
    m=len(y)

    return (6-l)*"0"+x+(6-m)*"0"+y

for a,b in ANS:
    print(numb(a,b))
Buggy code:
import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    n, m = read_ints()
    py = []
    for i in range(m):
        p, y = read_ints()
        py.append([y, p, i])
    py.sort(key=lambda x: x[0])  
    cnt = [0] * n
    
    for year, prefecture, idx in py:
        cnt[prefecture - 1] += 1
        print(f'{prefecture:06d}{cnt[prefecture-1]:06d}')

if __name__ ==  '__main__':
    Main()

Fixed code:
import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    n, m = read_ints()
    py = []
    for i in range(m):
        p, y = read_ints()
        py.append([y, p, i])
    py.sort(key=lambda x: x[0])  
    cnt = [0] * n
    ans = [''] * m
    
    for year, prefecture, idx in py:
        cnt[prefecture - 1] += 1
        ans[idx] = f'{prefecture:06d}{cnt[prefecture-1]:06d}'

    print(*ans, sep='\n')        

if __name__ ==  '__main__':
    Main()
Buggy code:
n,m = map( int, input().split())
  input_list = [[] for i in range(n)]

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

result = [None]*m

for p,i in enumerate(input_list) :
  for n, (a,b) in enumerate(i):
    result[b] = str(p+1).zfill(6)+str(n+1).zfill(6)
    
print(*result, sep = '\n')

Fixed code:
n,m = map( int, input().split())
  
result= {}
input_list = [[] for i in range(n)]


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

result = [None]*m

for p,i in enumerate(input_list) :
  for n, (a,b) in enumerate(i):
    result[b] = str(p+1).zfill(6)+str(n+1).zfill(6)
    
print(*result, sep = '\n')
Buggy code:
n,m = map(int,input().split())
py = {}
for i in range(m):
    p,y = map(int,input().split())
    py[i] = (p,y)
ans = sorted(py.items(),key=lambda x:x[1])
#print(ans[0][1][1])
count = 1
number = []
number.append(count)
#print(ans)
for i in range(1,m):
    if ans[i][1][0] == ans[i-1][1][0]:
        count += 1
    else:
        count = 1
    number.append(count)
#print(number)

for i in range(m):
    a = "{0:06d}".format(ans[i][1][0])
    b = "{0:06d}".format(number[i])
    print(a,end="")
    print(b)

Fixed code:
n,m = map(int,input().split())
py = {}
for i in range(m):
    p,y = map(int,input().split())
    py[i] = [p,y]
ans = sorted(py.items(),key=lambda x:x[1])
#print(ans)
#print(ans[0][1])
count = 1
ans[0][1].append(count)
#print(ans)
for i in range(1,m):
    if ans[i][1][0] == ans[i-1][1][0]:
        count += 1
    else:
        count = 1
    ans[i][1].append(count)
#print(number)
ans = sorted(ans)
#print(ans)
for i in range(m):
    a = "{0:06d}".format(ans[i][1][0])
    b = "{0:06d}".format(ans[i][1][2])
    print(a,end="")
    print(b)