#ifdef NACHIA #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #include #include #include #include #include #include #include #include using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i=0; i--) const i64 INF = 1001001001001001001; const char* yn(bool x){ return x ? "Yes" : "No"; } template void chmin(A& l, const A& r){ if(r < l) l = r; } template void chmax(A& l, const A& r){ if(l < r) l = r; } template using nega_queue = std::priority_queue,std::greater>; template auto ComparingBy(R f){ return [g=std::move(f)](auto l, auto r) -> bool { return g(l) < g(r); }; } #include #include namespace nachia{ template struct MatrixModulo{ private: int h; int w; std::vector elems; public: MatrixModulo(int new_h=0, int new_w=0) : h(new_h), w(new_w), elems(h*w, Elem(0)){} MatrixModulo(const MatrixModulo &) = default; int numRow() const { return h; } int numColumn() const { return w; } int height() const { return numRow(); } int width() const { return numColumn(); } typename std::vector::iterator operator[](int y){ return elems.begin() + (y*w); } typename std::vector::const_iterator operator[](int y) const { return elems.begin() + (y*w); } static MatrixModulo Identity(int n){ auto res = MatrixModulo(n,n); for(int i=0; i operator*(const std::vector& r) const { assert(width() == int(r.size())); auto res = std::vector(h); for(int i=0; i=i; k--) g[j][k] -= g[j][i] * g[i][k]; } return ans; } int rank() const { if(height() == 0 || width() == 0) return 0; MatrixModulo g = *this; int y = 0; for(int d=0; d=d; j--) g[i][j] -= g[i][d] * g[y][j]; y++; } return y; } MatrixModulo pow(unsigned long long i){ auto a = *this; auto res = Identity(height()); while(i){ if(i%2) res = res * a; a = a * a; i /= 2; } return res; } }; } // namespace nachia using Modint = atcoder::static_modint<998244353>; using namespace std; void testcase(){ using Matrix = nachia::MatrixModulo; i64 H, W; cin >> H >> W; auto A = Matrix(H, W); rep(y,H) rep(x,W){ int a; cin >> a; A[y][x] = Modint::raw(a); } auto B = Matrix(H, W); rep(y,H) rep(x,W){ int a; cin >> a; B[y][x] = -Modint::raw(a); } B = B.transposed(); auto mat = Matrix::Identity(H); rep(y,H) rep(x,W) rep(f,H) mat[y][f] -= A[y][x] * B[x][f]; cout << (mat.det() - 1).val() << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); testcase(); return 0; }