constint N = 300010; const ll MOD = 998244353; constint INF = 0x3fffffff;
template <typename T> inlinevoidread(T &x){ x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; }
int n, T; ll ans, a[N], b[N], ta[N], tb[N], tot; ll sma, smb, sum, posa[N], posb[N], vis[N], vpos[N];
#define lb(t, len, x) lower_bound(t + 1, t + len + 1, x)
intmain(){ read(n); read(T); for (int i = 1; i <= n; ++ i) read(a[i]), (sma += a[i] * a[i] % MOD) %= MOD, ta[i] = a[i]; for (int i = 1; i <= n; ++ i) read(b[i]), (smb += b[i] * b[i] % MOD) %= MOD, tb[i] = b[i]; sort(ta + 1, ta + n + 1); sort(tb + 1, tb + n + 1); for (int i = 1; i <= n; ++ i) (sum += ta[i] * tb[i] % MOD) %= MOD; ans = ((sma + smb) % MOD - 2 * sum % MOD + MOD) % MOD; printf("%lld ", ans); if (!T) return0; for (int i = 1; i <= n; ++ i) posa[i] = lb(ta, n, a[i]) - ta; for (int i = 1; i <= n; ++ i) posb[i] = lb(tb, n, b[i]) - tb; for (int i = 1; i <= n; ++ i) vpos[posb[i]] = i; for (int i = 1; i <= n; ++ i) posa[i] = vpos[posa[i]]; for (int i = 1; i <= n; ++ i) { if (vis[i]) continue; int now = i; ++ tot; while (!vis[now]) {vis[now] = 1, now = posa[now];} } printf("%lld", n - tot); return0; }
template <typename T> inlinevoidread(T &x){ x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; }
template <typename T> inline T Max(T a, T b){return a > b ? a : b;} template <typename T> inline T Min(T a, T b){return a < b ? a : b;}
bool zx[N << 1], fx[N << 1]; ll even[N << 1], odd[N << 1], n, m, ans;
inline ll len(ll x){returnMin(x, 2 * n - x);}
intmain(){ read(n), read(m); ans = n * n; for (int i = 1; i <= m; ++ i) { ll x, y; read(x), read(y); zx[y - x + n] = 1, fx[2 * n - x - y + 1] = 1; } for (int i = 1; i < n << 1; ++ i) if (i & 1) odd[i] = odd[i - 1] + zx[i]; else odd[i] = odd[i - 1]; for (int i = 1; i < n << 1; ++ i) if (!(i & 1)) even[i] = even[i - 1] + zx[i]; else even[i] = even[i - 1]; for (int i = 1; i < n << 1; ++ i) ans -= zx[i] * len(i); for (int i = 1; i < n << 1; ++ i) ans -= fx[i] * len(i); for (int i = 1; i < n << 1; ++ i) { if (!fx[i]) continue; if (n & 1) { if (i & 1) ans += odd[n + len(i) - 1] - odd[n - len(i)]; else ans += even[n + len(i) - 1] - even[n - len(i)]; } else { if (!(i & 1)) ans += odd[n + len(i) - 1] - odd[n - len(i)]; else ans += even[n + len(i) - 1] - even[n - len(i)]; } } printf("%lld", ans); return0; }
constint N = 100010; const ll MOD = 998244353; constint INF = 0x3fffffff;
template <typename T> inlinevoidread(T &x){ x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; }
int n, fa[N], t[N], vis[N], lst[N], inc[N]; ll p[N], q[N], f[N], part1[N], g[N], m[N];
vector <int> trees[N];
inline ll fpow(ll x, ll y){ ll res = 1; while (y) { if (y & 1) (res *= x) %= MOD; y >>= 1, (x *= x) %= MOD; } return res; }
voidsolve(vector <int> &tree){ /*Get the ring on the tree.*/ int now = tree[0]; while (!vis[now]) vis[now] = true, now = t[now]; vector <int> ring(0); int nnow = now; do { ring.push_back(nnow); inc[nnow] = true; nnow = t[nnow]; } while (nnow != now); for (int i = 0; i < ring.size(); ++ i) { int j = (i + 1) % ring.size(); lst[ring[j]] = ring[i]; } /*Use queue to run DP on the tree.*/ for (auto u : tree) vis[u] = false; for (auto u : tree) ++ vis[t[u]]; frt = 0; tal = -1; for (auto u : tree) f[u] = 1; for (auto u : tree) if (!vis[u]) que[++ tal] = u; while (frt <= tal) { int x = que[frt ++]; if (!inc[t[x]] && !(-- vis[t[x]])) que[++ tal] = t[x]; f[x] = f[x] * (MOD + 1 - p[x]) % MOD; f[x] = (MOD + 1 - f[x]) % MOD; (f[t[x]] *= (MOD + 1 - q[x] * f[x] % MOD)) %= MOD; } for (auto u : ring) { f[u] = f[u] * (MOD + 1 - p[u]) % MOD; (f[u] = MOD + 1 - f[u]) %= MOD; } /*Calculate the answers on the ring.*/ ll M = 1; for (auto u : ring) { m[u] = (MOD + 1 - f[u]) * q[lst[u]] % MOD, (M *= m[u]) %= MOD; } now = ring[0]; ll ans0 = 0, tim = 1; do { (ans0 += tim * f[now]) %= MOD; tim = tim * m[now] % MOD; now = lst[now]; } while(now != ring[0]); for (auto u : ring) { g[u] = ans0; ans0 = ans0 * m[t[u]] % MOD; ans0 = ans0 - M * f[t[u]] + f[t[u]]; ans0 = ((ans0 % MOD) + MOD) % MOD; } for (auto u : ring) f[u] = g[u]; }
intmain(){ read(n); for (int i = 1; i <= n; ++ i) fa[i] = i; for (int i = 1, a, b; i <= n; ++ i) { read(a), read(b); p[i] = 1ll * a * fpow(b, MOD - 2) % MOD; } for (int i = 1; i <= n; ++ i) read(t[i]); for (int i = 1, a, b; i <= n; ++ i) { read(a), read(b); q[i] = 1ll * a * fpow(b, MOD - 2) % MOD; } for (int i = 1; i <= n; ++ i) if (find(i) != find(t[i])) fa[fa[i]] = fa[t[i]]; for (int i = 1; i <= n; ++ i) trees[find(i)].push_back(i); for (int i = 1; i <= n; ++ i) if (trees[i].size()) solve(trees[i]); for (int i = 1; i <= n; ++ i) printf("%lld ", f[i]); return0; }
constint N = (1 << 18) + 10; const ll MOD = 1e9 + 7;
template <typename T> inlinevoidread(T &x){ x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; }
int n, m, u, v, e[20], re[20]; ll pw[310], f[N], num[N], lb[N], cnt[N];
intmain(){ read(n); read(m); pw[0] = 1; f[0] = 1; for (int i = 1; i <= m; ++ i) pw[i] = (pw[i - 1] << 1) % MOD; for (int i = 1; i < (1 << n); ++ i) cnt[i] = cnt[i >> 1] + (i & 1); for (int i = 1; i < (1 << n); ++ i) lb[i] = (i & 1 ? 1 : lb[i >> 1] + 1); for (int i = 1; i <= m; ++ i) read(u), read(v), e[u] |= (1 << v - 1), re[v] |= (1 << u - 1); for (int i = 1; i < (1 << n); ++ i) { for (int t = (i - 1 & i), j = i - t; ; t = (t - 1 & i), j = i - t) { num[j] = num[j - (j & -j)] - cnt[re[lb[j]] & j] + cnt[e[lb[j]] & i - j]; (f[i] += ((cnt[j] & 1 ? 1 : MOD - 1) * pw[num[j]]) % MOD * f[i - j]) %= MOD; if (!t) break; } } printf("%d", (pw[m] - f[(1 << n) - 1] + MOD) % MOD); return0; }