Buggy python submission (verdict: Time Limit Exceeded):
S,K=input().split()
K=int(K)
K=min(K,300)
mod=998244353
a=[]
val=0
for i in range(len(S)):
    if S[i]=="0":
        a.append(val)
        val=0
    else:
        val+=1

if val!=0:
    a.append(val)
m=len(a)

dp=[[0 for i in range(K+1)] for j in range(K+1)]

for j in range(K+1):
    dp[j][j]=1

for i in range(m-1,-1,-1):
    ndp=[[0 for x in range(K+1)] for y in range(K+1)]
    for j in range(K,-1,-1):
        for k in range(K,-1,-1):
            M=max(k-j,-a[i])
            for l in range(max(0,M),K-j+1):
                ndp[j][k]+=dp[j+l][k]
                ndp[j][k]%=mod
            for l in range(1,min(K-k,-M)+1):
                ndp[j][k]+=dp[j][k+l]
                ndp[j][k]%=mod
    dp=ndp




print(dp[0][0])


Fixed submission:
S,K=input().split()
K=int(K)
K=min(K,300)
mod=998244353
a=[]
val=0
for i in range(len(S)):
    if S[i]=="0":
        a.append(val)
        val=0
    else:
        val+=1

if val!=0:
    a.append(val)
m=len(a)
K=min(sum(a),K)

dp=[[[0 for i in range(K+1)] for j in range(K+1)] for k in range(m+1)]

for j in range(K+1):
    dp[m][j][j]=1

b=[a[i] for i in range(m)]
c=[a[i] for i in range(m)]
for i in range(1,m):
    b[i]+=b[i-1]
b=[0]+b
for i in range(m-2,-1,-1):
    c[i]+=c[i+1]
for i in range(m-1,-1,-1):
    for j in range(K+1):
        for k in range(min(b[i],K)+1):
            M=max(k-j,-a[i])
            dp[i][j][k]=sum(dp[i+1][j+l][k] for l in range(max(0,M),K-j+1))+sum(dp[i+1][j][k+l] for l in range(1,min(K-k,-M)+1))
            dp[i][j][k]%=mod

print(dp[0][0][0])

Buggy python submission (verdict: Time Limit Exceeded):
S,K=input().split()
K=int(K)
K=min(K,300)
mod=998244353
a=[]
val=0
for i in range(len(S)):
    if S[i]=="0":
        a.append(val)
        val=0
    else:
        val+=1

if val!=0:
    a.append(val)
m=len(a)

dp=[[[0 for i in range(K+1)] for j in range(K+1)] for k in range(m+1)]

for j in range(K+1):
    dp[m][j][j]=1

for i in range(m-1,-1,-1):
    for j in range(K+1):
        for k in range(K+1):
            M=max(k-j,-a[i])
            for l in range(max(0,M),K-j+1):
                dp[i][j][k]+=dp[i+1][j+l][k]
                dp[i][j][k]%=mod
            for l in range(1,min(K-k,-M)+1):
                dp[i][j][k]+=dp[i+1][j][k+l]
                dp[i][j][k]%=mod




print(dp[0][0][0])

Fixed submission:
S,K=input().split()
K=int(K)
K=min(K,300)
mod=998244353
a=[]
val=0
for i in range(len(S)):
    if S[i]=="0":
        a.append(val)
        val=0
    else:
        val+=1

if val!=0:
    a.append(val)
m=len(a)
K=min(sum(a),K)

dp=[[[0 for i in range(K+1)] for j in range(K+1)] for k in range(m+1)]

for j in range(K+1):
    dp[m][j][j]=1

b=[a[i] for i in range(m)]
c=[a[i] for i in range(m)]
for i in range(1,m):
    b[i]+=b[i-1]
b=[0]+b
for i in range(m-2,-1,-1):
    c[i]+=c[i+1]
for i in range(m-1,-1,-1):
    for j in range(K+1):
        for k in range(min(b[i],K)+1):
            M=max(k-j,-a[i])
            dp[i][j][k]=sum(dp[i+1][j+l][k] for l in range(max(0,M),K-j+1))+sum(dp[i+1][j][k+l] for l in range(1,min(K-k,-M)+1))
            dp[i][j][k]%=mod

print(dp[0][0][0])

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    S,K=input().split()
    K=int(K)
    K=min(K,300)
    mod=998244353
    a=[]
    val=0
    for i in range(len(S)):
        if S[i]=="0":
            a.append(val)
            val=0
        else:
            val+=1
    
    if val!=0:
        a.append(val)
    m=len(a)
    
    dp=[[[0 for i in range(K+1)] for j in range(K+1)] for k in range(m+1)]
    
    for j in range(K+1):
        dp[m][j][j]=1
    
    for i in range(m-1,-1,-1):
        for j in range(K+1):
            for k in range(K+1):
                M=max(k-j,-a[i])
                if M>=0:
                    for l in range(max(0,M),K-j+1):
                        dp[i][j][k]+=dp[i+1][j+l][k]
                        dp[i][j][k]%=mod
                else:
                    for l in range(max(0,M),K-j+1):
                        dp[i][j][k]+=dp[i+1][j+l][k]
                        dp[i][j][k]%=mod
                    for l in range(1,min(K-k,-M)+1):
                        dp[i][j][k]+=dp[i+1][j][k+l]
                        dp[i][j][k]%=mod
    
    print(dp[0][0][0])

if __name__=="__main__":
    main()


