qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from collections import defaultdict
from bisect import bisect_left
N, M = map(int, input().split())
A = []
B = defaultdict(list)
 
for i in range(M):
    p, y = map(int, input().split())
    A.append([p, y])
    B[p].append(y)
 
for key in B.keys():
    B[key].sort()

print(A,B)
for a in A:
    print(a[0],a[1],B[a[0]],bisect_left(B[a[0]],a[1]))
for a in A:
    print("%06d%06d" % (a[0], bisect_left(B[a[0]], a[1])+1))

Fixed code:
from collections import defaultdict
from bisect import bisect_left
N, M = map(int, input().split())
A = []
B = defaultdict(list)
 
for i in range(M):
    p, y = map(int, input().split())
    A.append([p, y])
    B[p].append(y)
 
for key in B.keys():
    B[key].sort()

# print(A,B)
# for a in A:
#     print(a[0],a[1],B[a[0]],bisect_left(B[a[0]],a[1]))
for a in A:
    print("%06d%06d" % (a[0], bisect_left(B[a[0]], a[1])+1))
Buggy code:
import numpy as np
from itertools import accumulate

N, M = map(int, input().split())
P = []
p = [0] * (N+1)
for i in range(M):
    p1, y1 = map(str, input().split())
    p[int(p1)] += 1
    P.append(int(p1+y1.rjust(6,"0")))
    
ans = np.argsort(P)
ans = np.argsort(ans)
p = list(accumulate(p))

for i in range(M):
    a = P[i] // 10 ** 6 
    print(int(str(a).rjust(6,"0") + str(ans[i] - p[a-1] + 1).rjust(6,"0")))

Fixed code:
import numpy as np
from itertools import accumulate

N, M = map(int, input().split())
P = []
p = [0] * (N+1)
for i in range(M):
    p1, y1 = map(str, input().split())
    p[int(p1)] += 1
    P.append(int(p1+y1.rjust(10,"0")))
    
ans = np.argsort(P)
ans = np.argsort(ans)
p = list(accumulate(p))

for i in range(M):
    a = P[i] // 10 ** 10 
    print(str(a).rjust(6,"0") + str(ans[i] - p[a-1] + 1).rjust(6,"0"))
Buggy code:
n, m = map(int, input().split())
a = [0] * (n)
b = [list(map(int, input().split())) + [i] + [0] for i in range(m)]
b.sort(key= lambda x:x[1])
for i, (v, x, y, z) in enumerate(b):
    a[v-1] += 1
    b[i][3] = a[v-1]
b.sort(key = lambda x:x[2])
for v,x,y,z in b:
    print("{0:06d}{0:06d}".format(v,z))

Fixed code:
n, m = map(int, input().split())
a = [0] * (n+1)
b = [list(map(int, input().split())) + [i] + [0] for i in range(m)]
b.sort(key= lambda x:x[1])
for i, (v, x, y, z) in enumerate(b):
    a[v-1] += 1
    b[i][3] = a[v-1]
b.sort(key = lambda x:x[2])
for v,x,y,z in b:
    print("{0:06d}{1:06d}".format(v,z))
Buggy code:
import bisect

def main():
  N,M = map(int,input().split())
  pref = [[] for i in range(N)]
  id = [[]] * M
  
  for i in range(M):
    p,y = map(int,input().split())
    id[i] = [p,y]
    pref[p - 1].append(y)
    #pref[p - 1] = sorted(pref[p - 1])
  
  for i in range(N):
    pref[i] = sorted(pref[i])
  
  orders = [0] * N
  
  for i in range(M):
    p = id[i][0] - 1
    y = id[i][1]
    order = str(bisect.bisect_left(pref[p],y) + 1)
    city = str(p + 1)
    ID = ""
    ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order
    print(ID)

if __init__ == '__main__':
  main()

Fixed code:
import bisect

