#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   long long powMod(long long x, long long y) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * (x % ((long long)1e9 + 7))) % ((long long)1e9 + 7);       }       y /= 2;       x = ((x % ((long long)1e9 + 7)) * (x % ((long long)1e9 + 7))) %           ((long long)1e9 + 7);     }     return p;   }   long long CpowMod(long long x, long long y, long long w) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * (x % w)) % w;       }       y /= 2;       x = ((x % w) * (x % w)) % w;     }     return p;   }   long long invMod(long long x) { return powMod(x, ((long long)1e9 + 7) - 2); }   long long CinvMod(long long x, long long w) { return CpowMod(x, w - 2, w); }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long totLeaf;   vector<set<long long> > edges;   long long bud = -1;   long long n;   void removeEdge(long long x, long long y) {     {};     edges[x].erase(y);   }   void dfs(long long node, long long par) {     for (auto &it : edges[node]) {       if (it != par) {         dfs(it, node);       }     }     long long cnt = 0;     for (auto &it : edges[node]) {       if (it == par || edges[it].count(node) == 0) {         continue;       }       cnt++;     }     if (cnt) {       totLeaf += cnt;       bud++;       removeEdge(node, par);     }   }   void solve() {     long long T;     cin >> T;     while (T--) {       totLeaf = 0;       bud = -1;       cin >> n;       edges = vector<set<long long> >(n + 1);       for (long long i = 0; i <= n - 2; i++) {         long long x, y;         cin >> x >> y;         edges[x].insert(y);         edges[y].insert(x);       }       dfs(1, 0);       cout << totLeaf - (bud) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(10);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 5;   const int N = 1e4 + 5;   const int inf = 0x3f3f3f3f;   struct hor {     int x1, x2, y;     bool operator<(const hor& a) const { return y < a.y; }   } h[maxn];   struct ver {     int y1, y2, x;     bool operator<(const ver& a) const { return y1 < a.y1; }   } v[maxn];   int n, cntv, cnth;   int c[N];   int lowbit(int x) { return x & (-x); }   int sum(int x) {     int ans = 0;     for (int i = x; i > 0; i -= lowbit(i)) ans += c[i];     return ans;   }   int get_sum(int l, int r) { return sum(r) - sum(l - 1); }   void update(int x, int val) {     for (int i = x; i <= N; i += lowbit(i)) c[i] += val;   }   int main() {     scanf( %d , &n);     cntv = cnth = 0;     for (int i = 1; i <= n; ++i) {       int x1, y1, x2, y2;       scanf( %d %d %d %d , &x1, &y1, &x2, &y2);       x1 += 5001, y1 += 5001, x2 += 5001, y2 += 5001;       if (x1 == x2)         v[++cntv] = {min(y1, y2), max(y1, y2), x1};       else         h[++cnth] = {min(x1, x2), max(x1, x2), y1};     }     sort(h + 1, h + cnth + 1);     sort(v + 1, v + cntv + 1);     long long ans = 0;     for (int i = 1; i <= cnth; ++i) {       memset(c, 0, sizeof(c));       for (int j = 1, k = 1; k < i;) {         if (v[j].y1 <= h[k].y && j <= cntv) {           if (v[j].x >= h[i].x1 && v[j].x <= h[i].x2 && v[j].y2 >= h[i].y)             update(v[j].x, 1);           ++j;         } else {           int res = get_sum(h[k].x1, h[k].x2);           ans += 1ll * res * (res - 1) / 2;           ++k;         }       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   const int INF = 500000001;   const double EPS = 1e-9;   const double PI = acos(-1.0);   using namespace std;   int main() {     srand(time(NULL));     char ch[101][105];     int n, m;     int bl[105][105];     while (~scanf( %d %d , &n, &m)) {       for (int i = 0; i < n; i++) {         scanf( %s , ch[i]);       }       int ans = 0;       for (int j = 0; j < m; j++) {         int flag = 1;         bl[0][j] = 1;         for (int i = 1; i < n; i++) {           if (ch[i][j] < ch[i - 1][j] && (j == 0 || bl[i][j - 1] <= 1)) {             flag = 0;             break;           } else if (ch[i][j] == ch[i - 1][j] && (j == 0 || bl[i][j - 1] == 1)) {             bl[i][j] = 1;           } else if (j == 0 || bl[i][j - 1] >= 1) {             bl[i][j] = 2;           } else {             bl[i][j] = 0;           }         }         if (!flag) {           ++ans;           for (int i = 0; i < n; i++) {             ch[i][j] = ch[0][j];             if (j == 0)               bl[i][j] = 1;             else               bl[i][j] = bl[i][j - 1];           }         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long vec3[17][1 << 17];   long long mn(int i, int j) {     int p = 31 - __builtin_clz(j - i);     return min(vec3[p][i], vec3[p][j - (1 << p)]);   }   void mn_init(int n) {     int mp = 31 - __builtin_clz(n);     for (int p = 0; p < mp; ++p)       for (int x = 0; x < n - (1 << p); ++x)         vec3[p + 1][x] = min(vec3[p][x], vec3[p][x + (1 << p)]);   }   long long vec2[17][1 << 17];   long long mx(int i, int j) {     int p = 31 - __builtin_clz(j - i);     return max(vec2[p][i], vec2[p][j - (1 << p)]);   }   void mx_init(int n) {     int mp = 31 - __builtin_clz(n);     for (int p = 0; p < mp; ++p)       for (int x = 0; x < n - (1 << p); ++x)         vec2[p + 1][x] = max(vec2[p][x], vec2[p][x + (1 << p)]);   }   int izq[100010];   struct rmq {     int MAX;     long long vec[4 * 100000];     long long* init(int n) {       MAX = 1 << (32 - __builtin_clz(n));       fill(vec, vec + 2 * MAX, 0);       return vec + MAX;     }     void updall() {       for (int i = MAX - 1; i >= 0; --i) vec[i] = min(vec[2 * i], vec[2 * i + 1]);     }     void pset(int i, long long vl) {       vec[i += MAX] = vl;       while (i) {         i /= 2;         vec[i] = min(vec[2 * i], vec[2 * i + 1]);       }     }     long long pget(int i, int j) { return _pget(i + MAX, j + MAX); }     long long _pget(int i, int j) {       long long res = 100000000;       if (j - i <= 0) return res;       if (i % 2) res = min(res, vec[i++]);       res = min(res, _pget(i / 2, j / 2));       if (j % 2) res = min(res, vec[--j]);       return res;     }   };   rmq DP;   int main() {     long long n, s, l;     cin >> n >> s >> l;     for (int i = 0; i < n; i++) {       cin >> vec3[0][i];       vec2[0][i] = vec3[0][i];     }     mn_init(n);     mx_init(n);     for (int i = 1; i < n; i++) {       if (mn(0, i) < vec3[0][i] - s) {         int bot = 0, top = i;         while (top - bot > 1) {           int mid = (top + bot) / 2;           if (mn(mid, i) < vec3[0][i] - s)             bot = mid;           else             top = mid;         }         izq[i] = max(izq[i], top);       }       if (mx(0, i) > vec3[0][i] + s) {         int bot = 0, top = i;         while (top - bot > 1) {           int mid = (top + bot) / 2;           if (mx(mid, i) > vec3[0][i] + s)             bot = mid;           else             top = mid;         }         izq[i] = max(izq[i], top);       }     }     for (int i = 1; i < n; i++) izq[i] = max(izq[i], izq[i - 1]);     for (int i = 0; i < n; ++i) izq[i]--;     long long* v = DP.init(n);     for (int i = 0; i < n; ++i) v[i] = 100000000;     DP.updall();     for (int i = 0; i < n; ++i) {       if (izq[i] == -1 && i >= l - 1)         DP.pset(i, 1);       else {         DP.pset(i, DP.pget(izq[i], i - l + 1) + 1);       }     }     if (DP.pget(n - 1, n) <= n)       cout << DP.pget(n - 1, n) << endl;     else       cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v;   vector<string> veg;   bool comp(pair<int, int> p1, pair<int, int> p2) {     return (p1.first < p2.first or             ((p1.first == p2.first) and (p1.second < p2.second)));   }   int main() {     int n, m, k, t, x, y;     veg.push_back( Grapes );     veg.push_back( Carrots );     veg.push_back( Kiwis );     cin >> n >> m >> k >> t;     while (k--) {       cin >> x >> y;       v.push_back(make_pair(x, y));     }     sort(v.begin(), v.end(), comp);     while (t--) {       int f = 0, s = 0;       int left = 0, right = v.size() - 1;       cin >> f >> s;       int mid = (left + right) / 2, flag = 0;       while (left < right) {         mid = left + (right - left) / 2 + 1;         if (v[mid].first == f and v[mid].second == s) {           flag = 1;           cout <<  Waste  << endl;           break;         }         if (f < v[mid].first or (f == v[mid].first and s < v[mid].second))           right = mid - 1;         else           left = mid;       }       if (!flag) {         if (v[left].first == f and v[left].second == s)           cout <<  Waste  << endl;         else {           if (v[left].first > f or v[left].first == f and v[left].second > s)             left--;           cout << veg[((f - 1) * m + s - left - 1) % 3] << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxlongint = 2147483647;   const int inf = 1000000000;   char s[10], a[1000][1100];   ;   int main() {     scanf( %s , s);     int n;     cin >> n;     for (int i = 1; i <= n; i++) scanf( %s , a[i]);     int ans = 0;     for (int i = 1; i <= n; i++) {       if (a[i][0] == s[0] && a[i][1] == s[1]) ans = 1;       for (int j = 1; j <= n; j++)         if (a[i][1] == s[0] && a[j][0] == s[1]) ans = 1;     }     if (ans)       printf( YES );     else       printf( NO );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 7;   vector<int> G[N];   int vis[N] = {0}, p[N];   long long sum[N] = {0};   stack<int> s;   void dfs(int u, int fa) {     s.push(u);     vis[u] = 1;     for (int i = 0; i < (int)G[u].size(); i++) {       int v = G[u][i];       if (v == fa) continue;       if (!vis[v])         dfs(v, u);       else if (vis[v] == 1) {         int maxx = u, minn = u;         while (!s.empty()) {           int t = s.top();           s.pop();           maxx = max(t, maxx);           minn = min(t, minn);           if (t == v) break;         }         p[minn] = maxx;       }     }     if (!s.empty() && s.top() == u) s.pop();     vis[u] = 2;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       G[x].push_back(y);       G[y].push_back(x);     }     for (int i = 1; i <= n + 1; i++) p[i] = n + 1;     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i, -1);     for (int i = n; i >= 1; i--) {       p[i] = min(p[i], p[i + 1]);       sum[i] = sum[i + 1] + p[i] - i;     }     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r;       int L = l, R = r + 1;       while (L < R) {         int m = (L + R) / 2;         if (p[m] > r)           R = m;         else           L = m + 1;       }       cout << sum[l] - sum[L] + 1ll * (r - L + 1) * (r - L + 2) / 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t[10], card[105];   int main() {     int i, sum, ans;     sum = 0;     for (i = 1; i <= 5; i++) {       cin >> t[i];       sum = sum + t[i];       card[t[i]]++;     }     ans = sum;     for (i = 100; i >= 1; i--) {       if (card[i] == 2) {         if (sum - 2 * i < ans) ans = sum - 2 * i;       }       if (card[i] >= 3) {         if (sum - 3 * i < ans) ans = sum - 3 * i;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mM(long long a, long long b, long long mod) {     long long res = 0;     a %= mod;     while (b) {       if (b & 1) res = (res + a) % mod;       a = (2 * a) % mod;       b >>= 1;     }     return res;   }   long long fpow(long long first, long long second, long long p) {     first = first % p;     long long res = 1;     while (second) {       if (second & 1) res = mM(res, first, p);       res %= p;       if (res < 0) res = (res + p) % p;       second = second >> 1;       first = mM(first, first, p);       if (first < 0) first = (first + p) % p;       first %= p;     }     return res;   }   long long inv(long long n) { return fpow(n, 1000000007 - 2, 1000000007); }   long long modmul(long long first, long long second) {     return mM(first, second, 1000000007);   }   long long modadd(long long first, long long second) {     long long temp = first % 1000000007 + second % 1000000007;     temp %= 1000000007;     if (temp < 0) temp = (temp + 1000000007) % 1000000007;     return temp;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) {       long long n, m;       cin >> n >> m;       string s, p;       cin >> s >> p;       string s1 =   , s2 =   ;       for (int i = 0; i < s.size(); i++)         if (s[i] !=  * )           s1 += s[i];         else           break;       for (int i = n - 1; i >= 0; i--)         if (s[i] !=  * )           s2 += s[i];         else           break;       if (s == p) {         cout <<  YES n ;         return 0;       }       string jk = s2;       reverse(jk.begin(), jk.end());       if (s1 == s && jk == s && s != p) {         cout <<  NO n ;         return 0;       }       if (s1.size() + s2.size() > p.size()) {         cout <<  NO n ;         return 0;       }       int i;       for (i = 0; i < s1.size(); i++)         if (s1[i] != p[i]) break;       int j, k = m - 1;       for (j = 0; j < s2.size(); j++)         if (s2[j] != p[k])           break;         else           k--;       if (i != s1.size() || j != s2.size())         cout <<  NO n ;       else         cout <<  YES n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   vector<int> e[N];   set<int> s[N];   queue<int> q;   bool vis[N];   int d[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       d[u]++, d[v]++;       e[u].push_back(v), e[v].push_back(u);     }     for (int i = 1; i <= n; i++)       if (d[i] == 1) q.push(i), s[i].insert(0);     while (q.size()) {       int tp = q.front();       q.pop();       vis[tp] = true;       for (int i = 0; i < e[tp].size(); i++) {         int v = e[tp][i];         if (vis[v]) continue;         d[v]--;         s[v].insert(*(s[tp].begin()) + 1);         if (d[v] == 1 && s[v].size() == 1) q.push(v);       }     }     int cnt = 0, ans = 0;     for (int i = 1; i <= n; i++)       if (s[i].size() > 2 || s[i].size() == 0)         return 0 * puts( -1 );       else if (s[i].size() == 1)         ans = max(ans, *s[i].begin());       else         cnt++, ans = max(ans, (*s[i].begin()) + (*s[i].rbegin()));     if (cnt > 1)       puts( -1 );     else {       while (ans % 2 == 0) ans /= 2;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, y, m;   int main() {     cin >> x >> y >> m;     if (x >= m || y >= m)       cout << 0 <<   n ;     else {       if (x <= 0 && y <= 0)         cout << -1 <<   n ;       else {         long long cc = 0;         if (x > y) swap(x, y);         if (x < 0) {           cc += x >= 0 ? x : -x / y;           x += y * (long long)cc;         }         while (x < m && y < m) {           if (x < y)             x = x + y;           else             y = x + y;           cc++;         }         cout << cc <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     int n, m;     cin >> n >> m;     int maks = 0;     for (int i = 0; i < n; i++) v.push_back(i + 1);     do {       int res = 0;       for (int i = 0; i < n; i++) {         for (int j = i; j < n; j++) {           int x = 100;           for (int k = i; k <= j; k++) x = min(x, v[k]);           res += x;         }       }       maks = max(res, maks);     } while (next_permutation(v.begin(), v.end()));     v.clear();     for (int i = 0; i < n; i++) v.push_back(i + 1);     do {       int res = 0;       for (int i = 0; i < n; i++) {         for (int j = i; j < n; j++) {           int x = 100;           for (int k = i; k <= j; k++) x = min(x, v[k]);           res += x;         }       }       if (res == maks) {         m--;         if (m > 0) continue;         for (int i = 0; i < n; i++) cout << v[i] <<    ;         cout <<   n ;         break;       }     } while (next_permutation(v.begin(), v.end()));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2, s3;     long long a = 0, b = 0, c = 0;     string unia;     cin >> s1 >> s2 >> s3;     long long *trm1, *trm2;     string *uni;     uni = &unia;     if (s1[0] ==  A )       trm1 = &a;     else if (s1[0] ==  B )       trm1 = &b;     else if (s1[0] ==  C )       trm1 = &c;     if (s1[2] ==  A )       trm2 = &a;     else if (s1[2] ==  B )       trm2 = &b;     else if (s1[2] ==  C )       trm2 = &c;     if (s1[1] ==  > ) {       *uni += s1[0];       *trm1 = *trm2 + 1 + *trm1;     } else if (s1[1] ==  < ) {       *uni += s1[2];       *trm2 = *trm1 + 1 + *trm2;     }     if (s2[0] ==  A )       trm1 = &a;     else if (s2[0] ==  B )       trm1 = &b;     else if (s2[0] ==  C )       trm1 = &c;     if (s2[2] ==  A )       trm2 = &a;     else if (s2[2] ==  B )       trm2 = &b;     else if (s2[2] ==  C )       trm2 = &c;     if (s2[1] ==  > ) {       *uni += s2[0];       *trm1 = *trm2 + 1 + *trm1;     } else if (s2[1] ==  < ) {       *uni += s2[2];       *trm2 = *trm1 + 1 + *trm2;     }     if (s3[0] ==  A )       trm1 = &a;     else if (s3[0] ==  B )       trm1 = &b;     else if (s3[0] ==  C )       trm1 = &c;     if (s3[2] ==  A )       trm2 = &a;     else if (s3[2] ==  B )       trm2 = &b;     else if (s3[2] ==  C )       trm2 = &c;     if (s3[1] ==  > ) {       *uni += s3[0];       *trm1 = *trm2 + 1 + *trm1;     } else if (s3[1] ==  < ) {       *uni += s3[2];       *trm2 = *trm1 + 1 + *trm2;     }     long long unicnt = 0;     long long repcnt = 0;     for (long long i = 0; i < 3; i++) {       if (i == 0)         unicnt++;       else {         long long j;         for (j = i - 1; j >= 0; j = j - 1) {           if (unia[i] == unia[j]) {             repcnt++;             break;           }         }         if (j < 0) unicnt++;       }     }     if (repcnt != 1) {       cout <<  Impossible  << endl;     } else {       vector<pair<long long, char>> m;       m.push_back(make_pair(a,  A ));       m.push_back(make_pair(b,  B ));       m.push_back(make_pair(c,  C ));       sort(m.begin(), m.end());       for (long long i = 0; i < m.size(); i++) {         cout << m[i].second;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     ios_base::sync_with_stdio(0);     cin >> N;     string K;     cin >> K;     int zm = N;     for (int i = 1; i < N; i++) {       if (K[i] != K[i - 1]) {         zm--;         if (i < N - 1) K[i] = K[i + 1];       }     }     cout << zm;   }


