qyliang/CodeNanoFix huggingface dataset:
Buggy code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, m = LI()
lst = [[] for _ in range(n)]

for i in range(m):
    p, y = LI()
    lst[p-1].append([y, i])

for i in lst:
    i.sort()

ans = []
for i in range(n):
    for idx, [j, k] in enumerate(lst[i]):
        s = "0" * 6 + str(i+1)
        s = s[-6:]
        t = "0" * 6 + str(idx+1)
        t = t[-6:]
        ans.append([i, s+t])
ans.sort()
for i, j in ans:
    print(j)

Fixed code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, m = LI()
lst = [[] for _ in range(n)]

for i in range(m):
    p, y = LI()
    lst[p-1].append([y, i])

for i in lst:
    i.sort()

ans = []
for i in range(n):
    for idx, [j, k] in enumerate(lst[i]):
        s = "0" * 6 + str(i+1)
        s = s[-6:]
        t = "0" * 6 + str(idx+1)
        t = t[-6:]
        ans.append([k, s+t])
ans.sort()
for i, j in ans:
    print(j)
Buggy code:
n,m = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(m)]

pref = {}
for p,y in info:
    if not p in pref: pref[p] = [y]
    else: pref[p].append(y)

id = {}
for p,years in pref.items():
    id[p] = {}
    for i,y in enumerate(years):
        id[p][y] = str(p).zfill(6) + str(i+1).zfill(6)

for p,y in info:
    print(id[p][y])

Fixed code:
n,m = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(m)]

pref = {}
for p,y in info:
    if not p in pref: pref[p] = [y]
    else: pref[p].append(y)

id = {}
for p,years in pref.items():
    years.sort()
    id[p] = {}
    for i,y in enumerate(years):
        id[p][y] = str(p).zfill(6) + str(i+1).zfill(6)

for p,y in info:
    print(id[p][y])
Buggy code:
import bisect
import heapq
n,m=map(int,input().split())
py_i=[[int(x) for x in input().split()] for _ in range(m)]
y_p=[[] for i in range(n+1)]
for x,y in sorted(py_i):
    print(x)
    y_p[x].append(y)
for x,y in py_i:
    z=bisect.bisect_right(y_p[x],y)
    print("%06d"%x+"%06d"%z)

#print(y_p)

Fixed code:
import bisect
import heapq
n,m=map(int,input().split())
py_i=[[int(x) for x in input().split()] for _ in range(m)]
y_p=[[] for i in range(n+1)]
for x,y in sorted(py_i):
    #print(x)
    y_p[x].append(y)
for x,y in py_i:
    z=bisect.bisect_right(y_p[x],y)
    print("%06d"%x+"%06d"%z)

#print(y_p)
Buggy code:
N, M = map(int, input().split())
city = [0]*M
for i in range(M):
    city[i] = [i] * 4
    prefecture, year = map(int, input().split())
    city[i][0], city[i][1] = year, prefecture

city = sorted(city)
print(city)

print(city)
ite = [1] * (N+1)
for k in range(M):
    city[k][3] = ite[city[k][1]]
    ite[city[k][1]] += 1
city = sorted(city, key=lambda x: x[2])
for j in range(M):
    print("{:0=12}".format(city[j][1]*1000000+city[j][3]))  # zero padding


Fixed code:
N, M = map(int, input().split())
city = [0]*M
for i in range(M):
    city[i] = [i] * 4
    prefecture, year = map(int, input().split())
    city[i][0], city[i][1] = year, prefecture

city = sorted(city)

ite = [1] * (N+1)
for k in range(M):
    city[k][3] = ite[city[k][1]]
    ite[city[k][1]] += 1
city = sorted(city, key=lambda x: x[2])
for j in range(M):
    print("{:0=12}".format(city[j][1]*1000000+city[j][3]))  # zero padding
Buggy code:

N, M = map(int, input().split(" "))

city = []
PY = []
for i in range(M):
    ll = [i] + list(map(int, input().split(" ")))
    # print(ll)
    PY.append(ll)

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

ken = [1]*N
answer = []
for i in range(M):
    ue6 = "{0:06d}".format(PY[i][1])
    sita6 = "{0:06d}".format(ken[PY[i][1]-1])
    ken[PY[i][1]-1] += 1
    answer.append([PY[i][0], ue6+sita6])

