qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n,m=map(int,input().split())
l=[]
for i in range(m):
    a,b=map(int,input().split())
    l.append([a,b])
x=sorted(l)
dic={}
x.append([0,0])
f=1
for i in range(m):
    if x[i][0]==x[i+1][0]:
        dic[str(x[i][0])+'000000'+str(x[i][1])]=f
        f+=1
    else:
        dic[str(x[i][0])+'000000'+str(x[i][1])]=f
        f=1
for i in range(m):
    b=dic[str(l[i][0])+'000000'+str(l[i][1])]
    p=len(list(str(l[i])))
    q=len(list(str(b)))
    ans=''
    for j in range(6-p):
        ans+='0'
    ans+=str(l[i])
    for j in range(6-q):
        ans+='0'
    ans+=str(b)
    print(ans)


Fixed code:
n,m=map(int,input().split())
l=[]
for i in range(m):
    a,b=map(int,input().split())
    l.append([a,b])
x=sorted(l)
dic={}
x.append([0,0])
f=1
for i in range(m):
    if x[i][0]==x[i+1][0]:
        dic[str(x[i][0])+'000000'+str(x[i][1])]=f
        f+=1
    else:
        dic[str(x[i][0])+'000000'+str(x[i][1])]=f
        f=1
for i in range(m):
    b=dic[str(l[i][0])+'000000'+str(l[i][1])]
    p=len(list(str(l[i][0])))
    q=len(list(str(b)))
    ans=''
    for j in range(6-p):
        ans+='0'
    ans+=str(l[i][0])
    for j in range(6-q):
        ans+='0'
    ans+=str(b)
    print(ans)
Buggy code:
import bisect
import collections

N, M = map(int, input().split())
PM = [[int(j) for j in input().split()] for i in range(M)]
A = collections.defaultdict(list)
for x, y in sorted(PM):
    A[x] += [y]
for x, y in PM:
    z = bisect.bisect(A[x], y)
    print('%06d%06d'%(x,y))

Fixed code:
import bisect
import collections

N, M = map(int, input().split())
PM = [[int(j) for j in input().split()] for i in range(M)]
A = collections.defaultdict(list)
for x, y in sorted(PM):
    A[x] += [y]
for x, y in PM:
    z = bisect.bisect(A[x], y)
    print('%06d%06d'%(x,z))
Buggy code:
# ABC113C - ID
import sys
input = sys.stdin.readline

def main():
    N, M = tuple(map(int, input().split()))
    P = [[] for _ in range(N + 1)]  # prefectures
    for num in range(M):  # classify cities by prefectures
        pref, year = tuple(map(int, input().split()))
        P[pref] += [(year, num)]
    ans = [""] * M
    P = tuple(sorted(p) for p in P)  # sort by year
    for pref_idx, pref in enumerate(P):
        for city_idx, (_, num) in enumerate(pref, 1):
            x = "{:06}{:06}".format(pref_idx, city_idx)
            ans[num] = x
    print(*ans, sep="\n")
    print(type(P))

if __name__ == "__main__":
    main()

Fixed code:
# ABC113C - ID
import sys
input = sys.stdin.readline

def main():
    N, M = tuple(map(int, input().split()))
    P = [[] for _ in range(N + 1)]  # prefectures
    for num in range(M):
        pref, year = tuple(map(int, input().split()))
        P[pref] += [(year, num)]
    ans = []
    P = [sorted(p) for p in P]
    for pref_idx, pref in enumerate(P[1:], 1):
        if pref:
            for city_idx, (_, num) in enumerate(pref, 1):
                x = "{:06}{:06}".format(pref_idx, city_idx)
                ans += [(num, x)]
    print(*[i[1] for i in sorted(ans)], sep="\n")

if __name__ == "__main__":
    main()