def main():
  N,M = map(int,input().split())
  pref = [[] for i in range(N)]
  id = [[]] * M
  
  for i in range(M):
    p,y = map(int,input().split())
    id[i] = [p,y]
    pref[p - 1].append(y)
    #pref[p - 1] = sorted(pref[p - 1])
  
  for i in range(N):
    pref[i] = sorted(pref[i])
  
  orders = [0] * N
  
  for i in range(M):
    p = id[i][0] - 1
    y = id[i][1]
    order = str(bisect.bisect_left(pref[p],y) + 1)
    city = str(p + 1)
    ID = ""
    ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order
    print(ID)

if __name__ == '__main__':
  main()
Buggy code:
N,M = map(int,input().split())
pref = [[] for i in range(N)]
id = [[]] * M

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

for i in range(N):
  pref[i] = sorted(pref[i])

orders = [0] * N

for i in range(M):
  p = id[i][0]
  y = id[i][1]
  orders[p - 1] += 1
  order = str(orders[p - 1])
  city = str(p)
  ID = ""
  ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order
  print(ID)

Fixed code:
import bisect

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

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

for i in range(N):
  pref[i] = sorted(pref[i])

orders = [0] * N

for i in range(M):
  p = id[i][0] - 1
  y = id[i][1]
  order = str(bisect.bisect_left(pref[p],y) + 1)
  city = str(p + 1)
  ID = ""
  ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order
  print(ID)
Buggy code:
from collections import defaultdict
import bisect

pre = defaultdict(list)
ori = []
n, m = map(int, input().split())
for _ in range(m):
    x, y = map(int, input().split())
    pre[x].append(y)
    ori.append([x, y])

for key, val in pre.items():
    val.sort()

print(pre)
for i in range(m):
    l = pre[ori[i][0]]
    idx = bisect.bisect(l, ori[i][1])
    print(f'{ori[i][0]:06}{idx:06}')



Fixed code:
from collections import defaultdict
import bisect

pre = defaultdict(list)
ori = []
n, m = map(int, input().split())
for _ in range(m):
    x, y = map(int, input().split())
    pre[x].append(y)
    ori.append([x, y])

for key, val in pre.items():
    val.sort()

for i in range(m):
    l = pre[ori[i][0]]
    idx = bisect.bisect(l, ori[i][1])
    print(f'{ori[i][0]:06}{idx:06}')
Buggy code:
def resolve():
    n,m=map(int,input().split())
    py=[[0]*3 for _ in range(m)]
    for i in range(m):
        p,y=map(int,input().split())
        py[i][0],py[i][1],py[i][2]=p,y,i
    py.sort()
    ans=[[''] for _ in range(m)]
    cnt=[0]*n
    for p,y,i in py:
        cnt[p]+=1
        ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
    for i in ans:
        print(i)


if __name__ == '__main__':
    resolve()

Fixed code:
def resolve():
    n,m=map(int,input().split())
    py=[[0]*3 for _ in range(m)]
    for i in range(m):
        p,y=map(int,input().split())
        py[i][0],py[i][1],py[i][2]=p,y,i
    py.sort()
    ans=[[''] for _ in range(m)]
    cnt=[0]*(n+1)
    for p,y,i in py:
        cnt[p]+=1
        ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
    for i in ans:
        print(i)


if __name__ == '__main__':
    resolve()
Buggy code:
from collections import defaultdict
import bisect
N, M = map(int, input().split())
P = [[int(i) for i in input().split()] for _ in range(M)]
D = defaultdict(list)

for p, y in sorted(P):
  D[p] += [y]
  
for p, y in sorted(P):
  z = D[p].index(y)
  print ("%06d%06d"%(p, z+1))


Fixed code:
from collections import defaultdict
import bisect
N, M = map(int, input().split())
P = [[int(i) for i in input().split()] for _ in range(M)]
D = defaultdict(list)

for p, y in sorted(P):
  D[p] += [y]
  
