#include <bits/stdc++.h> n using namespace std; n std::mt19937 rnd( n     (int)std::chrono::steady_clock::now().time_since_epoch().count()); n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MAXN = 250000; n struct P { n   int x, y; n   P() {} n   P(int x, int y) : x(x), y(y) {} n }; n bool operator<(const P& a, const P& b) { n   if (a.x != b.x) return a.x < b.x; n   return a.y < b.y; n } n int ninit; n P pinit[MAXN]; n set<P> infected; n vector<P> getadj(const P& a) { n   vector<P> ret(3); n   ret[0] = P(a.x + 1, a.y); n   ret[1] = P(a.x - 1, a.y); n   ret[2] = a.x & 1 ? P(a.x - 1, a.y + 1) : P(a.x + 1, a.y - 1); n   return ret; n } n int ntree; n vector<P> ptree; n map<P, int> pmap; n vector<vector<int>> adj; n vector<int> col; n vector<int> par; n bool dfscycle(int at) { n   for (int i = (0); i < (((int)(adj[at]).size())); ++i) { n     int to = adj[at][i]; n     if (to == par[at]) continue; n     if (par[to] != -2) return true; n     par[to] = at; n     if (dfscycle(to)) return true; n   } n   return false; n } n bool hascycle() { n   par = vector<int>(ntree, -2); n   for (int i = (0); i < (ntree); ++i) n     if (par[i] == -2) { n       par[i] = -1; n       if (dfscycle(i)) return true; n     } n   return false; n } n void determineinfected() { n   infected.clear(); n   queue<P> q; n   for (int i = (0); i < (ninit); ++i) n     infected.insert(pinit[i]), q.push(pinit[i]); n   while (!q.empty()) { n     P a = q.front(); n     q.pop(); n     for (const P& b : getadj(a)) { n       if (infected.count(b)) continue; n       int cntadjinfected = 0; n       for (const P& c : getadj(b)) cntadjinfected += infected.count(c); n       if (cntadjinfected >= 2) infected.insert(b), q.push(b); n     } n   } n } n void buildgraph() { n   ptree = vector<P>(((int)(infected).size())); n   ntree = 0; n   pmap.clear(); n   for (const P& a : infected) pmap[a] = ntree, ptree[ntree] = a, ++ntree; n   adj = vector<vector<int>>(ntree); n   col = vector<int>(ntree, 0); n   for (int i = (0); i < (ntree); ++i) n     for (const P& b : getadj(ptree[i])) n       if (pmap.count(b)) adj[i].push_back(pmap[b]); n   for (int i = (0); i < (ninit); ++i) n     if (pmap.count(pinit[i])) col[pmap[pinit[i]]] = 1; n } n int calcsteps() { n   set<int> cheap; n   set<int> expansive; n   vector<bool> alive(ntree, true); n   vector<int> cntadjalive(ntree, 0); n   vector<int> cntadjblack(ntree, 0); n   for (int at = (0); at < (ntree); ++at) n     cntadjalive[at] = ((int)(adj[at]).size()); n   for (int at = (0); at < (ntree); ++at) n     for (int to : adj[at]) cntadjblack[at] += col[to]; n   auto upd = [&](int at) { n     cheap.erase(at); n     expansive.erase(at); n     if (!alive[at]) return; n     if (col[at] == 0) { n       if (cntadjblack[at] == 2) cheap.insert(at); n       if (cntadjblack[at] == 3) expansive.insert(at); n     } else { n       if (cntadjblack[at] == 1 && cntadjalive[at] == 1) cheap.insert(at); n       if (cntadjblack[at] == 0 && cntadjalive[at] == 0) expansive.insert(at); n     } n   }; n   for (int at = (0); at < (ntree); ++at) upd(at); n   int ret = 0; n   while (true) { n     if (!cheap.empty()) { n       int at = *cheap.begin(); n       if (col[at] == 0) { n         assert(cntadjblack[at] == 2); n         col[at] = 1, ++ret; n         for (int& to : adj[at]) ++cntadjblack[to]; n         upd(at); n         for (int& to : adj[at]) upd(to); n       } else { n         assert(cntadjblack[at] == 1 && cntadjalive[at] == 1); n         int oth = -1; n         for (int& to : adj[at]) n           if (alive[to]) { n             assert(oth == -1); n             oth = to; n           } n         assert(oth != -1 && col[oth] == 1); n         if (cntadjalive[oth] == 2 && cntadjblack[oth] == 1) { n           int w = -1; n           for (int& to : adj[oth]) n             if (alive[to] && to != at) { n               assert(w == -1); n               w = to; n             } n           assert(w != -1 && col[w] == 0); n           if (cntadjblack[w] == 3) { n             col[oth] = 0, ++ret; n             col[w] = 1, ++ret; n             col[oth] = 1, ++ret; n             for (int& to : adj[w]) ++cntadjblack[to]; n             upd(at); n             upd(w); n             for (int& to : adj[w]) upd(to); n             continue; n           } n         } n         col[at] = 0, alive[at] = false, ++ret; n         for (int& to : adj[at]) --cntadjblack[to], --cntadjalive[to]; n         upd(at); n         for (int& to : adj[at]) upd(to); n       } n     } else if (!expansive.empty()) { n       int at = *expansive.begin(); n       if (col[at] == 0) { n         assert(cntadjblack[at] == 3 && cntadjalive[at] == 3); n         bool done = false; n         for (int& oth : adj[at]) { n           if (cntadjblack[oth] != 1) continue; n           done = true; n           col[oth] = 0, ++ret; n           col[at] = 1, ++ret; n           col[oth] = 1, ++ret; n           for (int& to : adj[at]) ++cntadjblack[to]; n           upd(at); n           for (int& to : adj[at]) upd(to); n           break; n         } n         if (done) continue; n         col[at] = 1, ++ret; n         for (int& to : adj[at]) ++cntadjblack[to]; n         upd(at); n         for (int& to : adj[at]) upd(to); n       } else { n         assert(cntadjblack[at] == 0 && cntadjalive[at] == 0); n         col[at] = 0, alive[at] = false, ++ret; n         for (int& to : adj[at]) --cntadjblack[to], --cntadjalive[to]; n         upd(at); n         for (int& to : adj[at]) upd(to); n       } n     } else { n       break; n     } n   } n   for (int at = (0); at < (ntree); ++at) assert(!alive[at] && col[at] == 0); n   return ret; n } n int solve() { n   determineinfected(); n   buildgraph(); n   if (hascycle()) return -1; n   return calcsteps(); n } n void run() { n   scanf( %d , &ninit); n   for (int i = (0); i < (ninit); ++i) scanf( %d%d , &pinit[i].x, &pinit[i].y); n   int ans = solve(); n   if (ans == -1) n     printf( SICK n ); n   else n     printf( RECOVERED n%d n , ans); n } n void stress() { n   std::mt19937 rnd(123); n   for (int rep = (0); rep < (1000000); ++rep) { n     ninit = rnd() % 20 + 1; n     int minsz = 1; n     while (minsz * minsz < ninit) ++minsz; n     int sz = minsz + rnd() % (minsz + 1); n     set<P> seen; n     for (int i = (0); i < (ninit); ++i) n       while (true) { n         P p; n         p.x = rnd() % sz, p.y = rnd() % sz; n         if (seen.count(p)) continue; n         seen.insert(p); n         pinit[i] = p; n         break; n       } n     solve(); n     if (rep % 1000 == 999) printf( . ); n   } n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 16, inf = 2e8 + 10; n ; n int n, m, dis[maxn][maxn], deg[maxn], ans, dp[1024 * 33]; n vector<int> veci; n void find(int a) { n   int cnt = 0; n   for (int i = 0; i < n; i++) n     if ((a >> i) & 1) cnt++; n   if (cnt % 2 == 1) return; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) n       if (i != j && (a >> i) & 1 && (a >> j) & 1) { n         int ki = a; n         ki ^= (1 << i); n         ki ^= (1 << j); n         dp[a] = min(dp[a], dp[ki] + dis[veci[i]][veci[j]]); n       } n } n int main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   fill_n(dis[0], maxn * maxn, inf); n   fill_n(dp, 1024 * 33, inf); n   cin >> n >> m; n   for (int i = 0; i < n; i++) dis[i][i] = 0; n   for (int i = 0; i < m; i++) { n     int u, v, w; n     cin >> u >> v >> w; n     u--, v--; n     deg[u]++, deg[v]++; n     ans += w; n     dis[u][v] = dis[v][u] = min(dis[u][v], w); n   } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) n       for (int k = 0; k < n; k++) n         dis[j][k] = min(dis[j][k], dis[j][i] + dis[i][k]); n   for (int i = 0; i < n; i++) n     if (deg[i] > 0 && dis[i][0] == inf) n       return cout << -1, 0; n     else if (deg[i] % 2 == 1) n       veci.push_back(i); n   dp[0] = 0; n   for (int i = 0; i < (1 << (veci.size())); i++) find(i); n   cout << ans + dp[(1 << (veci.size())) - 1]; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n using ll = long long; n using ld = long double; n using pii = pair<int, int>; n using vi = vector<int>; n const ld PI = acos(-1); n template <typename T, typename U> n inline bool chmax(T &a, U b) { n   return a < b && (a = b, true); n } n template <typename T, typename U> n inline bool chmin(T &a, U b) { n   return a > b && (a = b, true); n } n mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); n template <typename T, typename U> n std::ostream &operator<<(std::ostream &stream, const pair<T, U> &p) { n   return stream << p.first <<     << p.second; n } n template <typename T1, typename U> n istream &operator>>(istream &is, pair<T1, U> &p) { n   is >> p.first >> p.second; n   return is; n } n template <typename T> n std::ostream &operator<<(std::ostream &out, const vector<T> &vec) { n   for (const T &x : vec) out << x <<    ; n   return out; n } n template <typename T> n std::istream &operator>>(std::istream &in, vector<T> &vec) { n   for (auto &x : vec) in >> x; n   return in; n } n template <typename T> n T gcd(T a, T b) { n   a = abs(a); n   b = abs(b); n   while (b != 0) { n     a = a % b; n     swap(a, b); n   } n   return a; n } n template <typename T> n T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n template <typename T, typename U> n T power(T a, T b, U mod) { n   T res = 1; n   while (b) { n     if (b & 1) { n       res = (res * a) % mod; n     } n     a = (a * a) % mod; n     b /= 2; n   } n   return res; n } n template <typename T> n std::vector<T> powers(T base, int length) { n   std::vector<T> result(length); n   if (length > 0) { n     result[0] = 1; n   } n   for (int i = 1; i < length; i++) { n     result[i] = result[i - 1] * base; n   } n   return result; n } n bool miller_rabin(unsigned n) { n   if (n < 2) return false; n   for (unsigned p : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}) n     if (n % p == 0) return n == p; n   int r = __builtin_ctz(n - 1); n   unsigned d = (n - 1) >> r; n   for (unsigned a : {2, 7, 61}) { n     unsigned x = power(a % n, d, n); n     if (x <= 1 || x == n - 1) continue; n     for (int i = 0; i < r - 1 && x != n - 1; i++) n       x = unsigned(uint64_t(x) * x % n); n     if (x != n - 1) return false; n   } n   return true; n } n struct Sieve { n   int maxn; n  n  public: n   using MapType = unordered_map<long long, long long>; n   std::vector<long long> spf; n   std::vector<long long> primes; n   std::vector<long long> mobius; n   std::vector<bool> is_prime; n   explicit Sieve(int _n = 2e6 + 7) : maxn(_n + 1) { n     spf.resize(maxn, 1); n     is_prime.resize(maxn, true); n     primes.clear(); n     is_prime[0] = is_prime[1] = false; n     for (long long i = 2; i < maxn; ++i) { n       if (is_prime[i]) { n         primes.push_back(i); n         spf[i] = i; n       } n       for (long long j = 0; j < (int)primes.size() && (i * primes[j]) < maxn && n                             primes[j] <= spf[i]; n            ++j) { n         is_prime[i * primes[j]] = false; n         spf[i * primes[j]] = primes[j]; n       } n     } n   } n   void genMobius() { n     mobius.resize(maxn, 0); n     mobius[1] = 1; n     for (long long i = 2; i < maxn; ++i) { n       if (spf[i / spf[i]] == spf[i]) { n         mobius[i] = 0; n       } else { n         mobius[i] = -mobius[i / spf[i]]; n       } n     } n   } n   long long nextPrime(long long x, bool strict = false) { n     auto it = upper_bound(primes.begin(), primes.end(), x); n     if (!strict and is_prime[x]) return x; n     next(it); n     return *it; n   } n   bool isPrime(long long num) { n     if (num < maxn) { n       return is_prime[num]; n     } n     for (long long div = 2; div * div <= num; ++div) { n       if (num % div == 0) return false; n     } n     return true; n   } n   long long numDivisors(long long val) { n     auto div = primeFactors(val); n     long long ans = 1; n     for (const auto &p : div) { n       ans *= p.second + 1; n     } n     return ans; n   } n   long long countDivisors(long long n) { n     if (n == 1) return 1; n     long long ans = 1; n     for (int i = 0;; i++) { n       if (primes[i] * primes[i] * primes[i] > n) break; n       int cnt = 1; n       while (n % primes[i] == 0) { n         n /= primes[i]; n         cnt++; n       } n       ans *= cnt; n     } n     if (is_prime[n]) n       ans = ans * 2; n     else if (is_prime[sqrt(n)] && (long long)sqrt(n) == sqrt(n)) n       ans = ans * 3; n     else if (n != 1) n       ans = ans * 4; n     return ans; n   } n   vector<pair<long long, long long>> divisorPair(long long x) { n     vector<pair<long long, long long>> res; n     for (long long i = 1; i * i <= x; i++) { n       if (x % i == 0) { n         if (x / i == i) { n           res.emplace_back(i, i); n         } else { n           res.emplace_back(i, x / i); n         } n       } n     } n     return res; n   } n   vector<long long> divisor(long long x) { n     vector<long long> res; n     for (long long i = 1; i * i <= x; i++) { n       if (x % i == 0) { n         res.push_back(i); n         if ((x / i) != i) { n           res.push_back(x / i); n         } n       } n     } n     return res; n   } n   set<long long> divisorSet(long long x) { n     set<long long> res; n     for (long long i = 1; i * i <= x; i++) { n       if (x % i == 0) { n         res.insert(i); n         res.insert(x / i); n       } n     } n     return res; n   } n   MapType primeFactors(long long val) { n     MapType fac; n     while (val > 1) { n       auto pf = spf[val]; n       if (pf == 1) break; n       long long cnt = 0; n       while (val % pf == 0) { n         cnt++; n         val /= pf; n       } n       fac[pf] = cnt; n     } n     return fac; n   } n   set<long long> divisorsBrute(long long val) { n     set<long long> res; n     for (long long i = 1; i * i <= val; i++) { n       if (val % i == 0) { n         if ((val / i) == i) { n           res.insert(i); n         } else { n           res.insert(i); n           res.insert(val / i); n         } n       } n     } n     return res; n   } n }; n Sieve sieve(sqrt(1e9 + 7)); n class CPythagoreanTriples { n  public: n   bool ok(ll h, ll y) { return h >= 1 && y >= 1 && h <= 1e18 && y <= 1e18; } n   bool solveBase(ll n) { n     auto div = sieve.divisorPair(n); n     for (auto [a1, b1] : div) { n       for (auto [a2, b2] : div) { n         for (auto [a, b] : {make_pair(a1 * a2, b1 * b2), {a1 * b2, a2 * b1}}) { n           { n             ll h = (a + b) / 2; n             ll y = (b - a) / 2; n             if (n * n == h * h - y * y && ok(h, y)) { n               cout << h <<     << y <<   n ; n               return true; n             } n           } n           { n             ll y = (a + b) / 2; n             ll h = (b - a) / 2; n             if (n * n == h * h - y * y && ok(h, y)) { n               cout << h <<     << y <<   n ; n               return true; n             } n           } n         } n       } n     } n     return false; n   } n   bool solveHypot(ll n) { return false; } n   void solve() { n     ll n; n     cin >> n; n     if (solveBase(n)) { n       return; n     } else if (solveHypot(n)) { n       return; n     } else { n       cout << -1 <<   n ; n     } n   } n }; n int32_t main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(nullptr); n   std::cout.tie(nullptr); n   CPythagoreanTriples solver; n   solver.solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int N = 1e6 + 7; n const int mxn = 3e5 + 9; n inline long long in() { n   long long _; n   scanf( %lld , &_); n   return _; n } n int n, m, k; n struct node { n   int len; n   int link; n   int firstpos; n   map<char, int> nxt; n   void clr() { n     len = link = firstpos = 0; n     nxt.clear(); n   } n   void print() { n     cerr << __FUNCTION__ <<     << 50 <<  ..  , n         cerr <<  len  n              <<   =   << len, n         cerr <<   ,  , n         cerr <<  link  n              <<   =   << link, n         cerr <<   ,  , n         cerr <<  firstpos  n              <<   =   << firstpos, n         cerr << endl; n     for (auto z : nxt) { n       cerr << z.first <<     << z.second << endl; n     } n   } n }; n node t[mxn]; n int sz, last; n void init() { n   sz = last = 0; n   t[0].len = 0; n   t[0].firstpos = 0; n   t[0].link = -1; n   sz++; n } n long long cnt[mxn]; n set<pair<int, int> > nodes; n void add_letter(char ch) { n   int cur = sz++; n   t[cur].len = t[last].len + 1; n   t[cur].firstpos = t[cur].len; n   cnt[cur] = 1; n   nodes.insert(make_pair(t[cur].len, cur)); n   int p; n   for (p = last; p != -1 && !t[p].nxt.count(ch); p = t[p].link) n     t[p].nxt[ch] = cur; n   if (p == -1) n     t[cur].link = 0; n   else { n     int q = t[p].nxt[ch]; n     if (t[p].len + 1 == t[q].len) n       t[cur].link = q; n     else { n       int clone = sz++; n       t[clone].len = t[p].len + 1; n       t[clone].nxt = t[q].nxt; n       t[clone].link = t[q].link; n       t[clone].firstpos = t[q].firstpos; n       cnt[clone] = 0; n       nodes.insert(make_pair(t[clone].len, clone)); n       for (; p != -1 && t[p].nxt[ch] == q; p = t[p].link) t[p].nxt[ch] = clone; n       t[q].link = t[cur].link = clone; n     } n   } n   last = cur; n } n string ans =   ; n void kth(int cur) { n   if (k <= 0) return; n   for (auto x : t[cur].nxt) { n     k -= cnt[x.second]; n     kth(x.second); n     if (k <= 0) { n       ans += x.first; n       return; n     } n   } n } n void CLR() { n   for (int i = 0; i < sz; i++) { n     t[i].clr(); n     cnt[i] = 0; n   } n   sz = last = 0; n   nodes.clear(); n } n char s[mxn]; n int main() { n   int tc = 1; n   while (tc--) { n     scanf( %s , s); n     k = in(); n     init(); n     n = strlen(s); n     if (1LL * n * (n + 1) < k * 2) { n       printf( No such line. n ); n       continue; n     } n     for (int i = 0; i < n; i++) add_letter(s[i]); n     for (set<pair<int, int> >::reverse_iterator it = nodes.rbegin(); n          it != nodes.rend(); it++) { n       int x = (*it).second; n       cnt[t[x].link] += cnt[x]; n     } n     ans =   ; n     kth(0); n     reverse(ans.begin(), ans.end()); n     printf( %s n , ans.c_str()); n     if (tc) CLR(); n   } n   return 0; 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   string s; n   cin >> s; n   s =  $  + s; n   int n = s.length(); n   vector<vector<int>> c(n, vector<int>(26, 0)); n   for (int i = 1; i < n; i++) { n     for (int j = 0; j < 26; j++) { n       c[i][j] += c[i - 1][j]; n     } n     c[i][s[i] -  a ]++; n   } n   int q; n   cin >> q; n   while (q--) { n     int l, r; n     cin >> l >> r; n     int d = 0; n     for (int j = 0; j < 26; j++) { n       d += ((c[r][j] - c[l - 1][j]) > 0); n     } n     cout << ((l == r or s[l] != s[r] or d > 2) ?  Yes n  :  No n ); 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   long long n; n   cin >> n; n   unordered_map<long long, long long> mymap; n   long long maxval = INT_MIN, minval = INT_MAX; n   for (int i = 0; i < n; i++) { n     long long temp; n     cin >> temp; n     mymap[temp]++; n     if (temp > maxval) maxval = temp; n     if (temp < minval) minval = temp; n   } n   cout << maxval - minval <<    ; n   if (maxval == minval) n     cout << (mymap[maxval] * (mymap[maxval] - 1)) / 2 << endl; n   else n     cout << mymap[maxval] * mymap[minval] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, ans; n int main() { n   cin >> n; n   int sq; n   ans = -1e9; n   for (int i = 0; i < n; i++) { n     cin >> a; n     if (a < 0) { n       ans = max(ans, a); n       continue; n     } n     sq = sqrt(a); n     if (sq * sq != a) { n       ans = max(ans, a); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct nom { n   int i, a, l; n }; n long long po(int a, int n) { n   if (n == 0) return 1; n   if (n == 1) return a; n   if (n & 1) n     return a * po(a * a, n / 2); n   else n     return po(a * a, n / 2); n } n struct rec { n   int x, y, x1, y1; n }; n int main() { n   string a; n   cin >> a; n   cout << ((a.size() + 1) * 26 - a.size()); n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, b, k; n long long MOD = 1000000007; n long long pref[5005][2], dp[5005][2]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> a >> b >> k; n   for (int i = 0; i < n + 5; i++) { n     pref[i][0] = pref[i][1] = dp[i][0] = dp[i][1] = 0; n   } n   if (b < a) { n     a = n + 1 - a; n     b = n + 1 - b; n   } n   dp[a][0] = 1; n   for (int i = a; i < b; i++) pref[i][0] = 1; n   for (int j = 1; j <= k; j++) { n     for (int i = 1; i < b; i++) { n       dp[i][j % 2] = n           (pref[(b + i - 1) / 2][(j - 1) % 2] - dp[i][(j - 1) % 2] + MOD) % MOD; n       pref[i][j % 2] = (pref[i - 1][j % 2] + dp[i][j % 2]) % MOD; n     } n   } n   cout << pref[b - 1][k % 2] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char tab[100], znak; n   int konik, insekt, dlugosc, skok; n   cin >> dlugosc; n   cin >> skok; n   for (int i = 0; i < dlugosc; i++) { n     cin >> znak; n     tab[i] = znak; n     if (znak ==  G ) konik = i; n     if (znak ==  T ) insekt = i; n   } n   if (konik == insekt) { n     cout <<  YES ; n     return 0; n   } n   if (konik < insekt) { n     while (konik <= dlugosc && konik <= insekt) { n       konik += skok; n       if (konik == insekt) { n         cout <<  YES ; n         return 0; n       } n       if (tab[konik] ==  # ) { n         cout <<  NO ; n         return 0; n       } n     } n     cout <<  NO ; n   } else { n     while (konik >= 0 && konik >= insekt) { n       konik -= skok; n       if (konik == insekt) { n         cout <<  YES ; n         return 0; n       } n       if (tab[konik] ==  # ) { n         cout <<  NO ; n         return 0; n       } n     } n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ceiling(long long a, long long b) { n   if (a % b != 0) { n     return (a / b) + 1; n   } else n     return (a / b); n } n void solve() { n   long long n, k; n   cin >> n >> k; n   long long a[n * k]; n   for (long long i = 0; i < n * k; i++) { n     cin >> a[i]; n   } n   sort(a, a + n * k); n   long long cnt = 0; n   long long cnt1 = 0; n   long long i = n * k - 1 - (n / 2); n   while (cnt1 < k and i >= 0) { n     cnt1++; n     cnt += a[i]; n     i -= (n / 2) + 1; n   } n   cout << cnt << endl; n   return; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long tc; n   cin >> tc; n   while (tc--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = (long long)1e9 + 7; n string substrs(string s, int i, int j) { n   string a; n   for (int h = i; h < j + 1; h++) { n     a.push_back(s[h]); n   } n   return a; n } n int main() { n   int T; n   cin >> T; n   for (int zz = 0; zz < T; zz++) { n     string s, s1; n     cin >> s; n     vector<int> cnt[3]; n     for (int i = 0; i < s.length(); i++) { n       if (islower(s[i])) { n         s1.push_back( l ); n         cnt[0].push_back(i); n       } else if (isupper(s[i])) { n         s1.push_back( u ); n         cnt[1].push_back(i); n       } else if (isdigit(s[i])) { n         s1.push_back( d ); n         cnt[2].push_back(i); n       } n     } n     int num = 0; n     for (int i = 0; i < 3; i++) n       if (!cnt[i].size()) num++; n     if (num == 0) { n       cout << s <<   n ; n       continue; n     } else if (num == 1) { n       for (int i = 0; i < 3; i++) { n         if (!cnt[i].size()) { n           for (int j = 1; j < 3; j++) { n             if (cnt[(i + j) % 3].size() != 1) { n               if (i == 0) n                 s[cnt[(i + j) % 3][0]] =  a ; n               else if (i == 1) n                 s[cnt[(i + j) % 3][0]] =  A ; n               else if (i == 2) n                 s[cnt[(i + j) % 3][0]] =  1 ; n               break; n             } n           } n           break; n         } n       } n     } else if (num == 2) { n       for (int i = 0; i < 3; i++) { n         if (cnt[i].size()) { n           if (i == 0) { n             s[0] =  A ; n             s[1] =  1 ; n           } else if (i == 1) { n             s[0] =  a ; n             s[1] =  1 ; n           } else if (i == 2) { n             s[0] =  A ; n             s[1] =  a ; n           } n           break; n         } n       } n     } n     cout << s <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[200005], sh[200005], sp[200005]; n int main() { n   long long i, j, k, n, m, p, q, t, cnt = 0, mn; n   scanf( %lld , &n); n   scanf( %lld , &k); n   for (i = 0; i < n; i++) { n     scanf( %lld , &arr[i]); n     ; n   } n   sort(arr, arr + n); n   for (i = 0; i < n; i++) { n     cnt = 0; n     while (1) { n       sh[arr[i]]++; n       if (sh[arr[i]] <= k) sp[arr[i]] += cnt; n       if (!arr[i]) break; n       arr[i] /= 2; n       cnt++; n     } n   } n   mn = sp[0]; n   for (i = 0; i <= 200005; i++) { n     if (sh[i] >= k && sp[i] < mn) mn = sp[i]; n   } n   cout << mn << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[205]; n vector<int> h(205, 0); n void doit(int s, int par) { n   if (par != -1) { n     h[s] = 1 + h[par]; n   } n   for (int i = 0; i < v[s].size(); i++) { n     if (v[s][i] == par) continue; n     doit(v[s][i], s); n   } n } n string pre(string s) { n   string tmp; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] >=  A  && s[i] <=  Z ) { n       tmp.push_back((char)((97 + s[i] -  A ))); n     } else { n       tmp.push_back(s[i]); n     } n   } n   return tmp; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   map<string, int> p; n   int k = 0; n   vector<string> tmp[n]; n   for (int i = 0; i < n; i++) { n     string s1, s2, s3; n     cin >> s1 >> s2 >> s3; n     s1 = pre(s1); n     s2 = pre(s2); n     s3 = pre(s3); n     if (p.find(s3) == p.end()) { n       p.insert(make_pair(s3, k)); n       k++; n     } n     if (p.find(s1) == p.end()) { n       p.insert(make_pair(s1, k)); n       k++; n     } n     tmp[i].push_back(s1); n     tmp[i].push_back(s3); n   } n   for (int i = 0; i < n; i++) { n     string s1 = tmp[i][0]; n     string s2 = tmp[i][1]; n     int x = p[s1]; n     int y = p[s2]; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   h[0] = 1; n   doit(0, -1); n   int ans = INT_MIN; n   for (int i = 0; i < 205; i++) ans = max(ans, h[i]); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n int Begin[N], Next[N], to[N], cost[N], e; n void Add(int u, int v, int w) { n   to[++e] = v, Next[e] = Begin[u], Begin[u] = e, cost[e] = w; n } n int n, m; n long long dis[N]; n bool vis[N]; n struct Vertex { n   int o; n   long long d; n   bool operator<(const Vertex& A) const { return d > A.d; } n }; n void Dijkstra() { n   priority_queue<Vertex> q; n   memset(dis, 0x3f, sizeof dis); n   q.push((Vertex){1, 0}), dis[1] = 0; n   while (!q.empty()) { n     Vertex v = q.top(); n     q.pop(); n     int o = v.o; n     if (vis[o]) continue; n     vis[o] = true; n     for (int i = Begin[o]; i; i = Next[i]) { n       int u = to[i]; n       if (dis[u] > dis[o] + cost[i]) { n         dis[u] = dis[o] + cost[i]; n         q.push((Vertex){u, dis[u]}); n       } n     } n   } n } n int delt[N]; n queue<int> que[N]; n void Work(int s) { n   for (int i = 1; i <= n; i++) delt[i] = 1e9, vis[i] = false; n   que[0].push(1), delt[1] = 0; n   for (int i = 0; i <= s; i++) n     while (!que[i].empty()) { n       int o = que[i].front(); n       que[i].pop(); n       if (vis[o]) continue; n       vis[o] = true; n       for (int j = Begin[o]; j; j = Next[j]) { n         int u = to[j]; n         int new_delt = dis[o] + delt[o] + cost[j] - dis[u]; n         if (delt[u] > new_delt) { n           delt[u] = new_delt; n           if (delt[u] <= s) que[delt[u]].push(u); n         } n       } n     } n   for (int i = 1; i <= n; i++) dis[i] += delt[i]; n }; n int q; n int main() { n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 1; i <= m; i++) { n     int u, v, c; n     scanf( %d%d%d , &u, &v, &c); n     Add(u, v, c); n   } n   Dijkstra(); n   while (q--) { n     int ty, s; n     scanf( %d%d , &ty, &s); n     if (ty == 1) n       printf( %I64d n , dis[s] > 1e17 ? -1 : dis[s]); n     else { n       for (int i = 1; i <= s; i++) { n         int u; n         scanf( %d , &u); n         ++cost[u]; n       } n       Work(min(s, n)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string mat[24]; n int n, m; n bool che(int i, int j) { n   map<string, bool> mp; n   for (int ii = 1; ii <= n; ii += i) { n     for (int jj = 1; jj <= m; jj += j) { n       string s2 =   ; n       for (int k = ii; k < ii + i; k++) { n         for (int l = jj; l < jj + j; l++) { n           s2 += mat[k - 1][l - 1]; n         } n       } n       if (mp[s2]) return false; n       mp[s2] = 1; n       reverse(s2.begin(), s2.end()); n       mp[s2] = 1; n       string s3 =   ; n       if (i == j) { n         for (int l = jj; l < jj + j; l++) { n           for (int k = ii + i - 1; k >= ii; k--) { n             s3 += mat[k - 1][l - 1]; n           } n         } n         mp[s3] = 1; n         reverse(s3.begin(), s3.end()); n         mp[s3] = 1; n       } n     } n   } n   return true; n } n int main() { n   cin >> n >> m; n   long long ans = 0, mi = INT_MAX, mx = INT_MAX, my = INT_MAX; n   for (int i = 0; i < n; i++) { n     cin >> mat[i]; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (n % i == 0 && m % j == 0) { n         if (che(i, j)) { n           ans++; n           if (i * j < mi || (i * j == mi && i < mx)) { n             mi = i * j; n             mx = i; n             my = j; n           } n         } n       } n     } n   } n   cout << ans <<   n ; n   cout << mx <<     << my <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char buf[1 << 20], *p1, *p2; n template <class T> n inline void read(T &n) { n   char ch = n       (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) n            ? 0 n            : *p1++); n   T w = 1, x = 0; n   while (!isdigit(ch)) { n     if (ch ==  - ) w = -1; n     ch = n         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) n              ? 0 n              : *p1++); n   } n   while (isdigit(ch)) { n     x = (x << 3) + (x << 1) + (ch ^ 48); n     ch = n         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) n              ? 0 n              : *p1++); n   } n   n = x * w; n } n const int maxn = 200005; n int n, m, q; n char s[maxn]; n int sa[maxn], rk[maxn], y[maxn]; n void Rsort() { n   static int c[maxn]; n   for (int i = 1; i <= m; i++) c[i] = 0; n   for (int i = 1; i <= n; i++) c[rk[i]]++; n   for (int i = 1; i <= m; i++) c[i] += c[i - 1]; n   for (int i = n; i >= 1; i--) sa[c[rk[y[i]]]--] = y[i]; n } n void getSA() { n   for (int i = 1; i <= n; i++) rk[i] = s[i], y[i] = i; n   m = 122, Rsort(); n   for (int k = 1;; k <<= 1) { n     int num = 0; n     for (int i = n - k + 1; i <= n; i++) y[++num] = i; n     for (int i = 1; i <= n; i++) n       if (sa[i] > k) y[++num] = sa[i] - k; n     Rsort(), swap(rk, y); n     num = rk[sa[1]] = 1; n     for (int i = 2; i <= n; i++) { n       if (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k]) n         rk[sa[i]] = num; n       else n         rk[sa[i]] = ++num; n     } n     if (num == n) return; n     m = num; n   } n } n int height[maxn], st[maxn][19], Log[maxn]; n void getheight() { n   for (int i = 1, k = 0; i <= n; i++) { n     if (rk[i] == 1) continue; n     if (k) k--; n     int j = sa[rk[i] - 1]; n     while (i + k <= n && j + k <= n && s[i + k] == s[j + k]) k++; n     height[rk[i]] = k; n   } n   for (int i = 2; i <= n; i++) Log[i] = Log[i >> 1] + 1; n   for (int i = 1; i <= n; i++) st[i][0] = height[i]; n   for (int j = 1; j <= Log[n]; j++) n     for (int i = 1; i + (1 << j) - 1 <= n; i++) n       st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]); n } n int query(int l, int r) { n   if (rk[l] > rk[r]) swap(l, r); n   int L = rk[l] + 1, R = rk[r]; n   int i = Log[R - L + 1]; n   return min(st[L][i], st[R - (1 << i) + 1][i]); n } n int A[maxn], B[maxn], X, Y, bel[maxn]; n int bot[maxn << 1], tot, S[maxn << 1], top, sum[maxn << 1], h[maxn << 1]; n bool cmp(int x, int y) { return rk[x] < rk[y]; } n long long ans, f[maxn << 1]; n void solve() { n   read(X), read(Y); n   ans = tot = 0; n   for (int i = 1; i <= X; i++) { n     read(A[i]); n     bel[A[i]] = 1, bot[++tot] = A[i]; n   } n   for (int i = 1; i <= Y; i++) { n     read(B[i]); n     if (bel[B[i]]) n       ans += n - B[i] + 1, bel[B[i]] = 3; n     else n       bel[B[i]] = 2, bot[++tot] = B[i]; n   } n   sort(bot + 1, bot + tot + 1, cmp); n   top = 0; n   for (int i = 1; i <= tot; i++) sum[i] = sum[i - 1] + (bel[bot[i]] >= 2); n   for (int i = 1; i <= tot; i++) { n     h[i] = query(bot[i], bot[i - 1]); n     while (top && h[i] < h[S[top]]) top--; n     f[i] = f[S[top]] + 1ll * h[i] * (sum[i - 1] - sum[S[top] - 1]); n     if (bel[bot[i]] & 1) ans += f[i]; n     S[++top] = i; n   } n   top = 0; n   for (int i = 1; i <= tot; i++) sum[i] = sum[i - 1] + (bel[bot[i]] & 1); n   for (int i = 1; i <= tot; i++) { n     while (top && h[i] < h[S[top]]) top--; n     f[i] = f[S[top]] + 1ll * h[i] * (sum[i - 1] - sum[S[top] - 1]); n     if (bel[bot[i]] >= 2) ans += f[i]; n     S[++top] = i; n   } n   for (int i = 1; i <= X; i++) bel[A[i]] = 0; n   for (int i = 1; i <= Y; i++) bel[B[i]] = 0; n   printf( %lld n , ans); n } n int main() { n   scanf( %d%d , &n, &q); n   scanf( %s , s + 1); n   getSA(), getheight(); n   for (int i = 1; i <= q; i++) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   long long int num, num_backup; n   long long int a[2], j = 0; n   cin >> num; n   num_backup = num; n   for (long long int i = 2; i * i <= num; i++) { n     if (num % i == 0) { n       a[j++] = i; n       if (j == 2) break; n       num /= i; n       i--; n     } n   } n   if (j == 0) n     cout << 1 << endl << 0 << endl; n   else if (a[0] * a[1] == num_backup || j == 1) n     cout << 2 << endl; n   else n     cout << 1 << endl << a[0] * a[1] << endl; n   return 0; n } n