Buggy code:
## ABC113C - ID
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    ans = [""] * m
    arr = []
    cnt = 1
    for i in range(m):
        p, y = list(map(int, input().split()))
        arr += [(p, y, i)]
    arr = sorted(arr)

    ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
    for i in range(1, m):
        if arr[i - 1][0] == arr[i][0]:
            cnt += 1
        else:
            cnt = 1
        ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

    for i in ans:
        print(i)
    print(ans)


if __name__ == "__main__":
    main()

Fixed code:
## ABC113C - ID
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    ans = [""] * m
    arr = []
    cnt = 1
    for i in range(m):
        p, y = list(map(int, input().split()))
        arr += [(p, y, i)]
    arr = sorted(arr)

    ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
    for i in range(1, m):
        if arr[i - 1][0] == arr[i][0]:
            cnt += 1
        else:
            cnt = 1
        ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

    for i in ans:
        print(i)


if __name__ == "__main__":
    main()
Buggy code:
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
ans = [""] * m
arr = []
cnt = 1
for i in range(m):
    p, y = map(int, input().split())
    arr += [(p, y, i)]
arr = sorted(arr)

ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
for i in range(1, m):
    if arr[i - 1][0] == arr[i][0]:
        cnt += 1
    else:
        cnt = 1
    ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

for i in asn:
    print(i)
print(*ans, sep="\n")

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

n, m = list(map(int, input().rstrip().split()))
ans = [""] * m
arr = []
cnt = 1
for i in range(m):
    p, y = map(int, input().split())
    arr += [(p, y, i)]
arr = sorted(arr)

ans[arr[0][2]] = "{:06}{:06}".format(arr[0][0], cnt)
for i in range(1, m):
    if arr[i - 1][0] == arr[i][0]:
        cnt += 1
    else:
        cnt = 1
    ans[arr[i][2]] = "{:06}{:06}".format(arr[i][0], cnt)

for i in ans:
    print(i)
Buggy code:
n, m = map(int, input().split())

info_list = []

for i in range(m):
    pi, yi = map(int, input().split())
    info_list.append([i+1, pi, yi])
print(info_list)

from operator import itemgetter
info_list.sort(key = itemgetter(2))
print(info_list)


xth = [1 for i in range(1, n+1)]
print(xth)

for info in info_list:
    info.append(str(info[1]).zfill((6)) + str(xth[info[1]-1]).zfill(6))
    xth[info[1]-1]+=1


info_list.sort(key = itemgetter(0))

for ele in info_list:
    print(ele[3])

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

info_list = []

for i in range(m):
    pi, yi = map(int, input().split())
    info_list.append([i+1, pi, yi])
# print(info_list)

from operator import itemgetter
info_list.sort(key = itemgetter(2))
# print(info_list)


xth = [1 for i in range(1, n+1)]
# print(xth)

for info in info_list:
    info.append(str(info[1]).zfill((6)) + str(xth[info[1]-1]).zfill(6))
    xth[info[1]-1]+=1


info_list.sort(key = itemgetter(0))

for ele in info_list:
    print(ele[3])
Buggy code:
m = nm[1]
all_city = list()
for i in range(m):
    py = list(map(int, input().split()))
    py.append(i)
    all_city.append(py)
ac_list = copy.deepcopy(all_city)
ac_list.sort()
ac_dict = {}
a = 0
b = 0
for i in range(m):
    if ac_list[i][0] == a:
        b += 1
    else:
        a += 1
        b = 1
    ac_dict[ac_list[i][2]] = str(str(a).zfill(6) + str(b).zfill(6))
for i in range(m):
    print(ac_dict.get(all_city[i][2]))

Fixed code:
import copy
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
all_city = list()
for i in range(m):
    py = list(map(int, input().split()))
    py.append(i)
    all_city.append(py)
ac_list = copy.deepcopy(all_city)
ac_list.sort()
ac_dict = {}
a = 0
b = 0
for i in range(m):
    if ac_list[i][0] == a:
        b += 1
    else:
        a = ac_list[i][0]
        b = 1
    ac_dict[ac_list[i][2]] = str(str(a).zfill(6) + str(b).zfill(6))