for p, y in P:
  z = bisect.bisect(D[p], y)
  print ("%06d%06d"%(p, z))
Buggy code:
import itertools
from collections import Counter
N, M = list(map(int,input().split()))
city_list = [list(map(int,input().split())) +[i+1]  for i in range(M)]
city_list_sorted = sorted(city_list,key=lambda x: (x[0],x[1]) )
city_list_grouped = itertools.groupby(city_list_sorted,key=lambda x:x[0])
ans = [None for i in range(M)]
m =0
for k, v in city_list_grouped:
  print(k)
  counter1 = 1
  for x1 in v:
    ans[m] = [x1[2],format(k,'0>6')+format(counter1,'0>6')]
    counter1 += 1 
    m+=1

print(ans)
for x in sorted(ans):
  print(x[1])

Fixed code:
import itertools
from collections import Counter
N, M = list(map(int,input().split()))
city_list = [list(map(int,input().split())) +[i+1]  for i in range(M)]
city_list_sorted = sorted(city_list,key=lambda x: (x[0],x[1]) )
city_list_grouped = itertools.groupby(city_list_sorted,key=lambda x:x[0])
ans = [None for i in range(M)]
m =0
for k, v in city_list_grouped:
  counter1 = 1
  for x1 in v:
    ans[m] = [x1[2],format(k,'0>6')+format(counter1,'0>6')]
    counter1 += 1 
    m+=1

for x in sorted(ans):
  print(x[1])
Buggy code:
n,m = [int(x) for x in input().split()]
py = []
for i in range(m):
    p,y = [int(x) for x in input().split()]
    py.append([p,y,i+1])

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(py[0])+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {x: 0 for x in range(1,m+1)}

    for i in range(m):
        dic[year_py[i][0]] += 1
        year_py[i].append(dic[year_py[i][0]])
    yb_py = sorted(year_py, key=lambda x: x[2])

    #for i in range(m):
    #    print(zero(yb_py[i][0]) + zero(yb_py[i][3]))

Fixed code:
n,m = [int(x) for x in input().split()]
py = []
for i in range(m):
    p,y = [int(x) for x in input().split()]
    py.append([p,y,i+1])

def zero(num):
    return str(num).zfill(6)


if m == 1:
    print(zero(py[0][0])+zero(1))
else:
    year_py = sorted(py, key=lambda x: x[1])
    dic = {str(x): 0 for x in range(1,n+1)}

    for i in range(m):
        dic[str(year_py[i][0])] += 1
        year_py[i].append(dic[str(year_py[i][0])])
    yb_py = sorted(year_py, key=lambda x: x[2])

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

PY_sort = sorted(PY)

tmp = dict()

before = 0
for py in PY_sort:
    if before != py[0]:
        count = 0
    count += 1
    tmp[py] = count

for py in PY:
    print("{:06}{:06}".format(tmp[py][0],tmp[py][1]))

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

PY_sort = sorted(PY)

tmp = dict()

before = 0
for py in PY_sort:
    if before != py[0]:
        before = py[0]
        count = 0
    count += 1
    tmp[py] = count

for py in PY:
    print("{:06}{:06}".format(py[0],tmp[py]))
Buggy code:
import sys
input=sys.stdin.readline

N,M=[int(n) for n in input().split()]
lis=[[i]+[int(n) for n in input().split()] for i in range(M)]
print(lis)
l_2=sorted(lis, key=lambda x: x[2])
dic={}
for k,i,j in l_2:
    dic[i]=dic.get(i,0)+1
    lis[k]='{:0=6}{:0=6}'.format(i,dic[i])
for i in lis:print(i)

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

N,M=[int(n) for n in input().split()]
lis=[[i]+[int(n) for n in input().split()] for i in range(M)]
#print(lis)
l_2=sorted(lis, key=lambda x: x[2])
dic={}
for k,i,j in l_2:
    dic[i]=dic.get(i,0)+1
    lis[k]='{:0=6}{:0=6}'.format(i,dic[i])
