#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7, abc = 864197532, N = 1000001, logN = 17; n vector<int> a; n vector<int> d, lp; n struct Seg { n   int l, r, m; n   long long int val = 0; n   Seg* ch[2]; n   Seg(int _l, int _r) : l(_l), r(_r), m(l + r >> 1) { n     if (r - l > 1) { n       ch[0] = new Seg(l, m); n       ch[1] = new Seg(m, r); n       pull(); n     } else { n       val = a[l]; n     } n   } n   void pull() { val = ch[0]->val + ch[1]->val; } n   void set(int p) { n     if (r - l == 1) n       val = d[val]; n     else n       ch[p >= m]->set(p), pull(); n   } n   long long int query(int a, int b) { n     if (a <= l && r <= b) return val; n     long long int ans = 0; n     if (a < m) ans += ch[0]->query(a, b); n     if (m < b) ans += ch[1]->query(a, b); n     return ans; n   } n }; n void build() { n   d.assign(N, 1); n   lp.assign(N, 0); n   for (int i = 2; i < N; ++i) n     if (lp[i] == 0) { n       for (int j = i; j < N; j += i) lp[j] = i; n     } n   for (int i = 2; i < N; ++i) { n     int p = lp[i], tmp = i, cnt = 0; n     while (tmp % p == 0) tmp /= p, cnt++; n     d[i] = d[tmp] * (cnt + 1); n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   build(); n   int n, q, t, l, r; n   cin >> n >> q; n   a.resize(n); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   Seg root(0, n); n   set<int> s; n   for (int i = 0; i < n; ++i) n     if (a[i] > 2) s.insert(i); n   vector<int> eras; n   while (q--) { n     cin >> t >> l >> r, l--; n     if (t == 1) { n       for (auto it = s.lower_bound(l); it != s.end() && *it < r; ++it) { n         int p = *it; n         root.set(p); n         a[p] = d[a[p]]; n         if (a[p] <= 2) eras.push_back(p); n       } n       while (eras.size()) { n         s.erase(eras.back()); n         eras.pop_back(); n       } n     } else { n       cout << root.query(l, r) <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class L> n bool smax(T &x, L y) { n   return x < y ? (x = y, 1) : 0; n } n template <class T, class L> n bool smin(T &x, L y) { n   return y < x ? (x = y, 1) : 0; n } n const int maxn = 1e5 + 17, S = 1e9 + 1, maxfen = S * 2; n map<int, vector<pair<int, int>>> xs, ys; n int n; n unordered_map<int, int> iman; n struct eve { n   int x, y, v; n }; n vector<eve> event; n void make(vector<pair<int, int>> &vec) { n   vector<pair<int, int>> ans; n   sort(vec.begin(), vec.end()); n   int mxr = vec[0].second; n   ans.push_back({vec[0].first, -1}); n   for (int i = 1; i < vec.size(); i++) { n     if (mxr < vec[i].first) n       ans.back().second = mxr + 1, ans.push_back({vec[i].first, -1}); n     smax(mxr, vec[i].second); n   } n   ans.back().second = mxr + 1; n   vec = ans; n } n void majid(long long p, int v) { n   for (p += S; p < maxfen; p += p & -p) iman[p] += v; n } n int hamid(int p) { n   int ans = 0; n   for (p += S; p; p ^= p & -p) ans += iman[p]; n   return ans; n } n int hamid(int l, int r) { return hamid(r - 1) - hamid(l - 1); } n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   cin >> n; n   for (int x1, y1, x2, y2, i = 0; i < n; i++) { n     cin >> x1 >> y1 >> x2 >> y2; n     if (x1 == x2) n       xs[x1].push_back(minmax(y1, y2)); n     else n       ys[y1].push_back(minmax(x1, x2)); n   } n   long long ans = 0; n   for (auto &v : ys) { n     make(v.second); n     for (auto x : v.second) { n       ans += x.second - x.first; n       event.push_back({v.first, x.first, 1}); n       event.push_back({v.first, x.second, -1}); n     } n   } n   sort(event.begin(), event.end(), [](eve &a, eve &b) { return a.y < b.y; }); n   int ptr = 0; n   for (auto &v : xs) { n     make(v.second); n     while (ptr < event.size() && event[ptr].y <= v.first) n       majid(event[ptr].x, event[ptr].v), ptr++; n     for (auto x : v.second) { n       ans += x.second - x.first; n       ans -= hamid(x.first, x.second); n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const float pi = acos(-1.0); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   t = 1; n   while (t--) { n     long long int n; n     cin >> n; n     cout << 0 <<     << 0 <<     << n; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T inline sqr(T x) { n   return x * x; n } n const int mlen = 303; n int p[6]; n char s[6][mlen]; n char res[mlen][mlen]; n vector<vector<string> > x; n void draw(int sx, int sy, const char *s, int dx, int dy) { n   while (*s) res[sy][sx] = *s++, sx += dx, sy += dy; n } n int main() { n   for (int i = 0; i < (int)(6); i++) gets(s[i]), p[i] = i; n   do { n     int H = strlen(s[p[0]]) - 1; n     int W = strlen(s[p[1]]) - 1; n     int h = strlen(s[p[2]]) - 1; n     int w = strlen(s[p[3]]) - 1; n     int bad = 0; n     bad |= (strlen(s[p[0]]) != strlen(s[p[2]]) + strlen(s[p[4]]) - 1); n     bad |= (strlen(s[p[1]]) != strlen(s[p[3]]) + strlen(s[p[5]]) - 1); n     bad |= (s[p[0]][0] != s[p[3]][w]); n     bad |= (s[p[0]][h] != s[p[1]][w]); n     bad |= (s[p[0]][H] != s[p[5]][0]); n     bad |= (s[p[2]][0] != s[p[3]][0]); n     bad |= (s[p[2]][h] != s[p[1]][0]); n     bad |= (s[p[4]][0] != s[p[1]][W]); n     bad |= (s[p[4]][H - h] != s[p[5]][W - w]); n     if (bad) continue; n     memset(res,  . , sizeof(res)); n     draw(0, 0, s[p[2]], 0, 1); n     draw(w, 0, s[p[0]], 0, 1); n     draw(W, h, s[p[4]], 0, 1); n     draw(0, 0, s[p[3]], 1, 0); n     draw(0, h, s[p[1]], 1, 0); n     draw(w, H, s[p[5]], 1, 0); n     vector<string> R; n     for (int i = 0; i < (int)(H + 1); i++) n       res[i][W + 1] = 0, R.push_back(res[i]); n     x.push_back(R); n   } while (next_permutation(p, p + 6)); n   sort((x).begin(), (x).end()); n   if (!x.size()) n     puts( Impossible ); n   else { n     for (int i = 0; i < (int)(x[0].size()); i++) { n       for (int j = 0; j < (int)(x[0][0].size()); j++) printf( %c , x[0][i][j]); n       puts(  ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 75005; n const long long maxm = (1 << 15) + 5; n long long k, n[16], s[16], a[16][5005], co[maxn], col[maxn], idx, b[maxn], n     yhp[16], num; n long long st[maxn], cnt[16], vis[maxm], lst[maxm], from[maxm], sel[maxn]; n long long head[maxn], ecnt, d[maxn]; n struct edge { n   long long to, next; n } e[maxn << 1]; n map<long long, long long> id, ans; n long long sum[maxn]; n vector<long long> to, nxt; n void adde(long long u, long long v) { n   e[++ecnt].to = v; n   d[v]++; n   e[ecnt].next = head[u]; n   head[u] = ecnt; n } n long long read() { n   long long res = 0, f = 1; n   char ch; n   do { n     ch = getchar(); n     if (ch ==  - ) f = -1; n   } while (!isdigit(ch)); n   do { n     res = res * 10 + ch -  0 ; n     ch = getchar(); n   } while (isdigit(ch)); n   return res * f; n } n void topsort() { n   queue<long long> q; n   for (long long i = (1); i <= (s[k]); ++i) n     if (!d[i]) q.push(i); n   while (!q.empty()) { n     long long u = q.front(); n     q.pop(); n     for (long long i = head[u]; i; i = e[i].next) { n       long long v = e[i].to; n       d[v]--; n       if (!d[v]) q.push(v); n     } n   } n } n void dfs(long long u) { n   col[u] = idx; n   st[idx] |= (1 << (yhp[co[u]] - 1)); n   cnt[yhp[co[u]]]++; n   for (long long i = head[u]; i; i = e[i].next) { n     long long v = e[i].to; n     if (!d[v] || col[v]) continue; n     dfs(v); n   } n } n signed main() { n   k = read(); n   for (long long i = (1); i <= (k); ++i) { n     n[i] = read(); n     s[i] = s[i - 1] + n[i]; n     for (long long j = (1); j <= (n[i]); ++j) n       a[i][j] = read(), id[a[i][j]] = s[i - 1] + j, co[id[a[i][j]]] = i, n       b[id[a[i][j]]] = a[i][j], sum[i] += a[i][j]; n     sum[0] += sum[i]; n   } n   if (sum[0] % k != 0) { n     puts( No ); n     return 0; n   } n   sum[0] /= k; n   for (long long i = (1); i <= (k); ++i) n     if (sum[i] == sum[0]) n       yhp[i] = yhp[i - 1]; n     else n       yhp[i] = ++num; n   for (long long i = (1); i <= (k); ++i) n     for (long long j = (1); j <= (n[i]); ++j) { n       if (sum[i] == sum[0]) continue; n       long long x = (sum[0] - (sum[i] - a[i][j])); n       if (id[x] == 0 || (co[id[a[i][j]]] == co[id[x]] && id[a[i][j]] != id[x])) n         continue; n       adde(id[a[i][j]], id[x]); n     } n   topsort(); n   for (long long i = (1); i <= (s[k]); ++i) { n     if (d[i] && !col[i]) { n       ++idx; n       memset(cnt, 0, sizeof(cnt)); n       dfs(i); n       for (long long j = (1); j <= (k); ++j) n         if (cnt[j] > 1) st[idx] = 0; n     } n   } n   vis[0] = 1; n   to.push_back(0); n   long long S = (1 << num) - 1; n   for (long long i = (1); i <= (idx); ++i) { n     if (!st[i]) continue; n     nxt.clear(); n     for (long long x : to) { n       if (x & st[i]) continue; n       if (vis[x | st[i]]) continue; n       vis[x | st[i]] = 1; n       lst[x | st[i]] = x; n       from[x | st[i]] = i; n       nxt.push_back(x | st[i]); n     } n     for (long long x : nxt) to.push_back(x); n   } n   if (!vis[S]) { n     puts( No ); n     return 0; n   } n   puts( Yes ); n   long long tmp = S; n   while (tmp) sel[from[tmp]] = 1, tmp = lst[tmp]; n   for (long long u = (1); u <= (s[k]); ++u) n     if (sel[col[u]]) n       for (long long i = head[u]; i; i = e[i].next) { n         long long v = e[i].to; n         if (d[v]) ans[b[v]] = co[u]; n       } n   for (long long i = (1); i <= (k); ++i) { n     if (sum[i] == sum[0]) n       printf( %lld %lld n , a[i][1], i); n     else n       for (long long j = (1); j <= (n[i]); ++j) n         if (ans[a[i][j]]) printf( %lld %lld n , a[i][j], ans[a[i][j]]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000009; n long long poww(long long base, long long power) { n   long long ret = 1; n   for (long long i = 0; i < power; i++) { n     ret *= base; n     ret %= mod; n   } n   return ret; n } n int main() { n   long long ans; n   long long n, m; n   while (~scanf( %I64d%I64d , &n, &m)) { n     ans = 1; n     long long sum = poww(2, m); n     for (long long i = 1; i <= n; i++) { n       ans *= (sum - i); n       ans %= mod; n     } n     printf( %I64d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n int search(int a[], int j, int n) { n   int i; n   for (i = 0; i < n; i++) { n     if (a[i] == j) { n       a[i] = 0; n       return (i + 1); n     } n   } n   return 0; n } n int main() { n   int t, n, i, j, k, m, x, y, z; n   scanf( %d , &n); n   int a[n]; n   int f[3] = {0}; n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     if (a[i] == 1) { n       f[0]++; n     } n     if (a[i] == 2) { n       f[1]++; n     } n     if (a[i] == 3) { n       f[2]++; n     } n   } n   m = 50000; n   for (i = 0; i < 3; i++) { n     if (f[i] < m) { n       m = f[i]; n     } n   } n   printf( %d n , m); n   for (i = 0; i < m; i++) { n     x = search(a, 1, n); n     y = search(a, 2, n); n     z = search(a, 3, n); n     if (x * y * z) { n       printf( %d %d %d n , x, y, z); n     } else { n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n int dist[200002]; n vector<pair<int, int>> v[200002]; n vector<int> nes[200002]; n char s[200002]; n vector<string> ans; n void dfs(int d) { n   if (ans.size() >= k) return; n   if (d > n) { n     ans.push_back(s); n     return; n   } n   for (auto i : nes[d]) { n     s[i] =  1 ; n     dfs(d + 1); n     s[i] =  0 ; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m >> k; n   for (int i = 0; i < m; ++i) { n     int a, b; n     cin >> a >> b; n     v[a].push_back({b, i}); n     v[b].push_back({a, i}); n   } n   queue<int> q; n   q.push(1); n   dist[1] = 1; n   while (q.size()) { n     int x = q.front(); n     q.pop(); n     for (auto i : v[x]) { n       if (dist[i.first]) continue; n       dist[i.first] = dist[x] + 1; n       q.push(i.first); n     } n   } n   for (int i = 2; i <= n; ++i) { n     for (auto j : v[i]) { n       if (dist[j.first] + 1 == dist[i]) nes[i].push_back(j.second); n     } n   } n   fill(s, s + m,  0 ); n   dfs(2); n   cout << ans.size() <<   n ; n   for (auto i : ans) cout << i <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t = 1; n   while (t--) { n     long long int n, m, c = 0; n     cin >> n >> m; n     vector<set<long long int>> v(n + 1); n     long long int x, y; n     for (int i = 0; i < m; i++) { n       cin >> x >> y; n       v[x].insert(y); n       v[y].insert(x); n     } n     while (1) { n       vector<long long int> q; n       for (int i = 1; i <= n; i++) n         if (v[i].size() == 1) q.push_back(i); n       for (int i = 0; i < q.size(); i++) { n         auto it = v[q[i]].begin(); n         v[q[i]].clear(); n         v[*it].erase(q[i]); n       } n       if (q.size() > 0) n         c++; n       else n         break; n     } n     cout << c; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long geti() { n   long long ret = 0; n   char ch = getchar(), k = 1; n   while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) k = 0, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) ret = ret * 10 + ch -  0 , ch = getchar(); n   return k ? ret : -ret; n } n const int N = 1000010; n const int mo = 1000000007; n int n, t, mx; n long long f[N], g[N], mi2[N], ans = 0; n int main() { n   n = geti(); n   for (int i = 1; i <= n; i += 1) { n     t = geti(); n     mx = max(mx, t); n     for (int j = 1; j * j <= t; j += 1) { n       if (t % j != 0) continue; n       f[j] += 1; n       if (j != t / j) f[t / j] += 1; n     } n   } n   mi2[0] = 1; n   for (int i = 1; i <= mx; i += 1) mi2[i] = mi2[i - 1] * 2 % mo; n   for (int i = mx; i > 1; i -= 1) { n     g[i] = f[i] * mi2[f[i] - 1] % mo; n     for (int j = 2 * i; j <= mx; j += i) { n       g[i] -= g[j]; n       g[i] %= mo; n     } n     ans += i * g[i] % mo; n     ans %= mo; n   } n   cout << (ans + mo) % mo; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000 + 5; n int b[maxn]; n int g[maxn]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &b[i]); n   for (int i = 1; i <= m; i++) scanf( %d , &g[i]); n   long long sum = 0; n   sort(b + 1, b + n + 1); n   sort(g + 1, g + m + 1); n   if (b[n] > g[1]) n     printf( -1 n ); n   else { n     int cur = m; n     for (int i = n; i >= 1; i--) { n       sum += (long long)b[i] * m; n       int k = m; n       if (cur == m) { n         while (k > 0 && cur >= 2 && g[cur] > b[i]) { n           k--; n           sum += g[cur] - b[i]; n           cur--; n         } n       } else { n         while (k > 0 && cur >= 1 && g[cur] > b[i]) { n           k--; n           sum += g[cur] - b[i]; n           cur--; n         } n       } n       while (cur >= 1 && g[cur] == b[i]) cur--; n     } n     if (cur >= 1) n       printf( -1 n ); n     else n       printf( %I64d n , sum); n   } n   return 0; n } n


