qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from itertools import groupby

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

py = [py_i + [i] for i, py_i in enumerate(py)]
py_ = []
for key, group in groupby(py, lambda x: x[0]):
	for i, city in enumerate(group):
		py_.append(city + [i+1])
py = sorted(py_, key=lambda x: x[3])

for py_i in py:
	print(str(py_i[0]).zfill(6) + str(py_i[3]).zfill(6))

Fixed code:
from itertools import groupby

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

py = [py_i + [i] for i, py_i in enumerate(py)]
py_ = []
for key, group in groupby(sorted(py, key=lambda x: x[0]), lambda x: x[0]):
	for i, city in enumerate(sorted(group, key=lambda x: x[1])):
		py_.append(city + [i+1])

py = sorted(py_, key=lambda x: x[2])

for py_i in py:
	print(str(py_i[0]).zfill(6) + str(py_i[3]).zfill(6))
Buggy code:
n, m =map(int, input().split())
py_array = [[int(x) for x in input().split()]+[y] for x, y in enumerate(range(m), 0)]
py_array = sorted(py_array, key=lambda x:(x[0], x[1]))

base = 1
base2 = 0
res_array = []
for i, j, k in py_array:
    if base == i:
        base2 += 1
        print(i)
    else:
        base = i
        base2 = 1
    res_array.append([str(base).zfill(6), str(base2).zfill(6), k])

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

for i, j, k in res_array:
    print(i, j)

Fixed code:
n, m =map(int, input().split())
py_array = [[int(x) for x in input().split()]+[y] for x, y in enumerate(range(m), 0)]
py_array = sorted(py_array, key=lambda x:(x[0], x[1]))

base = 1
base2 = 0
res_array = []
for i, j, k in py_array:
    if base == i:
        base2 += 1
    else:
        base = i
        base2 = 1
    res_array.append([str(base).zfill(6), str(base2).zfill(6), k])

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

for i, j, k in res_array:
    print(i+j)
Buggy code:
N, M = map(int, input().split())

_number = []
P = []
Y = []
yp = [[] for i in range(N+1)]
_yp = []

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

# print(yp)

_l_yp = len(yp)

for i in range(_l_yp):
    yp[i].sort()


ans_yp = [[] for i in range(M)]

for i in range(_l_yp):
    nga_yp = len(yp[i])

    for j in range(nga_yp):
       print(i, j)
       print(yp[i][j][1])
       ans_yp[yp[i][j][1]].append(i)
       ans_yp[yp[i][j][1]].append(j+1)


__len = len(ans_yp)

for i in range(__len):
    buff = ''
    for d in range(2):
        ans = ''
        for j in range((6-len(str(ans_yp[i][d])))):
            ans += '0'

        buff += ans + str(ans_yp[i][d])

    print(buff)


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

_number = []
P = []
Y = []
yp = [[] for i in range(N+1)]
_yp = []

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

# print(yp)

_l_yp = len(yp)

for i in range(_l_yp):
    yp[i].sort()


ans_yp = [[] for i in range(M)]

for i in range(_l_yp):
    nga_yp = len(yp[i])

    for j in range(nga_yp):
    #    print(i, j)
    #    print(yp[i][j][1])
       ans_yp[yp[i][j][1]].append(i)
       ans_yp[yp[i][j][1]].append(j+1)


__len = len(ans_yp)

for i in range(__len):
    buff = ''
    for d in range(2):
        ans = ''
        for j in range((6-len(str(ans_yp[i][d])))):
            ans += '0'

        buff += ans + str(ans_yp[i][d])

    print(buff)
Buggy code:
N, M = [int(n) for n in input().split()]

def main():
    ps = [[] for _ in range(N)]
    print(ps)

    for m in range(M):
        p, y = [int(n) for n in input().split()]
        pref = ps[p - 1]
        pref.append([m, y])

    result = []

    for i, pref in enumerate(ps):
        pref.sort(key=lambda p: p[1])
        for j, p in enumerate(pref):
            result.append([p[0], '{:06}{:06}'.format(i + 1, j + 1)])

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

    ans = '\n'.join(map(lambda p: p[1], result))
    print(ans)