answer = sorted(answer, key=lambda x: x[0])
for i in range(M):
    print(answer[i][1])

Fixed code:

N, M = map(int, input().split(" "))

city = []
PY = []
for i in range(M):
    ll = [i] + list(map(int, input().split(" ")))
    # print(ll)
    PY.append(ll)

PY = sorted(PY, key=lambda x: x[2])
# print(PY)

ken = [1]*N
answer = []
for i in range(M):
    ue6 = "{0:06d}".format(PY[i][1])
    sita6 = "{0:06d}".format(ken[PY[i][1]-1])
    ken[PY[i][1]-1] += 1
    answer.append([PY[i][0], ue6+sita6])

answer = sorted(answer, key=lambda x: x[0])
for i in range(M):
    print(answer[i][1])
Buggy code:
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    PY[i].append(i)
PY.sort(key=lambda x:x[1])
ans = [0]*M
num = [0]*N
for p,y,i in PY:
    ans[i] = str(p).zfill(6) + str(num[p]+1).zfill(6)
    num[p] += 1
for s in ans:print(s)

Fixed code:
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    PY[i].append(i)
PY.sort(key=lambda x:x[1])
ans = [0]*M
num = [0]*N
for p,y,i in PY:
    ans[i] = str(p).zfill(6) + str(num[p-1]+1).zfill(6)
    num[p-1] += 1
for s in ans:print(s)
Buggy code:
n, m = map(int, input().split())
py = [[i, list(map(int, input().split()))] for i in range(m)]

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

cnt = 1
prev_p = 0
for i in py:
    p, y = i[1][0], i[1][1]
    if prev_p == p:
        cnt += 1
    else:
        cnt = 1

    ans = str(p).zfill(6) + str(cnt).zfill(6)
    i.append(ans)
    prev_p = p

py = sorted(py, key=lambda x: x[0])
for i in py:
    print(i[2])

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

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

cnt = 1
prev_p = 0
for i in py:
    p, y = i[1][0], i[1][1]
    if prev_p == p:
        cnt += 1
    else:
        cnt = 1

    ans = str(p).zfill(6) + str(cnt).zfill(6)
    i.append(ans)
    prev_p = p

py = sorted(py, key=lambda x: x[0])
for i in py:
    print(i[2])
Buggy code:
n , m = map(int, input().split())

lis = []
for i in range(m):
    a = list(map(int, input().split()))
    a.append(i)
    lis.append(a)
print(lis)

t = 1
tmp = sorted(lis)[0][0]

nlis =[]

for i in sorted(lis):
    if tmp == i[0]:
        a = str(i[0])
        left = a.zfill(6)
        right = str(t).zfill(6)
        t += 1
    else:
        t = 1
        tmp = i[0]
        left = str(i[0]).zfill(6)
        right = str(t).zfill(6)
    
    nlis.append([i[2],left+right])

for j in sorted(nlis):
    print(j[1])


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

lis = []
for i in range(m):
    a = list(map(int, input().split()))
    a.append(i)
    lis.append(a)

t = 1
tmp = sorted(lis)[0][0]

nlis =[]

for i in sorted(lis):
    if tmp == i[0]:
        left = str(i[0]).zfill(6)
        right = str(t).zfill(6)
        t += 1
    else:
        t = 1
        tmp = i[0]
        left = str(i[0]).zfill(6)
        right = str(t).zfill(6)
        t += 1
    
    nlis.append([i[2],left+right])

for j in sorted(nlis):
    print(j[1])
Buggy code:
n,m = map(int, input().split())
py=[]
for i in range(m):
    p,y=map(int, input().split())
    py.append([i,p,y])
#py = [list(map(int, input().split())) for i in range(m)]
py.sort(key=lambda x:(x[1],x[2]))
sorted_py = py
num = 1
prev_p = str(sorted_py[0][1])
for i in range(m):
    if prev_p != sorted_py[i][1]:
        num = 1
    p = str(sorted_py[i][1])
    str_num = str(num)
    if len(p)!=6:
        p = '0'*(6-len(p))+p
    if len(str_num)!=6:
        str_num = '0'*(6-len(str_num))+str_num
    sorted_py[i].append(p+str_num)
    prev_p = p
    num+=1
sorted_py.sort()
for i in range(m):
    print(sorted_py[i][3])