for i in lis:print(i)
Buggy code:
 # -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 18:54:20 2018
ABC113C
@author: maezawa
"""

n, m = list(map(int, input().split()))
p = [0]
y = [0]
for i in range(m):
    pi, yi = list(map(int, input().split()))
    p.append(pi)
    y.append(yi)

#print(p)
#print(y)
    
cityn = ['']*m

ps = [[] for _ in range(n+1)]
for i in range(1,m+1):
    ps[p[i]].append(i)
    
for j in range(1,n+1):
    ps[j].sort(key = lambda x: y[x])
    for i, k in enumerate(ps[j]):
        left = '000000'+ str(j)
        right = '000000' + str(i+1)
        cityn[k-1] = left[len(left)-5:] + right[len(right)-5:]

for i in range(m):
    print(cityn[i])
    

Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 18:54:20 2018
ABC113C
@author: maezawa
"""

n, m = list(map(int, input().split()))
p = [0]
y = [0]
for i in range(m):
    pi, yi = list(map(int, input().split()))
    p.append(pi)
    y.append(yi)

#print(p)
#print(y)
    
cityn = ['']*m

ps = [[] for _ in range(n+1)]
for i in range(1,m+1):
    ps[p[i]].append(i)
    
for j in range(1,n+1):
    ps[j].sort(key = lambda x: y[x])
    for i, k in enumerate(ps[j]):
        left = '000000'+ str(j)
        right = '000000' + str(i+1)
        cityn[k-1] = left[len(left)-6:] + right[len(right)-6:]

for i in range(m):
    print(cityn[i])
Buggy code:
import sys

h, w, k = map(int, input().split())
MOD = 1000000007

dp = [[0] * w for _ in range(h + 1)]
dp[0][0] = 1

fn = [1, 1, 2, 3, 5, 8, 13, 21, 34]

if w == 1:
    print(1)
    sys.exit()

for i in range(1, h + 1):
    for j in range(w):
        dp[i][j] = dp[i - 1][j] * fn[w - 1] % MOD
        if j < w - 1:
            dp[i][j] += dp[i - 1][j + 1] * fn[w - 2] % MOD
        if 0 < j:
            dp[i][j] += dp[i - 1][j - 1] * fn[w - 2] % MOD

print(dp[-1][k - 1] % MOD)

Fixed code:
import sys

h, w, k = map(int, input().split())
MOD = 1000000007

dp = [[0] * w for _ in range(h + 1)]
dp[0][0] = 1

fn = [1, 1, 2, 3, 5, 8, 13, 21, 34]

if w == 1:
    print(1)
    sys.exit()

for i in range(1, h + 1):
    for j in range(w):
        dp[i][j] = dp[i - 1][j] * fn[j] * fn[w - j - 1]
        if j < w - 1:
            dp[i][j] += dp[i - 1][j + 1] * fn[j] * fn[w - j - 2]
        if 0 < j:
            dp[i][j] += dp[i - 1][j - 1] * fn[j - 1] * fn[w - j - 1]
        dp[i][j] %= MOD

print(dp[-1][k - 1] % MOD)
Buggy code:
H, W, K = map(int, input().split())

WW = [0]*(W+1)
WW[0] = 1
WW[1] = 1
for i in range(2, W+1):
    WW[i] = WW[i-1] + WW[i-2]
DP = [[0]*W for i in range(H+1)]
DP[0][0] = 1
mod = 10**9+7
for i in range(1, H+1):
    for j in range(W):
        if j == 0:
            DP[i][j] = DP[i-1][j]*WW[W-1] + DP[i-1][j+1]*WW[W-2]
        elif j == W-1:
            DP[i][j] = DP[i-1][j]*WW[W-1] + DP[i-1][j-1]*WW[W-2]
        else:
            DP[i][j] = DP[i-1][j]*WW[j]*WW[W-1-j]+DP[i-1][j-1] * \
                WW[j-1]*WW[W-1-j]+DP[i-1][j+1]*WW[j]*WW[W-2-j]

        DP[i][j] %= mod