if __name__ == '__main__':
    main()

Fixed code:
N, M = [int(n) for n in input().split()]

def main():
    ps = [[] for _ in range(N)]

    for m in range(M):
        p, y = [int(n) for n in input().split()]
        pref = ps[p - 1]
        pref.append([m, y])

    result = []

    for i, pref in enumerate(ps):
        pref.sort(key=lambda p: p[1])
        for j, p in enumerate(pref):
            result.append([p[0], '{:06}{:06}'.format(i + 1, j + 1)])

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

    ans = '\n'.join(map(lambda p: p[1], result))
    print(ans)

if __name__ == '__main__':
    main()
Buggy code:
import bisect

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

cities = {}
prefs = []

for i in range(1, M + 1):
  p, y = list(map(int, input().split()))
  
  pref = {"city": p, "year": y}
  prefs.append(pref)

  if p not in cities:
    cities[p] = [pref]
  else:
    cities[p].append(pref)
print(cities)
for city in cities.values():
  city.sort(key=lambda p: p['year'])
  for idx, pref in enumerate(city):
    pref['pref_id'] = str(idx + 1).zfill(6)

[print("%s%s" % (
  str(int(pref['city'])).zfill(6), 
  pref['pref_id'])) for pref in prefs]


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

cities = {}
prefs = []

for i in range(1, M + 1):
  p, y = list(map(int, input().split()))
  
  pref = {"city": p, "year": y}
  prefs.append(pref)

  if p not in cities:
    cities[p] = [pref]
  else:
    cities[p].append(pref)

for city in cities.values():
  city.sort(key=lambda p: p['year'])
  for idx, pref in enumerate(city):
    pref['pref_id'] = str(idx + 1).zfill(6)

[print("%s%s" % (
  str(int(pref['city'])).zfill(6), 
  pref['pref_id'])) for pref in prefs]
Buggy code:
n,m=[int(i) for i in input().split()]
P=[[int(i) for i in input().split()] for j in range(m)]

def prefecturesort(i):
    return i[0]

def yearsort(i):
    return i[1]

W=[]
Z=[]

for i in range(m):
    P[i].append(i)
    W.append(P[i][0])

P.sort(key=prefecturesort)
P_c=[]
sum=0
for i in range(n):
    P_c.append(P[sum:W.count(i+1)+sum])
    sum+=c
    P_c[i].sort(key=yearsort)
for x in P_c:
    for j in range(len(x)):
        X=str("{0:06d}".format(x[j][0]))
        Y=str("{0:06d}".format(j+1))
        Z.append([X+Y,x[j][2]])
Z.sort(key=yearsort)
for i in range(m):
    print(Z[i][0])

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

def prefecturesort(i):
    return i[0]

def yearsort(i):
    return i[1]

W=[0 for i in range(n)]
Z=[]

for i in range(m):
    P[i].append(i)
    W[P[i][0]-1]+=1

P.sort(key=prefecturesort)
P_c=[]
sum=0
for i in range(n):
    c=W[i]
    if c==0:
        P_c.append([])
    else:
        P_c.append(P[sum:c+sum])
    sum+=c
    P_c[i].sort(key=yearsort)
for x in P_c:
    for j in range(len(x)):
        X=str("{0:06d}".format(x[j][0]))
        Y=str("{0:06d}".format(j+1))
        Z.append([X+Y,x[j][2]])
Z.sort(key=yearsort)
for i in range(m):
    print(Z[i][0])
Buggy code:
def main():
    # n = int(input())
    n, m = map(int, input().split())
    # v = list(map(int, input().split()))
    # s = input()
    py = []
    for i in range(m):
        p, y = map(int, input().split())
        py.append([i, p, y])
    print(py)

    py.sort(key=lambda x: (x[1], x[2]))
    print(py)

    num = 1
    for i in range(0, m):
        if i == 0:
            py[i].append(num)
        else:
            if py[i][1] == py[i-1][1]:
                num += 1
            else:
                num = 1
            py[i].append(num)
    print(py)

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

    for i in range(m):
        print(str(py[i][1]).zfill(6) + str(py[i][3]).zfill(6))