/* n     Author: Zhikun Wang  n */ n   n #include <bits/stdc++.h> n  n using namespace std; n  n template <typename A, typename B>string to_string(pair<A, B> p);template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p);template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p);string to_string(const string& s) {  return     + s +    ;}string to_string(const char* s) {  return to_string((string) s);}string to_string(bool b) {  return (b ?  true  :  false );}string to_string(vector<bool> v) {  bool first = true;  string res =  { ;  for (int i = 0; i < static_cast<int>(v.size()); i++) {    if (!first) {      res +=  ,  ;    }    first = false;    res += to_string(v[i]);  }  res +=  } ;  return res;}template <size_t N>string to_string(bitset<N> v) {  string res =   ;  for (size_t i = 0; i < N; i++) {    res += static_cast<char>( 0  + v[i]);  }  return res;}template <typename A>string to_string(A v) {  bool first = true;  string res =  { ;  for (const auto &x : v) {    if (!first) {      res +=  ,  ;    }    first = false;    res += to_string(x);  }  res +=  } ;  return res;}template <typename A, typename B>string to_string(pair<A, B> p) {  return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;}template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p) {  return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + to_string(get<2>(p)) +  ) ;}template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p) {  return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;}void debug_out() { cerr << endl; }template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) {  cerr <<     << to_string(H);  debug_out(T...);} n  n #ifdef LOCAL n #define debug(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__) n #else n #define debug(...) 42 n #endif n  n #define set0(x) memset(x,0,sizeof(x)) n #define F first n #define S second n #define PB push_back n #define MP make_pair n #define rep(i, a, b) for(int i = a; i < (b); ++i) n #define trav(a, x) for(auto& a : x) n #define all(x) x.begin(), x.end() n #define sz(x) (int)(x).size() n  n typedef long long ll; n typedef pair<int,int> pii; n typedef pair<ll,ll> pll; n typedef vector<int> vi; n  n template<typename T> void read(T &x){ n     x = 0;char ch = getchar();ll f = 1; n     while(!isdigit(ch)){if(ch ==  - )f*=-1;ch=getchar();} n     while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f; n } n template<typename T, typename... Args> void read(T &first, Args& ... args) { n     read(first); n     read(args...); n } n  n struct solver{ n     #define nn 55 n     vector<int> Map[nn]; n     int T, i, m, u, v; n     int n, vis[nn], match[nn]; n     bool dfs(int u) n     { n         for(int i = 0; i < Map[u].size(); i++) n         { n             int to = Map[u][i]; n             if(!vis[to]) n             { n                 vis[to] = 1; n                 if(!match[to] || dfs(match[to])) n                 { n                     match[to] = u; n                     return 1; n                 } n             } n         } n         return 0; n     } n     int solve() n     { n         memset(match, 0, sizeof(match)); n         int ans = 0; n         for(int i = 1; i <= n; i++)//求最大匹配数 n         { n             memset(vis, 0, sizeof(vis)); n             if(dfs(i)) ans++; n         } n         return ans; n     } n     void add(int u, int v){ n         Map[u].push_back(v); n     } n     int main(){ n         return n - solve(); n     } n }; n  n int n,m,k; n  n int ind[55]; n vi G[55],rG[55]; n vi Q,A; n  n ll dp[55][55],fr[55][55],x[55],y[55],u,v; n int use[55],ruse[55]; n int main(){ n     read(n,m,k); n     solver S; n     S.n = n;S.m = m; n     for(int i=0;i<m;i++){ n         read(u,v); n         G[u].PB(v); n         rG[v].PB(u); n         ind[v]+=1; n         S.add(u,v); n     } n     for(int i=1;i<=n;i++){ n         use[i] = 1; n         ruse[i] = 1; n     } n     int cs = S.main(); n     memset(dp,7,sizeof(dp)); n     dp[0][0] = 0; n     int req = max(0,k-cs+1); n     int la = cs; n     for(int i=0;i<req;i++){ n         for(int j=1;j<=n;j++){ n             if(!use[j])continue; n             use[j] = 0; n             solver nS; nS.n = n; n             for(int u=1;u<=n;u++){ n                 for(auto v:G[u]){ n                     if(use[u] && ruse[v])nS.add(u,v); n                 } n             } n             if(nS.main()!=la){ n                 A.PB(j); n                 goto nxt; n             }else{ n                 use[j] = 1; n             } n         } n         for(int j=1;j<=n;j++){ n             if(!ruse[j])continue; n             ruse[j] = 0; n             solver nS; nS.n = n; n             for(int u=1;u<=n;u++){ n                 for(auto v:G[u]){ n                     if(use[u] && ruse[v])nS.add(u,v); n                 } n             } n             if(nS.main()!=la){ n                 A.PB(-j); n                 goto nxt; n             }else{ n                 ruse[j] = 1; n             } n         } n         nxt:; n         la+=1; n     } n     for(int i=1;i<=k;i++){ n         read(x[i],y[i]); n         for(int j=0;j<=req;j++){ n             for(int kk=max(j,i-cs+1);kk<=req;kk++){ n                 if(dp[i-1][j]+min(x[i],(kk-j)*y[i])<dp[i][kk]){ n                     dp[i][kk] = dp[i-1][j]+min(x[i],(kk-j)*y[i]); n                     fr[i][kk] = j; n                 } n             } n         } n     } n     vi O; n     int p = req; n     for(int i=k;i>=1;i--){ n         O.PB(0); n         for(int j=fr[i][p];j<p;j++)O.PB(A[j]); n         p = fr[i][p]; n     } n     reverse(all(O)); n     cout<<O.size()<<endl; n     for(int i=0;i<O.size();i++)cout<<O[i]<<   ;cout<<endl; n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n long long res, mx, r1, r2; n int main() { n   long long h, w, p, q; n   cin >> h >> w; n   p = 1; n   while (p <= h) { n     if (p > h) break; n     q = (long long)(p / 4.0 * 5.0); n     if (q > w) q = w; n     if ((long long)(q / 4.0 * 5.0) < p) break; n     if (p * q > mx) { n       mx = p * q; n       r1 = p; n       r2 = q; n     } n     p *= 2; n   } n   q = 1; n   while (q <= w) { n     if (q > w) break; n     p = (long long)(q / 4.0 * 5.0); n     if (p > h) p = h; n     if ((long long)(p / 4.0 * 5.0) < q) break; n     if (p * q > mx) { n       mx = p * q; n       r1 = p; n       r2 = q; n     } n     q *= 2; n   } n   if (r1 <= w && r2 <= h) { n     if (r1 < r2) { n       int temp = r1; n       r1 = r2; n       r2 = temp; n     } n   } n   cout << r1 <<     << r2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Pair { n   long long f, s; n   Pair() { f = s = 0; } n   Pair(long long f, long long s) { n     this->f = f; n     this->s = s; n   } n }; n const int maxn = 36 + 100; n Pair d[maxn][maxn]; n int pr[maxn][maxn]; n long long _10(int); n void print(int, int); n int main() { n   int n; n   string str; n   cin >> n >> str; n   for (int i = 0; i <= n; i++) n     for (int j = 0; j <= n; j++) { n       if (i) { n         pr[i][j] = 1; n         d[i][j].f = d[i - 1][j].f + _10(n - i) * (str[i + j - 1] -  0 ); n         d[i][j].s = d[i - 1][j].s; n       } n       if (j) { n         if (d[i][j].f + d[i][j].s < d[i][j - 1].f + d[i][j - 1].s + n                                         _10(n - j) * (str[i + j - 1] -  0 )) { n           pr[i][j] = 0; n           d[i][j].f = d[i][j - 1].f; n           d[i][j].s = d[i][j - 1].s + _10(n - j) * (str[i + j - 1] -  0 ); n         } n       } n     } n   print(n, n); n   cout << endl; n } n long long _10(int k) { n   long long res = 1; n   while (k--) res *= 10; n   return res; n } n void print(int i, int j) { n   if (!i && !j) return; n   if (pr[i][j]) { n     print(i - 1, j); n     cout <<  H ; n     return; n   } n   print(i, j - 1); n   cout <<  M ; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> vec; n int main(void) { n   long long n1, n2, i, j, k, n, d; n   cin >> n >> d; n   for (i = 0; i < n; i++) vec.push_back(i + 1); n   long long Min, Max = 0, sum; n   do { n     sum = 0; n     for (i = 0; i < n; i++) { n       for (j = i; j < n; j++) { n         Min = vec[i]; n         for (k = i; k <= j; k++) Min = min(vec[k], Min); n         sum += Min; n       } n     } n     Max = max(Max, sum); n   } while (std::next_permutation(vec.begin(), vec.end())); n   long long count = 0; n   sort(vec.begin(), vec.end()); n   do { n     sum = 0; n     for (i = 0; i < n; i++) { n       for (j = i; j < n; j++) { n         Min = vec[i]; n         for (k = i; k <= j; k++) Min = min(vec[k], Min); n         sum += Min; n       } n     } n     if (sum == Max) { n       count++; n       if (count == d) break; n     } n   } while (std::next_permutation(vec.begin(), vec.end())); n   for (i = 0; i < n; i++) cout << vec[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n int n, m; n struct node { n   int from, to, w; n } edge[maxn]; n int in[maxn]; n vector<int> e[maxn]; n int top[maxn]; n bool topsort(int mid) { n   memset(in, 0, sizeof(in)); n   int cnt = 0; n   queue<int> q; n   for (int i = 1; i <= n; ++i) e[i].clear(); n   for (int i = 1; i <= m; ++i) { n     if (edge[i].w > mid) n       e[edge[i].from].push_back(edge[i].to), in[edge[i].to]++; n   } n   for (int i = 1; i <= n; ++i) { n     if (!in[i]) { n       q.push(i); n       top[i] = ++cnt; n     } n   } n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (auto it : e[u]) { n       int v = it; n       in[v]--; n       if (!in[v]) { n         q.push(v); n         top[v] = ++cnt; n       } n     } n   } n   for (int i = 1; i <= n; ++i) { n     if (in[i]) return false; n   } n   return true; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= m; ++i) { n     cin >> edge[i].from >> edge[i].to >> edge[i].w; n   } n   int l = 0, r = 0x3f3f3f3f; n   int ret = 0; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (topsort(mid)) { n       ret = mid; n       r = mid - 1; n     } else n       l = mid + 1; n   } n   topsort(ret); n   vector<int> ans; n   for (int i = 1; i <= m; ++i) { n     if (edge[i].w <= ret && top[edge[i].from] > top[edge[i].to]) { n       ans.push_back(i); n     } n   } n   cout << ret <<     << ans.size() << endl; n   for (int i = 0; i < ans.size(); ++i) { n     cout << ans[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3) n #pragma GCC optimize( inline ) n using namespace std; n long long n; n double ans; n struct dt { n   double x; n   double y; n } a[1 << 11]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (register long long i = 1; (i - 1 ^ n); i++) cin >> a[i].x >> a[i].y; n   for (register long long i = 1; (i - 1) ^ n; i++) { n     ans += a[i].y; n   } n   ans /= n; n   ans += 5; n   cout << fixed << setprecision(3) << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int min(int a, int b) { n   if (a < b) n     return a; n   else n     return b; n } n int main() { n   int n, pos, l, r; n   scanf( %d %d %d %d , &n, &pos, &l, &r); n   if (l == 1 && r == n) n     printf( 0 n ); n   else if (l == 1) n     printf( %d n , abs(pos - r) + 1); n   else if (r == n) n     printf( %d n , abs(pos - l) + 1); n   else n     printf( %d n , min(abs(pos - r), abs(pos - l)) + abs(r - l) + 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const char nl =   n ; n const long long inf = 1e9 + 10; n const long long inf2 = 1e18 + 99LL; n const long double inf3 = 1e17; n const long long mod = 1e9 + 7, mod2 = 998244353; n const long double eps = 1e-9; n const bool local = false; n const int logn = 17, maxn = 1000001, maxm = 200001, maxn2 = 3; n int p[maxn], s[maxn]; n int find(int v) { n   if (p[v] != v) p[v] = find(p[v]); n   return p[v]; n } n void f(int a, int b) { n   a = find(a); n   b = find(b); n   if (a == b) return; n   if (s[a] < s[b]) swap(a, b); n   p[b] = a; n   s[a] += s[b]; n } n vector<int> b[maxn]; n int c[maxn]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   int n, q; n   cin >> n >> q; n   vector<int> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) { n     int j = 2; n     int ta = a[i]; n     while (j * j <= ta) { n       if (ta % j == 0) { n         b[j].push_back(i); n         while (ta % j == 0) ta /= j; n       } n       j++; n     } n     if (ta > 1) b[ta].push_back(i); n   } n   for (int i = 0; i < n; i++) { n     s[i] = 1; n     p[i] = i; n   } n   for (int i = 0; i < maxn; i++) { n     for (int j = 0; j + 1 < (int)((b[i]).size()); j++) { n       f(b[i][j], b[i][j + 1]); n     } n   } n   for (int i = 0; i < maxn; i++) { n     if ((int)((b[i]).size())) { n       c[i] = find(b[i][0]); n     } else { n       c[i] = -1; n     } n   } n   set<pair<int, int>> st; n   for (int i = 0; i < n; i++) { n     int j = 2; n     int ta = a[i] + 1; n     vector<int> d; n     while (j * j <= ta) { n       if (ta % j == 0) { n         d.push_back(j); n         while (ta % j == 0) ta /= j; n       } n       j++; n     } n     if (ta > 1) d.push_back(ta); n     vector<int> e = {find(i)}; n     for (int x : d) { n       if (c[x] == -1) continue; n       e.push_back(c[x]); n     } n     for (j = 0; j < (int)((e).size()); j++) { n       for (int k = j + 1; k < (int)((e).size()); k++) { n         int x = e[j], y = e[k]; n         if (x == y) continue; n         if (x > y) swap(x, y); n         st.emplace(x, y); n       } n     } n   } n   while (q--) { n     int ts, t; n     cin >> ts >> t; n     ts--; n     t--; n     int x = find(ts), y = find(t); n     if (x > y) swap(x, y); n     if (x == y) { n       cout << 0 << nl; n     } else if (st.count({x, y})) { n       cout << 1 << nl; n     } else { n       cout << 2 << nl; n     } n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1108864220 ) n using namespace std; n const int MOD = 1000000007; n const int INF = 1000000000; n const double EPS = 1e-9; n const int HASH_POW = 29; n const long double PI = acos(-1.0); n mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); n long long nextLong(long long l, long long r) { n   uniform_int_distribution<long long> foo(l, r); n   return foo(rnd); n } n double nextDouble(double l, double r) { n   uniform_real_distribution<double> foo(l, r); n   return foo(rnd); n } n double workTime() { return double(clock()) / CLOCKS_PER_SEC; } n void myReturn(int code = 0) { exit(code); } n int n, p[100010], depth[100010]; n vector<int> G[100010]; n vector<int> order, oper; n bool compare(int u, int v) { return depth[u] < depth[v]; } n void dfs(int v) { n   depth[v] = 0; n   for (auto to : G[v]) { n     dfs(to); n     depth[v] = max(depth[v], depth[to] + 1); n   } n   sort(G[v].begin(), G[v].end(), compare); n } n void getOrder(int v) { n   order.push_back(v); n   for (auto to : G[v]) { n     getOrder(to); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   scanf( %d , &n); n   for (int i = 1; i < n; ++i) { n     scanf( %d , &p[i]); n     G[p[i]].push_back(i); n   } n   dfs(0); n   getOrder(0); n   for (int i = 1; i < n; ++i) { n     int v = order[i], par = order[i - 1]; n     while (par != p[v]) { n       oper.push_back(v); n       par = p[par]; n     } n   } n   for (auto i : order) { n     printf( %d  , i); n   } n   printf(  n%d n , oper.size()); n   for (auto i : oper) { n     printf( %d  , i); n   } n   myReturn(); n } n


