inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 107
int x[N], y[N], z[N];
map<pair<int, int>, bool> vis;
intmain(){ int n = rd(); for (int i = 1; i <= n; ++i) { x[i] = rd(); y[i] = rd(); z[i] = rd(); } int X = 0, Y = 0, Z = 0; for (int i = 1; i <= n; ++i) { pii nw = make_pair(y[i], z[i]); if (vis[nw]) continue; vis[nw] = true; ++X; } vis.clear(); for (int i = 1; i <= n; ++i) { pii nw = make_pair(x[i], y[i]); if (vis[nw]) continue; vis[nw] = true; ++Z; } vis.clear(); for (int i = 1; i <= n; ++i) { pii nw = make_pair(x[i], z[i]); if (vis[nw]) continue; vis[nw] = true; ++Y; } if (X >= Y && X >= Z) puts("X"); elseif (Y >= X && Y >= Z) puts("Y"); elseputs("Z"); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
template<typename T> inlineboolgetmax(T &a, T b){return a < b ? (a = b, true) : false;}
#define N 10007 #define mp make_pair #define pb push_back
int a[N], f[2][N][4];
// 1 : - a[y] // 2 : a[x] // 3 : a[x] - a[y]
intmain(){ int n = rd(); for (int i = 1; i <= n; ++i) a[i] = rd(); memset(f, 0xcf, sizeof(f)); f[0][0][3] = 0; for (int i = 1; i <= n; ++i) { int nw = (i & 1); int pre = 1 - nw; for (int j = 1; j <= n; ++j) for (int k = 0; k < 4; ++k) f[nw][j][k] = f[pre][j][k]; for (int j = 1; j <= n; ++j) { getmax(f[nw][j][0], f[pre][j - 1][3]); getmax(f[nw][j][1], max(f[pre][j][0], f[pre][j - 1][3]) - a[i]); getmax(f[nw][j][2], max(f[pre][j][0], f[pre][j - 1][3]) + a[i]); getmax(f[nw][j][3], max({f[pre][j - 1][3], f[pre][j][1] + a[i], f[pre][j][2] - a[i]})); } } for (int j = 1; j <= n; ++j) printf("%d\n", f[n & 1][j][3]); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 100007 #define M 500007
#define all(s) (s).begin(), (s).end()
structedge {int u, v, w;} e[M];
vector<int> vertex, sel;
vector<edge> E, out;
map<pair<int, int>, bool> vis;
int f[N], id[20][2];
intfind(int x){return x == f[x] ? x : f[x] = find(f[x]);}
inlineboolmerge(int u, int v){ u = find(u); v = find(v); return u == v ? false : (f[u] = v, true); }
intmain(){ int n = rd(), m = rd(); for (int i = 1; i <= n; ++i) f[i] = i; for (int i = 1; i <= m; ++i) { int u = rd(), v = rd(), w = rd(); E.push_back(e[i] = {u, v, w}); } sort(all(E), [&](edge &a, edge &b){return a.w < b.w;}); int q = rd(), cnt = n - 1; for (int i = 0; i < q; ++i) for (int j = 0; j <= 1; ++j) { id[i][j] = rd(); cnt -= merge(e[id[i][j]].u, e[id[i][j]].v); }
int add = 0; for (auto ed : E) if (merge(ed.u, ed.v)) {--cnt; add += ed.w; out.push_back(ed);} if (cnt) {puts("-1"); return0;} // not connected
int ans = 1e9; for (int i = 1; i <= n; ++i) f[i] = i; for (auto ed : out) merge(ed.u, ed.v); for (int i = 1; i <= n; ++i) if (f[i] == i) vertex.push_back(i); for (int i = 1; i <= m; ++i) { e[i].u = find(e[i].u); e[i].v = find(e[i].v); } for (auto ed : E) { // reduction int u = find(ed.u), v = find(ed.v); if (u == v || vis[make_pair(u, v)]) continue; vis[make_pair(u, v)] = true; E[cnt++] = {u, v, ed.w}; } E.resize(cnt); for (int i = 0; i < (1 << q); ++i) { int tmp = 0; sel.clear(); for (auto x : vertex) f[x] = x; for (int j = 0; j < q; ++j) sel.push_back(id[j][(i >> j) & 1]); sort(all(sel)); sel.erase(unique(all(sel)), sel.end()); for (auto ID : sel) {tmp += e[ID].w; merge(e[ID].u, e[ID].v);} for (auto ed : E) if (merge(ed.u, ed.v)) tmp += ed.w; ans = min(ans, tmp); } printf("%d\n", ans + add); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define M 10007 #define N 100007 #define mp make_pair
int h[N], p[N], l[N], r[N];
set<int> s;
intmain(){ int n = rd(), q = rd(); for (int i = 1; i <= n; ++i) h[i] = rd(); for (int i = 1; i <= n; ++i) p[i] = rd(); ll ans = 0; auto sqr = [&](int x) {return x * x;}; auto pre = [&](int x) {return x == 1 ? n : x - 1;}; auto work = [&](int x) { x = pre(x); s.clear(); ans = 0; ll nw = 0; for (int i = 1; i < n; ++i) { l[i] = i - 1; r[i] = i + 1; nw += sqr(h[i + 1] - h[i]); } l[n] = n - 1; for (int i = 1; i <= n; ++i) { ans += nw; int id = p[x]; if (l[id]) nw -= sqr(h[id] - h[l[id]]); if (r[id]) nw -= sqr(h[id] - h[r[id]]); if (l[id] && r[id]) nw += sqr(h[l[id]] - h[r[id]]); r[l[id]] = r[id]; l[r[id]] = l[id]; x = pre(x); } }; int st = 1; work(st); printf("%lld\n", ans); for (int i = 1; i <= q; ++i) { int k = (rd() + ans) % n; st = (st + k - 1) % n + 1; work(st); printf("%lld\n", ans); } return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
structP { double x, y, z; P operator + (letp &p) const {return {x + p.x, y + p.y, z + p.z};} P operator - (letp &p) const {return {x - p.x, y - p.y, z - p.z};} booloperator == (letp &p) const {return x == p.x && y == p.y && z == p.z;} P rotx(double ang)const{ double cosa = cos(ang), sina = sin(ang); return {x, y * cosa - z * sina, y * sina + z * cosa}; } P roty(double ang)const{ double cosa = cos(ang), sina = sin(ang); return {x * cosa - z * sina, y, x * sina + z * cosa}; } P rotz(double ang)const{ double cosa = cos(ang), sina = sin(ang); return {x * cosa - y * sina, x * sina + y * cosa, z}; } inlinedoubledis(letp &p){ returnsqrt(sqr(x - p.x) + sqr(y - p.y) + sqr(z - p.z)); } };
inlineboolcheck(vector<P> &s, int n){ for (auto x : s) { int cnt = 0; for (auto y : s) { if (x == y) continue; double d = x.dis(y); if (z(d)) returnfalse; if (z(d - 1.0)) ++cnt; } if (cnt != n) returnfalse; } returntrue; }
inlinevector<P> random_rotate(vector<P> &s){ vector<P> res = s; double ang = 360.0 * rand() / RAND_MAX; for (auto &x : res) x = x.rotx(ang); ang = 360.0 * rand() / RAND_MAX; for (auto &x : res) x = x.roty(ang); ang = 360.0 * rand() / RAND_MAX; for (auto &x : res) x = x.rotz(ang); return res; }
vector<P> ans[11];
intmain(){ ans[1].pb({0, 0, 0}); ans[1].pb({1, 0, 0}); ans[2] = ans[1]; ans[2].pb({0.5, sqrt(3) / 2, 0}); ans[3] = ans[2]; ans[3].pb({0.5, sqrt(3) / 6, sqrt(6) / 3}); ans[4].pb({0, 0, 0}); ans[4].pb({1, 0, 0}); ans[4].pb({0, 1, 0}); ans[4].pb({1, 1, 0}); ans[4].pb({0.5, 0.5, sqrt(2) / 2}); ans[4].pb({0.5, 0.5, -sqrt(2) / 2}); for (int i = 5; i <= 10; ++i) { int x = 1, nw = 100; for (int j = 1; j < i; ++j) if (ans[j].size() * ans[i - j].size() < nw) { nw = ans[j].size() * ans[i - j].size(); x = j; } vector<P> p; while (true) { ans[i].clear(); p = random_rotate(ans[x]); for (auto a : p) for (auto b : ans[i - x]) ans[i].pb(a + b); if (check(ans[i], i)) break; } }
int n = rd(); printf("%d\n", (int)ans[n].size()); for (auto x : ans[n]) printf("%.10lf %.10lf %.10lf\n", x.x, x.y, x.z); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
intmain(){ int n = rd(); for (int i = 1, m = n * n; i <= m; ++i) for (int j = 0; j < 4; ++j) adj[i][j] = rd(); for (int i = 1, m = n * n; i <= m; ++i) if (adj[i][0] == -1 && adj[i][2] == -1) { ans[1][1] = i; q.push(mp(1, 1)); break; } while (!q.empty()) { auto [x, y] = q.front(); q.pop(); int num = ans[x][y]; for (int j = 0; j < 4; ++j) if (adj[num][j] != -1) { int tx = x + dx[j]; int ty = y + dy[j]; if (ans[tx][ty]) continue; ans[tx][ty] = adj[num][j]; q.push(mp(tx, ty)); } } for (int i = 1; i <= n; ++i) { printf("%d", ans[i][1]); for (int j = 2; j <= n; ++j) printf(" %d", ans[i][j]); puts(""); } return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 50007 #define mp make_pair
inlineinttrans(char c){ if (c >= 'a' && c <= 'z') return c - 'a'; if (c == '.') return26; return27; }
int tot = 1;
structnode{bool tag, vis; int fa, tr[28];} c[3000007];
int Ans;
intinsert(int *s, int len){ int nw = 1; for (int i = 1; i <= len; nw = c[nw].tr[s[i++]]) if (!c[nw].tr[s[i]]) c[c[nw].tr[s[i]] = ++tot].fa = nw; return nw; }
voiddel(int nw, int *s, int len){ while (nw != 1) { if (c[nw].tag) {c[nw].tag = false; --Ans;} // 若原本有标记则要撤销 if (!c[nw].vis) { // 若第一次经过该点,则对所有其他儿子打标记 c[nw].vis = true; for (int i = 0; i < 28; ++i) if (c[nw].tr[i] && !c[c[nw].tr[i]].vis) {++Ans; c[c[nw].tr[i]].tag = true;} } --len; nw = c[nw].fa; } }
char S[N];
int s[N][60], pos[N];
int len[N], ans[N];
intmain(){ int n = rd(); for (int i = 1; i <= n; ++i) { scanf("%s", S + 1); len[i] = strlen(S + 1); for (int j = 1; j <= len[i]; ++j) s[i][j] = trans(S[j]); pos[i] = insert(s[i], len[i]); } for (int i = 0; i < 28; ++i) if (c[1].tr[i]) {++Ans; c[c[1].tr[i]].tag = true;} ans[n] = Ans; for (int i = n; i; --i) { del(pos[i], s[i], len[i]); ans[i - 1] = Ans; } for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]); return0; }