# print(DP, WW)
print(DP[-1][K-1])


Fixed code:
H, W, K = map(int, input().split())

WW = [0]*(W+1)
WW[0] = 1
WW[1] = 1
for i in range(2, W+1):
    WW[i] = WW[i-1] + WW[i-2]
DP = [[0]*W for i in range(H+1)]
DP[0][0] = 1
mod = 10**9+7
for i in range(1, H+1):
    for j in range(W):
        if j == 0:
            DP[i][j] = DP[i-1][j]*WW[W-1]
            if W > 1:
                DP[i][j] += DP[i-1][j+1]*WW[W-2]
        elif j == W-1:
            DP[i][j] = DP[i-1][j]*WW[W-1]
            if W > 1:
                DP[i][j] += DP[i-1][j-1]*WW[W-2]
        else:
            DP[i][j] = DP[i-1][j]*WW[j]*WW[W-1-j]+DP[i-1][j-1] * \
                WW[j-1]*WW[W-1-j]+DP[i-1][j+1]*WW[j]*WW[W-2-j]

        DP[i][j] %= mod
# print(DP, WW)
print(DP[-1][K-1])
Buggy code:
#!/usr/bin/env python3

import itertools
mod = 1000000007

h, w, k = list(map(int, input().split()))

dp = [[0]*(w) for _ in range(h+1)]

dp[0][0] = 1

for h_ in range(1, h+1):
    for bridges in itertools.product([0, 1], repeat=w-1):
        flag = 0
        for j in range(len(bridges)-1):
            if bridges[j] == 1 and bridges[j+1] == 1:
                flag = 1
        if flag == 1:
            continue
        # print(bridges)

        for w_ in range(w):
            if w_ > 0:
                if bridges[w_-1] == 1:
                    dp[h_][w_] += dp[h_-1][w_-1] % mod
                    continue
            elif w_ < w-1:
                if bridges[w_] == 1:
                    dp[h_][w_] += dp[h_-1][w_+1] % mod
                    continue
            dp[h_][w_] += dp[h_-1][w_] % mod

# print(dp)
print(dp[-1][k-1] % mod)


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

import itertools
mod = 1000000007

h, w, k = list(map(int, input().split()))

dp = [[0]*(w) for _ in range(h+1)]

dp[0][0] = 1

for h_ in range(1, h+1):
    for bridges in itertools.product([0, 1], repeat=w-1):
        flag = 0
        for j in range(len(bridges)-1):
            if bridges[j] == 1 and bridges[j+1] == 1:
                flag = 1
                continue
        if flag == 1:
            continue
        # print(bridges)
        for w_ in range(w):
            if w_ > 0:
                if bridges[w_-1] == 1:
                    dp[h_][w_] += dp[h_-1][w_-1] % mod
                    continue
            if w_ < w-1:
                if bridges[w_] == 1:
                    dp[h_][w_] += dp[h_-1][w_+1] % mod
                    continue
            dp[h_][w_] += dp[h_-1][w_] % mod

# print(dp)

print(dp[-1][k-1] % mod)
Buggy code:
from itertools import product
H, W, K = map(int, input().split())
MOD = 10 ** 9 + 7

dp = [[0] * W for _ in range(H+1)]
dp[0][0] = 1
for h in range(H):
    for bit in range(1<<(W-1)):
        if "11" in bin(bit): continue
        for w in range(W):
            if (bit>>w)&1 == 0:
                dp[h+1][w] += dp[h][w]
                dp[h+1][w] %= MOD
            else:
                dp[h+1][w+1] += dp[h][w]
                dp[h+1][w+1] %= MOD
            if w > 0 and (bit>>(w-1))&1:
                dp[h+1][w-1] += dp[h][w]
                dp[h+1][w-1] %= MOD