#include <bits/stdc++.h> n using namespace std; n string to_string(string s) { return     + s +    ; } n string to_string(char c) { return      + string(1, c) +     ; } n string to_string(const char *s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A> n string to_string(A v) { n   bool first = true; n   string res =  { ; n   for (const auto &x : v) { n     if (!first) res +=  ,  ; n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n string to_str(const int &n) { n   ostringstream stm; n   stm << n; n   return stm.str(); n } n string to_str(const long long &n) { n   ostringstream stm; n   stm << n; n   return stm.str(); n } n template <class T> n string tostring(T x, int len = 0) { n   stringstream ss; n   ss << x; n   string r = ss.str(); n   if (int((r).size()) < len) r = string(len - int((r).size()),  0 ) + r; n   return r; n } n template <class T> n void convert(string x, T &r) { n   stringstream ss(x); n   ss >> r; n } n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= 1000000007; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % 1000000007; n     a = a * a % 1000000007; n   } n   return res; n } n long long modinv(long long a) { return powmod(a, 1000000007 - 2); } n long long modinv(long long a, long long m) { return powmod(a, m - 2); } n long long nCkMp(long long n, long long k) { n   long long numerator = 1, denominator = 1; n   for (int i = 0; i < k; i++) numerator = (numerator * (n - i)) % 1000000007; n   for (int i = 1; i <= k; i++) denominator = (denominator * i) % 1000000007; n   return (numerator * modinv(denominator)) % 1000000007; n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } n int TT = 1, tt; n clock_t t1; n void solve() { n   t1 = clock(); n   int n, m, c, q, res = 0; n   vector<int> x(105), y; n   (cin >> (n)); n   (cin >> (m)); n   for (auto i = (0); i < (m); i++) { n     (cin >> (q)); n     x[q]++; n   } n   for (auto i = (105 - 1); i >= (1); i--) { n     c = 0; n     for (auto j = (0); j < (105); j++) c += x[j] / i; n     if (c >= n) { n       res = i; n       break; n     } n   } n   (cout << (res) << endl); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   for (tt = 0; tt < TT; tt++) solve(); n   return EXIT_SUCCESS; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace chrono; n template <class T> n void show(vector<vector<T>> &a) { n   for (auto &i : a) { n     for (T &j : i) cout << j <<    ; n     cout << endl; n   } n } n template <class T> n void show(vector<T> &a) { n   for (T i : a) cout << i <<    ; n   cout << endl; n } n template <class T> n void show(vector<pair<T, T>> &a) { n   for (auto &i : a) { n     cout << i.first <<     << i.second << endl; n   } n } n template <class T> n void show(pair<T, T> p) { n   cout << p.first <<     << p.second << endl; n } n void show(vector<string> &a) { n   for (auto &i : a) cout << i << endl; n } n template <class T> n void take(vector<T> &a) { n   for (auto &i : a) cin >> i; n } n long long digits(long long n) { n   long long k = 0; n   while (n) k++, n /= 10; n   return k; n } n bool isprime(long long n) { n   long long i; n   if (n == 1) return 0; n   if (n == 2) return 1; n   if (n % 2 == 0) return 0; n   for (i = 3; i * i <= n; i += 2) { n     if (n % i == 0) return 0; n   } n   return 1; n } n long long power(long long x, long long y, long long MOD) { n   long long ans = 1; n   x %= MOD; n   while (y > 0) { n     if (y % 2 == 1) ans = (ans * x) % MOD; n     y /= 2; n     x = (x * x) % MOD; n   } n   return ans; n } n void sieve(vector<bool> &a, long long n) { n   long long i, j; n   a[1] = 0; n   a[0] = 0; n   long long h = sqrt(n + 1); n   for (i = 2; i < h; i++) { n     if (!a[i]) continue; n     for (j = 2 * i; j < n + 1; j += i) a[j] = 0; n   } n } n void load(unordered_map<long long, long long> &g) { g.max_load_factor(0.25); } n vector<long long> bits(long long n) { n   vector<long long> a; n   long long i; n   for (i = 0; i < 33; i++) { n     a.push_back(n % 2); n     n /= 2; n   } n   reverse(a.begin(), a.end()); n   return a; n } n void sub() {} n const long long N = 1e9 + 7; n const long long M = 998244353; n void solve() { n   long long i, j, n, m; n   cin >> n; n   vector<long long> a(n); n   take(a); n   long long ans = 0; n   for (i = 0; i < n; i++) n     if (a[i] == 1) ans++; n   ans = (power(2, ans, M) - 1 + M) % M; n   vector<long long> b(n + 3), c(n + 3); n   for (i = 0; i < n; i++) { n     if (a[i] == 0) b[0] = (2 * b[0] + 1) % M; n     if (a[i] == 1) b[1] = (2 * b[1] + b[0]) % M; n     if (a[i] > 1) b[a[i]] = (2 * b[a[i]] + b[a[i] - 1]) % M; n     if (a[i] > 1) c[a[i] - 1] = (2 * c[a[i] - 1] + b[a[i] - 2]) % M; n     c[a[i] + 1] = (2 * c[a[i] + 1]) % M; n   } n   for (i = 0; i < n + 1; i++) { n     ans = (ans + b[i] + c[i]) % M; n   } n   cout << ans <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   sub(); n   auto start1 = high_resolution_clock::now(); n   long long t = 1, s; n   cin >> t; n   for (s = 1; s < t + 1; s++) { n     solve(); n   } n   auto stop1 = high_resolution_clock::now(); n   auto duration = duration_cast<microseconds>(stop1 - start1); n   cerr <<  Time:   << (double)duration.count() / 1000 <<   ms  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> a[10], b[10]; n int main() { n   for (int i = 1; i <= 3; i++) scanf( %d %d , &a[i].first, &a[i].second); n   for (int i = 0; i < 8; i++) { n     for (int j = 1; j <= 3; j++) b[j] = a[j]; n     for (int j = 1; j <= 3; j++) n       if (i >> (j - 1) & 1) swap(b[j].first, b[j].second); n     if (b[1].first >= b[2].first + b[3].first && n         b[1].second >= max(b[2].second, b[3].second)) n       puts( YES ), exit(0); n     if (b[1].second >= b[2].second + b[3].second && n         b[1].first >= max(b[2].first, b[3].first)) n       puts( YES ), exit(0); n   } n   puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const int maxn = 505, maxm = 1005; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long powermod(long long a, long long b, long long c) { n   a = a % c; n   long long ans = 1; n   while (b) { n     if (b % 2) ans = (ans * a) % c; n     b = b / 2; n     a = (a * a) % c; n   } n   return ans; n } n long long a[100005]; n long long sum[100005]; n int main() { n   { n     long long n, m, i, j, k; n     scanf( %lld , &n); n     long long cnt = 0, cnt1 = 0; n     for (i = 1; i <= n; i++) { n       scanf( %lld , &a[i]); n       sum[a[i]]++; n       if (sum[a[i]] % 2 == 0) cnt++; n       if (sum[a[i]] % 4 == 0) cnt1++; n     } n     long long q, x; n     char s[10]; n     scanf( %lld , &q); n     while (q--) { n       scanf( %s%lld , s, &x); n       if (s[0] ==  + ) { n         sum[x]++; n         if (sum[x] % 2 == 0) cnt++; n         if (sum[x] % 4 == 0) cnt1++; n         if (cnt >= 4 && cnt1 >= 1) n           printf( YES n ); n         else n           printf( NO n ); n       } else { n         sum[x]--; n         if (sum[x] % 2 == 1) cnt--; n         if (sum[x] % 4 == 3) cnt1--; n         if (cnt >= 4 && cnt1 >= 1) n           printf( YES n ); n         else n           printf( NO n ); n       } n     } n   } 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   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     bool sym = false; n     for (int i = 0; i < n; i++) { n       int a, b, c, d; n       cin >> a >> b >> c >> d; n       if (b == c) sym = true; n     } n     cout << (!(m & 1) && sym ?  YES  :  NO ) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 100; n pair<long long, long long> p[maxn]; n long long m[maxn][2], mm[maxn][2], ycords[maxn], xcords[maxn]; n int n; n bool can(long long l) { n   for (int i = 0; i < n; i++) { n     if (i > 0 && p[i - 1].second == p[i].second) continue; n     long long newY = p[i].second + l; n     int ind = upper_bound(ycords, ycords + n, newY) - ycords; n     int ind1 = lower_bound(ycords, ycords + n, p[i].second) - ycords - 1; n     long long left = n         min(ind1 < 0 ? INT_MAX : mm[ind1][0], ind < n ? m[ind][0] : INT_MAX); n     long long right = n         max(ind1 < 0 ? -INT_MAX : mm[ind1][1], ind < n ? m[ind][1] : -INT_MAX); n     if (right - left <= l || (left == INT_MAX && right == -INT_MAX)) { n       return true; n     } n     newY = p[i].second - l; n     ind = upper_bound(ycords, ycords + n, p[i].second) - ycords; n     ind1 = lower_bound(ycords, ycords + n, newY) - ycords - 1; n     left = n         min(ind1 >= 0 ? mm[ind1][0] : INT_MAX, ind < n ? m[ind][0] : INT_MAX); n     right = n         max(ind1 >= 0 ? mm[ind1][1] : -INT_MAX, ind < n ? m[ind][1] : -INT_MAX); n     if (right - left <= l || (left == INT_MAX && right == -INT_MAX)) { n       return true; n     } n   } n   return false; n } n int main() { n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> p[i].first >> p[i].second; n   } n   pair<long long, long long> rot[n]; n   for (long long i = 0; i < n; i++) { n     rot[i].first = p[i].first - p[i].second; n     rot[i].second = p[i].second + p[i].first; n     p[i] = rot[i]; n   } n   sort(p, p + n, n        [](pair<long long, long long> a, pair<long long, long long> b) { n          swap(a.first, a.second); n          swap(b.first, b.second); n          return a < b; n        }); n   for (int i = 0; i < n; i++) { n     ycords[i] = p[i].second; n   } n   m[n - 1][0] = p[n - 1].first; n   m[n - 1][1] = p[n - 1].first; n   for (int i = n - 2; i >= 0; i--) { n     m[i][0] = min(m[i + 1][0], p[i].first); n     m[i][1] = max(m[i + 1][1], p[i].first); n   } n   mm[0][0] = p[0].first; n   mm[0][1] = p[0].first; n   for (int i = 1; i < n; i++) { n     mm[i][0] = min(mm[i - 1][0], p[i].first); n     mm[i][1] = max(mm[i - 1][1], p[i].first); n   } n   long long l = 0, r = 4 * (2e9 + 100); n   while (l < r) { n     long long mid = (l + r) / 2; n     bool result = can(mid); n     if (result) { n       r = mid; n     } else { n       l = mid + 1; n     } n   } n   cout << fixed << l / 2.f <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, m, p, k = 0; n   cin >> a >> m; n   p = a + m; n   while (1) { n     if ((k % 2) == 0) { n       p = p - 2; n       a--; n       m--; n       if (p == 1 || p == 0 || a == 0 || m == 0) { n         cout <<  Akshat ; n         break; n       } n     } else { n       p = p - 2; n       a--; n       m--; n       if (p == 1 || p == 0 || a == 0 || m == 0) { n         cout <<  Malvika ; n         break; n       } n     } n     k++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool containsr(int x21, int y21, int x22, int y22, int x11, int y11, int x12, n                int y12) { n   return x21 >= x11 && y21 >= y11 && x22 <= x12 && y22 <= y12; n } n int main() { n   int n; n   cin >> n; n   int found = 0; n   int x11 = -1, y11 = -1, x12 = -1, y12 = -1; n   int bottom = 1; n   int left = 1; n   int top = n; n   int right = n; n   int l = bottom, r = top; n   while (true) { n     if (l > r) { n       top = l; n       break; n     } n     int m = (r + l) / 2; n     cout <<  ?   << left <<     << bottom <<     << right <<     << m << endl; n     fflush(stdout); n     int res; n     cin >> res; n     if (res >= 1) { n       r = m - 1; n     } else { n       l = m + 1; n     } n   } n   l = bottom, r = top; n   while (true) { n     if (l > r) { n       bottom = r; n       break; n     } n     int m = (r + l) / 2; n     cout <<  ?   << left <<     << m <<     << right <<     << top << endl; n     fflush(stdout); n     int res; n     cin >> res; n     if (res >= 1) { n       l = m + 1; n     } else { n       r = m - 1; n     } n   } n   l = left, r = right; n   while (true) { n     if (l > r) { n       right = l; n       break; n     } n     int m = (r + l) / 2; n     cout <<  ?   << left <<     << bottom <<     << m <<     << top << endl; n     fflush(stdout); n     int res; n     cin >> res; n     if (res >= 1) { n       r = m - 1; n     } else { n       l = m + 1; n     } n   } n   l = left, r = right; n   while (true) { n     if (l > r) { n       left = r; n       break; n     } n     int m = (r + l) / 2; n     cout <<  ?   << m <<     << bottom <<     << right <<     << top << endl; n     fflush(stdout); n     int res; n     cin >> res; n     if (res >= 1) { n       l = m + 1; n     } else { n       r = m - 1; n     } n   } n   x11 = left, y11 = bottom, x12 = right, y12 = top; n   int x21 = -1, y21 = -1, x22 = -1, y22 = -1; n   bottom = 1; n   left = 1; n   top = n; n   right = n; n   l = bottom, r = top; n   while (true) { n     if (l > r) { n       top = l; n       break; n     } n     int m = (r + l) / 2; n     cout <<  ?   << left <<     << bottom <<     << right <<     << m << endl; n     fflush(stdout); n     int res; n     cin >> res; n     if (containsr(x11, y11, x12, y12, left, bottom, right, m)) { n       res--; n     } n     if (res >= 1) { n       r = m - 1; n     } else { n       l = m + 1; n     } n   } n   l = bottom, r = top; n   while (true) { n     if (l > r) { n       bottom = r; n       break; n     } n     int m = (r + l) / 2; n     cout <<  ?   << left <<     << m <<     << right <<     << top << endl; n     fflush(stdout); n     int res; n     cin >> res; n     if (containsr(x11, y11, x12, y12, left, m, right, top)) { n       res--; n     } n     if (res >= 1) { n       l = m + 1; n     } else { n       r = m - 1; n     } n   } n   l = left, r = right; n   while (true) { n     if (l > r) { n       right = l; n       break; n     } n     int m = (r + l) / 2; n     cout <<  ?   << left <<     << bottom <<     << m <<     << top << endl; n     fflush(stdout); n     int res; n     cin >> res; n     if (containsr(x11, y11, x12, y12, left, bottom, m, top)) { n       res--; n     } n     if (res >= 1) { n       r = m - 1; n     } else { n       l = m + 1; n     } n   } n   l = left, r = right; n   while (true) { n     if (l > r) { n       left = r; n       break; n     } n     int m = (r + l) / 2; n     cout <<  ?   << m <<     << bottom <<     << right <<     << top << endl; n     fflush(stdout); n     int res; n     cin >> res; n     if (containsr(x11, y11, x12, y12, m, bottom, right, top)) { n       res--; n     } n     if (res >= 1) { n       l = m + 1; n     } else { n       r = m - 1; n     } n   } n   x21 = left, y21 = bottom, x22 = right, y22 = top; n   cout <<  !   << x11 <<     << y11 <<     << x12 <<     << y12 <<     << x21 n        <<     << y21 <<     << x22 <<     << y22 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int f(string s1, string s2) { n   int k = 0; n   while (s2 != s1) { n     s2 += s2[0]; n     s2 = s2.substr(1); n     k++; n     if (k > s2.length()) return 1000000; n   } n   return k; n } n int main() { n   int n; n   cin >> n; n   vector<string> V(n); n   for (int i = 0; i < n; i++) cin >> V[i]; n   int MIN = 1000000, ans; n   for (int i = 0; i < n; i++) { n     ans = 0; n     for (int j = 0; j < n; j++) n       if (j != i) ans += f(V[i], V[j]); n     if (ans < MIN) MIN = ans; n   } n   if (MIN == 1000000) n     cout << -1 << endl; n   else n     cout << MIN << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n using graph = vector<vector<int>>; n const ll mod = 1e9 + 7; n const int MAX = 2e5; n int n; n map<pii, ll> memo; n int size[MAX]; n void dfs1(int v, int prev, const graph& G, const vector<ll>& V) { n   pii p(prev, v); n   ll res = 0; n   int cnt = 1; n   for (auto to : G[v]) n     if (to != prev) { n       dfs1(to, v, G, V); n       pii q(v, to); n       cnt += size[to]; n       res = (res - memo[q] + mod) % mod; n     } n   res = (res + cnt * V[v] % mod) % mod; n   size[v] = cnt; n   memo[p] = res; n } n void dfs2(int v, int prev, const graph& G, const vector<ll>& V) { n   ll val = memo[pii(-1, v)]; n   for (auto to : G[v]) n     if (to != prev) { n       ll x = memo[pii(v, to)]; n       ll c = size[to]; n       ll tmp = memo[pii(to, v)] = (val + x - V[v] * c % mod + mod) % mod; n       memo[pii(-1, to)] = (x - tmp + mod + V[to] * (n - c) % mod) % mod; n       dfs2(to, v, G, V); n     } n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0); n   cin >> n; n   vector<ll> V(n); n   for (int i = 0; i < n; i++) { n     cin >> V[i]; n     V[i] = (V[i] + mod) % mod; n   } n   graph G(n); n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b; n     a--, b--; n     G[a].push_back(b); n     G[b].push_back(a); n   } n   dfs1(0, -1, G, V); n   dfs2(0, -1, G, V); n   ll res = 0; n   for (int i = 0; i < n; i++) { n     res = (res + memo[pii(-1, i)]) % mod; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> a, b; n   int n, m; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int tmp; n     cin >> tmp; n     a.push_back(tmp); n   } n   cin >> m; n   for (int i = 0; i < m; i++) { n     int tmp; n     cin >> tmp; n     b.push_back(tmp); n   } n   sort(a.begin(), a.end()); n   sort(b.begin(), b.end()); n   int a3 = 0, b3 = 0; n   for (int i = a.size() - 1; i >= 0; i--) { n     int l = 0, r = m; n     while (l < r) { n       int mid = (l + r) / 2; n       if (b[mid] >= a[i]) { n         r = mid; n       } else n         l = mid + 1; n     } n     if ((n - i) - (m - l) >= (a3 - b3)) { n       a3 = n - i; n       b3 = m - l; n     } n   } n   cout << a3 * 3 + (n - a3) * 2 <<  :  << b3 * 3 + (m - b3) * 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T bigmod(T b, T p, T M) { n   long long ret = 1; n   for (; p > 0; p >>= 1) { n     if (p & 1) ret = (ret * b) % M; n     b = (b * b) % M; n   } n   return (T)ret; n } n template <class T> n inline T lcm(T a, T b) { n   return (a * b) / __gcd(a, b); n } n int dx4[] = {-1, 0, 1, 0}; n int dy4[] = {0, 1, 0, -1}; n int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; n int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1}; n int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2}; n int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1}; n const double PI = acos(-1.0), EPS = 1e-7; n const long long INF = (long long)1e18 + 7; n const int N = 2e5 + 5, M = 1e9 + 7; n string s, t; n int ok[N]; n char re[N]; n void fun() { n   ok[ A ]++; n   re[ A ] =  A ; n   ok[ b ]++; n   re[ b ] =  d ; n   ok[ d ]++; n   re[ d ] =  b ; n   ok[ H ]++; n   re[ H ] =  H ; n   ok[ I ]++; n   re[ I ] =  I ; n   ok[ M ]++; n   re[ M ] =  M ; n   ok[ O ]++; n   re[ O ] =  O ; n   ok[ o ]++; n   re[ o ] =  o ; n   ok[ p ]++; n   re[ p ] =  q ; n   ok[ q ]++; n   re[ q ] =  p ; n   ok[ T ]++; n   re[ T ] =  T ; n   ok[ U ]++; n   re[ U ] =  U ; n   ok[ V ]++; n   re[ V ] =  V ; n   ok[ v ]++; n   re[ v ] =  v ; n   ok[ W ]++; n   re[ W ] =  W ; n   ok[ w ]++; n   re[ w ] =  w ; n   ok[ X ]++; n   re[ X ] =  X ; n   ok[ x ]++; n   re[ x ] =  x ; n   ok[ Y ]++; n   re[ Y ] =  Y ; n } n int main() { n   fun(); n   cin >> s; n   t = s; n   reverse(s.begin(), s.end()); n   for (int i = 0; i < s.size(); i++) { n     if (ok[s[i]] && re[s[i]] == t[i]) n       ; n     else { n       puts( NIE ); n       return 0; n     } n   } n   puts( TAK ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, x, y; n int main() { n   cin >> n >> k; n   int l = 1, r = n, mid; n   while (l <= r) { n     if (l == r) { n       x = l; n       break; n     } n     mid = l + r >> 1; n     cout <<  1   << mid <<     << mid + 1 << endl; n     fflush(stdout); n     string s; n     cin >> s; n     if (s ==  TAK ) n       r = mid; n     else n       l = mid + 1; n   } n   l = 1, r = x - 1; n   while (l <= r) { n     if (l == r) { n       y = l; n       break; n     } n     mid = l + r >> 1; n     cout <<  1   << mid <<     << mid + 1 << endl; n     fflush(stdout); n     string s; n     cin >> s; n     if (s ==  TAK ) n       r = mid; n     else n       l = mid + 1; n   } n   if (y > 0) { n     cout <<  1   << y <<     << x << endl; n     fflush(stdout); n     string s; n     cin >> s; n     if (s ==  TAK ) { n       cout <<  2   << x <<     << y << endl; n       fflush(stdout); n       return 0; n     } n   } n   l = x + 1, r = n; n   while (l <= r) { n     if (l == r) { n       y = l; n       break; n     } n     mid = l + r >> 1; n     cout <<  1   << mid <<     << mid + 1 << endl; n     fflush(stdout); n     string s; n     cin >> s; n     if (s ==  TAK ) n       r = mid; n     else n       l = mid + 1; n   } n   cout <<  2   << x <<     << y << endl; n   fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int r; n bool check(int x, int y) { return 1ll * x * x + 3ll * y * y <= 4ll * r * r; } n int main(void) { n   scanf( %d , &r); n   int i = 1, j = 1; n   long long ans = 1; n   while (check(i, j + 2)) { n     ans += 2; n     j += 2; n   } n   do { n     i += 3; n     ++j; n     while ((j > 0) && ((!check(i, j)) || (!check(i + 1, j - 1)))) j -= 2; n     if (j > 0) ans += j * 2; n   } while (j > 0); n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 110000; n const int B = 60; n int n, q, mc; n int aint[4 * N][B]; n void update(int nod, int pozx, int pozy, int poz, int val) { n   int i; n   if (pozx == pozy) { n     for (i = 0; i < B; ++i) { n       aint[nod][i] = 1; n       if (i % val == 0) aint[nod][i]++; n     } n     return; n   } n   int mid = (pozx + pozy) / 2; n   if (mid >= poz) n     update(2 * nod, pozx, mid, poz, val); n   else n     update(2 * nod + 1, mid + 1, pozy, poz, val); n   for (i = 0; i < B; ++i) n     aint[nod][i] = n         aint[2 * nod][i] + aint[2 * nod + 1][(i + aint[2 * nod][i]) % B]; n } n int query(int nod, int pozx, int pozy, int poz1, int poz2) { n   if (poz1 <= pozx && pozy <= poz2) { n     int rez = aint[nod][mc]; n     mc = (mc + aint[nod][mc]) % B; n     return rez; n   } n   int mid = (pozx + pozy) / 2, rez = 0; n   if (mid >= poz1) rez = query(2 * nod, pozx, mid, poz1, poz2); n   if (mid < poz2) rez += query(2 * nod + 1, mid + 1, pozy, poz1, poz2); n   return rez; n } n int main() { n   int i; n   cin >> n; n   for (i = 1; i <= n; ++i) { n     int x; n     cin >> x; n     update(1, 1, n, i, x); n   } n   cin >> q; n   for (i = 1; i <= q; ++i) { n     char a; n     int p1, p2; n     cin >> a >> p1 >> p2; n     if (a ==  A ) { n       mc = 0; n       cout << query(1, 1, n, p1, p2 - 1) <<   n ; n     } else n       update(1, 1, n, p1, p2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int64_t a[4][4] = {0}; n int64_t b[4][4] = {0}; n int64_t chk(int64_t aa, int64_t bb) { n   if (aa == bb) return 0; n   if (aa == 3 && bb == 2) return 1; n   if (aa == 2 && bb == 1) return 1; n   if (aa == 1 && bb == 3) return 1; n   return 2; n } n int64_t ma[4][4] = {0}; n signed main() { n   int64_t k, A, B; n   cin >> k >> A >> B; n   for (int64_t i = 1; i <= 3; ++i) { n     for (int64_t j = 1; j <= 3; ++j) cin >> a[i][j]; n   } n   for (int64_t i = 1; i <= 3; ++i) { n     for (int64_t j = 1; j <= 3; ++j) cin >> b[i][j]; n   } n   if (k <= 100 * 1000) { n     int64_t curr1 = A; n     int64_t curr2 = B; n     int64_t la = 0, lb = 0; n     int64_t score1 = 0; n     int64_t score2 = 0; n     int64_t len = 0; n     int64_t hey_a = -1, hey_b = -1; n     for (int64_t t = 1; t <= k; ++t) { n       if (chk(curr1, curr2) == 1) n         score1++; n       else if (chk(curr1, curr2) == 2) n         score2++; n       int64_t _c1 = curr1, _c2 = curr2; n       curr1 = a[_c1][_c2]; n       curr2 = b[_c1][_c2]; n     } n     cout << score1 <<     << score2 <<   n ; n     return 0; n   } n   int64_t curr1 = A; n   int64_t curr2 = B; n   int64_t la = 0, lb = 0; n   int64_t score1 = 0; n   int64_t score2 = 0; n   int64_t len = 0; n   int64_t hey_a = -1, hey_b = -1; n   for (int64_t t = 1; t <= k; ++t) { n     if (ma[curr1][curr2] > 0) { n       hey_a = curr1, hey_b = curr2; n       len = t - ma[curr1][curr2]; n       break; n     } n     ma[curr1][curr2] = t; n     int64_t _c1 = curr1, _c2 = curr2; n     curr1 = a[_c1][_c2]; n     curr2 = b[_c1][_c2]; n   } n   int64_t tstart = -1; n   int64_t cnt1 = 0; n   curr1 = A, curr2 = B; n   for (int64_t t = 1; t <= k; ++t) { n     if (curr1 == hey_a && curr2 == hey_b) { n       tstart = t; n       break; n     } n     cnt1++; n     if (chk(curr1, curr2) == 1) n       la++; n     else if (chk(curr1, curr2) == 2) n       lb++; n     int64_t _c1 = curr1, _c2 = curr2; n     curr1 = a[_c1][_c2]; n     curr2 = b[_c1][_c2]; n   } n   for (int64_t t = tstart; t <= k; ++t) { n     if (chk(curr1, curr2) == 1) n       score1++; n     else if (chk(curr1, curr2) == 2) n       score2++; n     int64_t _c1 = curr1, _c2 = curr2; n     curr1 = a[_c1][_c2]; n     curr2 = b[_c1][_c2]; n     if (curr1 == hey_a && curr2 == hey_b) { n       break; n     } n   } n   if (len > 0 && (k - cnt1) / len > 0) { n     score1 = ((k - cnt1) / len) * score1; n     score2 = ((k - cnt1) / len) * score2; n   } n   score1 += la; n   score2 += lb; n   int64_t rem = 0; n   if (len > 0) rem = (k - cnt1) % len; n   if (rem > 0) { n     curr1 = hey_a; n     curr2 = hey_b; n     while (rem--) { n       if (chk(curr1, curr2) == 1) n         score1++; n       else if (chk(curr1, curr2) == 2) n         score2++; n       int64_t _c1 = curr1, _c2 = curr2; n       curr1 = a[_c1][_c2]; n       curr2 = b[_c1][_c2]; n     } n   } n   cout << score1 <<     << score2 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int pow_mod(int a, long long k, int mod) { n   if (k == 0) { n     return 1; n   } n   int sub = pow_mod(a, k / 2, mod); n   if (k % 2 == 0) { n     return ((long long)sub * sub) % mod; n   } else { n     return (((long long)sub * sub) % mod * a) % mod; n   } n } n int main() { n   int h, i, j, l; n   int t, n, m, k, q; n   int r, c; n   scanf( %d %d %d %d %d , &n, &m, &k, &r, &c); n   int ax, ay, bx, by; n   scanf( %d %d %d %d , &ax, &ay, &bx, &by); n   long long count; n   long long mod = 1e9 + 7; n   if (ax == bx && ay == by) { n     count = (long long)n * m; n   } else { n     count = (long long)n * m - (long long)r * c; n   } n   printf( %d n , pow_mod(k, count, mod)); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n const int mod = 1e9 + 7; n long long a[N], n, mx, cnt; n vector<int> v, e; n long long ans = 1; n long long pw(long long a, long long b) { n   if (b == 0) return 1; n   long long res = pw(a, b / 2); n   res = res * res % mod; n   if (b % 2) res = res * a % mod; n   return res; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]), mx = max(mx, a[i]); n   sort(a, a + n); n   for (int i = 2; i <= mx; i++) { n     v.clear(); n     e.clear(); n     for (int j = 1; j * j <= i; j++) { n       if (i % j == 0) { n         v.push_back(j); n         if (j * j != i) e.push_back(i / j); n       } n     } n     for (int j = (int)e.size() - 1; j >= 0; j--) v.push_back(e[j]); n     int now = 0; n     long long sum = 1, sum2 = 1; n     for (int j = 1; j < (int)v.size(); j++) { n       int to = lower_bound(a + now, a + n, v[j]) - a; n       sum = sum * pw(j, to - now) % mod; n       now = to; n     } n     sum = sum * pw((int)v.size(), n - now) % mod; n     now = 0; n     for (int j = 1; j < v.size() - 1; j++) { n       int to = lower_bound(a + now, a + n, v[j]) - a; n       sum2 = sum2 * pw(j, to - now) % mod; n       now = to; n     } n     sum2 = sum2 * pw((int)v.size() - 1, n - now) % mod; n     ans = (ans + sum) % mod; n     ans = (ans + mod - sum2) % mod; n   } n   ans = (ans + mod) % mod; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> s; n int a[2000]; n int main(int argc, char const *argv[]) { n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int i = 0; i < n; ++i) { n     for (int j = i + 1; j < n; ++j) { n       int sum = a[i] + a[j]; n       if (s.find(sum) == s.end()) n         s[sum] = 1; n       else n         s[sum]++; n     } n   } n   int ans = 0; n   for (auto i : s) { n     ans = max(ans, i.second); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(const vector<int>& pearl) { n   vector<pair<int, int>> ans; n   ans.reserve(pearl.size()); n   set<int> app; n   int l = 0; n   for (int i = 0; i < pearl.size(); i++) { n     int cur = pearl[i]; n     if (app.find(cur) != end(app)) { n       ans.push_back(make_pair(l + 1, i + 1)); n       l = i + 1; n       set<int>().swap(app); n     } else n       app.insert(cur); n   } n   if (l != pearl.size()) { n     if (l == 0) { n       printf( -1 n ); n       return; n     } n     ans[ans.size() - 1].second = pearl.size(); n   } n   printf( %d n , ans.size()); n   for (const auto& a : ans) printf( %d %d n , a.first, a.second); n } n int main() { n   int n; n   scanf( %d , &n); n   vector<int> pearl(n); n   for (int i = 0; i < n; i++) scanf( %d , &pearl[i]); n   solve(pearl); n } n