for i in range(m):
    print(ac_dict.get(all_city[i][2]))
Buggy code:
import collections
import bisect

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

ans = collections.defaultdict(list)

for p, y in sorted(P):
    ans[p] += [y]
for p, y in P:
    print("%06d%06d"%(p, bisect.bisect(a[p], y)))

Fixed code:
import collections
import bisect

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

ans = collections.defaultdict(list)

for p, y in sorted(P):
    ans[p] += [y]
for p, y in P:
    print("%06d%06d"%(p, bisect.bisect(ans[p], y)))
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])
ans = ['0'] * m
py.sort()
print(py)
j = 0
for i in range(m):
    if j!= py[i][0]:
        j = py[i][0]
        c=1
    ans[py[i][2]] = str(py[i][0]).zfill(6) + str(c).zfill(6)
    c += 1
for i in range(m):
    print(ans[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])
ans = ['0'] * m
py.sort()
#print(py)
j = 0
for i in range(m):
    if j!= py[i][0]:
        j = py[i][0]
        c=1
    ans[py[i][2]] = str(py[i][0]).zfill(6) + str(c).zfill(6)
    c += 1
for i in range(m):
    print(ans[i])
Buggy code:
def read():
    return int(input())

def reads():
    return list(map(int, input().split()))

n,m = reads()
cnt = {k:[] for k in range(n+1)}
buf = [0]*m
for i in range(m):
    p,y = reads()
    cnt[p].append((y,i))
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:
def read():
    return int(input())

def reads():
    return list(map(int, input().split()))

n,m = reads()
cnt = {k:[] for k in range(n+1)}
buf = [None]*m
for i in range(m):
    p,y = reads()
    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:
n,m = map(int,input().split())

#p = [-1]*m
#y = [-1]*m
ipy=[]

for i in range(m):
    ipy.append(list(map(int,(str(i) + " " + input()).split())))


print(ipy)

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

print(ipy)

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

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

for i in range(m):
    print(f'{ipy[i][1]:06}'+f'{ipy[i][2]:06}')



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

#p = [-1]*m
#y = [-1]*m
ipy=[]

for i in range(m):
    ipy.append(list(map(int,(str(i) + " " + input()).split())))

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

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

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

for i in range(m):
    print(f'{ipy[i][1]:06}'+f'{ipy[i][2]:06}')
Buggy code:

n,m = map(int, input().split())
pyl = [ [] for _ in range(n+1) ]

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

ans = ['']*m
for p, yil in enumerate(pyl):
    top = str(p).zfill(6)
    yil.sort()
    for order,(y,i) in enumerate(yil):
        print(order,i)
        bottom = order+1
        bottom = str(bottom).zfill(6)
        ans[i] = top+bottom

for a in ans:
    print(a)

Fixed code:

n,m = map(int, input().split())
pyl = [ [] for _ in range(n+1) ]

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

ans = ['']*m
for p, yil in enumerate(pyl):
    top = str(p).zfill(6)
    yil.sort()
    for order,(y,i) in enumerate(yil):
        bottom = order+1
        bottom = str(bottom).zfill(6)
        ans[i] = top+bottom

for a in ans:
    print(a)
Buggy code:
n,m = map(int, input().split())
PY = [[] for i in range(m)]
for i in range(m):
  PY[i] = list(i,map(int, input().split()))

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

l = [0]*(n)
for i in range(m):
  l[PY[i][1]-1]+=1

for i in range(n):
  j = 0
  while j < l[i]:
    list(filter(lambda x:x[1]==i+1,PY))[j].append(j+1)
    j += 1
  
PY.sort(key = lambda x:x[0])
for i in range(m):
  print('{:0=6}'.format(PY[i][1])+'{:0=6}'.format(PY[i][3]))
  

