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)

fn run() {
    proconio::input! {
        mut s: proconio::marker::Chars,
        k: usize,
    }
    for c in "01".chars() {
        while s.last().map_or(false, |p| *p == c) {
            s.pop();
        }
        s.reverse();
    }
    let mut a = vec![];
    for c in s {
        if c == '0' {
            a.push(0);
        } else {
            *a.last_mut().unwrap() += 1;
        }
    }
    let k = std::cmp::min(k, a.iter().sum());
    // [取り出した回数][挿入した回数]
    const MOD: u64 = 998_244_353;
    let mut dp = vec![vec![1u64]];
    for a in a.into_iter().rev() {
        let len = std::cmp::min(k + 1, dp.len() + a);
        let mut next = vec![vec![0; len]; len];
        // 挿入
        for (i, (next, dp)) in next.iter_mut().zip(dp.iter()).enumerate() {
            let mut s = 0;
            for (a, b) in next.iter_mut().zip(dp.iter()).take(i + 1) {
                *a = s + *b;
                s = *a;
            }
        }
        // 取り出す
        for (i, dp) in dp.iter().enumerate() {
            for (j, &v) in dp.iter().enumerate().take(i + 1) {
                for next in next.iter_mut().skip(i + 1).take(a) {
                    next[j] += v;
                }
            }
        }
        dp = next;
        dp.iter_mut().for_each(|dp| dp.iter_mut().for_each(|v| *v %= MOD));
    }
    let ans = dp.into_iter().map(|dp| dp.into_iter().sum::<u64>()).sum::<u64>() % MOD;
    println!("{}", ans);
}

fn main() {
    run();
}