#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const double eps = 1e-12; n const int inf = 2000000000; n const long long int infLL = (long long int)1e18; n long long int MOD = 1000000007; n int MOD1 = 1000000007; n int MOD2 = 1000000009; n inline bool checkBit(long long int n, long long int i) { n   return n & (1LL << i); n } n inline long long int setBit(long long int n, long long int i) { n   return n | (1LL << i); n   ; n } n inline long long int resetBit(long long int n, long long int i) { n   return n & (~(1LL << i)); n } n int dx[] = {0, 0, +1, -1}; n int dy[] = {+1, -1, 0, 0}; n inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } n inline bool isLeapYear(long long int year) { n   return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); n } n inline void normal(long long int &a) { n   a %= MOD; n   (a < 0) && (a += MOD); n } n inline long long int modMul(long long int a, long long int b) { n   a %= MOD, b %= MOD; n   normal(a), normal(b); n   return (a * b) % MOD; n } n inline long long int modAdd(long long int a, long long int b) { n   a %= MOD, b %= MOD; n   normal(a), normal(b); n   return (a + b) % MOD; n } n inline long long int modSub(long long int a, long long int b) { n   a %= MOD, b %= MOD; n   normal(a), normal(b); n   a -= b; n   normal(a); n   return a; n } n inline long long int modPow(long long int b, long long int p) { n   long long int r = 1LL; n   while (p) { n     if (p & 1) r = modMul(r, b); n     b = modMul(b, b); n     p >>= 1LL; n   } n   return r; n } n inline long long int modDiv(long long int a, long long int b) { n   return modMul(a, modPow(b, MOD - 2)); n } n bool comp(const pair<long long int, pair<long long int, long long int> > &p1, n           const pair<long long int, pair<long long int, long long int> > &p2) { n   return p1.first > p2.first; n } n bool comp1(const pair<long long int, long long int> &p1, n            const pair<long long int, long long int> &p2) { n   if (p1.first == p2.first) { n     return p1.second > p2.second; n   } n   return p1.first < p2.first; n } n long long int converter(string a) { n   long long int i, mul = 1LL, r, t, ans = 0LL; n   if (a.length() == 0) return 0; n   for (i = a.length() - 1; i >= 0; i--) { n     t = a[i] -  0 ; n     r = t % 10; n     ans += (mul * r); n     mul = mul * 10; n   } n   return ans; n } n int msb(unsigned x) { n   union { n     double a; n     int b[2]; n   }; n   a = x; n   return (b[1] >> 20) - 1023; n } n const int MAX = 400005; n long long int n, b, a[MAX]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cout.unsetf(ios::floatfield); n   cout.precision(20); n   cout.setf(ios::fixed, ios::floatfield); n   ; n   cin >> n >> b; n   memset(a, -1, sizeof(a)); n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   long long int tol = (b * 8LL) / n; n   long long int k = pow(2LL, tol); n   sort(a + 1, a + n + 1); n   int d = 0, len = 0, i = 1, j = 0, maxi = 0; n   while (i <= n) { n     while (1) { n       if ((d == k && a[j] != a[j + 1]) || (j == n)) n         break; n       else { n         if (a[j] != a[j + 1]) ++d; n         ++len; n         ++j; n       } n     } n     maxi = max(maxi, len); n     int savei = i; n     while (1) { n       if (a[i] == a[savei]) n         ++i, --len; n       else { n         --d; n         break; n       } n     } n   } n   cout << n - maxi <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long k, a, b; n   cin >> k >> a >> b; n   long long k1, k2, r1, r2; n   if (a >= 0) { n     k1 = a / k; n     r1 = a % k; n   } else { n     k1 = a / k; n     r1 = a % k; n     if (r1) { n       k1 -= 1; n       r1 += k; n     } n   } n   if (b >= 0) { n     k2 = b / k; n     r2 = b % k; n   } else { n     k2 = b / k; n     r2 = b % k; n     if (r2) { n       k2 -= 1; n       r2 += k; n     } n   } n   if (r1) { n     cout << (k2 - k1) <<   n ; n     ; n   } else { n     cout << (k2 - k1 + 1) <<   n ; n     ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10, T = 3010, size = 1 << 20, mod = 998244353, inf = 2e9; n const long long INF = 1e15; n template <class o> n void qr(o &x) { n   char c = getchar(); n   x = 0; n   int f = 1; n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) x = x * 10 + c -  0 , c = getchar(); n   x *= f; n } n template <class o> n void qw(o x) { n   if (x / 10) qw(x / 10); n   putchar(x % 10 +  0 ); n } n template <class o> n void pr1(o x) { n   if (x < 0) x = -x, putchar( - ); n   qw(x); n   putchar(   ); n } n template <class o> n void pr2(o x) { n   if (x < 0) x = -x, putchar( - ); n   qw(x); n   putchar(  n ); n } n int n, k, m, Q, a[N], b[N], c[N], R[N], lim[N], val[N], id[N], tot, ans, cnt; n int bl[T], br[T], pos[N], w[T][1 << 14], tag[N]; n void ask() { n   if (cnt) n     puts( -1 ); n   else n     pr2(ans); n } n void add(int x, int y, int z) { n   if (x > y) return; n   int p = pos[x], q = pos[y]; n   if (p == q) { n     for (auto i = x; i <= y; i++) w[p][val[i]]--, w[p][val[i] ^= z]++; n     return; n   } n   for (auto i = p + 1; i <= q - 1; i++) tag[i] ^= z; n   for (auto i = x; i <= br[p]; i++) w[p][val[i]]--, w[p][val[i] ^= z]++; n   for (auto i = bl[q]; i <= y; i++) w[q][val[i]]--, w[q][val[i] ^= z]++; n } n int count(int x, int y) { n   if (x > y) return 0; n   int p = pos[x], q = pos[y], s = 0; n   if (p == q) { n     for (auto i = x; i <= y; i++) s += (val[i] != tag[p]); n     return s; n   } n   for (auto i = p + 1; i <= q - 1; i++) s += w[i][tag[i]]; n   for (auto i = x; i <= br[p]; i++) s += (val[i] == tag[p]); n   for (auto i = bl[q]; i <= y; i++) s += (val[i] == tag[q]); n   return y - x + 1 - s; n } n void modify(int x, int y) { n   if (x > n) return; n   int z = x % k; n   cnt -= count(lim[z], R[z]); n   ans -= count(id[x], R[z]); n   add(id[x], R[z], y); n   cnt += count(lim[z], R[z]); n   ans += count(id[x], R[z]); n } n int main() { n   qr(n); n   qr(k); n   m = n - k + 1; n   qr(Q); n   for (auto i = 1; i <= n; i++) qr(a[i]); n   for (auto i = 1; i <= n; i++) qr(b[i]), c[i] = a[i] ^ b[i]; n   for (auto i = n; i >= 1; i--) c[i] ^= c[i - 1]; n   for (auto i = 0; i <= k - 1; i++) { n     int s = (n - i) / k + (i > 0), j, d = 0; n     for (j = !i ? k : i; s--; j += k) val[++tot] = d = c[j] ^ d, id[j] = tot; n     j -= k; n     R[i] = tot; n     if (j > m) n       lim[i] = tot, cnt += !!val[tot]; n     else n       lim[i] = tot + 1; n   } n   for (auto i = 1; i <= tot; i++) ans += !!val[i]; n   int len = max(sqrt(1.0 * n / k + 0.5), ceil(1.0 * n / 3000)), t = n / len; n   for (auto i = 1; i <= t; i++) bl[i] = br[i - 1] + 1, br[i] = i * len; n   if (R[t] < n) t++, bl[t] = br[t - 1] + 1, br[t] = n; n   for (auto i = 1; i <= t; i++) n     for (auto j = bl[i]; j <= br[i]; j++) pos[j] = i, w[i][val[j]]++; n   ask(); n   while (Q--) { n     char s[5]; n     int x, y; n     scanf( %s , s); n     qr(x); n     qr(y); n     if (s[0] ==  a ) n       modify(x, a[x] ^ y), modify(x + 1, a[x] ^ y), a[x] = y; n     else n       modify(x, b[x] ^ y), modify(x + 1, b[x] ^ y), b[x] = y; n     ask(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, c, d, e; n int main() { n   scanf( %d%d%d%d%d , &a, &b, &c, &d, &e); n   cout << min(a, min(b, min(c / 2, min(d / 7, e / 4)))); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, d; n long long dp[150005][5]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cin >> n >> m >> d; n   long long pt; n   long long prev, curr; n   for (long long i = 0; i < m; i++) { n     long long a, b, t; n     cin >> a >> b >> t; n     if (i == 0) { n       prev = 0; n       curr = 1; n       for (long long j = 1; j <= n; j++) dp[j][i] = b - abs(a - j); n       pt = t; n     } else { n       for (long long j = 1; j <= n; j++) dp[j][curr] = b - abs(a - j); n       long long s = (t - pt) * d; n       pt = t; n       deque<long long> mq; n       for (long long j = 1; j <= s + 1 && j <= n; j++) { n         while (!mq.empty() && dp[mq.back()][prev] < dp[j][prev]) mq.pop_back(); n         mq.push_back(j); n       } n       for (long long j = 1; j <= n; j++) { n         while (!mq.empty() && mq.front() < j - s) mq.pop_front(); n         dp[j][curr] += dp[mq.front()][prev]; n         if (j + s + 1 <= n) { n           while (!mq.empty() && j + s + 1 <= n && n                  dp[mq.back()][prev] < dp[j + 1 + s][prev]) n             mq.pop_back(); n           mq.push_back(j + s + 1); n         } n       } n       swap(prev, curr); n     } n   } n   long long sol = dp[1][prev]; n   for (int i = 2; i <= n; i++) n     if (sol < dp[i][prev]) sol = dp[i][prev]; n   cout << sol << endl; n   return 0; n } n


#include<bits/stdc++.h> n #define int long long n using namespace std; n inline int read() n { n     char c = getchar(); n     int x = 0, f = 1; n     while (c <  0  || c >  9 ) n     { n         if (c ==  - ) n             f = -1; n         c = getchar(); n     } n     while (c >=  0  && c <=  9 ) n     { n         x = (x << 1) + (x << 3) + (c ^ 48); n         c = getchar(); n     } n     return x * f; n } n template <class cl> n void put(cl x) n { n     if (x < 0) n         putchar( - ), x = -x; n     if (x > 9) n         put(x / 10); n     putchar(x % 10 +  0 ); n     return; n } n int n; n int a[55]; n signed main() n { n     int t; n     t=read(); n     int n; n     while(t--) n     { n         n=read(); n         int zheng=0,fu=0; n         for(int i=1;i<=n;i++) n         { n             a[i]=read(); n             if(a[i]>=0) zheng++; n             else fu++; n         } n         if( fu !=0) n         { n             puts( no );continue; n         } n         else  n         { n             puts( yes ); n             sort(a+1,a+1+n); n             if(a[n]>=0) n             { n                 cout<<a[n]+1<<  n ; n                 for(int i=0;i<=a[n];i++) n                 { n                     cout<<i<<   ; n                 } n                 cout<<  n ; n             } n         } n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n long n, m, k, c = 1, s = 1; n int main() { n   cin >> n >> m >> k; n   m -= n; n   while (m > 0) { n     if (k - c >= 1) s++; n     if (k + c <= n) s++; n     m -= s; n     c++; n   } n   cout << c; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n void fast() { n   std::ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n } n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   priority_queue<int> q; n   int val; n   while (n--) cin >> val, q.push(val); n   while (!q.empty()) n     if (k % q.top()) n       q.pop(); n     else n       return !printf( %d , k / q.top()); n } n


