#include #include #include #include #include using mint = atcoder::modint998244353; constexpr int L = 300; constexpr int M = 2 * L + 1; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m; std::cin >> n >> m; std::vector a(n), b(n); for (auto&& e : a) std::cin >> e; for (auto&& e : b) std::cin >> e; std::vector binom(M, std::vector(M)); for (int i = 0; i < M; ++i) { binom[i][0] = binom[i][i] = 1; for (int j = 1; j < i; ++j) { binom[i][j] = binom[i - 1][j - 1] + binom[i - 1][j]; } } int zero = 0; std::deque> fs; for (int i = 0; i < m; ++i) { int minx = L, miny = L; std::vector x, y; for (int j = i; j < n; j += m) { x.push_back(a[j]); y.push_back(b[j]); minx = std::min(minx, a[j]); miny = std::min(miny, b[j]); } const int siz = x.size(); std::vector f(minx + miny + 1, 1); for (int j = 0; j < siz; ++j) { const auto &t = binom[x[j] + y[j]]; for (int d = -miny; d <= minx; ++d) { f[miny + d] *= t[y[j] + d]; } } fs.emplace_back(std::move(f)); zero += miny; } while (fs.size() >= 2) { auto f = std::move(fs.front()); fs.pop_front(); auto g = std::move(fs.front()); fs.pop_front(); auto h = atcoder::convolution(std::move(f), std::move(g)); if (h.size() > zero) h.resize(zero + 1); fs.push_back(std::move(h)); } std::cout << fs.front()[zero].val() << std::endl; }