qyliang/CodeNanoFix huggingface dataset:
Buggy code:
#C - ID
import numpy as np

N,M = map(int, input().split())
py = [[int(i) for i in input().split()] for i in range(M)]

pref_dic = {}
for i in range(N):
    pref_dic[i+1] = []
for e,index in zip(py, range(M)):
    pref = e[0]
    year = e[1]
    
    pref_dic[pref].append((index, year))
        
city_num_dic = {}
for pref in pref_dic.keys():
    pref_string = str(pref)
    if len(pref_string) < 6:
        while len(pref_string) < 6:
            pref_string = "0" + pref_string
    
    in_year_list = np.array(pref_dic[pref])
    if len(in_year_list) == 0:
        continue
    
    year_ =  in_year_list[:, 1]
    city_ = in_year_list[:, 0]
    
    hayaijun_ind = np.argsort(year_)
    for index, i in zip(hayaijun_ind, range(len(hayaijun_ind))):
        city_name = city_[index]
        num = str(i+1)
        if len(num) < 7:
            while len(num) < 7:
                num = "0" + num
        city_num_dic[city_name] = pref_string + num


for city in np.sort(list(city_num_dic.keys())):
    print(city_num_dic[city])

Fixed code:
import numpy as np

N,M = map(int, input().split())
py = [[int(i) for i in input().split()] for i in range(M)]

pref_dic = {}
for i in range(N):
    pref_dic[i+1] = []
for e,index in zip(py, range(M)):
    pref = e[0]
    year = e[1]
    
    pref_dic[pref].append((index, year))
        
city_num_dic = {}
for pref in pref_dic.keys():
    pref_string = str(pref)
    if len(pref_string) < 6:
        while len(pref_string) < 6:
            pref_string = "0" + pref_string
    
    in_year_list = np.array(pref_dic[pref])
    if len(in_year_list) == 0:
        continue
    
    year_ =  in_year_list[:, 1]
    city_ = in_year_list[:, 0]
    
    hayaijun_ind = np.argsort(year_)
    for index, i in zip(hayaijun_ind, range(len(hayaijun_ind))):
        city_name = city_[index]
        num = str(i+1)
        if len(num) < 6:
            while len(num) < 6:
                num = "0" + num
        city_num_dic[city_name] = pref_string + num


for city in np.sort(list(city_num_dic.keys())):
    print(city_num_dic[city])
Buggy code:
n,m=map(int,input().split())
pre=[[] for _ in range(n)]
for _ in range(m):
    p,y=map(int,input().split())
    pre[p-1].append([y,_,p])
for p in range(n):
    pre[p].sort(key=lambda x:x[0])
    for i in range(len(pre[p])):
        pre[p][i].append(i)
lis=[]
for i in pre:
    for j in i:
        lis.append(j)
lis.sort(key=lambda x:x[1])
for i in lis: print("{:06}{:06}".format(i[3]+1,i[2]))

Fixed code:
n,m=map(int,input().split())
pre=[[] for _ in range(n)]
for _ in range(m):
    p,y=map(int,input().split())
    pre[p-1].append([y,_,p])
for p in range(n):
    pre[p].sort(key=lambda x:x[0])
    for i in range(len(pre[p])):
        pre[p][i].append(i)
lis=[]
for i in pre:
    for j in i:
        lis.append(j)
lis.sort(key=lambda x:x[1])
for i in lis: print("{:06}{:06}".format(i[2],i[3]+1))
Buggy code:
n,m=map(int,input().split())
d=[]
for i in range(m):
  d.append(list(map(int,input().split())))
  d[i].append(1)
s=sorted(d)
k=0
if m>1:
  for i in range(m-1):
    if s[i][0]==s[i+1][0]:
      s[i][2]=k
      s[i+1][2]=k+1
      k=k+1
    else:
      k=1
      s[i+1][2]=k
      
  for i in range(m):
    ans=1000000000000+d[i][0]*1000000+d[i][2]
    print(str(ans)[1:])
else:
  print("000001000001")