Fixed code:
n,m = map(int, input().split())
PY = [[] for i in range(m)]
for i in range(m):
  PY[i] = list(map(int, input().split()))
  PY[i].append(i)
  
PY.sort(key = lambda x:x[1])

l = [0]*(n)
for i in range(m):
  l[PY[i][0]-1]+=1
  PY[i].append(l[PY[i][0]-1])

  
PY.sort(key = lambda x:x[2])
for i in range(m):
  print('{:0=6}'.format(PY[i][0])+'{:0=6}'.format(PY[i][3]))
Buggy code:
n,m = map(int,input().split())
city = [[] for _ in range(n+1)]
ret = ["" for _ in range(m)]
def createSix(s):
    while len(s) != 6:
        s = "0" + s
    return s
for i in range(m):
    a,b = map(int, input().split())
    city[a].append((b, i))
for i in range(m):
    city[i].sort()
print(city)
for i in range(n+1):
    for j in range(len(city[i])):
        ret[city[i][j][1]] = createSix(str(i)) + createSix(str(j+1))
for i in ret:
    print(i)
    

    


Fixed code:
n,m = map(int,input().split())
city = [[] for _ in range(n+1)]
ret = ["" for _ in range(m)]
def createSix(s):
    while len(s) != 6:
        s = "0" + s
    return s
for i in range(m):
    a,b = map(int, input().split())
    city[a].append((b, i))
for i in range(n+1):
    city[i].sort()
for i in range(n+1):
    for j in range(len(city[i])):
        ret[city[i][j][1]] = createSix(str(i)) + createSix(str(j+1))
for i in ret:
    print(i)
Buggy code:
from operator import itemgetter
n,m=map(int,input().split())
l=[]
id_list=[]
for i in range(m):
  l.append(list(map(int, input().split())))
l=sorted(l, key=itemgetter(1))
idx=0
for j in range(m):
  if j == 0:
    idx=1
  else:
    if l[j][0] == l[j-1][0]:
      idx+=1
    else:
      idx =1
  id_list.append(str(l[j][0]).zfill(6)+str(idx).zfill(6))
print(sorted(id_list))

Fixed code:
from operator import itemgetter
n,m=map(int,input().split())
l=[]
id_list=[]
for i in range(m):
  obj = list(map(int, input().split()))
  obj.append(i+1)
  l.append(obj)
l=sorted(l, key=itemgetter(0,1))
idx=0
for j in range(m):
  id_obj=[]
  if j == 0:
    idx=1
  else:

    if l[j][0] == l[j-1][0]:
      idx+=1
    else:
      idx =1
  id_obj.append(l[j][2])
  id_obj.append(str(l[j][0]).zfill(6)+str(idx).zfill(6))
  id_list.append(id_obj)
id_list = sorted(id_list)
for k in range(m):
  print(id_list[k][1])
Buggy code:
import bisect
n, m = map(int, input().split())
p = []
y = []
py = []
categorized = [[] for i in range(n+1)]
for i in range(m):
    tmpp, tmpy = map(int, input().split())
    p.append(tmpp)
    y.append(tmpy)
    categorized[tmpp].append(tmpy)

for c in categorized:
    c.sort()
print(categorized)
for i in range(m):
    order = bisect.bisect(categorized[p[i]], y[i])
    print('%06d%06d' % (p[i], order))


Fixed code:
import bisect
n, m = map(int, input().split())
p = []
y = []
py = []
categorized = [[] for i in range(n+1)]
for i in range(m):
    tmpp, tmpy = map(int, input().split())
    p.append(tmpp)
    y.append(tmpy)
    categorized[tmpp].append(tmpy)

for c in categorized:
    c.sort()
for i in range(m):
    order = bisect.bisect(categorized[p[i]], y[i])
    print('%06d%06d' % (p[i], order))
Buggy code:
import bisect
def zaatu(a):
    b=list(set(a))
    for i in range(len(a)):
        a[i]=bisect.bisect_left(b,a[i])
    return a