#include <bits/stdc++.h> n const int MAXN = 5E5 + 10; n int n; n int a[MAXN << 1]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; ++i) { n     int t = i + 1 >> 1; n     if (i & 1) n       a[t] = a[n - t + 1] = i; n     else n       a[n + t] = a[n * 2 - t] = i; n   } n   a[2 * n] = n; n   if (n & 1) n     a[n + 1 >> 1] = n; n   else n     a[n + (n >> 1)] = n; n   for (int i = 2 * n; i > 0; --i) printf( %d%c , a[i],   n  [i > 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double const pi = 3.1415926535897932384626433832795; n int const inf = (int)1e9; n long long const inf64 = (long long)2e18; n const string name =  d ; n vector<pair<int, int> > ans; n int n, d[21]; n void rec(int n, int x, int y, int z, bool rev) { n   if (n == 0) return; n   int now = n - 1; n   while (now >= 0 && d[now] == d[n - 1]) now--; n   if (now == -1) { n     if (rev) n       for (int i = 0; i < (int)n; i++) ans.push_back(make_pair(x, y)); n     else { n       for (int i = 0; i < (int)n - 1; i++) ans.push_back(make_pair(x, z)); n       ans.push_back(make_pair(x, y)); n       for (int i = 0; i < (int)n - 1; i++) ans.push_back(make_pair(z, y)); n     } n     return; n   } n   if (now + 1 == n - 1) { n     rec(now + 1, x, z, y, 1); n     ans.push_back(make_pair(x, y)); n     rec(now + 1, z, y, x, 1); n   } else { n     if (!rev) { n       rec(now + 1, x, y, z, 1); n       for (int it = 0; it < (int)n - now - 1; it++) n         ans.push_back(make_pair(x, z)); n       rec(now + 1, y, x, z, 1); n       for (int it = 0; it < (int)n - now - 1; it++) n         ans.push_back(make_pair(z, y)); n       rec(now + 1, x, y, z, 0); n     } else { n       rec(now + 1, x, z, y, 1); n       for (int it = 0; it < (int)n - now - 1; it++) n         ans.push_back(make_pair(x, y)); n       rec(now + 1, z, y, x, 1); n     } n   } n } n int main() { n   cin >> n; n   for (int i = 0; i < (int)n; i++) cin >> d[i]; n   reverse(d, d + n); n   rec(n, 0, 2, 1, 0); n   cout << ans.size() << endl; n   for (int i = 0; i < (int)ans.size(); i++) n     printf( %d %d n , ans[i].first + 1, ans[i].second + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, r; n int main() { n   cin >> n >> r; n   int ans = 0, Max = -1, mark = false; n   for (int i = 1; i <= r; i++) { n     int t = i, b = r, num = 0, cnt = 0; n     while (t > 0 && b > 0) { n       bool flag = false; n       if (b > t) { n         int c = b / t - 1; n         num += c; n         b -= t * c; n         if (b > t) { n           b -= t; n           num++; n         } n         flag = true; n       } else { n         if (t > b) { n           int c = t / b - 1; n           num += c; n           t -= b * c; n           if (t > b) { n             t -= b; n             num++; n           } n         } n       } n       cnt++; n       if (t == b) { n         num++; n         t -= b; n         cnt++; n         if (b == r) cnt--; n         if (cnt > Max && (max(b, t) == 1 && min(b, t) == 0) && num == n) { n           if (!flag) n             mark = true; n           else n             mark = false; n           Max = cnt; n           ans = i; n         } n       } n     } n   } n   if (Max == -1) { n     cout <<  IMPOSSIBLE  << endl; n     return 0; n   } n   string s; n   int t = ans, b = r; n   if (mark) swap(b, t); n   while (t > 0 && b > 0) { n     if (t >= b) { n       t -= b; n       s +=  T ; n     } else { n       b -= t; n       s +=  B ; n     } n   } n   reverse(s.begin(), s.end()); n   cout << n - Max << endl << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e6; n vector<int> g[MAXN], g1[MAXN]; n int n, p, mp, m, all_n; n void add(int t1, int t2) { n   g[t1 ^ 1].push_back(t2); n   g1[t2].push_back(t1 ^ 1); n   g[t2 ^ 1].push_back(t1); n   g1[t1].push_back(t2 ^ 1); n } n vector<int> order; n bool vis[MAXN]; n int comp[MAXN]; n vector<int> res; n void dfs1(int u) { n   vis[u] = 1; n   for (auto v : g[u]) { n     if (vis[v] == 1) continue; n     dfs1(v); n   } n   order.push_back(u); n } n void dfs2(int u, int c) { n   comp[u] = c; n   for (auto v : g1[u]) { n     if (comp[v] == 0) dfs2(v, c); n   } n } n bool solveSAT() { n   for (int i = 0; i <= all_n * 2 - 3; i++) { n     if (vis[i] == 0) dfs1(i); n   } n   reverse(order.begin(), order.end()); n   int cnt = 1; n   for (auto u : order) { n     if (comp[u] == 0) dfs2(u, cnt++); n   } n   for (int i = 0; i < all_n - 1; i++) { n     if (comp[2 * i] == comp[2 * i + 1]) { n       return 0; n     } n     if (comp[2 * i] > comp[2 * i + 1]) { n       res.push_back(i); n     } n   } n   return 1; n } n int main() { n   cin >> n >> p >> mp >> m; n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     x--; n     y--; n     add(x * 2, y * 2); n   } n   all_n = mp + p; n   for (int i = 0; i < p; i++) { n     int l, r; n     cin >> l >> r; n     if (l != 1) { n       add((l + p - 2) * 2, i * 2 + 1); n     } n     if (r != mp) { n       add((r + p - 1) * 2 + 1, i * 2 + 1); n     } n   } n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     x--; n     y--; n     add(x * 2 + 1, y * 2 + 1); n   } n   for (int i = 2; i < mp; i++) { n     add((i + p - 2) * 2, (i + p - 1) * 2 + 1); n   } n   if (!solveSAT()) { n     cout <<  -1 n ; n     return 0; n   } n   vector<int> st; n   int k = 1; n   for (auto t : res) { n     if (t < p) { n       st.push_back(t); n     } else { n       k = max(k, t - p + 2); n     } n   } n   cout << st.size() <<     << k << endl; n   for (int i = 0; i < st.size(); i++) cout << st[i] + 1 <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long const M = 2e5 + 10, M2 = 1e7 + 10, mod = 1e9 + 7, inf = 1e9 + 10, n                 sq = 450; n long long a[M], cnt[M], t1, t2, t0, x1; n pair<long long, long long> good, ans; n bool check(long long ind, long long sum) { n   if (sum - ind > x1) return 0; n   long long res = t2 * ind + t1 * (sum - ind); n   if (res >= sum * t0) return 1; n   return 0; n } n int32_t main() { n   long long x2; n   cin >> t1 >> t2 >> x1 >> x2 >> t0; n   bool flag = 0; n   good = make_pair(-1, -1); n   if (t1 > t2) swap(t1, t2), swap(x1, x2), flag = 1; n   for (long long i = 1; i <= x1 + x2; i++) { n     long long lo = 0, hi = min(x2, i); n     if (!check(hi, i)) continue; n     while (hi > lo + 1) { n       long long mid = (lo + hi) / 2; n       if (check(mid, i)) n         hi = mid; n       else n         lo = mid + 1; n     } n     long long best = hi; n     if (check(lo, i)) best = lo; n     long long res = best * t2 + t1 * (i - best); n     if (good.first == -1 || (res * good.second <= good.first * i)) n       good = make_pair(res, i), ans = make_pair(best, i - best); n   } n   swap(ans.first, ans.second); n   if (flag) n     cout << ans.second <<     << ans.first; n   else n     cout << ans.first <<     << ans.second; n } n