Fixed code:
n,m = map(int, input().split())
py=[]
for i in range(m):
    p,y=map(int, input().split())
    py.append([i,p,y])
#py = [list(map(int, input().split())) for i in range(m)]
py.sort(key=lambda x:(x[1],x[2]))
sorted_py = py
num = 1
prev_p = str(sorted_py[0][1])
for i in range(m):
    p = str(sorted_py[i][1])
    if prev_p != p:
        num = 1
        prev_p = p
    str_num = str(num)
    if len(p)!=6:
        p = '0'*(6-len(p))+p
    if len(str_num)!=6:
        str_num = '0'*(6-len(str_num))+str_num
    sorted_py[i].append(p+str_num)
    num+=1
sorted_py.sort()
for i in range(m):
    print(sorted_py[i][3])
Buggy code:
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
PY = sorted(PY, key = lambda x: (x[0], x[1]))
d = {}
for py in PY:
  if(py[0] not in d):
    d[py[0]] = 1
  else:
    d[py[0]] += 1
  py[2] = d[py[0]]
for py in PY:
  print(str(py[0]).zfill(6) + str(py[2]).zfill(6))

Fixed code:
N, M = map(int,input().split())
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
sort_PY = sorted(PY, key = lambda x: x[1])
d = {}
for py in sort_PY:
  if(py[0] not in d):
    d[py[0]] = 1
  else:
    d[py[0]] += 1
  py[2] = d[py[0]]
for py in PY:
  print(str(py[0]).zfill(6) + str(py[2]).zfill(6))
Buggy code:
pre_n, city_n = map(int, input().split())
cities = [list(map(int, input().split())) for x in range(city_n)]

history = {}

A = {}

print(sorted(cities))

for x in sorted(cities):
    pref = str(x[0])
    if pref not in history:
        history[pref] = '1'

    A.setdefault(str(x), '0'*(6-len(pref)) + pref + '0'*(6-len(history[pref])) + history[pref])

    history[pref] = str(int(history[pref]) + 1)

for x in cities:
    print(A[str(x)])


Fixed code:
pre_n, city_n = map(int, input().split())
cities = [list(map(int, input().split())) for x in range(city_n)]

history = {}

A = {}

for x in sorted(cities):
    pref = str(x[0])
    if pref not in history:
        history[pref] = '1'

    A.setdefault(str(x), '0'*(6-len(pref)) + pref + '0'*(6-len(history[pref])) + history[pref])

    history[pref] = str(int(history[pref]) + 1)

for x in cities:
    print(A[str(x)])
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]))
print(py)
_dict = {}

ans=[]
for i in range(m):
    if not py[i][0] in _dict:
        _dict[py[i][0]]=1
    else:
        _dict[py[i][0]]+=1
    p="0"*(6-len(str(py[i][0])))+str(py[i][0])
    y="0"*(6-len(str(py[i][0])))+str(_dict[py[i][0]])
    ans.append([p+y,py[i][2]])

ans.sort(key=lambda x: x[1])
for i in range(m):
    print(ans[i][0])

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]))
_dict = {}

ans=[]
for i in range(m):
    if not py[i][0] in _dict:
        _dict[py[i][0]]=1
    else:
        _dict[py[i][0]]+=1
    p="0"*(6-len(str(py[i][0])))+str(py[i][0])
    y="0"*(6-len(str(_dict[py[i][0]])))+str(_dict[py[i][0]])
    ans.append([p+y,py[i][2]])

ans.sort(key=lambda x: x[1])
for i in range(m):
    print(ans[i][0])
Buggy code:
N,M = map(int,input().split())

P = [0]*M
Y = [0]*M

for i in range(M):
    p,y = map(int,input().split())
    P.append(p)
    Y.append(y)

A = [0]*M
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = Y[i]*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))


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

P = [0]*M
Y = [0]*M

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

A = [0]*N
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = Y[i]*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))
Buggy code:
ken_num, city_num = map(int,input().split())
city_list = [None for _ in range(city_num)]
ken_list = [1 for _ in range(ken_num+1)]
id_list = [None for _ in range(city_num)]
for index in range(city_num):
    city_list[index] = list(map(int,input().split()))
    city_list[index].append(index)
city_list = sorted(city_list, key=lambda x: x[1])