if __name__ == '__main__':
    main()


Fixed code:
def main():
    # n = int(input())
    n, m = map(int, input().split())
    # v = list(map(int, input().split()))
    # s = input()
    py = []
    for i in range(m):
        p, y = map(int, input().split())
        py.append([i, p, y])

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

    num = 1
    for i in range(0, m):
        if i == 0:
            py[i].append(num)
        else:
            if py[i][1] == py[i-1][1]:
                num += 1
            else:
                num = 1
            py[i].append(num)

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

    for i in range(m):
        print(str(py[i][1]).zfill(6) + str(py[i][3]).zfill(6))


if __name__ == '__main__':
    main()
Buggy code:
from operator import itemgetter, attrgetter

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

pym = [None] * m
for i in range(m):
    pym[i] = [i] + list(map(int, input().split(' ')))

pyms = sorted(pym, key=itemgetter(1, 2))

x = 1
pyms[0].append(x)

for i in range(1, m):
    if pyms[i - 1][1] != pyms[i][1]:
        x = 1
    else:
        x += 1
    pyms[i].append(x)
    
pym = sorted(pyms, key=itemgetter(0, ))

for i in range(m):
    city_id = str(pym[i][1]).zfill(8) + str(pym[i][3]).zfill(8)
    print(city_id)


Fixed code:
from operator import itemgetter, attrgetter

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

pym = [None] * m
for i in range(m):
    pym[i] = [i] + list(map(int, input().split(' ')))

pyms = sorted(pym, key=itemgetter(1, 2))

x = 1
pyms[0].append(x)

for i in range(1, m):
    if pyms[i - 1][1] != pyms[i][1]:
        x = 1
    else:
        x += 1
    pyms[i].append(x)
    
pym = sorted(pyms, key=itemgetter(0, ))

for i in range(m):
    city_id = str(pym[i][1]).zfill(6) + str(pym[i][3]).zfill(6)
    print(city_id)
Buggy code:
n, m = map(int, input().split())
queue = []
for i in range(m):
    c, y= map(int, input().split())
    queue.append([c, y, i])

queue = sorted(queue)

index = 0
keep = 1
for i in range(m):
    if keep != queue[1][0]:
        index = 0
    index += 1
    queue[i][0] = str(queue[i][0]).zfill(6)
    queue[i][1] = str(index).zfill(6)

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

for data in queue:
    cn, yn, i = data
    print(cn + yn)

Fixed code:
n, m = map(int, input().split())
queue = []
for i in range(m):
    c, y= map(int, input().split())
    queue.append([c, y, i])

queue = sorted(queue)

index = 0
keep = queue[0][0]
for i in range(m):
    if keep != queue[i][0]:
        index = 0
        keep = queue[i][0]
    index += 1
    queue[i][0] = str(queue[i][0]).zfill(6)
    queue[i][1] = str(index).zfill(6)

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

for data in queue:
    cn, yn, i = data
    print(cn + yn)
Buggy 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])

city = {}
for i in range(M):
  p, y = sort_PY[i][0], sort_PY[i][1]
  if p in city:
    city[p] += 1
  else:
    city[p] = 1
  sort_PY[i][2] = city[p]
  print(city)
for p, y, z in PY:
  print(str(p).zfill(6)+str(z).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])

city = {}
for i in range(M):
  p, y = sort_PY[i][0], sort_PY[i][1]
  if p in city:
    city[p] += 1
  else:
    city[p] = 1
  sort_PY[i][2] = city[p]
for p, y, z in PY:
  print(str(p).zfill(6)+str(z).zfill(6))
Buggy code:
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]

def zeroPadding(num):
    return "%06d"%num

class Row:
    def __init__(self, i, pref_id, year):
        self.i = i
        self.pref_id = pref_id
        self.year = year
        self.city_id = -1
        
    def __str__(self):
        return "{i: %d, pref_id: %d, year: %d, city_id: %d}"%(self.i, self.pref_id, self.year, self.city_id)
        
    def set_city_id(self, city_id):
        self.city_id = city_id
            
    def get_sort_key(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.year ) 
            
    def get_str(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.city_id)