Fixed code:
n,m=map(int,input().split())
d=[]
for i in range(m):
  d.append(list(map(int,input().split())))
  d[i].append(1)
s=sorted(d)
k=1
if m>1:
  for i in range(m-1):
    if s[i][0]==s[i+1][0]:
      s[i][2]=k
      s[i+1][2]=k+1
      k=k+1
    else:
      k=1
      s[i+1][2]=k
      
for i in range(m):
  ans=1000000000000+d[i][0]*1000000+d[i][2]
  print(str(ans)[1:])
Buggy code:
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
buf = [None] * m
cnt = {k: [] for k in range(n + 1)}
for i in range(m):
    p, y = na()
    cnt[p].append((y, i))
print(cnt)
for p, l in cnt.items():
    if not l:
        continue
    l.sort()
    print(l)
    for j, (y, i) in enumerate(l):
        buf[i] = '{:06d}{:06d}'.format(p, j + 1)

print('\n'.join(buf))



Fixed code:
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
buf = [None] * m
cnt = {k: [] for k in range(n + 1)}
for i in range(m):
    p, y = na()
    cnt[p].append((y, i))
for p, l in cnt.items():
    if not l:
        continue
    l.sort()
    for j, (y, i) in enumerate(l):
        buf[i] = '{:06d}{:06d}'.format(p, j + 1)

print('\n'.join(buf))
Buggy code:
import copy

n,m = map(int,input().split())

cnt = [0]*(10**5+4)

yy = []
yp = []
for _ in range(m):
    a,b = map(int,input().split())
    a,b = b,a
    yy.append([a,0])
    yp.append([a,b])

inlist = copy.deepcopy(yp)
yp.sort()
yy = dict(yy)

for i in range(m):
    print(yp[i][1])
    cnt[yp[i][1]]+=1
    yy[yp[i][0]] = cnt[yp[i][1]]

for key,value in inlist:
    print("{:06}{:06}".format(value,yy[key]))

Fixed code:
import copy

n,m = map(int,input().split())

cnt = [0]*(10**5+4)

yy = []
yp = []
for _ in range(m):
    a,b = map(int,input().split())
    a,b = b,a
    yy.append([a,0])
    yp.append([a,b])

inlist = copy.deepcopy(yp)
yp.sort()
yy = dict(yy)

for i in range(m):
    cnt[yp[i][1]]+=1
    yy[yp[i][0]] = cnt[yp[i][1]]

for key,value in inlist:
    print("{:06}{:06}".format(value,yy[key]))
Buggy code:
nm_lst = list(map(int, input().split()))
city_lst = [list(map(int, (str(i)+' '+input()).split())) for i in range(nm_lst[1])]

city_lst = sorted(city_lst, key = lambda x: x[1]*10**7 + x[2])

ans_lst = []
num_num = 0
for n, city in enumerate(city_lst):
    prefec_num = city[1]
    prefec_str = '0' * (6-len(str(prefec_num))) + str(prefec_num)
    if n = 0 or (prefec_num != city_lst[n-1][1]):
        num_str = '000001'
        num_num = 1
    else:
        num_num += 1
        num_str = '0' * (6-len(str(num_num))) + str(num_num)
    ans_lst.append([city[0], prefec_str, num_str])
    
ans_lst = sorted(ans_lst, key = lambda x:x[0])

for city in ans_lst:
    print(city[1]+city[2])

Fixed code:
nm_lst = list(map(int, input().split()))
city_lst = [list(map(int, (str(i)+' '+input()).split())) for i in range(nm_lst[1])]

city_lst = sorted(city_lst, key = lambda x: x[1]*(10**12) + x[2])

ans_lst = []
num_num = 0
for n, city in enumerate(city_lst):
    prefec_num = city[1]
    prefec_str = '0' * (6-len(str(prefec_num))) + str(prefec_num)
    if n == 0 or (prefec_num != city_lst[n-1][1]):
        num_num = 1
    else:
        num_num += 1
    num_str = '0' * (6-len(str(num_num))) + str(num_num)
    ans_lst.append([city[0], prefec_str, num_str])
    