for index,city in enumerate(city_list):
    id_list[city[2]] = str(city[0]).zfill(6) + str(ken_list[city[0]]).zfill(6)
    ken_list[city[0]] += 1

print(id_list)

Fixed code:
ken_num, city_num = map(int,input().split())
city_list = [None for _ in range(city_num)]
ken_list = [1 for _ in range(ken_num+1)]
id_list = [None for _ in range(city_num)]
for index in range(city_num):
    city_list[index] = list(map(int,input().split()))
    city_list[index].append(index)
city_list = sorted(city_list, key=lambda x: x[1])

for index,city in enumerate(city_list):
    id_list[city[2]] = str(city[0]).zfill(6) + str(ken_list[city[0]]).zfill(6)
    ken_list[city[0]] += 1

for ans in id_list:
    print(ans)
Buggy code:
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(m)]
s = []
for i in enumerate(l):
    s.append(i)
a = 1
for i in range(m):
    if i==0:
        s[0][1][1]=1
    elif s[i][1][0]==s[i-1][1][0]:
        a+=1
        s[i][1][1]=a
    elif s[i][1][0] != s[i-1][1][0]:
        a=1
        s[i][1][1]=a
s = sorted(s,key=lambda x:x[0])
for i in s:
    print('%06d'%i[1][0]+'%06d'%i[1][1])


Fixed code:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
s=[]
for i in enumerate(l):
    s.append(i)
s=sorted(s,key=lambda x:(x[1][0],x[1][1]))
a=0
for i in range(m):
    if s[i][1][0]==0:
       a=1     
    elif s[i][1][0]==s[i-1][1][0]:
        a+=1
    elif s[i][1][0]!=s[i-1][1][0]:
        a=1
    s[i][1][1]=a
s = sorted(s,key=lambda x:x[0])
for i in s:
    print('%06d'%i[1][0]+'%06d'%i[1][1])
Buggy code:
import bisect
N, M = map(int, input().split())
P, Y = [], []
pref = [[] for _ in range(N+1)] # non-0-indexed
for m in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
bisect.insort(pref[p], y)

    
for p,y in zip(P,Y):
    ans = "{:0>6}".format(p)
    i = bisect.bisect(pref[p], y)
    ans += "{:0>6}".format(i)
    print(ans)


Fixed code:
import bisect
N, M = map(int, input().split())
P, Y = [], []
pref = [[] for _ in range(N+1)] # non-0-indexed
for m in range(M):
    p,y = map(int, input().split())
    P.append(p)
    Y.append(y)
    pref[p].append(y)
for i, p in enumerate(pref):
    pref[i] = sorted(p)
    
for p,y in zip(P,Y):
    ans = "{:0>6}".format(p)
    i = bisect.bisect(pref[p], y)
    ans += "{:0>6}".format(i)
    print(ans)
Buggy code:
n,m = map(int,input().split())
inl = [[i] + list(map(int,input().split())) for i in range(m)]
inl = sorted(inl,key=lambda x:x[1])
inl = sorted(inl,key=lambda x:x[2])
cnt = 1
for i in range(m):
    inl[i][1] = str(inl[i][1]).rjust(6,"0")
    inl[i][2] = str(cnt).rjust(6,"0")
    cnt +=1
    if  i!=m-1 and inl[i][1] != inl[i+1][1]:
        cnt = 1

inl = sorted(inl,key=lambda x:x[0])
for i in range(m):
    print(str(inl[i][1])+str(inl[i][2]))

Fixed code:
n,m = map(int,input().split())
inl = [[i] + list(map(int,input().split())) for i in range(m)]
inl = sorted(inl,key=lambda x:x[2])
inl = sorted(inl,key=lambda x:x[1])
cnt = 1
for i in range(m):
    a = str(inl[i][1]).rjust(6,"0")
    b = str(cnt).rjust(6,"0")
    cnt +=1
    if i !=m-1 and inl[i][1] != inl[i+1][1]:
        cnt = 1
    inl[i][1] = a
    inl[i][2] = b
inl = sorted(inl,key=lambda x:x[0])
for i in range(m):
    print(str(inl[i][1])+str(inl[i][2]))
Buggy code:
N, M = map(int,input().split())
all_city = [list(map(int,input().split())) for i in range(M)]

city = {}
for i in all_city:
    if i[0] in city:
        city[i[0]].append(i[1])
    else:
        city[i[0]] = [i[1]]