//Be Name Khoda n  n #include<bits/stdc++.h> n  n using namespace std; n  n typedef long long ll; n  n #define pb push_back n #define pp pop_back n #define all(x) x.begin(), x.end() n  n const ll mxn = 3e5 + 5; n ll t, n = 0, k, q; n ll cnt[mxn]; n vector<ll> v, v2; n  n void input() { n  n     for(int i = 0; i <= n; i++) { n         cnt[i] = 0; n     } n  n     v.clear(), v2.clear(); n  n     cin >> n; n  n     for(int i = 0; i < n; i++) { n         cin >> q;  n         v.pb(q); n         cnt[q]++; n     } n  n } n  n  n void solve() { n  n     ll l = 0, r = n - 1; n  n     if(cnt[1] > 0) { n         v2.pb(1); n     } n  n     for(int i = 2; i < n; i++) { n         if(cnt[1] == 0 || cnt[i] == 0 || cnt[i - 1] > 1) { n             break; n         } n         if(v[l] == i - 1) { n             v2.pb(1); n             l++; n         } n         else if(v[r] == i - 1) { n             v2.pb(1); n             r--; n         } n         else { n             break; n         } n     } n  n     while(v2.size() < n - 1) { n         v2.pb(0); n     } n  n     bool check = 1; n  n     for(int i = 1; i <= n; i++) { n         if(cnt[i] != 1) { n             check = 0; n             break; n         } n     } n  n     if(n > 1) { n         if(!check) { n             v2.pb(0); n         } n         else { n             v2.pb(1); n         } n     } n  n     for(int i = v2.size() - 1; i > -1; i--) { n         cout << v2[i]; n     } n     cout << endl; n  n } n  n int main() { n  n     ios::sync_with_stdio(false); n  n     cin >> t; n  n     while(t--) { n         input(), solve(); n     } n      n     return 0; n      n }


#include <bits/stdc++.h> n using namespace std; n int I, len[500005], las[500005]; n string second, ans[500005]; n char fi[500005], se[500005]; n string get(int raod, char c, int ind) { n   len[I] = raod + len[ind]; n   raod = min(raod, 10); n   string ret =   ; n   for (int i = 0; i < raod; i++) ret += c; n   ret = ret + ans[ind]; n   if (ret.size() <= 10) return ret; n   string ne; n   for (int i = 0; i < 5; i++) ne += ret[i]; n   ne +=  ... ; n   for (int i = (int)ret.size() - 2; i < ret.size(); i++) ne += ret[i]; n   return ne; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> second; n   int n = (int)second.size(); n   ans[n - 1] += second[n - 1]; n   len[n - 1] = 1; n   las[n - 1] = n; n   fi[n - 1] = second[n - 1]; n   se[n - 1] =  % ; n   fi[n] =  % ; n   se[n] =  % ; n   for (int i = (int)second.size() - 2; i >= 0; i--) { n     I = i; n     int raod; n     if (second[i] == second[i + 1]) { n       las[i] = las[i + 1]; n     } else { n       las[i] = i + 1; n     } n     int ind = las[i]; n     if (fi[ind] ==  % ) { n       raod = (ind - i) % 2; n       ans[i] = get(raod, second[i], ind); n       if (raod) { n         fi[i] = second[i]; n       } else n         fi[i] =  % ; n       se[i] =  % ; n       continue; n     } n     if (fi[ind] == second[i]) { n       if (se[ind] ==  % ) { n         raod = (ind - i) % 2; n         ans[i] = get(raod, second[i], ind); n         fi[i] = second[i]; n         se[i] =  % ; n         continue; n       } else { n         if (se[ind] > second[i]) { n           ans[i] = get(ind - i, second[i], ind); n           fi[i] = second[i]; n           se[i] = se[ind]; n         } else { n           raod = (ind - i) % 2; n           ans[i] = get(raod, second[i], ind); n           fi[i] = second[i]; n           se[i] = se[i]; n         } n       } n     } else { n       if (fi[ind] > second[i]) { n         ans[i] = get(ind - i, second[i], ind); n         fi[i] = second[i]; n         se[i] = fi[ind]; n       } else { n         raod = (ind - i) % 2; n         ans[i] = get(raod, second[i], ind); n         if (raod) { n           fi[i] = second[i]; n           se[i] = fi[ind]; n         } else { n           fi[i] = fi[ind]; n           se[i] = se[ind]; n         } n       } n     } n   } n   for (int i = 0; i < n; i++) cout << len[i] <<     << ans[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int in() { n   int x, y; n   y = scanf( %d , &x); n   return x; n } n const int N = 100 * 1000 + 5; n const long long INF = 10LL * 1000 * 1000 * 1000 * 1000; n long long a[N]; n pair<long long, long long> next(long long x, long long c) { n   pair<long long, long long> res = {-1, -1}; n   for (long long d = 1; d * d <= c; d++) n     if (c % d == 0 && (d + c / d) % 2 == 0) { n       long long x2 = (d + c / d) / 2; n       long long x1 = c / d - x2; n       if (x1 > x && x2 > x1 && x1 * x1 - x * x <= INF && n           (res.second == -1 || x2 < res.second)) n         res = {x1, x2}; n     } n   return res; n } n int main() { n   int n = in(); n   long long x = 0; n   for (int i = 0; i < n / 2; i++) { n     long long c = in(); n     a[2 * i + 1] = c; n     pair<long long, long long> nx = next(x, c); n     if (nx.first == -1) return (cout <<  No n ), 0; n     a[2 * i] = nx.first * nx.first - x * x; n     x = nx.second; n   } n   cout <<  Yes n ; n   for (int i = 0; i < n; i++) cout << a[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, b, p[100000], la[100000], lb[100000]; n int party[100000]; n bool pass, assigned[100000]; n map<int, int> m; n inline int deg(int i) { return (la[i] != -1) + (lb[i] != -1); } n int dfs(int i) { n   if (deg(i) == 0) { n     return 1; n   } n   if (~la[i]) { n     int t = la[i]; n     la[t] = la[i] = lb[i] = -1; n     if (!assigned[i] && (assigned[i] = assigned[t] = 1)) n       party[i] = party[t] = 0; n     if (t == i) pass = 1; n     return 1 + dfs(t); n   } else { n     int t = lb[i]; n     lb[t] = la[i] = lb[i] = -1; n     if (!assigned[i] && (assigned[i] = assigned[t] = 1)) n       party[i] = party[t] = 1; n     if (t == i) pass = 1; n     return 1 + dfs(t); n   } n } n int main() { n   scanf( %d%d%d , &n, &a, &b); n   for (int i = 0; i < n; ++i) scanf( %d , p + i), m[p[i]] = i; n   auto fd = [](int x) { n     auto it = m.find(x); n     return it == m.end() ? -1 : it->second; n   }; n   for (int i = 0; i < n; ++i) { n     la[i] = fd(a - p[i]); n     lb[i] = fd(b - p[i]); n     if (deg(i) == 0) { n       puts( NO ); n       return 0; n     } n   } n   for (int i = 0; i < n; ++i) { n     if (deg(i) == 1) { n       pass = 0; n       if (dfs(i) & 1 && !pass) { n         puts( NO ); n         return 0; n       } n     } n   } n   for (int i = 0; i < n; ++i) { n     if (deg(i) == 2) { n       dfs(i); n     } n   } n   puts( YES ); n   for (int i = 0; i < n; ++i) printf( %d  , party[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 5; n long long n; n long long deg[N], ans[N]; n vector<pair<long long, long long> > g[N]; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t = 1; n   while (t--) { n     long long x1, x2, y1, y2, z1, z2; n     cin >> x1 >> y1 >> z1; n     cin >> x2 >> y2 >> z2; n     bool x = x1 ^ x2; n     x = !x; n     bool y = y1 ^ y2; n     y = !y; n     bool z = z1 ^ z2; n     z = !z; n     if (x || y || z) n       cout <<  YES  n            <<   n ; n     else n       cout <<  NO  n            <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct second { n   int l, r, x, id; n   bool operator<(const second a) const { n     if (r < a.r) return 1; n     if (r > a.r) return 0; n     return id < a.id; n   } n } s[10005]; n int cmp(const second a, const second b) { n   if (a.l != b.l) return a.l < b.l; n   return a.r < b.r; n } n set<second> st; n int a[10005]; n int dp1[10005], dp2[10005]; n bool ans[10005]; n int main(void) { n   int n, q; n   scanf( %d%d , &n, &q); n   int i; n   for (i = 0; i < q; i++) { n     scanf( %d%d%d , &s[i].l, &s[i].r, &s[i].x); n     s[i].id = i; n   } n   sort(s, s + q, cmp); n   int j = 0; n   dp1[0] = dp2[0] = 1; n   for (i = 1; i <= n; i++) { n     bool modi = false; n     while (j < q && s[j].l <= i) { n       st.insert(s[j]); n       int x = s[j].x; n       for (int l = n; l >= x; l--) { n         dp1[l] += dp1[l - x]; n         dp1[l] %= 19950527; n         dp2[l] += dp2[l - x]; n       } n       modi = true; n       j++; n     } n     while (!st.empty()) { n       auto it = st.begin(); n       if (it->r < i) { n         int x = it->x; n         for (int l = x; l <= n; l++) { n           dp1[l] -= dp1[l - x]; n           dp1[l] %= 19950527; n           dp2[l] -= dp2[l - x]; n         } n         st.erase(it); n         modi = true; n       } else { n         break; n       } n     } n     if (!modi) continue; n     for (int l = 1; l <= n; l++) n       if (dp1[l] || dp2[l]) ans[l] = true; n   } n   int cnt = 0; n   for (i = 1; i <= n; i++) n     if (ans[i]) cnt++; n   printf( %d n , cnt); n   for (i = 1; i <= n; i++) n     if (ans[i]) printf( %d  , i); n   return 0; n } n