#include <bits/stdc++.h> n int main() { n   char a[110], b[110]; n   scanf( %s , a); n   getchar(); n   scanf( %s , b); n   int len = strlen(a); n   for (int i = 0; i < len; i++) { n     if (a[i] < b[i]) { n       printf( -1 ); n       return 0; n     } n   } n   for (int i = 0; i < len; i++) { n     if (a[i] == b[i]) n       printf( z ); n     else n       printf( %c , b[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n vector<long long> a; n vector<long long> res; n int main() { n   scanf( %I64d , &n); n   for (long long i = 1; i <= n; ++i) { n     scanf( %I64d , &m); n     for (long long j = 0; j < m; ++j) { n       a.push_back(i); n     } n   } n   scanf( %I64d , &m); n   for (long long i = 0; i < m; ++i) { n     scanf( %I64d , &n); n     res.push_back(a[n - 1]); n   } n   for (long long i = 0; i < (long long)res.size(); ++i) { n     printf( %I64d n , res[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n, y, i, j, a[5001]; n int main() { n   cin >> t; n   for (j = 1; j <= t; j++) { n     cin >> n; n     y = -1; n     cin >> a[1]; n     for (i = 2; i <= n; i++) { n       cin >> a[i]; n       if (y == -1) { n         if (a[1] != a[i]) y = i; n       } n     } n     if (y == -1) { n       cout <<  NO  << endl; n       continue; n     } else n       cout <<  YES  << endl; n     for (i = 2; i <= n; i++) { n       if (a[i] == a[1]) n         cout << y <<     << i << endl; n       else n         cout << 1 <<     << i << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int q; n long long n; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> q; n   while (q--) { n     cin >> n; n     int res = 0; n     while (n != 1) { n       if (n % 2 == 0) { n         n /= 2; n         res++; n       } else if (n % 3 == 0) { n         n = (n / 3) * 2; n         res++; n       } else if (n % 5 == 0) { n         n = (n / 5) * 4; n         res++; n       } else n         break; n     } n     if (n != 1) n       cout << -1 << endl; n     else n       cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e18; n const long long N = 2e5 + 33; n void solve() { n   int64_t n; n   cin >> n; n   vector<int64_t> v(n + 1); n   for (int64_t i = 0; i < n; i++) { n     cin >> v[i]; n   } n   vector<int64_t> ans(n + 10, 0); n   for (int64_t i = 0; i < n; i++) { n     vector<int64_t> mp(n + 10, 0); n     int64_t maxi = 0, num = 60000; n     for (int64_t j = i; j < n; j++) { n       mp[v[j]]++; n       if (maxi < mp[v[j]]) { n         maxi = mp[v[j]]; n         num = v[j]; n       } n       if (maxi == mp[v[j]] && num > v[j]) num = v[j]; n       ans[num]++; n     } n   } n   for (int64_t i = 1; i <= n; i++) cout << ans[i] <<    ; n } n signed main() { n   int64_t t = 1; n   while (t--) { n     solve(); n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int L[n]; n   for (int i = 0; i < n; ++i) scanf( %d , &L[i]); n   int imos[n + 1]; n   fill(imos, imos + n + 1, 0); n   for (int i = 0; i < n; ++i) { n     L[i] = min(L[i], i); n     ++imos[i - L[i]]; n     --imos[i]; n   } n   int t = 0, ans = n; n   for (int i = 0; i <= n; ++i) { n     t += imos[i]; n     if (t > 0) --ans; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 4e+18; n const int N = 100010; n struct rec { n   long long a, b, c; n }; n int cas, n; n long long x[N], y[N], z[N]; n rec get(long long la, long long ra, long long lb, long long rb, long long lc, n         long long rc, long long labc, long long rabc, int k) { n   la -= k, ra -= k, lb -= k, rb -= k, lc -= k, rc -= k; n   labc -= 3 * k, rabc -= 3 * k; n   if (la % 2 != 0) la++; n   if (ra % 2 != 0) ra--; n   if (lb % 2 != 0) lb++; n   if (rb % 2 != 0) rb--; n   if (lc % 2 != 0) lc++; n   if (rc % 2 != 0) rc--; n   if (labc % 2 != 0) labc++; n   if (rabc % 2 != 0) rabc--; n   if (la > ra || lb > rb || lc > rc || labc > rabc) return (rec){inf, inf, inf}; n   if (rabc < la + lb + lc) return (rec){inf, inf, inf}; n   if (labc > ra + rb + rc) return (rec){inf, inf, inf}; n   if (labc <= la + lb + lc && la + lb + lc <= rabc) n     return (rec){la + k, lb + k, lc + k}; n   if (labc <= ra + rb + rc && ra + rb + rc <= rabc) n     return (rec){ra + k, rb + k, rc + k}; n   if (labc <= la + lb + rc) return (rec){la + k, lb + k, labc - la - lb + k}; n   if (labc <= la + rb + rc) return (rec){la + k, labc - la - rc + k, rc + k}; n   return (rec){labc - rb - rc + k, rb + k, rc + k}; n } n rec check(long long mid) { n   long long la, lb, lc, labc, ra, rb, rc, rabc; n   la = lb = lc = labc = -inf; n   ra = rb = rc = rabc = inf; n   for (int i = 1; i <= n; i++) { n     la = max(la, -x[i] + y[i] + z[i] - mid); n     ra = min(ra, -x[i] + y[i] + z[i] + mid); n     lb = max(lb, x[i] - y[i] + z[i] - mid); n     rb = min(rb, x[i] - y[i] + z[i] + mid); n     lc = max(lc, x[i] + y[i] - z[i] - mid); n     rc = min(rc, x[i] + y[i] - z[i] + mid); n     labc = max(labc, x[i] + y[i] + z[i] - mid); n     rabc = min(rabc, x[i] + y[i] + z[i] + mid); n   } n   if (la > ra || lb > rb || lc > rc || labc > rabc) return (rec){inf, inf, inf}; n   rec tmp = get(la, ra, lb, rb, lc, rc, labc, rabc, 0); n   if (tmp.a != inf) return tmp; n   tmp = get(la, ra, lb, rb, lc, rc, labc, rabc, 1); n   if (tmp.a != inf) return tmp; n   return (rec){inf, inf, inf}; n } n int main() { n   scanf( %d , &cas); n   while (cas--) { n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) scanf( %lld%lld%lld , &x[i], &y[i], &z[i]); n     long long l = 0, r = inf; n     while (l < r) { n       long long mid = (l + r) >> 1; n       if (check(mid).a != inf) n         r = mid; n       else n         l = mid + 1; n     } n     rec ans = check(l); n     printf( %lld %lld %lld n , (ans.b + ans.c) / 2, (ans.a + ans.c) / 2, n            (ans.a + ans.b) / 2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010; n vector<int> v; n map<int, int> mp; n int main() { n   ios::sync_with_stdio(0); n   int T; n   cin >> T; n   while (T--) { n     string s1, s2; n     cin >> s1 >> s2; n     reverse(s1.begin(), s1.end()); n     reverse(s2.begin(), s2.end()); n     int len1 = s1.size(); n     int len2 = s2.size(); n     int pos1 = -1, pos2 = -1; n     for (int i = 0; i < len2; i++) { n       if (s2[i] ==  1 ) { n         pos2 = i; n         break; n       } n     } n     for (int i = pos2; i < len1; i++) { n       if (s1[i] ==  1 ) { n         pos1 = i; n         break; n       } n     } n     if (pos1 == pos2) n       cout << 0 << endl; n     else n       cout << pos1 - pos2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, c = 0; n   string s; n   cin >> n >> s; n   for (i = 0; i < n; i++) { n     if (s[i] == s[i + 1]) { n       c++; n     } n   } n   cout << c; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, x, y, s1, s2, i, j, a, b, c, r = 0; n   cin >> n >> s1 >> s2; n   long long x1[n + 1], x2[n + 1], y1[n + 1], y2[n + 1]; n   for (i = 1; i <= n; i++) { n     cin >> x >> y; n     x1[i] = min(x, s1), x2[i] = max(x, s1), y1[i] = min(y, s2), n     y2[i] = max(y, s2); n   } n   vector<pair<long long, long long> > v1; n   if (s1 - 1 >= 0) v1.push_back({s1 - 1, s2}); n   if (s1 + 1 <= 1e9) v1.push_back({s1 + 1, s2}); n   if (s2 - 1 >= 0) v1.push_back({s1, s2 - 1}); n   if (s2 + 1 <= 1e9) v1.push_back({s1, s2 + 1}); n   for (i = 0; i < v1.size(); i++) { n     x = v1[i].first, y = v1[i].second, c = 0; n     for (j = 1; j <= n; j++) { n       if (x >= x1[j] && x <= x2[j] && y >= y1[j] && y <= y2[j]) c++; n     } n     if (c >= r) r = c, a = x, b = y; n   } n   cout << r <<   n ; n   cout << a <<     << b <<   n ; n } n


