#include #include #include #include using mint = atcoder::modint998244353; constexpr int L = 30; constexpr int N = 4; int main() { std::array r, c; for (auto&& e : r) std::cin >> e, e -= 4; for (auto&& e : c) std::cin >> e, e -= 4; using key = std::pair, std::array>; std::array, L + 1> dp{}; dp[0][{ r, c }] = 1; for (int i = 0; i < L; ++i) { for (const auto& [k, v] : dp[i]) { for (int s = 0; s < 1 << ((N - 1) * (N - 1)); ++s) { auto [r, c] = k; std::array, N> d; for (int a = 0; a < N - 1; ++a) { for (int b = 0; b < N - 1; ++b) { int bit = (s >> (a * (N - 1) + b)) & 1; d[a][b] = bit; r[a] -= bit, c[b] -= bit; } } for (int a = 0; a < N - 1; ++a) { const int b = N - 1; int bit = r[a] & 1; d[a][b] = bit; r[a] -= bit, c[b] -= bit; } for (int b = 0; b < N - 1; ++b) { const int a = N - 1; int bit = c[b] & 1; d[a][b] = bit; r[a] -= bit, c[b] -= bit; } { int bit = r[N - 1] & 1; d[N - 1][N - 1] = bit; r[N - 1] -= bit, c[N - 1] -= bit; } bool ok = (c[N - 1] & 1) == 0; for (int a = 0; a < N; ++a) { ok &= r[a] >= 0; r[a] >>= 1; } for (int b = 0; b < N; ++b) { ok &= c[b] >= 0; c[b] >>= 1; } if (ok) { dp[i + 1][{ r, c }] += v; } } } } std::cout << dp[L][key{}].val() << std::endl; return 0; }