#include <bits/stdc++.h> n #pragma optimize( Ofast ) n using namespace std; n unsigned int start = clock(); n using ll = unsigned long long; n struct obj { n   int fi, se; n   obj() { fi = se = 0; } n }; n void gettime(string s) { n   cout << endl << s << (clock() - start) / 1000000.0 << endl; n } n void insert() {} n void solve() { n   int n, k; n   cin >> n >> k; n   vector<int> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   vector<int> pref(n, 0); n   for (int i = 1; i < n - 1; i++) { n     pref[i] = pref[i - 1] + (a[i - 1] < a[i] && a[i] > a[i + 1] ? 1 : 0); n   } n   pref[n - 1] = pref[n - 2]; n   int l = 0; n   int ans = pref[k - 2]; n   for (int i = k - 1; i < n; i++) { n     if (ans < pref[i - 1] - pref[i - k + 1]) { n       ans = pref[i - 1] - pref[i - k + 1]; n       l = i - k + 1; n     } n   } n   cout << ans + 1 <<     << l + 1 <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int q = 1; n   cin >> q; n   while (q--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e9 + 7; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= M; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % M; n     a = a * a % M; n   } n   return res % M; n } n const long long N = 1e5; n int main() { n   int n; n   cin >> n; n   map<string, int> m; n   int c = 0; n   set<string> st[21], st1[21]; n   for (int i = 0; i < n; ++i) { n     string s; n     cin >> s; n     if (m.count(s)) n       ; n     else n       m[s] = c++; n     int nn; n     cin >> nn; n     for (int j = 0; j < nn; ++j) { n       string ss; n       cin >> ss; n       st[m[s]].insert(ss); n     } n   } n   for (int i = 0; i < c; ++i) { n     for (set<string>::iterator it = st[i].begin(); it != st[i].end(); ++it) { n       bool flag = 0; n       for (set<string>::iterator it1 = st[i].begin(); it1 != st[i].end(); n            ++it1) { n         if (*it != *it1) { n           string s1 = *it, s2 = *it1; n           if (s1.size() <= s2.size()) { n             int k = s2.size() - s1.size(); n             int j = 0; n             for (; k < s2.size(); ++k) { n               if (s2[k] == s1[j]) n                 j++; n               else n                 break; n             } n             if (j == s1.size()) flag = 1; n           } n         } n       } n       if (flag == 0) st1[i].insert(*it); n     } n   } n   cout << c << endl; n   for (map<string, int>::iterator it = m.begin(); it != m.end(); ++it) { n     cout << it->first <<     << st1[it->second].size() <<    ; n     for (set<string>::iterator it1 = st1[it->second].begin(); n          it1 != st1[it->second].end(); ++it1) n       cout << *it1 <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n struct Point { n   int x, y; n   Point(int x_ = 0, int y_ = 0) : x(x_), y(y_) {} n   Point(std::istream &in) { n     in >> x >> y; n     x *= 2; n     y *= 2; n   } n }; n bool operator<(const Point &a, const Point &b) { n   return (a.x < b.x) || (a.x == b.x && a.y < b.y); n } n bool cmp_sum(const Point &a, const Point &b) { return (a.x + a.y < b.x + b.y); } n bool cmp_diff(const Point &a, const Point &b) { n   return (a.x - a.y < b.x - b.y); n } n int n, k; n vector<Point> gnome, metro; n vector<int> sorted_x, sorted_y; n vector<int> tree; n int curk; n void upd_val(int x, int val, const vector<int> &coords) { n   x = lower_bound(coords.begin(), coords.end(), x) - coords.begin(); n   x += curk; n   tree[x] = min(tree[x], val); n   x /= 2; n   while (x != 1) { n     tree[x] = min(tree[x * 2], tree[x * 2 + 1]); n     x /= 2; n   } n } n int get_min_val(int l, int r, const vector<int> &coords) { n   l = lower_bound(coords.begin(), coords.end(), l) - coords.begin(); n   r = lower_bound(coords.begin(), coords.end(), r) - coords.begin(); n   l += curk; n   r += curk; n   int res = INF; n   while (l < r) { n     res = min(res, min(tree[l], tree[r])); n     l = (l + 1) / 2; n     r = (r - 1) / 2; n   } n   if (l == r) { n     res = min(res, tree[l]); n   } n   return res; n } n void shrink(vector<int> &coord) { n   sort(coord.begin(), coord.end()); n   coord.resize(unique(coord.begin(), coord.end()) - coord.begin()); n } n template <typename T> n std::vector<int> argsort(const std::vector<T> &vals, bool reverse = false) { n   vector<int> result(vals.size()); n   for (int i = 0; i < int(vals.size()); ++i) { n     result[i] = i; n   } n   sort(result.begin(), result.end(), n        [&](int a, int b) -> bool { return (vals[a] < vals[b]); }); n   if (reverse) { n     std::reverse(result.begin(), result.end()); n   } n   return result; n } n void get_min_dist(const std::vector<Point> &gnome, std::vector<Point> metro, n                   std::vector<int> &result) { n   sorted_x.clear(); n   sorted_y.clear(); n   for (auto &x : gnome) { n     sorted_x.push_back(x.x); n     sorted_y.push_back(x.y); n   } n   for (auto &x : metro) { n     sorted_x.push_back(x.x); n     sorted_y.push_back(x.y); n   } n   shrink(sorted_x); n   shrink(sorted_y); n   int nn = gnome.size(); n   result.assign(nn, INF); n   auto indices = argsort(gnome); n   sort(metro.begin(), metro.end()); n   curk = 2; n   while (int(sorted_y.size()) > curk) curk *= 2; n   { n     tree.assign(2 * curk, INF); n     int l = 0, r = 0; n     while (l < nn) { n       int ind = indices[l]; n       while (r < k && metro[r].x <= gnome[ind].x) { n         upd_val(metro[r].y, -metro[r].x - metro[r].y, sorted_y); n         ++r; n       } n       result[ind] = min(result[ind], n                         get_min_val(sorted_y.front(), gnome[ind].y, sorted_y) + n                             gnome[ind].x + gnome[ind].y); n       ++l; n     } n   } n   { n     tree.assign(2 * curk, INF); n     int l = 0, r = 0; n     while (l < nn) { n       int ind = indices[l]; n       while (r < k && metro[r].x <= gnome[ind].x) { n         upd_val(metro[r].y, -metro[r].x + metro[r].y, sorted_y); n         ++r; n       } n       result[ind] = min(result[ind], n                         get_min_val(gnome[ind].y, sorted_y.back(), sorted_y) + n                             gnome[ind].x - gnome[ind].y); n       ++l; n     } n   } n   reverse(metro.begin(), metro.end()); n   reverse(indices.begin(), indices.end()); n   { n     tree.assign(2 * curk, INF); n     int l = 0, r = 0; n     while (l < nn) { n       int ind = indices[l]; n       while (r < k && metro[r].x >= gnome[ind].x) { n         upd_val(metro[r].y, metro[r].x - metro[r].y, sorted_y); n         ++r; n       } n       result[ind] = min(result[ind], n                         get_min_val(sorted_y.front(), gnome[ind].y, sorted_y) - n                             gnome[ind].x + gnome[ind].y); n       ++l; n     } n   } n   { n     tree.assign(2 * curk, INF); n     int l = 0, r = 0; n     while (l < nn) { n       int ind = indices[l]; n       while (r < k && metro[r].x >= gnome[ind].x) { n         upd_val(metro[r].y, metro[r].x + metro[r].y, sorted_y); n         ++r; n       } n       result[ind] = min(result[ind], n                         get_min_val(gnome[ind].y, sorted_y.back(), sorted_y) - n                             gnome[ind].x - gnome[ind].y); n       ++l; n     } n   } n } n int find_dist(pair<pair<int, int>, pair<int, int> > rect, const Point &pnt) { n   int sum = pnt.x + pnt.y; n   int diff = pnt.x - pnt.y; n   int sum_dist = n       max(0, -min(rect.first.second, sum) + max(rect.first.first, sum)); n   int diff_dist = n       max(0, -min(rect.second.second, diff) + max(rect.second.first, diff)); n   return max(sum_dist, diff_dist); n } n void get_all_min_dist(vector<pair<pair<int, int>, pair<int, int> > > rect, n                       vector<Point> metro, vector<int> &dist) { n   dist.assign(n, INF); n   vector<Point> ok_points; n   for (int i = 0; i < n; ++i) { n     const auto &cr = rect[i]; n     int a, b, c, d; n     tie(a, b) = cr.first; n     tie(c, d) = cr.second; n     ok_points.emplace_back((a + c) / 2, (a - c) / 2); n     ok_points.emplace_back((a + d) / 2, (a - d) / 2); n     ok_points.emplace_back((b + c) / 2, (b - c) / 2); n     ok_points.emplace_back((b + d) / 2, (b - d) / 2); n   } n   vector<int> tmp; n   get_min_dist(ok_points, metro, tmp); n   for (int i = 0; i < n * 4; ++i) { n     dist[i / 4] = min(dist[i / 4], tmp[i]); n   } n   vector<int> sorted_sum; n   vector<int> sorted_diff; n   for (auto &pnt : rect) { n     sorted_sum.push_back(pnt.first.first); n     sorted_sum.push_back(pnt.first.second); n     sorted_diff.push_back(pnt.second.first); n     sorted_diff.push_back(pnt.second.second); n   } n   for (auto &pnt : metro) { n     sorted_sum.push_back(pnt.x + pnt.y); n     sorted_diff.push_back(pnt.x - pnt.y); n   } n   shrink(sorted_sum); n   shrink(sorted_diff); n   sort(metro.begin(), metro.end(), cmp_sum); n   curk = 2; n   while (curk < int(sorted_diff.size())) curk *= 2; n   vector<pair<pair<int, int>, pair<int, int> > > segment; n   for (int i = 0; i < n; ++i) { n     segment.emplace_back(make_pair(rect[i].first.first, i), rect[i].second); n     if (rect[i].first.first != rect[i].first.second) { n       segment.emplace_back(make_pair(rect[i].first.second, i), rect[i].second); n     } n   } n   sort(segment.begin(), segment.end()); n   { n     tree.assign(curk * 2, INF); n     int nn = segment.size(); n     int l = 0, r = 0; n     while (l < nn) { n       while (r < k && metro[r].x + metro[r].y <= segment[l].first.first) { n         upd_val(metro[r].x - metro[r].y, -metro[r].y - metro[r].x, sorted_diff); n         ++r; n       } n       int ind = segment[l].first.second; n       dist[ind] = n           min(dist[ind], get_min_val(segment[l].second.first, n                                      segment[l].second.second, sorted_diff) + n                              segment[l].first.first); n       ++l; n     } n   } n   reverse(metro.begin(), metro.end()); n   reverse(segment.begin(), segment.end()); n   { n     tree.assign(curk * 2, INF); n     int nn = segment.size(); n     int l = 0, r = 0; n     while (l < nn) { n       while (r < k && metro[r].x + metro[r].y >= segment[l].first.first) { n         upd_val(metro[r].x - metro[r].y, metro[r].x + metro[r].y, sorted_diff); n         ++r; n       } n       int ind = segment[l].first.second; n       dist[ind] = n           min(dist[ind], get_min_val(segment[l].second.first, n                                      segment[l].second.second, sorted_diff) - n                              segment[l].first.first); n       ++l; n     } n   } n   sort(metro.begin(), metro.end(), cmp_diff); n   segment.clear(); n   for (int i = 0; i < n; ++i) { n     segment.emplace_back(make_pair(rect[i].second.first, i), rect[i].first); n     if (rect[i].second.first != rect[i].second.second) { n       segment.emplace_back(make_pair(rect[i].second.second, i), rect[i].first); n     } n   } n   sort(segment.begin(), segment.end()); n   curk = 2; n   while (curk < int(sorted_sum.size())) curk *= 2; n   { n     tree.assign(curk * 2, INF); n     int nn = segment.size(); n     int l = 0, r = 0; n     while (l < nn) { n       while (r < k && metro[r].x - metro[r].y <= segment[l].first.first) { n         upd_val(metro[r].x + metro[r].y, metro[r].y - metro[r].x, sorted_sum); n         ++r; n       } n       int ind = segment[l].first.second; n       dist[ind] = n           min(dist[ind], get_min_val(segment[l].second.first, n                                      segment[l].second.second, sorted_sum) + n                              segment[l].first.first); n       ++l; n     } n   } n   reverse(metro.begin(), metro.end()); n   reverse(segment.begin(), segment.end()); n   { n     tree.assign(curk * 2, INF); n     int nn = segment.size(); n     int l = 0, r = 0; n     while (l < nn) { n       while (r < k && metro[r].x - metro[r].y >= segment[l].first.first) { n         upd_val(metro[r].x + metro[r].y, metro[r].x - metro[r].y, sorted_sum); n         ++r; n       } n       int ind = segment[l].first.second; n       dist[ind] = n           min(dist[ind], get_min_val(segment[l].second.first, n                                      segment[l].second.second, sorted_sum) - n                              segment[l].first.first); n       ++l; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> k; n   for (int i = 0; i < n; ++i) { n     gnome.emplace_back(std::cin); n   } n   for (int i = 0; i < k; ++i) { n     metro.emplace_back(std::cin); n   } n   int min_x = INF, max_x = -INF; n   int min_y = INF, max_y = -INF; n   for (const auto &pnt : gnome) { n     min_x = min(min_x, pnt.x + pnt.y); n     max_x = max(max_x, pnt.x + pnt.y); n     min_y = min(min_y, pnt.x - pnt.y); n     max_y = max(max_y, pnt.x - pnt.y); n   } n   int result = (max(max_x - min_x, max_y - min_y) + 1) / 2; n   if (n > 1 && k) { n     vector<int> dist; n     get_min_dist(gnome, metro, dist); n     auto indices = argsort(dist, true); n     vector<pair<pair<int, int>, pair<int, int> > > all_rect; n     vector<int> add_dist; n     min_x = INF, max_x = -INF; n     min_y = INF, max_y = -INF; n     for (int i = 0; i < n; ++i) { n       const auto &pnt = gnome[indices[i]]; n       min_x = min(min_x, pnt.x + pnt.y); n       max_x = max(max_x, pnt.x + pnt.y); n       min_y = min(min_y, pnt.x - pnt.y); n       max_y = max(max_y, pnt.x - pnt.y); n       int dist = (max(max_x - min_x, max_y - min_y) + 1) / 2; n       add_dist.push_back(dist); n       all_rect.emplace_back(make_pair(max_x - dist, min_x + dist), n                             make_pair(max_y - dist, min_y + dist)); n     } n     result = min(result, dist[indices[0]]); n     vector<int> new_dist; n     get_all_min_dist(all_rect, metro, new_dist); n     for (int i = 0; i < n - 1; ++i) { n       int t1 = add_dist[i]; n       int t2 = new_dist[i]; n       int t3 = dist[indices[i + 1]]; n       int x = (max(0, min(2 * t2, t3 + t2 - t1)) + 1) / 2; n       result = min(result, max(t1 + x, t3 + t2 - x)); n     } n   } n   result = (result + 1) / 2; n   cout << result <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using P = pair<int, int>; n constexpr ll INF = (1LL << 30) - 1LL; n constexpr ll LINF = (1LL << 60) - 1LL; n constexpr ll MOD = 1e9 + 7; n template <typename T> n void chmin(T &a, T b) { n   a = min(a, b); n } n template <typename T> n void chmax(T &a, T b) { n   a = max(a, b); n } n template <typename T> n struct Median { n   priority_queue<T> smq; n   priority_queue<T, vector<T>, greater<T>> lgq; n   void push(T x) { n     if (smq.empty()) { n       smq.push(x); n       return; n     } n     T t = smq.top(); n     if (smq.size() > lgq.size()) { n       if (t <= x) { n         lgq.push(x); n       } else { n         lgq.push(t); n         smq.pop(); n         smq.push(x); n       } n     } else { n       if (t >= x) { n         smq.push(x); n       } else { n         lgq.push(x); n         smq.push(lgq.top()); n         lgq.pop(); n       } n     } n   } n   inline T get() { return smq.top(); } n }; n template <typename T> n struct BinaryIndexedTree { n   vector<T> node; n   int n; n   BinaryIndexedTree(int n) : n(n) { node.assign(++n, 0); } n   void add(int k, T x) { n     for (++k; k < n; k += k & -k) { n       node[k] += x; n     } n   } n   T sum(int k) { n     if (k < 0) { n       return 0; n     } n     T res = 0; n     for (++k; k > 0; k -= k & -k) { n       res += node[k]; n     } n     return res; n   } n }; n int main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   vector<int> p(n), pos(n + 1); n   for (int i = 0; i < n; i++) { n     cin >> p[i]; n     pos[p[i]] = i; n   } n   BinaryIndexedTree<ll> bit(n + 1), bit2(n + 1); n   for (int i = 0; i < n; i++) { n     bit2.add(i, 1); n   } n   ll res = 0; n   Median<ll> med; n   for (int k = 1; k <= n; k++) { n     res += bit.sum(n - 1) - bit.sum(pos[k]); n     res -= min(bit.sum(pos[k] - 1), bit.sum(n - 1) - bit.sum(pos[k])); n     bit.add(pos[k], 1); n     bit2.add(pos[k], -1); n     int t; n     if (k % 2 > 0) { n       med.push(pos[k]); n     } n     if (k > 1) { n       t = med.get(); n       if (t < pos[k]) { n         res += bit2.sum(pos[k]) - bit2.sum(t - 1); n       } else { n         res += bit2.sum(t) - bit2.sum(pos[k] - 1); n       } n       if (k % 2 == 0) { n         med.push(pos[k]); n       } n     } n     cout << res; n     if (k < n) { n       cout <<    ; n     } else { n       cout << endl; n     } n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n long long MOD = 998244353; n double eps = 1e-12; n void solve() { n   long long n, k; n   cin >> n >> k; n   if (n == 1 && k == 10) { n     cout <<  -1  n          <<   n ; n     return; n   } n   if (k == 10) { n     cout << 1; n     for (int i = 1; i <= n - 1; i++) { n       cout << 0; n     } n   } else { n     for (int i = 1; i <= n; i++) { n       cout << k; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, a; n   cin >> n; n   vector<int> c(3 * 1e5, 0); n   for (int i = 1; i <= n / 2; i++) { n     cin >> a; n     if (a >= i) c[1e5 + a - i]++; n   } n   if (n % 2) { n     cin >> a; n     if (a >= n / 2 + 1) c[1e5 + a - (n / 2) - 1]++; n   } n   for (int i = n / 2; i > 0; i--) { n     cin >> a; n     if (a >= i) c[1e5 + a - i]++; n   } n   int ans = 0; n   for (int i = 0; i < 3 * 1e5; i++) ans = max(ans, c[i]); n   cout << n - ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n int sumo[maxn], sume[maxn]; n int main() { n   int n; n   ios::sync_with_stdio(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int t; n     cin >> t; n     if (i % 2) n       sumo[i] = sumo[i - 1] + t; n     else n       sumo[i] = sumo[i - 1]; n     if (i % 2 == 0) n       sume[i] = sume[i - 1] + t; n     else n       sume[i] = sume[i - 1]; n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     int cnto = sumo[i - 1] + (sume[n] - sume[i]); n     int cnte = sume[i - 1] + (sumo[n] - sumo[i]); n     if (cnto == cnte) { n       ans++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int BIG = 1e9 + 239; n const int M = 2010; n int n, m, kol[M], id[M][M]; n vector<int> v[M]; n bitset<M> a[M]; n string s; n bool used[M], need[M]; n vector<pair<int, int> > ans; n inline void upd(int s, int f) { n   used[s] = false; n   for (int i = 0; i < n; i++) n     if (used[i]) { n       if (id[s][i] == -1) continue; n       int bk = (int)v[i].back(); n       id[bk][i] = id[s][i]; n       v[i][id[s][i]] = bk; n       v[i].pop_back(); n       id[s][i] = -1; n     } n   for (int i = 0; i < m; i++) n     if (a[s][i]) kol[i]--; n   bool ch = false; n   for (int i = 0; i < m; i++) n     if (kol[i] < 2 && a[f][i] == 1) a[f][i] = 0, ch = true; n   if (ch) { n     for (int i = 0; i < n; i++) need[i] = true; n     for (int i : v[f]) need[i] = false; n     for (int i = 0; i < n; i++) n       if (need[i] && used[i] && i != f && ((a[f] & a[i]) == a[f])) { n         id[i][f] = (int)v[f].size(); n         v[f].push_back(i); n       } n   } n } n inline void solve() { n   ans.clear(); n   cin >> n >> m; n   for (int i = 0; i < n; i++) v[i].clear(); n   for (int i = 0; i < n; i++) a[i] = 0; n   for (int i = 0; i < m; i++) kol[i] = 0; n   for (int i = 0; i < m; i++) { n     cin >> s; n     for (int x = 0; x < n; x++) { n       a[x][i] = (s[x] -  0 ); n       if (s[x] ==  1 ) kol[i]++; n     } n   } n   for (int i = 0; i < m; i++) n     if (kol[i] < 2) n       for (int x = 0; x < n; x++) a[x][i] = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) id[i][j] = -1; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) n       if (i != j) n         if ((a[i] & a[j]) == a[i]) { n           id[j][i] = (int)v[i].size(); n           v[i].push_back(j); n         } n   for (int i = 0; i < n; i++) used[i] = true; n   for (int iter = 0; iter < n - 1; iter++) { n     int s = -1; n     for (int i = 0; i < n; i++) n       if (used[i] && !v[i].empty()) { n         s = i; n         break; n       } n     if (s == -1) { n       cout <<  NO n ; n       return; n     } n     int f = v[s].back(); n     ans.push_back(make_pair(s, f)); n     upd(s, f); n   } n   cout <<  YES n ; n   for (pair<int, int> t : ans) n     cout << (t.first + 1) <<     << (t.second + 1) <<   n ; n } n int main() { n   cin.sync_with_stdio(0); n   int T; n   cin >> T; n   while (T--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cout <<  INTERCAL n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N, M; n   cin >> N >> M; n   if (N == 1) { n     if (M == 2) { n       cout << 0 << endl; n       cout <<  1 1  << endl <<  1 2  << endl <<  1 1  << endl; n       return 0; n     } n     cout << 1 << endl; n     cout << 1 <<     << M <<     << 1 <<     << 1 << endl; n     for (int i = 0; i < M; i++) cout << 1 <<     << i + 1 << endl; n     cout << 1 <<     << 1 << endl; n   } else if (M == 1) { n     if (N == 2) { n       cout << 0 << endl; n       cout <<  1 1  << endl <<  2 1  << endl <<  1 1  << endl; n       return 0; n     } n     cout << 1 << endl; n     cout << N <<     << 1 <<     << 1 <<     << 1 << endl; n     for (int i = 0; i < N; i++) cout << i + 1 <<     << 1 << endl; n     cout << 1 <<     << 1 << endl; n   } else if (N % 2 == 0) { n     cout << 0 << endl; n     int k = 1; n     cout << 1 <<     << 1 << endl; n     while (k <= N) { n       for (int i = 2; i <= M; i++) cout << k <<     << i << endl; n       k++; n       for (int i = M; i >= 2; i--) cout << k <<     << i << endl; n       k++; n     } n     for (int i = N; i >= 1; i--) cout << i <<     << 1 << endl; n   } else if (M % 2 == 0) { n     cout << 0 << endl; n     int k = 1; n     cout << 1 <<     << 1 << endl; n     while (k <= M) { n       for (int i = 2; i <= N; i++) cout << i <<     << k << endl; n       k++; n       for (int i = N; i >= 2; i--) cout << i <<     << k << endl; n       k++; n     } n     for (int i = M; i >= 1; i--) cout << 1 <<     << i << endl; n   } else { n     cout << 1 << endl; n     cout << N <<     << M <<     << 1 <<     << 1 << endl; n     int i = 1; n     while (i <= N) { n       for (int j = 1; j <= M; j++) cout << i <<     << j << endl; n       i++; n       if (i > N) break; n       for (int j = M; j >= 1; j--) cout << i <<     << j << endl; n       i++; n     } n     cout << 1 <<     << 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int x[1000000]; n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> x[i]; n   sort(x, x + n); n   int sol = x[n - 1] - x[0]; n   int p = n / 2 - 1; n   for (int i = 0; i <= p; i++) sol = min(sol, x[n - 1 - (p - i)] - x[i]); n   cout << sol << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 100, inF = 1e6 + 10; n int n, k, u, v, c, maxi, a[N], sz[N]; n bool ok; n vector<int> nei[N]; n int get_sz(int v, int par = -1) { n   for (int u : nei[v]) n     if (u != par) sz[v] += get_sz(u, v); n   return ++sz[v]; n } n int dfs(int v, int par = -1) { n   int dp = (a[v] < c ? -inF : 1); n   int mx1 = 0, mx2 = 0; n   for (int u : nei[v]) n     if (u != par) { n       int DP = dfs(u, v); n       if (DP == sz[u]) n         dp += DP; n       else { n         mx2 = max(mx2, DP); n         if (mx2 > mx1) swap(mx1, mx2); n       } n     } n   ok |= (dp + mx1 + mx2) >= k; n   if (a[v] < c) return 0; n   return dp + mx1; n } n bool check() { n   ok = false; n   dfs(min_element(a, a + n) - a); n   return ok; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0); n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n - 1; i++) { n     cin >> u >> v; n     nei[--u].push_back(--v); n     nei[v].push_back(u); n   } n   get_sz(min_element(a, a + n) - a); n   int l = 0, r = inF; n   while (r - l > 1) { n     c = (l + r) >> 1; n     if (check()) n       l = c; n     else n       r = c; n   } n   cout << l; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 8; n int a[N], fa[N][20]; n vector<int> E[N]; n long long res; n void dfs(int x, int f) { n   fa[x][0] = f; n   long long temp = a[f]; n   for (int i = 1; i < 20; i++) { n     fa[x][i] = fa[fa[x][i - 1]][i - 1]; n     temp = min(temp, (i + 1ll) * a[fa[x][i]]); n   } n   if (f != x) res += temp + a[x]; n   for (int &e : E[x]) n     if (e != f) dfs(e, x); n } n int main() { n   ios::sync_with_stdio(false); n   int n, rt = 0; n   a[0] = INT_MAX; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i], rt = a[rt] < a[i] ? rt : i; n   for (int i = 1, u, v; i < n; i++) n     cin >> u >> v, E[u].push_back(v), E[v].push_back(u); n   dfs(rt, rt); n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int INF = 1e9 + 5; n const long long LINF = LLONG_MAX; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     if (360 % (180 - n) == 0) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   long int k, col = 0; n   cin >> n >> m >> k; n   vector<int> desk; n   for (int i = 1; i < n + 1; ++i) { n     desk.push_back(m * i); n   } n   for (int i = 1; i < desk.size() + 1; ++i) { n     if (k <= desk[i - 1] * 2) { n       cout << i <<    ; n       if (k % 2 == 0) { n         if (i > 1) n           cout << (k - desk[i - 2] * 2) / 2 <<   R ; n         else n           cout << k / 2 <<   R ; n       } else { n         if (i > 1) n           cout << ((k + 1) - desk[i - 2] * 2) / 2 <<   L ; n         else n           cout << (k + 1) / 2 <<   L ; n       } n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n using namespace std; n int main() { n   int q; n   long long int a, b, c; n   long long int ans = 0; n   cin >> q; n   while (q--) { n     cin >> a >> b >> c; n     ans = (a + b + c) / 2; n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n, bt[1000001] = {}, ar[1000001] = {}; n vector<int> v; n int main() { n   ios ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> t; n   while (t--) { n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> ar[i]; n       ar[i] = i - ar[i]; n       bt[i] = 0; n     } n     int x = 0; n     while (!bt[x]) { n       v.push_back(x); n       bt[x] = v.size(); n       x = ar[x]; n     } n     cout << v.size() - bt[x] + 1 <<   n ; n     for (int i = bt[x] - 1; i < v.size(); i++) { n       cout << v[i] + 1; n       if (i < v.size() - 1) { n         cout <<    ; n       } n     } n     cout <<   n ; n     v.clear(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n void solve() { n   int r1, r2, c1, c2, d1, d2; n   cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; n   int a; n   bool ans = false; n   for (a = 1; a <= 9; ++a) { n     int b = r1 - a; n     int c = c1 - a; n     int d = d1 - a; n     if (a > 0 && a < 10 && b > 0 && b < 10 && c > 0 && c < 10 && d > 0 && n         d < 10) { n       if (a != b && b != c && c != d && b != d && a != d && a != c) { n         if (a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 && n             a + d == d1 && b + c == d2) { n           cout << a <<     << b <<   n ; n           cout << c <<     << d <<   n ; n           ans = true; n         } n       } n     } n   } n   if (!ans) cout <<  -1 ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   while (cin >> s) { n     int ans = 1e6; n     for (int i =  a ; i <=  z ; i++) { n       int t = 0, k = 0; n       for (int j = 0; j < s.length(); j++) { n         if (s[j] == i) n           t = 0; n         else n           t++; n         k = max(k, t); n       } n       ans = min(ans, k); n     } n     cout << ans + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> ans; n void solve() { n   long long int i, a, b, c, d, n; n   cin >> a >> b >> c >> d; n   n = a + b + c + d; n   string s =   ; n   while (a > 0) { n     s +=  0 ; n     a--; n   } n   while (c > 0) { n     s +=  2 ; n     c--; n   } n   i = 0; n   while (b > 0 && i < s.length()) { n     if (s[i] ==  0 ) { n       s.insert(i + 1, 1,  1 ); n       b--; n     } else { n       break; n     } n     i = i + 2; n   } n   while (d > 0 && i < s.length()) { n     if (s[i] ==  2 ) { n       s.insert(i + 1, 1,  3 ); n       d--; n     } n     i = i + 2; n   } n   while (b > 0 && i < s.length()) { n     if (s[i] ==  2 ) { n       s.insert(i + 1, 1,  1 ); n       b--; n     } n     i = i + 2; n   } n   if (d > 0 && s[0] ==  2 ) { n     s.insert(0, 1,  3 ); n     d--; n   } n   if (b > 0 && (s[0] ==  0  || s[0] ==  2 )) { n     s.insert(0, 1,  1 ); n     b--; n   } n   if (b > 0 && (s[s.length() - 1] ==  0  || s[s.length() - 1] ==  2 )) { n     s.insert(s.length() - 1, 1,  1 ); n     b--; n   } n   while (b > 0) { n     s +=  1 ; n     b--; n   } n   while (d > 0) { n     s +=  3 ; n     d--; n   } n   for (i = 1; i < n; i++) { n     if (abs(s[i] - s[i - 1]) != 1) { n       cout <<  NO ; n       return; n     } n   } n   cout <<  YES n ; n   for (i = 0; i < n; i++) cout << s[i] <<    ; n } n int main() { n   long long int t; n   t = 1; n   while (t--) { n     solve(); n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> E[65600]; n vector<pair<int, int> > V; n int main() { n   int n; n   scanf( %d , &n); n   queue<int> Q; n   int degree[65600 + 10], Xsum[65600 + 10]; n   for (int i = 0; i < n; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     degree[i] = a; n     Xsum[i] = b; n     if (degree[i] == 1) Q.push(i); n   } n   while (!Q.empty()) { n     int u = Q.front(); n     Q.pop(); n     if (degree[u] == 0) continue; n     int othernode = Xsum[u]; n     V.push_back(make_pair(u, othernode)); n     degree[othernode]--; n     degree[u]--; n     Xsum[othernode] = Xsum[othernode] ^ u; n     if (degree[othernode] == 1) Q.push(othernode); n   } n   printf( %d n , V.size()); n   for (int i = 0; i < V.size(); i++) printf( %d %d n , V[i].first, V[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long int; n using dl = double; n const int N = 2e5 + 10; n ll aarray[200000 + 10]; n ll magic[101][101]; n vector<ll> primes; n bool prime[1000001]; n int main() { n   ios_base::sync_with_stdio(false); n   string str, ptr, ans =    ; n   ll a, b, c, d, e, f, x = INT_MAX, y, k, t, A = 0, mod, B = 0, L, j, i, l, r, n                        m, n, C = 0, sum = 0, sum1 = 0; n   vector<ll> v, v1; n   queue<ll> qu; n   cin >> str; n   cin >> n; n   ll cnt = 0, fla = 0; n   for (i = 1; i <= n; i++) { n     cin >> ptr; n     if (ptr.size() >= str.size()) { n       if (ptr.substr(0, str.size()) == str) { n         if (ptr < ans || ans ==    ) ans = ptr; n       } n     } n   } n   if (ans ==    ) n     cout << str << endl; n   else n     cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   long long int t = 1; n   while (t--) { n     long long int k, b, n; n     cin >> k >> b >> n; n     long long int s = 0; n     long long int a[n]; n     map<long long int, vector<long long int> > mp; n     mp[0].push_back(-1); n     for (long long int i = 0; i < n; i++) { n       cin >> a[i]; n       s = s + a[i]; n       s = s % (k - 1); n       mp[s].push_back(i); n     } n     long long int an = 0; n     if (b == k - 1 || b == 0) { n       map<long long int, long long int> mp; n       mp[0]++; n       long long int an = 0, z = 0, ts = 0; n       for (long long int i = 0; i < n; i++) { n         ts = (ts + a[i]) % (k - 1); n         if (a[i] == 0) n           z++; n         else n           z = 0; n         long long int tmp = (ts + (k - 1) - b) % (k - 1); n         if (b == 0) n           an += z; n         else n           an = an + mp[tmp] - z; n         mp[ts]++; n       } n       cout << an; n     } else { n       for (auto x : mp) { n         long long int y = x.first; n         y = (y + b) % (k - 1); n         for (long long int i = 0; i < x.second.size(); i++) { n           long long int l = n               lower_bound(mp[y].begin(), mp[y].end(), x.second[i]) - n               mp[y].begin(); n           an = an + max(0ll, (long long int)(mp[y].size() - l)); n         } n       } n       cout << an; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unordered_set<long long int> s; n void fun(long long int l, long long int r, long long int n) { n   if (n > r) n     return; n   else if (n <= r and n >= l) { n     s.insert(n); n   } n   fun(l, r, n * 2); n   fun(l, r, n * 3); n } n void solve() { n   long long int l, r; n   cin >> l >> r; n   fun(l, r, 1); n   cout << s.size() << endl; n } n signed main() { n   long long int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct mat { n   int num[4][4]; n }; n int p[100009]; n mat mult(mat &a, mat &b) { n   mat ret; n   for (int i = 0; i < 4; i++) n     for (int j = 0; j < 4; j++) { n       long long t = 0; n       for (int k = 0; k < 4; k++) t += 1ll * a.num[i][k] * b.num[k][j]; n       ret.num[i][j] = t % 1000000007; n     } n   return ret; n } n int cal(string &a, string &b) { n   if (b.size() > a.size()) return 0; n   int ret = 0; n   p[0] = -1; n   for (int j, i = 0; b[i]; i++) { n     for (j = p[i]; j >= 0 && b[i] != b[j]; j = p[j]) n       ; n     p[i + 1] = j + 1; n   } n   for (int j = 0, i = 0; a[i]; i++) { n     for (; j >= 0 && a[i] != b[j]; j = p[j]) n       ; n     j++; n     if (j == b.size()) ret++, j = p[j]; n   } n   return ret; n } n mat m1, m2; n int query(long long n, string &q) { n   if (n == 1) { n     return q ==  a  ? 1 : 0; n   } n   if (n == 2) { n     return q ==  b  ? 1 : 0; n   } n   string s1 =  a , s2 =  b , s =  b ; n   for (n -= 2; n && s1.size() < q.size(); n--, s1 = s2, s2 = s) s = s2 + s1; n   int f1 = cal(s1, q), f2 = cal(s, q); n   if (!n) return f2; n   s = s2.substr(s2.size() - q.size() + 1, q.size() - 1) + n       s2.substr(0, q.size() - 1); n   int t1 = cal(s, q); n   s = s1.substr(s1.size() - q.size() + 1, q.size() - 1) + n       s1.substr(0, q.size() - 1); n   int t2 = cal(s, q); n   m1.num[0][0] = m1.num[0][1] = m1.num[0][2] = m1.num[1][0] = m1.num[2][2] = n       m1.num[3][3] = 1; n   m2.num[0][0] = m2.num[0][1] = m2.num[0][3] = m2.num[1][0] = m2.num[2][2] = n       m2.num[3][3] = 1; n   mat res, t = mult(m2, m1); n   bool flag = 0; n   if (n % 2) res = m1, flag = 1; n   for (n /= 2; n; n >>= 1, t = mult(t, t)) n     if (n & 1) { n       if (!flag) n         res = t, flag = 1; n       else n         res = mult(res, t); n     } n   return (1ll * res.num[0][0] * f2 + 1ll * res.num[0][1] * f1 + n           1ll * res.num[0][2] * t1 + 1ll * res.num[0][3] * t2) % n          1000000007; n } n int main() { n   long long n, m; n   cin >> n >> m; n   string s; n   while (m--) cin >> s, cout << query(n, s) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int n; n   cin >> n; n   long long int one = (n / 2) + (n / 3) + (n / 5) + (n / 7), n                 two = (n / 6) + (n / 10) + (n / 14) + (n / 15) + (n / 21) + n                       (n / 35), n                 three = (n / (2 * 3 * 5)) + (n / (3 * 5 * 7)) + n                         (n / (2 * 5 * 7)) + (n / (2 * 3 * 7)), n                 four = (n / (2 * 3 * 5 * 7)); n   cout << n - one + two - three + four; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, k; n long long dc(long long x, long long y) { n   long long r; n   while (y) { n     r = x % y; n     x = y; n     y = r; n   } n   return x; n } n int main() { n   cin >> n >> m >> k; n   if (2 * n * m % k != 0) n     cout <<  NO ; n   else { n     int ok = 0; n     cout <<  YES  <<   n ; n     if (k % 2 == 0) { n       k = k / 2; n       ok = 1; n     } n     long long d = dc(n, k); n     k = k / d; n     long long x = n / d; n     d = dc(m, k); n     k = k / d; n     long long y = m / d; n     if (ok) { n       cout << 0 <<     << 0 <<   n ; n       cout << x <<     << 0 <<   n ; n       cout << 0 <<     << y <<   n ; n     } else { n       cout << 0 <<     << 0 <<   n ; n       if (x < n) n         x *= 2; n       else if (y < m) n         y *= 2; n       cout << x <<     << 0 <<   n ; n       cout << 0 <<     << y <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q, k; n   cin >> q; n   long long l, r, d, x; n   for (k = 0; k < q; ++k) { n     cin >> l >> r >> d; n     if (d < l || d > r) n       x = d; n     else { n       if (r % d == 0) n         x = r + d; n       else n         x = r + (d - (r % d)); n     } n     cout << x << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T solve(T n, T k) { n   vector<T> arr(n); n   for (T i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   T sum = 0; n   sort(arr.begin(), arr.end(), greater<int>()); n   for (int i = 2 * k; i < n; i++) { n     sum += arr[i]; n   } n   for (T i = 0; i < k; ++i) { n     sum += (arr[i + k] / arr[i]); n   } n   return sum; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long n, k; n     cin >> n >> k; n     cout << solve(n, k) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 10, M = 1e6 + 100, MOD = 1e9 + 7, ML = 25; n int a[M], ne[M]; n map<int, bool> mp[M]; n vector<int> ve[M], adj[M]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   for (int i = 1; i <= n; i++) { n     adj[i].push_back(INF); n     sort(adj[i].begin(), adj[i].end()); n     ne[i] = i + 1; n   } n   ne[n] = -1; n   int l = 0, r = 0, cnt = 0, link = 1; n   while (link != -1) { n     int la = r; n     a[r++] = link; n     link = ne[link]; n     while (l < r) { n       int v = a[l++]; n       ve[cnt].push_back(v); n       int u = link, la = -1; n       while (u != -1) { n         int z = *lower_bound(adj[v].begin(), adj[v].end(), u); n         if (z != u) { n           if (u == link) link = ne[link]; n           if (la != -1) ne[la] = ne[u]; n           a[r++] = u; n         } else n           la = u; n         u = ne[u]; n       } n     } n     cnt++; n   } n   printf( %d n , cnt); n   for (int i = 0; i < cnt; i++) { n     printf( %d  , ve[i].size()); n     for (int u : ve[i]) printf( %d  , u); n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool check(long long n, long long pos) { return (n & (1 << pos)); } n bool Set(long long n, long long pos) { return (n | (1 << pos)); } n long double LOG(long double b, long double e) { return log(b) / log(e); } n vector<int> v1[200005], v2[200005], comps[200005], vv; n vector<pair<int, int> > v; n int st[200005], en[200005], cnt = 1, level[200005], par[200005]; n bitset<200005> b1, yes; n void solve() { n   int n, a, b, cc; n   cin >> n >> a >> b; n   bool ok = 0; n   cc = b * 10; n   while (1) { n     if (cc >= n) { n       ok = 1; n       break; n     } n     if (a) { n       n /= 2; n       n += 10; n       --a; n     } n     if (cc >= n) { n       ok = 1; n       break; n     } n     if (a == 0) break; n   } n   ok ? cout <<  YES n  : cout <<  NO n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   t = 1; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int q; n vector<pair<int, int> > v; n vector<pair<int, int> > V; n vector<int> amount; n int root = 0; n int en = 100002 - 1; n struct MaximumFlow { n   static const long long int InfCapacity = LLONG_MAX; n   struct Edge { n     int to; n     long long int capacity; n     int rev; n   }; n   vector<vector<Edge> > g; n   void init(int n) { g.assign(n, vector<Edge>()); } n   void add(int i, int j, long long int capacity) { n     Edge e, f; n     e.to = j, f.to = i; n     e.capacity = capacity, f.capacity = 0; n     g[i].push_back(e); n     g[j].push_back(f); n     g[i].back().rev = (int)g[j].size() - 1; n     g[j].back().rev = (int)g[i].size() - 1; n   } n   void addB(int i, int j, long long int capacity) { n     Edge e, f; n     e.to = j, f.to = i; n     e.capacity = capacity, f.capacity = capacity; n     g[i].push_back(e); n     g[j].push_back(f); n     g[i].back().rev = (int)g[j].size() - 1; n     g[j].back().rev = (int)g[i].size() - 1; n   } n   long long int maximumFlow(int s, int t) { n     int n = g.size(); n     vector<int> level(n); n     long long int total = 0; n     bool update; n     do { n       update = false; n       fill(level.begin(), level.end(), -1); n       level[s] = 0; n       queue<int> q; n       q.push(s); n       for (int d = n; !q.empty() && level[q.front()] < d;) { n         int u = q.front(); n         q.pop(); n         if (u == t) d = level[u]; n         for (auto e = g[u].begin(); e != g[u].end(); e++) n           if (e->capacity > 0 && level[e->to] == -1) n             q.push(e->to), level[e->to] = level[u] + 1; n       } n       vector<int> iter(n); n       for (int i = 0; i < n; i++) iter[i] = (int)g[i].size() - 1; n       while (1) { n         long long int f = augment(level, iter, s, t, InfCapacity); n         if (f == 0) break; n         total += f; n         update = true; n       } n     } while (update); n     return total; n   } n   long long int augment(vector<int> &level, vector<int> &iter, int u, int t, n                         long long int f) { n     if (u == t || f == 0) return f; n     int lv = level[u]; n     if (lv == -1) return 0; n     level[u] = -1; n     for (; iter[u] >= 0; --iter[u]) { n       Edge &e = g[u][iter[u]]; n       if (level[e.to] <= lv) continue; n       long long int l = augment(level, iter, e.to, t, min(f, e.capacity)); n       if (l == 0) continue; n       e.capacity -= l; n       g[e.to][e.rev].capacity += l; n       level[u] = lv; n       return l; n     } n     return 0; n   } n }; n MaximumFlow f; n void add_edge(int a, int b, int c) { f.add(a, b, c); } n int b; n int lab[10002]; n int linkk[10002]; n int main() { n   cin >> n >> b >> q; n   while (q--) { n     int c, d; n     scanf( %d%d , &c, &d); n     v.push_back(make_pair(c, d)); n   } n   v.push_back(make_pair(b, n)); n   sort(v.begin(), v.end()); n   int pr = 1; n   int cnt = 0; n   for (int i = 0; i < v.size(); i++) { n     int res = v[i].second - cnt; n     if (res < 0) { n       puts( unfair ); n       return 0; n     } n     V.push_back(make_pair(pr, v[i].first)); n     amount.push_back(res); n     cnt = v[i].second; n     pr = v[i].first + 1; n   } n   int C = 11451; n   for (int i = 0; i < V.size(); i++) { n     linkk[i] = C; n     C++; n   } n   f.init(100002); n   for (int i = 0; i < 5; i++) { n     add_edge(root, i + 1, n / 5); n   } n   for (int i = 1; i <= b; i++) { n     lab[i] = 5 + i; n     add_edge((i % 5) + 1, lab[i], 1); n     add_edge(lab[i], n              linkk[lower_bound(V.begin(), V.end(), make_pair(i, INT_MAX)) - n                    V.begin() - 1], n              1); n   } n   for (int i = 0; i < V.size(); i++) { n     add_edge(linkk[i], en, amount[i]); n   } n   int ans = f.maximumFlow(root, en); n   if (ans == n) { n     puts( fair ); n   } else { n     puts( unfair ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<bool> visited; n vector<vector<int> > adj; n void dfs(int node, long long &s0, long long &s1, int mod) { n   if (mod == 0) n     s0++; n   else n     s1++; n   visited[node] = true; n   for (int i = 0; i < adj[node].size(); i++) { n     if (!visited[adj[node][i]]) { n       dfs(adj[node][i], s0, s1, (mod + 1) % 2); n     } n   } n } n int main() { n   int t = 1; n   while (t--) { n     int n; n     cin >> n; n     adj = vector<vector<int> >(n + 1); n     visited = vector<bool>(n + 1, false); n     for (int i = 0; i < n - 1; i++) { n       int a, b; n       cin >> a >> b; n       adj[a].push_back(b); n       adj[b].push_back(a); n     } n     long long s0 = 0, s1 = 0; n     dfs(1, s0, s1, 0); n     cout << s0 * s1 - n + 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,popcnt,tune=native ) n using namespace std; n const int MN = 3333, inf = 1000000005, mod = 1000000007; n const long long INF = 1000000000000000005LL; n bitset<MN> Z[MN]; n int dist[MN][MN], X[MN], Y[MN]; n inline int d2(int a, int b) { n   return (X[a] - X[b]) * (X[a] - X[b]) + (Y[a] - Y[b]) * (Y[a] - Y[b]); n } n int n; n bool dasie(int x) { n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) Z[i][j] = (i != j && dist[i][j] >= x); n   for (int i = 1; i <= n; ++i) n     for (int j = i + 1; j <= n; ++j) { n       if (Z[i][j] == 0) continue; n       if ((Z[i] & Z[j]).count()) return true; n     } n   return false; n } n int bs() { n   int zd = 0, zg = 1e9 + 5; n   while (zd != zg) { n     int mid = (zd + zg + 1) >> 1; n     if (dasie(mid)) n       zd = mid; n     else n       zg = mid - 1; n   } n   return zd; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d%d , &X[i], &Y[i]); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) dist[i][j] = d2(i, j); n   int ans = bs(); n   double odp = ans; n   odp = sqrt(odp) / 2.0; n   printf( %.9lf , odp); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n, a = INT_MIN, b = INT_MIN; n   cin >> n; n   vector<long long int> v(n); n   for (long long int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   if (n == 1) { n     for (int i = 0; i < 3; i++) { n       cout << 1 <<     << 1 <<   n ; n       cout << (-1) * v[0] <<   n ; n       v[0] = 0; n     } n     return 0; n   } n   cout << 1 <<     << n - 1 <<   n ; n   for (int i = 0; i < n - 1; i++) { n     if (v[i] < 0) { n       int a = v[i] % (n - 1); n       cout << (abs(v[i]) + a * (n)) <<    ; n       v[i] = (a * (n)); n       continue; n     } n     cout << v[i] * (n - 1) <<    ; n     v[i] = v[i] * (n); n   } n   cout <<   n ; n   cout << n <<     << n <<   n ; n   cout << (-1) * v[n - 1] <<   n ; n   v[n - 1] = 0; n   cout << 1 <<     << n <<   n ; n   for (int i = 0; i < n; i++) { n     cout << (-1) * v[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n string to_string(pair<T1, T2> p); n template <typename T1, typename T2, typename T3> n string to_string(tuple<T1, T2, T3> tup); n template <typename T1, typename T2, typename T3, typename T4> n string to_string(tuple<T1, T2, T3, T4> tup); n string to_string(const string& v) { return  {  + v +  } ; } n string to_string(const char* v) { return to_string((string)v); } n string to_string(const bool& v) { return (v ?  True  :  False ); } n string to_string(vector<bool> v) { n   string ret =  [ ; n   int n = (int)v.size(); n   for (int i = 0; i < n - 1; i++) { n     ret +=  [  + to_string(i) +  ](  + to_string(v[i]) +  ),  ; n   } n   ret +=  [  + to_string(n - 1) +  ](  + to_string(v[n - 1]) +  )] ; n   return ret; n } n template <size_t N> n string to_string(bitset<N> b) { n   string ret =   ; n   for (int i = 0; i < N; i++) { n     ret += (char)(b[i] +  0 ); n   } n   return ret; n } n template <typename T> n string to_string(T v) { n   bool ok = true; n   string ret =  [ ; n   int cnt = 0; n   for (auto x : v) { n     if (!ok) { n       ret +=  ,  ; n     } n     ok = false; n     ret +=  [  + to_string(cnt++) +  ](  + to_string(x) +  ) ; n   } n   return ret +  ] ; n } n template <typename T1, typename T2> n string to_string(pair<T1, T2> p) { n   return  {  + to_string(p.first) +  ,   + to_string(p.second) +  } ; n } n template <typename T1, typename T2, typename T3> n string to_string(tuple<T1, T2, T3> tup) { n   return  {  + to_string(get<0>(tup)) +  ,   + to_string(get<1>(tup)) +  ,   + n          to_string(get<2>(tup)) +  } ; n } n template <typename T1, typename T2, typename T3, typename T4> n string to_string(tuple<T1, T2, T3, T4> tup) { n   return  {  + to_string(get<0>(tup)) +  ,   + to_string(get<1>(tup)) +  ,   + n          to_string(get<2>(tup)) +  ,   + to_string(get<3>(tup)) +  } ; n } n void DEBUG() { cerr <<   n ; } n template <typename start, typename... end> n void DEBUG(start first, end... other) { n   cerr <<   |   << to_string(first); n   DEBUG(other...); n } n void solve() { n   int n, k; n   cin >> n >> k; n   if (n / 2 > k || (n == 1 && k != 0)) { n     cout << -1; n     return; n   } n   if (n == 1 && k == 0) { n     cout << 1; n     return; n   } n   int x = k - n / 2 + 1; n   cout << x <<     << 2 * x <<    ; n   for (long long i = 0; i < n - 2; i++) cout << 2 * x + 1 + i <<    ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = (int)1e9 + 7; n const int INF = (int)1e9; n const long long LINF = (long long)1e18; n const long double PI = acos((long double)-1); n const long double EPS = 1e-9; n inline long long gcd(long long a, long long b) { n   long long r; n   while (b) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline long long fpow(long long n, long long k, int p = MOD) { n   long long r = 1; n   for (; k; k >>= 1) { n     if (k & 1) r = r * n % p; n     n = n * n % p; n   } n   return r; n } n template <class T> n inline int chkmin(T& a, const T& val) { n   return a > val ? a = val, 1 : 0; n } n template <class T> n inline int chkmax(T& a, const T& val) { n   return a < val ? a = val, 1 : 0; n } n inline long long isqrt(long long k) { n   long long r = sqrt(k) + 1; n   while (r * r > k) r--; n   return r; n } n inline long long icbrt(long long k) { n   long long r = cbrt(k) + 1; n   while (r * r * r > k) r--; n   return r; n } n inline void addmod(int& a, int val, int p = MOD) { n   if ((a = (a + val)) >= p) a -= p; n } n inline void submod(int& a, int val, int p = MOD) { n   if ((a = (a - val)) < 0) a += p; n } n inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } n inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } n const int MAXN = 654321; n const int NOTFOUND = -1; n struct HashMap { n   int cur, head[MAXN], next[MAXN]; n   long long l[MAXN]; n   int x[MAXN]; n   HashMap() { n     cur = 0; n     fill_n(head, MAXN, 0); n     fill_n(next, MAXN, 0); n   } n   int find(long long key) { n     for (int i = head[key % MAXN]; i; i = next[i]) { n       if (l[i] == key) { n         return x[i]; n       } n     } n     return NOTFOUND; n   } n   void insert(long long key, int val) { n     if (find(key) != NOTFOUND) return; n     l[++cur] = key; n     x[cur] = val; n     next[cur] = head[key % MAXN]; n     head[key % MAXN] = cur; n   } n } hs; n const int maxn = 1000 + 10; n const int maxd = 7000 + 10; n int n; n long long k; n long long a[maxn]; n vector<long long> dvs; n pair<int, long long> f[maxn][maxd]; n int r[maxn][maxd]; n void solve() { n   cin >> n >> k; n   for (int i = 1; (long long)i * i <= k; i++) { n     if (k % i == 0) { n       dvs.push_back(i); n       if (i < k / i) { n         dvs.push_back(k / i); n       } n     } n   } n   sort((dvs).begin(), (dvs).end()); n   for (int i = (0); i < (int((dvs).size())); i++) { n     hs.insert(dvs[i], i); n   } n   for (int i = (0); i < (n); i++) cin >> a[i]; n   if (k == 1) { n     cout << 1 <<   n ; n     int best = 0; n     for (int i = (1); i < (n); i++) n       if (a[best] > a[i]) best = i; n     cout << best + 1 <<   n ; n     return; n   } n   for (int i = (0); i < (n + 1); i++) n     for (int j = (1); j < (int((dvs).size())); j++) f[i][j] = make_pair(INF, 0); n   for (int pos = (n)-1; pos >= (0); pos--) n     for (int i = (1); i < (int((dvs).size())); i++) { n       f[pos][i] = f[pos + 1][i]; n       int nxt = hs.find(dvs[i] / gcd(dvs[i], a[pos])); n       if (chkmin(f[pos][i], make_pair(f[pos + 1][nxt].first + 1, n                                       f[pos + 1][nxt].second + a[pos]))) { n         r[pos][i] = 1; n       } n     } n   int ans = f[0][int((dvs).size()) - 1].first; n   if (ans > n) { n     cout << -1 <<   n ; n     return; n   } n   cout << ans <<   n ; n   int cur = 0; n   k = int((dvs).size()) - 1; n   while (cur < n) { n     if (r[cur][k]) { n       cout << cur + 1 <<    ; n       k = hs.find(dvs[k] / gcd(dvs[k], a[cur])); n     } n     cur++; n   } n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> a; n   vector<vector<int> > gr(n + 1, a); n   int any; n   int th; n   for (int i = 1; i <= n; i++) { n     cin >> th; n     if (th != 0) { n       gr[i].push_back(th); n       gr[th].push_back(i); n     } n   } n   vector<int> chet(n + 1, 0); n   for (int i = 1; i <= n; i++) { n     if (gr[i].size() % 2 == 0) { n       chet[i] = 1; n       any = i; n     } n   } n   if (n % 2 == 0) { n     cout <<  NO ; n   } else { n     cout <<  YES n ; n     queue<int> q; n     q.push(any); n     vector<int> dist(n + 1, 0); n     vector<int> bfu(n + 1, 0); n     vector<int> pred(n + 1, 0); n     vector<vector<int> > next(n + 1, a); n     bfu[any] = 1; n     pred[any] = -1; n     while (q.size() != 0) { n       int v = q.front(); n       q.pop(); n       for (int i = 0; i < gr[v].size(); i++) { n         if (bfu[gr[v][i]] == 0) { n           pred[gr[v][i]] = v; n           q.push(gr[v][i]); n           bfu[gr[v][i]] = 1; n           next[v].push_back(gr[v][i]); n           dist[gr[v][i]] = dist[v] + 1; n         } n       } n     } n     vector<int> ans; n     int maxd = dist[max_element(dist.begin(), dist.end()) - dist.begin()]; n     vector<int> ansu(n + 1, 0); n     set<int> sss; n     vector<set<int> > ch(maxd + 1, sss); n     for (int i = 1; i <= n; i++) { n       if (chet[i] == 1) { n         ch[dist[i]].insert(i); n       } n     } n     for (int i = ch.size() - 1; i >= 0; i--) { n       for (auto j : ch[i]) { n         queue<int> qq; n         qq.push(j); n         if (i != 0) { n           if (ch[i - 1].find(pred[j]) != ch[i - 1].end()) { n             ch[i - 1].erase(pred[j]); n           } else { n             ch[i - 1].insert(pred[j]); n           } n         } n         while (qq.size() != 0) { n           int v = qq.front(); n           qq.pop(); n           if (ansu[v] == 0) { n             cout << v <<   n ; n             ansu[v] = 1; n             for (int jj = 0; jj < next[v].size(); jj++) { n               qq.push(next[v][jj]); n             } n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> ans; n map<string, int> lo; n string s[100], V[55]; n long long int n, m, k, done[100], fyes = -1; n void give() { n   string T =  abcdef ; n   do { n     ans.push_back(T); n   } while (next_permutation(T.begin(), T.end())); n   for (int i = 0; i < ans.size(); i++) lo[ans[i]] = i; n } n int main() { n   give(); n   cin >> n >> k; n   for (int i = 0; i < (n - k + 1); i++) { n     cin >> s[i]; n     if (s[i] ==  YES  && fyes == -1) fyes = i; n   } n   if (fyes != -1) { n     for (int i = fyes, j = 0; j < k; i++, j++) V[i] = ans[j]; n     for (int i = fyes + 1; i < n - k + 1; i++) { n       if (s[i] ==  YES ) { n         V[i + k - 1] = ans[lo[V[i]] + k - 1]; n       } else { n         V[i + k - 1] = V[i]; n       } n     } n     for (int i = 0; i < fyes; i++) V[i] = V[fyes]; n   } else { n     for (int i = 0; i < n; i++) V[i] =  fuchka ; n   } n   for (int i = 0; i < n; i++) { n     V[i][0] = V[i][0] +  A  -  a ; n     cout << V[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int dp[1 << 23]; n vector<pair<int, int> > p[23]; n int a[100]; n int main() { n   int n, res = 1000; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     for (int j = 0; j < i; j++) n       for (int k = j; k < i; k++) n         if (a[j] + a[k] == a[i]) p[i].push_back(make_pair(j, k)); n   } n   memset(dp, 125, sizeof(dp)); n   dp[1] = 1; n   for (int i = 1; i < n; i++) { n     for (int j = 0; j < (1 << (i - 1)); j++) { n       int jj = j | (1 << (i - 1)); n       for (int k = 0; k < p[i].size(); k++) { n         int a = p[i][k].first, b = p[i][k].second; n         if (!(jj & (1 << a)) || !(jj & (1 << b))) continue; n         int msk = jj | (1 << i); n         dp[msk] = min(dp[msk], dp[jj] + 1); n         for (int del = 0; del < i; del++) n           if (msk & (1 << del)) n             dp[msk ^ (1 << del)] = min(dp[msk ^ (1 << del)], dp[jj]); n       } n     } n   } n   for (int i = 0; i < 1 << n; i++) n     if ((i & (1 << (n - 1)))) res = min(res, dp[i]); n   cout << (res == 1000 ? -1 : res) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = (int)1e9; n const double PI = 2 * acos(0.0); n const double eps = 1e-9; n int n, m; n vector<int> len; n vector<pair<int, int> > pos; n deque<int> ans; n vector<bool> vis; n int find(int x) { n   for (int i = 0; i < (int)len.size(); ++i) { n     if (len[i] == x and !vis[i]) return i; n   } n   return -1; n } n int main() { n   cin >> n >> m; n   pos = vector<pair<int, int> >(n); n   len = vector<int>(m); n   for (int i = 0; i < n; ++i) cin >> pos[i].first >> pos[i].second; n   for (int i = 0; i < m; ++i) cin >> len[i]; n   if (n % 2) { n     cout <<  NO n ; n     return 0; n   } n   bool good = 0; n   vis = vector<bool>(m, 0); n   ans = deque<int>(); n   for (int i = 0; i < n; i += 2) { n     int prev = (i + n - 1) % n; n     int dist1 = (int)hypot(pos[prev].first - pos[i].first, n                            pos[prev].second - pos[i].second); n     int dist2 = (int)hypot(pos[i + 1].first - pos[i].first, n                            pos[i + 1].second - pos[i].second); n     int idx = find(dist1 + dist2); n     if (idx != -1) { n       vis[idx] = 1; n       ans.push_back(idx); n     } else n       goto no; n   } n   cout <<  YES  << endl; n   for (int i = 0; i < n; ++i) { n     if (i % 2 == 1) n       cout << -1 <<    ; n     else { n       cout << ans.front() + 1 <<    ; n       ans.pop_front(); n     } n   } n   cout << endl; n   return 0; n no:; n   vis = vector<bool>(m, 0); n   ans = deque<int>(); n   for (int i = 1; i < n; i += 2) { n     int nxt = (i + n + 1) % n; n     int dist1 = (int)hypot(pos[i - 1].first - pos[i].first, n                            pos[i - 1].second - pos[i].second); n     int dist2 = (int)hypot(pos[nxt].first - pos[i].first, n                            pos[nxt].second - pos[i].second); n     int idx = find(dist1 + dist2); n     if (idx != -1) { n       vis[idx] = 1; n       ans.push_back(idx); n     } else { n       good = 0; n       goto noo; n     } n   } n   cout <<  YES  << endl; n   for (int i = 0; i < n; ++i) { n     if (i % 2 == 0) n       cout << -1 <<    ; n     else { n       cout << ans.front() + 1 <<    ; n       ans.pop_front(); n     } n   } n   cout << endl; n   return 0; n noo:; n   cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n; n   std::cin >> n; n   if (n > 1) { n     std::cout << 2 * (n - 1); n   } else { n     std::cout << 1; n   }; n   std::cout <<     << 2 << std::endl << 1 <<     << 2; n   return NULL; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, i, j, sum, k; n int main() { n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a; n     sum += a; n     j += 1 - 2 * a; n     if (j < 0) j = 0; n     if (k < j) k = j; n   } n   if (!k) { n     cout << sum - 1; n   } else { n     cout << sum + k; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int tt; n   cin >> tt; n   while (tt--) { n     int a, b, c; n     cin >> a >> b >> c; n     int ans = (int)1e9; n     int A = -1, B = -1, C = -1; n     for (int cA = 1; cA <= 2 * a; cA++) { n       for (int cB = cA; cB <= 2 * b; cB += cA) { n         for (int i = 0; i < 2; i++) { n           int cC = cB * (c / cB) + i * cB; n           int res = abs(cA - a) + abs(cB - b) + abs(cC - c); n           if (ans > res) { n             ans = res; n             A = cA; n             B = cB; n             C = cC; n           } n         } n       } n     } n     cout << ans <<   n  << A <<     << B <<     << C <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e5 + 5; n long long ans[N]; n struct person { n   int t, s, f, num; n   void read() { scanf( %d%d%d , &t, &s, &f); } n   bool operator<(const person &b) const { return t < b.t; } n } a[N]; n int n, m, X, D, sl, sr; n long long T; n multiset<pair<long long, int> > s; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) a[i].num = i, a[i].read(); n   sort(a + 1, a + n + 1); n   T = 0; n   X = 1; n   D = 0; n   int i = 1; n   while (i <= n || !s.empty()) { n     multiset<pair<long long, int> >::iterator tmp; n     if (D == 1) n       tmp = s.lower_bound(pair<long long, int>(X, -N)); n     else if (D == -1) { n       tmp = s.upper_bound(pair<long long, int>(X, +N)); n       if (tmp == s.begin()) n         tmp = s.end(); n       else n         --tmp; n     } else n       tmp = s.end(); n     if (i > n || tmp != s.end() && (tmp->first - X) * D <= a[i].t - T) { n       T += (tmp->first - X) * D; n       int tx = X; n       X = tmp->first; n       if (X < tx) { n         multiset<pair<long long, int> >::iterator n             beg = s.lower_bound(pair<long long, int>(X, -N)), n             end = s.lower_bound(pair<long long, int>(X, +N)); n         for (; beg != end; beg++) sl--, sr++; n       } n       if (tmp->second > 0) { n         s.insert(pair<long long, int>(a[tmp->second].f, -tmp->second)); n         if (a[tmp->second].f >= X) n           sr++; n         else n           sl++; n       } else { n         ans[a[-tmp->second].num] = T; n       } n       if (tmp->first >= X) n         sr--; n       else n         sl--; n       s.erase(tmp); n     } else { n       X += (a[i].t - T) * D; n       T = a[i].t; n       s.insert(pair<long long, int>(a[i].s, i)); n       if (a[i].s >= X) n         sr++; n       else n         sl++; n       i++; n     } n     if (sr == 0 && sl == 0) n       D = 0; n     else if (sr >= sl) n       D = 1; n     else n       D = -1; n   } n   for (int i = 1; i <= n; i++) printf( %I64d n , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, c; n int main() { n   cin >> a >> b >> c; n   int ans = 0; n   for (int i = 0; i <= c; i += a) { n     if ((c - i) % b == 0) ans++; n   } n   if (ans == 0) n     cout <<  No ; n   else n     cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxint = -1u >> 2; n const double eps = 1e-6; n const int MAX = 100001; n int CA[MAX]; n int CB[MAX]; n int main() { n   int N; n   cin >> N; n   int ans = N + 1; n   if (N == 1 || N == 2) { n     cout << 0 << endl; n     return 0; n   } n   vector<int> A(N); n   vector<int> B(N); n   map<int, int> MA; n   map<int, int> MB; n   int half = N / 2; n   if (N % 2) half += 1; n   for (int i = 0; i < N; ++i) { n     int a, b; n     cin >> a >> b; n     if (a != b) { n       MB[b] = MB[b] + 1; n     } n     MA[a] = MA[a] + 1; n     if (MA[a] >= half) { n       cout << 0 << endl; n       return 0; n     } n     if (MB[b] >= half) { n       ans = min(ans, MB[b]); n     } n   } n   for (map<int, int>::iterator itr = MA.begin(); itr != MA.end(); ++itr) { n     if (itr->second + MB[itr->first] >= half) { n       ans = min(ans, half - itr->second); n     } n   } n   if (ans == N + 1) { n     cout << -1 << endl; n   } else n     cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100000 + 7; n int n, m, comp[N], y, spre[N]; n bool vis[N]; n vector<int> g[N], ig[N], ord, rep[N]; n set<int> sgn[N]; n void dfs1(int a) { n   vis[a] = 1; n   for (auto &b : g[a]) { n     if (!vis[b]) { n       dfs1(b); n     } n   } n   ord.push_back(a); n } n void dfs2(int a) { n   rep[y].push_back(a); n   comp[a] = y; n   for (auto &b : ig[a]) { n     if (!comp[b]) { n       dfs2(b); n     } n   } n } n int este(int i, int j) { n   cout <<  ?   << i <<     << j << endl; n   int r; n   cin >> r; n   return r; n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     int x, y; n     cin >> x >> y; n     g[x].push_back(y); n     ig[y].push_back(x); n   } n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       dfs1(i); n     } n   } n   reverse(ord.begin(), ord.end()); n   for (auto &i : ord) { n     if (comp[i] == 0) { n       y++; n       dfs2(i); n     } n   } n   for (int i = 1; i <= n; i++) n     for (auto &j : g[i]) n       if (comp[i] != comp[j]) sgn[comp[i]].insert(comp[j]); n   n = y; n   for (int i = 1; i <= n; i++) { n     g[i].clear(); n     for (auto &j : sgn[i]) { n       g[i].push_back(j); n       spre[j]++; n     } n   } n   vector<int> stk; n   for (int i = 1; i <= n; i++) { n     if (!spre[i]) stk.push_back(i); n   } n   int ret = stk[0]; n   while ((int)stk.size() > 1) { n     int now = stk.back(); n     while ((int)rep[now].size() > 0 && (int)rep[ret].size() > 0) { n       int x = rep[now].back(), y = rep[ret].back(); n       if (este(x, y)) n         rep[ret].pop_back(); n       else n         rep[now].pop_back(); n     } n     if (rep[ret].empty()) { n       swap(stk.back(), stk[0]); n       swap(ret, now); n     } n     stk.pop_back(); n     for (auto &j : g[now]) { n       spre[j]--; n       assert(spre[j] >= 0); n       if (!spre[j]) { n         stk.push_back(j); n       } n     } n   } n   cout <<  !   << rep[ret].back() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool func(int x) { n   int cnt = 0; n   while (x != 0) { n     x = x / 10; n     cnt++; n   } n   if (cnt == 1) n     return true; n   else if (cnt == 2) n     return false; n   else if (cnt == 0) n     return true; n } n int main() { n   int h1, h2, m1, m2; n   int h, m, temp; n   char ch; n   cin >> h1; n   cin >> ch; n   cin >> m1; n   cin >> h2; n   cin >> ch; n   cin >> m2; n   int dh, dm, t; n   dh = h2 - h1; n   dm = m2 - m1; n   if (dm == 0) { n     float g = (double)dh / 2; n     g *= 60; n     if (g >= 60) { n       int ho = g / 60; n       int mi = (long long)g % 60; n       h = h1 + ho; n       m = mi + m1; n     } else { n       m = m1 + g; n       if (m >= 60) { n         h = h1 + (m / 60); n         m = m % 60; n       } else n         h = h1; n     } n   } else if (dh == 0) { n     h = h1; n     m = m1 + dm / 2; n   } else { n     if (dm < 0) { n       --dh; n       t = dh + (60 - m1) + m2; n     } else { n       dh; n       t = dh * 60 + (m2 - m1); n     } n     t = t / 2; n     if (t + m1 >= 60) { n       int u = h1 + t / 60; n       int left = t % 60; n       if (m1 + left >= 60) { n         ++u; n         m = (left - (60 - m1)); n       } else n         m = m1 + left; n       h = u; n     } else { n       h = h1; n       m = m1 + t; n     } n   } n   if (func(h) == true && func(m) == true) { n     cout <<  0  << h <<  :  <<  0  << m << endl; n   } else if (func(h) && !func(m)) { n     cout <<  0  << h <<  :  << m << endl; n   } else if (!func(h) && func(m)) { n     cout << h <<  :  <<  0  << m << endl; n   } else n     cout << h <<  :  << m << endl; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:40000000 ) n using namespace std; n const double EPS = 1e-10; n const double PI = acos(-1.0); n const int mod = 1000000007; n const int MAXN = 200 * 200; n int a[111]; n int n; n int main() { n   cin >> n; n   bool p = 1; n   for (int(i) = (0); (i) < (n); ++(i)) { n     int x; n     cin >> x; n     a[x]++; n     if (x == 25) continue; n     if (x == 50) { n       a[25]--; n       if (a[25] < 0) p = 0; n     } n     if (x == 100) { n       if (a[50] && a[25]) { n         a[50]--; n         a[25]--; n       } else { n         a[25] -= 3; n         if (a[25] < 0) p = 0; n       } n     } n   } n   if (p) n     cout <<  YES  << endl; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Append(const string& w, string& a) { n   a += w; n   a +=  , ; n } n bool IsNumber(const string& w) { n   for (char c : w) { n     if (!isdigit(c)) return false; n   } n   return !w.empty() && (w ==  0  || w[0] !=  0 ); n } n void Process(const string& s, int start, int end, string& a, string& b) { n   assert(end - start + 1 >= 0); n   const string w = s.substr(start, end - start + 1); n   if (IsNumber(w)) { n     Append(w, a); n   } else { n     Append(w, b); n   } n } n void Output(string& s) { n   if (s.empty()) n     cout <<  - n ; n   else n     cout <<     << s.substr(0, s.size() - 1) <<    n ; n } n int main() { n   string s; n   cin >> s; n   s +=  , ; n   string a, b; n   int start = 0; n   for (int i = 0; i < (int)s.size(); ++i) { n     if (s[i] ==  ;  || s[i] ==  , ) { n       Process(s, start, i - 1, a, b); n       start = i + 1; n     } n   } n   Output(a); n   Output(b); n } n