#include <bits/stdc++.h> n int pct(int x) { return __builtin_popcount(x); } n using namespace std; n char grid[101][101]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int n, m; n   char c; n   cin >> n >> m >> c; n   int row; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> grid[i][j]; n     } n   } n   set<char> s; n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (grid[i][j] != c && grid[i][j] !=  . ) { n         if (i + 1 < n && grid[i + 1][j] == c && s.find(grid[i][j]) == s.end()) { n           ans++; n           s.insert(grid[i][j]); n         } else if (i - 1 >= 0 && grid[i - 1][j] == c && n                    s.find(grid[i][j]) == s.end()) { n           ans++; n           s.insert(grid[i][j]); n         } else if (j + 1 < m && grid[i][j + 1] == c && n                    s.find(grid[i][j]) == s.end()) { n           ans++; n           s.insert(grid[i][j]); n         } else if (j - 1 >= 0 && grid[i][j - 1] == c && n                    s.find(grid[i][j]) == s.end()) { n           ans++; n           s.insert(grid[i][j]); n         } n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 100; n const long long INF = 1e12; n int solve(long long x) { n   int res = 0; n   while (x) { n     res += (x % 10); n     x /= 10; n   } n   return res; n } n int main() { n   ios::sync_with_stdio(false); n   long long n; n   while (cin >> n) { n     long long tmp = 0, b = 0; n     while (1) { n       tmp = tmp * 10 + 9; n       if (tmp > n) break; n       b = tmp; n     } n     cout << solve(b) + solve(n - b) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string lower(string s) { n   for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]); n   return s; n } n vector<string> sep(string s, char c) { n   string temp; n   vector<string> res; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] == c) { n       if (temp !=   ) res.push_back(temp); n       temp =   ; n       continue; n     } n     temp = temp + s[i]; n   } n   if (temp !=   ) res.push_back(temp); n   return res; n } n template <class T> n T toint(string s) { n   stringstream ss(s); n   T ret; n   ss >> ret; n   return ret; n } n template <class T> n string tostr(T inp) { n   string ret; n   stringstream ss; n   ss << inp; n   ss >> ret; n   return ret; n } n template <class T> n void D(T A[], int n) { n   for (int i = 0; i < n; i++) cout << A[i] <<    ; n   cout << endl; n } n template <class T> n void D(vector<T> A, int n = -1) { n   if (n == -1) n = A.size(); n   for (int i = 0; i < n; i++) cout << A[i] <<    ; n   cout << endl; n } n vector<int> edge[1001]; n vector<int> cost[1001]; n int main() { n   int n; n   scanf( %d , &n); n   vector<pair<int, int> > lst; n   for (int(i) = (0); (i) < (n); (i)++) { n     int pq; n     scanf( %d , &pq); n     lst.push_back((make_pair(pq, i))); n   } n   sort(lst.rbegin(), lst.rend()); n   int m; n   scanf( %d , &m); n   for (int(i) = (0); (i) < (m); (i)++) { n     int a, b, c; n     scanf( %d%d%d , &a, &b, &c); n     a--; n     b--; n     edge[b].push_back((a)); n     cost[b].push_back((c)); n   } n   long long ans = 1000000000000LL; n   for (int(i) = (0); (i) < (n); (i)++) { n     long long total = 0; n     bool tval = 1; n     for (int(j) = (0); (j) < (n); (j)++) { n       if (i == j) continue; n       if (edge[j].size() == 0) { n         tval = 0; n         break; n       } n       long long chs = 1000000000000LL; n       for (int(k) = (0); (k) < (edge[j].size()); (k)++) n         chs = min(chs, (long long)cost[j][k]); n       total += chs; n     } n     if (!tval) continue; n     ans = min(ans, total); n   } n   if (ans == 1000000000000LL) n     cout << -1 << endl; n   else n     cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   bool F = 1; n   for (int i = 2; (long long)i * i <= n; i++) { n     if (n % i == 0) { n       F = 0; n       break; n     } n   } n   bool F2 = 1; n   for (int i = 2; (long long)i * i <= n - 2; i++) { n     if ((n - 2) % i == 0) { n       F2 = 0; n       break; n     } n   } n   printf( %d n , F ? 1 : n % 2 == 0 || F2 ? 2 : 3); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n ostream &operator<<(ostream &os, vector<T> V) { n   os <<  [  ; n   for (auto v : V) os << v <<    ; n   os <<  ] ; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, set<T> S) { n   os <<  {  ; n   for (auto s : S) os << s <<    ; n   return os <<  } ; n } n template <class L, class R> n ostream &operator<<(ostream &os, pair<L, R> P) { n   return os <<  (  << P.first <<  ,  << P.second <<  ) ; n } n template <class L, class R> n ostream &operator<<(ostream &os, map<L, R> M) { n   os <<  {  ; n   for (auto m : M) os <<  (  << m.first <<  :  << m.second <<  )  ; n   return os <<  } ; n } n vector<long long> adj[500050]; n long long a[500050], b[500050]; n set<long long> s; n void dfs(long long x, long long pr) { n   for (long long i = 0; i < adj[x].size(); i++) n     if (adj[x][i] != pr) a[adj[x][i]] = *s.begin(), s.erase(s.begin()); n   b[x] = *s.begin(); n   s.erase(s.begin()); n   for (long long j = adj[x].size() - 1; j >= 0; j--) n     if (adj[x][j] != pr) dfs(adj[x][j], x); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, x, y; n   cin >> n; n   if (n == 1) { n     cout <<  1 2 ; n     return 0; n   } n   for (long long i = 2; i < 2 * n + 1; i++) s.insert(i); n   for (long long i = 0; i < n - 1; i++) n     cin >> x >> y, adj[x].push_back(y), adj[y].push_back(x); n   a[1] = 1; n   dfs(1, -1); n   for (long long i = 1; i < n + 1; i++) cout << a[i] <<     << b[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int n; n int a[15][15]; n void dp() { n   for (int i = 1; i <= n; i++) a[i][1] = 1; n   for (int j = 1; j <= n; j++) a[1][j] = 1; n   for (int i = 2; i <= n; i++) { n     for (int j = 2; j <= n; j++) { n       a[i][j] = a[i - 1][j] + a[i][j - 1]; n     } n   } n } n int main() { n   scanf( %d , &n); n   dp(); n   printf( %d , a[n][n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<pair<pair<long long, long long>, long long>> v; n   long long n, k; n   cin >> n >> k; n   long long p[n], c[n], ans[n]; n   for (int i = 0; i < n; i++) cin >> p[i]; n   for (int i = 0; i < n; i++) { n     cin >> c[i]; n     ans[i] = c[i]; n   } n   for (int i = 0; i < n; i++) { n     v.push_back({{p[i], c[i]}, i}); n   } n   sort(v.begin(), v.end()); n   multiset<long long, greater<long long>> s; n   for (int i = 0; i < n; i++) { n     pair<long long, long long> x = v[i].first; n     long long in = v[i].second; n     long long coin = x.second; n     int cnt = 0; n     for (auto e : s) { n       if (cnt >= k) break; n       ans[in] += e; n       cnt++; n     } n     s.insert(coin); n   } n   for (int i = 0; i < n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void debug_out(const char* name, Arg1&& arg1) { n   cout << name <<   =   << arg1 <<   ]  <<   n ; n } n template <typename Arg1, typename... Args> n void debug_out(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<   =   << arg1 <<  , ; n   debug_out(comma + 1, args...); n } n mt19937_64 rang( n     chrono::high_resolution_clock::now().time_since_epoch().count()); n const long long mod = 1e9 + 7; n const long long N = 3e5, M = N; n void Solve_main() { n   long long n, m, k; n   string s; n   char won =  # ; n   cin >> n >> s; n   deque<long long> d, r; n   for (long long i = (0); i < (n); ++i) { n     if (s[i] ==  D ) { n       d.push_back(i); n     } else { n       r.push_back(i); n     } n   } n   while (!d.empty() && !r.empty()) { n     if (d.front() < r.front()) { n       r.pop_front(); n       long long temp = d.front() + n; n       d.pop_front(); n       d.push_back(temp); n     } else { n       d.pop_front(); n       long long temp = r.front() + n; n       r.pop_front(); n       r.push_back(temp); n     } n   } n   if (!d.empty()) { n     cout <<  D  <<   n ; n   } else { n     cout <<  R  <<   n ; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   srand(chrono::high_resolution_clock::now().time_since_epoch().count()); n   long long tc = 1; n   for (long long i = 0; i < tc; i++) { n     Solve_main(); n   } n   cerr <<  [time:  << 1.0 * clock() / CLOCKS_PER_SEC <<  s]  ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void ckmax(T& x, T y) { n   x = (y > x ? y : x); n } n template <typename T> n inline void ckmin(T& x, T y) { n   x = (y < x ? y : x); n } n namespace Fread { n const int SIZE = 1 << 21; n char buf[SIZE], *S, *T; n inline char getchar() { n   if (S == T) { n     T = (S = buf) + fread(buf, 1, SIZE, stdin); n     if (S == T) return EOF; n   } n   return *S++; n } n }  // namespace Fread n namespace Fwrite { n const int SIZE = 1 << 21; n char buf[SIZE], *S = buf, *T = buf + SIZE; n inline void flush() { n   fwrite(buf, 1, S - buf, stdout); n   S = buf; n } n inline void putchar(char c) { n   *S++ = c; n   if (S == T) flush(); n } n struct NTR { n   ~NTR() { flush(); } n } ztr; n }  // namespace Fwrite n namespace Fastio { n struct Reader { n   template <typename T> n   Reader& operator>>(T& x) { n     char c = Fread ::getchar(); n     T f = 1; n     while (c <  0  || c >  9 ) { n       if (c ==  - ) f = -1; n       c = Fread ::getchar(); n     } n     x = 0; n     while (c >=  0  && c <=  9 ) { n       x = x * 10 + (c -  0 ); n       c = Fread ::getchar(); n     } n     x *= f; n     return *this; n   } n   Reader& operator>>(char& c) { n     c = Fread ::getchar(); n     while (c ==   n  || c ==    ) c = Fread ::getchar(); n     return *this; n   } n   Reader& operator>>(char* str) { n     int len = 0; n     char c = Fread ::getchar(); n     while (c ==   n  || c ==    ) c = Fread ::getchar(); n     while (c !=   n  && c !=    ) { n       str[len++] = c; n       c = Fread ::getchar(); n     } n     str[len] =   0 ; n     return *this; n   } n   Reader() {} n } cin; n const char endl =   n ; n struct Writer { n   template <typename T> n   Writer& operator<<(T x) { n     if (x == 0) { n       Fwrite ::putchar( 0 ); n       return *this; n     } n     if (x < 0) { n       Fwrite ::putchar( - ); n       x = -x; n     } n     static int sta[45]; n     int top = 0; n     while (x) { n       sta[++top] = x % 10; n       x /= 10; n     } n     while (top) { n       Fwrite ::putchar(sta[top] +  0 ); n       --top; n     } n     return *this; n   } n   Writer& operator<<(char c) { n     Fwrite ::putchar(c); n     return *this; n   } n   Writer& operator<<(char* str) { n     int cur = 0; n     while (str[cur]) Fwrite ::putchar(str[cur++]); n     return *this; n   } n   Writer& operator<<(const char* str) { n     int cur = 0; n     while (str[cur]) Fwrite ::putchar(str[cur++]); n     return *this; n   } n   Writer() {} n } cout; n }  // namespace Fastio n const int MAXN = 2e5; n int n; n void solve_case() { n   Fastio ::cin >> n; n   int ans = n; n   for (int i = n - 1; i >= 1; --i) { n     ans = (ans + i + 1) / 2; n   } n   Fastio ::cout << ans << Fastio ::endl; n   ans = n; n   for (int i = n - 1; i >= 1; --i) { n     Fastio ::cout << ans <<     << i << Fastio ::endl; n     ans = (ans + i + 1) / 2; n   } n } n int main() { n   int T; n   Fastio ::cin >> T; n   while (T--) { n     solve_case(); n   } n   return 0; n } n