#include <bits/stdc++.h>   int mod = 1000000007;   using namespace std;   using namespace std;   int n, k;   int a[400005];   int pos[400005];   map<int, int> m;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     cin >> n >> k;     for (int i = 1; i <= n; i++) pos[i] = 1e7;     m[a[1]] = 1e7;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       pos[m[a[i]]] = i;       m[a[i]] = i;     }     int ans = 0;     set<int> s;     set<pair<int, int> > ss;     for (int i = 1; i <= n; i++) {       if (!s.count(a[i])) {         if (s.size() < k) {           ans++;           s.insert(a[i]);           ss.insert(make_pair(pos[i], a[i]));         } else {           ans++;           set<pair<int, int> >::iterator it = ss.end();           it--;           int val = (*it).second;           ss.erase(it);           s.erase((val));           s.insert(a[i]);           ss.insert(make_pair(pos[i], a[i]));         }       } else {         ss.erase(ss.begin());         ss.insert(make_pair(pos[i], a[i]));       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int arr[11][11];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       arr[1][i] = 1;     }     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= n; j++) {         arr[i][j] = arr[i - 1][j] + arr[i][j - 1];       }     }     cout << arr[n][n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n, m, k;     int h;     while (scanf( %d%d%d , &n, &m, &h) != EOF) {       int sum1, sum2;       sum1 = sum2 = 0;       for (i = 1; i <= m; i++) {         scanf( %d , &k);         if (i == h)           sum1 = k;         else           sum2 += k;       }       k = n - 1;       if (sum1 + sum2 < n)         puts( -1 );       else if (sum2 < k - 1)         puts( 1 );       else {         k = n - 1;         h = sum2;         double ans = 1;         for (i = 1; i <= k; i++) {           ans *= h;           h--;         }         h = sum2 + sum1 - 1;         for (i = 1; i <= k; i++) {           ans /= h;           h--;         }         printf( %.7lf n , 1 - ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, m, c;     cin >> n >> m >> c;     vector<int> a(n), b(m);     for (int i = 0; i < n; i++) cin >> a[i];     for (int j = 0; j < m; j++) cin >> b[j];     vector<int> beg(n);     beg.assign(n, 0);     vector<int> start(n), end(n);     start.assign(n, 0);     end.assign(n, 0);     int max;     if (n >= 2 * m) {       for (int i = 0; i < m; ++i) {         beg[i] = i + 1;         start[i] = 0;         end[i] = start[i] + beg[i];       }       for (int i = m; i < n - m + 1; ++i) {         beg[i] = m;         start[i] = 0;         end[i] = start[i] + beg[i];       }       for (int i = n - m + 1; i < n; ++i) {         beg[i] = n - i;         start[i] = start[i - 1] + 1;         end[i] = start[i] + beg[i];       }     } else {       for (int i = 0; i < n - m + 1; ++i) {         beg[i] = i + 1;         start[i] = 0;         end[i] = start[i] + beg[i];       }       for (int i = n - m + 1; i < m; ++i) {         beg[i] = n - m + 1;         start[i] = start[i - 1] + 1;         end[i] = start[i] + beg[i];       }       for (int i = m; i < n; ++i) {         beg[i] = n - i;         start[i] = start[i - 1] + 1;         end[i] = start[i] + beg[i];       }     }     for (int i = 0; i < n; ++i) {       for (int j = start[i]; j < end[i]; ++j) a[i] = (a[i] + b[j]) % c;       cout << a[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int a[100];     int e, n, i, j;     scanf( %d , &n);     for (i = 0; i < n; i++) {       a[i] = 0;     }     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         scanf( %d , &e);         if (i >= j) {           continue;         }         a[i] |= e;         a[j] |= e;       }     }     for (i = 0; i < n; i++) {       printf( %d  , a[i]);     }     return 0;   }