ans_lst = sorted(ans_lst, key = lambda x:x[0])

for city in ans_lst:
    print(city[1]+city[2])
Buggy code:
n,m = map(int,input().split())
city = [[] for i in range(n)]
def f(s):
    s = str(s)
    t  = 6 - len(s)
    s = "0"*t + s
    return s
for i in range(m):
    ken,year = map(int,input().split())
    city[ken-1].append(year)
for i in range(n):
    city[i].sort()
    for j in range(len(city[i])):
        ans = f(i+1) + f(j+1)
        print(ans)

Fixed code:
n,m = map(int,input().split())
city = [[] for i in range(n)]
def f(s):
    s = str(s)
    t  = 6 - len(s)
    s = "0"*t + s
    return s
for i in range(m):
    ken,year = map(int,input().split())
    city[ken-1].append([year,i])
newcity = []
for i in range(n):
    city[i].sort()
    for j in range(len(city[i])):
        newcity.append([city[i][j][1],f(i+1) + f(j+1)])
newcity.sort()
for i in range(m):
    print(newcity[i][1])
Buggy code:
N, M = map(int, input().split())
from bisect import bisect_right
dic = [[] for i in range(N)]

shi = {}
for i in range(M):
    p, y = map(int, input().split())
    dic[p-1].append(y)
    shi[i] = (p, y)

for j in range(M):
    p, y = shi[j]
    print('{:06}{:06}'.format(p, bisect_right(dic[p-1], y)))



Fixed code:
N, M = map(int, input().split())
from bisect import bisect_right
dic = [[] for i in range(N)]

shi = {}
for i in range(M):
    p, y = map(int, input().split())
    dic[p-1].append(y)
    shi[i] = (p, y)

for i in range(N):
    dic[i].sort()

for j in range(M):
    p, y = shi[j]
    print('{:06}{:06}'.format(p, bisect_right(dic[p-1], y)))
Buggy code:
N, M = map(int, input().split())

P = [0] * M
Y = [0] * M
dic = {}
ano_dic = {}
for m in range(M):
    line = list(map(int, input().split()))
    P[m] = line[0]
    Y[m] = line[1]
    
    dic[m] =[P[m], Y[m]]


ID = {}
count = 0
sorted_list = sorted(dic.items(), key=lambda x: (x[1][0], x[0]))


for i, item in enumerate(sorted_list):
    if item[1][0] == sorted_list[i - 1][1][0]:
        count += 1
        ID[item[0]] = str(item[1][0]).zfill(6) + str(count).zfill(6)
    else:
        count = 1
        ID[item[0]] = str(item[1][0]).zfill(6) + str(count).zfill(6)

for item in sorted(ID.items(), key=lambda x: x[0]):
    print(item[1])

Fixed code:
N, M = map(int, input().split())

P = [0] * M
Y = [0] * M
dic = {}
ano_dic = {}
for m in range(M):
    line = list(map(int, input().split()))
    P[m] = line[0]
    Y[m] = line[1]
    
    dic[m] =[P[m], Y[m]]


ID = {}
count = 0
sorted_list = sorted(dic.items(), key=lambda x: (x[1][0], x[1][1]))



for i, item in enumerate(sorted_list):
    if item[1][0] == sorted_list[i - 1][1][0]:
        count += 1
        ID[item[0]] = str(item[1][0]).zfill(6) + str(count).zfill(6)
    else:
        count = 1
        ID[item[0]] = str(item[1][0]).zfill(6) + str(count).zfill(6)

for item in sorted(ID.items(), key=lambda x: x[0]):
    print(item[1])
Buggy code:
from operator import itemgetter
pres = []
numbers = []
N,M = map(int, input().split())

for i in range(M):
    numbers.append('')

for i in range(N):
    pres.append([])

i = 0
for t in range(M):
    p,y = map(int,input().split())
    pres[p-1].append((y,i))
    i+=1