#include <bits/stdc++.h> n int arr[101]; n int N; n int min = 999999999; n int memo[101][3]; n int findMin(int idx, int prev) { n   int min_Rest = 999999999; n   if (idx == N + 1) return 0; n   if (memo[idx][prev] != -1) return memo[idx][prev]; n   if (prev != 1 && (arr[idx] == 1 || arr[idx] == 3)) n     min_Rest = ((min_Rest) < (findMin(idx + 1, 1)) ? (min_Rest) n                                                    : (findMin(idx + 1, 1))); n   if (prev != 2 && (arr[idx] == 2 || arr[idx] == 3)) n     min_Rest = ((min_Rest) < (findMin(idx + 1, 2)) ? (min_Rest) n                                                    : (findMin(idx + 1, 2))); n   min_Rest = n       ((min_Rest) < (1 + findMin(idx + 1, 0)) ? (min_Rest) n                                               : (1 + findMin(idx + 1, 0))); n   memo[idx][prev] = min_Rest; n   return min_Rest; n } n int main() { n   int T, TC; n   { n     int i, j; n     scanf( %d , &N); n     for (i = 1; i <= N; i++) scanf( %d , &arr[i]); n     min = 999999999; n     for (i = 0; i <= N; i++) n       for (j = 0; j < 3; j++) memo[i][j] = -1; n     printf( %d n , findMin(1, 0)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool debug = false; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n long long a[305]; n int pt[20]; n int main() { n   scanf( %d , &n); n   for (int(i) = 0; (i) < (int)(n); (i)++) scanf( %lld , a + i + 1); n   long long ans = 0; n   int t; n   pt[0] = 1; n   for (int i = 1; i < 20; i++) pt[i] = 2 * pt[i - 1]; n   for (int i = 1; i < n; i++) { n     ans += a[i]; n     printf( %lld n , ans); n     for (t = 0; i + pt[t] <= n; t++) n       ; n     a[i + pt[t - 1]] += a[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   while (q--) { n     int a, b, c; n     cin >> a >> b >> c; n     int temp = min(a, b); n     if (temp * 3 <= a + b + c) { n       cout << temp << endl; n       continue; n     } else { n       cout << (a + b + c) / 3 << endl; n       continue; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, t; n   cin >> s >> t; n   string ans; n   long cnt = 0; n   for (long i = 0; i < s.size(); i++) { n     if (s[i] == t[i]) n       ans +=  1 ; n     else { n       if (cnt % 2) n         ans += s[i]; n       else n         ans += t[i]; n       cnt++; n     } n   } n   int d1 = 0, d2 = 0; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] != ans[i]) d1++; n     if (t[i] != ans[i]) d2++; n   } n   if (d1 == d2) n     cout << ans << endl; n   else n     cout <<  impossible  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B> n string to_string(pair<A, B> p); n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p); n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p); n string to_string(const string &s) { return     + s +    ; } n string to_string(const char *s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n string to_string(vector<bool> v) { n   bool first = true; n   string res =  { ; n   for (int i = 0; i < static_cast<int>(v.size()); i++) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(v[i]); n   } n   res +=  } ; n   return res; n } n template <size_t N> n string to_string(bitset<N> v) { n   string res =   ; n   for (size_t i = 0; i < N; i++) { n     res += static_cast<char>( 0  + v[i]); n   } n   return res; 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) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } 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, typename B, typename C> n string to_string(tuple<A, B, C> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ) ; n } n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,  + n          to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ; n } n void debug() { cerr << endl; } n template <typename Head, typename... Tail> n void debug(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug(T...); n } n struct Fast_power { n   long long integer(long long n, long long e, n                     long long my_mod = 9223372036854775807LL) { n     long long ans = 1; n     while (e) { n       if (e & 1) n         ans = (ans * n) % my_mod, e--; n       else n         n = (n * n) % my_mod, e >>= 1; n     } n     return ans; n   } n   long long matrix(vector<vector<long long>> &n, long long e, n                    long long my_mod = 9223372036854775807LL); n }; n struct Euclidean { n   int gcdi(int a, int b) { return b ? gcdi(b, a % b) : a; } n   double gcdf(double a, double b, double accuracy) { n     return b <= accuracy ? a : gcdf(b, fmod(a, b), accuracy); n   } n }; n const int maxnD = 200000 + 5; n struct Dijkstra { n   struct Edge { n     int from, to, dist; n   }; n   struct HeapNode { n     int d, u; n     bool operator<(const HeapNode &rhs) const { return d > rhs.d; } n   }; n   vector<Edge> edges; n   vector<int> G[maxnD]; n   bool done[maxnD]; n   int d[maxnD], p[maxnD], n, INF = 0x3f3f3f3f; n   void init(int n) { n     this->n = n; n     for (int i = 0; i <= n; i++) G[i].clear(); n     edges.clear(); n   } n   void AddEdge(int from, int to, int dist) { n     edges.push_back((Edge){from, to, dist}); n     int m = edges.size(); n     G[from].push_back(m - 1); n   } n   void dijkstra(int s) { n     priority_queue<HeapNode> q; n     memset(d, INF, sizeof(d)); n     d[s] = 0; n     memset(done, 0, sizeof(done)); n     q.push((HeapNode){0, s}); n     while (!q.empty()) { n       HeapNode x = q.top(); n       q.pop(); n       int u = x.u; n       if (done[u]) continue; n       done[u] = true; n       for (int i = 0; i < G[u].size(); i++) { n         Edge &e = edges[G[u][i]]; n         if (d[e.to] > d[u] + e.dist) { n           d[e.to] = d[u] + e.dist; n           p[e.to] = G[u][i]; n           q.push((HeapNode){d[e.to], e.to}); n         } n       } n     } n   } n }; n const int INF = 0x3f3f3f3f; n const int maxn = 200000; n int ch[maxn * 20][2] = {0}; n int cnt = 0; n void add(int *f) { n   int root = 0; n   for (int i = 0; i < 31; i++) { n     if (!ch[root][f[i]]) ch[root][f[i]] = ++cnt; n     root = ch[root][f[i]]; n   } n } n int dfs(int root) { n   int ans = 0; n   if (ch[root][0] && ch[root][1]) n     ans = max(dfs(ch[root][0]), dfs(ch[root][1])) + 1; n   else if (ch[root][0]) n     ans = dfs(ch[root][0]); n   else if (ch[root][1]) n     ans = dfs(ch[root][1]); n   else n     ans = 1; n   return ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   int num; n   for (int i = 0; i < n; i++) { n     cin >> num; n     int f[31] = {0}, cur = 0; n     while (num) f[cur++] = num % 2, num /= 2; n     for (int q = 0; q < 15; q++) swap(f[q], f[31 - q - 1]); n     add(f); n   } n   cout << n - dfs(0) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[2 * 100001]; n int color[2 * 100001]; n void dfs(int s, int p, int clr, int pclr) { n   color[s] = clr; n   int y = 1; n   for (int i = 0; i < v[s].size(); i++) { n     int u = v[s][i]; n     if (u == p) continue; n     while (y == clr || y == pclr) { n       y++; n     } n     dfs(u, s, y, clr); n     y++; n   } n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   memset(color, 0, sizeof color); n   dfs(1, 0, 1, -1); n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     ans = max(ans, color[i]); n   } n   cout << ans << endl; n   for (int i = 1; i <= n; i++) { n     cout << color[i] <<    ; n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n  n  n int main() n { n     long long int t; n     cin>>t; n     while(t--) n     { n         long long int i,j,k,l,m,n,c1=0,c2=0,ans=0,res=0; n         map<long long int,long long int>mp,mp1; n         vector<long long int>v,v1,v2; n         set<long long int>st,st1; n         vector<pair<long long int,long long int>>vp,vp1; n         cin>>n; n         long long int arr1[n]; n         for(i=0;i<n;i++)cin>>arr1[i]; n         m=*min_element(arr1,arr1+n); n         for(i=0;i<n;i++) n         { n             if(arr1[i]==m)c1++; n             if((arr1[i]&m)!=m)c2++; n         } n         if(c1<2||c2!=0)cout<<0<<endl; n         else n         {ans=c1*(c1-1); n         for(i=n-2;i>=1;i--) n         ans=(ans*i)%1000000007; n         cout<<ans<<endl; n         } n     } n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   s =  00  + s; n   int l = s.length(); n   int fi = 0, fj = 0, i, j, k, num; n   for (i = 0; i < l; i++) { n     for (j = i + 1; j < l; j++) { n       for (k = j + 1; k < l; k++) { n         num = 100 * (s[i] -  0 ) + 10 * (s[j] -  0 ) + (s[k] -  0 ); n         if (num % 8 == 0) { n           fi = fj = 1; n           break; n         } n       } n       if (fj) break; n     } n     if (fi) break; n   } n   if (fi) { n     cout <<  YES  << endl; n     for (int l = 2; l <= k; l++) { n       if (l < i) n         cout << s[l]; n       else { n         if (l == i || l == j || l == k) cout << s[l]; n       } n     } n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long a, long long n, long long lelo) { n   if (n == 0) return 1; n   if (n == 1) return a; n   if (n == 2) return (a * a) % lelo; n   if (n % 2) n     return (a * power(a, n - 1, lelo)) % lelo; n   else n     return power(power(a, n / 2, lelo), 2, lelo) % lelo; n } n void swap(long long &a, long long &b) { n   long long tm = a; n   a = b; n   b = tm; n } n const long long N = 1e+5; n bool comp(const pair<long long, long long> &p1, n           const pair<long long, long long> &p2) { n   if (p1.first != p2.first) n     return p1.first > p2.first; n   else n     return p1.second < p2.second; n } n long long n, k; n vector<long long> v; n bool chk(long long x) { n   for (long long(i) = (0); (i) < (n); (i)++) n     if (abs(v[i] - x) > k) return 0; n   return 1; n } n void solve() { n   cin >> n >> k; n   v.resize(n); n   for (long long(i) = (0); (i) < (n); (i)++) cin >> v[i]; n   sort((v).begin(), (v).end()); n   long long t1 = v[0] + k, t2 = v[n - 1] - k; n   if (v[n - 1] - v[0] <= k) { n     cout << v[0] + k; n     return; n   } n   if (t2 > t1) { n     cout << -1; n     return; n   } n   cout << t1; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long double tt = 1.0 * clock(); n   long long t = 1; n   cin >> t; n   for (long long(i) = (1); (i) < (t + 1); (i)++) { n     solve(); n     if (i < t) cout <<   n ; n   } n   tt = 1.000000000 * (clock() - tt) / CLOCKS_PER_SEC; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp_vector(const vector<int>& a, const vector<int>& b) { n   int i; n   for (i = 0; i < a.size(); i++) { n     if (a[i] > b[i]) { n       return false; n     } else if (a[i] < b[i]) { n       return true; n     } n   } n   return false; n } n int main() { n   int h, i, j, k; n   int t, n, m; n   int in; n   scanf( %d , &n); n   int c[n]; n   vector<vector<int> > a; n   for (i = 0; i < n; i++) { n     scanf( %d , &c[i]); n     vector<int> e; n     for (j = 0; j < c[i]; j++) { n       scanf( %d , &in); n       e.push_back(in); n     } n     a.push_back(e); n   } n   scanf( %d , &m); n   vector<vector<int> > b; n   for (i = 0; i < m; i++) { n     vector<int> e; n     for (j = 0; j < n; j++) { n       scanf( %d , &in); n       e.push_back(in - 1); n     } n     b.push_back(e); n   } n   sort(b.begin(), b.end(), cmp_vector); n   vector<int> test(n); n   int maxpower = 0; n   vector<int> answer(n); n   for (i = 0; i < n; i++) { n     test[i] = c[i] - 1; n   } n   if (!binary_search(b.begin(), b.end(), test)) { n     int power = 0; n     for (i = 0; i < n; i++) { n       power += a[i][test[i]]; n     } n     if (power > maxpower) { n       maxpower = power; n       for (i = 0; i < n; i++) { n         answer[i] = test[i]; n       } n     } n   } n   for (i = 0; i < b.size(); i++) { n     for (j = 0; j < n; j++) { n       test[j] = b[i][j]; n     } n     for (j = 0; j < n; j++) { n       if (b[i][j] != 0) { n         test[j]--; n         if (!binary_search(b.begin(), b.end(), test)) { n           int power = 0; n           for (k = 0; k < n; k++) { n             power += a[k][test[k]]; n           } n           if (power > maxpower) { n             maxpower = power; n             for (k = 0; k < n; k++) { n               answer[k] = test[k]; n             } n           } n         } n         test[j]++; n       } n     } n   } n   for (i = 0; i < n; i++) { n     printf( %d  , answer[i] + 1); n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (int)5e5 + 5; n vector<int> edges[MAXN]; n int n; n int l[MAXN]; n int r[MAXN]; n int cur = 2; n void go(int node, int p = 0) { n   int tt = 0; n   for (int i : edges[node]) { n     if (i == p) continue; n     tt++; n   } n   r[node] = cur + tt; n   int val = cur + tt - 1; n   for (int i : edges[node]) { n     if (i == p) continue; n     l[i] = val; n     val--; n   } n   cur = r[node] + 1; n   for (int i : edges[node]) { n     if (i == p) continue; n     go(i, node); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b; n     edges[a].push_back(b); n     edges[b].push_back(a); n   } n   l[1] = 1; n   go(1); n   for (int i = 1; i <= n; i++) cout << l[i] <<     << r[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n FILE* in = stdin; n FILE* out = stdout; n const int MAX = 2002; n int n, k; n char a[MAX]; n void solve() { n   vector<pair<int, int> > ans; n   int idx = 0; n   while (k > 1) { n     if (a[idx] !=  ( ) { n       int nxt = idx + 1; n       while (a[nxt] !=  ( ) nxt++; n       ans.push_back(make_pair(idx, nxt)); n       reverse(a + idx, a + nxt + 1); n     } n     idx++; n     if (a[idx] !=  ) ) { n       int nxt = idx + 1; n       while (a[nxt] !=  ) ) nxt++; n       ans.push_back(make_pair(idx, nxt)); n       reverse(a + idx, a + nxt + 1); n     } n     idx++; n     k--; n   } n   int rem = (n - idx) / 2; n   for (int i = 0; i < rem; i++) { n     if (a[idx + i] ==  ( ) { n       continue; n     } else { n       int nxt = idx + i + 1; n       while (a[nxt] !=  ( ) nxt++; n       ans.push_back(make_pair(idx + i, nxt)); n       reverse(a + idx + i, a + nxt + 1); n     } n   } n   fprintf(out,  %d n , (int)ans.size()); n   for (int i = 0; i < (int)ans.size(); i++) n     fprintf(out,  %d %d n , ans[i].first + 1, ans[i].second + 1); n } n int main(void) { n   int numTests; n   fscanf(in,  %d , &numTests); n   for (int test = 0; test < numTests; test++) { n     fscanf(in,  %d %d , &n, &k); n     fscanf(in,  %s , a); n     solve(); n   } n   return 0; n } n


