#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 = uint32_t; constexpr int K = 4; using state = std::pair, std::array>; auto get_state = [&](key k, int bit) { auto bit_slice = [&](int i) { return (k >> (i * K)) & ((1 << K) - 1); }; state s; auto &[sr, sc] = s; for (int a = 0; a < N; ++a) { sr[a] = (r[a] >> bit) - bit_slice(a); } for (int b = 0; b < N; ++b) { sc[b] = (c[b] >> bit) - bit_slice(N + b); } return s; }; auto get_key = [&](const state& s, int bit) { const auto &[sr, sc] = s; key k = 0; auto add = [&](int v, int i) { assert(0 <= v and v <= 4); k |= v << (i * K); }; for (int a = 0; a < N; ++a) { add((r[a] >> bit) - sr[a], a); } for (int b = 0; b < N; ++b) { add((c[b] >> bit) - sc[b], N + b); } return k; }; std::map pd{}; pd[0] = 1; for (int i = 0; i < L; ++i) { std::map dp{}; for (const auto& [k, v] : pd) { for (int s = 0; s < 1 << ((N - 1) * (N - 1)); ++s) { auto [r, c] = get_state(k, i); 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[get_key({ r, c }, i + 1)] += v; } } } pd.swap(dp); } std::cout << pd[0].val() << std::endl; return 0; }