n,m=map(int,input().split())
a=[[] for _ in range(n)]
b=[]
for i in range(m):
    p,y=map(int,input().split())
    a[p-1].append([p,y,i])
for i in range(n):
    a[i].sort(key=lambda x:x[1])
for i in range(n):
    for j in range(len(a[i])):
        b.append([a[i][j],j+1])
b.sort(key=lambda x:x[0][2])
print(b)
for i in b:
    print('0'*(6-len(str(i[0][0])))+str(i[0][0])+'0'*(6-len(str(i[1])))+str(i[1]))

Fixed code:
import bisect
def zaatu(a):
    b=list(set(a))
    for i in range(len(a)):
        a[i]=bisect.bisect_left(b,a[i])
    return a
n,m=map(int,input().split())
a=[[] for _ in range(n)]
b=[]
for i in range(m):
    p,y=map(int,input().split())
    a[p-1].append([p,y,i])
for i in range(n):
    a[i].sort(key=lambda x:x[1])
for i in range(n):
    for j in range(len(a[i])):
        b.append([a[i][j],j+1])
b.sort(key=lambda x:x[0][2])
for i in b:
    print('0'*(6-len(str(i[0][0])))+str(i[0][0])+'0'*(6-len(str(i[1])))+str(i[1]))
Buggy code:
import sys

def fill(s): while len(s) < 6: s = '0' + s; return s
def create_id(p, o): return fill(str(p)) + fill(str(o))

n, m, *py = map(int, sys.stdin.read().split())
pyi = sorted(zip(zip(*[iter(py)] * 2), range(m)))

def main():
    res = [None] * m
    prev = j = None
    for (p, y), i in pyi:
        j = j + 1 if p == prev else 1
        res[i] = create_id(p, j)
        prev = p
    print(*res, sep='\n')
    
if __name__ ==  '__main__':
    main()

Fixed code:
import sys

def fill(s): return '0' * (6 - len(s)) + s
def create_id(p, o): return fill(str(p)) + fill(str(o))

n, m, *py = map(int, sys.stdin.read().split())
pyi = sorted(zip(*[iter(py)] * 2 + [range(m)]))

def main():
    res = [None] * m
    prev = j = None
    for p, y, i in pyi:
        j = j + 1 if p == prev else 1
        res[i] = create_id(p, j)
        prev = p
    print(*res, sep='\n')
    
if __name__ ==  '__main__':
    main()
Buggy code:
N,M = map(int,input().split())
city_d = {}
ans_l = ["" for _ in range(M)]
for i in range(M):
    P,Y = map(int,input().split())
    city_d.setdefault(P,[])
    city_d[P].append([Y,i])

for p,y_orgnum in city_d.items():
    for j,sorted_y_orgnum in enumerate(sorted(y_orgnum,key=lambda x:x[0])):
        ans_l[sorted_y_orgnum[1]] = str(p).zfill(8) + str(j+1).zfill(8)

for ans in ans_l:
    print(ans)




Fixed code:
N,M = map(int,input().split())
city_d = {}
ans_l = ["" for _ in range(M)]
for i in range(M):
    P,Y = map(int,input().split())
    city_d.setdefault(P,[])
    city_d[P].append([Y,i])

for p,y_orgnum in city_d.items():
    for j,sorted_y_orgnum in enumerate(sorted(y_orgnum,key=lambda x:x[0])):
        ans_l[sorted_y_orgnum[1]] = str(p).zfill(6) + str(j+1).zfill(6)

for ans in ans_l:
    print(ans)
Buggy code:
if __name__ == '__main__':
    N, M = map(int, input().split())
    PY = []
    for i in range(1, M+1):
        p, y = map(int, input().split())
        PY.append((y, p, i))
    PY.sort()
    ANS = [""]*(M+1)
    P = [0]*(N+1)
    for y, p, i in PY:
        P[p] += 1
        print(y, p, i)
        ANS[i] = "{0:06d}".format(p) + "{0:06d}".format(P[p])
    
    for ans in ANS:
        if ans=="": continue
        print(ans)