print(dp[-1][K-1] % MOD)


Fixed code:
from itertools import product
H, W, K = map(int, input().split())
MOD = 10 ** 9 + 7

dp = [[0] * W for _ in range(H+1)]
dp[0][0] = 1
for h in range(H):
    for bit in range(1<<(W-1)):
        if "11" in bin(bit): continue
        for w in range(W):
            if w > 0 and (bit>>(w-1))&1:
                dp[h+1][w-1] += dp[h][w]
                dp[h+1][w-1] %= MOD
            elif (bit>>w)&1:
                dp[h+1][w+1] += dp[h][w]
                dp[h+1][w+1] %= MOD
            else:
                dp[h+1][w] += dp[h][w]
                dp[h+1][w] %= MOD

print(dp[-1][K-1] % MOD)
Buggy code:
H,W,K = map(int,input().split())

if W == 1:
  print(1)
  exit()

possible = []
for i in range(1<<(W-1)):
  b = bin(i)[2:]
  flag = 1
  for j in range(len(b)-1):
    if b[j] == b[j+1] == "1":
      flag = 0
  if flag:
    possible.append(int(b,2))

def amida(b):
  ret = [i for i in range(W)]
  for i in range(W-1):
    if b>>i & 1:
      ret[i],ret[i+1] = ret[i+1],ret[i]
  return ret

ans = [0 for i in range(W)]
ans[0] = 1


for _ in range(H):
  new_ans = [0 for i in range(W)]
  for b in possible:
    for i in range(W):
      new_ans[i] = (new_ans[i] + ans[amida(b)[i]])%MOD
  ans = new_ans
  
print(ans[K-1])

Fixed code:
H,W,K = map(int,input().split())
MOD = 10**9+7

if W == 1:
  print(1)
  exit()

possible = []
for i in range(1<<(W-1)):
  b = bin(i)[2:]
  flag = 1
  for j in range(len(b)-1):
    if b[j] == b[j+1] == "1":
      flag = 0
  if flag:
    possible.append(int(b,2))

def amida(b):
  ret = [i for i in range(W)]
  for i in range(W-1):
    if b>>i & 1:
      ret[i],ret[i+1] = ret[i+1],ret[i]
  return ret

ans = [0 for i in range(W)]
ans[0] = 1

for _ in range(H):
  new_ans = [0 for i in range(W)]
  for b in possible:
    for i in range(W):
      new_ans[i] = (new_ans[i] + ans[amida(b)[i]])%MOD
  ans = new_ans
  
print(ans[K-1])
Buggy code:
import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

H,W,K = LI()

dp = [[0] * W for _ in range(H+1)]
dp[0][0] = 1

good = []
for ami in range(2**(W-1)-1):
    b = 1
    m = -2
    for i in range(W-1):
        if b & ami:
            if i <= m + 1:
                break
            m = i
        b <<= 1
    else:
        s = []
        b = 1
        for i in range(W):
            s.append(ami & b > 0)
            b <<= 1
        good.append([0] + s + [0])

for i in range(H):
    for ami in good:
        for j in range(W):
            if ami[j] == 0 and ami[j+1] == 0:
                dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD
            elif ami[j] == 1:
                dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j]) % MOD
            else:
                dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % MOD

print (dp[-1][K-1])

Fixed code:
import sys,queue,math,copy,itertools,bisect,collections,heapq
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

H,W,K = LI()

dp = [[0] * W for _ in range(H+1)]
dp[0][0] = 1

good = []
for ami in range(2**(W-1)):
    b = 1
    m = -2
    for i in range(W-1):
        if b & ami:
            if i <= m + 1:
                break
            m = i
        b <<= 1
    else:
        s = []
        b = 1
        for i in range(W):
            s.append(ami & b > 0)
            b <<= 1
        good.append([0] + s + [0])