i = 0
for p in pres:
    if p==[]:
        continue
    i+=1
    front = '00000' + str(i)
    front = front[-6:]
    temp_p = p
    temp_p.sort(key=itemgetter(0))
    j = 0
    for city in temp_p:
        j+=1
        back = '00000' + str(j)
        back = back[-6:]
        numbers[city[1]] = front+back
        
for num in numbers:
    print(num)


Fixed code:
from operator import itemgetter
pres = []
numbers = []
N,M = map(int, input().split())

for i in range(M):
    numbers.append('')

for i in range(N):
    pres.append([])

i = 0
for t in range(M):
    p,y = map(int,input().split())
    pres[p-1].append((y,i))
    i+=1

i = 0
for p in pres:
    i+=1
    if p==[]:
        continue
    front = '00000' + str(i)
    front = front[-6:]
    temp_p = p
    temp_p.sort(key=itemgetter(0))
    j = 0
    for city in temp_p:
        j+=1
        back = '00000' + str(j)
        back = back[-6:]
        numbers[city[1]] = front+back
        
for num in numbers:
    print(num)
Buggy code:
N, M = map(int, input().split())
pairs = [list(map(int,input().split())) for i in range(M)]

p_count = [1] * (N + 1)
for r in sorted(pairs, key=lambda x: x[1]):
    r.append("{:06}{:06}".format(r[0], p_count[r[0]]))
    p_count[r[0]] += 1
print(pairs)

print("\n".join((r[2] for r in pairs)))

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

p_count = [1] * (N + 1)
for r in sorted(pairs, key=lambda x: x[1]):
    r.append("{:06}{:06}".format(r[0], p_count[r[0]]))
    p_count[r[0]] += 1

print("\n".join((r[2] for r in pairs)))
Buggy code:
import numpy as np


def solve(string):
    n, m, *py = map(int, string.split())
    p = [[] for _ in range(n)]
    for _p, _y in py:
        p[_p - 1].append(_y)
    for i in range(n):
        p[i] = np.argsort(np.argsort(p[i]))
    counter = [0 for _ in range(n)]
    for _p, _y in py:
        t = "{:06}{:06}".format(_p, p[_p - 1][counter[_p - 1]] + 1)
        print(t)
        counter[_p - 1] += 1
        p[i] = np.argsort(np.argsort(p[i]))


if __name__ == '__main__':
    n, m = map(int, input().split())

    print(solve("{} {}\n".format(n, m) + "\n".join([input() for _ in range(m)])))


Fixed code:
import numpy as np


def solve(string):

    n, m, *py = map(int, string.split())
    py = [(_p, _y) for _p, _y in zip(py[0::2], py[1::2])]
    p = [[] for _ in range(n)]
    for _p, _y in py:
        p[_p - 1].append(_y)
    for i in range(n):
        p[i] = np.argsort(np.argsort(p[i]))

    counter = [0 for _ in range(n)]
    ans = []
    for _p, _y in py:
        ans.append("{:06}{:06}".format(_p, p[_p - 1][counter[_p - 1]] + 1))
        counter[_p - 1] += 1
    return "\n".join(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve("{} {}\n".format(n, m) + "\n".join([input() for _ in range(m)])))
Buggy code:
import numpy as np


n, m = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(m)]
p = [[] for _ in range(n)]
start = time.time()
for _p, _y in py:
    p[_p - 1].append(_y)
for i in range(n):
    p[i] = np.argsort(np.argsort(p[i]))

counter = [0 for _ in range(n)]
for _p, _y in py:
    t = "{:06}{:06}".format(_p, p[_p - 1][counter[_p - 1]] + 1)
    print(t)
    counter[_p - 1] += 1


Fixed code:
import time
import numpy as np

# def solve(n, m, py):
"""
n, m = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(m)]
"""

n, m = map(int, input().split())
py = [list(map(int, input().split())) for _ in range(m)]
p = [[] for _ in range(n)]
start = time.time()
for _p, _y in py:
    p[_p - 1].append(_y)
# print(time.time() - start)
for i in range(n):
    p[i] = np.argsort(np.argsort(p[i]))