Fixed code:
if __name__ == '__main__':
    N, M = map(int, input().split())
    PY = []
    for i in range(1, M+1):
        p, y = map(int, input().split())
        PY.append((y, p, i))
    PY.sort()
    ANS = [""]*(M+1)
    P = [0]*(N+1)
    for y, p, i in PY:
        P[p] += 1
        ANS[i] = "{0:06d}".format(p) + "{0:06d}".format(P[p])
    
    for ans in ANS:
        if ans=="": continue
        print(ans)
Buggy code:
from operator import itemgetter

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

x = [0] * n
pn = [i for i in range(1, m+1)]
idn = [''] * m
yp = list(zip(y, p, pn, idn))
yp.sort()

for i in range(m):
    p_ = p[i] - 1
    x[p_] += 1
    idn[i] = format(p[i], '0>6') + format(x[p_], '0>6')

yp.sort(key=itemgetter(2))
for i in range(m):
    print(idn[i])

Fixed code:
from operator import itemgetter

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

x = [0] * n
pn = [i for i in range(1, m+1)]
idn = [''] * m

yp = list(zip(y, p, pn))
yp.sort()

for i in range(m):
    p_ = yp[i][1] - 1
    x[p_] += 1
    idn[i] = format(yp[i][1], '0>6') + format(x[p_], '0>6')

y, p, pn = zip(*yp)
yp = list(zip(y, p, pn, idn))
yp.sort(key=itemgetter(2))
for i in range(m):
    print(yp[i][3])
Buggy code:
import numpy as np
from operator import itemgetter

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

for i, c in enumerate(C):
  C[i] = [int(c[0]), int(c[1])]
  C[i].append(i)

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

counter = 1
current = 1

for c in C_sorted:
  if current < c[0]:
    counter = 1
  pref = str(c[0])
  num = str(counter)
  number = ''
  for i in range(6 - len(pref)):
    number += '0'
  number += pref
  for i in range(6 - len(num)):
    number += '0'
  number += num

  c.append(number)
  counter += 1
  current = c[0]

print(C_sorted)

C_reversed = sorted(C_sorted, key = lambda x: x[2])

for c in C_reversed:
  print(c[3])

Fixed code:
import numpy as np
from operator import itemgetter

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

for i, c in enumerate(C):
  C[i] = [int(c[0]), int(c[1])]
  C[i].append(i)

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

counter = 1
current = 1

for c in C_sorted:
  if current < c[0]:
    counter = 1
  pref = str(c[0])
  num = str(counter)
  number = ''
  for i in range(6 - len(pref)):
    number += '0'
  number += pref
  for i in range(6 - len(num)):
    number += '0'
  number += num

  c.append(number)
  counter += 1
  current = c[0]

C_reversed = sorted(C_sorted, key = lambda x: x[2])

for c in C_reversed:
  print(c[3])
Buggy code:
import bisect

N, M = map(int, input().split())
PY = []
array = [[] for _ in range(N)]

for _ in range(M):
    P, Y = map(int, input().split())
    PY.append([P, Y])
    array[P-1].append(Y)

for p, y in PY:
    n = bisect.bisect_left(array[p-1], y) + 1
    print('%06d%06d' % (p, n))


Fixed code:
import bisect

N, M = map(int, input().split())
PY = []
array = [[] for _ in range(N)]

for _ in range(M):
    P, Y = map(int, input().split())
    PY.append([P, Y])
    array[P-1].append(Y)
    
for i in range(N):
    array[i].sort()

for p, y in PY:
    n = bisect.bisect_left(array[p-1], y) + 1
    print('%06d%06d' % (p, n))
Buggy code:
# ABC113 D 

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