for i in range(H):
    for ami in good:
        for j in range(W):
            if ami[j] == 0 and ami[j+1] == 0:
                dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD
            elif ami[j] == 1:
                dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j]) % MOD
            else:
                dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % MOD

print(dp[-1][K-1])
Buggy code:
mod = 10 ** 9 + 7
fib = [1, 1, 2, 3, 5, 8, 13, 21, 34]

H, W, K = map(int, input().split())

dp = [0] * W
dp[0] = 1

for _ in range(H):

    T = [0] * W

    for i in range(W):
        if 0 < i:
            T[i] += T[i - 1] * fib[i - 1] * fib[W - i - 1]

        T[i] += T[i] * fib[i] * fib[W - i - 1]

        if i < W - 1:
            T[i] += dp[i + 1] * fib[i] * fib[W - i - 2]

        T[i] %= mod

    dp = T

print(dp[K - 1])

Fixed code:
mod = 10 ** 9 + 7
fib = [1, 1, 2, 3, 5, 8, 13, 21, 34]

H, W, K = map(int, input().split())

dp = [0] * W
dp[0] = 1

for _ in range(H):

    T = [0] * W

    for i in range(W):
        if 0 < i:
            T[i] += dp[i - 1] * fib[i - 1] * fib[W - i - 1]

        T[i] += dp[i] * fib[i] * fib[W - i - 1]

        if i < W - 1:
            T[i] += dp[i + 1] * fib[i] * fib[W - i - 2]

        T[i] %= mod

    dp = T

print(dp[K - 1])
Buggy code:
h,w,k=map(int,input().split())
ws=[0]*10
ws[0]=1
ws[1]=1
for i in range(2,10):
    ws[i]=ws[i-1]+ws[i-2]
dp=[[0 for i in range(h+1)] for j in range(w)]
dp[0][0]=1
mod=10**9+7
if w==1:
    print(1)
    exit()
for i in range(h):
    for j in range(w):
        if j==0:
            dp[0][i+1]=dp[0][i]*ws[w-1]+dp[1][i]*ws[max(0,w-2)]
            dp[0][i+1]%=mod
        elif j==w-1:
            dp[w-1][i+1]=dp[w-1][i]*ws[w-1]+dp[w-2][i]*ws[max(0,w-2)]
            dp[w-1][i+1]%=mod
        else:
            dp[j][i+1]=dp[j][i]*ws[max(0,j)]*ws[max(0,w-j-1)]+dp[j-1][i]*ws[max(0,j-2)]*ws[max(0,w-j-1)]+dp[j+1][i]*ws[max(0,j-1)]*ws[max(0,w-j-2)]
            dp[j][i+1]%=mod
print(dp[k-1][h])

Fixed code:
h,w,k=map(int,input().split())
ws=[0]*10
ws[0]=1
ws[1]=1
for i in range(2,10):
    ws[i]=ws[i-1]+ws[i-2]
dp=[[0 for i in range(h+1)] for j in range(w)]
dp[0][0]=1
mod=10**9+7
if w==1:
    print(1)
    exit()
for i in range(h):
    for j in range(w):
        if j==0:
            dp[0][i+1]=dp[0][i]*ws[w-1]+dp[1][i]*ws[max(0,w-2)]
            dp[0][i+1]%=mod
        elif j==w-1:
            dp[w-1][i+1]=dp[w-1][i]*ws[w-1]+dp[w-2][i]*ws[max(0,w-2)]
            dp[w-1][i+1]%=mod
        else:
            dp[j][i+1]=dp[j][i]*ws[max(0,j)]*ws[max(0,w-j-1)]+dp[j-1][i]*ws[max(0,j-1)]*ws[max(0,w-j-1)]+dp[j+1][i]*ws[max(0,j)]*ws[max(0,w-j-2)]
            dp[j][i+1]%=mod
print(dp[k-1][h]%mod)