constint N = 1010; constint M = 4e7; 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; }
bitset <30> p[N];
int n, m, cnt[N], f[M], pos[M];
#define lowbit(x) (-(x)&(x))
intmain(){ read(n), read(m); for (int i = 0; i < n; ++ i) pos[(1 << i)] = i + 1; for (int i = 1; i <= m; ++ i) { int u, v; read(u), read(v); p[u][v] = 1, p[v][u] = 1; } for (int i = 1; i <= n; ++ i) p[i] >>= 1; f[0] = 0; cnt[0] = 1; for (int i = 1; i < (1 << n); ++ i) { int t = i, lt = pos[lowbit(i)]; bitset <30> bt(t); bt &= p[lt]; t -= lowbit(i); f[i] = f[t] + bt.count(); ++ cnt[f[i]]; } for (int i = 0; i <= m; ++ i) printf("%d ", cnt[i]); 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;}
structQuery {int op, r, x, id;} q[N];
int n, m, a[N], mu[N], prm[N], pcnt, nprm[N], sum[N], ans[N];
vector <int> P[N];
voideuler(int x){ mu[1] = 1; for (int i = 2; i <= x; ++ i) { if (!nprm[i]) prm[++ pcnt] = i, mu[i] = -1; for (int j = 1; j <= pcnt; ++ j) { if (prm[j] * i > x) break; nprm[prm[j] * i] = true; if (i % prm[j]) mu[i * prm[j]] = -mu[i]; elsebreak; } } }
inlinevoidget_list(int x){ if (P[x].size()) return; for (int i = 1; i * i <= x; ++ i) if (!(x % i)) { P[x].pbk(i); if (i != x / i) P[x].pbk(x / i); } }
intmain(){ read(n); read(m); euler(N >> 1); for (int i = 1; i <= n; ++ i) read(a[i]); for (int i = 1; i <= m; ++ i) { int l, r, x; read(l), read(r), read(x); q[(i << 1) - 1] = (Query){-1, l - 1, x, i}; q[(i << 1)] = (Query){1, r, x, i}; } sort(q + 1, q + (m << 1) + 1, cmp); for (int i = 1, j = 1; i <= m << 1; ++ i) { for (; j <= n && j <= q[i].r; ++ j) { get_list(a[j]); for (auto k : P[a[j]]) ++ sum[k]; } get_list(q[i].x); for (auto k : P[q[i].x]) ans[q[i].id] += q[i].op * mu[k] * sum[k]; } for (int i = 1; i <= m; ++ i) printf("%d\n", ans[i]); 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; }
int n; char s[N];
bitset <N> mp[N], beat[N], res, lasL[N], lasR[N];
intmain(){ read(n); for (int i = 1; i <= n; ++ i) { scanf("%s", s + 1); for (int j = 1; j <= n; ++ j) beat[i][j] = s[j] ^ 48; } for (int i = 1; i <= n; ++ i) lasL[i][i] = 1, lasR[i][i] = 1; for (int len = 1; len < n; ++ len) for (int l = 1, r = len; r <= n; ++ l, ++ r) { res = lasL[l] & lasR[r]; if (r != n && (beat[r + 1] & res).any()) lasL[l][r + 1] = 1; if (l != 1 && (beat[l - 1] & res).any()) lasR[r][l - 1] = 1; } res = lasL[1] & lasR[n]; for (int i = 1; i <= n; ++ i) if (res[i]) printf("%d ", i); return0; }
#define ll long long #define plli pair <long long, int> #define mp(a, b) make_pair(a, b) #define mset(l, x) memset(l, x, sizeof(l))
constint N = 1000010; constint M = 2000010; const ll INF = 1e17;
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;}
voidmark(int k){ int u = et[k].u, v = et[k].v; ll w = et[k].val; if (!dep[u] || !dep[v]) return; u = find(u), v = find(v); while (u != v) { if (dep[u] < dep[v]) swap(u, v); val[u] = w, fa[u] = fath[u]; u = find(u); } }
voidget_ans(int u){ while (q.size()) q.pop(); mset(vis, 0); mset(f, 0x3f); f[u] = 0; q.push(mp(0, u)); while (q.size()) { int x = q.top().second; q.pop(); if (vis[x]) continue; vis[x] = true; for (int i = head[x]; i; i = e[i].nxt) if (!vis[e[i].v]) if (f[e[i].v] > Max(val[e[i].v], f[x] + e[i].w)) { f[e[i].v] = Max(val[e[i].v], f[x] + e[i].w); q.push(mp(-f[e[i].v], e[i].v)); } } }
signedmain(){ int st; read(n), read(m), read(st); for (int i = 1; i <= m; ++ i) { int u, v; ll w; read(u), read(v), read(w); add_edge(u, v, w), add_edge(v, u, w); } dijkstra(st); mset(vis, 0); get_info(st, 0); for (int i = 2; i < ecnt; i += 2) { if (e[i].tag || e[i ^ 1].tag) continue; et[ect2] = e[i]; et[ect2 ++].val = calc(i); } auto cmp = [](Edge x, Edge y){return x.val < y.val;}; sort(et + 1, et + ect2, cmp); mset(val, 0x3f); for (int i = 1; i <= n; ++ i) fa[i] = i; for (int i = 1; i < ect2; ++ i) mark(i); for (int i = 1; i <= n; ++ i) val[i] -= dis[i]; get_ans(st); for (int i = 1; i <= n; ++ i) printf("%lld ", f[i] > INF / 10 ? -1 : f[i]); return0; }