# print(time.time() - start)
counter = [0 for _ in range(n)]
for _p, _y in py:
    # print("{:06}{:06}".format(_p, p[_p - 1].index(_y) + 1))
    # t = "{:06}{:06}".format(_p, p[_p - 1].index(_y) + 1)
    # print(counter[_y])
    t = "{:06}{:06}".format(_p, p[_p - 1][counter[_p - 1]] + 1)
    print(t)
    counter[_p - 1] += 1
Buggy code:
N, M = map(int,input().split())
py = []
for i in range(M):
  py.append(list(map(int,input().split())))
  py[i].append(i)
sorted_py = sorted(py, key=lambda x: x[1])
P = [0]*N
p_num = 0
num = 0
output = ''
output2 = []
outputs = []
for i in range(M):
  P[sorted_py[i][0]-1] += 1
  p_num = sorted_py[i][0]
  num = P[sorted_py[i][0]-1]
  output = str(p_num).zfill(6) + str(num).zfill(8)
  output2 = [output, sorted_py[i][2]]
  outputs.append(output2)
sorted_outputs = sorted(outputs, key=lambda x: x[1])
for out in sorted_outputs:
  print(out[0])

  

Fixed code:
N, M = map(int,input().split())
py = []
for i in range(M):
  py.append(list(map(int,input().split())))
  py[i].append(i)
sorted_py = sorted(py, key=lambda x: x[1])
P = [0]*N
p_num = 0
num = 0
output = ''
output2 = []
outputs = []
for i in range(M):
  P[sorted_py[i][0]-1] += 1
  p_num = sorted_py[i][0]
  num = P[sorted_py[i][0]-1]
  output = str(p_num).zfill(6) + str(num).zfill(6)
  output2 = [output, sorted_py[i][2]]
  outputs.append(output2)
sorted_outputs = sorted(outputs, key=lambda x: x[1])
for out in sorted_outputs:
  print(out[0])
Buggy code:
n,m=map(int,input().split())
s=[list(map(int, input().split())) for i in range(m)] 
for i in range(m):
    s[i].append(i+1)
print(s)
a=0
s.sort()
for i in range(m):
    if i>1:
        if s[i][0]!=s[i-1][0]:
            a=0
        
    s[i].append(str(0)*(6-len(str(s[i][0])))+str(s[i][0]))
    s[i].append(str(0)*(6-len(str(a)))+str(a+1))
    a+=1
s.sort(key=lambda x:x[2])
for i in range(m):
    print(s[i][3]+s[i][4])

Fixed code:
n,m=map(int,input().split())
s=[list(map(int, input().split())) for i in range(m)] 
for i in range(m):
    s[i].append(i+1)
a=0
s.sort()
for i in range(m):
    if i>=1:
        if s[i][0]!=s[i-1][0]:
            a=0
        
    s[i].append(str(0)*(6-len(str(s[i][0])))+str(s[i][0]))
    s[i].append(str(0)*(6-len(str(a+1)))+str(a+1))
    a+=1
s.sort(key=lambda x:x[2])
for i in range(m):
    print(s[i][3]+s[i][4])
Buggy code:
from operator import itemgetter

n,m = map(int,input().split())
py = []
pyy = []

npy = []

for i in range(m):

    pyy=list(map(int,input().split()))
    pyy.append(i)
    py.append(pyy)

print(py)
py.sort(key=itemgetter(0,1))

print(py)

num = 1

npy.append([str(10**12+py[0][0]*(10**6)+num)[1:13],py[0][2]])


for i in range(m-1):
    if py[i+1][0] == py[i][0]:
        num = num + 1
        npy.append([str(10**12+py[i+1][0]*(10**6)+num)[1:13],py[i+1][2]])
    else:
        num = 1
        npy.append([str(10**12+py[i+1][0]*(10**6)+num)[1:13],py[i+1][2]])

npy.sort(key=itemgetter(1))

for j in range(m):
    print(npy[j][0])


Fixed code:
from operator import itemgetter

n,m = map(int,input().split())
py = []
pyy = []

npy = []

for i in range(m):

    pyy=list(map(int,input().split()))
    pyy.append(i)
    py.append(pyy)