under6 = {}
for i,k in city.items():
    city[i] = sorted(k)
    for j in range(len(k)):
        under6[k[j]] = j + 1

def change_Prefecture_code(prefecture):
    return str(prefecture).zfill(6)

def change_birth_code(birth_num):
    return str(birth_num).zfill(6)

for i in all_city:
    print(change_Prefecture_code(i[0]) + change_birth_code(under6[i[1]]))

Fixed code:
N, M = map(int,input().split())
all_city = [list(map(int,input().split())) for i in range(M)]
 
city = {}
for i in all_city:
    if i[0] in city:
        city[i[0]].append(i[1])
    else:
        city[i[0]] = [i[1]]
 
under6 = {}
for i,k in city.items():
    city[i] = sorted(k)
    for j in range(len(city[i])):
        under6[city[i][j]] = j + 1

def change_Prefecture_code(prefecture):
    return str(prefecture).zfill(6)
 
def change_birth_code(birth_num):
    return str(birth_num).zfill(6)
 
for i in all_city:
    print(change_Prefecture_code(i[0]) + change_birth_code(under6[i[1]]))
Buggy code:
n, m = map(int,input().split())
xs = [0]*m
pre = [0]*m
for x in range(m):
    xs[x] = list(list(map(int,input().split())) + [x] + [x])
xs.sort()

print(xs)
skip = 0
for p in range(1,n+1):
    cnt = 1
    flag = 0
    for x in range(skip,len(xs)):
        if xs[x][0] <= p:
            xs[x][3] = cnt
            cnt += 1
            skip += 1
        else:
            flag = 1
        if flag:
            break


for x in sorted(xs, key=lambda x:x[2]):
    print('{0:06d}'.format(x[0]) + '{0:06d}'.format(x[3]))


Fixed code:
n, m = map(int,input().split())
xs = [0]*m
pre = [0]*m
for x in range(m):
    xs[x] = list(list(map(int,input().split())) + [x] + [x])
xs.sort()

skip = 0
for p in range(1,n+1):
    cnt = 1
    flag = 0
    for x in range(skip,len(xs)):
        if xs[x][0] <= p:
            xs[x][3] = cnt
            cnt += 1
            skip += 1
        else:
            flag = 1
        if flag:
            break


for x in sorted(xs, key=lambda x:x[2]):
    print('{0:06d}'.format(x[0]) + '{0:06d}'.format(x[3]))
Buggy code:
N, M = map(int, input().split())
D = [[] for i in range(N)]

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

ans = [None]*M

for i, d in enumerate(D): 
  d.sort()
  print(d)
  for k, (y, j) in enumerate(d): 
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6)
print(*ans, sep = '\n') 

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

ans = [None]*M
 
for i, d in enumerate(D): 
  d.sort()
  for k, (y, j) in enumerate(d): 
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6)
print(*ans, sep = '\n')
Buggy code:
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
town = [[] for _ in range(N)]
for i in range(Q):
    place, year = map(int, input().split())
    tmp = [0,0]
    tmp[0] = year
    tmp[1] = i
    town[place-1].append(tmp)

print(town)

ans = []

for item in town:
    index = town.index(item)
    print(item)
    item.sort()
    index += 1
    index = str(index)
    while len(index) < 6:
        index = '0' + index
    for i in range(len(item)):
        num = i + 1
        num = str(num)
        while len(num) < 6:
            num = '0' + num
        xxx = index + num
        tmp = []
        tmp.append(item[i][1])
        tmp.append(xxx)
        ans.append(tmp)

ans.sort()
for item in ans:
    print(item[1])


Fixed code:
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
town = [[] for _ in range(N)]
for i in range(Q):
    place, year = map(int, input().split())
    town[place-1].append([year,i])

# print(town)

ans = []
k = 0
for item in town:
    index = k
    # index = town.index(item)
    # print(item)
    item.sort()
    index = str(index+1)
    while len(index) < 6:
        index = '0' + index
    for i in range(len(item)):
        num = str(i+1)
        while len(num) < 6:
            num = '0' + num
        xxx = index + num
        ans.append([item[i][1],xxx])
    k += 1

ans.sort()
for item in ans:
    print(item[1])
Buggy code:
import bisect

n, m = [int(_) for _ in input().split(' ')]