#include <bits/stdc++.h>   #define fo(a,b,c) for (a=b; a<=c; a++)   #define fd(a,b,c) for (a=b; a>=c; a--)   #define fu(x) (((x)&1)?-1:1)   #define add(a,b) a=((a)+(b))%mod   #define min(a,b) (a<b?a:b)   #define max(a,b) (a>b?a:b)   #define mod 998244353   #define Mod 998244351   #define ll long long   //#define file   using namespace std;      int n,K,i,j,k,l,ii;   int a[51];   ll C[2001][2001],jc[2001],Jc[2001];   ll f[51][2001][51];   ll ans,p0,p1,Len,LEN,L;      ll qpower(ll a,int b) {ll ans=1; while (b) {if (b&1) ans=ans*a%mod;a=a*a%mod;b>>=1;} return ans;}   ll E(ll p,ll a,ll b) {return p*qpower(qpower(1-b,a+1),Mod)%mod;} //p*x^a*e^b      int main()   {    #ifdef file    freopen( CF1477F.in , r ,stdin);    #endif        scanf( %d%d ,&n,&K);    fo(i,1,n) scanf( %d ,&a[i]),Len+=a[i];LEN=qpower(Len,Mod);        C[0][0]=1;    fo(i,1,2000)    {     C[i][0]=C[i][i]=1;     fo(j,1,i-1) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;    }    jc[0]=1;    fo(i,1,2000) jc[i]=jc[i-1]*i%mod;    Jc[2000]=qpower(jc[2000],Mod);    fd(i,2000-1,0) Jc[i]=Jc[i+1]*(i+1)%mod;        f[0][0][0]=1;    fo(l,1,n)    {     L=a[l],ii=(L-1)/K;     fo(i,0,ii)     {      p0=qpower((L-i*K)*LEN%mod,i)*fu(i)*Jc[i]%mod;      if (i)      p1=qpower((L-i*K)*LEN%mod,i-1)*fu(i)*Jc[i-1]%mod;      fo(j,0,Len)      {       fo(k,0,l-1)       if (f[l-1][j][k])       {        add(f[l][j+i][k],f[l-1][j][k]*p0);        if (i)        add(f[l][j+i][k+1],f[l-1][j][k]*p1);       }      }     }    }    fo(j,0,Len) fo(k,0,n) f[n][j][k]=-f[n][j][k];    add(f[n][0][0],1);    assert(!f[n][0][0]);        fo(j,0,Len) fo(k,0,n) if (f[n][j][k])    add(ans,E(f[n][j][k],j-k,(Len-j*K)*LEN%mod)*jc[j-k]);    printf( %lld n ,(ans+mod)%mod);        fclose(stdin);    fclose(stdout);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1e9 + 7;   const long long int INF = 2e15;   const long long int MAXN = 2e5 + 5;   long long int fastexpo(long long int b, long long int exp) {     if (exp == 0) return 1;     if (exp == 1) return b;     long long int ans = (fastexpo(b, exp / 2) % MOD);     ans *= ans;     ans %= MOD;     if (exp % 2 == 1) {       ans *= b;     }     ans %= MOD;     return ans;   }   long long int n;   vector<long long int> a;   long long int dp[MAXN][4];   long long int solve(long long int idx, vector<long long int> nice,                       long long int which) {     if (idx < 0) {       return 0;     }     if (nice.size() == 1) {       return 0;     }     vector<long long int> o, z;     for (long long int i = 0; i < nice.size(); i++) {       if ((1LL << idx) & nice[i]) {         o.push_back(nice[i]);       } else {         z.push_back(nice[i]);       }     }     long long int lo = o.size();     long long int lz = z.size();     if (min(lo, lz) <= 1) {       if (max(lo, lz) <= 1) {         return 0;       } else {         if (lo <= 1) {           return solve(idx - 1, z, 0);         } else {           return solve(idx - 1, o, 1);         }       }     }     return dp[idx][which] =                min(solve(idx - 1, o, 1) + max((lz - 1), (long long int)0),                    solve(idx - 1, z, 0) + max((lo - 1), (long long int)0));   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     memset(dp, -1, sizeof(dp));     ;     long long int mx = 0;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       a.push_back(x);       mx = max(mx, (long long int)log2(x));     }     cout << solve(mx, a, 2) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[200005][4];   vector<int> v[200005];   int mod = 998244353;   void dfs(int first, int f) {     dp[first][0] = 1;     int visf = 0;     for (auto it : v[first]) {       if (it != f) {         dfs(it, first);         if (visf) {           dp[first][1] *= (dp[it][0] + dp[it][2] + dp[it][1]);           dp[first][1] %= mod;           dp[first][2] = (dp[first][2] * (dp[it][0] + dp[it][1] + dp[it][2]) +                           dp[first][0] * (dp[it][2] + dp[it][0])) %                          mod;           dp[first][3] *= (dp[it][0] + dp[it][1] + dp[it][2]);           dp[first][3] %= mod;         } else {           dp[first][1] = (dp[first][1] * (dp[it][0] + dp[it][1] + dp[it][2]) +                           dp[first][0] * (dp[it][2] + dp[it][0])) %                          mod;         }         dp[first][0] *= (dp[it][1] + dp[it][3]);         dp[first][0] %= mod;       } else {         visf = 1;         dp[first][3] = dp[first][0];       }     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int first, second;       scanf( %d %d , &first, &second);       v[first].push_back(second);       v[second].push_back(first);     }     dfs(1, 0);     printf( %lld n , (dp[1][0] + dp[1][1] + dp[1][2] + dp[1][3]) % mod);   }


#include <bits/stdc++.h>   inline int two(int n) { return 1 << n; }   inline int test(int n, int b) { return (n >> b) & 1; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   inline int ones(int n) {     int res = 0;     while (n && ++res) n -= n & (-n);     return res;   }   long long int gcd(long long int a, long long int b) {     return (a ? gcd(b % a, a) : b);   }   long long int modPow(long long int a, long long int b, long long int MOD) {     long long int x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y) % MOD;       }       b /= 2;       y = (y * y) % MOD;     }     return x;   }   long long int modInverse(long long int a, long long int p) {     return modPow(a, p - 2, p);   }   using namespace std;   int A[26];   int marked[26];   bool check(int ex) {     int i, ctr;     ctr = 0;     for (i = 0; i < (26); i++) {       if (A[i] == ex) ctr++;     }     if (ctr == 1)       return true;     else       return false;   }   int main() {     int n, i, j, k;     cin >> n;     char ch;     int inf = -999999;     string str;     int ans, ex, f;     ans = ex = f = 0;     for (i = (1); i <= (n); i++) {       cin >> ch >> str;       int len = str.size();       if (f) {         if (i == n) continue;         if (ch ==  !  || ch ==  ? ) ans++;       }       if (ch ==  ! ) {         memset(marked, 0, sizeof(marked));         ex++;         for (j = 0; j < (len); j++) {           if (A[str[j] -  a ] != inf && !marked[str[j] -  a ]) A[str[j] -  a ]++;           marked[str[j] -  a ]++;         }       } else if (ch ==  . ) {         for (j = 0; j < (len); j++) A[str[j] -  a ] = inf;       } else         A[str[0] -  a ] = inf;       if (check(ex) && !f) f++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int v1, v2, v3, vm;   inline long long readll() {     int sign = 1;     char c;     for (c = getchar(); !isdigit(c); c = getchar())       if (c ==  - ) sign = -sign;     long long res = c -  0 ;     for (c = getchar(); isdigit(c); c = getchar()) res = res * 10 + c -  0 ;     return sign * res;   }   void writell(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) writell(x / 10);     putchar(x % 10 +  0 );   }   void inp() { cin >> v1 >> v2 >> v3 >> vm; }   void out() {     if (vm < v2 && vm <= 2 * v3 && v3 <= 2 * vm) {       writell(v1 * 2);       putchar(  n );       writell(v2 * 2);       putchar(  n );       writell(min(v3 * 2, vm * 2));     } else {       putchar( - );       putchar( 1 );     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     inp();     out();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[105];   int main() {     int n, p, q;     cin >> n >> p;     for (int i = 0; i < p; ++i) cin >> x[i];     cin >> q;     for (int i = p; i < p + q; ++i) cin >> x[i];     sort(x, x + p + q);     int k = 0;     for (int i = 0; i < p + q; ++i) {       if (x[i] == k + 1) ++k;     }     if (k == n)       cout <<  I become the guy.  << endl;     else       cout <<  Oh, my keyboard!  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1505;   int n, k;   map<tuple<int, int, int>, bool> memo;   bool query(int a, int b, int c) {     if (b == a || b == c) return 1;     if (a > c) swap(a, c);     auto s = make_tuple(a, b, c);     if (memo.count(s)) return memo[s];     cout <<  ?   << a + 1 <<     << b + 1 <<     << c + 1 << endl;     cout.flush();     string ans;     cin >> ans;     return memo[s] = (ans[0] ==  Y );   }   bool alive[N], done;   int GOAL;   int closer(int u, int v) {     for (int w = 0; w < int(n); w++)       if (alive[w] && w != u && w != v && query(u, w, v)) v = w;     return v;   }   int iter(int u) {     vector<int> nodes;     for (int w = 0; w < int(n); w++)       if (w != u && alive[w]) nodes.push_back(w);     int sz = nodes.size();     auto w = nodes[rand() % sz];     w = closer(u, w);     vector<int> u_friends, w_friends;     u_friends.push_back(u);     w_friends.push_back(w);     for (auto v : nodes)       if (v != w) {         if (query(u, w, v))           w_friends.push_back(v);         else           u_friends.push_back(u);       }     int ans;     if (u_friends.size() > w_friends.size()) {       ans = u;       if (u_friends.size() == GOAL) done = 1;       for (auto v : w_friends) alive[v] = 0;     } else {       ans = w;       if (w_friends.size() == GOAL) done = 1;       for (auto v : u_friends) alive[v] = 0;     }     return ans;   }   int main() {     srand(time(0));     cin >> n >> k;     fill_n(alive, n, 1);     GOAL = 1;     while (GOAL * k <= n) GOAL *= k;     int u = 0;     while (!done) u = iter(u);     cout <<  !   << u + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     long long x, y, m;     cin >> x >> y >> m;     if (x <= 0 && y <= 0) {       if (max(x, y) >= m)         cout <<  0 ;       else         cout <<  -1 ;       return 0;     }     if (x > y) swap(x, y);     long long odp = 0;     if (x < 0 && y > 0) {       if (y < m) {         long long ile = abs(x) / y;         odp += ile;         x += ile * y;       }     }     while (max(x, y) < m) {       if (x < y)         x += y;       else         y += x;       ++odp;     }     cout << odp;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a;     int sum = 0;     for (int i = 0; i < n; i++) {       cin >> a;       sum += a;     }     cout << (sum % n == 0 ? n : n - 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, h;     cin >> n >> d >> h;     if (d > 2 * h || d < h) {       cout <<  -1  << endl;       return 0;     }     if (d == 1 && h == 1 && n != 2) {       cout <<  -1  << endl;       return 0;     }     vector<pair<int, int> > p;     for (int i = 0; i < h; i++) {       p.push_back(pair<int, int>(i + 1, i + 2));     }     if (d - h > 0) {       p.push_back(pair<int, int>(1, h + 2));       for (int i = 1; i < d - h; i++) {         p.push_back(pair<int, int>(h + 1 + i, h + 2 + i));       }     }     if (d + 1 > n) {       cout <<  -1  << endl;       return 0;     }     if (h != 1) {       for (int i = d + 2; i <= n; i++) {         p.push_back(pair<int, int>(2, i));       }     } else {       for (int i = d + 2; i <= n; i++) {         p.push_back(pair<int, int>(1, i));       }     }     for (int i = 0; i < p.size(); i++) {       cout << p[i].first <<     << p[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[569], sq[250069], zs, inf = 1e18;   void cyc(long long x) {     swap(a[x + 1], a[x + 2]);     swap(a[x], a[x + 1]);     zs++;     sq[zs] = x;   }   int main() {     long long t, rr, i, j, ii, e;     pair<long long, long long> mne;     scanf( %lld , &t);     for (rr = 0; rr < t; rr++) {       scanf( %lld , &n);       for (i = 1; i <= n; i++) {         scanf( %lld , a + i);       }       zs = 0;       for (i = 1; i <= n - 2; i++) {         mne = {inf, -1};         for (j = i; j <= n; j++) {           mne = min(mne, {a[j], j});         }         e = mne.second;         for (j = e - 2; j >= i; j -= 2) {           cyc(j);         }         if (j == i - 1) {           for (ii = 0; ii < 2; ii++) {             cyc(i);           }         }       }       if (a[n - 1] > a[n]) {         for (i = n - 2; i; i--) {           cyc(i);           if (a[i] <= a[i + 1]) {             break;           }         }         if (!i) {           zs = -1;         }       }       printf( %lld n , zs);       for (i = 1; i <= zs; i++) {         printf( %lld%c , sq[i],    n [i == zs]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e5 + 1;   struct Node {     int t, x, l, c;   } pnt[maxN];   long long t, pos[maxN];   int m, n;   int solve(long long t) {     int l, r, m;     while (t > 0) {       l = 1, r = n + 1;       while (l + 1 < r) {         m = (l + r) >> 1;         if (pos[m] < t)           l = m;         else           r = m;       }       if (pnt[l].t == 1) return pnt[l].x;       t = ((t - pos[l] - 1) % pnt[l].l) + 1;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &pnt[i].t);       if (pnt[i].t == 1) {         scanf( %d , &pnt[i].x);         pos[i + 1] = pos[i] + 1;       } else {         scanf( %d%d , &pnt[i].l, &pnt[i].c);         pos[i + 1] = pos[i] + pnt[i].l * pnt[i].c;       }     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %I64d , &t);       printf( %d , solve(t));       if (i < m)         printf(   );       else         printf(  n );     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const long double pi = acos(-1);   const long long int mod = 1e9 + 7;   bool debug = false;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t = 1, n, i, j, k, len, x, y, z, c, f, flag, p, q, mx, mn, l, r,                   sum, ans, tmp, it, pos, avg, m, cnt;     string s;     char ch;     vector<long long int> v;     vector<pair<long long int, long long int>> vec;     unordered_map<long long int, long long int> mappu;     pair<long long int, long long int> pr;     {       f = 0;       sum = 0;       flag = 0;       ans = 0;       cnt = 0;       v.clear();       mappu.clear();       vec.clear();       string s2;       cin >> s >> s2;       if (s == s2)         cout << s;       else         cout << 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void chmin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmax(T& a, const T& b) {     if (a < b) a = b;   }   tuple<long long, long long, long long> adj[400001];   long long cnt;   long long nm;   int main() {     long long k, a, x, y, m, n;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> k >> a >> x >> y >> m;       long long t = 0;       for (long long j = 1; j <= k; j++, adj[nm++] = make_tuple(t, a, i),                      (a > ((a * x + y) % m) && j != k + 1) ? t++ : t,                      a = (a * x + y) % m)         ;       cnt = max(cnt, t);     }     cout << cnt <<   n ;     sort(adj, adj + nm);     for (long long i = 0; i < nm; i++)       cout << get<1>(adj[i]) <<     << get<2>(adj[i]) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 5;   const int mod = 1e9 + 7;   long long n, k, arr[MAX], ans = 0;   int main(int argc, char** argv) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k;     if (n == 1) {       cout << 0;       exit(0);     }     bool moded = true;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     long long modu = arr[0] % k;     for (int i = 0; i < n; i++)       if (arr[i] % k != modu) moded = false;     if (moded)       for (int i = 0; i < n; i++) ans += (arr[i] - arr[0]) / k;     else       ans = -1;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 100005;   char str[Maxn];   int slen;   int cnt[Maxn];   bool was[Maxn];   int Z[Maxn];   vector<pair<int, int> > res;   int main() {     scanf( %s , str);     slen = strlen(str);     cnt[slen]++;     was[slen] = true;     int L = -1, R = -1;     for (int i = 1; i < slen; i++) {       if (i <= R) Z[i] = min(R - i + 1, Z[i - L]);       while (i + Z[i] < slen && str[Z[i]] == str[i + Z[i]]) Z[i]++;       if (i + Z[i] - 1 > R) {         L = i;         R = i + Z[i] - 1;       }       if (i + Z[i] == slen) was[Z[i]] = true;       cnt[Z[i]]++;     }     for (int i = slen - 1; i >= 0; i--) cnt[i] += cnt[i + 1];     for (int i = 1; i <= slen; i++)       if (was[i]) res.push_back(pair<int, int>(i, cnt[i]));     printf( %d n , res.size());     for (int i = 0; i < res.size(); i++)       printf( %d %d n , res[i].first, res[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[1000000];   long long bank;   vector<int> t;   int main() {     cin >> n >> m;     for (int i = 0, k; i < n; i++) {       cin >> k;       int p = -1;       bool q = false;       for (int j = 0; j < k; j++) {         cin >> a[j];         if (a[j] < m) p = 1;       }       if (p == true) {         t.push_back(i);         bank++;       }     }     cout << bank << endl;     for (int i = 0; i < t.size(); i++) cout << t[i] + 1 <<    ;   }


