#include #include #include #include using mint = atcoder::modint998244353; constexpr int L = 30; constexpr int N = 4; int main() { std::array h, w; for (auto&& e : h) std::cin >> e, e -= 4; for (auto&& e : w) std::cin >> e, e -= 4; if (std::accumulate(h.begin(), h.end(), 0LL) != std::accumulate(w.begin(), w.end(), 0LL)) { std::cout << 0 << std::endl; return 0; } constexpr int K = 4; std::array add{}; for (int s = 0; s < 1 << ((N - 1) * (N - 1)); ++s) { for (int a = 0; a < N - 1; ++a) for (int b = 0; b < N - 1; ++b) { int bit = (s >> (a * (N - 1) + b)) & 1; add[s] += bit << a * K; add[s] += bit << b * K << N * K; } } std::unordered_map pd{ { 0, 1 } }; for (int i = 0; i < L; ++i) { uint32_t sub_lo = 0, sub_hi = 0; std::array hb, wb; for (int a = 0; a < N; ++a) { hb[a] = ((h[a] >> i) & 1) << a * K; sub_lo += hb[a]; } for (int b = 0; b < N; ++b) { wb[b] = ((w[b] >> i) & 1) << b * K; sub_hi += wb[b]; } std::unordered_map dp; for (const auto& [k, v] : pd) { for (int s = 0; s < 1 << (N - 1) * (N - 1); ++s) { uint32_t lo = (k + add[s]) & ((1 << N * K) - 1); uint32_t hi = (k + add[s]) >> N * K; for (int a = 0; a < N - 1; ++a) { const int b = N - 1; int bit = ((lo ^ hb[a]) >> a * K) & 1; lo += bit << a * K; hi += bit << b * K; } for (int b = 0; b < N; ++b) { const int a = N - 1; int bit = ((hi ^ wb[b]) >> b * K) & 1; lo += bit << a * K; hi += bit << b * K; } hi -= sub_hi, lo -= sub_lo; dp[((hi << N * K) | lo) >> 1] += v; } } pd.swap(dp); } std::cout << pd[0].val() << std::endl; return 0; }