// Omar_Elaraby n #include <bits/stdc++.h> n using namespace std; n typedef long long ll; n #define EPS 1e-9 n  n int main() { n  ios::sync_with_stdio(false); n  cin.tie(0), cout.tie(0); n // freopen( in.txt ,  r , stdin); n // freopen( out.txt ,  w , stdout); n  n  int tt; n  cin >> tt; n  while (tt--) { n   long long p; n   vector<ll> v(3); n   cin >> p; n   for (ll &i : v) { n    cin >> i; n   } n  n   long long ans = LLONG_MAX; n   for (int i = 0; i < 3; ++i) { n    if (v[i] >= p) ans = min(ans, v[i] - p); n    else ans = min(ans, v[i] * ((p + v[i] - 1) / v[i]) - p); n   } n   cout << ans <<   n ; n  } n  n  return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 110; n int n, m, z; n int mapp[maxn][maxn][maxn]; n bool vis[maxn][maxn][maxn]; n string s; n int main() { n   int ans = 0, num; n   memset(vis, false, sizeof(vis)); n   memset(mapp, 0, sizeof(mapp)); n   scanf( %d%d%d , &n, &m, &z); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       cin >> s; n       for (int k = 0; k < z; k++) { n         if (s[k] ==  1 ) mapp[i][j][k + 1] = 1; n       } n     } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       for (int k = 1; k <= z; k++) { n         if (mapp[i][j][k]) { n           if (mapp[i - 1][j][k] && mapp[i + 1][j][k] && !vis[i][j][k]) { n             ans++; n             vis[i][j][k] = true; n           } n           if (mapp[i][j - 1][k] && mapp[i][j + 1][k] && !vis[i][j][k]) { n             ans++; n             vis[i][j][k] = true; n           } n           if (mapp[i][j][k - 1] && mapp[i][j][k + 1] && !vis[i][j][k]) { n             ans++; n             vis[i][j][k] = true; n           } n           if (mapp[i + 1][j][k] && mapp[i][j - 1][k] && n               !mapp[i + 1][j - 1][k] && !vis[i][j][k]) { n             ans++; n             vis[i][j][k] = true; n           } n           if (!mapp[i - 1][j + 1][k] && mapp[i][j + 1][k] && n               mapp[i - 1][j][k] && !vis[i][j][k]) { n             ans++; n             vis[i][j][k] = true; n           } n           if (mapp[i + 1][j][k] && mapp[i][j][k - 1] && n               !mapp[i + 1][j][k - 1] && !vis[i][j][k]) { n             ans++; n             vis[i][j][k] = true; n           } n           if (!mapp[i - 1][j][k + 1] && mapp[i][j][k + 1] && n               mapp[i - 1][j][k] && !vis[i][j][k]) { n             ans++; n             vis[i][j][k] = true; n           } n           if (mapp[i][j + 1][k] && mapp[i][j][k - 1] && n               !mapp[i][j + 1][k - 1] && !vis[i][j][k]) { n             ans++; n             vis[i][j][k] = true; n           } n           if (!mapp[i][j - 1][k + 1] && mapp[i][j][k + 1] && n               mapp[i][j - 1][k] && !vis[i][j][k]) { n             ans++; n             vis[i][j][k] = true; n           } n         } n       } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int OO = 1e9; n const double EPS = 1e-9; n template <class T> n void _db(const char* dbStr, T e) { n   cout << dbStr <<   =   << e << endl; n } n template <class T, class... L> n void _db(const char* dbStr, T e, L... r) { n   while (*dbStr !=  , ) cout << *dbStr++; n   cout <<   =   << e <<  , ; n   _db(dbStr + 1, r...); n } n template <class S, class T> n ostream& operator<<(ostream& o, const map<S, T>& v) { n   o <<  [ ; n   int i = 0; n   for (const pair<S, T>& pr : v) n     o << (!i++ ?    :  ,  ) <<  {  << pr.first <<   :   << pr.second <<  } ; n   return o <<  ] ; n } n template <template <class, class...> class S, class T, class... L> n ostream& operator<<(ostream& o, const S<T, L...>& v) { n   o <<  [ ; n   int i = 0; n   for (const auto& e : v) o << (!i++ ?    :  ,  ) << e; n   return o <<  ] ; n } n template <class S, class T> n ostream& operator<<(ostream& o, const pair<S, T>& pr) { n   return o <<  (  << pr.first <<  ,   << pr.second <<  ) ; n } n ostream& operator<<(ostream& o, const string& s) { n   for (const char& c : s) o << c; n   return o; n } n template <class T> n using V = vector<T>; n template <class T> n using VV = V<V<T>>; n template <class T> n using VVV = VV<V<T>>; n using ll = long long; n using pii = pair<int, int>; n using vi = V<int>; n using vii = V<pii>; n using vvi = VV<int>; n using mii = map<int, int>; n using umii = unordered_map<int, int>; n using si = set<int>; n using usi = unordered_set<int>; n int n, r, c; n V<string> s; n vi sum; n vvi adj; n vi path; n pii ans = make_pair(0, 0); n bool good(int i, int j) { return sum[j] - sum[i - 1] + (j - i) > c; } n void dfs(int u, int p) { n   path.push_back(u); n   int l = path[max(int(path.size()) - 1 - r, 0)] - u; n   true; n   if (l > ans.first) ans = make_pair(l, u); n   for (auto& v : adj[u]) { n     if (v != p) dfs(v, u); n   } n   path.pop_back(); n } n int main() { n   ios::sync_with_stdio(false); n   cout.precision(10); n   cin.tie(0); n   cin >> n >> r >> c; n   s.assign(n + 2,   ); n   sum.assign(n + 2, 0); n   adj.assign(n + 2, vi()); n   for (int i = 1; i <= n; ++i) { n     cin >> s[i]; n     sum[i] = sum[i - 1] + int(s[i].size()); n   } n   sum.back() = OO; n   vi next(n + 2, n + 1); n   for (int i = 1; i <= n; ++i) { n     int lo = i, hi = n + 1; n     while (lo < hi) { n       int mid = (lo + hi) / 2; n       if (good(i, mid)) n         hi = mid; n       else n         lo = mid + 1; n     } n     true; n     next[i] = lo; n     adj[next[i]].push_back(i); n   } n   true; n   for (int i = 1; i <= n + 1; ++i) { n     if (next[i] == i) dfs(i, i); n   } n   true; n   if (!ans.first) n     cout <<   n ; n   else { n     for (int l = ans.second, r = ans.second + ans.first, Sz = int(s[l].size()); n          l < r; ++l) { n       cout << s[l]; n       if (l + 1 == r || (l + 1 < r && Sz + 1 + int(s[l + 1].size()) > c)) { n         cout <<   n ; n         Sz = int(s[l + 1].size()); n       } else { n         cout <<    ; n         Sz += 1 + int(s[l + 1].size()); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   for (int j = 0; j < q; j++) { n     int n; n     long long int k; n     cin >> n >> k; n     long long int a[n]; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     sort(a, a + n); n     long long int mi, ma; n     mi = a[0]; n     ma = a[n - 1]; n     long long int diff = ma - mi; n     if (diff % 2 == 0) n       diff = diff / 2; n     else n       diff = diff / 2 + 1; n     if (k >= diff) { n       cout << mi + k << endl; n     } else n       cout << -1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using vi = vector<int>; n using vvi = vector<vi>; n using vvvi = vector<vvi>; n using ll = long long; n using vll = vector<ll>; n using vvll = vector<vll>; n using vvvll = vector<vvll>; n using ull = unsigned long long; n using vb = vector<bool>; n using vvb = vector<vb>; n using vd = vector<double>; n using vvd = vector<vd>; n using vvvd = vector<vvd>; n using vs = vector<string>; n using vvs = vector<vs>; n using vc = vector<char>; n using vvc = vector<vc>; n using ii = pair<int, int>; n using vii = vector<ii>; n using vvii = vector<vii>; n using dd = pair<double, double>; n using vdd = vector<dd>; n using vvdd = vector<vdd>; n using Mii = map<int, int>; n using vMii = vector<Mii>; n using Si = set<int>; n using vSi = vector<Si>; n using vvSi = vector<vSi>; n int main() { n   int n; n   while (cin >> n) { n     vi a; n     vector<pair<ll, ll>> v(n); n     for (int i = 0; i < n; ++i) { n       int x, y; n       cin >> x >> y; n       v[i] = {x, y}; n     } n     vll d(n); n     for (int i = 0; i < n; ++i) { n       d[i] = (v[i].first - v[0].first) * (v[i].first - v[0].first) + n              (v[i].second - v[0].second) * (v[i].second - v[0].second); n     } n     bool par = true; n     for (int i = 0; i < n and par; ++i) { n       if (d[i] & 1LL) par = false; n     } n     while (par) { n       for (int i = 0; i < n; ++i) { n         d[i] >>= 1LL; n         if (d[i] & 1LL) par = false; n       } n     } n     for (int i = 0; i < n; ++i) n       if (d[i] & 1LL) a.push_back(i + 1); n     cout << a.size() << endl; n     for (int x : a) cout << x <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int N; n signed long long mo = 1000000007; n signed long long ret = 1; n signed long long from[303][303]; n signed long long to[303][303]; n signed long long combi(int P_, int Q_) { n   static const int N_ = 1020; n   static signed long long C_[N_][N_]; n   if (C_[0][0] == 0) { n     int i, j; n     for (i = 0; i < (N_); i++) C_[i][0] = C_[i][i] = 1; n     for (i = 1; i < N_; i++) n       for (j = 1; j < i; j++) C_[i][j] = (C_[i - 1][j - 1] + C_[i - 1][j]) % mo; n   } n   if (P_ < 0 || P_ > N_ || Q_ < 0 || Q_ > P_) return 0; n   return C_[P_][Q_]; n } n signed long long hcomb(int P_, int Q_) { n   return (P_ == 0 && Q_ == 0) ? 1 : combi(P_ + Q_ - 1, Q_); n } n void solve() { n   int i, j, k, l, r, x, y; n   string s; n   map<int, int> M; n   cin >> N; n   for (i = 0; i < (N); i++) { n     cin >> x; n     for (j = 2; j * j <= x; j++) n       while (x % (j * j) == 0) x /= j * j; n     M[x]++; n   } n   from[1][0] = 1; n   for (auto& r : M) { n     int cnt = r.second; n     for (j = 1; j <= cnt; j++) ret = ret * j % mo; n     memset(to, 0, sizeof(to)); n     for (x = 0; x < (N + 2); x++) n       for (y = 0; y < (N + 2); y++) n         if (from[x][y]) { n           for (j = 1; j <= min(x + y, cnt); j++) { n             signed long long a = hcomb(j, cnt - j); n             int add = cnt - j; n             for (int z = 0; z <= min(j, x); z++) { n               int w = j - z; n               if (w > y) continue; n               signed long long b = combi(x, z); n               signed long long c = combi(y, w); n               (to[x + z + 2 * w][y - w + add] += n                a * b % mo * c % mo * from[x][y]) %= mo; n             } n           } n         } n     swap(from, to); n   } n   cout << ret * from[N + 1][0] % mo << endl; n } n int main(int argc, char** argv) { n   string s; n   int i; n   if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); n   for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ; n   for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 52; n struct node { n   int v, w, nxt; n } e[N << 1]; n int s, n, m, first[N], cnt = 1, siz[N], de[N]; n inline void add(int u, int v, int w) { n   e[++cnt].v = v; n   e[cnt].w = w; n   e[cnt].nxt = first[u]; n   first[u] = cnt; n   ++de[u]; n } n inline void dfs(int u, int f) { n   for (int i = first[u]; i; i = e[i].nxt) { n     int v = e[i].v; n     if (v == f) continue; n     dfs(v, u); n     siz[u] += siz[v]; n   } n } n int dp[N << 1][N][N]; n inline int solve(int i, int x, int y) { n   if (x + y == 0) return 0; n   int v = e[i].v; n   int &f = dp[i][x][y]; n   if (f != -1) return f; n   if (de[v] == 1) { n     if (y == 0) n       return 0; n     else { n       f = solve(i ^ 1, y, 0) + e[i].w; n       return f; n     } n   } n   int g[N]; n   memset(g, 0, sizeof(g)); n   g[0] = 0x3f3f3f3f; n   for (int j = first[v]; j; j = e[j].nxt) { n     if (j == (i ^ 1)) continue; n     for (int k = x; k >= 1; --k) n       for (int w = k; w; --w) n         g[k] = max(g[k], min(g[k - w], e[j].w + solve(j, w, x + y - w))); n   } n   return f = g[x]; n } n int main() { n   memset(dp, -1, sizeof(dp)); n   scanf( %d , &n); n   for (int i = 1, u, v, w; i < n; ++i) { n     scanf( %d%d%d , &u, &v, &w); n     add(u, v, w); n     add(v, u, w); n   } n   scanf( %d%d , &s, &m); n   for (int i = 1, x; i <= m; ++i) { n     scanf( %d , &x); n     siz[x]++; n   } n   dfs(s, 0); n   int ans = 0x3f3f3f3f; n   for (int i = first[s]; i; i = e[i].nxt) { n     int v = e[i].v; n     ans = min(ans, solve(i, siz[v], m - siz[v]) + e[i].w); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct chip { n   char dir; n   chip *u, *r, *d, *l; n   chip(char _dir) { n     dir = _dir; n     u = r = d = l = NULL; n   } n }; n int main(int argc, char* argv[]) { n   int n, m; n   cin >> n >> m; n   chip*** t; n   t = (chip***)malloc(n * sizeof(chip**)); n   for (int i = 0; i < n; i++) t[i] = (chip**)malloc(m * sizeof(chip*)); n   char d; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> d; n       if (d !=  . ) { n         t[i][j] = new chip(d); n         if (i > 0) { n           int k = i - 1; n           while ((k >= 0) && (t[k][j] == NULL)) k--; n           if (k >= 0) { n             t[k][j]->d = t[i][j]; n             t[i][j]->u = t[k][j]; n           } n         } n         if (j > 0) { n           int k = j - 1; n           while ((k >= 0) && (t[i][k] == NULL)) k--; n           if (k >= 0) { n             t[i][k]->r = t[i][j]; n             t[i][j]->l = t[i][k]; n           } n         } n       } else n         t[i][j] = NULL; n     } n   } n   int max = 0; n   int count = 0; n   vector<chip*> v; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       v.clear(); n       chip* c = t[i][j]; n       while (c != NULL) { n         v.push_back(c); n         chip* e; n         if (c->dir ==  U ) e = c->u; n         if (c->dir ==  R ) e = c->r; n         if (c->dir ==  D ) e = c->d; n         if (c->dir ==  L ) e = c->l; n         if (c->u != NULL) c->u->d = c->d; n         if (c->r != NULL) c->r->l = c->l; n         if (c->d != NULL) c->d->u = c->u; n         if (c->l != NULL) c->l->r = c->r; n         c = e; n       } n       if (v.size() > max) { n         max = v.size(); n         count = 0; n       } n       if (v.size() == max) count++; n       for (vector<chip*>::reverse_iterator r = v.rbegin(); r < v.rend(); r++) { n         chip* e = *r; n         if (e->u != NULL) e->u->d = e; n         if (e->r != NULL) e->r->l = e; n         if (e->d != NULL) e->d->u = e; n         if (e->l != NULL) e->l->r = e; n       } n     } n   } n   cout << max <<     << count << endl; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) free(t[i][j]); n   for (int i = 0; i < n; i++) free(t[i]); n   free(t); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, ans, c, d; n int a[1005][1005], b[1005][1005]; n string s[1003]; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n   } n   for (int i = 0; i < n; i++) { n     d = 0; n     for (int j = 0; j < m; j++) { n       if (s[i][j] ==  * ) d++; n     } n     (d > 0) ? d-- : d; n     for (int j = 0; j < m; j++) { n       if (s[i][j] ==  * ) a[i][j] = d; n     } n   } n   for (int i = 0; i < m; i++) { n     d = 0; n     for (int j = 0; j < n; j++) { n       if (s[j][i] ==  * ) d++; n     } n     (d > 0) ? d-- : d; n     for (int j = 0; j < n; j++) { n       if (s[j][i] ==  * ) b[j][i] = d; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (s[i][j] ==  * ) { n         ans += a[i][j] * b[i][j]; n       } n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int N_MAX = 102; n const int K_MAX = 10002; n const int MOD = 1e9 + 7; n int pwr(int a, long long b) { n   if (b == 0) return 1; n   if (b & 1) return 1LL * a * pwr(a, (b ^ 1)) % MOD; n   int aux = pwr(a, (b >> 1)); n   return 1LL * aux * aux % MOD; n } n int n, k; n long long m; n int comb[N_MAX]; n int pw[N_MAX][N_MAX]; n int dp[N_MAX][K_MAX]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> k; n   for (int i = 0; i <= n; i++) { n     comb[i] = 1; n     for (int j = i + 1; j <= n; j++) comb[i] = 1LL * comb[i] * j % MOD; n     for (int j = 1; j <= n - i; j++) n       comb[i] = 1LL * comb[i] * pwr(j, MOD - 2) % MOD; n   } n   for (int c = 0; c <= n; c++) n     for (int i = 1; i <= n; i++) pw[c][i] = pwr(comb[c], (m - i) / n + 1); n   dp[0][0] = 1; n   for (int i = 1; i <= n; i++) n     for (int j = 0; j <= k; j++) { n       for (int c = 0; c <= j && c <= n; c++) { n         dp[i][j] += 1LL * dp[i - 1][j - c] * pw[c][i] % MOD; n         if (dp[i][j] >= MOD) dp[i][j] -= MOD; n       } n     } n   cout << dp[n][k] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   vector<int> A(n + 7); n   for (int i = 1; i <= n; i++) cin >> A[i]; n   vector<int> B(n); n   for (int i = 1; i <= n; i++) B[i - 1] = i; n   sort(B.begin(), B.end(), [&](int a, int b) { return A[a] > A[b]; }); n   set<int> G, S; n   multiset<int> O; n   G.insert(0); n   G.insert(n + 1); n   O.insert(n + 1); n   int ret = A[B[0]] + 1, loc = 1; n   for (int bb = 0; bb < n; bb++) { n     int b = B[bb]; n     auto jt = G.upper_bound(b); n     auto it = prev(jt); n     int dif = (*jt - *it); n     O.erase(O.find(dif)); n     int p = (*jt - b); n     int q = (b - *it); n     if (p != 1) O.insert(p); n     if (q != 1) O.insert(q); n     if ((O.empty() or *O.begin() == *O.rbegin()) and loc <= int(O.size())) { n       loc = int(O.size()); n       ret = A[B[bb + 1]] + 1; n     } n     G.insert(b); n   } n   cout << ret <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MOD = (long long int)1e9 + 7; n long long int powmod(long long int a, long long int b) { n   long long int res = 1; n   while (b > 0) { n     if (b & 1) res = (res * a) % MOD; n     a = (a * a) % MOD; n     b = b >> 1; n   } n   return res % MOD; n } n vector<vector<long long int> > G; n void solve(long long int testnum) { n   long long int n, m; n   cin >> n >> m; n   G.resize(n + 1); n   vector<long long int> tt(n + 1, 0); n   for (long long int i = 0; i < m; i++) { n     long long int a, b; n     cin >> a >> b; n     G[a].push_back(b); n     G[b].push_back(a); n   } n   vector<pair<long long int, long long int> > bc; n   for (long long int i = 1; i <= n; i++) { n     long long int temp; n     cin >> temp; n     bc.push_back(make_pair(temp, i)); n   } n   sort(bc.begin(), bc.end()); n   long long int check = 0; n   for (long long int i = 0; i < bc.size(); i++) { n     tt[bc[i].second] = bc[i].first; n     vector<long long int> naap; n     for (long long int j = 0; j < G[bc[i].second].size(); j++) { n       naap.push_back(tt[G[bc[i].second][j]]); n     } n     if (naap.size() == 0) { n       if (bc[i].first != 1) { n         check = 1; n       } n       continue; n     } n     sort(naap.begin(), naap.end()); n     for (long long int k = 0; k < naap.size(); k++) { n       long long int temp = naap[k]; n       if (k > 0) { n         temp -= naap[k - 1]; n       } n       if (temp > 1) { n         check = 1; n       } n     } n     if (naap[naap.size() - 1] != bc[i].first - 1) { n       check = 1; n     } n   } n   if (check == 1) { n     cout <<  -1 n ; n     return; n   } n   for (long long int i = 0; i < n; i++) { n     cout << bc[i].second <<    ; n   } n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t = 1; n   for (long long int i = 1; i <= t; i++) { n     solve(i); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Update { n   int cost, profit; n   Update(int cost, int profit) : cost(cost), profit(profit) {} n }; n struct CommutativeUndoableDS { n   const int MAX_COST = 4000; n   vector<vector<int> > stk; n   CommutativeUndoableDS() { stk.emplace_back(MAX_COST + 1, 0); } n   void addUpdate(Update u) { n     int sz = stk.size(); n     stk.push_back(stk.back()); n     for (int i = MAX_COST; i >= u.cost; i--) { n       stk[sz][i] = max(stk[sz][i], stk[sz - 1][i - u.cost] + u.profit); n     } n   } n   void undoLastUpdate() { n     stk.pop_back(); n     assert(!stk.empty()); n   } n   int bestProfitWith(int budget) { return stk.back()[budget]; } n }; n struct QueueUndoDS { n   vector<pair<Update, int> > qyu; n   CommutativeUndoableDS ds; n   void pushBack(pair<Update, int> u) { n     ds.addUpdate(u.first); n     qyu.push_back(u); n   } n   void pushBack(Update u) { pushBack(pair<Update, int>(u, 0)); } n   void popFront() { n     assert(!qyu.empty()); n     vector<pair<Update, int> > popped[2]; n     while (!qyu.empty()) { n       ds.undoLastUpdate(); n       popped[qyu.back().second].push_back(qyu.back()); n       qyu.pop_back(); n       if (popped[1].size() >= popped[0].size()) break; n     } n     if (popped[1].empty()) { n       for (pair<Update, int> &u : popped[0]) { n         u.second = 1; n         pushBack(u); n       } n     } else { n       for (int i : {0, 1}) { n         reverse(popped[i].begin(), popped[i].end()); n         for (pair<Update, int> &u : popped[i]) pushBack(u); n       } n     } n     ds.undoLastUpdate(); n     qyu.pop_back(); n   } n }; n const int MAX_TIME = 20001; n vector<Update> startsAt[MAX_TIME]; n vector<Update> endsAt[MAX_TIME]; n vector<pair<int, int> > askAt[MAX_TIME]; n int ans[MAX_TIME]; n int main() { n   int n, p; n   cin >> n >> p; n   while (n--) { n     int c, h, t; n     cin >> c >> h >> t; n     startsAt[t].emplace_back(c, h); n     endsAt[t + p - 1].emplace_back(c, h); n   } n   int q; n   cin >> q; n   for (int i = 1; i <= q; i++) { n     int a, b; n     cin >> a >> b; n     askAt[a].emplace_back(i, b); n   } n   QueueUndoDS knapsackQueuUndo; n   for (int t = 1; t < MAX_TIME; t++) { n     for (Update u : startsAt[t]) { n       knapsackQueuUndo.pushBack(u); n     } n     for (pair<int, int> query : askAt[t]) { n       ans[query.first] = knapsackQueuUndo.ds.bestProfitWith(query.second); n     } n     for (Update u : endsAt[t]) { n       knapsackQueuUndo.popFront(); n     } n   } n   for (int i = 1; i <= q; i++) { n     cout << ans[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:200000000 ) n const double EPS = 1E-9; n const int INF = 1000000000; n const long long INF64 = (long long)1E18; n const double PI = 3.1415926535897932384626433832795; n string s[110000]; n int n, k, z[110][110], dp[1100000]; n char buf[110000]; n int main() { n   scanf( %d%d n , &n, &k); n   for (int i = 0; i < (int)(n); i++) { n     scanf( %s , buf); n     s[i] = buf; n   } n   for (int i = 0; i < (int)(n); i++) n     for (int j = 0; j < (int)(n); j++) { n       int ans = 0; n       while (ans < (int)s[i].size() && ans < (int)s[j].size() && n              s[i][ans] == s[j][ans]) n         ans++; n       z[i][j] = ans; n     } n   int res = 0; n   for (int msk = 1; msk < (1 << n); msk++) { n     int cur; n     for (int i = 0; i < (int)(n); i++) n       if (msk & (1 << i)) { n         cur = i; n         break; n       } n     int val = dp[msk ^ (1 << cur)], cnt = 0; n     for (int i = 0; i < (int)(n); i++) n       if ((msk & (1 << i)) && i != cur) { n         val += z[i][cur]; n         cnt++; n       } n     if (cnt + 1 == k) res = max(res, val); n     dp[msk] = val; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:66777216 ) n using namespace std; n template <typename TT, int V, int E> n struct DinicFlow { n   int ds[V + 1], q[V + 1], nx[E + 1], last[V + 1], ver[E + 1], now[V + 1], n, n       edgesCount, S, T; n   TT cap[E + 1], flow[E + 1]; n   DinicFlow() : n(0), S(0), T(0), edgesCount(0) {} n   DinicFlow(int _n) : n(_n), S(0), T(0), edgesCount(0) {} n   inline void reset(int _n) { n     edgesCount = 0; n     n = _n; n     memset(last, -1, n * sizeof(int)); n   } n   inline void addEdge(int v, int w, TT c, TT rc) { n     ver[edgesCount] = w; n     cap[edgesCount] = c; n     flow[edgesCount] = 0; n     nx[edgesCount] = last[v]; n     last[v] = edgesCount++; n     ver[edgesCount] = v; n     cap[edgesCount] = rc; n     flow[edgesCount] = 0; n     nx[edgesCount] = last[w]; n     last[w] = edgesCount++; n   } n   inline bool bfs() { n     memset(ds, 63, n * sizeof(int)); n     int a = 0, b = 0; n     ds[T] = 0; n     q[0] = T; n     while (a <= b) { n       int v = q[a++]; n       for (int w = last[v]; w >= 0; w = nx[w]) { n         if (cap[w ^ 1] - flow[w ^ 1] && ds[ver[w]] > ds[v] + 1) { n           ds[ver[w]] = ds[v] + 1; n           q[++b] = ver[w]; n         } n       } n     } n     return ds[S] < 1000000000; n   } n   TT dfs(int v, TT cur) { n     if (v == T) return cur; n     for (int &w = now[v]; w >= 0; w = nx[w]) { n       if (cap[w] - flow[w] && ds[ver[w]] == ds[v] - 1) { n         TT rr = dfs(ver[w], min(cur, cap[w] - flow[w])); n         if (rr) { n           flow[w] += rr; n           flow[w ^ 1] -= rr; n           return rr; n         } n       } n     } n     return 0; n   } n   inline TT maxFlow() { n     TT ans = 0; n     while (bfs()) { n       memcpy(now, last, n * sizeof(int)); n       TT tf; n       while (tf = dfs(S, 1000000000)) ans += tf; n     } n     return ans; n   } n }; n int a, b, c, d, n, m, k; n DinicFlow<int, 205, 2100> q; n int ds[202][202]; n bool used[202]; n int main() { n   scanf( %d%d , &n, &m); n   q.reset(n + 2); n   for (int _n((m)-1), i(0); i <= _n; i++) { n     scanf( %d%d%d , &a, &b, &c); n     --a; n     --b; n     q.addEdge(a, b, c, c); n   } n   for (int _n((n)-1), i(0); i <= _n; i++) { n     for (int _n((i)-1), j(0); j <= _n; j++) { n       memset((q.flow), 0, sizeof(q.flow)); n       q.S = i; n       q.T = j; n       ds[i][j] = ds[j][i] = q.maxFlow(); n     } n   } n   vector<int> ans; n   int mx = 0; n   for (int _n((n)-1), i(0); i <= _n; i++) { n     for (int _n((i)-1), j(0); j <= _n; j++) { n       if (ds[i][j] > mx) { n         ans.clear(); n         ans.push_back(i); n         ans.push_back(j); n         mx = ds[i][j]; n       } n     } n   } n   memset((used), 0, sizeof(used)); n   used[ans[0]] = used[ans[1]] = 1; n   while ((int)((ans).size()) < n) { n     int mx = -1, v = -1; n     for (int _n((n)-1), i(0); i <= _n; i++) { n       if (used[i]) continue; n       if (ds[ans.back()][i] > mx) { n         mx = ds[ans.back()][i]; n         v = i; n       } n     } n     ans.push_back(v); n     used[v] = 1; n   } n   int res = 0; n   for (int _n(((int)((ans).size()) - 1) - 1), i(0); i <= _n; i++) n     res += ds[ans[i]][ans[i + 1]]; n   printf( %d n , res); n   for (int _n(((int)((ans).size())) - 1), i(0); i <= _n; i++) { n     if (i) printf(   ); n     printf( %d , ans[i] + 1); n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[3010], vert; n map<int, vector<pair<int, int> > > query[3010]; n int ans[400010], vis[3010], in_cycle; n void dfs(int v, int par) { n   vis[v] = 1; n   if (!in_cycle) vert.push_back(v); n   if (query[par].count(v)) { n     vector<pair<int, int> > *ptr = &query[par][v]; n     int vert_size = vert.size(); n     for (auto p : *ptr) { n       ans[p.second] = n           ((p.first > vert_size || in_cycle) ? -1 : vert[p.first - 1]); n     } n   } n   for (int i = 0; i < adj[v].size(); ++i) { n     int t = adj[v][i]; n     if (vis[t] == 0) n       dfs(t, par); n     else if (vis[t] == 1) { n       ++in_cycle; n       ++vis[t]; n     } n   } n   if (v == vert.back()) vert.pop_back(); n   if (vis[v] > 1) n     --in_cycle; n   else n     vis[v] = 2; n } n int main() { n   int n, m, q; n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 0; i < m; ++i) { n     int u, v; n     scanf( %d %d , &u, &v); n     adj[u].push_back(v); n   } n   for (int i = 1; i <= n; ++i) { n     sort(adj[i].begin(), adj[i].end()); n   } n   for (int i = 0; i < q; ++i) { n     int s, t, k; n     scanf( %d %d %d , &s, &t, &k); n     query[s][t].push_back(make_pair(k, i)); n   } n   for (int i = 0; i < q; ++i) ans[i] = -1; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) vis[j] = 0; n     in_cycle = 0; n     dfs(i, i); n   } n   for (int i = 0; i < q; ++i) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 9; n int arr[maxn], ar[maxn]; n int main() { n   int a, b, c, d, e, f, g, h; n   while (cin >> a) { n     cin >> e >> f; n     for (int i = 1; i <= a; i++) { n       cin >> arr[i]; n     } n     for (int i = 1; i <= a; i++) { n       cin >> ar[i]; n     } n     g = 1; n     for (int i = 1; i < e; i++) { n       if (arr[i] != ar[i]) { n         g = 0; n         break; n       } n     } n     for (int i = f + 1; i <= a; i++) { n       if (arr[i] != ar[i]) { n         g = 0; n         break; n       } n     } n     map<int, int> ma1, ma2; n     for (int i = e; i <= f; i++) { n       ma1[arr[i]]++; n       ma2[ar[i]]++; n     } n     if (ma1 != ma2) g = 0; n     if (!g) { n       cout <<  LIE  << endl; n     } else { n       cout <<  TRUTH  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxm = 6e5 + 5; n int l[maxm], r[maxm]; n int c[maxm]; n int pos[maxm]; n int n, m; n int max(int a, int b) { n   if (a > b) n     return a; n   else n     return b; n } n int lowbit(int i) { return i & -i; } n void add(int i, int t) { n   while (i < maxm) { n     c[i] += t; n     i += lowbit(i); n   } n } n int ask(int i) { n   int ans = 0; n   while (i) { n     ans += c[i]; n     i -= lowbit(i); n   } n   return ans; n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     l[i] = r[i] = i; n     add(i + m, 1); n     pos[i] = i + m; n   } n   int last = m; n   while (m--) { n     int x; n     cin >> x; n     l[x] = 1; n     int num = ask(pos[x]); n     r[x] = max(r[x], num); n     if (num == 1) continue; n     add(pos[x], -1); n     pos[x] = last; n     add(pos[x], 1); n     last--; n   } n   for (int i = 1; i <= n; i++) { n     r[i] = max(r[i], ask(pos[i])); n   } n   for (int i = 1; i <= n; i++) { n     cout << l[i] <<     << r[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n int size(T& a) { n   return (int)a.size(); n } n template <typename T> n T sqr(T a) { n   return a * a; n } n int offset; n int f[1000000 * 4 + 10]; n int start[27]; n int getmask(int l, int r) { n   int res = 0; n   for (l += offset, r += offset; l <= r; l /= 2, r /= 2) { n     if (l % 2 == 1) { n       res |= f[l++]; n     } n     if (r % 2 == 0) { n       res |= f[r--]; n     } n   } n   return res; n } n vector<int> pos[27]; n int ans[10000]; n map<int, int> num; n int cnt[27][10000]; n int g[10000]; n int main() { n   string s; n   cin >> s; n   s += (char)( z  + 1); n   offset = 1; n   while (offset < size(s)) offset *= 2; n   memset((f), (0), sizeof(f)); n   for (int i = offset; i < offset + size(s); ++i) { n     f[i] = 1 << (s[i - offset] -  a ); n   } n   for (int i = offset - 1; i >= 1; --i) { n     f[i] = f[2 * i] | f[2 * i + 1]; n   } n   for (int i = 0; i < size(s); ++i) { n     pos[s[i] -  a ].push_back(i); n   } n   int q; n   cin >> q; n   for (int i = 0; i < q; ++i) { n     string e; n     cin >> e; n     int mask = 0; n     for (int j = 0; j < e.length(); ++j) { n       mask |= 1 << (e[j] -  a ); n     } n     g[i] = mask; n     num[mask] = i; n   } n   for (int i = 0; i < size(s) - 1; ++i) { n     for (int b = 0; b < 27; ++b) { n       if (s[i] -  a  == b) continue; n       while (start[b] < pos[b].size() && pos[b][start[b]] < i) { n         ++start[b]; n       } n       if (start[b] < pos[b].size() && pos[b][start[b]] >= i) { n         int m = getmask(i, pos[b][start[b]] - 1); n         if (i > 0 && (m & (1 << (s[i - 1] -  a ))) != 0) continue; n         if (!num.count(m)) continue; n         cnt[b][num[m]]++; n       } n     } n   } n   for (int i = 0; i < q; ++i) { n     int res = 0; n     for (int b = 0; b < 27; ++b) n       if ((g[i] & (1 << b)) == 0) { n         res += cnt[b][num[g[i]]]; n       } n     cout << res << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n string g[51]; n int pre[52][52]; n int dp[51][51][51][51]; n bool chk(int x1, int x2, int y1, int y2) { n   int r = pre[x2][y2] - pre[x1][y1 - 1] - pre[x1 - 1][y1] + pre[x1 - 1][y1 - 1]; n   if (r >= 1) return true; n   return false; n } n int fun(int r1, int r2, int c1, int c2) { n   if (chk(r1, r2, c1, c2) == false) return 0; n   if (dp[r1][r2][c1][c2] != -1) return dp[r1][r2][c1][c2]; n   int ans = max((r2 - r1 + 1), (c2 - c1 + 1)); n   for (int i = r1; i < r2; i++) n     ans = min(ans, fun(r1, i, c1, c2) + fun(i + 1, r2, c1, c2)); n   for (int j = c1; j < c2; j++) { n     ans = min(ans, fun(r1, r2, c1, j) + fun(r1, r2, j + 1, c2)); n   } n   return dp[r1][r2][c1][c2] = ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   memset(dp, -1, sizeof(dp)); n   for (int i = 0; i < n; i += 1) cin >> g[i]; n   pre[0][0] = 1; n   for (int i = 0; i < n; i++) { n     pre[i][0] = pre[0][i] = 0; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (g[i][j] ==  # ) pre[i + 1][j + 1] = 1; n       pre[i + 1][j + 1] += (pre[i][j + 1] + pre[i + 1][j] - pre[i][j]); n     } n   } n   int ans = fun(1, n, 1, n); n   cout << ans << endl; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define ll long long n #define pb push_back n #define ff first n #define ss second n #define mod 1000000007 n #define t5 100005 n #define inf 100000000000000000 n ll ask(ll t,ll i,ll j , ll x){ n  cout << ?  << t <<     << i <<     << j <<     << x << endl; n  ll temp; n  cin >> temp; n  return temp; n } n void solve(){ n  ll n; n  cin>> n; n  ll pos = 0; n  for(ll i=1 ;  i<n ; i+=2){ n   ll q; n   q = ask(2,i,i+1,1); n   if(q == 1){ n    pos = i; n    break; n   } n   else if(q == 2){ n    q = ask(2,i+1,i,1); n    if(q == 1){ n     pos = i+1; n     break; n    } n   } n  } n  if(!pos) n   pos = n; n  vector <ll> v(n+1); n  for(ll i=1 ; i<=n ; i++){ n   if(i==pos){ n    v[i] = 1; n   } n   else{ n    ll q = ask(1,pos,i,n-1); n    v[i] = q; n   } n  } n  cout << ! ; n  for(ll i=1 ; i<=n ; i++){ n   cout <<    << v[i]; n  } n  cout << endl; n } n int main(){ n  ios_base::sync_with_stdio(0); n     cin.tie(0); n     cout.tie(0); n  ll t; n  cin >> t; n  while(t--){ n   solve(); n  } n   n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   vector<pair<int, int>> a(n); n   vector<int> diff(n), dp(n + 1), take(n + 1); n   for (int i = 0; i < n; i++) scanf( %d , &a[i].first), a[i].second = i; n   sort(a.begin(), a.end()); n   if (n < 6) { n     cout << a[n - 1].first - a[0].first <<     << 1 << endl; n     for (int i = 0; i < n; i++) cout << 1 <<    ; n     return 0; n   } n   for (int i = 0; i < n - 1; i++) diff[i] = a[i + 1].first - a[i].first; n   dp[2] = diff[2]; n   take[2] = 1; n   for (int i = 3; i < n - 3; i++) { n     if (dp[i - 3] + diff[i] > dp[i - 1]) { n       take[i] = 1; n       dp[i] = dp[i - 3] + diff[i]; n     } else { n       dp[i] = dp[i - 1]; n     } n   } n   vector<int> ans(n); n   int cnt = 1; n   for (int i = n - 1; i >= 0;) { n     if (take[i]) { n       ++cnt; n       for (int j = 0; j < 3; j++) ans[a[i--].second] = cnt; n     } else n       ans[a[i--].second] = cnt; n   } n   cout << a[n - 1].first - a[0].first - dp[n - 4] <<     << cnt << endl; 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 long long a[35], b[35], k[35], p[35]; n long long n, u, r, ans; n void op1() { n   for (int i = 0; i < n; i++) a[i] = a[i] ^ b[i]; n } n void op2() { n   long long tmp[35]; n   for (int i = 0; i < n; i++) tmp[i] = a[p[i]] + r; n   for (int i = 0; i < n; i++) a[i] = tmp[i]; n } n void dfs(int t, int f) { n   long long x = 0; n   if ((t & 1) == 0) { n     for (int i = 0; i < n; i++) x += a[i] * k[i]; n     ans = max(x, ans); n   } n   if (t == 0) return; n   long long tmp[35]; n   for (int i = 0; i < n; i++) tmp[i] = a[i]; n   op2(); n   dfs(t - 1, 1); n   for (int i = 0; i < n; i++) a[i] = tmp[i]; n   if (f) { n     op1(); n     dfs(t - 1, 0); n     for (int i = 0; i < n; i++) a[i] = tmp[i]; n   } n   return; n } n int main() { n   cin >> n >> u >> r; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> b[i]; n   for (int i = 0; i < n; i++) cin >> k[i]; n   for (int i = 0; i < n; i++) cin >> p[i], p[i]--; n   ans = -100000000000000009; n   dfs(u, 1); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 2, K = 102, P = 102; n int dp[3][K][P], a[N], mn[N][K], pre[N]; n int main() { n   ios::sync_with_stdio(), cin.tie(0), cout.tie(0); n   int n, k, p; n   cin >> n >> k >> p; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     a[i] %= p; n   } n   if (10000 >= n) { n     for (int i = 0; i <= 100; i++) n       for (int j = 0; j <= 100; j++) dp[0][i][j] = 1e8; n     for (int i = 0; i <= 10000; i++) n       for (int j = 0; j <= 100; j++) mn[i][j] = 1e8; n     dp[0][0][0] = 0; n     mn[0][0] = 0; n     for (int i = 1; i <= n; i++) { n       int nw = (i & 1); n       int pas = (nw ^ 1); n       for (int ii = 0; ii <= 100; ii++) n         for (int j = 0; j <= 100; j++) dp[nw][ii][j] = 1e8; n       for (int j = 1; j <= k; j++) { n         for (int las = 0; las < p; las++) { n           if (las == a[i - 1]) { n             dp[nw][j][las] = mn[i - 1][j - 1] + a[i - 1]; n           } n           dp[nw][j][las] = n               min(dp[nw][j][las], dp[pas][j][((las - a[i - 1] + p) % p)] - n                                       ((las - a[i - 1] + p) % p) + las); n           mn[i][j] = min(mn[i][j], dp[nw][j][las]); n         } n       } n     } n     int ans = 1e8; n     for (int i = 0; i < p; i++) { n       ans = min(ans, dp[n & 1][k][i]); n     } n     cout << ans; n   } else { n     for (int i = 1; i <= n; i++) { n       pre[i] = pre[i - 1] + a[i - 1]; n       pre[i] %= p; n     } n     vector<int> lis; n     lis.clear(); n     for (int i = 1; i < n; i++) { n       auto it = upper_bound(lis.begin(), lis.end(), pre[i]); n       if (it == lis.end()) { n         lis.emplace_back(pre[i]); n       } else { n         lis[it - lis.begin()] = pre[i]; n       } n     } n     auto it = upper_bound(lis.begin(), lis.end(), pre[n]); n     if (it - lis.begin() + 1 >= k) n       cout << pre[n]; n     else n       cout << pre[n] + p; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e10, mpow = 33, N = 1e5, M = 1e3; n vector<int> prime; n int nt[N + 10]; n void sieve() { n   for (int i = 2; i <= N; i++) n     if (!nt[i]) { n       prime.push_back(i); n       for (int j = i * 2; j <= N; j += i) nt[j] = 1; n     } n } n string tostring(long long x) { n   string res; n   while (x) { n     char ch = (char)(x % 10 + 48); n     res = ch + res; n     x /= 10; n   } n   return res; n } n long long power(long long x, int h) { n   long long res = 1; n   for (; h; h >>= 1) { n     if (h & 1) { n       if (res > inf / x) return inf; n       res = res * x; n     } n     if (h == 1) return res; n     if (x > inf / x) return inf; n     x = x * x; n   } n   return res; n } n int cb(long long x, int h) { n   int l = 2, r = N; n   while (l <= r) { n     int mid = (l + r) / 2; n     long long tmp = power(mid, h); n     if (tmp > x) n       r = mid - 1; n     else if (tmp < x) n       l = mid + 1; n     else n       return mid; n   } n   return -1; n } n string best_rep1(long long x) { n   string res = tostring(x); n   for (int i = 2; i <= mpow; i++) { n     int tmp = cb(x, i); n     if (tmp == -1) continue; n     string can = tostring(tmp) +  ^  + tostring(i); n     if (can.length() < res.length()) res = can; n   } n   return res; n } n map<long long, string> in_num3, in_num4; n vector<long long> divi(long long x) { n   vector<long long> res; n   res.push_back(1); n   for (int p : prime) n     if (x % p == 0) { n       long long bonus = 1; n       while (x % p == 0) { n         x /= p; n         bonus *= p; n         for (long long k : res) { n           if (k % p == 0) break; n           res.push_back(k * bonus); n         } n       } n     } n   if (x > 1) { n     for (long long k : res) { n       if (k % x == 0) break; n       res.push_back(k * x); n     } n   } n   return res; n } n string best_rep2(long long x, int mlen) { n   string res = best_rep1(x); n   vector<long long> divisor = divi(x); n   sort(divisor.begin(), divisor.end()); n   for (long long k : divisor) { n     if (x / k < k) break; n     string can = best_rep1(k) +  *  + best_rep1(x / k); n     if (can.length() < res.length()) res = can; n   } n   if (mlen == 9) { n     for (int i = 2; i <= 9; i++) n       for (int j = 2; j <= 9; j++) n         for (int t = 2; t <= 9; t++) { n           long long tmp = power(i, j) * t; n           string st = in_num3[x / tmp]; n           if (x % tmp == 0 && st !=   ) { n             string can = n                 tostring(i) +  ^  + tostring(j) +  *  + st +  *  + tostring(t); n             if (can.length() < res.length()) res = can; n           } n         } n   } n   return res; n } n string solve(long long n) { n   if (n == 1e10) return  10^10 ; n   for (int i = 2; i <= 9; i++) n     for (int j = 2; j <= 9; j++) n       in_num3[power(i, j)] = tostring(i) +  ^  + tostring(j); n   string res = best_rep2(n, 9); n   long long R = n, L = max((long long)1, n - M + 1); n   for (long long i = L; i < R; i++) { n     string can = tostring(n - i) +  + ; n     can += best_rep2(i, 9 - (int)can.length()); n     if (can.length() < res.length()) res = can; n   } n   for (int i = 2; i <= 99; i++) n     for (int j = 2; j <= mpow; j++) { n       long long tmp = power(i, j); n       if (tmp >= n) continue; n       in_num4[tmp] = tostring(i) +  ^  + tostring(j); n       string can = tostring(i) +  ^  + tostring(j) +  +  + tostring(n - tmp); n       if (can.length() < res.length()) res = can; n     } n   for (int i = 2; i <= 99; i++) n     for (int j = 2; j <= mpow; j++) { n       long long tmp = power(i, j); n       if (tmp >= n) continue; n       string st = in_num4[n - tmp]; n       if (st !=   ) { n         string can = tostring(i) +  ^  + tostring(j) +  +  + st; n         if (can.length() < res.length()) res = can; n       } n     } n   for (int i = 2; i <= 9; i++) n     for (int j = 2; j <= 9; j++) { n       for (int t = 2; t <= 9; t++) { n         long long tmp = power(i, j) + t; n         string st = in_num3[n - tmp]; n         if (st !=   ) { n           string can = n               tostring(i) +  ^  + tostring(j) +  +  + st +  +  + tostring(t); n           if (can.length() < res.length()) res = can; n         } n       } n       long long tmp = power(i, j); n       if (tmp >= n) continue; n       string can = tostring(i) +  ^  + tostring(j) +  + ; n       can += best_rep2(n - tmp, 9 - can.length()); n       if (can.length() < res.length()) res = can; n     } n   return res; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n; n   cin >> n; n   sieve(); n   cout << solve(n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n template <typename T> n ostream& operator<<(ostream& out, vector<T> v) { n   out <<  { ; n   for (size_t i = 0; i < v.size(); ++i) out << (i == 0 ?    :  ,  ) << v[i]; n   return out <<  } ; n } n template <typename Arg1> n void myPrint(const char* name, Arg1&& arg1) { n   std::cout << name <<  =  << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void myPrint(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   std::cout.write(names, comma - names) <<  =  << arg1; n   myPrint(comma, args...); n } n void run(); n int main() { n   if (strlen(  ) > 0) { n     freopen( n            n          .in , n          r , stdin); n     freopen( n            n          .out , n          w , stdout); n   } n   run(); n   return 0; n } n long long n, q; n long long add[2]; n void run() { n   scanf( %d%d , &n, &q); n   while (q--) { n     int t, x; n     scanf( %d , &t); n     if (t == 1) { n       scanf( %d , &x); n       if (x < 0) x += n; n       add[0] += x; n       add[1] += x; n     } else { n       if (add[0] % 2) { n         --add[0]; n         ++add[1]; n       } else { n         ++add[0]; n         --add[1]; n       } n     } n   } n   vector<int> a(n); n   for (int i = 0; i < n; ++i) a[((i + add[i % 2]) % n + n) % n] = i; n   for (int x : a) printf( %d  , x + 1); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n int ar[1000009]; n int main() { n   long long a, s, d, f, g, h, j, k, l; n   cin >> a; n   k = 0; n   for (s = 1; s <= a; s++) { n     scanf( %d , &ar[s]); n     if (ar[s]) k++; n   } n   d = 0; n   l = 0; n   for (s = 1; s <= a; s++) { n     if (ar[s] == 1) { n       d = d + (a - k - l); n     } else n       l++; n   } n   f = 0; n   for (s = a; s >= 1; s--) { n     if (ar[s] == 0) n       f = f + k; n     else n       k--; n   } n   cout << min(d, f) << endl; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, count, area; n   cin >> a >> b; n   area = a * b; n   if (area < 2) n     cout <<  0  << endl; n   else { n     while (area >= 2) { n       count++; n       area -= 2; n     } n     cout << count << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, m; n vector<long long int> a[200005]; n long long int rankof[200005]; n long long int parentof[200005]; n long long int maxof[200005]; n void initialize() { n   for (long long int i = 0; i <= 200005; i++) { n     rankof[i] = 1; n     parentof[i] = i; n     maxof[i] = i; n   } n } n long long int root(long long int x) { n   if (x == parentof[x]) { n     return x; n   } n   parentof[x] = root(parentof[x]); n   return parentof[x]; n } n void combine(long long int x, long long int y) { n   x = root(x); n   y = root(y); n   long long int maxx = max(maxof[x], maxof[y]); n   if (x != y) { n     if (rankof[x] >= rankof[y]) { n       parentof[y] = x; n       rankof[x] += rankof[y]; n       maxof[x] = maxx; n     } else { n       parentof[x] = y; n       rankof[y] += rankof[x]; n       maxof[y] = maxx; n     } n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int i, j; n   cin >> n >> m; n   initialize(); n   for (i = 0; i < m; i++) { n     long long int u, v; n     cin >> u >> v; n     combine(u, v); n   } n   long long int curmax, cnt = 0; n   for (i = 1; i <= n;) { n     curmax = maxof[root(i)]; n     j = i + 1; n     while (j <= curmax) { n       if (root(j) != root(i)) { n         combine(i, j); n         cnt++; n       } n       curmax = maxof[root(i)]; n       j++; n     } n     i = j; n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename P, typename Q> n ostream& operator<<(ostream& os, pair<P, Q> p) { n   os <<  (  << p.first <<  ,  << p.second <<  ) ; n   return os; n } n template <typename P, typename Q> n istream& operator>>(istream& is, pair<P, Q>& p) { n   is >> p.first >> p.second; n   return is; n } n template <typename T> n ostream& operator<<(ostream& os, vector<T> v) { n   os <<  ( ; n   for (auto& i : v) os << i <<  , ; n   os <<  ) ; n   return os; n } n template <typename T> n istream& operator>>(istream& is, vector<T>& v) { n   for (auto& i : v) is >> i; n   return is; n } n template <typename T> n ostream& operator<<(ostream& os, set<T> s) { n   os <<  #{ ; n   for (auto& i : s) os << i <<  , ; n   os <<  } ; n   return os; n } n template <typename K, typename V> n ostream& operator<<(ostream& os, map<K, V> m) { n   os <<  { ; n   for (auto& i : m) os << i <<  , ; n   os <<  } ; n   return os; n } n template <typename T> n inline T setmax(T& a, T b) { n   return a = std::max(a, b); n } n template <typename T> n inline T setmin(T& a, T b) { n   return a = std::min(a, b); n } n template <typename P, typename Q> n inline pair<Q, P> reverse(pair<P, Q> p) { n   return make_pair(p.second, p.first); n } n using lli = long long int; n using ull = unsigned long long; n using point = complex<double>; n using str = string; n template <typename T> n using vec = vector<T>; n constexpr lli mod = 1e9 + 7; n template <typename T> n struct SegTree { n   int n; n   vector<T> dat; n   using F = function<T(T, T)>; n   F fn; n   T e; n   SegTree(int n_, T e_, F fn_) { n     e = e_; n     fn = fn_; n     n = 1; n     while (n < n_) n *= 2; n     dat.resize(2 * n - 1, e); n   } n   void update(size_t k, T a) { n     k += n - 1; n     dat[k] = a; n     while (k > 0) { n       k = (k - 1) / 2; n       dat[k] = fn(dat[k * 2 + 1], dat[k * 2 + 2]); n     } n     return; n   } n   T query(size_t a, size_t b) { return query(a, b, 0, 0, n); } n   T query(size_t a, size_t b, size_t k, size_t l, size_t r) { n     if (r <= a || b <= l) return e; n     if (a <= l && r <= b) return dat.at(k); n     T vl = query(a, b, k * 2 + 1, l, (l + r) / 2); n     T vr = query(a, b, k * 2 + 2, (l + r) / 2, r); n     return fn(vl, vr); n   } n }; n int main(int argc, char* argv[]) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, m, k; n   while (cin >> n >> m >> k) { n     vector<int> a(k); n     cin >> a; n     for (auto& i : a) --i; n     const int N = 2 * 1e5 + 5; n     vector<int> g[N]; n     for (int i = 0; i < m; ++i) { n       int x, y; n       cin >> x >> y; n       --x; n       --y; n       g[x].push_back(y); n       g[y].push_back(x); n     } n     const int inf = 1 << 29; n     auto bfs = [&](int src) { n       vector<int> cost(n, inf); n       queue<int> q; n       cost[src] = 0; n       for (q.push(src); q.size(); q.pop()) { n         int curr = q.front(); n         for (auto& next : g[curr]) { n           if (cost[next] == inf) { n             cost[next] = cost[curr] + 1; n             q.push(next); n           } n         } n       } n       return cost; n     }; n     vector<int> d1 = bfs(0); n     vector<int> d2 = bfs(n - 1); n     sort(a.begin(), a.end(), [&](int i, int j) { return d1[i] < d1[j]; }); n     SegTree<int> rmq(a.size(), -(1 << 29), n                      [](int a, int b) { return max(a, b); }); n     for (int i = 0; i < a.size(); ++i) { n       rmq.update(i, d2[a[i]]); n     } n     int mx = 0; n     for (int i = 0; i < a.size(); ++i) { n       int x = rmq.query(i + 1, a.size()); n       setmax(mx, d1[a[i]] + x + 1); n     } n     cout << min(mx, d1[n - 1]) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6; n int L[N], R[N], sp[N], levsp[30], lev[N]; n long long val[N], a[N]; n void lazyUpdate(int node) { n   if (!L[node]) return; n   if (sp[node] ^ levsp[lev[node]]) { n     swap(L[node], R[node]); n     sp[node] ^= 1; n   } n } n long long build(int node, int l, int r, int lv) { n   if (l == r) return val[node] = a[l]; n   int mid = l + r >> 1; n   lev[node] = lv; n   L[node] = node << 1, R[node] = node << 1 | 1; n   val[node] = n       build(L[node], l, mid, lv - 1) + build(R[node], mid + 1, r, lv - 1); n   return val[node]; n } n long long update(int node, int l, int r, int pos, int k) { n   lazyUpdate(node); n   if (r < pos || l > pos) return val[node]; n   if (l == r) return val[node] = k; n   int mid = l + r >> 1; n   return val[node] = update(L[node], l, mid, pos, k) + n                      update(R[node], mid + 1, r, pos, k); n } n long long query(int node, int l, int r, int pos) { n   lazyUpdate(node); n   if (l > pos) return 0; n   if (r <= pos) return val[node]; n   int mid = l + r >> 1; n   return query(L[node], l, mid, pos) + query(R[node], mid + 1, r, pos); n } n int main() { n   int n, q; n   scanf( %d%d , &n, &q); n   int nn = 1 << n; n   for (int i = 1; i <= nn; i++) scanf( %lld , &a[i]); n   build(1, 1, nn, n); n   while (q--) { n     int t, x, k; n     scanf( %d , &t); n     if (t == 1) { n       scanf( %d%d , &x, &k); n       update(1, 1, nn, x, k); n     } else if (t == 2) { n       scanf( %d , &k); n       for (int i = 0; i <= k; i++) levsp[i] ^= 1; n     } else if (t == 3) { n       scanf( %d , &k); n       levsp[k + 1] ^= 1; n     } else { n       int l, r; n       scanf( %d%d , &l, &r); n       printf( %lld n , query(1, 1, nn, r) - query(1, 1, nn, l - 1)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100500]; n vector<int> gr[100500]; n int n, m, s, k; n int res[100500][101]; n int d[100500]; n int q[100500]; n int A[100500]; n int B[100500]; n int sz[100500]; n int main() { n   scanf( %d %d %d %d , &n, &m, &k, &s); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , a + i); n     int u = n + a[i]; n     gr[u].push_back(i); n   } n   for (int i = 0; i < m; i++) { n     int c, b; n     scanf( %d %d , &c, &b); n     A[i] = c; n     B[i] = b; n     sz[c]++; n     sz[b]++; n   } n   for (int i = 1; i <= n; i++) gr[i].resize(sz[i]); n   for (int i = 0; i < m; i++) { n     gr[A[i]][--sz[A[i]]] = B[i]; n     gr[B[i]][--sz[B[i]]] = A[i]; n   } n   for (int i = 1; i <= k; ++i) { n     int ql = 0, qr = 0; n     for (int j = 1; j <= n; ++j) { n       if (a[j] != i) n         d[j] = 1e9; n       else { n         d[j] = 0; n         q[qr++] = j; n       } n     } n     while (ql <= qr) { n       auto x = q[ql++]; n       res[x][i - 1] = d[x]; n       for (auto v : gr[x]) { n         if (d[v] >= 1e9) { n           d[v] = 1 + d[x]; n           q[qr++] = v; n         } n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     sort(res[i], res[i] + k); n     int w = 0; n     for (int j = 0; j < s; ++j) { n       w += res[i][j]; n     } n     cout << w <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s[101][2]; n int n, m; n int main() { n   cin >> n; n   m = 0; n   for (int i = 1; i <= n; i++) { n     bool mark = true; n     m++; n     cin >> s[m][0] >> s[m][1]; n     for (int j = 1; j < m; j++) n       if ((s[m][0] == s[j][0]) && (s[m][1] == s[j][1])) { n         mark = false; n         break; n       } n     if (!mark) { n       m--; n     } n   } n   cout << m << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n long long int N[100000 + 100]; n long long int ans = 0; n int main() { n   int n; n   cin >> n; n   int court = 0; n   int court_1 = 0; n   int court_2 = 0; n   for (int i = 0; i < n; ++i) cin >> N[i]; n   for (int i = 0; i < n; ++i) { n     if (N[i] < -1) { n       ans += -1 - N[i]; n       N[i] = -1; n       ++court_2; n     } else if (N[i] > 1) { n       ans += N[i] - 1; n       N[i] = 1; n       ++court_1; n     } else if (N[i] == 0) { n       court++; n     } else if (N[i] == 1) { n       court_1++; n     } else if (N[i] == -1) { n       court_2++; n     } n   } n   if (court_2 % 2 != 0) { n     if (court != 0) { n       ans += 1; n       court--; n     } else if (court == 0) { n       if (court_1 != 0) { n         court_1--; n         ans += 2; n       } else if (court_1 == 0) { n         ans += 2; n       } n     } n   } n   if (court != 0) ans += court; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n char buf[1 << 15], *fs, *ft; n inline char getc() { n   return (fs == ft && n           (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft)) n              ? 0 n              : *fs++; n } n inline int read() { n   int x = 0, f = 1; n   char ch = getc(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getc(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getc(); n   } n   return x * f; n } n const int MAXN = 40010; n int n, m; n int q[MAXN * 20], vis[MAXN * 20], mark[MAXN * 20]; n int cnt, S, T, len, tot = 1, maxflow, t, h, st; n int f[MAXN][16], num[MAXN][16], Log[MAXN], d[MAXN]; n int lin[MAXN], ver[MAXN << 1], nex[MAXN << 1], pos[MAXN << 1]; n int lc[MAXN * 20], nc[MAXN * 20 << 2], vc[MAXN * 20 << 2], e[MAXN * 20 << 2]; n int cur[MAXN * 20]; n inline void add(int x, int y) { n   ver[++len] = y; n   nex[len] = lin[x]; n   lin[x] = len; n } n inline void adc(int x, int y, int z) { n   vc[++tot] = y; n   nc[tot] = lc[x]; n   lc[x] = tot; n   e[tot] = z; n   vc[++tot] = x; n   nc[tot] = lc[y]; n   lc[y] = tot; n   e[tot] = 0; n } n inline void dfs(int x, int father) { n   d[x] = d[father] + 1; n   for (int i = lin[x]; i; i = nex[i]) { n     int tn = ver[i]; n     if (tn == father) continue; n     f[tn][0] = x; n     num[tn][0] = pos[i]; n     for (int j = 1; j <= Log[d[x]]; ++j) { n       num[tn][j] = ++cnt; n       f[tn][j] = f[f[tn][j - 1]][j - 1]; n       adc(num[tn][j], num[tn][j - 1], 1000000000); n       adc(num[tn][j], num[f[tn][j - 1]][j - 1], 1000000000); n     } n     dfs(tn, x); n   } n } n inline void LCA(int x, int y) { n   if (d[x] < d[y]) swap(x, y); n   for (int i = Log[d[x]]; i >= 0; --i) n     if (d[f[x][i]] >= d[y]) { n       adc(st, num[x][i], 1); n       x = f[x][i]; n     } n   if (x == y) return; n   for (int i = Log[d[x]]; i >= 0; --i) n     if (f[x][i] != f[y][i]) { n       adc(st, num[x][i], 1); n       adc(st, num[y][i], 1); n       x = f[x][i]; n       y = f[y][i]; n     } n   adc(st, num[x][0], 1); n   adc(st, num[y][0], 1); n   return; n } n inline int bfs() { n   t = h = 0; n   for (int i = 1; i <= cnt; ++i) { n     cur[i] = lc[i]; n     vis[i] = 0; n   } n   q[++t] = S; n   vis[S] = 1; n   while (h++ < t) { n     int x = q[h]; n     for (int i = lc[x]; i; i = nc[i]) { n       int tn = vc[i]; n       if (vis[tn] || !e[i]) continue; n       q[++t] = tn; n       vis[tn] = vis[x] + 1; n       if (tn == T) return 1; n     } n   } n   return 0; n } n inline int dinic(int x, int flow) { n   if (x == T) return flow; n   int rest = flow, k; n   for (int i = cur[x]; i && rest; i = nc[i]) { n     cur[x] = i; n     int tn = vc[i]; n     if (vis[tn] == vis[x] + 1 && e[i]) { n       k = dinic(tn, min(e[i], rest)); n       if (!k) { n         vis[tn] = 0; n         continue; n       } n       e[i] -= k; n       e[i ^ 1] += k; n       rest -= k; n     } n   } n   return flow - rest; n } n inline void bfs(int s) { n   t = h = 0; n   memset(vis, 0, sizeof(vis)); n   q[++t] = s; n   while (h++ < t) { n     int x = q[h]; n     vis[x] = 1; n     for (int i = lc[x]; i; i = nc[i]) { n       int tn = vc[i]; n       if (!e[i]) continue; n       if (vis[tn]) continue; n       q[++t] = tn; n     } n   } n } n int main() { n   n = read(); n   m = read(); n   cnt = n - 1; n   for (int i = 1; i < n; ++i) { n     int x, y; n     x = read(); n     y = read(); n     add(x, y); n     add(y, x); n     pos[len] = pos[len - 1] = i; n     Log[i + 1] = Log[(i + 1) >> 1] + 1; n   } n   dfs(1, 0); n   S = ++cnt; n   T = ++cnt; n   for (int i = 1; i < n; ++i) adc(i, T, 1); n   for (int i = 1; i <= m; ++i) { n     int x, y; n     st = i + cnt; n     x = read(); n     y = read(); n     adc(S, st, 1); n     LCA(x, y); n   } n   int flow = 0; n   st = cnt; n   cnt = cnt + m; n   while (bfs()) n     while ((flow = dinic(S, 1000000000))) maxflow += flow; n   printf( %d n , maxflow); n   bfs(S); n   int count = 0; n   for (int i = 1; i <= m; ++i) n     if (!vis[st + i]) ++count; n   printf( %d , count); n   for (int i = 1; i <= m; ++i) n     if (!vis[st + i]) printf(  %d , i); n   puts(  ); n   count = 0; n   for (int i = 1; i < n; ++i) n     if (vis[i]) ++count; n   printf( %d , count); n   for (int i = 1; i < n; ++i) n     if (vis[i]) printf(  %d , i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, t[200005], ans = 0; n bool chk[200005]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , t + i); n   chk[0] = true; n   for (int i = n; i >= 1; i--) n     if (!chk[i]) { n       int x = i; n       ans++; n       while (!chk[x]) chk[x] = true, x = t[x]; n     } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     int x, y, z; n     cin >> x >> y >> z; n     if (x != y && y != z && z != x) n       cout <<  NO  n            <<   n ; n     else { n       int a = min(min(x, y), z); n       int c = max(max(x, y), z); n       int b = x + y + z - a - c; n       if (a == c || b == c) n         cout <<  YES  n              <<   n  n              << min(a, b) <<     << min(a, b) <<     << c <<   n ; n       else if (a == b) { n         if (b == c) n           cout <<  YES  n                <<   n  n                << a <<     << b <<     << c <<   n ; n         else n           cout <<  NO  n                <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class n, class second> n ostream &operator<<(ostream &p, pair<n, second> x) { n   return p <<  <  << x.first <<  ,   << x.second <<  > ; n } n template <class n> n auto operator<<(ostream &p, n y) -> n     typename enable_if<!is_same<n, string>::value, n                        decltype(y.begin(), p)>::type { n   int o = 0; n   p <<  { ; n   for (auto c : y) { n     if (o++) p <<  ,  ; n     p << c; n   } n   return p <<  } ; n } n void dor() { cerr <<   n ; } n template <class n, class... second> n void dor(n p, second... y) { n   cerr << p <<    ; n   dor(y...); n } n template <class n, class second> n void mini(n &p, second y) { n   if (p > y) p = y; n } n template <class n, class second> n void maxi(n &p, second y) { n   if (p < y) p = y; n } n int main() { n   vector<vector<int> > res; n   string second; n   cin >> second; n   while (1) { n     if (second.size() == 0) break; n     int wsk = second.size() - 1; n     vector<int> act; n     for (int i = 0; i < (int)(second.size()); ++i) { n       ; n       if (second[i] ==  ( ) { n         while (wsk > i && second[wsk] !=  ) ) { n           wsk--; n         } n         if (wsk <= i) break; n         act.push_back(i); n         act.push_back(wsk); n         second[i] =    ; n         second[wsk] =    ; n       } n     } n     if (act.size() == 0) break; n     res.push_back(act); n   } n   sort((res).begin(), (res).end()); n   if (res.size() == 0) n     cout << 0 <<   n ; n   else { n     cout << res.size() <<   n ; n     for (auto j : res) { n       sort((j).begin(), (j).end()); n       cout << j.size() <<   n ; n       for (auto i : j) cout << i + 1 <<    ; n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n vector<int> basis; n void add(int x) { n   for (int& a : basis) n     if (a & -a & x) x ^= a; n   if (x == 0) return; n   for (int& a : basis) n     if (x & -x & a) a ^= x; n   basis.emplace_back(x); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int x = 0; n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     int a; n     cin >> a; n     add(x ^= a); n   } n   if (x) n     cout << basis.size(); n   else n     cout <<  -1 ; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = (int)1e9 + 7; n int pw(int a, int b) { n   if (b == 0) return 1; n   long long t = pw(a, b / 2); n   t = (t * t) % mod; n   if (b % 2) t = (t * a) % mod; n   return t; n } n int arr[26]; n int main() { n   int n, i, j; n   string str; n   cin >> n >> str; n   for (i = 0; i < n; i++) arr[str[i] -  A ]++; n   int mx = 0; n   for (i = 0; i < 26; i++) mx = max(mx, arr[i]); n   int k = 0; n   for (i = 0; i < 26; i++) { n     if (arr[i] == mx) k++; n   } n   cout << pw(k, n) << endl; n   return 0; n } n