p, y = [], []
for _ in range(m):
    temp = [int(_) for _ in input().split(' ')]
    p.append(temp[0])
    y.append(temp[1])
ys = dict()
for i in range(m):
    if not(p[i] in ys):
        ys[p[i]] = []
    ys[p[i]].append(y[i])

for j in ys.keys():
    ys[j].sort()

print(ys)

for i in range(m):
    print('{0}{1}'.format(str(p[i]).zfill(6), str(bisect.bisect(ys[p[i]], y[i])).zfill(6)))


Fixed code:
import bisect

n, m = [int(_) for _ in input().split(' ')]

p, y = [], []
for _ in range(m):
    temp = [int(_) for _ in input().split(' ')]
    p.append(temp[0])
    y.append(temp[1])
ys = dict()
for i in range(m):
    if not(p[i] in ys):
        ys[p[i]] = []
    ys[p[i]].append(y[i])

for j in ys.keys():
    ys[j].sort()

for i in range(m):
    print('{0}{1}'.format(str(p[i]).zfill(6), str(bisect.bisect(ys[p[i]], y[i])).zfill(6)))
Buggy code:
N,M = map(int,input().split())
PY = []
for i in range(M):
    p,y = map(int,input().split())
    PY.append([p,y,i])
PY.sort()
print(PY)

ans = [0 for i in range(M)]
c = 1
d = 0
for i in range(M):
    
    if c == PY[i][0]:
        d += 1
    else:
        c = PY[i][0]
        d = 1
    ans[PY[i][2]] = '0'*(6-len(str(PY[i][0])))  + str(PY[i][0]) + '0'*(6-len(str(PY[i][1]))) + str(d)
for i in ans:
    print(i)

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


ans = [0 for i in range(M)]
c = 1
d = 0
for i in range(M):
    
    if c == PY[i][0]:
        d += 1
    else:
        c = PY[i][0]
        d = 1
    ans[PY[i][2]] = '0'*(6-len(str(PY[i][0])))  + str(PY[i][0]) + '0'*(6-len(str(d))) + str(d)
for i in ans:
    print(i)
Buggy code:
import sys
class City:
  def __init__(self, index, pref, time):
    self.index = index
    self.pref = pref
    self.time = time
    self.sort_res = None
  def get_id(self):
    str1 = "0"*(6-len(str(self.pref)))+str(self.pref)
    str2 = "0"*(6-len(str(self.sort_res)))+str(self.sort_res)
    return str1 + str2
if __name__ == '__main__':
  nm = list(sys.stdin,readline().split(" "))
  N = int(nm[0])
  M = int(nm[1])
  prefs = [[]] * N
  cities = []
  for i in range(M):
    info = list(sys.stdin,readline().split(" "))
    newcity = City(i,int(info[0]),int(info[1]))
    prefs[int(info[0])].append(newcity)
  for i in range(N):
    prefs[i].sort(key = lambda x: x.time)
  	for j in range(len(prefs[i])):
      prefs[i][j].sort_res = j+1
  for i in prefs:
    for j in i:
      cities.append(i)
  cities.sort(key = lambda x:x.index)
  for i in cities:
    print(i.get_id())
  
      
   
  

Fixed code:
import sys


class City:
    def __init__(self, ind, pref, time):
        self.ind = ind
        self.pref = pref
        self.time = time
        self.sort_res = None

    def get_id(self):
        str1 = "0" * (6 - len(str(self.pref))) + str(self.pref)
        str2 = "0" * (6 - len(str(self.sort_res))) + str(self.sort_res)
        return str1 + str2
    def __str__(self):
    	return str(self.ind)
if __name__ == '__main__':
    nm = list(sys.stdin.readline().split(" "))
    N = int(nm[0])
    M = int(nm[1])
    prefs = [[] for x in range(N)]
    cities = []
    for i in range(M):
        info = sys.stdin.readline().rstrip().split(" ")
        newcity = City(i, int(info[0]), int(info[1]))
        prefs[int(info[0])-1].append(newcity)
    for i in range(N):
        prefs[i].sort(key=lambda x: x.time)
        for j in range(len(prefs[i])):
            prefs[i][j].sort_res = j + 1
    for i in prefs:
        for j in i:
            cities.append(j)
    cities.sort(key=lambda y: y.ind)
    for i in cities:
        print(i.get_id())