row_list = [Row(i, d[0], d[1]) for i,d in enumerate(P)]
del P
row_list = sorted(row_list, key=lambda x: x.get_sort_key())

now_pref_id = -1
cnt = 1

result = []
for i, row in enumerate(sorted_row_list):
    if row.pref_id != now_pref_id:
        now_pref_id = row.pref_id
        cnt = 1
    
    row.set_city_id(cnt)
    sorted_row_list[i] = row
    cnt += 1

[print(x.get_str()) for x in sorted(sorted_row_list, key=lambda x: x.i)]

Fixed code:
def zeroPadding(num):
    return "%06d"%num

def zeroPadding10(num):
    return "%010d"%num

class Row:
    def __init__(self, i, pref_id, year):
        self.i = i
        self.pref_id = pref_id
        self.year = year
        self.city_id = -1
        
    def __str__(self):
        return "{i: %d, pref_id: %d, year: %d, city_id: %d}"%(self.i, self.pref_id, self.year, self.city_id)
        
    def set_city_id(self, city_id):
        self.city_id = city_id
            
    def get_sort_key(self):
        return zeroPadding(self.pref_id ) + zeroPadding10(self.year) 
            
    def get_str(self):
        return zeroPadding(self.pref_id ) + zeroPadding(self.city_id)

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

row_list = []

for i in range(M):
    d = list(map(int,input().split())) 
    row_list.append(Row(i, d[0], d[1]))

row_list = sorted(row_list, key=lambda x: x.get_sort_key())

now_pref_id = -1
cnt = 1

result = []
for i, row in enumerate(row_list):
    if row.pref_id != now_pref_id:
        now_pref_id = row.pref_id
        cnt = 1
    
    row.set_city_id(cnt)
    row_list[i] = row
    cnt += 1

[print(x.get_str()) for x in sorted(row_list, key=lambda x: x.i)]
Buggy code:
N,M=map(int,input().split())
data=[list(map(int,input().split()+[i])) for i in range(M)]
data=sorted(data,key=lambda x:x[1])
data=sorted(data,key=lambda x:x[0])
preP=None
count=None
printdata=[]
for i in data:
    if preP==i[0]:
        count+=1
    else:
        preP=i[0]
        count=1
    printdata.append(["0"*(6-len(str(preP)))+str(preP)+"0"*(6-len(str(count)))+str(count),i[2]])
printdata=sorted(printdata,key=lambda x:x[1])
for i in printdata:
    print(i)


Fixed code:
N,M=map(int,input().split())
data=[list(map(int,input().split()+[i])) for i in range(M)]
data=sorted(data,key=lambda x:x[1])
data=sorted(data,key=lambda x:x[0])
preP=None
count=None
printdata=[]
for i in data:
    if preP==i[0]:
        count+=1
    else:
        preP=i[0]
        count=1
    printdata.append(["0"*(6-len(str(preP)))+str(preP)+"0"*(6-len(str(count)))+str(count),i[2]])
printdata=sorted(printdata,key=lambda x:x[1])
for i in printdata:
    print(i[0])
Buggy code:
N,M = map(int,input().split())
P=[map(int,input().split()) for _ in range(M)]
d = {}
for p,y in P:
  if p not in d:
    d[p]=[]
  d[p].append(y)
sd = {k:dict(zip(sorted(v),range(1,1+len(v))))
      for k,v in d.items()}
for p,y in P:
  print('%06d%06d' % (p, sd[p][y]))

Fixed code:
N,M = map(int,input().split())
P=[]
for _ in range(M):
  p,y = map(int,input().split())
  P.append((p,y))
d = {}
for p,y in P:
  if p not in d:
    d[p]=[]
  d[p].append(y)
sd = {k:dict(zip(sorted(v),range(1,1+len(v))))
      for k,v in d.items()}
for p,y in P:
  print('%06d%06d' % (p, sd[p][y]))