//In rememberance to GOD//   //May GOD take care to me,my family and all the creatures//   #include<bits/stdc++.h>   using namespace std;            #define ll long long   #define int ll      #define mod ((int)1e9+7)   #define pii pair<int,int>   #define vi vector<int>   #define vvi vector<vi>   #define vc vector<char>   #define vpi vector<pii>   #define vpic vector<pair<int,char>>   #define vpid vector<pair<int,double>>   #define INF (ll)1e15   #define all(x)  (x).begin(),(x).end()   #define allr(x) (x).rbegin(),(x).rend()   #define pb push_back   #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))   #define eb emplace_back      #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(),  , ,    ); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }      void err(istream_iterator<string> it) {}   template<typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {    cerr << *it <<   =   << a << endl;    err(++it, args...);   }      #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)   #define time__(d)        for (            auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);            blockTime.second;            debug( %s: %lld ms n , d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false        )      //fill memset iota function   // use 1ll<<number(left shift)      const int N=((int)1e6);            // int primes[N];   // // int spf[N];   // vector<int> pr;      // void sieve(){      //     // iota(spf+2,spf+N,2);      //  for(ll i=2;i<N;i++){   //   if(primes[i]==0){   //     pr.eb(i*i);   //    for(ll j=i*i;j<N;j+=i){   //                 // if(spf[j]==j)   //                 // spf[j]=i;   //     primes[j]=1;   //    }   //   }   //   primes[i]^=1;   //  }      // }   // nloglogn               ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}   void swap(int &x, int &y) {int temp = x; x = y; y = temp;}   ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}   ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}   ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}   ll power(ll x, ll y,ll m) {ll res = 1;while (y > 0){ if (y & 1) res = (res*x)%m;y = y>>1;x = x*x%m;}return res;}   //avoid it in power of 2.   //logn implementation   //divisors in o(sqrt(n)) and no of divisors less than 2*(n^1/2);//128(max divisors for n<=1e5)   //for n>=1e5 no of divisors is less than n^1/3;   // use i&1 instead of i%2   //stoll convert string to integer(long long)   //  if(a>b) { return a/b+fun(b,a%b);} else return b/a+fun(a,b%a); technique of mod and minus similar answer but diffent time complexity.   // if(a>b) { return 1+fun(b,a-b);} else return 1+fun(a,b-a);   // class cmp { public:   //     bool operator()(const pair<int,pii> &p1,const pair<int,pii> &p2) const { if(p1.first!=p2.first) return p1.first>p2.first;else   //         {   //             if(p1.second.first!=p2.second.first)   //             {   //                 return p1.second.first>p2.second.first;   //             }   //             else   //             {   //                 return p1.second.second>p2.second.second;   //             }                  //         }              //     }       // };   // instead of priority queue i use set defined with cmp class strictly using  =  sign in comparisons(work as multi set)   //erase function with values won t work   //to modify a set i use cmp class stictly without using  =  sign in comparions,example above!!!!     //erase function with values will work                        /////////////////////////////////////// CODE ////////////////////////////////////////////////         // int dx[] = {1,0,-1,0};   // int dy[] = {0,1,0,-1};                  // vi adj[N];   // int visited[N];   // int par[N];   // int d[N];            // int binary_searching(int a,int y)   // {   //     int start=-1;   //     int end=a;      //     while(start+1!=end)   //     {   //         int mid=(start+end)/2;   //         if(mid>(a-y))   //         {   //             end=mid;   //         }   //         else   //         {   //             start=mid;   //         }   //     }      //     return end;                    // }         bool palin(string s)   {       int n=s.size();                 for(int i=0;i<n/2;i++)       {           if(s[i]!=s[n-i-1])           {               return false;           }       }          return true;   }            void solve()   {       string s;       cin>>s;          bool flag=false;          for(int i=0;i<s.size();i++)       {           if(s[i]!= a )           {               flag=true;               break;           }       }          if(!flag)       {           cout<< NO <<  n ;           return;       }          //appling to first;       string temp;       // temp=s;          temp= a +s;       if(!palin(temp))       {           cout<< YES <<  n ;           cout<<temp<<  n ;           return;       }          temp=s+ a ;          if(!palin(temp))       {           cout<< YES <<  n ;           cout<<temp<<  n ;       }                                                                                }                           int32_t main()   {       #ifndef ONLINE_JUDGE           freopen( input.txt ,  r , stdin);           freopen( output.txt ,  w , stdout);       #endif          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);          int t;       cin>>t;             // sieve();                    // t=1;                 for(int i=1;i<=t;i++)       {           solve();           // time__( solve );       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q;   int p[200001];   int a[200001];   vector<int> cur[200001];   int pos[200001];   int par[200001][21];   struct cmp {     bool operator()(pair<int, int> a, pair<int, int> b) {       return a.second > b.second;     }   };   priority_queue<pair<int, int>, vector<pair<int, int> >, cmp> h;   struct Q {     int l, r, id;   };   vector<Q> Query;   bool cmp(Q a, Q b) { return a.l < b.l; }   int ans[200001];   int Process(int pos) {     int k = n - 1;     for (int i = 20; i >= 0; i--) {       if (k & (1 << i)) {         if (par[pos][i] == -1) return -1;         pos = par[pos][i];       }     }     return pos;   }   int main() {     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       cin >> p[i];       pos[p[i]] = i;     }     for (int i = 1; i <= m; i++) {       cin >> a[i];     }     memset(par, -1, sizeof par);     for (int i = 1; i <= m; i++) {       int x = pos[a[i]];       int y;       if (x == 1)         y = p[n];       else         y = p[x - 1];       for (auto k : cur[y]) {         par[k][0] = i;       }       cur[y].clear();       cur[a[i]].push_back(i);     }     for (int j = 1; j <= 20; j++) {       for (int i = 1; i <= m; i++) {         if (par[i][j - 1] != -1) par[i][j] = par[par[i][j - 1]][j - 1];       }     }     for (int i = 1; i <= q; i++) {       int l, r;       cin >> l >> r;       Query.push_back({l, r, i});     }     sort(Query.begin(), Query.end(), cmp);     for (int i = 1; i <= m; i++) {       int r = Process(i);       if (r != -1) h.push({i, r});     }     for (auto x : Query) {       int id = x.id;       while (!h.empty() && h.top().first < x.l) h.pop();       if (h.empty() || h.top().second > x.r)         ans[id] = 0;       else         ans[id] = 1;     }     for (int i = 1; i <= q; i++) cout << ans[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   vector<int> adj[N];   int a[N], d[N], din[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d %d , a + i, d + i);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         if (d[i] < 0) {           if (make_pair(a[i], -i) > make_pair(a[j], -j) &&               make_pair(a[j], -j) > make_pair(a[i] + d[i], -i) &&               make_pair(a[i] + d[i], -i) > make_pair(a[j] + d[j], -j))             adj[i].push_back(j);         } else {           if (make_pair(a[i], -i) < make_pair(a[j], -j) &&               make_pair(a[j], -j) < make_pair(a[i] + d[i], -i) &&               make_pair(a[i] + d[i], -i) < make_pair(a[j] + d[j], -j))             adj[i].push_back(j);         }       }     }     memset(din, 0, sizeof din);     for (int i = 0; i < n; i++) {       for (int u : adj[i]) din[u]++;     }     stack<int> st;     for (int i = 0; i < n; i++)       if (din[i] == 0) {         st.push(i);       }     vector<int> order;     while (!st.empty()) {       int u = st.top();       st.pop();       order.push_back(u);       for (int v : adj[u]) {         din[v]--;         if (din[v] == 0) st.push(v);       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       int cnt1, cnt2;       cnt1 = cnt2 = 0;       for (int j = 0; j < n; j++) {         if (j == order[i]) continue;         cnt1 += (make_pair(a[j], -j) < make_pair(a[order[i]], -order[i]));         cnt2 += (make_pair(a[j], -j) <                  make_pair(a[order[i]] + d[order[i]], -order[i]));       }       ans += abs(cnt1 - cnt2);       a[order[i]] += d[order[i]];     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100005];   long long sum[100005];   map<int, long long> f;   long long solve(int n, int k) {     if (f.count(k)) return f[k];     long long ret = 0;     long long cur = n - 2;     long long p = k;     while (cur >= 0) {       ret += sum[cur];       cur -= p;       p *= k;     }     return f[k] = ret;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &arr[i]);     sort(arr, arr + n);     sum[0] = arr[0];     for (int i = 1; i < n; ++i) sum[i] = sum[i - 1] + arr[i];     int q, a;     scanf( %d , &q);     for (int i = 0; i < q; ++i) {       scanf( %d , &a);       if (i) printf(   );       printf( %I64d , solve(n, a));     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace ::std;   int main() {     int n, m;     cin >> n;     int ara[2 * n + 7];     for (int i = 0; i < 2 * n; i++) {       cin >> ara[i];     }     sort(ara, ara + (2 * n));     if (ara[n - 1] == ara[n]) {       cout <<  NO ;     } else {       cout <<  YES ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   inline int gi() {     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     int sum = 0;     while ( 0  <= c && c <=  9 ) sum = sum * 10 + c - 48, c = getchar();     return sum;   }   int n, m, q, A[maxn], B[maxn];   vector<pair<int, int>> vec[maxn];   long long sum[maxn], Min[maxn << 2], tag[maxn << 2];   priority_queue<long long, vector<long long>, greater<long long>> q1, q2;   void build(int s, int l, int r) {     if (l == r) return Min[s] = B[l - 1], void();     build((s << 1), l, ((l + r) >> 1));     build((s << 1 | 1), ((l + r) >> 1) + 1, r);     Min[s] = min(Min[(s << 1)], Min[(s << 1 | 1)]);   }   void modify(int s, int l, int r, int ql, int qr, int v) {     if (ql <= l && r <= qr) return tag[s] += v, Min[s] += v, void();     if (ql <= ((l + r) >> 1)) modify((s << 1), l, ((l + r) >> 1), ql, qr, v);     if (qr >= ((l + r) >> 1) + 1)       modify((s << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, v);     Min[s] = min(Min[(s << 1)], Min[(s << 1 | 1)]) + tag[s];   }   int main() {     n = gi();     m = gi();     q = gi();     for (int i = 1; i < n; ++i) A[i] = gi(), B[i] = gi();     for (int u, v, w, i = 1; i <= m; ++i) {       u = gi();       v = gi();       w = gi();       vec[u].push_back(make_pair(v, w));     }     build(1, 1, n);     for (int i = 1; i <= n; ++i) {       for (auto j : vec[i]) modify(1, 1, n, 1, j.first, j.second);       sum[i] = Min[1];       q1.push(sum[i] + A[i]);     }     printf( %lld n , q1.top());     for (int i = 1, x, v; i <= q; ++i) {       x = gi();       v = gi();       q2.push(A[x] + sum[x]);       q1.push((A[x] = v) + sum[x]);       while (!q1.empty() && !q2.empty() && q1.top() == q2.top())         q1.pop(), q2.pop();       printf( %lld n , q1.top());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans, sx, sy, ex, ey, endx = -1, endy = -1;   char s[1005][1006];   pair<int, int> xx[1005];   pair<int, int> yy[1005];   bool able(int x, int y) {     int nx = sx, ny = sy;     while (true) {       int nex = nx + x + 1, ney = ny + y + 1;       if (nex > endx && ney > endy) return true;       if (s[nx][ney] ==  X ) {         if (nex <= endx && xx[nex].first <= ny) return false;         ny++;         continue;       } else if (s[nex][ny] ==  X ) {         if (ney <= endy && yy[ney].first <= nx) return false;         nx++;         continue;       } else         return false;     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     int state = 0;     for (int i = 0; i < n; i++) {       xx[i].first = -1;       for (int j = 0; j < m; j++) {         if (s[i][j] ==  X ) xx[i].second = j, endx = i;         if (s[i][j] ==  X  && xx[i].first == -1) xx[i].first = j;       }       if (xx[i].first != -1) {         for (int j = xx[i].first; j <= xx[i].second; j++)           if (s[i][j] !=  X ) {             printf( -1 );             return 0;           }         if (state < 2)           state++;         else if (state == 5) {           printf( -1 );           return 0;         }       } else if (state != 0)         state = 5;       if (state != 2) continue;       if (xx[i].first < xx[i - 1].first || xx[i].second < xx[i - 1].second ||           xx[i].first > xx[i - 1].second) {         printf( -1 );         return 0;       }     }     state = 0;     for (int i = 0; i < m; i++) {       yy[i].first = -1;       for (int j = 0; j < n; j++) {         if (s[j][i] ==  X ) yy[i].second = j, endy = i;         if (s[j][i] ==  X  && yy[i].first == -1) yy[i].first = j;       }       if (yy[i].first != -1) {         for (int j = yy[i].first; j <= yy[i].second; j++)           if (s[j][i] !=  X ) {             printf( -1 );             return 0;           }         if (state < 2)           state++;         else if (state == 5) {           printf( -1 );           return 0;         }       } else if (state != 0)         state = 5;       if (state != 2) continue;       if (yy[i].first < yy[i - 1].first || yy[i].second < yy[i - 1].second ||           yy[i].first > yy[i - 1].second) {         printf( -1 );         return 0;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] ==  X ) {           sx = i, sy = j;           i = n;           break;         }       }     }     if (endx == -1) {       printf( 0 );       return 0;     }     for (int i = sx; i < n; i++) {       if (s[i][sy] ==  X )         ex = i;       else         break;     }     for (int i = sy; i < m; i++) {       if (s[sx][i] ==  X )         ey = i;       else         break;     }     ans = 2140000000;     for (int i = 0; i <= ex - sx; i++) {       if (able(i, ey - sy)) {         ans = min(ans, (i + 1) * (ey - sy + 1));       }     }     for (int i = 0; i <= ey - sy; i++) {       if (able(ex - sx, i)) {         ans = min(ans, (i + 1) * (ex - sx + 1));       }     }     printf( %d , ans == 2140000000 ? -1 : ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 502;   int n, k;   int a[maxn], b[maxn], c[maxn];   bool check(int l, int r) {     if (l == r) return true;     for (int i = l + 1; i <= r; ++i)       if (a[i] != a[l]) return true;     return false;   }   bool print(int p, int r, int dir) {     printf( %d %c n , p, dir == -1 ?  L  :  R );     if (dir == -1) --p;     a[p] += a[p + 1];     for (++p; p < r; ++p) a[p] = a[p + 1];     return true;   }   bool solve(int l, int r) {     if (l == r) return false;     int i, mx = -1;     for (i = l; i <= r; ++i) mx = max(mx, a[i]);     for (i = l; i <= r; ++i) {       if (a[i] != mx) continue;       if (i == l && a[i] > a[i + 1]) return print(l, r, 1);       if (i == r && a[i] > a[i - 1]) return print(r, r, -1);       if (i != l && i != r && a[i] > a[i + 1]) return print(i, r, 1);       if (i != l && i != r && a[i] > a[i - 1]) return print(i, r, -1);     }     return puts( WTF??? );   }   int main() {     int i, j, s = 0;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     scanf( %d , &k);     for (i = 1; i <= k; ++i) scanf( %d , &b[i]);     for (i = j = 1; i <= n; ++i) {       s += a[i];       if (s < b[j]) continue;       if (s > b[j]) return puts( NO ), 0;       c[j] = i;       s = 0;       if (++j > k && i < n) return puts( NO ), 0;     }     if (j != k + 1) return puts( NO ), 0;     for (i = 1; i <= k; ++i)       if (!check(c[i - 1] + 1, c[i])) return puts( NO ), 0;     puts( YES );     for (i = k; i; --i)       while (solve(c[i - 1] + 1, c[i])) --c[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int M[16];   int R[16];   int N;   int main() {     cin >> N;     for (int i = 0; i < N; i++) {       cin >> M[i];     }     for (int i = 0; i < N; i++) {       cin >> R[i];     }     int ans = 0;     for (int i = 0; i < 720720; i++) {       bool checker = false;       for (int j = 0; j < N; j++) {         if (i % M[j] == R[j]) checker = true;       }       if (checker) ans++;     }     cout << ans / 720720.0 << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   long long a, b;   int main() {     ios_base::sync_with_stdio(0);     cin >> a >> b;     while (true) {       v.push_back(b);       if (b % 10 == 1) {         b--;         b /= 10;       } else if (b % 2 == 0) {         b /= 2;       } else {         cout <<  NO n ;         return 0;       }       if (b == a)         break;       else if (b < a) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     cout << v.size() + 1 <<   n ;     cout << a <<    ;     for (long long i = v.size() - 1; i >= 0; i--) {       cout << v[i];       cout <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l;     cin >> n >> l;     vector<int> v = vector<int>(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     int vals = 1;     int prev = v[0];     vector<pair<int, int>> vp;     vp.push_back(make_pair(prev, 1));     for (int i = 1; i < n; i++) {       if (v[i] == prev) {         vp[vp.size() - 1].second++;       } else {         prev = v[i];         vp.push_back(make_pair(prev, 1));         vals++;       }     }     double t = log2(vals);     int fs = t;     if (t > fs) fs++;     if (fs * n < l * 8) {       cout << 0 << endl;       return 0;     }     int max_log = (l * 8) / n;     int distinct = 1 << max_log;     int start_p = 0;     int end_p = vp.size() - 1;     vector<int> ps = vector<int>(vp.size() + 1, 0);     ps[0] = 0;     for (int i = 0; i < vp.size(); i++) ps[i + 1] = ps[i] + vp[i].second;     vector<int> ss = vector<int>(vp.size() + 1, 0);     ss[0] = 0;     for (int i = 0; i < vp.size(); i++) {       ss[i + 1] = ss[i] + vp[vp.size() - 1 - i].second;     }     int mn = n;     for (int i = 0; i < vals - distinct; i++) {       if (ps[i] + ss[vals - distinct - i] < mn)         mn = ps[i] + ss[vals - distinct - i];     }     cout << mn << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e15;   const int N = 2e5 + 10;   int I[N], st[N], fn[N], par[N], h[N], sz[N], big[N], hd[N], n, m, q, timer;   long long w[N];   vector<int> g[N], V[N];   struct Node {     pair<long long, long long> Mn;     long long Lazy = 0;   } seg[N << 2];   void apply(int id, long long val) {     seg[id].Mn.first += val;     seg[id].Lazy += val;   }   void shift(int id) {     if (seg[id].Lazy == 0) return;     apply(id << 1, seg[id].Lazy);     apply(id << 1 | 1, seg[id].Lazy);     seg[id].Lazy = 0;   }   void add(int l, int r, long long val, int L = 0, int R = n + m, int id = 1) {     if (r <= L || R <= l) return;     if (l <= L && R <= r) {       apply(id, val);       return;     }     shift(id);     add(l, r, val, L, (L + R) >> 1, id << 1);     add(l, r, val, (L + R) >> 1, R, id << 1 | 1);     seg[id].Mn = min(seg[id << 1].Mn, seg[id << 1 | 1].Mn);   }   pair<long long, long long> get(int l, int r, int L = 0, int R = n + m,                                  int id = 1) {     if (r <= L || R <= l) return {inf, inf};     if (l <= L && R <= r) return seg[id].Mn;     shift(id);     return min(get(l, r, L, (L + R) >> 1, id << 1),                get(l, r, (L + R) >> 1, R, id << 1 | 1));   }   void Build(int L = 0, int R = n + m, int id = 1) {     if (R - L == 1) {       seg[id].Mn = {w[I[L]], I[L]};       return;     }     Build(L, (L + R) >> 1, id << 1);     Build((L + R) >> 1, R, id << 1 | 1);     seg[id].Mn = min(seg[id << 1].Mn, seg[id << 1 | 1].Mn);     return;   }   int dfs_size(int v) {     for (int u : g[v])       if (u != par[v]) {         par[u] = v, h[u] = h[v] + 1;         sz[v] += dfs_size(u);         if (sz[u] > sz[big[v]]) big[v] = u;       }     return ++sz[v];   }   void dfs_hld(int v) {     for (int i : V[v]) I[timer] = i, st[i] = timer++;     if (big[v]) hd[big[v]] = hd[v], dfs_hld(big[v]);     for (int u : g[v])       if (u != par[v] & u != big[v]) hd[u] = u, dfs_hld(u);     for (int i : V[v]) fn[i] = timer;   }   pair<long long, long long> getmin(int u, int v) {     pair<long long, long long> res = {inf, inf};     while (hd[u] != hd[v]) {       if (h[hd[v]] > h[hd[u]]) swap(u, v);       res = min(res, get(st[hd[u]], st[u] + (int)V[u].size()));       u = par[hd[u]];     }     if (h[v] < h[u]) swap(u, v);     res = min(res, get(st[u], st[v] + (int)V[v].size()));     return res;   }   void query(int u, int v, int k) {     vector<int> ans;     while (k--) {       pair<long long, long long> p = getmin(u, v);       if (p.first >= inf) break;       ans.push_back(p.second);       add(st[p.second], st[p.second] + 1, inf);     }     cout << ans.size() <<    ;     for (int i : ans) cout << i - n <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m >> q;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n + m; i++) {       if (i <= n) {         V[i].push_back(i), w[i] = inf;         continue;       }       int c;       cin >> c;       V[c].push_back(i), w[i] = i - n;     }     dfs_size(1), hd[1] = 1, dfs_hld(1), Build();     while (q--) {       int t;       cin >> t;       if (t == 1) {         int u, v, k;         cin >> u >> v >> k;         query(u, v, k);       }       if (t == 2) {         int v, k;         cin >> v >> k;         add(st[v], fn[v], k);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   set<int> a, b;   set<int> pre;   char str[10];   int main() {     int n;     cin >> n;     long long ans = 1;     a.insert(0);     b.insert(1e9 + 5);     for (int i = 0; i < n; ++i) {       int x;       scanf( %s%d , str, &x);       if (str[1] ==  D ) {         int l = *a.rbegin();         int r = *b.begin();         if (x > l && x < r) {           pre.insert(x);         } else {           if (x < l)             a.insert(x);           else             b.insert(x);         }       } else {         if (pre.count(x)) {           ans *= 2;           ans %= mod;           for (auto it : pre) {             if (it > x)               b.insert(it);             else if (it < x)               a.insert(it);           }           pre.clear();         } else {           int l = *a.rbegin();           int r = *b.begin();           if (x == l) {             a.erase(x);             for (auto it : pre) {               if (it != x) b.insert(it);             }           } else if (x == r) {             b.erase(x);             for (auto it : pre) {               if (it != x) a.insert(it);             }           } else             return puts( 0 );           pre.clear();         }       }     }     int x = pre.size();     ans *= (x + 1);     ans %= mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int prev = 0;     int ans = 0;     for (int i = 1; i <= n; i++) {       ans += (n - i) * (i - 1) + i;       prev = i;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3005;   const int maxm = maxn * maxn << 1;   int n, m, q;   int id[maxn][maxn << 1];   int fa[maxm];   int vis[maxm];   int top = 0;   stack<pair<int, int> > sta;   inline int getfa(int x) {     sta.push(make_pair(x, fa[x]));     return fa[x] == x ? x : fa[x] = getfa(fa[x]);   }   inline void bing(int x, int y) {     if (vis[x] && vis[y]) {       int fax = getfa(x);       int fay = getfa(y);       if (fax != fay) fa[fax] = fay;     }   }   inline void Union(int x, int y) {     int now = id[x][y];     bing(id[x + 1][y], now);     bing(id[x + 1][y - 1], now);     bing(id[x + 1][y + 1], now);     bing(id[x - 1][y], now);     bing(id[x - 1][y - 1], now);     bing(id[x - 1][y + 1], now);     bing(id[x][y - 1], now);     bing(id[x][y + 1], now);   }   inline void rm() {     while (!sta.empty()) {       fa[sta.top().first] = sta.top().second;       sta.pop();     }   }   int main() {     scanf( %d%d%d , &n, &m, &q);     int __cnt = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= (m << 1); ++j) {         id[i][j] = ++__cnt;         fa[id[i][j]] = id[i][j];       }     }     for (int i = 1; i <= n; ++i) {       id[i][0] = id[i][m << 1];       id[i][m << 1 | 1] = id[i][1];     }     int ans = 0;     while (q--) {       int x, y;       scanf( %d%d , &x, &y);       if (vis[id[x][y]]) continue;       vis[id[x][y]] = vis[id[x][y + m]] = true;       Union(x, y);       Union(x, y + m);       if (getfa(id[x][y]) == getfa(id[x][y + m])) {         rm();         vis[id[x][y]] = vis[id[x][y + m]] = false;       } else         ans++;       while (!sta.empty()) sta.pop();     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast,unroll-loops )   #pragma GCC target( avx,avx2,sse,sse2 )   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c *x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug &operator<<(const c &) {       return *this;     }   };   struct segment {     long long a, b;     int t;     int id;     segment(long long _a = 0, long long _b = 0, int _t = 0, int _id = 0) {       a = _a;       b = _b;       t = _t;       id = _id;     }   };   struct query {     long long a, b;     int t;     query(long long _a = 0, long long _b = 0, int _t = 0) {       a = _a;       b = _b;       t = _t;     }   };   const int MAXN = 51;   const int MAXM = 5e4 + 10;   vector<segment> segments;   vector<query> queries;   vector<int> gr[2 * MAXN * MAXM];   int t[2 * MAXN * MAXM];   int card[2 * MAXN * MAXM];   int no = 0;   vector<segment> rec(long long l, long long r, vector<segment> &segments) {     vector<segment> s;     if (!segments.size()) {       s.emplace_back(l, r, 1e9, no++);       return s;     }     if (segments.size() == 1 && segments[0].a == l && segments[0].b == r) {       s.emplace_back(l, r, segments[0].t, no++);       return s;     }     vector<segment> s_left;     vector<segment> s_right;     long long m = l + r >> 1;     for (auto &x : segments) {       if (x.b <= m) {         s_left.emplace_back(x);       } else if (x.a > m) {         s_right.emplace_back(x);       } else {         s_left.emplace_back(x.a, m, x.t);         s_right.emplace_back(m + 1, x.b, x.t);       }     }     auto ss_left = rec(l, m, s_left);     auto ss_right = rec(m + 1, r, s_right);     int long long = 0, rr = 0;     long long dif = m + 1 - l;     while (long long < ss_left.size() && rr < ss_right.size()) {       if ((ss_left[long long].a >= ss_right[rr].a - dif &&            ss_left[long long].a <= ss_right[rr].b - dif) ||           (ss_right[rr].a >= ss_left[long long].a + dif &&            ss_right[rr].a <= ss_left[long long].b + dif)) {         gr[ss_left[long long].id].emplace_back(ss_right[rr].id);         gr[ss_right[rr].id].emplace_back(ss_left[long long].id);       }       if (ss_left[long long].b <= ss_right[rr].b - dif) {         ++long long;       } else {         ++rr;       }     }     for (auto &x : ss_right) {       ss_left.emplace_back(x);     }     return ss_left;   }   int root(int x) { return x == t[x] ? x : t[x] = root(t[x]); }   void onion(int x, int y) {     if ((x = root(x)) == (y = root(y))) return;     if (card[x] < card[y]) swap(x, y);     t[y] = x;     card[x] += card[y];     return;   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       string s;       long long a, b;       cin >> s >> a >> b;       if (s ==  ask ) {         queries.emplace_back(a, b, i);       } else {         segments.emplace_back(a, b, i, segments.size());       }     }     auto s = rec(0, (1ll << n) - 1, segments);     for (int i = 0; i < no; ++i) {       t[i] = i;       card[i] = 1;     }     reverse((queries).begin(), (queries).end());     vector<int> alive(no);     auto s_time = s;     sort((s_time).begin(), (s_time).end(),          [&](segment &a, segment &b) { return a.t > b.t; });     auto getSegment = [&](long long a) {       int ret = 0;       int l = 0, r = s.size() - 1;       while (l <= r) {         int m = l + r >> 1;         if (s[m].a <= a && s[m].b >= a) return s[m].id;         if (s[m].b < a) {           l = m + 1;         } else {           r = m - 1;         }       }       assert(false);       return -1;     };     int now = 0;     vector<int> ans;     for (auto &x : queries) {       while (now < s_time.size() && s_time[now].t >= x.t) {         alive[s_time[now].id] = 1;         for (auto &x : gr[s_time[now].id]) {           if (alive[x]) onion(root(s_time[now].id), root(x));         }         ++now;       }       ans.emplace_back(root(getSegment(x.a)) == root(getSegment(x.b)));     }     reverse((ans).begin(), (ans).end());     for (auto &x : ans) cout << x <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   long long Max(long long a, long long b) { return a > b ? a : b; }   long long Min(long long a, long long b) { return a < b ? a : b; }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = ((res % p) * (x % p)) % p;       y = y >> 1;       x = ((x % p) * (x % p)) % p;     }     return res;   }   bool isprime(long long n) {     if (n == 2) return true;     if (n % 2 == 0) return false;     for (long long i = 3; i * i <= n; i += 2) {       if (n % i == 0) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, lo = 0, hi = 1000000007LL, ans = -1000000007LL, flag = 0;     cin >> n;     vector<pair<long long, long long> > arr(n);     vector<pair<long long, long long> > poss(n + 1);     for (long long i = 0; i < n; i++) {       cin >> arr[i].first >> arr[i].second;       if (arr[i].second == 2) flag = 1;     }     if (arr[0].second == 1) {       poss[0].first = 1900;       poss[0].second = 1000000007LL;     } else {       poss[0].first = -1000000007LL;       poss[0].second = 1899;     }     for (long long i = 1; i < n; i++) {       poss[i].first = poss[i - 1].first + arr[i - 1].first;       poss[i].second = poss[i - 1].second + arr[i - 1].first;       if (poss[i].first > poss[i].second) {         cout <<  Impossible ;         return 0;       }       if (arr[i].second == 1) {         poss[i].first = Max(poss[i].first, 1900);         if (poss[i].second < poss[i].first) {           cout <<  Impossible ;           return 0;         }       } else {         poss[i].second = Min(poss[i].second, 1899);         if (poss[i].second < poss[i].first) {           cout <<  Impossible ;           return 0;         }       }     }     poss[n].first = poss[n - 1].first + arr[n - 1].first;     poss[n].second = poss[n - 1].second + arr[n - 1].first;     if (poss[n].first > poss[n].second) {       cout <<  Impossible ;       return 0;     } else if (flag == 0) {       cout <<  Infinity ;     } else {       cout << poss[n].second;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long n, k, c, a, b, d;   multiset<unsigned long long> vn;   multiset<unsigned long long> vk;   unsigned long long mod = 1e9 + 7;   unsigned long long sum = 0;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> k >> c;     for (int i = 1; i <= n; i++) {       cin >> a >> b;       vn.insert(a), vk.insert(b);       d = c * (b - a);       sum = (sum + d) % mod;     }     multiset<unsigned long long>::iterator it;     while (vn.size() > 0 && vk.size() > 0) {       if (*vn.begin() <= *vk.begin()) {         sum = (k + sum) % mod;         vn.erase(vn.find(*vn.begin()));       } else {         if ((*vn.begin() - *vk.begin()) * c < k) {           int t;           for (it = vk.begin(); it != vk.end(); it++) {             if ((*it) >= *vn.begin()) break;             t = (*it);           }           sum = (sum + (*vn.begin() - t) * c) % mod;           vn.erase(vn.find(*vn.begin()));           vk.erase(vk.find(t));         } else {           vk.erase(*vk.begin());         }       }     }     cout << sum % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 10;   long long par[maxn], t[maxn], c[maxn];   const long long inf = 1000000000000ll;   long long dist[maxn][maxn], dis[maxn];   bool mark[maxn];   vector<int> v[maxn], u[maxn];   set<pair<long long, int> > s;   vector<long long> cost1[maxn], cost2[maxn];   int main() {     int n, m, x, y;     cin >> n >> m >> x >> y;     x--;     y--;     for (int i = 0; i < m; i++) {       int a, b, z;       cin >> a >> b >> z;       a--;       b--;       v[a].push_back(b);       v[b].push_back(a);       cost1[a].push_back(z);       cost1[b].push_back(z);     }     for (int i = 0; i < n; i++) {       cin >> t[i] >> c[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) dist[i][j] = inf;     }     for (int i = 0; i < n; i++) {       for (int k = 0; k < n; k++) mark[k] = 0;       dist[i][i] = 0;       s.insert(make_pair(0, i));       while (!s.empty()) {         int cur = s.begin()->second;         s.erase(s.begin());         mark[cur] = true;         for (int j = 0; j < v[cur].size(); j++) {           int next = v[cur][j];           if (mark[next] == true) continue;           long long ndist = dist[i][cur] + cost1[cur][j];           if (dist[i][next] > ndist) {             par[next] = cur;             s.erase(make_pair(dist[i][next], next));             dist[i][next] = min(ndist, dist[i][next]);             s.insert(make_pair(dist[i][next], next));           }         }       }     }     for (int i = 0; i < n; i++) mark[i] = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (dist[i][j] > 0 && dist[i][j] <= t[i]) {           u[i].push_back(j);           cost2[i].push_back(c[i]);         }       }     }     for (int i = 0; i < n; i++) dis[i] = inf;     dis[x] = 0;     s.insert(make_pair(0, x));     while (!s.empty()) {       int cur = s.begin()->second;       s.erase(s.begin());       mark[cur] = true;       for (int i = 0; i < u[cur].size(); i++) {         int next = u[cur][i];         if (mark[next] == true) continue;         long long ndist = dis[cur] + cost2[cur][i];         if (dis[next] > ndist) {           s.erase(make_pair(dis[next], next));           dis[next] = min(ndist, dis[next]);           s.insert(make_pair(dis[next], next));         }       }     }     if (mark[y] == true)       cout << dis[y];     else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int maxn = 1e5 + 5;   string s;   set<pair<int, int>> t;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> s;     int cnt = 0;     for (int i = (int)s.size() - 1; i >= 0; i--) {       if (s[i] ==  0 )         cnt++;       else {         if (cnt)           cnt--;         else           s[i] =  0 ;       }     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 50505;   const int LMAX = 1600505;   int N, A[NMAX];   vector<int> G[NMAX];   int currIdx;   unordered_map<int, int> allValues;   vector<int> newValues;   int L[NMAX];   bool mark[NMAX];   vector<int> R;   void read() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d , &A[i]);     }     for (int i = 1; i <= N; i++) {       G[i].reserve(30);     }   }   inline int bit(int idx) { return 1 << (idx - 1); }   inline bool hasBit(int mask, int idx) { return mask & bit(idx); }   void findCandidates(int x, int maxV, vector<int>& result) {     int fstBit;     for (int i = 30; i >= 1; i--) {       if (hasBit(x, i)) {         fstBit = i;         break;       }     }     int curr = 0;     for (int i = fstBit; i >= 1; i--) {       curr = (curr << 1) + hasBit(x, i);       if (curr > maxV) {         break;       }       result.push_back(curr);     }   }   void clearPrevIter() {     allValues.clear();     newValues.clear();     for (int i = 1; i <= N; i++) {       G[i].clear();     }     currIdx = N;   }   bool pairup(int x) {     mark[x] = true;     for (auto& y : G[x]) {       if (!R[y] || (!mark[R[y]] && pairup(R[y]))) {         L[x] = y;         R[y] = x;         return true;       }     }     return false;   }   bool canMatch() {     memset(L, 0, sizeof(L));     R.assign(currIdx + 1, 0);     bool improve = true;     int currMatches = 0;     while (improve) {       improve = false;       memset(mark, false, sizeof(mark));       for (int i = 1; i <= N; i++) {         if (!L[i] && pairup(i)) {           improve = true;           currMatches++;         }       }     }     return currMatches == N;   }   bool check(int maxV) {     vector<int> currCandidates;     currCandidates.reserve(30);     clearPrevIter();     for (int i = 1; i <= N; i++) {       currCandidates.clear();       findCandidates(A[i], maxV, currCandidates);       for (auto& cand : currCandidates) {         auto it = allValues.find(cand);         int matchIdx;         if (it == allValues.end()) {           allValues[cand] = ++currIdx;           newValues.push_back(cand);           matchIdx = currIdx;         } else {           matchIdx = it->second;         }         G[i].push_back(matchIdx);       }     }     return canMatch();   }   int bSearch() {     int i, step = (1 << 30);     for (i = 0; step; step >>= 1) {       if (!check(i + step)) {         i += step;       }     }     return ++i;   }   void solve() {     int maxElem = bSearch();     check(maxElem);     for (int i = 1; i <= N; i++) {       if (i > 1) {         printf(   );       }       printf( %d , newValues[L[i] - N - 1]);     }     printf(  n );   }   int main() {     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     ios::sync_with_stdio(false);     register int i;     register priority_queue<int> Queue;     register int N, T;     cin >> N >> T;     register int Ans;     Ans = 0;     for (i = 1; i <= N; i += 1) {       while (!Queue.empty() && Queue.top() >= T - i) {         Queue.pop();       }       register int X;       cin >> X;       if (max(X, i) < T) {         Queue.push(X - i);       }       Ans = max(Ans, (int)Queue.size());     }     cout << Ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double v[1000006], t[1000006];   int main() {     int n, i;     double a, d;     scanf( %d , &n);     scanf( %lf , &a);     scanf( %lf , &d);     for (i = 0; i < n; i++) {       scanf( %lf , &t[i]);       scanf( %lf , &v[i]);     }     double t0 = sqrt(2 * d / a);     double v0 = a * t0;     double prevt = -1, curt;     for (i = 0; i < n; i++) {       if (v[i] >= v0) {         curt = t[i] + t0;       } else {         double t1 = v[i] / a;         double d1 = 0.5 * a * t1 * t1;         double t2 = (d - d1) / v[i];         curt = t[i] + t1 + t2;       }       curt = max(curt, prevt);       printf( %.9lf n , curt);       prevt = curt;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool ch[30];   int whenlast[30];   char g[1000005];   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       scanf(  %c , &g[i]);       whenlast[g[i] -  A ] = i;     }     int rlt = 0, ans = 0;     for (int i = 0; i < n; i++) {       ch[g[i] -  A ] = true;       rlt = 0;       for (int p = 0; p < 30; p++)         if (ch[p]) rlt++;       ans = max(ans, rlt);       for (int x = 0; x < 30; x++)         if (whenlast[x] == i) ch[x] = false;     }     if (ans <= k)       puts( NO );     else       puts( YES );     return 0;   }


