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 Rust (1.42.0) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use competitive::prelude::*;

type GF = competitive::gf::GF<promote!(998244353)>;

fn main() {
    input! {
        s: Chars,
        k: usize,
    }

    let n = s.len();
    let k = min(k, n + 1);

    let mut v = vec![];

    let mut acc = 0;
    for c in s {
        if c == '0' {
            v.push(acc);
            acc = 0;
        } else {
            acc += 1;
        }
    }

    v.push(acc);

    let ans = solve(v.len() - 1, k, 0, &v);
    echo!(ans);
}

#[memoise(i, k, rest)]
fn solve(i: usize, k: usize, rest: usize, v: &[usize]) -> GF {
    if i == 0 {
        return 1.into();
    }

    let rest = rest + v[i];
    let mut ret = GF::new(0);

    for cur in 0..=rest {
        if cur >= v[i] {
            ret += solve(i - 1, k, rest - cur, v);
        } else {
            if v[i] - cur <= k {
                ret += solve(i - 1, k - (v[i] - cur), rest - cur, v);
            }
        }
    }

    ret
}
*/

fn main() {
    let exe = "/tmp/bin3282607F";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";