#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000005 #define Inf64 1000000000000000001LL mint solve(vector> a){ int n = a.size(),m = a[0].size(); if(m<=16){ vector cur(1< nex(1<=0;k--){ if((j>>k)&1){ if(c && a[i][k+1] != a[i][0]){ c = 2; break; } c = 1; } } if(c<=1)nex[j] = 1; } vector ndp(1<= 0;T = (T-1)&j){ ndp[j] += cur[T]*nex[j^T]; if(T==0)break; } } cur = ndp; } return cur[(1< dp(1< ndp(1<>k)&1){ int nj = j; if(i!=m-1 && a[k][i+1] != a[k][0])nj ^= 1<>n>>m; vector> a(n,vector(m)); rep(i,n){ rep(j,m)cin>>a[i][j]; } mint ans = 0; rep(i,301){ vector> t; rep(j,n){ if(a[j][0]!=i)continue; t.push_back(a[j]); } if(t.size()==0)continue; ans += solve(t); } cout<