Problem:
Score : 800 points

Problem Statement

Given is a string S consisting of 0 and 1. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive):

Choose a pair of integers i, j (1\leq i < j\leq |S|) such that the i-th and j-th characters of S are 0 and 1, respectively. Remove the j-th character from S and insert it to the immediate left of the i-th character.

Constraints

1 \leq |S| \leq 300

0 \leq K \leq 10^9

S consists of 0 and 1.

Input

Input is given from Standard Input in the following format:

S K

Output

Find the number of strings, modulo 998244353, that can result from applying the operation on S between 0 and K times (inclusive).

Sample Input 1

0101 1

Sample Output 1

4

Four strings, 0101, 0110, 1001, and 1010, can result.

Sample Input 2

01100110 2

Sample Output 2

14

Sample Input 3

1101010010101101110111100011011111011000111101110101010010101010101 20

Sample Output 3

113434815

Solution in Fortran (GNU Fortran 9.2.1) (judge verdict: Wrong Answer)

program shift
  implicit none
  integer(8), parameter :: modu = 998244353
  character(300) :: s
  integer :: k, n, a(302) = 0, m = 1, x = 0, h = 0, r, d, w, c, b, i, j
  integer(8) :: dp(0:300, 0:301) = 0
  read(*,*) s, k
  n = len_trim(s)
  do i = 1, n
    if (s(i:i) == '0') then
      m = m + 1
      a(m) = x
    else
      x = x + 1
    end if
  end do
  m = m + 1
  a(m) = x
  k = min(k, x)
  dp(0, 0) = 1
  do i = 1, m - 1
    do j = h, 0, -1
      r = min(k - j, a(i + 1) - a(i))
      do d = 1, r
        w = j + d
        b = a(m) - a(i + 1) + d
        do c = 0, a(m) - a(i + 1)
          b = c + d
          dp(w, c) = dp(w, c) + dp(j, b)
          if (dp(w, c) >= modu) dp(w, c) = dp(w, c) - modu
        end do
      end do
      do c = 1, a(m) - a(i + 1)
        dp(j, c) = dp(j, c) + dp(j, c - 1)
        !if (dp(j, c) >= modu) dp(j, c) = dp(j, c) - modu
      end do
    end do
    h = min(k, h + a(i + 1) - a(i))
  end do
  write(*,'(i0)') mod(sum(dp(0:h, 0)), modu)
end program shift