#include <bits/stdc++.h>   long long R = 7 + 1e9, NUMTESTCASE;   const int NN = 10 + 2e6;   const double pi = acos(-1.0);   int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1},       DI[8] = {1, 1, 0, -1, -1, -1, 0, 1}, DJ[8] = {0, 1, 1, 1, 0, -1, -1, -1};   using namespace std;   int n, ti = 1, timein[NN], timeout[NN], lev[NN], parn[NN], Hash[NN], m,          segtree[NN];   vector<int> G[NN];   void DFS(int ver, int par, int cnt) {     int in = ti++;     for (int u : G[ver])       if (u != par) DFS(u, ver, cnt + 1);     Hash[ver] = ++m;     lev[Hash[ver]] = cnt;     parn[Hash[ver]] = par;     timein[Hash[ver]] = in;     timeout[Hash[ver]] = ti++;   }   bool isgra(int ver, int par) {     return (timein[par] <= timein[ver] && timeout[par] >= timeout[ver]);   }   unordered_map<int, unordered_map<int, int> > memo;   int com_par(int u, int v) {     if (isgra(v, u)) return u;     if (isgra(u, v)) return v;     auto it1 = memo.find(u);     if (it1 != memo.end()) {       auto it2 = it1->second.find(v);       if (it2 != it1->second.end()) return it2->second;     }     return memo[u][v] = memo[v][u] = com_par(u, parn[v]);   }   void build(int pos, int st, int en) {     if (st == en) {       segtree[pos] = st;       return;     }     build(2 * pos, st, (st + en) / 2);     build(2 * pos + 1, (st + en) / 2 + 1, en);     segtree[pos] = com_par(segtree[2 * pos], segtree[2 * pos + 1]);   }   int seg_com_par(int pos, int st, int en, int u, int v) {     if (en < u || st > v) return -1;     if (st >= u && en <= v) return segtree[pos];     int flag1 = seg_com_par(2 * pos, st, (st + en) / 2, u, v);     int flag2 = seg_com_par(2 * pos + 1, (st + en) / 2 + 1, en, u, v);     int res;     if (flag1 != -1 && flag2 != -1)       res = com_par(flag1, flag2);     else if (flag1 != -1)       res = flag1;     else       res = flag2;     return res;   }   int dis(int v, int u) {     if (u > v) swap(u, v);     return lev[v] + lev[u] - 2 * lev[seg_com_par(1, 1, m, u, v)];   }   int main() {     cin >> n;     int u, v;     for (int i = (1); i <= (n - 1); ++i) {       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     DFS(1, -1, 0);     parn[Hash[1]] = 1;     for (int i = (1); i <= (n); ++i) parn[i] = Hash[parn[i]];     build(1, 1, m);     int x, y, a, b, k, q;     cin >> q;     while (q--) {       scanf( %d%d%d%d%d , &x, &y, &a, &b, &k);       x = Hash[x];       y = Hash[y];       a = Hash[a];       b = Hash[b];       int flag = 0, ab = dis(a, b), axyb = 1 + dis(a, x) + dis(y, b),           ayxb = 1 + dis(a, y) + dis(x, b);       if (ab % 2 == k % 2 && ab <= k) flag = 1;       if (axyb % 2 == k % 2 && axyb <= k) flag = 1;       if (ayxb % 2 == k % 2 && ayxb <= k) flag = 1;       printf(flag ?  YES n  :  NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int n, q;   int f[MAXN];   long long t[MAXN];   set<pair<long long, int> > seta[MAXN];   unordered_map<int, long long> child_profit[MAXN];   long long child_sum[MAXN];   set<pair<long long, int> > global_seta_min, global_seta_max;   long long minAns[MAXN];   long long maxAns[MAXN];   const long long inf = 1e18;   void init() {     for (int i = 1; i < n + 1; ++i) {       child_sum[i] = 0;     }   }   void preprocess() {     for (int i = 1; i < n + 1; ++i) {       long long aroundProfit = t[i] / (seta[i].size() + 2);       long long ownProfit = t[i] - (seta[i].size() + 1) * aroundProfit;       for (auto item : seta[i])         child_sum[i] += t[item.second] / (seta[item.second].size() + 2);       seta[f[i]].erase(make_pair(0, i));       child_profit[f[i]][i] = ownProfit + child_sum[i];       seta[f[i]].insert(make_pair(child_profit[f[i]][i], i));     }     for (int u = 1; u < n + 1; ++u) {       long long delta = t[u] / (seta[u].size() + 2);       minAns[u] = (seta[u].size() > 0) ? (seta[u].begin()->first + delta) : inf;       maxAns[u] = (seta[u].size() > 0) ? (seta[u].rbegin()->first + delta) : 0;       global_seta_min.insert(make_pair(minAns[u], u));       global_seta_max.insert(make_pair(maxAns[u], u));     }   }   void updateMinMax(int u) {     global_seta_min.erase(make_pair(minAns[u], u));     global_seta_max.erase(make_pair(maxAns[u], u));     long long delta = t[u] / (seta[u].size() + 2);     minAns[u] = (seta[u].size() > 0) ? seta[u].begin()->first + delta : inf;     maxAns[u] = (seta[u].size() > 0) ? seta[u].rbegin()->first + delta : 0;     global_seta_min.insert(make_pair(minAns[u], u));     global_seta_max.insert(make_pair(maxAns[u], u));   }   long long calcProfitWithoutParent(int u) {     return child_sum[u] + t[u] -            (seta[u].size() + 1) * (t[u] / (seta[u].size() + 2));   }   void solve() {     scanf( %d%d , &n, &q);     init();     for (int i = 1; i < n + 1; ++i) scanf( %I64d , &t[i]);     for (int i = 1; i < n + 1; ++i) {       scanf( %I64d , &f[i]);       seta[f[i]].insert(make_pair(0, i));       child_profit[f[i]][i] = 0;     }     preprocess();     long long profit;     int newF, oldF;     for (int i = 0; i < q; ++i) {       int type;       scanf( %d , &type);       switch (type) {         case 1:           int a, b;           scanf( %d%d , &a, &b);           oldF = f[a];           newF = b;           child_sum[oldF] -= t[a] / (seta[a].size() + 2);           child_sum[f[oldF]] -= t[oldF] / (seta[oldF].size() + 2);           seta[oldF].erase(make_pair(child_profit[oldF][a], a));           child_profit[oldF].erase(a);           child_sum[f[oldF]] += t[oldF] / (seta[oldF].size() + 2);           seta[f[f[oldF]]].erase(               make_pair(child_profit[f[f[oldF]]][f[oldF]], f[oldF]));           child_profit[f[f[oldF]]][f[oldF]] = calcProfitWithoutParent(f[oldF]);           seta[f[f[oldF]]].insert(               make_pair(child_profit[f[f[oldF]]][f[oldF]], f[oldF]));           seta[f[oldF]].erase(make_pair(child_profit[f[oldF]][oldF], oldF));           child_profit[f[oldF]][oldF] = calcProfitWithoutParent(oldF);           seta[f[oldF]].insert(make_pair(child_profit[f[oldF]][oldF], oldF));           updateMinMax(f[f[oldF]]);           updateMinMax(f[oldF]);           updateMinMax(oldF);           child_sum[newF] += t[a] / (seta[a].size() + 2);           child_sum[f[newF]] -= t[newF] / (seta[newF].size() + 2);           child_profit[newF].insert(make_pair(a, calcProfitWithoutParent(a)));           seta[newF].insert(make_pair(child_profit[newF][a], a));           child_sum[f[newF]] += t[newF] / (seta[newF].size() + 2);           seta[f[f[newF]]].erase(               make_pair(child_profit[f[f[newF]]][f[newF]], f[newF]));           child_profit[f[f[newF]]][f[newF]] = calcProfitWithoutParent(f[newF]);           seta[f[f[newF]]].insert(               make_pair(child_profit[f[f[newF]]][f[newF]], f[newF]));           seta[f[newF]].erase(make_pair(child_profit[f[newF]][newF], newF));           child_profit[f[newF]][newF] = calcProfitWithoutParent(newF);           seta[f[newF]].insert(make_pair(child_profit[f[newF]][newF], newF));           updateMinMax(f[f[newF]]);           updateMinMax(f[newF]);           updateMinMax(newF);           f[a] = newF;           break;         case 2:           int x;           scanf( %d , &x);           profit = t[x] - (seta[x].size() + 1) * (t[x] / (seta[x].size() + 2)) +                    child_sum[x] + t[f[x]] / (seta[f[x]].size() + 2);           printf( %I64d n , profit);           break;         case 3:           printf( %I64d %I64d n , global_seta_min.begin()->first,                  global_seta_max.rbegin()->first);           break;       }     }   }   int main() {     solve();     return 0;   }