Fixed submission:
S,K=input().split()
K=int(K)
K=min(K,300)
mod=998244353
a=[]
val=0
for i in range(len(S)):
    if S[i]=="0":
        a.append(val)
        val=0
    else:
        val+=1

if val!=0:
    a.append(val)
m=len(a)
K=min(sum(a),K)

dp=[[[0 for i in range(K+1)] for j in range(K+1)] for k in range(m+1)]

for j in range(K+1):
    dp[m][j][j]=1

b=[a[i] for i in range(m)]
c=[a[i] for i in range(m)]
for i in range(1,m):
    b[i]+=b[i-1]
b=[0]+b
for i in range(m-2,-1,-1):
    c[i]+=c[i+1]
for i in range(m-1,-1,-1):
    for j in range(K+1):
        for k in range(min(b[i],K)+1):
            M=max(k-j,-a[i])
            dp[i][j][k]=sum(dp[i+1][j+l][k] for l in range(max(0,M),K-j+1))+sum(dp[i+1][j][k+l] for l in range(1,min(K-k,-M)+1))
            dp[i][j][k]%=mod

print(dp[0][0][0])

Buggy python submission (verdict: Time Limit Exceeded):
S,K=input().split()
K=int(K)
K=min(K,300)
mod=998244353
a=[]
val=0
for i in range(len(S)):
    if S[i]=="0":
        a.append(val)
        val=0
    else:
        val+=1

if val!=0:
    a.append(val)
m=len(a)

dp=[[[0 for i in range(K+1)] for j in range(K+1)] for k in range(m+1)]

for j in range(K+1):
    dp[m][j][j]=1

for i in range(m-1,-1,-1):
    for j in range(K+1):
        for k in range(K+1):
            M=max(k-j,-a[i])
            if M>=0:
                for l in range(max(0,M),K-j+1):
                    dp[i][j][k]+=dp[i+1][j+l][k]
                    dp[i][j][k]%=mod
            else:
                for l in range(max(0,M),K-j+1):
                    dp[i][j][k]+=dp[i+1][j+l][k]
                    dp[i][j][k]%=mod
                for l in range(1,min(K-k,-M)+1):
                    dp[i][j][k]+=dp[i+1][j][k+l]
                    dp[i][j][k]%=mod

print(dp[0][0][0])


Fixed submission:
S,K=input().split()
K=int(K)
K=min(K,300)
mod=998244353
a=[]
val=0
for i in range(len(S)):
    if S[i]=="0":
        a.append(val)
        val=0
    else:
        val+=1

if val!=0:
    a.append(val)
m=len(a)
K=min(sum(a),K)

dp=[[[0 for i in range(K+1)] for j in range(K+1)] for k in range(m+1)]

for j in range(K+1):
    dp[m][j][j]=1

b=[a[i] for i in range(m)]
c=[a[i] for i in range(m)]
for i in range(1,m):
    b[i]+=b[i-1]
b=[0]+b
for i in range(m-2,-1,-1):
    c[i]+=c[i+1]
for i in range(m-1,-1,-1):
    for j in range(K+1):
        for k in range(min(b[i],K)+1):
            M=max(k-j,-a[i])
            dp[i][j][k]=sum(dp[i+1][j+l][k] for l in range(max(0,M),K-j+1))+sum(dp[i+1][j][k+l] for l in range(1,min(K-k,-M)+1))
            dp[i][j][k]%=mod

print(dp[0][0][0])

Buggy python submission (verdict: Time Limit Exceeded):
S,K=input().split()
K=int(K)
K=min(K,300)
mod=998244353
a=[]
val=0
for i in range(len(S)):
    if S[i]=="0":
        a.append(val)
        val=0
    else:
        val+=1

if val!=0:
    a.append(val)
m=len(a)

dp=[[[0 for i in range(K+1)] for j in range(K+1)] for k in range(m+1)]

for j in range(K+1):
    dp[m][j][j]=1

for i in range(m-1,-1,-1):
    for j in range(K+1):
        for k in range(K+1):
            M=max(k-j,-a[i])
            if M>=0:
                dp[i][j][k]=sum(dp[i+1][j+l][k] for l in range(max(0,M),K-j+1))
            else:
                dp[i][j][k]=sum(dp[i+1][j+l][k] for l in range(max(0,M),K-j+1))+sum(dp[i+1][j][k+l] for l in range(1,min(K-k,-M)+1))
            dp[i][j][k]%=mod

print(dp[0][0][0])


Fixed submission:
S,K=input().split()
K=int(K)
K=min(K,300)
mod=998244353
a=[]
val=0
for i in range(len(S)):
    if S[i]=="0":
        a.append(val)
        val=0
    else:
        val+=1

if val!=0:
    a.append(val)
m=len(a)
K=min(sum(a),K)

dp=[[[0 for i in range(K+1)] for j in range(K+1)] for k in range(m+1)]

for j in range(K+1):
    dp[m][j][j]=1

b=[a[i] for i in range(m)]
c=[a[i] for i in range(m)]
for i in range(1,m):
    b[i]+=b[i-1]
b=[0]+b
for i in range(m-2,-1,-1):
    c[i]+=c[i+1]
for i in range(m-1,-1,-1):
    for j in range(K+1):
        for k in range(min(b[i],K)+1):
            M=max(k-j,-a[i])
            dp[i][j][k]=sum(dp[i+1][j+l][k] for l in range(max(0,M),K-j+1))+sum(dp[i+1][j][k+l] for l in range(1,min(K-k,-M)+1))
            dp[i][j][k]%=mod

print(dp[0][0][0])