Buggy code:
N, M = map(int, input().split())
records = []

for i in range(M):
    pi, yi = map(int, input().split())
    records.append([i, pi, yi, "X"])

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

city = 1
city_num = 0

for i in range(M):
    if records[i][1] == city:
        city_num += 1
        records[i][3] = city_num
    else:
        city += records[i][1]
        records[i][3] = 1
        city_num = 1

records.sort()

for record in records:
    ans = "%06d" % record[1] + "%06d" % record[3]
    print(ans)


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

for i in range(M):
    pi, yi = map(int, input().split())
    records.append([i, pi, yi, "X"])

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

# for i in records:
#     print(i)
city = records[0][1]
city_num = 0

for i in range(M):
    if records[i][1] == city:
        city_num += 1
        records[i][3] = city_num
    else:
        city = records[i][1]
        records[i][3] = 1
        city_num = 1
records.sort()
for record in records:
    ans = "%06d" % record[1] + "%06d" % record[3]
    print(ans)
Buggy code:
n,m = input().split()
plist = []
ylist = []
n = int(n)
m = int(m)
anslist = [0 for i in range(m)]
list = [[] for i in range(n+1)]
for i in range(m):
    p,y = input().split()
    p = int(p)
    y = int(y)
    plist.append(p)
    ylist.append(y)
for i in range(m):
    for j in range(n+1):
        if plist[i] == j + 1:
            list[j].append([ylist[i],i])
for i in range(n):
    list[i].sort()
for i in range(n):
    for j in range(len(list[i])):
        mtem = list[i][j][1]
        ans1 = str(plist[mtem])
        while len(ans1) <= 6:
            ans1 = "0" + ans1
        ans2 = str(j+1)
        while len(ans2) <= 6:
            ans2 = "0" + ans2
        anslist[mtem] = ans1 + ans2
for i in range(m):
    print(anslist[i])

Fixed code:
n,m = input().split()
plist = []
ylist = []
n = int(n)
m = int(m)
anslist = [0 for i in range(m)]
list = [[] for i in range(n+1)]
for i in range(m):
    p,y = input().split()
    p = int(p)
    y = int(y)
    plist.append(p)
    ylist.append(y)
    list[p-1].append([ylist[i],i])
for i in range(n):
    list[i].sort()
    for j in range(len(list[i])):
        mtem = list[i][j][1]
        ans1 = str(plist[mtem])
        while len(ans1) < 6:
            ans1 = "0" + ans1
        ans2 = str(j+1)
        while len(ans2) < 6:
            ans2 = "0" + ans2
        anslist[mtem] = ans1 + ans2
for i in range(m):
    print(anslist[i])
Buggy code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
l=[None]*M
for i in range(M):
    P,Y=map(int,input().split())
    l[i]=(P,Y,i)
l.sort()
a=[None]*M
s=0
t=1
for i in l:
    if i[0]==s:
        t+=1
    else:
        t=1
        s=i[0]
    a[i[2]]="{:06d}".format(i[0]) + "{:06d}".format(t)
print(a)

Fixed code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
l=[None]*M
for i in range(M):
    P,Y=map(int,input().split())
    l[i]=(P,Y,i)
l.sort()
a=[None]*M
s=0
t=1
for i in l:
    if i[0]==s:
        t+=1
    else:
        t=1
        s=i[0]
    a[i[2]]="{:06d}".format(i[0]) + "{:06d}".format(t)
print(*a,sep="\n")
Buggy code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7

n,m=MI()
pref=[]
for i in range(m):
    p,y=MI()
    pref+=[(p,i,y)]
pref.sort(key=lambda x:x[0]*10**10+x[2])
c=1
pre=pref[0][0]
ans=[]
for p,i,y in pref:
    pid='0'*(6-len(str(p)))+str(p)
    if pre==p:
        cid='0'*(6-len(str(c)))+str(c)
        c+=1
    else:
        c=1
        cid='0'*(6-len(str(c)))+str(c)
    ans+=[(i,pid+cid)]
    pre=p
ans.sort(key=lambda x:x[1])
for i,iid in ans:
    print(iid)


