#include #include #include #include #include using mint = atcoder::modint998244353; std::istream& operator>>(std::istream& is, mint& v) { int r; is >> r, v = r; return is; } std::ostream& operator<<(std::ostream& os, const mint& v) { return os << v.val(); } template struct matrix { using size_type = std::ptrdiff_t; using value_type = ValueType; private: size_type _height, _width; std::vector> _data; size_type height() const { return this->_height; } size_type width() const { return this->_width; } public: matrix(const size_type n, const size_type m) : _height(n), _width(m), _data(n, std::vector(m)) {} void resize(const size_type n, const size_type m) { this->_height = n, this->_width = m; this->_data.resize(n); for(auto& row : this->_data) row.resize(m); } static matrix identity(const size_type n) { matrix res(n, n); for(const size_type i : std::views::iota(0, n)) res[i][i] = 1; return res; } inline const std::vector& operator[](const size_type p) const { return this->_data[p]; } inline std::vector& operator[](const size_type p) { return this->_data[p]; } matrix& operator+=(const matrix& rhs) { const size_type n = this->height(), m = this->width(); assert(n == rhs.height() && m == rhs.width()); for(size_type i : std::views::iota(0, n)) { for(size_type j : std::views::iota(0, m)) { (*this)[i][j] += rhs[i][j]; } } return *this; } matrix& operator*=(const matrix& rhs) { const size_type n = this->height(), m = rhs._width, l = this->width(); assert(l == rhs._height); matrix product(n, m); for(size_type i : std::views::iota(0, n)) { for(size_type j : std::views::iota(0, m)) { for(size_type k : std::views::iota(0, l)) { product[i][j] += (*this)[i][k] * rhs[k][j]; } } } this->resize(n, m); this->_data = std::move(product._data); return *this; } matrix& transpose() { matrix res(this->width(), this->height()); for(const size_type i : std::views::iota(0, this->height())) { for(const size_type j : std::views::iota(0, this->width())) { res[j][i] = (*this)[i][j]; } } this->resize(res.height(), res.width()); this->_data = std::move(res._data); return *this; } value_type det() const { auto X = this->_data; value_type res = 1; for(const size_type i : std::views::iota(0, this->width())) { size_type pivot = {-1}; for(const size_type j : std::views::iota(i, this->width())) { if(X[j][i] != 0) pivot = j; } if(pivot == -1) return 0; if(i != pivot) { res *= -1; std::swap(X[i], X[pivot]); } res *= X[i][i]; const value_type inv = 1 / X[i][i]; for(const size_type j : std::views::iota(0, this->width())) { X[i][j] *= inv; } for(const size_type j : std::views::iota(i + 1, this->width())) { const value_type v = X[j][i]; for(const size_type k : std::views::iota(0, this->width())) { X[j][k] -= X[i][k] * v; } } } return res; } friend matrix operator+(matrix a, const matrix& b) { return a += b; } friend matrix operator*(matrix a, const matrix& b) { return a *= b; } friend std::istream& operator>>(std::istream& is, matrix& p) { for(auto& row : p._data) { for(auto& v : row) is >> v; } return is; } }; int main() { int n, m; std::cin >> n >> m; matrix A(n, m), B(n, m); std::cin >> A >> B; std::cout << (matrix::identity(m) + A.transpose() * B).det() - 1 << "\n"; return 0; }