#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } // defcomp template vector compress(vector &X) { vector vals = X; sort(vals.begin(), vals.end()); vals.erase(unique(vals.begin(), vals.end()), vals.end()); return vals; } // ----- // importbisect template int bisect_left(vector &X, T v){ return lower_bound(X.begin(), X.end(), v) - X.begin(); } template int bisect_right(vector &X, T v){ return upper_bound(X.begin(), X.end(), v) - X.begin(); } // ----- //defmodfact const int COMinitMAX = 2111244; mint fact[COMinitMAX+1], factinv[COMinitMAX+1]; void modfact(){ fact[0] = 1; for (int i=1; i<=COMinitMAX; i++){ fact[i] = fact[i-1] * i; } factinv[COMinitMAX] = fact[COMinitMAX].inv(); for (int i=COMinitMAX-1; i>=0; i--){ factinv[i] = factinv[i+1] * (i+1); } } mint cmb(int a, int b){ if (a> n >> m >> k; vector x(k); vector y(k); rep(i,0,k){ cin >> x[i] >> y[i]; x[i]--; y[i]--; } vector zz; rep(i,0,k){ zz.push_back(x[i]); zz.push_back(y[i]); } vector z_c = compress(zz); int g = z_c.size(); vector ikeru(g, vector(0)); rep(i,0,k){ ikeru[bisect_left(z_c, y[i])].push_back(bisect_left(z_c, x[i])); } if (g == 0){ mint ans = 0; ans += (n-m) * fact[n-1]; cout << ans.val() << '\n'; return 0; } vector dp1(1 << g); // all vector dp2(1 << g); // first no sub rep(i,0,g){ if ((int)ikeru[i].size() == 0){ dp1[1 << i] += 1; if (z_c[i] >= m){ dp2[1 << i] += 1; } } } rep(i,1,1<> j & 1){ bool mode = 1; for(int k: ikeru[j]){ if ((i >> k & 1) == 0){ mode = 0; } } if (mode){ dp1[i] += dp1[i ^ (1 << j)]; dp2[i] += dp2[i ^ (1 << j)]; } } } } // mint ans = 0; ans += dp2[(1<= m){ cnt--; } } if (n-g-1 >= 0){ ans += dp1[(1<