#include <cmath>      #include <algorithm>   #include <iostream>   #include <string>   #include <vector>      using namespace std;      typedef long double ld;   typedef vector<int> vi;   typedef long long ll;      constexpr ld EPS = numeric_limits<ld>::epsilon();   constexpr int INF = numeric_limits<int>::max() - 10;   constexpr ll LINF = numeric_limits<ll>::max() - 10;      int w;   int h;   int n;      void input() {     cin >> w >> h >> n;   }      void solve() {     int alpha = (w & -w);     int beta = (h & -h);        string ans =  NO ;     if (alpha * beta >= n)       ans =  YES ;        cout << ans <<   n ;   }      int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);        cout.precision(16);     cout << fixed;        int _times = 1;      #ifdef _DEBUG     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   #endif        cin >> _times;        while (_times--) {       input();       solve();     }   }


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


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};   long long POW(long long x, long long y) {     long long ans = 1;     long long base = x;     while (y) {       if (y & 1) {         ans *= base;       }       base = base * base;       y = y >> 1;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, i, j, k, t, temp, tc;     cin >> tc;     while (tc--) {       cin >> n;       string a, b;       vector<long long> ans;       cin >> a >> b;       for (i = n - 1; i >= 0; i--) {         if (a[i] != b[i]) {           if (a[0] != b[i]) {             ans.push_back(i);           } else {             ans.push_back(0);             if (b[i] ==  1 ) {               a[0] =  0 ;             } else {               a[0] =  1 ;             }             ans.push_back(i);           }           for (j = 0; j <= i; j++) {             if (a[j] ==  1 ) {               a[j] =  0 ;             } else {               a[j] =  1 ;             }           }           long long lb = 0, ub = i;           while (lb < ub) {             auto ch = a[lb];             a[lb] = a[ub];             a[ub] = ch;             lb++;             ub--;           }         }       }       cout << ans.size() <<    ;       for (auto x : ans) {         cout << x + 1 <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inft = 1000000009;   const int MAXN = 400005, MAXM = MAXN;   int n;   vector<int> adj[MAXN];   int edgx[MAXM];   int cc;   int cycle[MAXM];   char used[MAXM];   int ep, sp, cur[MAXN], stackedge[MAXM];   void search(int v) {     sp = 0;     while (1) {       while (cur[v] != adj[v].size()) {         int e = adj[v][cur[v]++];         if (used[e]) continue;         used[e] = 1;         stackedge[sp++] = e;         v ^= edgx[e];       }       sp--;       if (sp < 0) break;       cycle[cc++] = stackedge[sp];       v ^= edgx[stackedge[sp]];     }   }   void search_all() {     for (int v = 0; v < (n); ++v) search(v);   }   void addedge(int a, int b) {     edgx[ep] = a ^ b;     adj[a].push_back(ep);     adj[b].push_back(ep);     ep++;   }   void clear() {     for (int i = 0; i < (n); ++i) adj[i].clear();     cc = 0;     ep = 0;     sp = 0;     for (int i = 0; i < (n); ++i) cur[i] = 0;   }   int X[MAXN], Y[MAXN];   char ANS[MAXN];   int main() {     int nn;     scanf( %d , &nn);     n = MAXN;     for (int i = 0; i < (nn); ++i) {       int a, b;       scanf( %d%d , &a, &b);       ++X[a];       ++Y[b];       addedge(a, b + MAXN / 2);     }     for (int i = 0; i < (MAXN / 2); ++i)       if (X[i] % 2) addedge(0, i);     for (int i = 0; i < (MAXN / 2); ++i)       if (Y[i] % 2) addedge(0, MAXN / 2 + i);     search_all();     for (int i = 0; i < (ep); ++i)       if (cycle[i] < nn) ANS[cycle[i]] = i % 2 ?  r  :  b ;     printf( %s n , ANS);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int b, w;     cin >> w >> b;     if (w == 0)       cout <<  0.000000000  << endl;     else if (b == 0)       cout <<  1.000000000  << endl;     else if (b == 1)       printf( %.9f n , double(w) / (w + 1));     else if (b == 2)       printf( %.9f n , double(w * (w + 1) + 2) / ((w + 1) * (w + 2)));     else {       double p[w + 1][b + 1];       if (b >= 2 * w) {         for (int col = b - 2 * w; col >= 0; col -= 3) p[0][col] = 0.0;         int startcol, endcol;         for (int row = 1; row <= w; row++) {           startcol = (b + w - row) % 3;           endcol = b - 2 * (w - row);           if (startcol == 0)             p[row][startcol] = 1.0;           else if (startcol == 1)             p[row][startcol] = double(row) / (row + 1);           else             p[row][startcol] =                 double(row * (row + 1) + 2) / ((row + 1) * (row + 2));           for (int col = startcol + 3; col <= endcol; col += 3) {             p[row][col] =                 double(row) / (row + col) +                 (p[row][col - 3] * (col - 2) + p[row - 1][col - 2] * row) * col *                     (col - 1) / (row + col) / (row + col - 1) / (row + col - 2);           }         }       } else {         int startcol, endcol;         int firstrow = w - b / 2;         for (int row = firstrow; row <= w; row++) {           startcol = (b + w - row) % 3;           endcol = b - 2 * (w - row);           if (startcol == 0)             p[row][startcol] = 1.0;           else if (startcol == 1)             p[row][startcol] = double(row) / (row + 1);           else             p[row][startcol] =                 double(row * (row + 1) + 2) / ((row + 1) * (row + 2));           for (int col = startcol + 3; col <= endcol; col += 3) {             p[row][col] =                 double(row) / (row + col) +                 (p[row][col - 3] * (col - 2) + p[row - 1][col - 2] * row) * col *                     (col - 1) / (row + col) / (row + col - 1) / (row + col - 2);           }         }       }       printf( %.9f n , p[w][b]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> s[100010];   bool flag[100010];   long double ans;   void dfs(int now, int deep) {     ans += 1.0 / (deep * 1.0);     flag[now] = false;     for (int i = 0; i < s[now].size(); i++) {       int next = s[now][i];       if (flag[next]) dfs(next, deep + 1);     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       s[x].push_back(y);       s[y].push_back(x);     }     memset(flag, true, sizeof(flag));     ans = 0;     dfs(1, 1);     cout << fixed << setprecision(6) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, t, m;   int vi[200010];   vector<int> v[200010];   map<int, int> mp;   int main() {     long long int a, b, c, r, l = 0, tt;     cin >> r >> a >> b >> c;     if ((b - c) <= a) {       if (r >= b) {         tt = (long long int)((double)(r - b) / (double)(b - c));         t = tt++;         if (t == tt) {           t++;         }         r = r - t * (b - c);         l = l + t;         while (r >= b) {           r = r - (b - c);           l++;         }       }       if (r >= a) {         t = r / a;         r = r - t * a;         l = l + t;       }     } else {       if (r >= a) {         t = r / a;         r = r - t * a;         l = l + t;       }       if (r >= b) {         tt = (long long int)((double)(r - b) / (double)(b - c));         t = tt++;         if (t == tt) {           t++;         }         r = r - t * (b - c);         l = l + t;         while (r >= b) {           r = r - (b - c);           l++;         }       }     }     cout << l << endl;     return 0;   }


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