func_code_string
stringlengths 59
71.4k
|
---|
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0; string x; cin >> n; for (int i = 1; i <= n; i++) { cin >> x; if (x == ABSINTH || x == BEER || x == BRANDY || x == CHAMPAGNE || x == GIN || x == RUM || x == SAKE || x == TEQUILA || x == VODKA || x == WHISKEY || x == WINE || x == 0 || x == 1 || x == 2 || x == 3 || x == 4 || x == 5 || x == 6 || x == 7 || x == 8 || x == 9 || x == 10 || x == 11 || x == 12 || x == 13 || x == 14 || x == 15 || x == 16 || x == 17 ) sum++; } cout << sum << n ; return 0; } |
#include <bits/stdc++.h> using namespace std; struct Root { int p, c; long long e, x; vector<int> v; Root(int p, long long e) : p(p), e(e) {} }; const int MAXN = 200200; bool oncirc[MAXN]; vector<pair<int, long long> > e[MAXN]; vector<Root> circ; long long ans[MAXN]; bool mark[MAXN]; int dfs(int v, int p) { if (mark[v]) { return v; } else { mark[v] = true; } for (vector<pair<int, long long> >::const_iterator it = e[v].begin(); it != e[v].end(); ++it) { int w = it->first; if (w == p) { continue; } int t = dfs(w, v); if (t != -1) { circ.push_back(Root(w, it->second)); return v == t ? -1 : t; } } return -1; } int findcirc(int n) { int m; dfs(0, -1); m = circ.size(); for (int i = 0; i < m; ++i) { oncirc[circ[i].p] = true; } return m; } Root* root; long long dd[MAXN], cc[MAXN], ss[MAXN], xx[MAXN]; void gao1(int v, int p) { root->v.push_back(v); cc[v] = 1; ss[v] = 0; for (vector<pair<int, long long> >::const_iterator it = e[v].begin(); it != e[v].end(); ++it) { int w = it->first; if (w == p || oncirc[w]) { continue; } dd[w] = dd[v] + it->second; gao1(w, v); cc[v] += cc[w]; ss[v] += ss[w] + cc[w] * it->second; } } void gao2(int v, int p, int n) { for (vector<pair<int, long long> >::const_iterator it = e[v].begin(); it != e[v].end(); ++it) { int w = it->first; if (w == p || oncirc[w]) { continue; } xx[w] = xx[v] + (ss[v] - (ss[w] + cc[w] * it->second)) + (n - cc[w]) * it->second; gao2(w, v, n); } } void calctree(Root& r) { root = &r; dd[r.p] = 0; gao1(r.p, -1); xx[r.p] = 0; r.c = cc[r.p]; gao2(r.p, -1, r.c); for (vector<int>::const_iterator it = r.v.begin(); it != r.v.end(); ++it) { ans[*it] = xx[*it] + ss[*it]; } r.x = ans[r.p]; } long long ee[MAXN + MAXN]; void calccirc(int n, int m) { long long circlen = 0; long long total = 0; long long cursum = 0; int curcnt = 0; int q = 0; for (int i = 0; i < m; ++i) { circlen += circ[i].e; total += circ[i].x; ee[i + 1 + m] = ee[i + 1] = circ[i].e; } ee[0] = 0; partial_sum(ee, ee + m + m + 1, ee); while (2 * (ee[q] - ee[0]) <= circlen) { cursum += (ee[q] - ee[0]) * circ[q % m].c; curcnt += circ[q % m].c; ++q; } for (int i = q; i < m; ++i) { cursum += (circlen - (ee[i] - ee[0])) * circ[i % m].c; } for (int i = 0; i < m; ++i) { while (2 * (ee[q] - ee[i]) <= circlen) { cursum -= (circlen - 2 * (ee[q] - ee[i])) * circ[q % m].c; curcnt += circ[q % m].c; ++q; } for (vector<int>::const_iterator it = circ[i].v.begin(); it != circ[i].v.end(); ++it) { ans[*it] += cursum + total - circ[i].x + dd[*it] * (n - circ[i].c); } curcnt -= circ[i].c; cursum += (n - curcnt) * circ[i].e; cursum -= curcnt * circ[i].e; } } int main() { int n, m, a, b, c; scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d%d%d , &a, &b, &c); --a; --b; e[a].push_back(make_pair(b, c)); e[b].push_back(make_pair(a, c)); } m = findcirc(n); for (int i = 0; i < m; ++i) { calctree(circ[i]); } calccirc(n, m); for (int i = 0; i < n; ++i) { printf( %I64d%c , ans[i], i == n - 1 ? n : ); } return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 1000000; bool can[2]; int a[N]; int main() { ios::sync_with_stdio(false); int n, x, y, l; cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) { cin >> a[i]; } set<int> q; for (int i = 0; i < n; i++) { q.insert(a[i]); } for (int i = 0; i < n; i++) { if (q.find(-x + a[i]) != q.end()) can[0] = 1; if (q.find(-y + a[i]) != q.end()) can[1] = 1; } if (!can[0] && !can[1]) { for (int i = 0; i < n; i++) { if (q.find(a[i] - x - y) != q.end()) { cout << 1 n << a[i] - x << n ; return 0; } if (q.find(a[i] + x - y) != q.end()) { if (0 <= a[i] + x && a[i] + x <= l) cout << 1 n << a[i] + x << n ; else if (0 <= a[i] - y && a[i] - y <= l) cout << 1 n << a[i] - y << n ; else continue; return 0; } } } vector<int> ans; if (!can[0]) ans.push_back(x); if (!can[1]) ans.push_back(y); cout << ans.size() << n ; while (ans.size()) { cout << ans.back() << ; ans.pop_back(); } return 0; } |
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; const int maxn = 200000, max0 = 100000, maxabs = 1e9; struct node; node *newnode(); struct node { node *c[2]; int Max; int label; node() : Max(0), label(0) { memset(c, 0, sizeof c); } void update() { Max = 0; for (int i = (0), _end_ = (2); i < _end_; ++i) if (c[i]) chkmax(Max, c[i]->Max); } void flag_label(int _label) { label += _label; Max += _label; } void push_down() { if (label) { for (int i = (0), _end_ = (2); i < _end_; ++i) { if (!c[i]) c[i] = newnode(); c[i]->flag_label(label); } label = 0; } } inline int get_Max() { return this ? Max : 0; } }; node *nd_pool; int nd_res = 0; node *newnode() { if (!nd_res) nd_pool = new node[max0], nd_res = max0; return nd_pool + (--nd_res); } node *rt; int seg_x, seg_y, seg_z; void add(node *&rt, int l, int r) { if (!rt) rt = newnode(); if (seg_x <= l && r <= seg_y) { rt->flag_label(seg_z); return; } int mid = (l + r) >> 1; rt->push_down(); if (seg_x < mid) add(rt->c[0], l, mid); if (seg_y > mid) add(rt->c[1], mid, r); rt->update(); } inline bool seg_add(int first, int second, int z) { if (first >= second) return 0; seg_x = first, seg_y = second, seg_z = z; add(rt, 0, maxabs + 1); return 1; } inline void find(node *rt, int l, int r) { assert(rt); if (r - l <= 1) { seg_y = l; return; } rt->push_down(); int mid = (l + r) >> 1; if (rt->c[0]->get_Max() >= seg_x) find(rt->c[0], l, mid); else find(rt->c[1], mid, r); } int n, d; pair<int, int> a[maxn + 5]; inline bool cmp(const pair<int, int> &first, const pair<int, int> &second) { return first.second < second.second; } inline int find(int first) { if (first > rt->get_Max()) return oo; seg_x = first; seg_y = oo; find(rt, 0, maxabs + 1); return seg_y; } int main() { scanf( %d%d , &n, &d); for (int i = (0), _end_ = (n); i < _end_; ++i) scanf( %d%d , &a[i].first, &a[i].second), ++a[i].second, chkmax(a[i].first, 0), chkmax(a[i].second, 0); int now = 0; sort(a, a + n, cmp); int lst = 0; for (int i = (0), _end_ = (n); i < _end_; ++i) { seg_add(lst, a[i].second, now); int tmp = -1; while ((tmp = find(now + 1) + d) < a[i].second) { ++now; chkmax(tmp, lst); seg_add(tmp, a[i].second, 1); } seg_add(a[i].first, a[i].second, 1); chkmax(lst, a[i].second); } printf( %d n , rt->get_Max()); return 0; } |
#include <bits/stdc++.h> using namespace std; int N, Q; vector<vector<int> > adj; vector<set<int> > grp; vector<int> dep, tin, tout; vector<vector<int> > par; int num = 0; void dfs(int now, int bf) { tin[now] = num++; if (bf != -1) par[now][0] = bf; for (int i = 1; i < 18; i++) { int tmp = par[now][i - 1]; if (tmp == -1) break; par[now][i] = par[tmp][i - 1]; } for (int i = 0; i < adj[now].size(); i++) { int nxt = adj[now][i]; if (nxt == bf) continue; dep[nxt] = dep[now] + 1; dfs(nxt, now); } tout[now] = num - 1; } void preproc() { dep.resize(N); tin.resize(N); tout.resize(N); par = vector<vector<int> >(N, vector<int>(18, -1)); dep[0] = 0; dfs(0, -1); } int lca(int x, int y) { if (dep[x] > dep[y]) swap(x, y); int dx = dep[y] - dep[x]; for (int i = 0; i < 18; i++) { if (dx & (1 << i)) y = par[y][i]; } if (x == y) return x; for (int i = 18; i--;) { if (par[x][i] != par[y][i]) { x = par[x][i]; y = par[y][i]; } } return par[x][0]; } int K; vector<int> V; vector<vector<int> > adj2; map<int, int> imp; bool cmp(int a, int b) { return tin[a] < tin[b]; } vector<int> dp, rem; void dfs2(int now, int bf) { int cnt = 0; for (int i = 0; i < adj2[now].size(); i++) { int nxt = adj2[now][i]; if (nxt == bf) continue; dfs2(nxt, now); dp[now] += dp[nxt]; if (rem[nxt] > 0) cnt++; } if (imp[V[now]]) { dp[now] += cnt; rem[now] = 1; } else { if (cnt > 1) { dp[now]++; rem[now] = 0; } else rem[now] = cnt; } } void get_dp() { dp.clear(); rem.clear(); dp = rem = vector<int>(V.size(), 0); dfs2(0, -1); } void solve() { sort(V.begin(), V.end(), cmp); for (int i = 0; i < K - 1; i++) { int x = lca(V[i], V[i + 1]); V.push_back(x); } sort(V.begin(), V.end(), cmp); V.resize(unique(V.begin(), V.end()) - V.begin()); stack<int> st; adj2.clear(); adj2.resize(V.size()); for (int i = V.size(); i--;) { while (!st.empty() && tin[V[st.top()]] <= tout[V[i]]) { adj2[i].push_back(st.top()); adj2[st.top()].push_back(i); st.pop(); } st.push(i); } bool ok = true; for (int i = 0; i < V.size(); i++) { for (int j = 0; j < adj2[i].size(); j++) { int k = adj2[i][j]; int u = V[i], v = V[k]; if (!imp[u] || !imp[v]) continue; if (grp[u].find(v) != grp[u].end()) { ok = false; break; } } } if (!ok) { printf( -1 n ); return; } get_dp(); printf( %d n , dp[0]); } int main() { scanf( %d , &N); adj.resize(N); grp.resize(N); for (int i = 0; i < N - 1; i++) { int u, v; scanf( %d %d , &u, &v); u--; v--; adj[u].push_back(v); adj[v].push_back(u); grp[u].insert(v); grp[v].insert(u); } preproc(); scanf( %d , &Q); for (int i = 0; i < Q; i++) { scanf( %d , &K); V.clear(); V.resize(K); imp.clear(); for (int j = 0; j < K; j++) { scanf( %d , &V[j]); V[j]--; imp[V[j]] = 1; } solve(); } } |
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n >> a; if (a & 1) cout << (a / 2 + 1); else { a = n - a; cout << a / 2 + 1; } return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int x, t, a, b, at, bt; cin >> x >> t >> a >> b >> at >> bt; int btek = b; set<int> my; my.insert(0); int ttek1 = t; while (btek > 0 && ttek1 > 0) { my.insert(btek); int atek = a; int ttek2 = t; while (atek > 0 && ttek2 > 0) { my.insert(atek); my.insert(atek + btek); ttek2--; atek -= at; } ttek1--; btek -= bt; } if (my.find(x) != my.end()) cout << YES ; else cout << NO ; } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; int n, i, ct = 0; cin >> n >> s; s = + s; for (i = 1; i <= n - 10; i++) { if (s[i] == 8 ) ct++; } if (ct > (n - 11) / 2) cout << YES n ; else cout << NO n ; return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 100005; struct Query { int idx, k; }; int n, m; int c[N], ans[N], cnt[N], pref[N]; vector<Query> qs[N]; vector<int> adj[N]; void read() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> c[i]; for (int i = 1; i <= n - 1; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 1; i <= m; i++) { int v, k; cin >> v >> k; qs[v].push_back({i, k}); } } int idx = 0; int fs[N], ed[N], euler[N], sz[N]; void findSz(int u, int p) { sz[u] = 1; fs[u] = ++idx; euler[idx] = u; for (auto& v : adj[u]) { if (v != p) { findSz(v, u); sz[u] += sz[v]; } } ed[u] = idx; } void dfs(int u, int p, bool keep) { int mx = -1, bigChild = -1; for (auto& v : adj[u]) { if (v != p && mx < sz[v]) mx = sz[v], bigChild = v; } for (auto& v : adj[u]) { if (v != p && v != bigChild) dfs(v, u, 0); } if (bigChild != -1) dfs(bigChild, u, 1); for (auto& v : adj[u]) { if (v != p && v != bigChild) { for (int i = fs[v]; i <= ed[v]; i++) { pref[cnt[c[euler[i]]]]--; cnt[c[euler[i]]]++; } } } pref[cnt[c[u]]]--; cnt[c[u]]++; for (auto& q : qs[u]) ans[q.idx] = N - pref[q.k - 1]; if (!keep) { for (int i = fs[u]; i <= ed[u]; i++) { cnt[c[euler[i]]]--; pref[cnt[c[euler[i]]]]++; } } } void solve() { findSz(1, 0); memset(cnt, 0, sizeof cnt); for (int i = 0; i < N; i++) pref[i] = N; dfs(1, 0, 1); for (int i = 1; i <= m; i++) cout << ans[i] << n ; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); read(); solve(); return 0; } |
#include<bits/stdc++.h> using namespace std; #define N 2005 int read(){ int w=0,f=1; char c= ; while(c< 0 ||c> 9 )f=(c== - ?-f:f),c=getchar(); while(c>= 0 &&c<= 9 )w=w*10+c- 0 ,c=getchar(); return w*f; } int T,n,ans[N],cnt; bool vis[N]; bool check(int x){ printf( ? %d %d n ,x,1); for(int i=1;i<=x;i++) printf( %d%c ,i,i==x? n : ); printf( %d n ,ans[2]); fflush(stdout); return read()?1:0; } signed main(){ T=read(); while(T--){ n=read(),cnt=2; for(int i=1;i<=n;i++) vis[i]=0; bool fl=0; for(int i=2;i<=n&&!fl;i++){ printf( ? %d %d n ,i-1,1); for(int j=1;j<i;j++) printf( %d%c ,j,j==i-1? n : ); printf( %d n ,i); fflush(stdout); if(read())ans[2]=i,fl=1; } int l=1,r=ans[2]-2; ans[1]=ans[2]-1; while(l<=r){ int mid=(l+r)>>1; if(check(mid))ans[1]=mid,r=mid-1; else l=mid+1; } for(int i=ans[2]+1;i<=n;i++){ printf( ? 1 1 n%d n%d n ,ans[2],i); fflush(stdout); if(read())ans[++cnt]=i; } for(int i=1;i<=cnt;i++) vis[ans[i]]=1; printf( ! %d ,n-cnt); for(int i=1;i<=n;i++) if(!vis[i])printf( %d%c ,i,i==n-cnt? n : ); fflush(stdout); } return 0; } |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = (int)1e9 + 7; const int N = (int)3e5 + 7; int n, p, k, a[N]; map<int, int> cnt; inline int add(int a, int b) { return (a += b) >= p ? a - p : a; } inline int mul(int a, int b) { return 1ll * a * b % p; } void Init() { cnt.clear(); for (int i = (1); i < (n + 1); ++i) scanf( %d , a + i); } int Solve() { long long ans = 0; for (int i = (1); i < (n + 1); ++i) { int tmp = mul(mul(a[i], a[i]), mul(a[i], a[i])); tmp = add(tmp, p - mul(k, a[i])); ans += cnt[tmp]; cnt[tmp]++; } return printf( %lld n , ans); } int main() { while (~scanf( %d%d%d , &n, &p, &k)) { Init(); Solve(); } return 0; } |
#include <bits/stdc++.h> using namespace std; int on[10001]; int main() { std::ios::sync_with_stdio(false); cin.tie(0); int n, t, r, ans = 0; cin >> n >> t >> r; for (int i = 0; i < n; ++i) { int w; cin >> w; w += 400; int cnt = 0; for (int j = w; j > w - t; --j) { if (on[j]) { ++cnt; } } int todo = max(r - cnt, 0); for (int j = w; j > w - t; --j) { if (!on[j] and todo > 0) { on[j] = 1; todo -= 1; ++ans; } } if (todo > 0) { cout << -1; return 0; } } cout << ans; } |
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 0, i, l; cin >> n; for (i = 1; i <= n; i++) { cin >> l; if (l == 1) { cnt += 1; } } if (cnt > 0) { cout << HARD ; } else { cout << EASY ; } } |
#include <bits/stdc++.h> using namespace std; int n, L, R; int a, b; int lo = -1, hi = 1e9 + 1; const int MAXN = 111111; const int INF = 1e9; vector<pair<int, int> > adj[MAXN]; int sz[MAXN], chk[MAXN]; int q[MAXN], f[MAXN], g[MAXN], d[MAXN], h[MAXN]; void dfs(int u, int p) { sz[u] = 1; for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i].first; if (v != p) { dfs(v, u); sz[u] += sz[v]; } } } int get_center(int u) { int s = sz[u]; while (1) { int r = 0; for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i].first; if (chk[v]) continue; if (sz[v] > sz[r]) r = v; } if (sz[r] <= s / 2) return u; sz[u] = s - sz[r], u = r; } } bool cmp(pair<int, int> a, pair<int, int> b) { return sz[a.first] < sz[b.first]; } void go(int u, int p, int mid, int s) { f[u] = s, d[u] = d[p] + 1; if (d[u] > R) return; if (f[h[d[u]]] < s) h[d[u]] = u; for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i].first; if (v == p || chk[v]) continue; go(v, u, mid, s + (adj[u][i].second >= mid ? 1 : -1)); } } bool check(int u, int mid, int &x, int &y) { f[u] = d[u] = 0, f[0] = -INF, g[0] = u; for (int j = 1; j <= R && j <= sz[u]; j++) g[j] = 0; for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i].first; if (chk[v]) continue; for (int j = 1; j <= R && j <= sz[v]; j++) h[j] = 0; go(v, u, mid, (adj[u][i].second >= mid ? 1 : -1)); int head = 0, tail = 0; for (int j = 1, k = min(sz[v], R - 1); j <= min(R, sz[v]); j++) { if (h[j] == 0) break; for (; k >= max(0, L - j); k--) { if (g[k] == 0) continue; while (head < tail && f[g[q[tail - 1]]] <= f[g[k]]) tail--; q[tail++] = k; } while (head < tail && q[head] > R - j) head++; if (head < tail && f[g[q[head]]] + f[h[j]] >= 0) { x = g[q[head]], y = h[j]; return 1; } } for (int j = 1; j <= min(R, sz[v]); j++) if (f[g[j]] < f[h[j]]) g[j] = h[j]; } return 0; } void process(int u) { sort((adj[u]).begin(), (adj[u]).end(), cmp); hi = 1e9 + 1; int x = 0, y = 0; while (hi - lo > 1) { int mid = lo + hi >> 1; if (check(u, mid, x, y)) a = x, b = y, lo = mid; else hi = mid; } } void solve(int u) { u = get_center(u); process(u), chk[u] = 1; for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i].first; if (!chk[v]) solve(v); } } int main() { cin >> n >> L >> R; for (int i = 1; i < n; i++) { int u, v, w; scanf( %d%d%d , &u, &v, &w); adj[u].push_back(make_pair(v, w)); adj[v].push_back(make_pair(u, w)); } dfs(1, 0); solve(1); printf( %d %d n , a, b); return 0; } |
#include <bits/stdc++.h> const int N = 200020; int _, n, m, x, y, flag, a[N], c[N], d[N]; std::queue<int> q; std::pair<int, int> b[N]; std::vector<int> g[N], ans; void f(int u) { if (++a[u] > g[u].size() && !c[u]) q.push(u), c[u] = 1; } int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , a + i); for (int i = 1; i <= m; i++) { scanf( %d%d , &x, &y); b[i] = {x, y}; g[x].push_back(i); g[y].push_back(i); } for (int i = 1; i <= n; i++) f(i); for (; q.size(); q.pop()) for (int u : g[q.front()]) if (!d[u]) ans.push_back(u), f(b[u].first), f(b[u].second), d[u] = 1; if (ans.size() == m) { puts( ALIVE ); reverse(ans.begin(), ans.end()); for (int j : ans) printf( %d , j); } else puts( DEAD ); } |
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long add(long long a, long long b) { return (a + b) % MOD; } long long sub(long long a, long long b) { return ((a - b) % MOD + MOD) % MOD; } long long mul(long long a, long long b) { return (a * b) % MOD; } long long a[800000], tim[200]; set<long long> se; long long n, m; bool check(long long x, long long s) { long long mid = x; long long p = -1, sum = 0; for (int i = 100; i >= 1; i--) { if (tim[i] <= x) x -= tim[i]; else if (tim[i] > x && p == -1) { p = tim[i] - x; x = -1; sum += p * i; } else if (p != -1) { sum += i * tim[i]; } } if (m - sum >= a[s]) return true; return false; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { long long l = 0, r = i + 1, mid, ans = LLONG_MAX; while (l <= r) { mid = (l + r) >> 1; if (check(mid, i)) { r = mid - 1; ans = min(ans, mid); } else l = mid + 1; } cout << ans << ; tim[a[i]]++; } } |
#include <bits/stdc++.h> using namespace std; long long int base = 639941; char str[1505], bad[30]; set<long long int> s; int main() { int k, n, i, j; scanf( %s , str); scanf( %s , bad); scanf( %d , &k); n = strlen(str); int ans = 0; for (i = 0; i < n; i++) { int b = 0; long long int h = 0; long long int pw = 1LL; for (j = i; j < n; j++) { b += ( 1 - bad[str[j] - a ]); if (b > k) break; pw *= base; h += (pw * str[j]); s.insert(h); } } printf( %d n , s.size()); return 0; } |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:128000000 ) using namespace std; const int INF = 1000000000; typedef struct zap { int p; zap *left, *right, *rod; }; char s[100]; zap *top = 0, *temp = 0; int dfs(zap *t) { if (t->p == 0) { printf( int ); return 0; } printf( pair< ); dfs(t->left); printf( , ); dfs(t->right); printf( > ); return 0; } int main() { int k, i, v, j, x, y, to, n, r, p, l, fl, m; scanf( %i , &n); fl = 0; while (scanf( %s , &s) != EOF) { if (fl) { printf( Error occurred n ); return 0; } if (!top) { top = new zap; top->left = top->rod = top->right = 0; if (s[0] == p ) top->p = 1; else top->p = 0; temp = top; if (top->p == 0) fl = 1; continue; } zap *newe = new zap; if (s[0] == p ) newe->p = 1; else newe->p = 0; newe->left = newe->right = newe->rod = 0; newe->rod = top; if (!top->left) { top->left = newe; top = newe; } else if (!top->right) { top->right = newe; top = newe; } while (top->p == 0 || (top->left && top->right)) { if (top == temp) { fl = 1; break; } top = top->rod; } } if (top != temp || (top->p && (!top->left || !top->right))) { printf( Error occurred n ); return 0; } dfs(top); return 0; } |
#include <bits/stdc++.h> using namespace std; int q, w, e, W; int a[500000], k, b, c, d, n, m, ip1, ip2, a1, b1, c1, d1, m1[500000], m2[500000], m3[500000], m4[500000]; string old[2000], nov[2000], s1, s2; int main() { cin >> q; for (int i = 1; i <= q; i++) { cin >> s1 >> s2; int ok = 0; for (int j = 1; j <= k; j++) if (nov[j] == s1) { nov[j] = s2; ok = 1; break; } if (ok == 0) old[++k] = s1, nov[k] = s2; } cout << k << endl; for (int j = 1; j <= k; j++) cout << old[j] << << nov[j] << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 300010; int dia, n; long long a[N], ans; map<long long, int> mp; int main() { cin >> dia >> n; ans = (long long)n * (n - 1LL) * (n - 2LL) / 6LL; for (int i = 1, s, f; i <= n; ++i) { cin >> s >> f; if (!s) f += dia; f %= 2 * dia; a[i] = f; } sort(a + 1, a + n + 1); for (int i = n + 1; i <= 2 * n; ++i) { a[i] = a[i - n] + 2 * dia; mp[a[i]]++; mp[a[i - n]]++; } for (int i = 1, ni = 1; i <= n; ++i) { for (; a[ni + 1] - a[i] < dia; ++ni) ; ans -= (long long)(ni - i) * (ni - i - 1LL) / 2LL; } if (ans) { cout << ans << n ; return 0; } long long l = 0; for (int i = 1, ni; i <= n; ++i) { for (; a[ni + 1] - a[i] < dia; ++ni) ; if (ni - i > 1) l = max(l, a[ni] - a[i]); } for (int i = 1, ni = 1; i <= n; ++i) { ni = max(ni, i); mp[a[i]]--; for (; a[ni + 1] - a[i] < l; ++ni) ; if (a[ni + 1] - a[i] == l) { if (ni + 1 - i > 1) ans += (long long)(ni - i) * mp[a[ni + 1]]; ans += (long long)mp[a[ni + 1]] * (mp[a[ni + 1]] - 1) / 2LL; } } cout << ans << n ; } |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t) { i >> v; } return i; } template <typename T, typename U> std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) { o << p.first << << p.second; return o; } template <typename T> std::ostream& operator<<(std::ostream& o, const vector<T>& t) { if (t.empty()) o << n ; for (size_t i = 0; i < t.size(); ++i) { o << t[i] << n [i == t.size() - 1]; } return o; } template <typename T> using minheap = priority_queue<T, vector<T>, greater<T>>; template <typename T> using maxheap = priority_queue<T, vector<T>, less<T>>; template <typename T> bool in(T a, T b, T c) { return a <= b && b < c; } unsigned int logceil(int first) { return first ? 8 * sizeof(int) - __builtin_clz(first) : 0; } namespace std { template <typename T, typename U> struct hash<pair<T, U>> { hash<T> t; hash<U> u; size_t operator()(const pair<T, U>& p) const { return t(p.first) ^ (u(p.second) << 7); } }; } // namespace std template <typename T, typename F> T bsh(T l, T h, const F& f) { T r = -1, m; while (l <= h) { m = (l + h) / 2; if (f(m)) { l = m + 1; r = m; } else { h = m - 1; } } return r; } template <typename F> double bshd(double l, double h, const F& f, double p = 1e-9) { unsigned int r = 3 + (unsigned int)log2((h - l) / p); while (r--) { double m = (l + h) / 2; if (f(m)) { l = m; } else { h = m; } } return (l + h) / 2; } template <typename T, typename F> T bsl(T l, T h, const F& f) { T r = -1, m; while (l <= h) { m = (l + h) / 2; if (f(m)) { h = m - 1; r = m; } else { l = m + 1; } } return r; } template <typename F> double bsld(double l, double h, const F& f, double p = 1e-9) { unsigned int r = 3 + (unsigned int)log2((h - l) / p); while (r--) { double m = (l + h) / 2; if (f(m)) { h = m; } else { l = m; } } return (l + h) / 2; } template <typename T> T gcd(T a, T b) { if (a < b) swap(a, b); return b ? gcd(b, a % b) : a; } template <typename T> class vector2 : public vector<vector<T>> { public: vector2() {} vector2(size_t a, size_t b, T t = T()) : vector<vector<T>>(a, vector<T>(b, t)) {} }; template <typename T> class vector3 : public vector<vector2<T>> { public: vector3() {} vector3(size_t a, size_t b, size_t c, T t = T()) : vector<vector2<T>>(a, vector2<T>(b, c, t)) {} }; template <typename T> class vector4 : public vector<vector3<T>> { public: vector4() {} vector4(size_t a, size_t b, size_t c, size_t d, T t = T()) : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {} }; template <typename T> class vector5 : public vector<vector4<T>> { public: vector5() {} vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T()) : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {} }; class TaskD { public: void solve(istream& cin, ostream& cout) { long long N, L, R, K; cin >> N >> L >> R >> K; long long Q = (N + R - L + 1) % N; if (Q == 0) Q = N; if (K < Q) { cout << -1 n ; return; } long long ans = -1; if (K <= 2 * Q) { cout << min(N, K - Q + 1 + (N - Q)) << endl; return; } for (long long rev = 1; rev <= 1000000; ++rev) { for (long long take : { (K - Q + N) / (rev + 1), (K - Q + N) / (rev + 1), (K - Q + N) / (rev + 1), (2 * N + K - 2 * Q + 1) / (rev + 1), (2 * N + K - 2 * Q + 1) / (rev + 1), (2 * N + K - 2 * Q + 1) / (rev + 1), }) { long long s = take - N; if (s < 0) continue; if (s > N) continue; long long left = (K - Q) - rev * take; if (left < 0) continue; if (left > Q) continue; if (left > s) continue; if (min(Q, left + 1) + (N - Q) < s) continue; ans = max(ans, s); } } for (long long take = 1; take <= 1000000; ++take) { if (take < N) continue; if (take > 2 * N) continue; long long s = take - N; for (long long rev = (K - 2 * Q) / take - 1; rev <= (K - Q) / take + 1; ++rev) { if (rev <= 0) continue; long long left = (K - Q) - rev * take; if (left < 0) continue; if (left > Q) continue; if (left > s) continue; if (min(Q, left + 1) + (N - Q) < s) continue; ans = max(ans, s); } } cout << ans << endl; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); TaskD solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; } |
#include <bits/stdc++.h> using namespace std; map<string, string> m; map<string, int> used; string f(string x) { used[x] = 1; if (m[x] == x) return x; return f(m[x]); } int main() { int count = 0; vector<string> tab; int n; cin >> n; for (int i = 0; i < n; i++) { string p1, p2; cin >> p1 >> p2; if (m[p1].empty()) { ++count; tab.push_back(p1); } used[p1] = 0; used[p2] = 0; m[p1] = p2; m[p2] = p2; } cout << count << endl; for (int i = 0; i < count; ++i) { if (used[tab[i]] == 1) continue; cout << tab[i] << << f(tab[i]) << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 2002; int n, a[N][N], c[N], p[N], t, A; string s[N]; bool C() { for (int i = 1; i <= n; i++) p[i] = c[i]; sort(p + 1, p + n + 1), t = 0; for (int i = 1; i < n; i++) { t += p[i]; if (t == i * (i - 1) / 2) return false; } return true; } void S(int x) { for (int i = 1; i <= n; i++) c[x] -= a[x][i], c[i] -= a[i][x], swap(a[x][i], a[i][x]), c[x] += a[x][i], c[i] += a[i][x]; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> s[i]; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) a[i][j] = s[i][j - 1] - 0 , c[i] += a[i][j]; for (int i = 1; i <= n; i++) S(i), A += C(), S(i); if (C()) cout << 0 << << 1; else if (A) cout << 1 << << A; else if (n == 6) cout << 2 << << 18; else cout << -1; return 0; } |
#include <bits/stdc++.h> using namespace std; const int maxn = 2010; int n, m, k; long long sum[maxn][maxn]; char s[maxn][maxn]; long long calc(int x, int y) { if (x <= 0 || y <= 0) return 0; long long ans = 0; int a = x % n, b = y % m; ans = (1ll * x * y - 1ll * a * b) / 2; if ((__builtin_popcount(x / n) ^ __builtin_popcount(y / m)) % 2 == 0) ans += sum[a][b]; else ans += 1ll * a * b - sum[a][b]; return ans; } int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { int now = s[i][j] - 0 ; sum[i][j] = now; sum[i][j + m] = now ^ 1; sum[i + n][j] = now ^ 1; sum[i + n][j + m] = now; } n <<= 1; m <<= 1; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]; while (k--) { int x1, y1, x2, y2; scanf( %d%d%d%d , &x1, &y1, &x2, &y2); printf( %lld n , calc(x2, y2) - calc(x2, y1 - 1) - calc(x1 - 1, y2) + calc(x1 - 1, y1 - 1)); } return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { long long a[100005]; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { printf( %I64d , a[i] + a[i + 1]); } } |
#include <bits/stdc++.h> using namespace std; string s; int k; int main() { cin >> s; for (int i = 0; i < s.length(); i++) if (s[i] == 1 ) k++; if (k > 1) cout << (s.length() + 1) / 2 << endl; else cout << s.length() / 2 << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; long long read() { long long a = 0, b = getchar(), c = 1; while (!isdigit(b)) c = b == - ? -1 : 1, b = getchar(); while (isdigit(b)) a = a * 10 + b - 0 , b = getchar(); return a * c; } void print(long long x) { if (x < 0) putchar( - ), x = -x; int y = x % 10 + 0 ; if (x >= 10) print(x / 10); putchar(y); } int n, x, y, a[100005]; int main() { n = read(), x = read(), y = read(); for (int i = 0; i < n; i++) a[i] = read(); for (int i = 0; i < n; i++) { bool z = true; for (int j = max(0, i - x); j < i; j++) if (a[j] <= a[i]) z = false; for (int j = min(n - 1, i + y); j > i; j--) if (a[j] <= a[i]) z = false; if (z) return print(i + 1), 0; } return 0; } |
#include <bits/stdc++.h> using namespace std; struct Vec { double x, y; Vec(double newX = 0, double newY = 0) { x = newX; y = newY; } Vec operator+(Vec r) { return Vec(x + r.x, y + r.y); } Vec operator-(Vec r) { return Vec(x - r.x, y - r.y); } Vec operator*(double r) { return Vec(x * r, y * r); } Vec operator/(double r) { return Vec(x / r, y / r); } double operator*(Vec r) { return x * r.x + y * r.y; } Vec normal() { return Vec(y, -x); } double len() { return sqrt(x * x + y * y); } }; double cprod(Vec l, Vec r) { return l.x * r.y - l.y * r.x; } Vec intersection(Vec first1, Vec first2, Vec second1, Vec second2) { Vec n1 = (first2 - first1).normal(); Vec n2 = (second2 - second1).normal(); double c1 = first1 * n1; double c2 = second1 * n2; double x = c1 * n2.y - c2 * n1.y; double y = c2 * n1.x - c1 * n2.x; double div = n1.x * n2.y - n1.y * n2.x; return Vec(x, y) / div; } double getArea(vector<Vec> pts) { double result = 0; for (size_t i = 0; i < pts.size(); i++) result += cprod(pts[i], pts[(i + 1) % pts.size()] - pts[i]) / 2; return abs(result); } int n, r; double pi = acos(-1); Vec getPt(int ind) { ind = (ind % n + n) % n; return Vec(r * sin(2 * pi * ind / n), r * cos(2 * pi * ind / n)); } int main() { double area = 0; cin >> n >> r; { vector<Vec> pts = { getPt(0), getPt(n / 2), intersection(getPt(n / 2), getPt(-1), getPt(n / 2 + 1), getPt(1)), getPt(n / 2 + 1)}; area += getArea(pts); } int segments = 2, cursize = (n - 3) / 2; while (cursize > 0) { Vec mid; if (cursize + 1 != n / 2) mid = intersection(getPt(0), getPt(n / 2), getPt(cursize + 1), getPt(cursize + 1 - n / 2)); else mid = getPt(0) + (getPt(n / 2) - getPt(0)) / 2; if (cursize % 2) { Vec top = getPt((cursize + 1) / 2); Vec lopp = getPt((cursize + 1) / 2 - n / 2); Vec ropp = getPt((cursize + 1) / 2 + n / 2); vector<Vec> pts = {top, intersection(top, lopp, getPt(0), getPt(n / 2)), mid, intersection(top, ropp, getPt(cursize + 1), getPt(cursize + 1 - n / 2))}; area += segments * getArea(pts); cursize = (cursize - 1) / 2; } else { Vec top1 = getPt((cursize + 1) / 2); Vec top2 = getPt((cursize + 1) / 2 + 1); Vec bot1 = getPt((cursize + 1) / 2 + n / 2); Vec bot2 = getPt((cursize + 1) / 2 - n / 2); Vec bot3 = getPt((cursize + 1) / 2 + 1 - n / 2); vector<Vec> pts = { top1, intersection(top1, bot2, getPt(0), getPt(n / 2)), mid, intersection(top2, bot2, getPt(cursize + 1), getPt(cursize + 1 - n / 2)), top2, intersection(top1, bot1, top2, bot3)}; area += segments * getArea(pts); cursize = (cursize - 2) / 2; } segments *= 2; } cout << fixed << setprecision(8) << area << n ; return 0; } |
#include <bits/stdc++.h> using namespace std; const int Maxn = 1 << 30; int n, m, str[100100], lim[100100], up[100100], D[100100], col[100100 * 4]; long long ans; vector<int> F[100100 * 4]; vector<long long> sum2[100100 * 4], sum[100100 * 4]; bool cmp(int x, int y) { return D[x] > D[y]; } void build(int node, int l, int r) { col[node] = -2; if (l == r) { F[node].push_back(l); sum[node].push_back(up[l]); sum2[node].push_back(lim[l]); return; } int mid = (l + r) >> 1, son = node << 1; build(son, l, mid); build(son | 1, mid + 1, r); F[node].resize(r - l + 1); sum[node].resize(r - l + 1); sum2[node].resize(r - l + 1); merge(F[son].begin(), F[son].end(), F[son | 1].begin(), F[son | 1].end(), F[node].begin(), cmp); sum[node][0] = up[F[node][0]], sum2[node][0] = lim[F[node][0]]; for (int i = 1, size = F[node].size(); i < size; i++) { sum[node][i] = sum[node][i - 1] + up[F[node][i]]; sum2[node][i] = sum2[node][i - 1] + lim[F[node][i]]; } } void update(int node) { if (col[node] > 0) col[node << 1] = col[(node << 1) | 1] = col[node]; } void getans(int node, int l, int r, int ll, int rr, int t) { if (l > rr || ll > r) return; if (ll <= l && rr >= r && (col[node] > 0 || col[node] == -2)) { if (col[node] > 0) { int dif = t - col[node]; int l = -1, r = F[node].size() - 1; while (l < r) { int mid = (l + r + 1) >> 1; if (D[F[node][mid]] >= dif) l = mid; else r = mid - 1; } if (l >= 0) ans += sum[node][l] * dif - sum2[node][l]; ans += sum2[node][F[node].size() - 1]; } else { for (int i = 0, size = F[node].size(); i < size; i++) ans += min((long long)lim[F[node][i]], (long long)t * up[F[node][i]] + str[F[node][i]]); } col[node] = t; return; } update(node); int mid = (l + r) >> 1, son = node << 1; getans(son, l, mid, ll, rr, t); getans(son | 1, mid + 1, r, ll, rr, t); if (col[son] == col[son | 1]) col[node] = col[son]; else col[node] = -1; } int main() { cin >> n; for (int i = 1; i <= n; i++) scanf( %d %d %d , &str[i], &lim[i], &up[i]), D[i] = up[i] == 0 ? Maxn : lim[i] / up[i]; build(1, 1, n); int t, l, r; cin >> m; for (int i = 1; i <= m; i++) { scanf( %d %d %d , &t, &l, &r); ans = 0; getans(1, 1, n, l, r, t); printf( %lld n , ans); } } |
#include <bits/stdc++.h> int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int la, ra, ta, lb, rb, tb; scanf( %d%d%d , &la, &ra, &ta), ++ra; scanf( %d%d%d , &lb, &rb, &tb), ++rb; int g = gcd(ta, tb); ra -= la / g * g, la %= g; rb -= lb / g * g, lb %= g; if (lb > la) lb -= g, rb -= g; int ans = 0; ans = std::max(ans, std::min(ra, rb) - std::max(la, lb)); lb += g, rb += g; ans = std::max(ans, std::min(ra, rb) - std::max(la, lb)); printf( %d n , ans); return 0; } |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1E4 + 10; bool st[MAXN]; int n, k, l, f[1 << 20], dis[25][25], id[MAXN], d[MAXN], tot; vector<int> g[MAXN]; queue<int> q; inline void add(int u, int v) { g[u].push_back(v); g[v].push_back(u); } void bfs(int s) { memset(d, 0x3f, sizeof d); d[s] = 0; q.push(s); while (!q.empty()) { int x = q.front(); q.pop(); for (int v : g[x]) if (d[v] == 0x3f3f3f3f) { d[v] = d[x] + 1; q.push(v); } } for (int i = 1; i <= n; i++) if (id[i]) dis[id[i]][id[s]] = min(dis[id[i]][id[s]], d[i]); } int main() { scanf( %d%d%d , &n, &k, &l); for (int i = 1, x; i <= k; i++) { scanf( %d , &x); st[x - 1] ^= 1; st[x] ^= 1; } for (int i = 0; i <= n; i++) if (st[i]) id[i] = ++tot; for (int i = 1, x; i <= l; i++) { scanf( %d , &x); for (int j = 1; j <= n - x + 1; j++) add(j - 1, j + x - 1); } memset(dis, 0x3f, sizeof dis); for (int i = 0; i <= n; i++) if (id[i]) bfs(i); memset(f, 0x3f, sizeof f); f[0] = 0; for (int s = 1; s < (1 << tot); s++) for (int i = 0; i < tot; i++) if ((s >> i) & 1) for (int j = 0; j < tot; j++) if ((s >> j) & 1) f[s] = min(f[s], f[s ^ (1 << i) ^ (1 << j)] + dis[i + 1][j + 1]); if (f[(1 << tot) - 1] == 0x3f3f3f3f) puts( -1 ); else printf( %d n , f[(1 << tot) - 1]); } |
#include <bits/stdc++.h> using namespace std; const int Maxn = 3e5 + 5; const int inf = 1 << 29; inline int min(int a, int b) { return a < b ? a : b; } inline int max(int a, int b) { return a > b ? a : b; } inline int R() { char ch = getchar(); int x = 0; bool f = 0; for (; !isdigit(ch); ch = getchar()) if (ch == - ) f = 1; for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48); if (f == 1) x = -x; return x; } int a[Maxn], n, t, L[Maxn], N[Maxn], ans[Maxn]; bool vis[Maxn]; int main() { t = R(); while (t--) { n = R(); for (int i = 0; i <= n + 1; i++) { ans[i] = inf; N[i] = vis[i] = 0; } for (int i = 1; i <= n; i++) { a[i] = R(); L[a[i]] = 0; } for (int i = 1; i <= n; i++) { if (!L[a[i]]) L[a[i]] = i; else { N[L[a[i]]] = i; L[a[i]] = i; } } for (int i = 1; i <= n; i++) if (N[i] == 0) N[i] = n + 1; for (int i = 1; i <= n; i++) if (!vis[i]) { int M = i; for (int p = i; N[p] != 0; p = N[p]) { vis[p] = 1; M = max(M, N[p] - p); } ans[M] = min(ans[M], a[i]); } ans[0] = inf; for (int i = 1; i <= n; i++) ans[i] = min(ans[i], ans[i - 1]); for (int i = 1; i <= n; i++) { if (ans[i] == inf) ans[i] = -1; printf( %d , ans[i]); } puts( ); } } |
#include <bits/stdc++.h> using namespace std; void work(long long ang) { for (long long n = 3;; n++) { if (ang * n % 180 == 0) { if (ang * n / 180 <= n - 2) { printf( %I64d n , n); return; } } if (n == 998244353) break; } } int main() { int T; int n; scanf( %d , &T); for (; T--;) { scanf( %d , &n); work(n); } return 0; } |
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; string s; int n, ans; int T, A[1010], B[1010], cnt, head[2010], nxt[100010], dis[100010], id; bool w[100010]; void link(int a, int b, int c) { nxt[++id] = head[a], head[a] = id, dis[id] = b, w[id] = c; nxt[++id] = head[b], head[b] = id, dis[id] = a, w[id] = c; } int power[2010]; bool vis[2010], col[2010]; bool dfs(int x) { for (int i = head[x]; i; i = nxt[i]) { if (!vis[dis[i]]) { vis[dis[i]] = 1; col[dis[i]] = col[x] ^ w[i]; if (dfs(dis[i])) return 1; } else if (col[dis[i]] ^ col[x] ^ w[i]) return 1; } return 0; } int main() { cin >> s; n = s.size(); s = + s; power[0] = 1; for (int i = 1; i <= 2000; ++i) power[i] = power[i - 1] * 2 % MOD; for (int S = 2; S <= n; ++S) { memset(head, 0, sizeof(head)); id = cnt = 0; T = cnt++; for (int i = S; i <= n; ++i) A[i] = cnt++; for (int i = 1; i <= n; ++i) B[i] = cnt++; link(B[1], T, 1); link(A[S], T, 1); for (int i = S; i <= n; ++i) { if (s[i] == 0 ) link(A[i], B[i], 0); else if (s[i] == 1 ) link(A[i], B[i], 1); } for (int i = 1; i < S; ++i) { if (s[i] == 0 ) link(B[i], T, 0); else if (s[i] == 1 ) link(B[i], T, 1); } for (int i = S, j = n; i < j; ++i, --j) link(A[i], A[j], 0); for (int i = 1, j = n; i < j; ++i, --j) link(B[i], B[j], 0); memset(vis, 0, sizeof(vis)); int C = 0; for (int i = 0; i < cnt; ++i) if (!vis[i]) { ++C; if (dfs(i)) { C = -1; break; } } if (~C) ans = (ans + power[C - 1]) % MOD; } printf( %d n , ans); return 0; } |
#include <bits/stdc++.h> using namespace std; const long long N = 4e6 + 5; long long n, a[N], b[N], sum[N], I, lim = 1, mx = -1, Ans; long long read() { long long x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 1) + (x << 3) + c - 0 ; c = getchar(); } return f * x; } long long qpow(long long x, long long y) { long long ret = 1; while (y) { if (y & 1) ret = ret * x; y >>= 1; x = x * x; } return ret; } long long LG2(long long x) { long long ret = log2(x); if (qpow(2, ret) >= x) return ret; else return ret + 1; } int main() { memset(sum, 0, sizeof(sum)); memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); n = read(), I = read(); for (register long long i = (1); i <= (n); i++) a[i] = read(); sort(a + 1, a + n + 1); a[0] = -1; for (register long long i = (1); i <= (n); i++) { if (a[i] != a[i - 1]) b[++b[0]] = 1; else b[b[0]]++; } for (register long long i = (2); i <= (b[0]); i++) { if (LG2(i) * n <= 8 * I) lim = i; else break; } if (lim >= b[0]) printf( 0 n ); else { for (register long long i = (1); i <= (b[0]); i++) sum[i] = sum[i - 1] + b[i]; for (register long long i = (lim); i <= (b[0]); i++) mx = max(mx, sum[i] - sum[i - lim]); Ans = sum[b[0]] - mx; printf( %lld n , Ans); } return 0; } |
#include <bits/stdc++.h> using namespace std; long long read() { long long w = 0, f = 1; char c = ; while (c < 0 || c > 9 ) c = getchar(), f = c == - ? -1 : f; while (c >= 0 && c <= 9 ) w = w * 10 + c - 48, c = getchar(); return w * f; } long long read14() { char c = getchar(); while (c != U && c != D && c != L && c != R ) c = getchar(); if (c == U ) return 1; if (c == D ) return 2; if (c == L ) return 3; return 4; } long long n, m, p[200005], dl[200005], dr[200005]; vector<long long> a[200005], e[200005]; long long pos(long long x, long long y) { if (x >= 1 && x <= n && y >= 1 && y <= m) return (x - 1) * m + y; return n * m + 1 + ((x + y) & 1); } long long minn[200005 << 2], tag[200005 << 2], val[200005 << 2]; void build(long long p, long long l, long long r) { if (l == r) { val[p] = 1; return; } long long mid = (l + r) >> 1; build(p << 1, l, mid); build(p << 1 | 1, mid + 1, r); val[p] = val[p << 1] + val[p << 1 | 1]; } void down(long long p, long long l, long long r) { if (!tag[p]) return; minn[p << 1] += tag[p]; minn[p << 1 | 1] += tag[p]; tag[p << 1] += tag[p]; tag[p << 1 | 1] += tag[p]; tag[p] = 0; } void update(long long p, long long x, long long y, long long v, long long l, long long r) { if (x <= l && y >= r) { minn[p] += v, tag[p] += v; return; } down(p, l, r); long long mid = (l + r) >> 1; if (x <= mid) update(p << 1, x, y, v, l, mid); if (y > mid) update(p << 1 | 1, x, y, v, mid + 1, r); if (minn[p << 1] == minn[p << 1 | 1]) val[p] = val[p << 1] + val[p << 1 | 1]; else if (minn[p << 1] < minn[p << 1 | 1]) val[p] = val[p << 1]; else val[p] = val[p << 1 | 1]; minn[p] = min(minn[p << 1], minn[p << 1 | 1]); } long long now, ans; void dfs1(long long u) { dl[u] = ++now; for (auto v : e[u]) dfs1(v); dr[u] = now; } void dfs2(long long u, long long rt) { if (u != rt) update(1, dl[p[u]], dr[p[u]], 1, 1, now), ans -= val[1] - 1; for (auto v : e[u]) dfs2(v, rt); if (u != rt) update(1, dl[p[u]], dr[p[u]], -1, 1, now); } signed main() { n = read(), m = read(), ans = n * n * m * m / 4; for (long long i = 1; i <= n; i++) { a[i].push_back(0); for (long long j = 1; j <= m; j++) { a[i].push_back(read14()); if (a[i][j] == 1) e[pos(i + 2, j)].push_back(pos(i, j)), p[pos(i, j)] = pos(i + 1, j); if (a[i][j] == 2) e[pos(i - 2, j)].push_back(pos(i, j)), p[pos(i, j)] = pos(i - 1, j); if (a[i][j] == 3) e[pos(i, j + 2)].push_back(pos(i, j)), p[pos(i, j)] = pos(i, j + 1); if (a[i][j] == 4) e[pos(i, j - 2)].push_back(pos(i, j)), p[pos(i, j)] = pos(i, j - 1); } } dfs1(n * m + 1); build(1, 1, now); dfs2(n * m + 2, n * m + 2); printf( %lld , ans); return 0; } |
#include <bits/stdc++.h> using namespace std; int n, apple[200000], a, b; long long tot = 0; vector<int> adj[200000]; int GCD(long long x, long long y) { if (y == 0) return x; return GCD(y, x % y); } pair<long long, long long> DFS(int ant, int act) { if (adj[act].size() == 1) return make_pair(apple[act], 1); vector<pair<long long, long long> > V; for (int i = 0; i < adj[act].size(); i++) { if (adj[act][i] == ant) continue; V.push_back(DFS(act, adj[act][i])); } long long mn = V[0].first; for (int i = 0; i < V.size(); i++) mn = min(mn, V[i].first); long long mcm = V[0].second; for (int i = 1; i < V.size(); i++) { if (mcm > mn) break; mcm = (mcm * V[i].second) / GCD(mcm, V[i].second); } return make_pair(V.size() * mcm * (mn / mcm), V.size() * mcm); } int main() { scanf( %d , &(n)); for (int i = 1; i <= n; i++) { scanf( %d , &(apple[i])); tot += apple[i]; } for (int i = 1; i < n; i++) { scanf( %d%d , &(a), &(b)); adj[a].push_back(b); adj[b].push_back(a); } adj[1].push_back(0); cout << tot - DFS(0, 1).first << endl; } |
#include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { int k, n; cin >> n >> k; int val[100000]; int awake[100000]; for (int i = 0; i < n; ++i) { cin >> val[i]; } int sum = 0; int extra = 0; int max = 0; for (int i = 0; i < n; ++i) { cin >> awake[i]; if (awake[i]) { sum += val[i]; val[i] = 0; } if (i < k) { extra += val[i]; } else { extra = extra + val[i] - val[i - k]; } if (extra > max) { max = extra; } } sum += max; cout << sum << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int c, e = 0; long long int s = 0, a; for (long long int i = 0; i < n; i++) { cin >> a; s += a; if (a % 2 != 0) { e++; if (e == 1) c = a; else if (e > 1) c = min(c, a); } } if (e % 2 != 0) s -= c; cout << s; } |
#include <bits/stdc++.h> using namespace std; const int MAXN = int(2e5 + 5); int n, m, S; int POW[25]; int f[MAXN]; bool vis[MAXN]; bool flag[MAXN]; long long tmp, tot, Ans, t; struct edge { int u, v, id; int w, c; } e[MAXN]; struct node { int to, id; node() {} node(int T, int I) : to(T), id(I) {} }; vector<node> G[MAXN]; void Addedge(int u, int v, int id) { G[u].push_back(node(v, id)); G[v].push_back(node(u, id)); } void Init() { POW[0] = 1; for (int i = 1; i <= 25; i++) POW[i] = 2 * POW[i - 1]; } int Find(int x) { return x == f[x] ? x : f[x] = Find(f[x]); } bool cmp(edge a, edge b) { return a.w < b.w; } bool cmp2(edge a, edge b) { return a.id < b.id; } void Kruskal() { sort(e + 1, e + m + 1, cmp); for (int i = 1; i <= n; i++) f[i] = i; t = 0; e[0].c = int(1e9 + 5); for (int i = 1; i <= m; i++) { int u = e[i].u, v = e[i].v; int fx = Find(u), fy = Find(v); if (fx != fy) { Addedge(u, v, i); f[fx] = fy; vis[i] = 1; tmp += e[i].w; if (e[i].c < e[t].c) t = i; } } tot = tmp; tmp -= S / e[t].c; } int MaxId(int a, int b) { return (e[a].w < e[b].w) ? b : a; } int Max[MAXN][25 + 5]; int fa[MAXN][25 + 5]; int dep[MAXN]; void Dfs(int u) { for (int i = 1; i <= 25; i++) { fa[u][i] = fa[fa[u][i - 1]][i - 1]; Max[u][i] = MaxId(Max[u][i - 1], Max[fa[u][i - 1]][i - 1]); } for (int i = 0; i < G[u].size(); i++) { int v = G[u][i].to; if (v == fa[u][0]) continue; dep[v] = dep[u] + 1; Max[v][0] = G[u][i].id; fa[v][0] = u; Dfs(v); } } int LCA(int u, int v) { if (dep[u] < dep[v]) swap(u, v); int t = dep[u] - dep[v]; for (int i = 0; POW[i] <= t; i++) if (POW[i] & t) u = fa[u][i]; if (u == v) return u; for (int i = 25; i >= 0; i--) if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i]; return fa[u][0]; } int Query(int u, int v) { int t = dep[u] - dep[v]; int ret = 0; for (int i = 0; POW[i] <= t; i++) if (POW[i] & t) { ret = MaxId(ret, Max[u][i]); u = fa[u][i]; } return ret; } int main() { Init(); scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { e[i].id = i; scanf( %d , &e[i].w); } for (int i = 1; i <= m; i++) scanf( %d , &e[i].c); for (int i = 1; i <= m; i++) scanf( %d%d , &e[i].u, &e[i].v); scanf( %d , &S); Kruskal(); e[0].w = -int(1e9 + 5); fill(Max[1], Max[1] + 25 + 1, 0); Dfs(1); long long Ans = tmp; int Last = -1, now = -1; for (int i = 1; i <= m; i++) if (e[i].c < e[t].c) { int u = e[i].u, v = e[i].v; int q = LCA(u, v); int x = MaxId(Query(u, q), Query(v, q)); tmp = (long long)tot - e[x].w + e[i].w - S / e[i].c; if (Ans > tmp) { Ans = tmp; vis[(Last != -1) ? Last : 0] = 1; vis[x] = 0; Last = x; vis[(now != -1) ? now : 0] = 0; vis[i] = 1; now = i; } } printf( %I64d n , Ans); if (now == -1) now = t; for (int i = 1; i <= m; i++) if (vis[i]) { if (now == i) e[i].w -= S / e[i].c; flag[e[i].id] = 1; } sort(e + 1, e + m + 1, cmp2); for (int i = 1; i <= m; i++) if (flag[i]) printf( %d %d n , i, e[i].w); } |
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; const long long inf = 1e14 + 10; long long n, k; long long a[N]; long long ps[N]; long long fen[N]; vector<long long> vec; void upd(long long x) { for (; x < N; x += (x & (-x))) { fen[x]++; } } long long get(long long x) { long long ret = 0; for (; x > 0; x -= (x & (-x))) { ret += fen[x]; } return ret; } bool check(long long K) { long long res = 0; for (long long i = 0; i < N; i++) { fen[i] = 0; } for (long long i = 1; i <= n; i++) { long long val = ps[i] - K; long long ind = upper_bound(vec.begin(), vec.end(), val) - vec.begin(); res += get(ind); ind = upper_bound(vec.begin(), vec.end(), ps[i]) - vec.begin(); upd(ind); if (ps[i] >= K) { res++; } } if (res >= k) { return true; } else { return false; } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (long long i = 1; i <= n; i++) { cin >> a[i]; ps[i] = ps[i - 1] + a[i]; vec.push_back(ps[i]); } sort(vec.begin(), vec.end()); long long L = -inf; long long R = inf; while (R - L > 1) { long long mid = (L + R) / 2; if (check(mid)) { L = mid; } else { R = mid; } } cout << L; return 0; } |
#include <bits/stdc++.h> int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); } int main() { int t, x, i, j, c; scanf( %d , &t); while (t--) { char n[101]; int m[101]; scanf( %s , &n); x = strlen(n); j = 0; c = 0; for (i = 0; i < x; i++) { if (n[i] == 1 ) c++; else if (c > 0) { m[j++] = c; c = 0; } } if (c > 0) m[j++] = c; qsort(m, j, sizeof(int), cmpfunc); c = 0; for (i = j - 1; i >= 0; i = i - 2) c = c + m[i]; printf( %d n , c); } } |
#include <bits/stdc++.h> using namespace std; long long ans[100004] = {0}; vector<long long> v[100005]; int main() { long long n, m, i, j, ms = 0, sum = 0, res = 0; scanf( %lld %lld , &n, &m); for (i = 0; i < n; i++) { long long a, b; scanf( %lld %lld , &a, &b); v[a].push_back(b); } for (i = 1; i <= m; i++) { sum = 0; sort(v[i].begin(), v[i].end()); long long si = v[i].size(); ms = max(ms, si); for (j = si - 1; j >= 0; j--) { sum += v[i][j]; if (sum > 0) ans[si - j] += sum; else break; } } for (i = 1; i <= ms; i++) res = max(res, ans[i]); printf( %lld n , res); return 0; } |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int cmx = 1e5 + 5; int n, k; char a[505][505]; int id[505][505]; int cc_sz[505 * 505]; int seen[505 * 505]; bool inside(int x, int y) { if (0 <= min(x, y) and max(x, y) < n) return true; return false; } int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, -1, 1}; void dfs(int x, int y, int cc_no) { id[x][y] = cc_no; cc_sz[cc_no]++; for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (inside(nx, ny) and (id[nx][ny] == 0 and a[nx][ny] == . )) dfs(nx, ny, cc_no); } } void add(int x, int y, int &ans, int flag) { if (a[x][y] == . and seen[id[x][y]] != flag) { seen[id[x][y]] = flag; ans += cc_sz[id[x][y]]; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = (0); i <= (n - 1); ++i) for (int j = (0); j <= (n - 1); ++j) cin >> a[i][j]; int which_cc = 0; for (int i = (0); i <= (n - 1); ++i) for (int j = (0); j <= (n - 1); ++j) { if (id[i][j] == 0 and a[i][j] == . ) { dfs(i, j, ++which_cc); } } int counter = 1; int best_ans = 0; for (int y_low = 0; (y_low + k) <= n; y_low++) { for (int x = 0; x < k; x++) for (int y = y_low; y < (y_low + k); y++) --cc_sz[id[x][y]]; for (int x_low = 0; (x_low + k) <= n; x_low++) { int ans = k * k; for (int x = 0; x < k; x++) { if (inside(x_low + x, y_low - 1)) add(x_low + x, y_low - 1, ans, counter); if (inside(x_low + x, y_low + k)) add(x_low + x, y_low + k, ans, counter); } for (int y = 0; y < k; y++) { if (inside(x_low - 1, y_low + y)) add(x_low - 1, y_low + y, ans, counter); if (inside(x_low + k, y_low + y)) add(x_low + k, y_low + y, ans, counter); } counter++; best_ans = max(best_ans, ans); if ((x_low + k) != n) { for (int y = 0; y < k; y++) { ++cc_sz[id[x_low][y + y_low]]; --cc_sz[id[x_low + k][y + y_low]]; } } } for (int x = n - k; x < n; x++) for (int y = 0; y < k; y++) ++cc_sz[id[x][y_low + y]]; } cout << best_ans << n ; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; int mark = 1; for (int i = 1; i < s.size(); i++) { if (s[i] != s[i - 1]) { mark = -1; break; } } if (mark == 1) { cout << s; for (int i = 1; i < k; i++) { cout << s[0]; } return 0; } for (int i = s.size() - 1; i >= 1; i--) { string t1 = s.substr(0, i); string t2 = s.substr(s.size() - i, i); if (t1 == t2) { int len = s.size() - i; string ost = s.substr(i, len); string ans = s; for (int j = 1; j < k; j++) { ans += ost; } int kol = 0; for (int j = 0; j + s.size() <= ans.size(); j++) { string mr = ans.substr(j, s.size()); if (mr == s) { kol++; if (kol == k) { string prt = ans.substr(0, j + s.size()); cout << prt << endl; return 0; } } } } } for (int i = 1; i <= k; i++) { cout << s; } return 0; } |
#include <bits/stdc++.h> using namespace std; int n, s[200003], m, cnt, ans[200003]; vector<pair<int, int> > v[200003], g[200003]; bool vis[200003]; int dfs(int x) { vis[x] = 1; int ret = 0, tmp; for (int i = 0; i < v[x].size(); i++) if (!vis[v[x][i].first]) { tmp = dfs(v[x][i].first); ret += tmp; ans[v[x][i].second] = -tmp; } for (int i = 0; i < g[x].size(); i++) if (!vis[g[x][i].first]) { tmp = dfs(g[x][i].first); ret += tmp; ans[g[x][i].second] = tmp; } return ret - s[x]; } int main() { cin >> n; for (int i = 0; i < n; i++) scanf( %d , s + i), cnt += s[i]; cin >> m; for (int i = 0; i < m; i++) { int x, y; scanf( %d%d , &x, &y); x--; y--; v[x].push_back(make_pair(y, i)); g[y].push_back(make_pair(x, i)); } if (cnt) { cout << Impossible ; return 0; } cout << Possible ; dfs(0); for (int i = 0; i < m; i++) printf( n%d , ans[i]); } |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, j = 0; cin >> a >> b >> c; for (int i = 1; i <= a; i++) { if (b >= 2 * i && c >= 4 * i) j++; } cout << j + 2 * j + 4 * j; return 0; } |
#include <bits/stdc++.h> using namespace std; struct Counter { static int k; Counter() { k++; } ~Counter() { k--; } }; int Counter::k = 0; template <typename T> void pr(const string& name, T t) { cout << name << = << t << endl; } template <typename T, typename... Types> void pr(const string& names, T t, Types... rest) { auto comma_pos = names.find( , ); cout << names.substr(0, comma_pos) << = << t << , ; auto next_name_pos = names.find_first_not_of( t n , comma_pos + 1); pr(string(names, next_name_pos), rest...); } void mod(long long& a, long long b) { a %= b; if (a < 0) a += b; } const long long MOD = 1000000007; deque<long long> DQ; long long Days[15], N, M; int main() { cin >> N >> M; string line; Days[1] = 0; Days[2] = 31; Days[3] = 59; Days[4] = 90; Days[5] = 120; Days[6] = 151; Days[7] = 181; Days[8] = 212; Days[9] = 243; Days[10] = 273; Days[11] = 304; Days[12] = 334; getline(cin, line); while (true) { getline(cin, line); if (cin.eof()) break; long long year = 0, month = 0, day = 0; for (int i = (0); i <= (3); i++) year = 10 * year + line[i] - 0 ; for (int i = (5); i <= (6); i++) month = 10 * month + line[i] - 0 ; for (int i = (8); i <= (9); i++) day = 10 * day + line[i] - 0 ; long long days = 365 * (year - 1) + Days[month] + day - 1; days += (year - 1) / 4; if (year % 4 == 0 && month > 2) days++; long long hr = 10 * (line[11] - 0 ) + line[12] - 0 ; long long mn = 10 * (line[14] - 0 ) + line[15] - 0 ; long long sc = 10 * (line[17] - 0 ) + line[18] - 0 ; long long sec = days * 60 * 60 * 24 + 3600 * hr + 60 * mn + sc; if (!DQ.empty() && sec - DQ.front() >= N) DQ.pop_front(); DQ.push_back(sec); if (DQ.size() >= M) { cout << line.substr(0, 19) << n ; return 0; } } cout << -1 ; } |
#include <bits/stdc++.h> using namespace std; int n, m, a[102], b[102]; int main(void) { scanf( %d %d , &n, &m); for (int i = 0; i < m; ++i) scanf( %d %d , &a[i], &b[i]); for (int x = 1; x <= n; ++x) { int c = 0; for (int i = 0; i < m; ++i) if (x >= a[i] && x <= b[i]) ++c; if (c != 1) { printf( %d %d n , x, c); return 0; } } puts( OK ); return 0; } |
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; long double a[maxn]; int main() { int n, s; long long k, b; while (~scanf( %d , &n)) { s = 0; for (int i = 0; i < n; i++) { scanf( %I64d %I64d , &k, &b); if (k != 0) { a[s++] = -(double)(b * 1.0) / (k * 1.0); } } sort(a, a + s); int count = 0; for (int i = 1; i < s; i++) { if (fabs(a[i] - a[i - 1]) > 0) { count++; } } if (s > 0) { count++; } printf( %d n , count); } return 0; } |
#include <bits/stdc++.h> using namespace std; inline long long bip(long long x, long long n, long long mod) { long long res = 1; while (n) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; } const int maxn = INT_MAX; const long long inf = 1e18; const int mod = 998244353; const int N = 1e5 + 10; void solve() { string a, b; cin >> a >> b; if ((int)b.size() > (int)a.size()) { sort(a.begin(), a.end()); reverse(a.begin(), a.end()); cout << a; return; } vector<int> cnt(10, 0); for (int i = 0; i < (int)a.size(); i++) cnt[a[i] - 0 ]++; vector<int> ans; for (int i = 0; i < (int)b.size(); i++) { int k = b[i] - 0 ; bool ok = 0; for (int j = k; j >= 0; j--) { if (cnt[j]) { ok = 1; cnt[j]--; ans.push_back(j); if (j < k) { for (int l = 9; l >= 0; l--) { while (cnt[l]--) ans.push_back(l); } for (auto it : ans) cout << it; return; } break; } } if (ok == 0) { for (int p = i - 1; p >= 0; p--) { int k = b[p] - 0 ; ans.pop_back(); cnt[k]++; bool ok = 0; for (int j = k - 1; j >= 0; j--) { if (cnt[j]) { ok = 1; break; } } if (ok) { for (int j = k - 1; j >= 0; j--) { if (cnt[j]) { ans.push_back(j); cnt[j]--; for (int l = 9; l >= 0; l--) { while (cnt[l]--) ans.push_back(l); } for (auto it : ans) cout << it; return; } } } } } } for (auto it : ans) cout << it; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int tt = 1; while (tt--) { solve(); cout << n ; } } |
#include <bits/stdc++.h> using namespace std; const int Maxn = 100000 + 19; int a[Maxn], Le[Maxn], Ri[Maxn], cnt, L, R, n, i, ans; int main() { scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &a[i]); Le[cnt = 1] = 1; a[++n] = a[n - 1] - 1; for (i = 1; i <= n; i++) if (a[i] <= a[i - 1]) { Ri[cnt] = i - 1; ans = max(ans, Ri[cnt] - Le[cnt] + 1); Le[++cnt] = i; } for (i = 1; i < cnt; i++) { if (Ri[i] < n - 1 || Le[i] > 1) ans = max(ans, Ri[i] - Le[i] + 2); if (i > 1) if (Ri[i - 1] > Le[i - 1] && Ri[i] > Le[i]) { if (a[Ri[i - 1] - 1] < a[Le[i]] - 1 || a[Ri[i - 1]] < a[Le[i] + 1] - 1) ans = max(ans, Ri[i] - Le[i - 1] + 1); } else { if (Ri[i - 1] == Le[i - 1]) ans = max(ans, Ri[i] - Le[i] + 2); if (Ri[i] == Le[i]) ans = max(ans, Ri[i - 1] - Le[i - 1] + 2); } } printf( %d n , ans); } |
#include <bits/stdc++.h> using namespace std; vector<int> path[1005]; long long d[105], t[105]; int n, m, u, v; queue<int> q; void work(int now) { for (int i = 1; i <= n; i++) { d[i] = 1 << 30; t[i] = 0; } d[now] = 0; t[now] = 1; q.push(now); while (!q.empty()) { u = q.front(); q.pop(); for (int i = 0; i < path[u].size(); i++) { v = path[u][i]; if (d[v] > d[u] + 1) { d[v] = d[u] + 1; t[v] = t[u]; q.push(v); } else if (d[v] == d[u] + 1) { t[v] += t[u]; } } } } int main() { long long len = 0, tmp = 0; double ans = 1.0; scanf( %d %d , &n, &m); for (int i = 1; i <= m; i++) { scanf( %d %d , &u, &v); path[u].push_back(v); path[v].push_back(u); } int start = 1; work(start), start++; len = d[n], tmp = t[n]; for (int i = start; i < n; i++) { start = 1; work(i); int see = 0; see = d[start] + d[n]; if (see == len) { double k = 0; k = (double)(2.0 * t[start] * t[n]) / (1.0 * tmp); ans = max(ans, k); } } printf( %.12lf n , ans); return 0; } |
#include <bits/stdc++.h> using namespace std; long long p, q, b, n, tmp; long long gcd(int x, int y) { return y ? gcd(y, x % y) : x; } int main() { ios::sync_with_stdio(false); cin.tie(); cout.tie(); cin >> n; for (int i = 0; i < n; i++) { cin >> p >> q >> b; q = q / gcd(q, p); while ((tmp = gcd(q, b)) != 1) while (q % tmp == 0) q /= tmp; if (q == 1) cout << Finite << endl; else cout << Infinite << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; long long binpow(long long a, long long b) { if (b == 0) return 1; long long res = binpow(a, b / 2); if (b % 2) return res * res * a; else return res * res; } vector<int> adj[200006]; bool vis[200006]; bool color[200006]; bool dfs(int x) { vis[x] = 1; for (int i = 0; i < adj[x].size(); i++) { if (!vis[adj[x][i]]) { color[adj[x][i]] = !color[x]; if (!dfs(adj[x][i])) return false; } else if (color[adj[x][i]] == color[x]) { return false; } } return true; } bool check(int a, int b) { while (a != 0) { int x = a % 10; if (x == 7) return 1; a /= 10; } while (b != 0) { int xx = b % 10; if (xx == 7) return 1; b /= 10; } return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt; cin >> tt; vector<pair<pair<int, int>, char>> vv; int ewq = 0; while (tt--) { char c; int r, l; cin >> c >> l >> r; vv.push_back({{l, r}, c}); } sort(vv.begin(), vv.end()); int F = 0; int M = 0; for (int i = 1; i <= 366; i++) { F = 0; M = 0; for (int j = 0; j < vv.size(); j++) { if (i >= vv[j].first.first && i <= vv[j].first.second) { if (vv[j].second == F ) F++; else M++; } } ewq = max(min(F, M), ewq); } cout << ewq * 2 << n ; return 0; } |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k; cin >> n >> k; string x; cin >> x; string ans = x; string y = ; long long p = n; for (long long i = 1; i < n; i++) { long long j; y = ; for (j = 0; i + j < n; j++) { if (x[i + j] != ans[j]) break; y += ans[j]; } if (i + j == n) { p = i; break; } } p = n - p; while (p--) { ans.erase(ans.begin()); } cout << x; while (--k) { cout << ans; } cout << endl; } |
#include <bits/stdc++.h> using namespace std; const int N = 1005; const int W = 1005; const long long inf = 1e18; struct dsu { vector<int> pr; vector<int> weights; vector<long long> beauties; set<int> roots; dsu(int _n) { pr.resize(_n + 5); weights.resize(_n + 5); beauties.resize(_n + 5); iota((pr).begin(), (pr).end(), 0); for (int u = (1); u <= ((_n)); u += (+1)) { roots.insert(u); } } int find(int u) { return pr[u] == u ? u : pr[u] = find(pr[u]); } bool unite(int u, int v) { u = find(u); v = find(v); if (u != v) { pr[u] = v; beauties[v] += beauties[u]; weights[v] += weights[u]; roots.erase(u); return true; } return false; } }; set<int> who[W]; long long dp[W]; int weights[N]; long long beauties[N]; bool done[W]; int n, m, max_w; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15); cin >> n >> m >> max_w; dsu dg(n); for (int u = (1); u <= ((n)); u += (+1)) { int w; cin >> w; dg.weights[u] = weights[u] = w; } for (int u = (1); u <= ((n)); u += (+1)) { long long b; cin >> b; dg.beauties[u] = beauties[u] = b; } for (int i = (0); i <= ((m)-1); i += (+1)) { int u, v; cin >> u >> v; dg.unite(u, v); } done[0] = true; for (int u : dg.roots) { for (int w = (max_w); w >= (0); w += (-1)) { if (w - dg.weights[u] < 0) { break; } int ru = dg.find(u); if (dp[w - dg.weights[u]] + dg.beauties[u] > dp[w] && !who[w - dg.weights[ru]].count(ru) && done[w - dg.weights[u]]) { done[w] = true; dp[w] = dp[w - dg.weights[u]] + dg.beauties[u]; who[w] = who[w - dg.weights[u]]; who[w].insert(ru); } } } for (int u = (1); u <= ((n)); u += (+1)) { for (int w = (max_w); w >= (0); w += (-1)) { if (w - weights[u] < 0) { break; } int ru = dg.find(u); if (dp[w - weights[u]] + beauties[u] > dp[w] && !who[w - weights[u]].count(ru) && done[w - weights[u]]) { done[w] = true; dp[w] = dp[w - weights[u]] + beauties[u]; who[w] = who[w - weights[u]]; who[w].insert(ru); } } } cout << *max_element(dp, dp + max_w + 1) << n ; return 0; } |
#include <bits/stdc++.h> using namespace std; const int maxn = 152; const int maxp = 51123987; static int A[maxn], len; static int opt[maxn][52][52][52], n, Ne[maxn][4]; char s[maxn]; static int idx[maxn * 10]; int main() { scanf( %d n , &n); for (int i = 1; i <= n; i++) { s[++len] = getchar(); if (s[len] == s[len - 1]) len--; } for (int i = len; i; i--) { int kd = s[i] == a ; if (s[i] == b ) kd = 2; if (s[i] == c ) kd = 3; Ne[i][1] = Ne[i + 1][1]; Ne[i][2] = Ne[i + 1][2]; Ne[i][3] = Ne[i + 1][3]; Ne[i][kd] = i; } int mxl = (n - 1) / 3 + 1; opt[Ne[1][1]][1][0][0] = 1; opt[Ne[1][2]][0][1][0] = 1; opt[Ne[1][3]][0][0][1] = 1; for (int i = 1; i <= len; i++) for (int j = 0; j <= mxl; j++) for (int k = 0; k <= mxl; k++) for (int l = 0; l <= mxl; l++) { opt[Ne[i][1]][j + 1][k][l] = opt[Ne[i][1]][j + 1][k][l] + opt[i][j][k][l]; if (opt[Ne[i][1]][j + 1][k][l] >= maxp) opt[Ne[i][1]][j + 1][k][l] -= maxp; opt[Ne[i][2]][j][k + 1][l] = opt[Ne[i][2]][j][k + 1][l] + opt[i][j][k][l]; if (opt[Ne[i][2]][j][k + 1][l] >= maxp) opt[Ne[i][2]][j][k + 1][l] -= maxp; opt[Ne[i][3]][j][k][l + 1] = opt[Ne[i][3]][j][k][l + 1] + opt[i][j][k][l]; if (opt[Ne[i][3]][j][k][l + 1] >= maxp) opt[Ne[i][3]][j][k][l + 1] -= maxp; } int ans = 0; for (int i = 1; i <= len; i++) { if (n % 3 == 0) ans = (ans + opt[i][mxl][mxl][mxl]) % maxp; if (n % 3 == 1) ans = (ans + opt[i][mxl - 1][mxl - 1][mxl] + opt[i][mxl - 1][mxl][mxl - 1] + opt[i][mxl][mxl - 1][mxl - 1]) % maxp; if (n % 3 == 2) ans = (ans + opt[i][mxl][mxl - 1][mxl] + opt[i][mxl - 1][mxl][mxl] + opt[i][mxl][mxl][mxl - 1]) % maxp; } printf( %d n , ans); return 0; } |
#include <bits/stdc++.h> using namespace std; char c[600]; vector<int> check; int n; vector<int> cal; int calculate() { int num = 0; cal.clear(); int minimum = INT_MAX; for (int i = 1; i <= n; i++) { if (c[i - 1] == ( ) { num++; minimum = min(minimum, num); cal.push_back(num); } else { num--; minimum = min(minimum, num); cal.push_back(num); } } int ret = 0; for (int i = 1; i <= n; i++) { if (minimum == cal[i - 1]) { ret++; } } return ret; } int main() { scanf( %d , &n); scanf( %s , c); int ans_l = 1, ans_r = 1; int beauty = INT_MIN; int cnt = 0; for (int i = 1; i <= n; i++) { if (c[i - 1] == ( ) { cnt++; } else { cnt--; } } if (cnt != 0) { printf( 0 n1 1 ); return 0; } for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { char temp = c[j - 1]; c[j - 1] = c[i - 1]; c[i - 1] = temp; int now_beauty = calculate(); if (beauty < now_beauty) { beauty = now_beauty; ans_l = i; ans_r = j; } temp = c[j - 1]; c[j - 1] = c[i - 1]; c[i - 1] = temp; } } printf( %d n%d %d , beauty, ans_l, ans_r); return 0; } |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long MOD = 1e9 + 7; const int N = 1e6; int T, n, r, A[1005]; void solve() { cin >> n >> r; for (int i = 1; i <= n; i++) { cin >> A[i]; } int ans = 0; int z; for (int i = 1; i <= n; i = z + r) { bool can_warm = false; z = -1; int left = max(i - r + 1, 0), right = min(i + r, n + 1); for (int j = left; j < right; j++) { if (A[j]) { can_warm = true; z = j; } } if (!can_warm) { cout << -1; return; } ans++; } cout << ans; } int(main)() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); T = 1; while (T--) { solve(); } } |
#include<iostream> #include<bits/stdc++.h> using namespace std; #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) #define ll unsigned long long int #define tinput int t; cin>>t; while(t--) #define rep(i,n,s) for((i)=(s); (i)<(n); (i)++) template <typename T> T getmini(T x, T y) { return (x<y)?x:y; } template <typename T> T getmaxi(T x, T y) { return (x>y)?x:y; } int main(){ #ifndef ONLINE_JUDGE freopen( b_input.txt , r , stdin); freopen( b_output.txt , w , stdout); #endif boost; tinput { int x, y; cin>>x>>y; int ans = x+y; if(abs(x-y)>1) { ans = ans + abs(x-y) - 1; } cout<<ans<<endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973, 10007, 10009, 10037, 10039, 10061, 10067, 10069, 10079, 10091, 10093, 10099, 10103, 10111, 10133, 10139, 10141, 10151, 10159, 10163, 10169, 10177, 10181, 10193, 10211, 10223, 10243, 10247, 10253, 10259, 10267, 10271, 10273, 10289, 10301, 10303, 10313, 10321, 10331, 10333, 10337, 10343, 10357, 10369, 10391, 10399, 10427, 10429, 10433, 10453, 10457, 10459, 10463, 10477, 10487, 10499, 10501, 10513, 10529, 10531, 10559, 10567, 10589, 10597, 10601, 10607, 10613, 10627, 10631, 10639, 10651, 10657, 10663, 10667, 10687, 10691, 10709, 10711, 10723, 10729, 10733, 10739, 10753, 10771, 10781, 10789, 10799, 10831, 10837, 10847, 10853, 10859, 10861, 10867, 10883, 10889, 10891, 10903, 10909, 10937, 10939, 10949, 10957, 10973, 10979, 10987, 10993, 11003, 11027, 11047, 11057, 11059, 11069, 11071, 11083, 11087, 11093, 11113, 11117, 11119, 11131, 11149, 11159, 11161, 11171, 11173, 11177, 11197, 11213, 11239, 11243, 11251, 11257, 11261, 11273, 11279, 11287, 11299, 11311, 11317, 11321, 11329, 11351, 11353, 11369, 11383, 11393, 11399, 11411, 11423, 11437, 11443, 11447, 11467, 11471, 11483, 11489, 11491, 11497, 11503, 11519, 11527, 11549, 11551, 11579, 11587, 11593, 11597, 11617, 11621, 11633, 11657, 11677, 11681, 11689, 11699, 11701, 11717, 11719, 11731, 11743, 11777, 11779, 11783, 11789, 11801, 11807, 11813, 11821, 11827, 11831, 11833, 11839, 11863, 11867, 11887, 11897, 11903, 11909, 11923, 11927, 11933, 11939, 11941, 11953, 11959, 11969, 11971, 11981, 11987, 12007, 12011, 12037, 12041, 12043, 12049, 12071, 12073, 12097, 12101, 12107, 12109, 12113, 12119, 12143, 12149, 12157, 12161, 12163, 12197, 12203, 12211, 12227, 12239, 12241, 12251, 12253, 12263, 12269, 12277, 12281, 12289, 12301, 12323, 12329, 12343, 12347, 12373, 12377, 12379, 12391, 12401, 12409, 12413, 12421, 12433, 12437, 12451, 12457, 12473, 12479, 12487, 12491, 12497, 12503, 12511, 12517, 12527, 12539, 12541, 12547, 12553, 12569, 12577, 12583, 12589, 12601, 12611, 12613, 12619, 12637, 12641, 12647, 12653, 12659, 12671, 12689, 12697, 12703, 12713, 12721, 12739, 12743, 12757, 12763, 12781, 12791, 12799, 12809, 12821, 12823, 12829, 12841, 12853, 12889, 12893, 12899, 12907, 12911, 12917, 12919, 12923, 12941, 12953, 12959, 12967, 12973, 12979, 12983, 13001, 13003, 13007, 13009, 13033, 13037, 13043, 13049, 13063, 13093, 13099, 13103, 13109, 13121, 13127, 13147, 13151, 13159, 13163, 13171, 13177, 13183, 13187, 13217, 13219, 13229, 13241, 13249, 13259, 13267, 13291, 13297, 13309, 13313, 13327, 13331, 13337, 13339, 13367, 13381, 13397, 13399, 13411, 13417, 13421, 13441, 13451, 13457, 13463, 13469, 13477, 13487, 13499, 13513, 13523, 13537, 13553, 13567, 13577, 13591, 13597, 13613, 13619, 13627, 13633, 13649, 13669, 13679, 13681, 13687, 13691, 13693, 13697, 13709, 13711, 13721, 13723, 13729, 13751, 13757, 13759, 13763, 13781, 13789, 13799, 13807, 13829, 13831, 13841, 13859, 13873, 13877, 13879, 13883, 13901, 13903, 13907, 13913, 13921, 13931, 13933, 13963, 13967, 13997, 13999, 14009, 14011, 14029, 14033, 14051, 14057, 14071, 14081, 14083, 14087, 14107, 14143, 14149, 14153, 14159, 14173, 14177, 14197, 14207, 14221, 14243, 14249, 14251, 14281, 14293, 14303, 14321, 14323, 14327, 14341, 14347, 14369, 14387, 14389, 14401, 14407, 14411, 14419, 14423, 14431, 14437, 14447, 14449, 14461, 14479, 14489, 14503, 14519, 14533, 14537, 14543, 14549, 14551, 14557, 14561, 14563, 14591, 14593, 14621, 14627, 14629, 14633, 14639, 14653, 14657, 14669, 14683, 14699, 14713, 14717, 14723, 14731, 14737, 14741, 14747, 14753, 14759, 14767, 14771, 14779, 14783, 14797, 14813, 14821, 14827, 14831, 14843, 14851, 14867, 14869, 14879, 14887, 14891, 14897, 14923, 14929, 14939, 14947, 14951, 14957, 14969, 14983, 15013, 15017, 15031, 15053, 15061, 15073, 15077, 15083, 15091, 15101, 15107, 15121, 15131, 15137, 15139, 15149, 15161, 15173, 15187, 15193, 15199, 15217, 15227, 15233, 15241, 15259, 15263, 15269, 15271, 15277, 15287, 15289, 15299, 15307, 15313, 15319, 15329, 15331, 15349, 15359, 15361, 15373, 15377, 15383, 15391, 15401, 15413, 15427, 15439, 15443, 15451, 15461, 15467, 15473, 15493, 15497, 15511, 15527, 15541, 15551, 15559, 15569, 15581, 15583, 15601, 15607, 15619, 15629, 15641, 15643, 15647, 15649, 15661, 15667, 15671, 15679, 15683, 15727, 15731, 15733, 15737, 15739, 15749, 15761, 15767, 15773, 15787, 15791, 15797, 15803, 15809, 15817, 15823, 15859, 15877, 15881, 15887, 15889, 15901, 15907, 15913, 15919, 15923, 15937, 15959, 15971, 15973, 15991, 16001, 16007, 16033, 16057, 16061, 16063, 16067, 16069, 16073, 16087, 16091, 16097, 16103, 16111, 16127, 16139, 16141, 16183, 16187, 16189, 16193, 16217, 16223, 16229, 16231, 16249, 16253, 16267, 16273, 16301, 16319, 16333, 16339, 16349, 16361, 16363, 16369, 16381, 16411, 16417, 16421, 16427, 16433, 16447, 16451, 16453, 16477, 16481, 16487, 16493, 16519, 16529, 16547, 16553, 16561, 16567, 16573, 16603, 16607, 16619, 16631, 16633, 16649, 16651, 16657, 16661, 16673, 16691, 16693, 16699, 16703, 16729, 16741, 16747, 16759, 16763, 16787, 16811, 16823, 16829, 16831, 16843, 16871, 16879, 16883, 16889, 16901, 16903, 16921, 16927, 16931, 16937, 16943, 16963, 16979, 16981, 16987, 16993, 17011, 17021, 17027, 17029, 17033, 17041, 17047, 17053, 17077, 17093, 17099, 17107, 17117, 17123, 17137, 17159, 17167, 17183, 17189, 17191, 17203, 17207, 17209, 17231, 17239, 17257, 17291, 17293, 17299, 17317, 17321, 17327, 17333, 17341, 17351, 17359, 17377, 17383, 17387, 17389, 17393, 17401, 17417, 17419, 17431, 17443, 17449, 17467, 17471, 17477, 17483, 17489, 17491, 17497, 17509, 17519, 17539, 17551, 17569, 17573, 17579, 17581, 17597, 17599, 17609, 17623, 17627, 17657, 17659, 17669, 17681, 17683, 17707, 17713, 17729, 17737, 17747, 17749, 17761, 17783, 17789, 17791, 17807, 17827, 17837, 17839, 17851, 17863, 17881, 17891, 17903, 17909, 17911, 17921, 17923, 17929, 17939, 17957, 17959, 17971, 17977, 17981, 17987, 17989, 18013, 18041, 18043, 18047, 18049, 18059, 18061, 18077, 18089, 18097, 18119, 18121, 18127, 18131, 18133, 18143, 18149, 18169, 18181, 18191, 18199, 18211, 18217, 18223, 18229, 18233, 18251, 18253, 18257, 18269, 18287, 18289, 18301, 18307, 18311, 18313, 18329, 18341, 18353, 18367, 18371, 18379, 18397, 18401, 18413, 18427, 18433, 18439, 18443, 18451, 18457, 18461, 18481, 18493, 18503, 18517, 18521, 18523, 18539, 18541, 18553, 18583, 18587, 18593, 18617, 18637, 18661, 18671, 18679, 18691, 18701, 18713, 18719, 18731, 18743, 18749, 18757, 18773, 18787, 18793, 18797, 18803, 18839, 18859, 18869, 18899, 18911, 18913, 18917, 18919, 18947, 18959, 18973, 18979, 19001, 19009, 19013, 19031, 19037, 19051, 19069, 19073, 19079, 19081, 19087, 19121, 19139, 19141, 19157, 19163, 19181, 19183, 19207, 19211, 19213, 19219, 19231, 19237, 19249, 19259, 19267, 19273, 19289, 19301, 19309, 19319, 19333, 19373, 19379, 19381, 19387, 19391, 19403, 19417, 19421, 19423, 19427, 19429, 19433, 19441, 19447, 19457, 19463, 19469, 19471, 19477, 19483, 19489, 19501, 19507, 19531, 19541, 19543, 19553, 19559, 19571, 19577, 19583, 19597, 19603, 19609, 19661, 19681, 19687, 19697, 19699, 19709, 19717, 19727, 19739, 19751, 19753, 19759, 19763, 19777, 19793, 19801, 19813, 19819, 19841, 19843, 19853, 19861, 19867, 19889, 19891, 19913, 19919, 19927, 19937, 19949, 19961, 19963, 19973, 19979, 19991, 19993, 19997, 20011, 20021, 20023, 20029, 20047, 20051, 20063, 20071, 20089, 20101, 20107, 20113, 20117, 20123, 20129, 20143, 20147, 20149, 20161, 20173, 20177, 20183, 20201, 20219, 20231, 20233, 20249, 20261, 20269, 20287, 20297, 20323, 20327, 20333, 20341, 20347, 20353, 20357, 20359, 20369, 20389, 20393, 20399, 20407, 20411, 20431, 20441, 20443, 20477, 20479, 20483, 20507, 20509, 20521, 20533, 20543, 20549, 20551, 20563, 20593, 20599, 20611, 20627, 20639, 20641, 20663, 20681, 20693, 20707, 20717, 20719, 20731, 20743, 20747, 20749, 20753, 20759, 20771, 20773, 20789, 20807, 20809, 20849, 20857, 20873, 20879, 20887, 20897, 20899, 20903, 20921, 20929, 20939, 20947, 20959, 20963, 20981, 20983, 21001, 21011, 21013, 21017, 21019, 21023, 21031, 21059, 21061, 21067, 21089, 21101, 21107, 21121, 21139, 21143, 21149, 21157, 21163, 21169, 21179, 21187, 21191, 21193, 21211, 21221, 21227, 21247, 21269, 21277, 21283, 21313, 21317, 21319, 21323, 21341, 21347, 21377, 21379, 21383, 21391, 21397, 21401, 21407, 21419, 21433, 21467, 21481, 21487, 21491, 21493, 21499, 21503, 21517, 21521, 21523, 21529, 21557, 21559, 21563, 21569, 21577, 21587, 21589, 21599, 21601, 21611, 21613, 21617, 21647, 21649, 21661, 21673, 21683, 21701, 21713, 21727, 21737, 21739, 21751, 21757, 21767, 21773, 21787, 21799, 21803, 21817, 21821, 21839, 21841, 21851, 21859, 21863, 21871, 21881, 21893, 21911, 21929, 21937, 21943, 21961, 21977, 21991, 21997, 22003, 22013, 22027, 22031, 22037, 22039, 22051, 22063, 22067, 22073, 22079, 22091, 22093, 22109, 22111, 22123, 22129, 22133, 22147, 22153, 22157, 22159, 22171, 22189, 22193, 22229, 22247, 22259, 22271, 22273, 22277, 22279, 22283, 22291, 22303, 22307, 22343, 22349, 22367, 22369, 22381, 22391, 22397, 22409, 22433, 22441, 22447, 22453, 22469, 22481, 22483, 22501, 22511, 22531, 22541, 22543, 22549, 22567, 22571, 22573, 22613, 22619, 22621, 22637, 22639, 22643, 22651, 22669, 22679, 22691, 22697, 22699, 22709, 22717, 22721, 22727, 22739, 22741, 22751, 22769, 22777, 22783, 22787, 22807, 22811, 22817, 22853, 22859, 22861, 22871, 22877, 22901, 22907, 22921, 22937, 22943, 22961, 22963, 22973, 22993, 23003, 23011, 23017, 23021, 23027, 23029, 23039, 23041, 23053, 23057, 23059, 23063, 23071, 23081, 23087, 23099, 23117, 23131, 23143, 23159, 23167, 23173, 23189, 23197, 23201, 23203, 23209, 23227, 23251, 23269, 23279, 23291, 23293, 23297, 23311, 23321, 23327, 23333, 23339, 23357, 23369, 23371, 23399, 23417, 23431, 23447, 23459, 23473, 23497, 23509, 23531, 23537, 23539, 23549, 23557, 23561, 23563, 23567, 23581, 23593, 23599, 23603, 23609, 23623, 23627, 23629, 23633, 23663, 23669, 23671, 23677, 23687, 23689, 23719, 23741, 23743, 23747, 23753, 23761, 23767, 23773, 23789, 23801, 23813, 23819, 23827, 23831, 23833, 23857, 23869, 23873, 23879, 23887, 23893, 23899, 23909, 23911, 23917, 23929, 23957, 23971, 23977, 23981, 23993, 24001, 24007, 24019, 24023, 24029, 24043, 24049, 24061, 24071, 24077, 24083, 24091, 24097, 24103, 24107, 24109, 24113, 24121, 24133, 24137, 24151, 24169, 24179, 24181, 24197, 24203, 24223, 24229, 24239, 24247, 24251, 24281, 24317, 24329, 24337, 24359, 24371, 24373, 24379, 24391, 24407, 24413, 24419, 24421, 24439, 24443, 24469, 24473, 24481, 24499, 24509, 24517, 24527, 24533, 24547, 24551, 24571, 24593, 24611, 24623, 24631, 24659, 24671, 24677, 24683, 24691, 24697, 24709, 24733, 24749, 24763, 24767, 24781, 24793, 24799, 24809, 24821, 24841, 24847, 24851, 24859, 24877, 24889, 24907, 24917, 24919, 24923, 24943, 24953, 24967, 24971, 24977, 24979, 24989, 25013, 25031, 25033, 25037, 25057, 25073, 25087, 25097, 25111, 25117, 25121, 25127, 25147, 25153, 25163, 25169, 25171, 25183, 25189, 25219, 25229, 25237, 25243, 25247, 25253, 25261, 25301, 25303, 25307, 25309, 25321, 25339, 25343, 25349, 25357, 25367, 25373, 25391, 25409, 25411, 25423, 25439, 25447, 25453, 25457, 25463, 25469, 25471, 25523, 25537, 25541, 25561, 25577, 25579, 25583, 25589, 25601, 25603, 25609, 25621, 25633, 25639, 25643, 25657, 25667, 25673, 25679, 25693, 25703, 25717, 25733, 25741, 25747, 25759, 25763, 25771, 25793, 25799, 25801, 25819, 25841, 25847, 25849, 25867, 25873, 25889, 25903, 25913, 25919, 25931, 25933, 25939, 25943, 25951, 25969, 25981, 25997, 25999, 26003, 26017, 26021, 26029, 26041, 26053, 26083, 26099, 26107, 26111, 26113, 26119, 26141, 26153, 26161, 26171, 26177, 26183, 26189, 26203, 26209, 26227, 26237, 26249, 26251, 26261, 26263, 26267, 26293, 26297, 26309, 26317, 26321, 26339, 26347, 26357, 26371, 26387, 26393, 26399, 26407, 26417, 26423, 26431, 26437, 26449, 26459, 26479, 26489, 26497, 26501, 26513, 26539, 26557, 26561, 26573, 26591, 26597, 26627, 26633, 26641, 26647, 26669, 26681, 26683, 26687, 26693, 26699, 26701, 26711, 26713, 26717, 26723, 26729, 26731, 26737, 26759, 26777, 26783, 26801, 26813, 26821, 26833, 26839, 26849, 26861, 26863, 26879, 26881, 26891, 26893, 26903, 26921, 26927, 26947, 26951, 26953, 26959, 26981, 26987, 26993, 27011, 27017, 27031, 27043, 27059, 27061, 27067, 27073, 27077, 27091, 27103, 27107, 27109, 27127, 27143, 27179, 27191, 27197, 27211, 27239, 27241, 27253, 27259, 27271, 27277, 27281, 27283, 27299, 27329, 27337, 27361, 27367, 27397, 27407, 27409, 27427, 27431, 27437, 27449, 27457, 27479, 27481, 27487, 27509, 27527, 27529, 27539, 27541, 27551, 27581, 27583, 27611, 27617, 27631, 27647, 27653, 27673, 27689, 27691, 27697, 27701, 27733, 27737, 27739, 27743, 27749, 27751, 27763, 27767, 27773, 27779, 27791, 27793, 27799, 27803, 27809, 27817, 27823, 27827, 27847, 27851, 27883, 27893, 27901, 27917, 27919, 27941, 27943, 27947, 27953, 27961, 27967, 27983, 27997, 28001, 28019, 28027, 28031, 28051, 28057, 28069, 28081, 28087, 28097, 28099, 28109, 28111, 28123, 28151, 28163, 28181, 28183, 28201, 28211, 28219, 28229, 28277, 28279, 28283, 28289, 28297, 28307, 28309, 28319, 28349, 28351, 28387, 28393, 28403, 28409, 28411, 28429, 28433, 28439, 28447, 28463, 28477, 28493, 28499, 28513, 28517, 28537, 28541, 28547, 28549, 28559, 28571, 28573, 28579, 28591, 28597, 28603, 28607, 28619, 28621, 28627, 28631, 28643, 28649, 28657, 28661, 28663, 28669, 28687, 28697, 28703, 28711, 28723, 28729, 28751, 28753, 28759, 28771, 28789, 28793, 28807, 28813, 28817, 28837, 28843, 28859, 28867, 28871, 28879, 28901, 28909, 28921, 28927, 28933, 28949, 28961, 28979, 29009, 29017, 29021, 29023, 29027, 29033, 29059, 29063, 29077, 29101, 29123, 29129, 29131, 29137, 29147, 29153, 29167, 29173, 29179, 29191, 29201, 29207, 29209, 29221, 29231, 29243, 29251, 29269, 29287, 29297, 29303, 29311, 29327, 29333, 29339, 29347, 29363, 29383, 29387, 29389, 29399, 29401, 29411, 29423, 29429, 29437, 29443, 29453, 29473, 29483, 29501, 29527, 29531, 29537, 29567, 29569, 29573, 29581, 29587, 29599, 29611, 29629, 29633, 29641, 29663, 29669, 29671, 29683, 29717, 29723, 29741, 29753, 29759, 29761, 29789, 29803, 29819, 29833, 29837, 29851, 29863, 29867, 29873, 29879, 29881, 29917, 29921, 29927, 29947, 29959, 29983, 29989, 30011, 30013, 30029, 30047, 30059, 30071, 30089, 30091, 30097, 30103, 30109, 30113, 30119, 30133, 30137, 30139, 30161, 30169, 30181, 30187, 30197, 30203, 30211, 30223, 30241, 30253, 30259, 30269, 30271, 30293, 30307, 30313, 30319, 30323, 30341, 30347, 30367, 30389, 30391, 30403, 30427, 30431, 30449, 30467, 30469, 30491, 30493, 30497, 30509, 30517, 30529, 30539, 30553, 30557, 30559, 30577, 30593, 30631, 30637, 30643, 30649, 30661, 30671, 30677, 30689, 30697, 30703, 30707, 30713, 30727, 30757, 30763, 30773, 30781, 30803, 30809, 30817, 30829, 30839, 30841, 30851, 30853, 30859, 30869, 30871, 30881, 30893, 30911, 30931, 30937, 30941, 30949, 30971, 30977, 30983, 31013, 31019, 31033, 31039, 31051, 31063, 31069, 31079, 31081, 31091, 31121, 31123, 31139, 31147, 31151, 31153, 31159, 31177, 31181, 31183, 31189, 31193, 31219, 31223, 31231, 31237, 31247, 31249, 31253, 31259, 31267, 31271, 31277, 31307, 31319, 31321, 31327, 31333, 31337, 31357, 31379, 31387, 31391, 31393, 31397, 31469, 31477, 31481, 31489, 31511, 31513, 31517, 31531, 31541, 31543, 31547, 31567, 31573, 31583, 31601, 31607, 31627, 31643, 31649, 31657, 31663, 31667, 31687, 31699, 31721, 31723, 31727, 31729, 31741, 31751, 31769, 31771, 31793, 31799, 31817, 31847, 31849, 31859, 31873, 31883, 31891, 31907, 31957, 31963, 31973, 31981, 31991, 32003, 32009, 32027, 32029, 32051, 32057, 32059, 32063, 32069, 32077, 32083, 32089, 32099, 32117, 32119, 32141, 32143, 32159, 32173, 32183, 32189, 32191, 32203, 32213, 32233, 32237, 32251, 32257, 32261, 32297, 32299, 32303, 32309, 32321, 32323, 32327, 32341, 32353, 32359, 32363, 32369, 32371, 32377, 32381, 32401, 32411, 32413, 32423, 32429, 32441, 32443, 32467, 32479, 32491, 32497, 32503, 32507, 32531, 32533, 32537, 32561, 32563, 32569, 32573, 32579, 32587, 32603, 32609, 32611, 32621, 32633, 32647, 32653, 32687, 32693, 32707, 32713, 32717, 32719, 32749, 32771, 32779, 32783, 32789, 32797, 32801, 32803, 32831, 32833, 32839, 32843, 32869, 32887, 32909, 32911, 32917, 32933, 32939, 32941, 32957, 32969, 32971, 32983, 32987, 32993, 32999, 33013, 33023, 33029, 33037, 33049, 33053, 33071, 33073, 33083, 33091, 33107, 33113, 33119, 33149, 33151, 33161, 33179, 33181, 33191, 33199, 33203, 33211, 33223, 33247, 33287, 33289, 33301, 33311, 33317, 33329, 33331, 33343, 33347, 33349, 33353, 33359, 33377, 33391, 33403, 33409, 33413, 33427, 33457, 33461, 33469, 33479, 33487, 33493, 33503, 33521, 33529, 33533, 33547, 33563, 33569, 33577, 33581, 33587, 33589, 33599, 33601, 33613, 33617, 33619, 33623, 33629, 33637, 33641, 33647, 33679, 33703, 33713, 33721, 33739, 33749, 33751, 33757, 33767, 33769, 33773, 33791, 33797, 33809, 33811, 33827, 33829, 33851, 33857, 33863, 33871, 33889, 33893, 33911, 33923, 33931, 33937, 33941, 33961, 33967, 33997, 34019, 34031, 34033, 34039, 34057, 34061, 34123, 34127, 34129, 34141, 34147, 34157, 34159, 34171, 34183, 34211, 34213, 34217, 34231, 34253, 34259, 34261, 34267, 34273, 34283, 34297, 34301, 34303, 34313, 34319, 34327, 34337, 34351, 34361, 34367, 34369, 34381, 34403, 34421, 34429, 34439, 34457, 34469, 34471, 34483, 34487, 34499, 34501, 34511, 34513, 34519, 34537, 34543, 34549, 34583, 34589, 34591, 34603, 34607, 34613, 34631, 34649, 34651, 34667, 34673, 34679, 34687, 34693, 34703, 34721, 34729, 34739, 34747, 34757, 34759, 34763, 34781, 34807, 34819, 34841, 34843, 34847, 34849, 34871, 34877, 34883, 34897, 34913, 34919, 34939, 34949, 34961, 34963, 34981, 35023, 35027, 35051, 35053, 35059, 35069, 35081, 35083, 35089, 35099, 35107, 35111, 35117, 35129, 35141, 35149, 35153, 35159, 35171, 35201, 35221, 35227, 35251, 35257, 35267, 35279, 35281, 35291, 35311, 35317, 35323, 35327, 35339, 35353, 35363, 35381, 35393, 35401, 35407, 35419, 35423, 35437, 35447, 35449, 35461, 35491, 35507, 35509, 35521, 35527, 35531, 35533, 35537, 35543, 35569, 35573, 35591, 35593, 35597, 35603, 35617, 35671, 35677, 35729, 35731, 35747, 35753, 35759, 35771, 35797, 35801, 35803, 35809, 35831, 35837, 35839, 35851, 35863, 35869, 35879, 35897, 35899, 35911, 35923, 35933, 35951, 35963, 35969, 35977, 35983, 35993, 35999, 36007, 36011, 36013, 36017, 36037, 36061, 36067, 36073, 36083, 36097, 36107, 36109, 36131, 36137, 36151, 36161, 36187, 36191, 36209, 36217, 36229, 36241, 36251, 36263, 36269, 36277, 36293, 36299, 36307, 36313, 36319, 36341, 36343, 36353, 36373, 36383, 36389, 36433, 36451, 36457, 36467, 36469, 36473, 36479, 36493, 36497, 36523, 36527, 36529, 36541, 36551, 36559, 36563, 36571, 36583, 36587, 36599, 36607, 36629, 36637, 36643, 36653, 36671, 36677, 36683, 36691, 36697, 36709, 36713, 36721, 36739, 36749, 36761, 36767, 36779, 36781, 36787, 36791, 36793, 36809, 36821, 36833, 36847, 36857, 36871, 36877, 36887, 36899, 36901, 36913, 36919, 36923, 36929, 36931, 36943, 36947, 36973, 36979, 36997, 37003, 37013, 37019, 37021, 37039, 37049, 37057, 37061, 37087, 37097, 37117, 37123, 37139, 37159, 37171, 37181, 37189, 37199, 37201, 37217, 37223, 37243, 37253, 37273, 37277, 37307, 37309, 37313, 37321, 37337, 37339, 37357, 37361, 37363, 37369, 37379, 37397, 37409, 37423, 37441, 37447, 37463, 37483, 37489, 37493, 37501, 37507, 37511, 37517, 37529, 37537, 37547, 37549, 37561, 37567, 37571, 37573, 37579, 37589, 37591, 37607, 37619, 37633, 37643, 37649, 37657, 37663, 37691, 37693, 37699, 37717, 37747, 37781, 37783, 37799, 37811, 37813, 37831, 37847, 37853, 37861, 37871, 37879, 37889, 37897, 37907, 37951, 37957, 37963, 37967, 37987, 37991, 37993, 37997, 38011, 38039, 38047, 38053, 38069, 38083, 38113, 38119, 38149, 38153, 38167, 38177, 38183, 38189, 38197, 38201, 38219, 38231, 38237, 38239, 38261, 38273, 38281, 38287, 38299, 38303, 38317, 38321, 38327, 38329, 38333, 38351, 38371, 38377, 38393, 38431, 38447, 38449, 38453, 38459, 38461, 38501, 38543, 38557, 38561, 38567, 38569, 38593, 38603, 38609, 38611, 38629, 38639, 38651, 38653, 38669, 38671, 38677, 38693, 38699, 38707, 38711, 38713, 38723, 38729, 38737, 38747, 38749, 38767, 38783, 38791, 38803, 38821, 38833, 38839, 38851, 38861, 38867, 38873, 38891, 38903, 38917, 38921, 38923, 38933, 38953, 38959, 38971, 38977, 38993, 39019, 39023, 39041, 39043, 39047, 39079, 39089, 39097, 39103, 39107, 39113, 39119, 39133, 39139, 39157, 39161, 39163, 39181, 39191, 39199, 39209, 39217, 39227, 39229, 39233, 39239, 39241, 39251, 39293, 39301, 39313, 39317, 39323, 39341, 39343, 39359, 39367, 39371, 39373, 39383, 39397, 39409, 39419, 39439, 39443, 39451, 39461, 39499, 39503, 39509, 39511, 39521, 39541, 39551, 39563, 39569, 39581, 39607, 39619, 39623, 39631, 39659, 39667, 39671, 39679, 39703, 39709, 39719, 39727, 39733, 39749, 39761, 39769, 39779, 39791, 39799, 39821, 39827, 39829, 39839, 39841, 39847, 39857, 39863, 39869, 39877, 39883, 39887, 39901, 39929, 39937, 39953, 39971, 39979, 39983, 39989, 40009, 40013, 40031, 40037, 40039, 40063, 40087, 40093, 40099, 40111, 40123, 40127, 40129, 40151, 40153, 40163, 40169, 40177, 40189, 40193, 40213, 40231, 40237, 40241, 40253, 40277, 40283, 40289, 40343, 40351, 40357, 40361, 40387, 40423, 40427, 40429, 40433, 40459, 40471, 40483, 40487, 40493, 40499, 40507, 40519, 40529, 40531, 40543, 40559, 40577, 40583, 40591, 40597, 40609, 40627, 40637, 40639, 40693, 40697, 40699, 40709, 40739, 40751, 40759, 40763, 40771, 40787, 40801, 40813, 40819, 40823, 40829, 40841, 40847, 40849, 40853, 40867, 40879, 40883, 40897, 40903, 40927, 40933, 40939, 40949, 40961, 40973, 40993, 41011, 41017, 41023, 41039, 41047, 41051, 41057, 41077, 41081, 41113, 41117, 41131, 41141, 41143, 41149, 41161, 41177, 41179, 41183, 41189, 41201, 41203, 41213, 41221, 41227, 41231, 41233, 41243, 41257, 41263, 41269, 41281, 41299, 41333, 41341, 41351, 41357, 41381, 41387, 41389, 41399, 41411, 41413, 41443, 41453, 41467, 41479, 41491, 41507, 41513, 41519, 41521, 41539, 41543, 41549, 41579, 41593, 41597, 41603, 41609, 41611, 41617, 41621, 41627, 41641, 41647, 41651, 41659, 41669, 41681, 41687, 41719, 41729, 41737, 41759, 41761, 41771, 41777, 41801, 41809, 41813, 41843, 41849, 41851, 41863, 41879, 41887, 41893, 41897, 41903, 41911, 41927, 41941, 41947, 41953, 41957, 41959, 41969, 41981, 41983, 41999, 42013, 42017, 42019, 42023, 42043, 42061, 42071, 42073, 42083, 42089, 42101, 42131, 42139, 42157, 42169, 42179, 42181, 42187, 42193, 42197, 42209, 42221, 42223, 42227, 42239, 42257, 42281, 42283, 42293, 42299, 42307, 42323, 42331, 42337, 42349, 42359, 42373, 42379, 42391, 42397, 42403, 42407, 42409, 42433, 42437, 42443, 42451, 42457, 42461, 42463, 42467, 42473, 42487, 42491, 42499, 42509, 42533, 42557, 42569, 42571, 42577, 42589, 42611, 42641, 42643, 42649, 42667, 42677, 42683, 42689, 42697, 42701, 42703, 42709, 42719, 42727, 42737, 42743, 42751, 42767, 42773, 42787, 42793, 42797, 42821, 42829, 42839, 42841, 42853, 42859, 42863, 42899, 42901, 42923, 42929, 42937, 42943, 42953, 42961, 42967, 42979, 42989, 43003, 43013, 43019, 43037, 43049, 43051, 43063, 43067, 43093, 43103, 43117, 43133, 43151, 43159, 43177, 43189, 43201, 43207, 43223, 43237, 43261, 43271, 43283, 43291, 43313, 43319, 43321, 43331, 43391, 43397, 43399, 43403, 43411, 43427, 43441, 43451, 43457, 43481, 43487, 43499, 43517, 43541, 43543, 43573, 43577, 43579, 43591, 43597, 43607, 43609, 43613, 43627, 43633, 43649, 43651, 43661, 43669, 43691, 43711, 43717, 43721, 43753, 43759, 43777, 43781, 43783, 43787, 43789, 43793, 43801, 43853, 43867, 43889, 43891, 43913, 43933, 43943, 43951, 43961, 43963, 43969, 43973, 43987, 43991, 43997, 44017, 44021, 44027, 44029, 44041, 44053, 44059, 44071, 44087, 44089, 44101, 44111, 44119, 44123, 44129, 44131, 44159, 44171, 44179, 44189, 44201, 44203, 44207, 44221, 44249, 44257, 44263, 44267, 44269, 44273, 44279, 44281, 44293, 44351, 44357, 44371, 44381, 44383, 44389, 44417, 44449, 44453, 44483, 44491, 44497, 44501, 44507, 44519, 44531, 44533, 44537, 44543, 44549, 44563, 44579, 44587, 44617, 44621, 44623, 44633, 44641, 44647, 44651, 44657, 44683, 44687, 44699, 44701, 44711, 44729, 44741, 44753, 44771, 44773, 44777, 44789, 44797, 44809, 44819, 44839, 44843, 44851, 44867, 44879, 44887, 44893, 44909, 44917, 44927, 44939, 44953, 44959, 44963, 44971, 44983, 44987, 45007, 45013, 45053, 45061, 45077, 45083, 45119, 45121, 45127, 45131, 45137, 45139, 45161, 45179, 45181, 45191, 45197, 45233, 45247, 45259, 45263, 45281, 45289, 45293, 45307, 45317, 45319, 45329, 45337, 45341, 45343, 45361, 45377, 45389, 45403, 45413, 45427, 45433, 45439, 45481, 45491, 45497, 45503, 45523, 45533, 45541, 45553, 45557, 45569, 45587, 45589, 45599, 45613, 45631, 45641, 45659, 45667, 45673, 45677, 45691, 45697, 45707, 45737, 45751, 45757, 45763, 45767, 45779, 45817, 45821, 45823, 45827, 45833, 45841, 45853, 45863, 45869, 45887, 45893, 45943, 45949, 45953, 45959, 45971, 45979, 45989, 46021, 46027, 46049, 46051, 46061, 46073, 46091, 46093, 46099, 46103, 46133, 46141, 46147, 46153, 46171, 46181, 46183, 46187, 46199, 46219, 46229, 46237, 46261, 46271, 46273, 46279, 46301, 46307, 46309, 46327, 46337, 46349, 46351, 46381, 46399, 46411, 46439, 46441, 46447, 46451, 46457, 46471, 46477, 46489, 46499, 46507, 46511, 46523, 46549, 46559, 46567, 46573, 46589, 46591, 46601, 46619, 46633, 46639, 46643, 46649, 46663, 46679, 46681, 46687, 46691, 46703, 46723, 46727, 46747, 46751, 46757, 46769, 46771, 46807, 46811, 46817, 46819, 46829, 46831, 46853, 46861, 46867, 46877, 46889, 46901, 46919, 46933, 46957, 46993, 46997, 47017, 47041, 47051, 47057, 47059, 47087, 47093, 47111, 47119, 47123, 47129, 47137, 47143, 47147, 47149, 47161, 47189, 47207, 47221, 47237, 47251, 47269, 47279, 47287, 47293, 47297, 47303, 47309, 47317, 47339, 47351, 47353, 47363, 47381, 47387, 47389, 47407, 47417, 47419, 47431, 47441, 47459, 47491, 47497, 47501, 47507, 47513, 47521, 47527, 47533, 47543, 47563, 47569, 47581, 47591, 47599, 47609, 47623, 47629, 47639, 47653, 47657, 47659, 47681, 47699, 47701, 47711, 47713, 47717, 47737, 47741, 47743, 47777, 47779, 47791, 47797, 47807, 47809, 47819, 47837, 47843, 47857, 47869, 47881, 47903, 47911, 47917, 47933, 47939, 47947, 47951, 47963, 47969, 47977, 47981, 48017, 48023, 48029, 48049, 48073, 48079, 48091, 48109, 48119, 48121, 48131, 48157, 48163, 48179, 48187, 48193, 48197, 48221, 48239, 48247, 48259, 48271, 48281, 48299, 48311, 48313, 48337, 48341, 48353, 48371, 48383, 48397, 48407, 48409, 48413, 48437, 48449, 48463, 48473, 48479, 48481, 48487, 48491, 48497, 48523, 48527, 48533, 48539, 48541, 48563, 48571, 48589, 48593, 48611, 48619, 48623, 48647, 48649, 48661, 48673, 48677, 48679, 48731, 48733, 48751, 48757, 48761, 48767, 48779, 48781, 48787, 48799, 48809, 48817, 48821, 48823, 48847, 48857, 48859, 48869, 48871, 48883, 48889, 48907, 48947, 48953, 48973, 48989, 48991, 49003, 49009, 49019, 49031, 49033, 49037, 49043, 49057, 49069, 49081, 49103, 49109, 49117, 49121, 49123, 49139, 49157, 49169, 49171, 49177, 49193, 49199, 49201, 49207, 49211, 49223, 49253, 49261, 49277, 49279, 49297, 49307, 49331, 49333, 49339, 49363, 49367, 49369, 49391, 49393, 49409, 49411, 49417, 49429, 49433, 49451, 49459, 49463, 49477, 49481, 49499, 49523, 49529, 49531, 49537, 49547, 49549, 49559, 49597, 49603, 49613, 49627, 49633, 49639, 49663, 49667, 49669, 49681, 49697, 49711, 49727, 49739, 49741, 49747, 49757, 49783, 49787, 49789, 49801, 49807, 49811, 49823, 49831, 49843, 49853, 49871, 49877, 49891, 49919, 49921, 49927, 49937, 49939, 49943, 49957, 49991, 49993, 49999, 50021, 50023, 50033, 50047, 50051, 50053, 50069, 50077, 50087, 50093, 50101, 50111, 50119, 50123, 50129, 50131, 50147, 50153, 50159, 50177, 50207, 50221, 50227, 50231, 50261, 50263, 50273, 50287, 50291, 50311, 50321, 50329, 50333, 50341, 50359, 50363, 50377, 50383, 50387, 50411, 50417, 50423, 50441, 50459, 50461, 50497, 50503, 50513, 50527, 50539, 50543, 50549, 50551, 50581, 50587, 50591, 50593, 50599, 50627, 50647, 50651, 50671, 50683, 50707, 50723, 50741, 50753, 50767, 50773, 50777, 50789, 50821, 50833, 50839, 50849, 50857, 50867, 50873, 50891, 50893, 50909, 50923, 50929, 50951, 50957, 50969, 50971, 50989, 50993, 51001, 51031, 51043, 51047, 51059, 51061, 51071, 51109, 51131, 51133, 51137, 51151, 51157, 51169, 51193, 51197, 51199, 51203, 51217, 51229, 51239, 51241, 51257, 51263, 51283, 51287, 51307, 51329, 51341, 51343, 51347, 51349, 51361, 51383, 51407, 51413, 51419, 51421, 51427, 51431, 51437, 51439, 51449, 51461, 51473, 51479, 51481, 51487, 51503, 51511, 51517, 51521, 51539, 51551, 51563, 51577, 51581, 51593, 51599, 51607, 51613, 51631, 51637, 51647, 51659, 51673, 51679, 51683, 51691, 51713, 51719, 51721, 51749, 51767, 51769, 51787, 51797, 51803, 51817, 51827, 51829, 51839, 51853, 51859, 51869, 51871, 51893, 51899, 51907, 51913, 51929, 51941, 51949, 51971, 51973, 51977, 51991, 52009, 52021, 52027, 52051, 52057, 52067, 52069, 52081, 52103, 52121, 52127, 52147, 52153, 52163, 52177, 52181, 52183, 52189, 52201, 52223, 52237, 52249, 52253, 52259, 52267, 52289, 52291, 52301, 52313, 52321, 52361, 52363, 52369, 52379, 52387, 52391, 52433, 52453, 52457, 52489, 52501, 52511, 52517, 52529, 52541, 52543, 52553, 52561, 52567, 52571, 52579, 52583, 52609, 52627, 52631, 52639, 52667, 52673, 52691, 52697, 52709, 52711, 52721, 52727, 52733, 52747, 52757, 52769, 52783, 52807, 52813, 52817, 52837, 52859, 52861, 52879, 52883, 52889, 52901, 52903, 52919, 52937, 52951, 52957, 52963, 52967, 52973, 52981, 52999, 53003, 53017, 53047, 53051, 53069, 53077, 53087, 53089, 53093, 53101, 53113, 53117, 53129, 53147, 53149, 53161, 53171, 53173, 53189, 53197, 53201, 53231, 53233, 53239, 53267, 53269, 53279, 53281, 53299, 53309, 53323, 53327, 53353, 53359, 53377, 53381, 53401, 53407, 53411, 53419, 53437, 53441, 53453, 53479, 53503, 53507, 53527, 53549, 53551, 53569, 53591, 53593, 53597, 53609, 53611, 53617, 53623, 53629, 53633, 53639, 53653, 53657, 53681, 53693, 53699, 53717, 53719, 53731, 53759, 53773, 53777, 53783, 53791, 53813, 53819, 53831, 53849, 53857, 53861, 53881, 53887, 53891, 53897, 53899, 53917, 53923, 53927, 53939, 53951, 53959, 53987, 53993, 54001, 54011, 54013, 54037, 54049, 54059, 54083, 54091, 54101, 54121, 54133, 54139, 54151, 54163, 54167, 54181, 54193, 54217, 54251, 54269, 54277, 54287, 54293, 54311, 54319, 54323, 54331, 54347, 54361, 54367, 54371, 54377, 54401, 54403, 54409, 54413, 54419, 54421, 54437, 54443, 54449, 54469, 54493, 54497, 54499, 54503, 54517, 54521, 54539, 54541, 54547, 54559, 54563, 54577, 54581, 54583, 54601, 54617, 54623, 54629, 54631, 54647, 54667, 54673, 54679, 54709, 54713, 54721, 54727, 54751, 54767, 54773, 54779, 54787, 54799, 54829, 54833, 54851, 54869, 54877, 54881, 54907, 54917, 54919, 54941, 54949, 54959, 54973, 54979, 54983, 55001, 55009, 55021, 55049, 55051, 55057, 55061, 55073, 55079, 55103, 55109, 55117, 55127, 55147, 55163, 55171, 55201, 55207, 55213, 55217, 55219, 55229, 55243, 55249, 55259, 55291, 55313, 55331, 55333, 55337, 55339, 55343, 55351, 55373, 55381, 55399, 55411, 55439, 55441, 55457, 55469, 55487, 55501, 55511, 55529, 55541, 55547, 55579, 55589, 55603, 55609, 55619, 55621, 55631, 55633, 55639, 55661, 55663, 55667, 55673, 55681, 55691, 55697, 55711, 55717, 55721, 55733, 55763, 55787, 55793, 55799, 55807, 55813, 55817, 55819, 55823, 55829, 55837, 55843, 55849, 55871, 55889, 55897, 55901, 55903, 55921, 55927, 55931, 55933, 55949, 55967, 55987, 55997, 56003, 56009, 56039, 56041, 56053, 56081, 56087, 56093, 56099, 56101, 56113, 56123, 56131, 56149, 56167, 56171, 56179, 56197, 56207, 56209, 56237, 56239, 56249, 56263, 56267, 56269, 56299, 56311, 56333, 56359, 56369, 56377, 56383, 56393, 56401, 56417, 56431, 56437, 56443, 56453, 56467, 56473, 56477, 56479, 56489, 56501, 56503, 56509, 56519, 56527, 56531, 56533, 56543, 56569, 56591, 56597, 56599, 56611, 56629, 56633, 56659, 56663, 56671, 56681, 56687, 56701, 56711, 56713, 56731, 56737, 56747, 56767, 56773, 56779, 56783, 56807, 56809, 56813, 56821, 56827, 56843, 56857, 56873, 56891, 56893, 56897, 56909, 56911, 56921, 56923, 56929, 56941, 56951, 56957, 56963, 56983, 56989, 56993, 56999, 57037, 57041, 57047, 57059, 57073, 57077, 57089, 57097, 57107, 57119, 57131, 57139, 57143, 57149, 57163, 57173, 57179, 57191, 57193, 57203, 57221, 57223, 57241, 57251, 57259, 57269, 57271, 57283, 57287, 57301, 57329, 57331, 57347, 57349, 57367, 57373, 57383, 57389, 57397, 57413, 57427, 57457, 57467, 57487, 57493, 57503, 57527, 57529, 57557, 57559, 57571, 57587, 57593, 57601, 57637, 57641, 57649, 57653, 57667, 57679, 57689, 57697, 57709, 57713, 57719, 57727, 57731, 57737, 57751, 57773, 57781, 57787, 57791, 57793, 57803, 57809, 57829, 57839, 57847, 57853, 57859, 57881, 57899, 57901, 57917, 57923, 57943, 57947, 57973, 57977, 57991, 58013, 58027, 58031, 58043, 58049, 58057, 58061, 58067, 58073, 58099, 58109, 58111, 58129, 58147, 58151, 58153, 58169, 58171, 58189, 58193, 58199, 58207, 58211, 58217, 58229, 58231, 58237, 58243, 58271, 58309, 58313, 58321, 58337, 58363, 58367, 58369, 58379, 58391, 58393, 58403, 58411, 58417, 58427, 58439, 58441, 58451, 58453, 58477, 58481, 58511, 58537, 58543, 58549, 58567, 58573, 58579, 58601, 58603, 58613, 58631, 58657, 58661, 58679, 58687, 58693, 58699, 58711, 58727, 58733, 58741, 58757, 58763, 58771, 58787, 58789, 58831, 58889, 58897, 58901, 58907, 58909, 58913, 58921, 58937, 58943, 58963, 58967, 58979, 58991, 58997, 59009, 59011, 59021, 59023, 59029, 59051, 59053, 59063, 59069, 59077, 59083, 59093, 59107, 59113, 59119, 59123, 59141, 59149, 59159, 59167, 59183, 59197, 59207, 59209, 59219, 59221, 59233, 59239, 59243, 59263, 59273, 59281, 59333, 59341, 59351, 59357, 59359, 59369, 59377, 59387, 59393, 59399, 59407, 59417, 59419, 59441, 59443, 59447, 59453, 59467, 59471, 59473, 59497, 59509, 59513, 59539, 59557, 59561, 59567, 59581, 59611, 59617, 59621, 59627, 59629, 59651, 59659, 59663, 59669, 59671, 59693, 59699, 59707, 59723, 59729, 59743, 59747, 59753, 59771, 59779, 59791, 59797, 59809, 59833, 59863, 59879, 59887, 59921, 59929, 59951, 59957, 59971, 59981, 59999}; int num_of_element = 6057; int *arr, n; typedef struct { int first; int second; } pa; vector<pa> pairs; void generate(vector<int> numbers) { int siz = numbers.size(); int i; if (numbers.size() % 2 != 0) { numbers.erase(numbers.begin() + 1); } for (i = 0; (i + 1) < siz;) { arr[numbers[i]] = 1; arr[numbers[i + 1]] = 1; pa t; t.first = numbers[i]; t.second = numbers[i + 1]; pairs.push_back(t); i = i + 2; } numbers.clear(); } void generatePairs() { vector<int> numbers; for (int pos = 1; pos <= 6056; pos++) { int prime = primes[pos]; if ((2 * prime) > n) return; for (int i = 1; (i * prime) <= n; i++) { if (arr[i * prime] == 0) numbers.push_back(i * prime); } generate(numbers); numbers.clear(); } } void last() { vector<int> numbers; for (int i = 2; i <= n; i++) { if ((i % 2 == 0) && (arr[i] == 0)) { numbers.push_back(i); } } int siz = numbers.size(); int i; for (i = 0; (i + 1) < siz;) { arr[numbers[i]] = 1; arr[numbers[i + 1]] = 1; pa t; t.first = numbers[i]; t.second = numbers[i + 1]; pairs.push_back(t); i = i + 2; } numbers.clear(); } int main() { scanf( %d , &n); arr = (int *)calloc(n + 10, sizeof(int)); if (n <= 3) { printf( 0 ); return 0; } arr = (int *)calloc(n + 10, sizeof(int)); generatePairs(); last(); printf( %d n , pairs.size()); int siz = pairs.size(); for (int i = 0; i < siz; i++) { printf( %d %d n , pairs[i].first, pairs[i].second); } } |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int pa[maxn], a[maxn], b[maxn]; struct Edge { int u, v, w; friend bool operator<(const Edge& a, const Edge& b) { return a.w > b.w; } } e[maxn]; void init(int n) { for (int i = 1; i <= n; i++) pa[i] = i, b[i] = 1; } int find(int x) { if (x == pa[x]) return x; return pa[x] = find(pa[x]); } int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); init(n); for (int i = 1; i <= m; i++) { scanf( %d%d , &e[i].u, &e[i].v); e[i].w = min(a[e[i].u], a[e[i].v]); } sort(e + 1, e + m + 1); double sum = 0; for (int i = 1; i <= m; i++) { int fu = find(e[i].u); int fv = find(e[i].v); if (fu != fv) { sum += 1.0 * e[i].w * b[fu] * b[fv]; pa[fv] = fu; b[fu] += b[fv]; b[fv] = 1; } } printf( %.6f n , sum * 2 / (1.0 * n * (n - 1))); return 0; } |
#include <bits/stdc++.h> using namespace std; long long M = 1e9 + 7; long long power(long long a, long long p) { if (p == 0) return 1; long long ans = power(a, p / 2); ans = (ans * ans) % M; if (p % 2) ans = (ans * a) % M; return ans; } int nC2(int n) { return (n * (n - 1)) / 2; } int fact(int n) { if (n == 0 || n == 1) { return 1; } else { return n * fact(n - 1); } } int countOne(int n) { return __builtin_popcount(n); } int checkParity(int n) { return __builtin_parity(n); } int digitCount(int n) { return floor(log10(n)) + 1; } int log2(int x) { int res = 0; while (x >>= 1) res++; return res; } int isPowerof2(int x) { return (x && !(x & x - 1)); } bool is_prime(int n) { if (n == 1) { return false; } int i = 2; while (i * i <= n) { if (n % i == 0) { return false; } i += 1; } return true; } int main() { int test, n, m, x, y, counter = 0, sum = 0, ans = 0, res = 0, rem = 0; bool flag = true; bool check = true; string s; cin >> n; for (int i = 0; i < n; i++) { if (i % 2 == 0 && flag == true) { cout << a ; check = true; } else if (i % 2 != 0 && check == true) { cout << b ; flag = false; } else if (i % 2 == 0 && flag == false) { cout << b ; check = false; } else if (i % 2 != 0 && check == false) { cout << a ; flag = true; } } cout << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; void test_case(); long long power(int n, int p); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { test_case(); } return 0; } void test_case() { int n, x; cin >> n >> x; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr.begin(), arr.end()); int teams = 0; int cnt = 1; for (int ptr = n - 1; ptr >= 0; ptr--) { if (arr[ptr] * cnt >= x) { teams++; cnt = 1; } else cnt++; } cout << teams << n ; } long long power(int n, int p) { long long ans = 1; if (p == 0) return 1; long long temp = power(n, p / 2); if (p % 2 == 0) ans = (temp * temp) % 1000000007; else { ans = (ans * n) % 1000000007; ans *= (temp * temp) % 1000000007; } return ans; } |
#include <bits/stdc++.h> using namespace std; struct rec { int l, r; }; rec f[2222][2223]; bool can[2222][2223]; int n, m, k, x, y, xx, yy; void del(int x, int y) { can[x][y] = false; for (int i = 1; i <= m; i++) { f[x][i].l = f[x][i - 1].l; if (can[x][i - 1]) f[x][i].l = i - 1; } for (int i = m; i >= 1; i--) { f[x][i].r = f[x][i + 1].r; if (can[x][i + 1]) f[x][i].r = i + 1; } return; } int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { f[i][j].l = j - 1; f[i][j].r = j + 1; can[i][j] = true; } for (int i = 1; i <= n; i++) { f[i][m + 1].r = m + m; } while (k--) { int ans = n + m + n + m; scanf( %d%d , &x, &y); for (int i = 1; i <= n; i++) { int u = abs(i - x); if (can[i][y]) { if (ans > u) { ans = u; xx = i; yy = y; } } else { if (f[i][y].l > 0 && ans > u + abs(f[i][y].l - y)) { ans = u + abs(f[i][y].l - y); xx = i; yy = f[i][y].l; } if (f[i][y].r < m + 1 && ans > u + abs(f[i][y].r - y)) { ans = u + abs(f[i][y].r - y); xx = i; yy = f[i][y].r; } } if (ans == 0) break; } printf( %d %d n , xx, yy); del(xx, yy); } return 0; } |
#include <bits/stdc++.h> using namespace std; int a[100007], b[100007], c[100007]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i < n + 1; i++) cin >> a[i]; for (int i = 1; i < n + 1; i++) { if (a[i] > a[i - 1]) b[i] = b[i - 1] + 1; else b[i] = 1; } c[n] = 1; a[n + 1] = INT_MAX; for (int i = n - 1; i > 0; i--) { if (a[i + 1] > a[i]) c[i] = c[i + 1] + 1; else c[i] = 1; } int mx = 0; for (int i = 1; i < n + 1; i++) { if (b[i] + 1 <= n) mx = max(mx, b[i] + 1); else mx = max(mx, b[i]); if (a[i - 1] + 1 < a[i + 1]) mx = max(mx, b[i - 1] + c[i + 1] + 1); } cout << mx << endl; } |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { long long n, k, d1, d2; cin >> n >> k >> d1 >> d2; if (n % 3) { cout << no n ; continue; } int flag = 0; long long x1, x2, x3; if (2 * d1 + d2 + k <= n && (2 * d1 + d2 + k) % 3 == 0) { x1 = (2 * d1 + d2 + k) / 3; x3 = x1 - (d1 + d2); x2 = x1 - d1; if (x1 >= 0 && x2 >= 0 && x3 >= 0 && x1 <= n / 3 && x2 <= n / 3 && x3 <= n / 3) flag = 1; } if (2 * d1 - d2 + k >= 0 && 2 * d1 - d2 + k <= n && (2 * d1 - d2 + k) % 3 == 0) { x1 = (2 * d1 - d2 + k) / 3; x3 = x1 - (d1 - d2); x2 = x1 - d1; if (x1 >= 0 && x2 >= 0 && x3 >= 0 && x1 <= n / 3 && x2 <= n / 3 && x3 <= n / 3) flag = 1; } if (-2 * d1 + d2 + k >= 0 && -2 * d1 + d2 + k <= n && (-2 * d1 + d2 + k) % 3 == 0) { x1 = (-2 * d1 + d2 + k) / 3; x3 = x1 - (-1 * d1 + d2); x2 = x1 + d1; if (x1 >= 0 && x2 >= 0 && x3 >= 0 && x1 <= n / 3 && x2 <= n / 3 && x3 <= n / 3) flag = 1; } if (-2 * d1 - d2 + k >= 0 && -2 * d1 - d2 + k <= n && (-2 * d1 - d2 + k) % 3 == 0) { x1 = (-2 * d1 - d2 + k) / 3; x3 = x1 - (-1 * d1 - d2); x2 = x1 + d1; if (x1 >= 0 && x2 >= 0 && x3 >= 0 && x1 <= n / 3 && x2 <= n / 3 && x3 <= n / 3) flag = 1; } if (flag) cout << yes n ; else cout << no n ; } return 0; } |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int N = 132007; int n, a, b; int rev[N], fac[N], finv[N], f[N], g[N], h[N]; inline int qpow(int x, int k, int r = 1) { for (; k; k >>= 1, x = 1ll * x * x % mod) if (k & 1) r = 1ll * r * x % mod; return r; } inline void ntt(int *a, int len, int opt) { for (int i = 0; i < len; ++i) if (i < rev[i]) swap(a[i], a[rev[i]]); for (int i = 1; i < len; i <<= 1) { int wn = qpow(3, (mod - 1) / (i << 1)); for (int j = 0; j < len; j += i << 1) { int w = 1; for (int k = 0; k < i; ++k, w = 1ll * w * wn % mod) { int x = a[j + k], y = 1ll * a[j + k + i] * w % mod; a[j + k] = (x + y) % mod; a[j + k + i] = (x - y + mod) % mod; } } } if (~opt) return; reverse(a + 1, a + len); const int inv = qpow(len, mod - 2); for (int i = 0; i < len; ++i) a[i] = 1ll * a[i] * inv % mod; } void solve(int n) { if (!n) return g[1] = 1, void(); int t = n - 1 >> 1, mid = n + 1 >> 1, len = 1, bit = 0; for (; len <= n + 2; len <<= 1, ++bit) ; solve(t); for (int i = 0; i < len; ++i) rev[i] = rev[i >> 1] >> 1 | (i & 1) << bit - 1; for (int i = f[0] = 1; i <= mid; ++i) f[i] = 1ll * f[i - 1] * mid % mod; for (int i = 0; i <= mid; ++i) f[i] = 1ll * f[i] * finv[i] % mod, h[i] = 1ll * g[i] * fac[i] % mod; for (int i = mid + 1; i < len; ++i) f[i] = h[i] = 0; reverse(f, f + mid + 2); ntt(f, len, 1); ntt(h, len, 1); for (int i = 0; i < len; ++i) h[i] = 1ll * f[i] * h[i] % mod; ntt(h, len, -1); for (int i = 0; i <= mid; ++i) h[i] = 1ll * h[i + mid + 1] * finv[i] % mod; for (int i = mid + 1; i < len; ++i) h[i] = 0; ntt(g, len, 1); ntt(h, len, 1); for (int i = 0; i < len; ++i) g[i] = 1ll * g[i] * h[i] % mod; ntt(g, len, -1); if (n & 1) return; for (int i = mid + mid + 1; i < len; ++i) g[i] = 0; for (int i = len - 1; i; --i) g[i] = (g[i - 1] + 1ll * g[i] * n) % mod; } inline int C(int n, int m) { return 1ll * fac[n] * finv[m] % mod * finv[n - m] % mod; } int main() { scanf( %d%d%d , &n, &a, &b); long long ans = 0; if (a == b && a == 1) return printf( %d n , n == 1) & 0; if (a + b > n + 1 || !a || !b) return printf( %d n , 0) & 0; for (int i = fac[0] = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod; finv[n] = qpow(fac[n], mod - 2); for (int i = n; i; --i) finv[i - 1] = 1ll * finv[i] * i % mod; solve(n - 2); return printf( %lld n , 1ll * g[a + b - 2] * C(a + b - 2, a - 1) % mod) & 0; } |
#include <bits/stdc++.h> using namespace std; int n, x; vector<int> v; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d , &x); int a = lower_bound(v.begin(), v.end(), x) - v.begin(); if (a == v.size()) v.push_back(x); else v[a] = x; } printf( %d n , v.size()); return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int n; int b; cin >> n >> b; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int mini[n]; mini[0] = a[0]; for (int i = 1; i < n; i++) { mini[i] = min(mini[i - 1], a[i]); } int maxi = b; for (int i = 1; i < n; i++) { maxi = max(maxi, b % mini[i] + (b / mini[i]) * a[i]); } cout << maxi; return 0; } |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; int n, m, x, y, w, cnt, col[maxn], dis[maxn], vis[maxn], d[maxn], head[maxn]; struct node { int nxt, to, val; } e[maxn << 1]; void add(int x, int y, int w) { e[++cnt].to = y; e[cnt].nxt = head[x]; head[x] = cnt; e[cnt].val = w; } queue<int> q; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; ++i) { scanf( %d%d%d , &x, &y, &w); add(y, x, w); } if (n == 1) { cout << 0 << endl << 0 ; return 0; } memset(col, -1, sizeof(col)); q.push(n); vis[n] = 0; while (q.size()) { int x = q.front(); q.pop(); if (x == 1) { break; } for (int i = head[x]; i; i = e[i].nxt) { int v = e[i].to; if (vis[v]) continue; if (col[v] == -1 || col[v] == 1 - e[i].val) { col[v] = 1 - e[i].val; } else { q.push(v); d[v] = d[x] + 1; vis[v] = 1; } } } if (d[1]) { cout << d[1] << endl; } else { cout << -1 << endl; } for (int i = 1; i <= n; ++i) { if (col[i] == -1) { cout << 0 ; } else { cout << col[i]; } } return 0; } |
#include <bits/stdc++.h> using namespace std; long long int fpow(long long int n, long long int k, long long int p = 1000000007) { long long int r = 1; n = n % p; while (k > 0) { if (k & 1) { r = (r * n) % p; } k = k >> 1; n = (n * n) % p; } return r; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n; cin >> n; if (n <= 9) { cout << 1 << n ; cout << n; } else { long long int ans = -1; for (long long int i = 1; i <= 9; i++) { if (n % i == 0) ans = i; } cout << n / ans << n ; for (long long int i = 1; i <= n / ans; i++) cout << ans << ; } return 0; } |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 51, MOD = 1e9 + 7; struct Matrix { int num[6][6]; Matrix() { memset(num, 0, sizeof(num)); } inline int* operator[](const int& x) { return num[x]; } inline const int* operator[](const int& x) const { return num[x]; } }; Matrix mat, mat2, x, x2; int f1, f2, f3, c, res; long long int n; inline long long int read() { register long long int num = 0, neg = 1; register char ch = getchar(); while (!isdigit(ch) && ch != - ) { ch = getchar(); } if (ch == - ) { neg = -1; ch = getchar(); } while (isdigit(ch)) { num = (num << 3) + (num << 1) + (ch - 0 ); ch = getchar(); } return num * neg; } inline int qpow(int base, int exponent) { int res = 1; while (exponent) { if (exponent & 1) { res = (long long int)res * base % MOD; } base = (long long int)base * base % MOD, exponent >>= 1; } return res; } inline Matrix operator*(Matrix x, Matrix y) { Matrix res; for (register int i = 1; i <= 5; i++) { for (register int j = 1; j <= 5; j++) { for (register int k = 1; k <= 5; k++) { res[i][j] = (res[i][j] + (long long int)x[i][k] * y[k][j] % (MOD - 1)) % (MOD - 1); } } } return res; } inline Matrix qpow(Matrix base, long long int exponent) { Matrix res; for (register int i = 1; i <= 5; i++) { res[i][i] = 1; } while (exponent) { if (exponent & 1) { res = res * base; } base = base * base, exponent >>= 1; } return res; } int main() { n = read(), f1 = read(), f2 = read(), f3 = read(), c = read(), res = 1; mat[1][1] = mat[2][1] = mat[3][1] = mat[1][2] = mat[2][3] = mat[4][4] = mat[5][4] = 1; mat[5][5] = x[1][5] = mat2[1][1] = 1, mat[4][1] = 2, mat[5][1] = MOD - 5, x[1][4] = 3; mat2[2][1] = mat2[3][1] = mat2[1][2] = mat2[2][3] = x2[1][3] = 1; res = qpow(c, (x * qpow(mat, n - 3))[1][1]); res = (long long int)res * qpow(f1, (x2 * qpow(mat2, n - 3))[1][1]) % MOD, x2[1][3] = 0, x2[1][2] = 1; res = (long long int)res * qpow(f2, (x2 * qpow(mat2, n - 3))[1][1]) % MOD, x2[1][2] = 0, x2[1][1] = 1; res = (long long int)res * qpow(f3, (x2 * qpow(mat2, n - 3))[1][1]) % MOD, printf( %d n , res); } |
#include <bits/stdc++.h> using namespace std; int main() { long long int t, i, n, ans = 0, k = 0, mx; cin >> n; long long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } ans = a[0] / 3; k = a[0] % 3; for (i = 1; i < n; i++) { mx = min(k, a[i] / 2); ans += mx; k -= mx; a[i] -= 2 * mx; ans += a[i] / 3; k += a[i] % 3; } cout << ans; return 0; } |
#include <bits/stdc++.h> using namespace std; void data() {} const int N = 1e6 + 100; const long long mod = 998244353; const long long mod2 = 1e9 + 7; int main() { data(); ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long k; cin >> k; string second; cin >> second; vector<long long> pos; long long ans = 0; if (k == 0) { long long ans = 0; long long cur = 0; for (long long i = 0; i < second.size(); i++) { if (second[i] == 0 ) { cur++; } else { ans += cur * (cur + 1) / 2; cur = 0; } } ans += cur * (cur + 1) / 2; cout << ans << n ; return 0; } pos.push_back(0); for (long long i = 0; i < second.size(); i++) { if (second[i] == 0 ) { continue; } pos.push_back(i + 1); } pos.push_back(second.size() + 1); long long cur = 0; for (long long i = 0; i < second.size(); i++) { if (second[i] == 0 ) { continue; } cur++; if (cur >= k) { ans += (pos[cur - k + 1] - pos[cur - k]) * (pos[cur + 1] - pos[cur]); } } cout << ans; } |
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int INF = (1 << 30) - 1; long long Gcd(long long a, long long b) { while (a > 0 && b > 0) { if (a > b) a %= b; else b %= a; } return a + b; } long long x, y; int main() { cin >> x >> y; if (Gcd(x, y) != 1) { printf( Impossible n ); return 0; } vector<char> ans; while (x > 0 && y > 0) { if (x > y) { long long k = x / y; x %= y; if (x == 0) k--; vector<char> g; while (k) { g.push_back(k % 10 + 0 ); k /= 10; } for (int i = g.size() - 1; i >= 0; --i) ans.push_back(g[i]); ans.push_back( A ); } else { long long k = y / x; y %= x; if (y == 0) k--; vector<char> g; while (k) { g.push_back(k % 10 + 0 ); k /= 10; } for (int i = g.size() - 1; i >= 0; --i) ans.push_back(g[i]); ans.push_back( B ); } } for (int i = 0; i < ans.size(); ++i) printf( %c , ans[i]); puts( ); return 0; } |
#include <bits/stdc++.h> using namespace std; long long read() { char ch; for (ch = getchar(); ch < 0 || ch > 9 ; ch = getchar()) ; long long x = ch - 0 ; for (ch = getchar(); ch >= 0 && ch <= 9 ; ch = getchar()) x = x * 10 + ch - 0 ; return x; } const int N = 2 * 1e5 + 5; struct node { long long j, k; node(long long _j = 0, long long _k = 0) { j = _j; k = _k; } friend bool operator<(node x, node y) { return x.j > y.j || x.j == y.j && x.k > y.k; } }; set<node> f; long long a[N]; int main() { int n = read(); for (int i = 1; i <= n; i++) a[i] = read(); f.insert(node(a[1] - 1, 0)); for (int i = 1; i <= n - 1; i++) { long long m = a[i + 1], Mx = 0; bool pty = 0; while (1) { set<node>::iterator pos = f.begin(); long long j = (*pos).j, k = (*pos).k; if (j < m) break; pty = 1; Mx = max(Mx, k + (long long)i * ((j + 1) / m * m - m)); f.insert(node(j % m, k + (long long)i * (j - j % m))); f.erase(pos); } if (pty) f.insert(node(m - 1, Mx)); } long long ans = 0; for (set<node>::iterator pos = f.begin(); pos != f.end(); pos++) { long long j = (*pos).j, k = (*pos).k; ans = max(ans, k + (long long)j * n); } printf( %I64d n , ans); } |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10, inf = 1e9 + 10, P = 53, MOD = 1e9 + 7; vector<int> a, b; int main() { ios_base::sync_with_stdio(false); long long n, x, t = 0; long long ans = 1; cin >> n >> x; for (int i = 0; i < 42; i++) if ((1ll << i) & x) { ans *= 2; n -= (1ll << i); t++; } if (n < 0 || (n == 0 && t == 1)) { cout << 0; return 0; } if (n == 0) { cout << ans - 2; return 0; } for (int i = 0; i < 42; i++) if (!((1ll << i) & x)) if ((1ll << (i + 1)) & n) n -= (1ll << (i + 1)); if (n == 0) cout << ans; else cout << 0; return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 110000; const int M = 1100000; const long long mod = 1e9 + 7; const int inf = (int)1e9; const double eps = 1e-9; long long n, k, a[N]; long long f[N], inv[N], fac[N], sinv[N], g[N]; long long pw[N]; long long pow_mod(long long a, long long e) { long long res = 1; for (; e; a = a * a % mod, e >>= 1) if (e & 1) res = res * a % mod; return res; } long long num; long long C(int n, int m) { long long res = fac[n] * sinv[m] % mod; res = res * sinv[n - m] % mod; return res; } map<int, int> S; long long cal(int i) { if (g[i] != -1) return g[i]; long long fm = pow_mod(pow_mod(k, num), mod - 2); long long res = 0; for (int j = 0; j <= num; j++) { long long tmp = C(num, j) * f[i + j] % mod; res = (res + tmp * pw[num - j]) % mod; } res = res * fm % mod; g[i] = res; return g[i]; } int main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == -1) num++; else S[a[i]]++; } inv[0] = inv[1] = 1; for (int i = 2; i <= n; i++) inv[i] = pow_mod(i, mod - 2); fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * (long long)i) % mod; sinv[0] = 1; for (int i = 1; i <= n; i++) sinv[i] = (sinv[i - 1] * inv[i]) % mod; f[0] = 0, f[1] = 0; for (int i = 2; i <= n; i++) { long long a = i - 1; long long tmp1 = (k - 1) * a + n - a; tmp1 %= mod; tmp1 = tmp1 * f[i - 1] % mod; long long tmp2 = (k - 1) * a % mod; tmp2 %= mod; tmp2 = tmp2 * f[i - 2] % mod; long long tmp3 = a * k % mod; long long tmp = (tmp1 - tmp2 - tmp3 + mod + mod) % mod; f[i] = tmp * inv[n - a] % mod; } pw[0] = 1; for (int i = 1; i <= n; i++) pw[i] = (pw[i - 1] * (k - 1)) % mod; memset(g, -1, sizeof(g)); long long ans = 0; for (auto p : S) { int val = p.second; ans = (ans + cal(val)) % mod; } ans = (ans + (k - S.size()) * cal(0)) % mod; cout << (ans - f[n] + mod) % mod << n ; return 0; } |
#include <bits/stdc++.h> int main() { int ara[5001], i, n, mx = 0, j, ans[5001] = {0}, col[5001] = {0}, eq, k; scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &ara[i]); for (i = 1; i <= n; i++) { for (k = 1; k <= n; k++) col[k] = 0; mx = 0, eq = 0; for (j = i; j <= n; j++) { col[ara[j]]++; if (col[ara[j]] > mx || (col[ara[j]] == mx && ara[j] < eq)) { mx = col[ara[j]]; eq = ara[j]; } ans[eq]++; } } for (i = 1; i <= n; i++) printf( %d , ans[i]); } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; vector<vector<int>> pr(n); vector<vector<int>> nx(n); vector<int> a(m); long long tot = 0; for (int i = 0; i < m; i++) { cin >> a[i]; a[i]--; if (i) { tot += labs(a[i] - a[i - 1]); pr[a[i]].push_back(a[i - 1]); nx[a[i - 1]].push_back(a[i]); } else { pr[a[i]].push_back(a[i]); } } nx[a[m - 1]].push_back(a[m - 1]); long long res = tot; for (int x = 0; x < n; x++) { if (!pr[x].size()) continue; long long was = 0; for (int i = 0; i < pr[x].size(); i++) was += labs(x - pr[x][i]) + labs(x - nx[x][i]); vector<int> v; for (int i = 0; i < pr[x].size(); i++) { if (pr[x][i] != x) v.push_back(pr[x][i]); if (nx[x][i] != x) v.push_back(nx[x][i]); } sort(v.rbegin(), v.rend()); long long now = 0; for (int i = 0; i < v.size(); i++) now += v[0] - v[i]; long long best = now; for (int i = 1; i < v.size(); i++) { now += i * (v[i - 1] - v[i]); now -= ((int)v.size() - i) * (v[i - 1] - v[i]); best = min(best, now); } res = min(res, tot - was + best); } cout << res; return 0; } |
#include <bits/stdc++.h> using namespace std; template <class X, class Y> bool minimize(X &x, const Y &y) { X eps = 1e-9; if (x > y + eps) { x = y; return true; } else return false; } template <class X, class Y> bool maximize(X &x, const Y &y) { X eps = 1e-9; if (x + eps < y) { x = y; return true; } else return false; } template <class T> T Abs(const T &x) { return (x < 0 ? -x : x); } const int MOD = (int)1e9 + 7; int numRow, numCol; char board[2020][2020]; int range[2020][2020][2], limit[2020][2020][2]; int numWay[2020][2020][2], sumRow[2020][2020][2], sumCol[2020][2020][2]; void init(void) { scanf( %d%d , &numRow, &numCol); for (int i = (1), _b = (numRow); i <= _b; i++) scanf( %s , board[i] + 1); if (board[1][1] == R || board[numRow][numCol] == R ) { cout << 0 << endl; exit(EXIT_SUCCESS); } if (numRow == 1 && numCol == 1) { cout << 1 << endl; exit(EXIT_SUCCESS); } } void add(int &x, const int &y) { x += y; if (x >= MOD) x -= MOD; } int sum(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; } int diff(int x, int y) { return x < y ? x - y + MOD : x - y; } void optimize(void) { for (int i = (1), _b = (numRow); i <= _b; i++) { int cntRock = 0; for (int j = (numCol), _a = (1); j >= _a; j--) { range[i][j][1] = numCol - cntRock; if (board[i][j] == R ) cntRock++; } int k = numCol; for (int j = (numCol), _a = (1); j >= _a; j--) { while (k >= 1 && range[i][k][1] >= j) k--; k++; limit[i][j][1] = k; } } for (int j = (1), _b = (numCol); j <= _b; j++) { int cntRock = 0; for (int i = (numRow), _a = (1); i >= _a; i--) { range[i][j][0] = numRow - cntRock; if (board[i][j] == R ) cntRock++; } int k = numRow; for (int i = (numRow), _a = (1); i >= _a; i--) { while (k >= 1 && range[k][j][0] >= i) k--; k++; limit[i][j][0] = k; } } for (int i = (2), _b = (numRow); i <= _b; i++) { if (i <= range[1][1][0]) numWay[i][1][0] = 1; sumCol[i][1][0] = sum(sumCol[i - 1][1][0], numWay[i][1][0]); sumRow[i][1][0] = numWay[i][1][0]; } for (int j = (2), _b = (numCol); j <= _b; j++) { if (j <= range[1][1][1]) numWay[1][j][1] = 1; sumRow[1][j][1] = sum(sumRow[1][j - 1][1], numWay[1][j][1]); sumCol[1][j][1] = numWay[1][j][1]; } for (int i = (2), _b = (numRow); i <= _b; i++) for (int j = (2), _b = (numCol); j <= _b; j++) { int k = limit[i][j][1]; numWay[i][j][1] = diff(sumRow[i][j - 1][0], sumRow[i][k - 1][0]); k = limit[i][j][0]; numWay[i][j][0] = diff(sumCol[i - 1][j][1], sumCol[k - 1][j][1]); for (int k = 0, _n = (2); k < _n; k++) { sumRow[i][j][k] = sum(sumRow[i][j - 1][k], numWay[i][j][k]); sumCol[i][j][k] = sum(sumCol[i - 1][j][k], numWay[i][j][k]); } } printf( %d n , sum(numWay[numRow][numCol][1], numWay[numRow][numCol][0])); } int main(void) { init(); optimize(); return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << (a - 1) * (b + c - 1) + b * c << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll t; cin >> t; while (t--) { int n, m; cin >> n >> m; int ar[n]; int su = 0; for (int i = 0; i < n; i++) { cin >> ar[i]; su += ar[i]; } int ans = min(su, m); cout << ans << n ; } } |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long long int INF = 1e12; int n, k; int memo[101][101][101]; int solve(string &str, int i, int N, int _max) { _max = max(N, _max); int &a = memo[i][N][_max]; if (a != -1) return a; if (i == n) { if (_max == k) return a = 1; return a = 0; } if (str[i] == Y ) return a = solve(str, i + 1, 0, _max); else if (str[i] == N ) return a = solve(str, i + 1, N + 1, _max); else { if (solve(str, i + 1, 0, _max)) return a = 1; return a = solve(str, i + 1, N + 1, _max); } return a = 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); memset(memo, -1, sizeof(memo)); cin >> n >> k; string str; cin >> str; if (solve(str, 0, 0, 0)) cout << YES ; else cout << NO ; return 0; } |
#include <bits/stdc++.h> using namespace std; int type, pos, len, start[100020], dest[100020], a[100020], b[100020], q, n, seg[4 * 100020]; bool mark[4 * 100020]; void setVal(int v, int vl, int vr, int val, int l, int r) { if (l <= vl && vr <= r) { seg[v] = max(seg[v], val); mark[v] = true; return; } if (r < vl || l > vr || vl == vr) return; if (mark[v]) { mark[v] = false; mark[2 * v] = mark[2 * v + 1] = true; seg[2 * v] = max(seg[2 * v], seg[v]); seg[2 * v + 1] = max(seg[2 * v + 1], seg[v]); } int mid = (vl + vr) / 2; setVal(2 * v, vl, mid, val, l, r); setVal(2 * v + 1, mid + 1, vr, val, l, r); seg[v] = max(seg[2 * v], seg[2 * v + 1]); } int getVal(int v, int vl, int vr, int p) { int mid = (vl + vr) / 2; if (vl == vr) return seg[v]; if (mark[v]) { mark[v] = false; mark[2 * v] = mark[2 * v + 1] = true; seg[2 * v] = max(seg[2 * v], seg[v]); seg[2 * v + 1] = max(seg[2 * v + 1], seg[v]); } if (p <= mid) return getVal(2 * v, vl, mid, p); else return getVal(2 * v + 1, mid + 1, vr, p); } int main() { scanf( %d %d , &n, &q); for (__typeof(n) i = (1); i <= (n); i++) scanf( %d , &b[i]); for (__typeof(n) i = (1); i <= (n); i++) scanf( %d , &a[i]); for (__typeof(q) i = (1); i <= (q); i++) { scanf( %d , &type); if (type == 2) { scanf( %d , &pos); int idx = getVal(1, 1, n, pos); if (idx == 0) printf( %d n , a[pos]); else printf( %d n , b[start[idx] + pos - dest[idx]]); } else { scanf( %d %d %d , &start[i], &dest[i], &len); setVal(1, 1, n, i, dest[i], dest[i] + len - 1); } } return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int y, b, r, ans = 0; cin >> y >> b >> r; if (y + 1 <= b && y + 2 <= r) { ans = max(ans, 3 * y + 3); } if (b + 1 <= r && b - 1 <= y) { ans = max(ans, 3 * b); } if (r - 1 <= b && r - 2 <= y) { ans = max(ans, 3 * r - 3); } cout << ans; return 0; } |
#include <bits/stdc++.h> using namespace std; template <class T> inline void umin(T &a, T b) { a = min(a, b); } template <class T> inline void umax(T &a, T b) { a = max(a, b); } const int INF = 0x3f3f3f3f; long long mod = 1e9 + 7; const int N = 100005; char s[N]; struct Trie { static const int maxnode = 100005; static const int sigma_size = 26; int ch[maxnode][sigma_size]; int val[maxnode]; int p[maxnode]; int d[maxnode], ms[maxnode]; priority_queue<int> q[maxnode]; int sz; void clear() { sz = 1; memset(ch[0], 0, sizeof(ch[0])); } int idx(char c) { return c - a ; } void insert(const char *s, int v) { int u = 0, n = strlen(s); for (int i = 0; i < n; i++) { int c = idx(s[i]); if (!ch[u][c]) { memset(ch[sz], 0, sizeof(ch[sz])); val[sz] = 0; ch[u][c] = sz++; d[ch[u][c]] = d[u] + 1; } p[ch[u][c]] = u; u = ch[u][c]; } val[u] = v; } void dfs(int u) { for (int i = 0; i < 26; i++) { int v = ch[u][i]; if (v) { dfs(v); while (!q[v].empty()) { q[u].push(q[v].top()); q[v].pop(); } } } if (u == 0) return; if (val[u] == 0) { q[u].pop(); q[u].push(d[u]); } else { q[u].push(d[u]); } } int solve() { dfs(0); int ans = 0; while (!q[0].empty()) { ans += q[0].top(); q[0].pop(); } return ans; } } wc; int main() { int n; scanf( %d , &n); wc.clear(); for (int i = 0; i < n; i++) { scanf( %s , s); wc.insert(s, 1); } printf( %d n , wc.solve()); return 0; } |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int idata = 2e5 + 7; int i, j, k; int judge, flag; long long step[idata]; long long temp; int n, m, t; double maxx = 0, minn = inf; long long cnt, len, sum, ans; long long high, wigh; map<long long, int> pre[2]; signed main() { while (cin >> n >> k) { memset(step, 0, sizeof step); for (i = 1; i <= n; i++) { cin >> step[i]; pre[0][step[i]]++; } for (i = 1; i <= n; i++) { pre[0][step[i]]--; if (step[i] % k == 0) { ans += (long long)pre[1][step[i] / k] * pre[0][step[i] * k]; } pre[1][step[i]]++; } cout << ans << endl; } return 0; } |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; int n; int a[MAXN]; int x[MAXN]; int y[MAXN]; int match[MAXN]; bool vis[MAXN]; int main() { ios::sync_with_stdio(0); cin >> n; if (~n & 1) { cout << First << endl; for (int i = 1; i <= n; i++) cout << i << ; for (int i = 1; i <= n; i++) cout << i << ; cout << endl; cout.flush(); return 0; } else { cout << Second << endl; for (int i = 1; i <= 2 * n; i++) { cin >> a[i]; if (x[a[i]]) y[a[i]] = i; else x[a[i]] = i; } for (int i = 1; i <= n; i++) { match[x[i]] = y[i]; match[y[i]] = x[i]; } for (int i = 1; i <= n; i++) { int cur = i; if (vis[i] || vis[i + n]) continue; while (!vis[cur]) { vis[cur] = 1; cur = (match[cur] > n ? match[cur] - n : match[cur] + n); } } int sum = 0; for (int i = 1; i <= 2 * n; i++) if (vis[i]) (sum += i) %= (2 * n); if (sum) { for (int i = 1; i <= 2 * n; i++) vis[i] ^= 1; } for (int i = 1; i <= 2 * n; i++) if (vis[i]) cout << i << ; cout << endl; cout.flush(); } return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, x, y, i, j, k, l; cin >> n >> m >> x >> y; cout << x << << y << n ; for (i = 1; i <= m; i++) if (i != y) cout << x << << i << n ; int c; for (i = 1, j = m; i <= n; i++) if (i != x) for (k = 1; k <= m; k++) { cout << i << << j << n ; if (j == m) c = -1; else if (j == 1) c = 1; if (k != m) j += c; } return 0; } |
#include <bits/stdc++.h> using namespace std; set<int> s; const int MAX = 150000; int t[MAX]; int main() { int n, q, k; cin >> n >> k >> q; for (int i = 0; i < n; i++) scanf( %d , t + i); for (int i = 0; i < q; i++) { int query; scanf( %d , &query); int x; scanf( %d , &x); x = t[x - 1]; if (query == 1) { if (s.size() == k) { set<int>::iterator it = s.begin(); if (x > *it) { s.erase(*it); s.insert(x); } } else { s.insert(x); } } else { if (s.count(x)) printf( YES n ); else printf( NO n ); } } return 0; } |
#include <bits/stdc++.h> using namespace std; pair<int, int> v[110]; int cur[110]; int main() { int n, w; scanf( %d %d , &n, &w); for (int i = 0; i < n; ++i) { scanf( %d , &v[i].first); v[i].second = i; } sort(v, v + n); reverse(v, v + n); for (int i = 0; i < n; ++i) { w -= (v[i].first + 1) / 2; if (w < 0) return puts( -1 ), 0; cur[i] = (v[i].first + 1) / 2; } for (int i = 0; i < n - 1; ++i) { if (cur[i] < cur[i + 1]) { int dif = cur[i + 1] - cur[i]; if (cur[i] == cur[i + 1]) dif++; if (w >= dif) { cur[i] += dif; w -= dif; } else if (cur[i + 1] >= dif) { cur[i + 1] -= dif; cur[i] += dif; } else return puts( -1 ); } } for (int i = 0; i < n; ++i) { if (w) { int dif = v[i].first - cur[i]; if (w >= dif) { cur[i] += dif; w -= dif; } else if (dif >= w) { cur[i] += w; w = 0; } } else break; } for (int i = 0; i < n; ++i) v[v[i].second].first = cur[i]; for (int i = 0; i < n; ++i) printf( %d , v[i].first); puts( ); return 0; } |
//#pragma GCC optimize( Ofast ) #include <iostream> #include <vector> #include <map> #include <algorithm> #include <random> #include <chrono> #include <complex> #include <cstdio> #include <deque> #include <cmath> #include <bitset> #include <set> #include <cassert> using namespace std; #define ll long long #define ull unsigned long long #define pb push_back #define se second #define fi first #define forn(i,n) for(int i = 0; i < (n); i++) #define read(a) for(int i = 0; i < a.size(); i++){cin >> a[i];} #define all(a) a.begin(),a.end() #define make_unique(a) sort(all(a)); a.resize(unique(a.begin(),a.end())-a.begin()); const int mod = 1e9 + 7; //#define int long long const int N = 10000000; int lp[N+1]; vector<int> pr; void solve(){ int t; cin >> t; for (int i=2; i<=N; ++i) { if (lp[i] == 0) { lp[i] = i; pr.push_back (i); } for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j) lp[i * pr[j]] = pr[j]; } set<vector<int>> se; while(t--){ int n,k; cin >> n >> k; vector<int> a(n); read(a); ll ans = 1; se.clear(); for(int i = 0; i < n; ++i){ vector<int> qw; int nw = a[i]; while(nw != 1){ if(!qw.empty() && qw.back() == lp[nw]){ qw.pop_back(); nw /= lp[nw]; continue; } if(qw.empty() || qw.back() != lp[nw]){ qw.push_back(lp[nw]); } nw /= lp[nw]; } if(se.count(qw)){ ans++; se.clear(); } se.insert(qw); } cout << ans << n ; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef Debugg freopen( ain.txt , r ,stdin); freopen( aout.txt , w ,stdout); #endif solve(); #ifdef Debugg cout << n << (double)clock()/CLOCKS_PER_SEC; #endif } |
#include <bits/stdc++.h> using namespace std; inline void pisz(int n) { printf( %d n , n); } int dl[1000][1000]; int dr[1000][1000]; int ul[1000][1000]; int ur[1000][1000]; int g[1000][1000]; int n, m; int recdl(int i, int j) { if (i < 0 || i == n || j < 0 || j == m) return -1001001001; if (i == n - 1 && j == 0) return g[i][j]; if (dl[i][j] != -1) return dl[i][j]; return dl[i][j] = g[i][j] + (recdl(i + 1, j) < recdl(i, j - 1) ? recdl(i, j - 1) : recdl(i + 1, j)); } int recdr(int i, int j) { if (i < 0 || i == n || j < 0 || j == m) return -1001001001; if (i == n - 1 && j == m - 1) return g[i][j]; if (dr[i][j] != -1) return dr[i][j]; return dr[i][j] = g[i][j] + (recdr(i + 1, j) < recdr(i, j + 1) ? recdr(i, j + 1) : recdr(i + 1, j)); } int recul(int i, int j) { if (i < 0 || i == n || j < 0 || j == m) return -1001001001; if (i == 0 && j == 0) return g[i][j]; if (ul[i][j] != -1) return ul[i][j]; return ul[i][j] = g[i][j] + (recul(i - 1, j) < recul(i, j - 1) ? recul(i, j - 1) : recul(i - 1, j)); } int recur(int i, int j) { if (i < 0 || i == n || j < 0 || j == m) return -1001001001; if (i == 0 && j == m - 1) return g[i][j]; if (ur[i][j] != -1) return ur[i][j]; return ur[i][j] = g[i][j] + (recur(i - 1, j) < recur(i, j + 1) ? recur(i, j + 1) : recur(i - 1, j)); } int main() { cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> g[i][j]; memset(dl, -1, sizeof(dl)); memset(dr, -1, sizeof(dr)); memset(ul, -1, sizeof(ul)); memset(ur, -1, sizeof(ur)); int res = 0; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { int b1 = recul(i - 1, j) + recdl(i, j - 1); int a1 = recdr(i + 1, j) + recur(i, j + 1); int b2 = recul(i, j - 1) + recdl(i + 1, j); int a2 = recdr(i, j + 1) + recur(i - 1, j); res = (res < (b1 + a1 < b2 + a2 ? b2 + a2 : b1 + a1) ? (b1 + a1 < b2 + a2 ? b2 + a2 : b1 + a1) : res); } cout << res << endl; } |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 0.0000000001; const int N = 100000 + 100; int head[N]; int tot; struct node { int to, next; } edge[N << 1]; int color[N]; int vis[N]; int a[N]; int b[N]; int num[N]; void init() { memset(head, -1, sizeof(head)); tot = 0; } void add(int u, int v) { edge[tot].to = v; edge[tot].next = head[u]; head[u] = tot++; } int DFS(int u, int t) { if (vis[u] == 0) { if (color[u] == 0) a[t]++; if (color[u] == 1) b[t]++; num[t]++; } vis[u] = 1; for (int i = head[u]; i != -1; i = edge[i].next) { int v = edge[i].to; if (color[v] == 0) { color[v] = color[u] ^ 1; if (DFS(v, t) == 0) return 0; } else if (color[u] == color[v]) { return 0; } } return 1; } int main() { int n, m; scanf( %d%d , &n, &m); init(); int u, v; for (int i = 1; i <= m; i++) { scanf( %d%d , &u, &v); add(u, v); add(v, u); } if (m == 0) { cout << 3 << << (long long)n * (n - 1) * (n - 2) / 6 << endl; return 0; } memset(color, 0, sizeof(color)); memset(vis, 0, sizeof(vis)); int flag = 0; int t = 0; for (int i = 1; i <= n; i++) { if (color[i] == 0 && vis[i] == 0) { if (DFS(i, ++t) == 0) { color[i] = 0; flag = 1; break; } } } if (flag == 1) { cout << 0 << << 1 << endl; return 0; } long long ans = 0; flag = 0; for (int i = 1; i <= t; i++) { if (num[i] <= 2) { flag++; continue; } ans = ans + (long long)a[i] * (a[i] - 1) / 2 + (long long)b[i] * (b[i] - 1) / 2; } if (flag != t) cout << 1 << << ans << endl; else { cout << 2 << << (long long)m * (n - 2) << endl; } } |
#include <bits/stdc++.h> int main() { int n, pur, foo = 0, quz = 1, bar = 0, baz = 0; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &pur); foo += pur, bar++; if (foo * quz > bar * baz) quz = bar, baz = foo; } printf( %.6lf n , (double)baz / quz); return 0; } |
#include <bits/stdc++.h> using namespace std; void fun() {} long long int md = 998244353; long long int __gcd(long long int a, long long int b) { if (b == 0) return a; return __gcd(b, a % b); } long long int poww(long long int a, long long int b, long long int md) { if (b < 0) return 0; if (a == 0) return 0; long long int res = 1; while (b) { if (b & 1) { res = (1ll * res * a) % md; } a = (1ll * a * a) % md; b >>= 1; } return res; } long long int poww(long long int a, long long int b) { if (b < 0) return 0; if (a == 0) return 0; long long int res = 1; while (b) { if (b & 1) { res = (1ll * res * a); } a = (1ll * a * a); b >>= 1; } return res; } void ainp(long long int arr[], long long int n) { for (long long int i = 1; i <= n; i++) cin >> arr[i]; } void disp(long long int arr[], long long int n) { for (long long int i = 1; i <= n; i++) cout << arr[i] << ; cout << n ; } void dispv(vector<long long int> &v) { for (long long int i = 0; i < v.size(); i++) cout << v[i] << ; cout << n ; } long long int divide(long long int a, long long int b, long long int md) { long long int rr = a * (poww(b, md - 2, md)); rr %= md; return rr; } const long long int size = 2e5 + 5; long long int n, m, k, u, v; vector<long long int> g[size]; pair<long long int, long long int> dis[size], prr[size]; queue<long long int> q; long long int arr[size], suffmax[size]; bool fnn(pair<long long int, long long int> &p1, pair<long long int, long long int> &p2) { return (p1.first - p1.second < p2.first - p2.second); } void bfs() { dis[1].first = 0; q.push(1); while (!q.empty()) { long long int node = q.front(); q.pop(); for (long long int child : g[node]) { if (dis[child].first > dis[node].first + 1 || (child != 1 && dis[child].first == 0)) { dis[child].first = dis[node].first + 1; q.push(child); } } } q.push(n); dis[n].second = 0; while (!q.empty()) { long long int node = q.front(); q.pop(); for (long long int child : g[node]) { if (dis[child].second > dis[node].second + 1 || (child != n && dis[child].second == 0)) { dis[child].second = dis[node].second + 1; q.push(child); } } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); fun(); cin >> n >> m >> k; ainp(arr, k); for (long long int i = 1; i <= m; i++) { cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } bfs(); for (long long int i = 1; i <= k; i++) prr[i] = dis[arr[i]]; sort(prr + 1, prr + 1 + k, fnn); for (long long int i = k; i > 0; i--) suffmax[i] = max(suffmax[i + 1], prr[i].second); long long int cost = dis[n].first; long long int cst = 0; for (long long int i = 1; i < k; i++) { cst = max(suffmax[i + 1] + 1 + prr[i].first, cst); } cout << min(cst, cost) << n ; return 0; } |
#include <bits/stdc++.h> using namespace std; int N, M, T; int A[20000]; int rans; vector<int> ans; set<pair<int, int>> online; multiset<pair<int, int>> events; bool solve() { bool good = false; for (int i = 0; i < N; i++) events.insert({A[i], -1}); while (!events.empty()) { int t = events.begin()->first; int v = events.begin()->second; events.erase(events.begin()); if (v == -1) { if ((int)online.size() < M) { rans++; online.insert({t + T - 1, rans}); events.insert({t + T - 1, rans}); ans.push_back(rans); } else { pair<int, int> guy = *online.rbegin(); online.erase(guy); events.erase(events.find(guy)); guy.first = t + T - 1; online.insert(guy); events.insert(guy); ans.push_back(guy.second); } good |= (int)online.size() == M; } else online.erase({t, v}); } return good; } int main() { scanf( %d%d%d , &N, &M, &T); int hh, mm, ss; for (int i = 0; i < N; i++) { scanf( %d:%d:%d , &hh, &mm, &ss); A[i] = hh * 3600 + mm * 60 + ss; } if (!solve()) printf( No solution n ); else { printf( %d n , rans); for (auto& it : ans) printf( %d n , it); } return 0; } |
Subsets and Splits