py.sort(key=itemgetter(0,1))


num = 1

npy.append([str(10**12+py[0][0]*(10**6)+num)[1:13],py[0][2]])


for i in range(m-1):
    if py[i+1][0] == py[i][0]:
        num = num + 1
        npy.append([str(10**12+py[i+1][0]*(10**6)+num)[1:13],py[i+1][2]])
    else:
        num = 1
        npy.append([str(10**12+py[i+1][0]*(10**6)+num)[1:13],py[i+1][2]])

npy.sort(key=itemgetter(1))

for j in range(m):
    print(npy[j][0])
Buggy code:
N, M = map(int, input().split())

shi_map = []

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

shi_map = sorted(shi_map, key=lambda x: (x[1], x[2]))
print(shi_map)

result = {}
shi_count = {}
for i, p, y in shi_map:

    if p in shi_count:
        c = shi_count[p]
        count = c + 1
        shi_count[p] = count
    else:
        shi_count[p] = 1
        count = 1
    result[i] = [p, count]
result = list(sorted(result.items(), key=lambda x: x[0]))

for i, p in result:

    p2 = str(p[0]).zfill(6)

    y = str(p[1]).zfill(6)
    r = p2+y
    print(r)

Fixed code:
N, M = map(int, input().split())

shi_map = []

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

shi_map = sorted(shi_map, key=lambda x: (x[1], x[2]))

result = {}
shi_count = {}
for i, p, y in shi_map:

    if p in shi_count:
        c = shi_count[p]
        count = c + 1
        shi_count[p] = count
    else:
        shi_count[p] = 1
        count = 1
    result[i] = [p, count]
result = list(sorted(result.items(), key=lambda x: x[0]))

for i, p in result:

    p2 = str(p[0]).zfill(6)

    y = str(p[1]).zfill(6)
    r = p2+y
    print(r)
Buggy code:
def get_line():
  return input().split(' ')

class element:
  def __init__(self, P, Y, idx):
    self.P = P
    self.Y = Y
    self.idx = idx
  def __lt__(self, other):
    return self.Y < other.Y

N, M = map(int, get_line())
els = [0] * M
for i in range(M):
  p, y = map(int, get_line())
  els[i] = Element(p, y, i)

p_map = [[] for _ in range(N)]

for e in els:
  p_map[e.P - 1].append(e)

ans = [0] * M

for mp in p_map:
  cnt = 1
  for e in sorted(mp):
    ans[e.idx] = "{:06d}{:06d}".format(e.P, cnt)
    cnt = cnt + 1

for e in ans:
  print(e)


Fixed code:
def get_line():
  return input().split(' ')

class element:
  def __init__(self, P, Y, idx):
    self.P = P
    self.Y = Y
    self.idx = idx
  def __lt__(self, other):
    return self.Y < other.Y

N, M = map(int, get_line())
els = [0] * M
for i in range(M):
  p, y = map(int, get_line())
  els[i] = element(p, y, i)

p_map = [[] for _ in range(N)]

for e in els:
  p_map[e.P - 1].append(e)

ans = [0] * M

for mp in p_map:
  cnt = 1
  for e in sorted(mp):
    ans[e.idx] = "{:06d}{:06d}".format(e.P, cnt)
    cnt = cnt + 1

for e in ans:
  print(e)
Buggy code:
n,m=map(int,input().split())
py=[]
for i in range(m):
    py.append(list(map(int,input().split()))+[i+1])
py.sort()
number_list=[]
number_list.append([str(0)]*(6-(len(list(str(py[0][0])))))+list(str(py[0][0]))+[str(0)]*(6-(len(list(str(1)))))+list(str(1))+[str(py[0][-1])])
k=2
for j in range(1,m):
    if py[j][0]==py[j-1][0]:
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str(py[j][-1])])    
        k+=1
    else:
        k=1
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str(py[j][-1])])
        k+=1