P=[[] for _ in [0]*(N+1)]

for i in range(M):
    p,y=map(int,input().split())
    P[p].append((y,i))
    
from bisect import bisect_left as bl

res=[]
for p in range(N+1):
    Y=P[p][:]
    if not Y:
        continue
    
    sortY=sorted(list(set([y for y,i in Y])))

    zatY=[]
    for y,i in Y:
        zatY.append(bl(sortY,y))
    
    for index in zatY:
        y,i=Y[index]
        num=10**12+p*10**6+index+1
        res.append((str(num)[1:],i))

res=[y for y,i in sorted(res,key=lambda x:x[1])]
print(*res,sep='\n')

Fixed code:
# ABC113 D 

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

P=[[] for _ in [0]*(N+1)]

for i in range(M):
    p,y=map(int,input().split())
    P[p].append((y,i))
    
from bisect import bisect_left as bl

res=[]
for p in range(N+1):
    Y=P[p][:]
    if not Y:
        continue
    
    sortY=sorted(list(set(Y)))
        
    zatY=[]
    for t_y in Y:
        zatY.append(bl(sortY,t_y))
    
    for index in zatY:
        y,i=sortY[index]
        num=10**12+p*10**6+index+1
        res.append((str(num)[1:],i))

res=[y for y,i in sorted(res,key=lambda x:x[1])]
print(*res,sep='\n')
Buggy code:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

A = [[] for _ in range(N+1)]

for i, py in enumerate(PY):
    A[py[0]].append([py[1], i])

City = []
for i in range(N+1):
    A[i] = sorted(A[i])
    for j, a in enumerate(A[i]):
        pref = i
        city = j
        City.append([a[1], str(pref).zfill(6) + str(city).zfill(6)])

City = sorted(City)
for city in City:
    print(city[1])

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

A = [[] for _ in range(N+1)]

for i, py in enumerate(PY):
    A[py[0]].append([py[1], i])

City = []
for i in range(N+1):
    A[i] = sorted(A[i])
    for j, a in enumerate(A[i]):
        pref = i
        city = j+1
        City.append([a[1], str(pref).zfill(6) + str(city).zfill(6)])

City = sorted(City)
for city in City:
    print(city[1])
Buggy code:
def mks(num):
  s=str(num)
  if len(s)<6:
    s='0'*(6-len(s))+s
  return s

n,m=map(int,input().split())
arr=[]
for i in range(m):
  p,y=map(int,input().split)
  arr.append([p,y,i])
ans=[0]*m
arr=sorted(arr,key=lambda x:x[1])
arr=sorted(arr,key=lambda x:x[0])
tmp=arr[0][0]
cnt=1
for i in range(m):
  if arr[i][0]==tmp:
    s1,s2=mks(tmp),mks(cnt)
    ans[arr[i][2]]=s1+s2
    cnt+=1
  else:
    cnt=1
    tmp=arr[i][0]
    s1,s2=mks(tmp),mks(cnt)
    ans[arr[i][2]]=s1+s2
for i in range(m):
  print(ans[i])

Fixed code:
def mks(num):
  s=str(num)
  if len(s)<6:
    s='0'*(6-len(s))+s
  return s

n,m=map(int,input().split())
arr=[]
for i in range(m):
  p,y=map(int,input().split())
  arr.append([p,y,i])
ans=[0]*m
arr=sorted(arr,key=lambda x:x[1])
arr=sorted(arr,key=lambda x:x[0])
tmp=arr[0][0]
cnt=1
for i in range(m):
  if arr[i][0]==tmp:
    s1,s2=mks(tmp),mks(cnt)
    ans[arr[i][2]]=s1+s2
    cnt+=1
  else:
    cnt=1
    tmp=arr[i][0]
    s1,s2=mks(tmp),mks(cnt)
    ans[arr[i][2]]=s1+s2
    cnt+=1
for i in range(m):
  print(ans[i])