Fixed code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7

n,m=MI()
pref=[]
for i in range(m):
    p,y=MI()
    pref+=[(p,i,y)]
pref.sort(key=lambda x:x[0]*10**10+x[2])
c=0
pre=pref[0][0]
ans=[]
for p,i,y in pref:
    pid='0'*(6-len(str(p)))+str(p)
    if pre==p:
        c+=1
        cid='0'*(6-len(str(c)))+str(c)
    else:
        c=1
        cid='0'*(6-len(str(c)))+str(c)
    ans+=[(i,pid+cid)]
    pre=p
ans.sort(key=lambda x:x[0])
for i,iid in ans:
    print(iid)
Buggy code:
N, M = map(int, input().split())

counts = defaultdict(int)
numbers = {}

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

sorted_cities = sorted(cities, key=lambda x: x[2])
for city in sorted_cities:
    i, p, y = city
    counts[p] += 1
    numbers[i] = '{:06}{:06}'.format(p, counts[p])

for city in cities:
    print(numbers[city[0]])

Fixed code:
from collections import defaultdict
N, M = map(int, input().split())

counts = defaultdict(int)
numbers = {}

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

sorted_cities = sorted(cities, key=lambda x: x[2])
for city in sorted_cities:
    i, p, y = city
    counts[p] += 1
    numbers[i] = '{:06}{:06}'.format(p, counts[p])

for city in cities:
    print(numbers[city[0]])
Buggy code:
N, M = map(int, input().split())
P = [0] * M
for i in range(M):
    P[i] = list(map(int, input().split())) + [i + 1]

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

a = P[0][0]
c = 0
for i in range(M):
    #print(P[i])
    if P[i][0] == a:
        c += 1
        P[i].append(c)
    else:
        c = 1
        a = P[i][0]
        P[i].append(c)
    print(P[i])

P = sorted(P, key = lambda x: x[2])
for i in range(M):
    s = str(P[i][0]).zfill(6)
    ss = str(P[i][3]).zfill(6)
    print(s + ss)




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

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

a = P[0][0]
c = 0
for i in range(M):
    #print(P[i])
    if P[i][0] == a:
        c += 1
        P[i].append(c)
    else:
        c = 1
        a = P[i][0]
        P[i].append(c)
    #print(P[i])

P = sorted(P, key = lambda x: x[2])
for i in range(M):
    s = str(P[i][0]).zfill(6)
    ss = str(P[i][3]).zfill(6)
    print(s + ss)
Buggy code:
N,M = map(int,input().split())
lis  = [list(input().split()) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis)
flag = lis_sort[0][0]
i = 1
for x in lis_sort:
    if x[0] != flag:
        flag = x[0]
        i=1
        print('if')
    x[1] = '0'*(6-len(str(i)))+str(i)
    i+=1
for x in lis:
    print('0'*(6-len(x[0])),x[0],x[1],sep='')

Fixed code:
N,M = map(int,input().split())
lis  = [list(map(int,input().split())) for _ in range(M)]
ans_lis = [0] * M
lis_sort = sorted(lis,key =lambda x:(x[0],x[1]))
flag = lis_sort[0][0]
i = 1
for x in lis_sort:
    if x[0] != flag:
        flag = x[0]
        i=1
    x[1] = '0'*(6-len(str(i)))+str(i)
    i+=1
for x in lis:
    print('0'*(6-len(str(x[0]))),str(x[0]),x[1],sep='')
Buggy code:
from bisect import bisect_left

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

P = []
Y = []
PY = [[] for _ in range(N+1)]

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

for i in range(M+1):
    PY[i].sort()

for i in range(M):
    x = bisect_left(PY[P[i]], Y[i]) + 1
    print("%06d%06d" % (P[i], x))

Fixed code:
from bisect import bisect_left

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

P = []
Y = []
PY = [[] for _ in range(N+1)]

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

for i in range(N+1):
    PY[i].sort()

for i in range(M):
    x = bisect_left(PY[P[i]], Y[i]) + 1
    print("%06d%06d" % (P[i], x))