number_list_sort=sorted(number_list,key=lambda x:x[-1])
for l in range(m):
    print(''.join(number_list_sort[l][:-1])

Fixed code:
n,m=map(int,input().split())
py1=[]
for i in range(m):
    py1.append(list(map(int,input().split()))+[i+1])
py=sorted(py1)

number_list=[]
number_list.append([str(0)]*(6-(len(list(str(py[0][0])))))+list(str(py[0][0]))+[str(0)]*(6-(len(list(str(1)))))+list(str(1))+[str(py[0][-1])])
k=2
for j in range(1,m):
    if py[j][0]==py[j-1][0]:
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str((py[j][-1]))])    
        k+=1
    else:
        k=1
        number_list.append([str(0)]*(6-(len(list(str(py[j][0])))))+list(str(py[j][0]))+[str(0)]*(6-(len(list(str(k)))))+list(str(k))+[str(py[j][-1])])
        k+=1
     
number_list_sort=sorted(number_list,key=lambda x:int(x[-1]))
for l in range(m):
    print(''.join(number_list_sort[l][:-1]))
Buggy code:
import collections
import bisect
n,m = map(int, input().split())
p = [list(map(int,input().split())) for i in range(m)]
a = collections.defaultdict(list)
for x,y in sorted(p):
  a[x]+=[y]
for x,y in p:
  print("%06d%06d"%(x,bisect.bisect(a[x],y))

Fixed code:
import collections
import bisect
n,m = map(int, input().split())
p = [list(map(int,input().split())) for i in range(m)]
a = collections.defaultdict(list)
for x,y in sorted(p):
  a[x]+=[y]
for x,y in p:
  print("%06d%06d"%(x,bisect.bisect(a[x],y)))
Buggy code:
from operator import itemgetter
N, M = map(int, input().split())
c=[]
for i in range(M):
	c.append(input().split())
for i in range(M):
	c[i].append(i)
C = sorted(sorted(c,key=itemgetter(1)), key=itemgetter(0))
x = 1
for i in range(M):
	if i > 0  and int(C[i][0]) - int(C[i-1][0]) > 0:
		x = 1
	else:
		x += 1
	C[i].append(x)
c = sorted(C, key=itemgetter(2))
for i in range(M):
	print("{:06d}{:06d}".format(int(c[i][0]), int(c[i][3])))

Fixed code:
from operator import itemgetter
N, M = map(int, input().split())
c=[]
for i in range(M):
	c.append(list(map(int, input().split())))
for i in range(M):
	c[i].append(i)
C = sorted(sorted(c,key=itemgetter(1)), key=itemgetter(0))
x = 0
for i in range(M):
	if i > 0  and C[i][0] - C[i-1][0] != 0:
		x = 1
	else:
		x += 1
	C[i].append(x)
c = sorted(C, key=itemgetter(2))
for i in range(M):
	print("{:06d}{:06d}".format(c[i][0], c[i][3]))
Buggy code:
import sys
input = sys.stdin.readline


def main():
    n, m = map(int, input().split())
    ans_id = [None]*m
    p_count = [0]*(n+1)

    list_ipy = [None]*m
    for i in range(m):
        p, y = map(int, input().split())
        list_ipy[i] = (i, p, y)
    list_ipy.sort(key=lambda x: x[2])

    for ipy in list_ipy:
        i, p, _ = ipy
        p_count[p] += 1
        first = format(p, '06')
        second = format(p_count[p], '08')
        ans_id[i] = first + second

    for id in ans_id:
        print(id)


if __name__ == '__main__':
    main()


Fixed code:
import sys
input = sys.stdin.readline


def main():
    n, m = map(int, input().split())
    ans_id = [None]*m
    p_count = [0]*(n+1)

    list_ipy = [None]*m
    for i in range(m):
        p, y = map(int, input().split())
        list_ipy[i] = (i, p, y)
    list_ipy.sort(key=lambda x: x[2])

    for ipy in list_ipy:
        i, p, _ = ipy
        p_count[p] += 1
        first = format(p, '06')
        second = format(p_count[p], '06')
        ans_id[i] = first + second

    for id in ans_id:
        print(id)


if __name__ == '__main__':
    main()