#include <bits/stdc++.h> n using namespace std; n long long f(long long x) { n   int num = 0; n   for (int i = 1; 1ll * i * i <= x; i++) { n     if (x % i) continue; n     num++; n     if (1ll * i * i != x) num++; n   } n   return num; n } n long long solve(vector<int> v) { n   int n = v.size(); n   long long num = 1ll * v[0] * v[n - 1]; n   for (int i = 1; i < n / 2 + (n % 2); i++) { n     long long cur = 1ll * v[i] * v[n - i - 1]; n     if (cur != num) return -1; n   } n   if (f(num) != n + 2) return -1; n   return num; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> a(n); n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     sort(a.begin(), a.end()); n     cout << solve(a) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1000005; n using namespace std; n long long n, k, sum, q, res, m, val, ans; n long long x, y; n double p; n long long xx[] = {1, 0, -1, 0}; n long long yy[] = {0, 1, 0, -1}; n void solve(long long no) { n   cin >> n; n   long long res = 0; n   vector<long long> v[64]; n   for (int i = 0; i < n; i++) { n     cin >> x; n     res ^= x; n     for (int j = 0; j < 64; j++) n       if (x & (1LL << j)) v[j].push_back(i); n   } n   if (res == 0) { n     cout <<  DRAW n ; n     return; n   } n   vector<long long> v1; n   for (int j = 63; j >= 0; j--) { n     if (v[j].size() % 4 == 1) { n       cout <<  WIN n ; n       return; n     } else if (v[j].size() % 4 == 3) { n       if ((n - v[j].size()) % 2) n         cout <<  WIN n ; n       else n         cout <<  LOSE n ; n       return; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   cin >> t; n   for (long long i = 1; i <= t; i++) solve(i); n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, m; n   cin >> n >> m; n   int sz = n + m - 2; n   int mid = sz / 2; n   int x; n   vector<pair<int, int>> a(mid + 1, {0, 0}); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> x; n       int id = i + j; n       if (id > mid) { n         id = sz - id; n       } n       if (x == 0) { n         a[id].first++; n       } else { n         a[id].second++; n       } n     } n   } n   int ans = 0; n   int ma = a.size(); n   if (sz % 2 == 0) { n     ma--; n   } n   for (int i = 0; i < ma; i++) { n     ans += min(a[i].first, a[i].second); n   } n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, t, last; n int f[6005][6005]; n inline void dfs(int x, int y, int o) { n   f[x][y] += o; n   int O = f[x][y]; n   f[x][y] %= 4; n   if (O < 4) return; n   dfs(x, y + 1, O / 4); n   dfs(x, y - 1, O / 4); n   dfs(x + 1, y, O / 4); n   dfs(x - 1, y, O / 4); n } n int main() { n   scanf( %d%d , &n, &t); n   dfs(2500, 2500, n); n   for (int i = 1; i <= t; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     x += 2500, y += 2500; n     if (x > 5000 || y > 5000 || x < 0 || y < 0) { n       printf( 0 n ); n       continue; n     } n     printf( %d n , f[x][y]); n   } n   return 0; n } n