#include using i64 = long long; #include "atcoder/modint" using Fp = atcoder::modint998244353; int main() { int N; std::cin >> N; std::string S; std::cin >> S; std::vector zero_ids; for (int i = 0; i < N; ++i) if (S[i] == '0') zero_ids.push_back(i); std::vector dp(N, std::vector(N, Fp(0))); std::vector is_seen(N, std::vector(N, false)); auto solve = [&](auto &&self, const int l, const int r) -> Fp { if (r - l + 1 < 3) return 0; if (is_seen[l][r]) return dp[l][r]; is_seen[l][r] = true; if (S[l] == '1' or S[r] == '1') return dp[l][r] = 0; if (S[l + 1] == '0' and S[r - 1] == '0') return dp[l][r] = 0; Fp res = 0; for (int nl = l + 1; nl != r; ++nl) { if (S[nl] != '1') for (int nr = r - 1; nr != nl; --nr) { if (S[nr] != '1') res += self(self, nl, nr); if (S[nr] == '0') break; } if (S[nl] == '0') break; } const auto itr = std::lower_bound(zero_ids.begin(), zero_ids.end(), l + 1); if (itr == zero_ids.end() or *itr >= r) ++res; return dp[l][r] = res; }; for (int i = 0; i < N; ++i) for (int j = i; j < N; ++j) solve(solve, i, j); std::vector dp2_a(N + 1, Fp(0)), dp2_b(N + 1, Fp(0)); dp2_a[0] = 1; for (int i = 0; i < N; ++i) { const auto itr = std::lower_bound(zero_ids.begin(), zero_ids.end(), i); for (int j = i + 1; j <= N; ++j) { dp2_a[j] += (dp2_a[i] + dp2_b[i]) * dp[i][j - 1]; if (itr == zero_ids.end() or *itr >= j) dp2_b[j] += dp2_a[i]; } } std::cout << (dp2_a[N] + dp2_b[N]).val() << std::endl; // ?? }