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, T, sum; ll len[N]; char s[2][N];
inlinevoidprework(){ for (int i = 1; i <= 50; ++ i) { len[i] = 1ll << (i - 1); if (len[i] > LIMIT) len[i] = LIMIT + 1; if (LIMIT / sum < len[i]) len[i] = LIMIT + 1; else len[i] = len[i] * sum; } for (int i = 51; i <= 935; ++ i) len[i] = LIMIT + 1;; }
intmain(){ read(n), read(m), read(T); sum = n + m; scanf("%s%s", s[0] + 1, s[1] + 1); prework(); while (T --) { ll x; read(x); int op = 0, now = 935; while (now > 1) { if (x > len[now - 1]) op ^= 1, x -= len[now - 1]; now --; } if (op == 1) {if (x > m) x -= m, op ^= 1;} else {if (x > n) x -= n, op ^= 1;} putchar(s[op][x]); putchar('\n'); } 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; }
map <int, int> Map;
structNode { int l, r, x; inlineNode(){} inlineNode(int l, int r, int x) : l(l), r(r), x(x) { } inlinebooloperator < (const Node &b) const {return x > b.x;} } a[N];
int T, n, m, tal;
inlineintSolve(){ int now = 0, lst = -1; for (auto p : Map) { if (now == 0) { now = p.second; lst = p.first; continue; } a[++ tal] = Node(lst, p.first - 1, now); lst = p.first; now += p.second; } sort(a + 1, a + tal + 1); int ans = 0; for (int i = 1; i <= tal; ++ i) { int len = a[i].r - a[i].l + 1; if (len > m) {ans += m * a[i].x; break;} else {ans += len * a[i].x; m -= len;} } return ans + n; }
signedmain(){ read(T); for (int i = 1; i <= T; ++ i) { read(n); read(m); Map.clear(); tal = 0; for (int i = 1; i <= n; ++ i) { int l, r; read(l); read(r); if (r == l + 1) continue; ++ Map[l + 1]; -- Map[r]; } printf("Case #%lld: %lld\n", i, Solve()); } return0; }
constint N = 810; constint M = 500000; const ll MOD = 1e9 + 7; 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; }
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;}
structEdge { int u, v, w; inlinebooloperator < (const Edge b) const {return w < b.w;} } e[N], ne[M];
structTEdge {int u, v, w, nxt;} te[N];
int n, m, fa[N], siz[N], nowans, c[N][N], ncnt; intecnt(1), head[N], dep[N], f[21][N], mx[21][N];
inlinevoidadd_edge(int u, int v, int w){ te[ecnt].u = u, te[ecnt].v = v, te[ecnt].w = w; te[ecnt].nxt = head[u], head[u] = ecnt ++; }
voiddfs(int x, int fa){ f[0][x] = fa, dep[x] = dep[fa] + 1; for (int i = 1; i <= 20; ++ i) f[i][x] = f[i - 1][f[i - 1][x]]; for (int i = 1; i <= 20; ++ i) mx[i][x] = Max(mx[i - 1][x], mx[i - 1][f[i - 1][x]]); for (int i = head[x]; i; i = te[i].nxt) if (te[i].v != fa) { mx[0][te[i].v] = te[i].w; dfs(te[i].v, x); } }
intget_limit(int u, int v){ int res = -INF; if (dep[u] < dep[v]) swap(u, v); for (int i = 20; ~i; -- i) if (dep[f[i][u]] >= dep[v]) res = Max(res, mx[i][u]), u = f[i][u]; if (u == v) return res; for (int i = 20; ~i; -- i) if (f[i][u] != f[i][v]) { res = Max(res, mx[i][u]), u = f[i][u]; res = Max(res, mx[i][v]), v = f[i][v]; } res = Max(res, Max(mx[0][u], mx[0][v])); return res; }
intmain(){ read(n); m = (n - 1) * n / 2; for (int i = 1; i < n; ++ i) { read(e[i].u), read(e[i].v), read(e[i].w); add_edge(e[i].u, e[i].v, e[i].w); add_edge(e[i].v, e[i].u, e[i].w); c[e[i].u][e[i].v] = e[i].w; c[e[i].v][e[i].u] = e[i].w; } sort(e + 1, e + n); int nowedge = 1; for (int i = 1; i <= n; ++ i) fa[i] = i; for (int i = 1; i <= n; ++ i) siz[i] = 1; ll ans = 1; for (int i = 1; i <= m; ++ i) { if (nowedge < n && e[nowedge].w == i) { connect(e[nowedge].u, e[nowedge].v); ++ nowedge; continue; } (ans *= (nowans - i + 1)) %= MOD; } printf("%lld\n", ans); nowedge = 1; if (!ans) return0; dfs(1, 0); for (int i = 1; i <= n; ++ i) for (int j = 1; j < i; ++ j) if (!c[i][j]) { ne[++ ncnt].u = i, ne[ncnt].v = j; ne[ncnt].w = get_limit(i, j); } sort(ne + 1, ne + ncnt + 1); int necnt = 1; for (int i = 1; i <= m; ++ i) { if (nowedge < n && e[nowedge].w == i) {++ nowedge; continue;} c[ne[necnt].u][ne[necnt].v] = i; c[ne[necnt].v][ne[necnt].u] = i; ++ necnt; } for (int i = 1; i <= n; ++ i) { for (int j = 1; j <= n; ++ j) printf("%d ", c[i][j]); printf("\n"); } return0; }
constint N = 110; constint INF = 0x3fffffff; constint MOD = 998244353;
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; }
char s[N]; int n, m; ll ans, vec[N], dm[N][N], cnt[N][10], w[N], f[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; }
intmain(){ read(n), read(m); for (int i = 1; i <= n; ++ i) { scanf("%s", s + 1); for (int j = 1; j <= m; ++ j) ++ cnt[i][s[j] - '0']; } for (int i = 0; i <= m; ++ i) { dm[i][0] = 1; for (int j = 1; j <= i; ++ j) dm[i][j] = dm[i][j - 1] * (i - j + 1) % MOD; } for (int i = 1; i < (1 << n); ++ i) { int tot = 0; ll sum = 0; for (int j = 0; j < n; ++ j) if (i & (1 << j)) vec[++ tot] = j + 1; f[0] = 1; for (int j = 1; j <= m; ++ j) f[j] = 0; for (int j = 0; j <= 9; ++ j) { for (int l = 0; l <= m; ++ l) { w[l] = fpow(dm[l][l], MOD - 2); for (int k = 1; k <= tot; ++ k) w[l] = w[l] * dm[cnt[vec[k]][j]][l] % MOD; } for (int l = m; l >= 0; -- l) for (int k = l - 1; k >= 0; -- k) (f[l] += f[k] * w[l - k] % MOD) %= MOD; } for (int j = 0; j <= m; ++ j) { ll tmp = f[j] * dm[j][j] % MOD; ll prod = fpow(dm[m][j], MOD - 2); (sum += tmp * fpow(prod, tot) % MOD) %= MOD; } if (tot & 1) (ans += sum) %= MOD; else ans = (ans - sum + MOD) % MOD; } printf("%lld", ans); return0; }