#include <bits/stdc++.h>   #include <iostream>   using namespace std;      #define db cout <<  debugging... n ;   #define db1(x) cout << #x <<   =   << x <<   n    #define db2(x, y) cout << #x <<   =   << x <<  ,   << #y <<   =   <<y <<   n    #define db3(x, y, z) cout << #x <<   =   << x <<  ,   << #y <<   =   << y <<  ,   << #z <<   =   << z <<   n    #define dbvec(a) cout << #a <<  :  ; for (auto x: a) cout << x <<    ; cout <<   n       #define int long long   #define pb push_back   #define all(x) x.begin(), x.end()   #define endl   n    #define fileio freopen( input.txt ,  r , stdin); freopen( output.txt ,  w , stdout)   #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)   const int MOD = 1000000007;      int32_t main() {       fastio;       // fileio;          int t;       cin >> t;          while (t--) {              int n;           cin >> n;              bool b = true;              for (int i = 0; i < n; ++i) {               int x;               cin >> x;                  // db3(t, n, x);                  int sqrtt = sqrt(x);               sqrtt *= sqrtt;                  if (sqrtt != x) {                   b = false;               }           }              if (b) {               cout <<  NO n ;           } else {               cout <<  YES n ;           }          }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int dx[] = {0, 0, -1, 1};   int dy[] = {1, -1, 0, 0};   char s[100002];   void Print(long long x) {     printf( %lld n , x);     exit(0);   }   bool ok(long long x1, long long y1, long long x2, long long y2, long long day) {     return (abs(x2 - x1) + abs(y2 - y1) <= day);   }   long long bs(long long addX, long long addY, int n, long long x1, long long y1,                long long x2, long long y2) {     long long i = 0, p = 1LL << 31;     while (p) {       if (i + p &&           !ok(x1 + addX * (i + p), y1 + addY * (i + p), x2, y2, (i + p) * n))         i += p;       p >>= 1;     }     return i;   }   int main() {     long long x1, y1, x2, y2;     int n;     scanf( %lld%lld%lld%lld%d n%s , &x1, &y1, &x2, &y2, &n, &s);     long long addX = 0, addY = 0;     for (int i = 0; i < n; ++i) {       int d;       if (s[i] ==  U )         d = 0;       else if (s[i] ==  D )         d = 1;       else if (s[i] ==  L )         d = 2;       else if (s[i] ==  R )         d = 3;       addX += dx[d];       addY += dy[d];       if (abs(x2 - x1 - addX) + abs(y2 - y1 - addY) <= (i + 1)) Print(i + 1);     }     long long cnt = bs(addX, addY, n, x1, y1, x2, y2);     if (cnt > 1) --cnt;     x1 += cnt * addX;     y1 += cnt * addY;     long long day = cnt * n;     for (int t = 0; t < 20; ++t) {       for (int i = 0; i < n; ++i) {         int d;         ++day;         if (s[i] ==  U )           d = 0;         else if (s[i] ==  D )           d = 1;         else if (s[i] ==  L )           d = 2;         else if (s[i] ==  R )           d = 3;         x1 += dx[d];         y1 += dy[d];         if (abs(x2 - x1) + abs(y2 - y1) <= day) Print(day);       }     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int recur_depth = 0;   const long long sz = 14, isz = 2e6 + 10, mod = 1e9 + 7;   long long p[sz], win[sz][sz], scc[(1 << sz)], n;   long long fastPow(long long x, long long n, long long MOD) {     long long ret = 1;     while (n) {       if (n & 1) ret = (ret * x) % MOD;       x = (x * x) % MOD;       n >>= 1;     }     return ret % MOD;   }   inline long long inv(long long x) { return fastPow(x, mod - 2, mod); }   long long prob(long long from, long long to) {     long long ret = 1;     for (long long i = 0; i < n; ++i) {       for (long long j = 0; j < n; ++j) {         if ((from >> i & 1) && (to >> j & 1)) ret = (ret * win[i][j]) % mod;       }     }     return ret;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n;     for (long long i = 0; i < n; ++i) cin >> p[i];     for (long long i = 0; i < n; ++i)       for (long long j = 0; j < n; ++j)         win[i][j] = (p[i] * inv(p[i] + p[j])) % mod;     long long ans = 0, lim = (1 << n) - 1;     for (int mask = 0; mask <= lim; mask++) {       scc[mask] = 1;       for (int i = mask; i > 0; i = (i - 1) & mask) {         if (i == mask) continue;         scc[mask] -= (scc[i] * prob(i, mask ^ i)) % mod;         if (scc[mask] < 0) scc[mask] += mod;       }       long long win_prob = (scc[mask] * __builtin_popcount(mask)) % mod;       win_prob = (win_prob * prob(mask, lim ^ mask)) % mod;       ans += win_prob;       if (ans >= mod) ans -= mod;     }     cout << ans <<   n ;     return 0;   }


#include <algorithm>   #include <array>   #include <bitset>   #include <cctype>   #include <chrono>   #include <cmath>   #include <ctime>   #include <deque>   #include <fstream>   #include <functional>   #include <iomanip>   #include <iostream>   #include <iso646.h>   #include <iterator>   #include <list>   #include <map>   #include <memory>   #include <numeric>   /*                           mnciitbhu                        */   //   //  |    /| |    |    --  |  |  -------  |⎻⎻   |   |  |    |   //  |   / | |    |   /    |  |     |     |   |  |   |  |    |   //  |   /  | |    |  (     |  |     |     |--<   |---|  |    |   //  |      | |    |       |  |     |     |   |  |   |     /   //  |      | |     |    --  |  |     |     |__/   |   |    --   //   #include <queue>   #include <ratio>   #include <regex>   #include <set>   #include <sstream>   #include <stack>   #include <string>   #include <type_traits>   #include <unordered_map>   #include <unordered_set>   #include <utility>   #include <valarray>   #include <vector>   using namespace std;   using namespace std::chrono;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   #if not defined(ONLINE_JUDGE) && not defined(_MSVC_LANG) && defined(DEBUG_)   #include  myconfig.hpp    #else   #define LOL(x) ;   #define LOLX(...) ;   #endif   #if not defined(DEBUG_)   #endif      int main()    {    ios::sync_with_stdio(false);    cin.tie(0);       string s;    cin >> s;    if(s.length() == 1)    {     cout << s;     return 0;    }    for(int i = 0; i < s.size() - 1; ++i)    {     if(i < s.size() - 2 and s[i] == s[i + 1] and s[i] == s[i + 2])     {      if(s[i] ==  z )       s[i + 1] =  a ;      else       s[i + 1] =  z ;     }     else if(s[i] == s[i + 1])     {      if(i != 0)       {       if(s[i - 1] !=  d  and s[i + 1] !=  d )        s[i] =  d ;       else if(s[i - 1] !=  e  and s[i + 1] !=  e )        s[i] =  e ;       else        s[i] =  f ;      }      else      {       if(s[i + 1] ==  d )        s[i] =  e ;       else        s[i] =  d ;      }     }    }    cout << s;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int>> v;     for (int i = 0; i < n; i++) {       int l, r;       cin >> r >> l;       v.push_back(make_pair(l, r));     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     int len = v.size();     long long k = 1, sum = 0, i = 0;     while (k--) {       sum += v[i].second;       k += v[i].first;       i++;       if (i == len) break;     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16000000 )   using namespace std;   long long mod = 998244353;   long double inf = 1e9;   long double eps = 1e-8;   long double pi = acos(-1);   ifstream in( input.txt );   ofstream out( output.txt );   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     string s;     cin >> s;     if (k == 0) {       cout << s;     } else {       if (s.size() == 1) {         cout << 0;         return 0;       }       if (s[0] !=  1 ) {         s[0] =  1 ;         k--;       }       for (int i = 1; i < n; i++) {         if (k == 0) break;         if (s[i] !=  0 ) {           s[i] =  0 ;           k--;         }       }       cout << s;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 101010;   int a[N];   int b[N];   int c[N];   int n;   long long ans;   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %1d , a + i);       c[i] = a[i];     }     for (int i = 1; i <= n; i++) {       scanf( %1d , b + i);     }     for (int i = 1; i < n; i++) {       int delta = c[i] - b[i];       c[i] -= delta;       c[i + 1] -= delta;       ans += abs(delta);     }   }   void check(int now, int add) {     if (ans == 0) return;     if (0 <= a[now + 1] + add && a[now + 1] + add <= 9) {       printf( %d %d n , now, add);       a[now] += add;       a[now + 1] += add;       ans--;       return;     }     check(now + 1, -add);     if (ans == 0) return;     printf( %d %d n , now, add);     a[now] += add;     a[now + 1] += add;     ans--;   }   void work() {     printf( %lld n , ans);     if (ans > 100000) ans = 100000;     for (int i = 1; i < n && ans > 0; i++)       while (a[i] != b[i] && ans) check(i, (b[i] > a[i]) ? 1 : -1);   }   int main() {     init();     if (c[n] == b[n])       work();     else       printf( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   class cmp {    public:     bool operator()(const pair<long long int, long long int> &a,                     const pair<long long int, long long int> &b) {       if (a.first == b.first) return a.second > b.second;       return a.first < b.first;     }   };   long long int a[N], b[N], fact[N];   long long int mod = 998244353;   void cal() {     fact[1] = 1;     for (long long int i = 2; i < N; i++) {       fact[i] = ((fact[i - 1] % mod) * (i % mod)) % mod;     }   }   bool sort1(const pair<long long int, long long int> &x,              const pair<long long int, long long int> &y) {     if (x.first == y.first) return x.second < y.second;     return x.first < y.first;   }   void solve() {     long long int n;     cin >> n;     cal();     memset(a, 0, sizeof(a));     memset(b, 0, sizeof(b));     long long int i, x, y, f = 0;     vector<pair<long long int, long long int>> v;     for (i = 0; i < n; i++) {       cin >> x >> y;       a[x]++;       b[y]++;       v.push_back({x, y});       if (a[x] == n || b[y] == n) f = 1;     }     if (f) {       cout <<  0  << endl;       return;     }     long long int ans = fact[n];     long long int ans1 = 1;     for (i = 1; i < N; i++) {       if (a[i]) {         long long int cnt = fact[a[i]];         ans1 = ((ans1 % mod) * (cnt % mod)) % mod;       }     }     ans = (ans - ans1 + mod) % mod;     long long int ans2 = 1;     for (i = 1; i < N; i++) {       if (b[i]) {         long long int cnt = fact[b[i]];         ans2 = ((ans2 % mod) * (cnt % mod)) % mod;       }     }     ans = (ans - ans2 + mod) % mod;     sort(v.begin(), v.end(), sort1);     long long int k = 0;     for (i = 0; i < n - 1; i++) {       if (v[i].second > v[i + 1].second) {         k = 1;         break;       }     }     if (k == 0) {       ans1 = 1;       for (i = 0; i < n;) {         long long int j = i;         long long int cnt = 0;         while (j < n && v[i].first == v[j].first && v[i].second == v[j].second) {           j++;           cnt++;         }         i = j;         cnt = fact[cnt];         ans1 = ((ans1 % mod) * (cnt % mod)) % mod;       }       ans = (ans + ans1) % mod;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100009], c[100009], b[100009], d[100009];   long long ksm(long long a, long long n, long long d) {     long long ans;     ans = 1;     while (n > 0) {       if (n % 2 == 1) ans = (ans * a) % d;       a = a * a % d;       n = n / 2;     }     return ans % d;   }   long long ksm2(long long a, long long n) {     long long ans;     ans = 1;     while (n > 0) {       if (n % 2 == 1) {         if (a > 1e5) return 0;         ans = ans * a;       }       if (ans > 1e5) return 0;       if (a > 1e5) return 0;       a = a * a;       n = n / 2;     }     return ans;   }   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       c[i] = 1;       b[i] = 1;       int gg = a[i];       for (int j = 2; j <= sqrt(gg); j++)         if (a[i] % j == 0) {           int g = 0;           while (a[i] % j == 0) {             g++;             a[i] /= j;           }           g = g % k;           b[i] *= ksm(j, g, 1e18 + 9);           c[i] *= ksm2(j, (k - g) % k);         }       if (a[i] != 1) {         b[i] *= a[i];         c[i] *= ksm2(a[i], k - 1);       }       d[b[i]]++;     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (c[i] != 0) {         ans += d[c[i]];         if (c[i] == b[i]) ans--;       }     }     ans /= 2;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   long long s1[N], s2[N];   int p, q, n, b[N], d[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &s1[i]), s1[i] += s1[i - 1];     for (int i = 1; i <= n; i++) scanf( %I64d , &s2[i]), s2[i] += s2[i - 1];     for (int i = 0; i <= n; i++) {       while (s1[i] > s2[p] && p <= n) p++;       if (s1[i] <= s2[p] && b[s2[p] - s1[i]]) {         q = b[s2[p] - s1[i]] - 1;         printf( %d n , i - q);         for (int j = q + 1; j <= i; j++) printf( %d  , j);         q = d[s2[p] - s1[i]];         putchar(  n );         printf( %d n , p - q);         for (int j = q + 1; j <= p; j++) printf( %d  , j);         return 0;       } else         b[s2[p] - s1[i]] = i + 1, d[s2[p] - s1[i]] = p;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const int len = 700, MAX = 1e7 + 10;   int n, m, k, a[maxn];   int f[MAX], g[MAX];   long long ans[maxn];   struct query {     int l, r, id;   } q[maxn];   bool operator<(const query &a, const query &b) {     if ((a.l - 1) / len != (b.l - 1) / len) return a.l < b.l;     return a.r < b.r;   }   void enter() {     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= m; ++i) {       cin >> q[i].l >> q[i].r;       q[i].id = i;     }     sort(q + 1, q + m + 1);   }   int lim(int i) { return ((i - 1) / len + 1) * len; }   void solve() {     long long ret = 0;     int rgt = 0, it, cur = 0;     g[0] = 1;     for (int i = 1; i <= m; ++i) {       if (rgt < lim(q[i].l)) {         rgt = lim(q[i].l);         it = rgt + 1;         memset(f, 0, sizeof(f));         f[0] = 1;         cur = 0;         ret = 0;       }       if (q[i].r <= rgt) {         long long tmp = 0;         for (int j = q[i].l, v = 0; j <= q[i].r; ++j) {           v ^= a[j];           tmp += g[v ^ k];           ++g[v];         }         ans[q[i].id] = tmp;         for (int j = q[i].l, v = 0; j <= q[i].r; ++j) {           v ^= a[j];           --g[v];         }         continue;       }       while (it <= q[i].r) {         cur ^= a[it++];         ret += f[cur ^ k];         ++f[cur];       }       long long save = ret;       --f[0];       for (int j = rgt, v = 0; j >= q[i].l; --j) {         v ^= a[j];         ret += f[v ^ k];         ret += g[v ^ k];         ++g[v];       }       ++f[0];       ans[q[i].id] = ret;       for (int j = rgt, v = 0; j >= q[i].l; --j) {         v ^= a[j];         --g[v];       }       ret = save;     }   }   int main() {     ios_base ::sync_with_stdio(0);     enter();     solve();     for (int i = 1; i <= m; ++i) printf( %I64d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   bool G[30][30];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, p;       scanf( %d%d , &n, &p);       memset(G, 0, sizeof(G));       for (int i = 0; i < n; ++i)         G[i][(i + 1) % n] = G[(i + 1) % n][i] = G[i][(i + 2) % n] =             G[(i + 2) % n][i] = 1;       for (int step = 3; p; ++step) {         for (int i = 0; p && i < n; ++i) {           G[i][(i + step) % n] = G[(i + step) % n][i] = 1;           --p;         }       }       for (int i = 0; i < n; ++i)         for (int j = i + 1; j < n; ++j)           if (G[i][j]) printf( %d %d n , i + 1, j + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, lg = 20, N = 1e5 + 5;   int ans[N];   bool vis[N];   vector<pair<int, int> > g[N];   struct node {     node *ch[11];     node *sp[lg];     int val, lvl, last;     node() {       memset(ch, 0, sizeof ch);       memset(sp, 0, sizeof sp);       val = lvl = last = 0;     }   };   struct cmp {     bool operator()(const pair<node *, int> a, const pair<node *, int> b) const {       if (b.first->lvl != a.first->lvl) return a.first->lvl < b.first->lvl;       node *u = (node *)b.first;       node *v = (node *)a.first;       for (int i = lg - 1; i >= 0; i--) {         if (u->sp[i] != v->sp[i]) {           u = u->sp[i];           v = v->sp[i];         }       }       if (v->last != u->last) return v->last < u->last;       return a.second < b.second;     }   };   vector<int> digits[N];   void build() {     for (int i = 1; i < N; i++) {       int j = i;       while (j) digits[i].push_back(j % 10), j /= 10;       reverse(digits[i].begin(), digits[i].end());     }   }   void build(node *a) {     for (int i = 1; i < lg; i++) {       a->sp[i] = a->sp[i - 1]->sp[i - 1];     }   }   void dij() {     node *root = new node();     root->sp[0] = root;     build(root);     set<pair<node *, int>, cmp> st;     st.insert({root, 1});     while (st.size()) {       node *cur = (*st.begin()).first;       int temp = (*st.begin()).second;       st.erase(st.begin());       if (vis[temp] == 0) {         vis[temp] = 1;         ans[temp] = cur->val;       } else         continue;       for (int i = 0; i < g[temp].size(); i++) {         int v = g[temp][i].first;         int cost = g[temp][i].second;         node *temp = cur;         for (auto dig : digits[cost]) {           if (!temp->ch[dig]) {             temp->ch[dig] = new node();             temp->ch[dig]->lvl = temp->lvl + 1;             temp->ch[dig]->val = ((temp->val * 1ll * 10) % mod + dig) % mod;             temp->ch[dig]->sp[0] = temp;             temp->ch[dig]->last = dig;             build(temp->ch[dig]);           }           temp = temp->ch[dig];         }         st.insert({temp, v});       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     build();     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       g[u].push_back({v, i});       g[v].push_back({u, i});     }     dij();     for (int i = 2; i <= n; i++) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma comment(linker,  /stack:200000000 )   using namespace std;   const int mnx = 3e5 + 9;   const int mod = 1e9 + 7;   const long long inf = 1e15 + 4;   long long binpow(long long a, int n) {     long long res = 1;     while (n) {       if (n & 1) res = (res * a) % mod;       a = (a * a) % mod;       n >>= 1;     }     return res % mod;   }   long long fact[mnx], rev[mnx];   void pre() {     fact[0] = rev[0] = 1;     for (int i = 1; i <= 1e5; i++) {       fact[i] = fact[i - 1] * i % mod;       rev[i] = binpow(fact[i], mod - 2) % mod;     }   }   long long cnk(int n, int k) {     if (n < k) return 0;     return (fact[n] * rev[k] % mod) * rev[n - k] % mod;   }   long long n, m, k;   void solve() {     cin >> n >> m >> k;     pre();     cout << cnk(m - 1, k * 2) * cnk(n - 1, k * 2) % mod <<   n ;   }   int main() {     int tt = 1;     while (tt--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  or c >  9 ) {       if (c ==  - ) f = -f;       c = getchar();     }     while (c >=  0  and c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   struct EDGE {     int to, Next;   } edge[400100];   struct DOTS {     long long cnt, num[2], all, sum, dpth;     vector<int> sons;   } dot[200100];   int n;   int h[200100], cnt;   long long ans;   bool vis[200100];   void add(int from, int to) {     edge[++cnt].to = to;     edge[cnt].Next = h[from];     h[from] = cnt;   }   void dfs(int t) {     vis[t] = 1;     dot[t].num[0]++;     for (int i = h[t]; i; i = edge[i].Next) {       int v = edge[i].to;       if (!vis[v]) {         dot[t].cnt++;         dot[t].sons.push_back(v);         dot[v].dpth = dot[t].dpth + 1;         dfs(v);         ans += dot[t].num[0] * dot[v].num[1] * 2 * dot[t].sum;         ans %= 1000000007;         ans -= dot[t].num[1] * dot[v].num[0] * 2 * dot[t].sum;         ans %= 1000000007;         dot[t].num[0] += dot[v].num[1];         dot[t].num[1] += dot[v].num[0];       }     }     ans += dot[t].sum;   }   void dp(int t) {     for (int i = 0; i < dot[t].cnt; ++i) {       int v = dot[t].sons[i];       ans += dot[v].num[0] * (dot[1].num[dot[v].dpth & 1] - dot[v].num[0]) * 2 *              dot[v].sum;       ans %= 1000000007;       ans -= dot[v].num[1] * (dot[1].num[(dot[v].dpth ^ 1) & 1] - dot[v].num[1]) *              2 * dot[v].sum;       ans %= 1000000007;       dp(v);     }   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) dot[i].sum = read();     for (int i = 1; i < n; ++i) {       int u = read();       int v = read();       add(u, v);       add(v, u);     }     dfs(1);     dp(1);     ans %= 1000000007;     ans += 1000000007;     ans %= 1000000007;     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, count = 0;     cin >> n >> m;     char x;     vector<int> r, c;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> x;         if (x ==  S ) {           r.push_back(i);           c.push_back(j);         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if ((find(r.begin(), r.end(), i) != r.end()) &&             (std::find(c.begin(), c.end(), j) != c.end())) {           continue;         } else {           count++;         }       }     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[11] = {0}, i, maxx, c;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       if (i == 1)         maxx = a[1];       else         maxx = max(a[i], maxx);     }     printf( %d , maxx ^ a[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans, temp;   set<int> st;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     cin >> n >> m;     ans = n + m;     temp = 2;     while (n) {       n -= (temp % 6 != 0);       st.insert(temp);       temp += 2;     }     temp = 3;     while (m) {       m -= (temp % 6 != 0);       st.insert(temp);       temp += 3;     }     for (auto i : st) {       ans--;       if (!ans) return cout << i <<   n , 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int p = 1000 * 1000 * 1000 + 7;   int main() {     int n, m;     vector<long long> fact(1000001);     fact[0] = 1;     for (int i = 1; i < 1000001; i++) fact[i] = (i * fact[i - 1]) % p;     cin >> n >> m;     vector<pair<int, int>> v(m);     for (int i = 0; i < n; i++) {       int k;       cin >> k;       for (int j = 0; j < k; j++) {         int l;         cin >> l;         l--;         v[l].first *= p;         v[l].first += i + 1;         v[l].second *= 2348621;         v[l].second += i + 1;       }     }     map<pair<int, int>, int> f;     for (int i = 0; i < m; i++) f[v[i]]++;     long long ans = 1;     for (map<pair<int, int>, int>::iterator a = f.begin(); a != f.end(); a++)       ans = (fact[(*a).second] * ans) % p;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   string arr[10] = { 0 ,  0 ,  2 ,  3 ,  322 ,  5 ,  53 ,  7 ,  7222 ,  7332 };   int main() {     int x;     cin >> x;     char a[x];     string s;     for (int i = 0; i < x; i++) {       cin >> a[i];       if (a[i] !=  0  && a[i] !=  1 ) s += arr[a[i] -  0 ];     }     sort(s.rbegin(), s.rend());     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, pair<long long, long long> > > edges;   vector<long long> wt(100005);   long long sz[100005], parent[100005];   long long ans = 0;   long long n, m;   void make_set() {     for (long long i = 1; i <= n; i++) {       sz[i] = 1;       parent[i] = i;     }   }   long long findParent(long long x) {     if (x == parent[x]) return x;     return findParent(parent[x]);   }   void merge_sets(long long x, long long y, long long w) {     x = findParent(x);     y = findParent(y);     if (x == y) return;     ans += w * sz[x] * sz[y];     if (sz[x] > sz[y]) {       parent[y] = x;       sz[x] += sz[y];     } else {       parent[x] = y;       sz[y] += sz[x];     }   }   int main() {     cin >> n >> m;     for (long long i = 1; i <= n; i++) cin >> wt[i];     for (long long i = 1; i <= m; i++) {       long long x, y;       cin >> x >> y;       edges.push_back(make_pair(min(wt[x], wt[y]), make_pair(x, y)));     }     sort(edges.begin(), edges.end());     reverse(edges.begin(), edges.end());     make_set();     for (long long i = 0; i < m; i++) {       merge_sets(edges[i].second.first, edges[i].second.second, edges[i].first);     }     double anss = (double)ans;     anss /= (double)n;     anss /= (double)(n - 1);     anss *= 2.00;     cout << fixed << setprecision(10) << anss << endl;     return 0;   }


#include <bits/stdc++.h>   const int P = (1 << 30) - 1;   int a, b, c, p[2005], vis[2005];   std::unordered_map<long long, int> mmp[2005];   void sieve(int n) {     vis[0] = vis[1] = 1;     for (int i = 2; i <= n; ++i) {       if (!vis[i]) p[++*p] = i;       for (int j = 1; j <= *p && i * p[j] <= n; ++j) {         vis[i * p[j]] = 1;         if (i % p[j] == 0) break;       }     }   }   int dp(int kk1, int kk2, int kk3, int pid) {     if (pid == 0) return 1;     long long ha = 1ll * kk1 * (a + 1) * (a + 1) + 1ll * kk2 * (a + 1) + kk3;     if (mmp[pid].count(ha)) return mmp[pid][ha];     int ans = 0;     int k1 = 1, k2 = 1, k3 = 1, k4 = 0;     while (k1 <= kk1) {       k2 = 1;       int k5 = 0;       while (k2 <= kk2) {         k3 = 1;         int k6 = 0;         while (k3 <= kk3) {           (ans +=            1ll * dp(kk1 / k1, kk2 / k2, kk3 / k3, pid - 1) * (k4 + k5 + k6 + 1) &            P) &= P;           k3 *= p[pid], ++k6;         }         k2 *= p[pid], ++k5;       }       k1 *= p[pid], ++k4;     }     return mmp[pid][ha] = ans;   }   int main() {     scanf( %d%d%d , &a, &b, &c);     if (a < b) a ^= b ^= a ^= b;     if (a < c) a ^= c ^= a ^= c;     sieve(a);     printf( %d n , dp(a, b, c, *p));     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast , 3,  inline )   using namespace std;   string s, t;   int n;   void pairr() {     if (cin >> t) {       s += t;       if (t ==  pair ) s +=  < , pairr(), s +=  , , pairr(), s +=  > ;     } else {       cout <<  Error occurred ;       exit(0);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     pairr();     if (cin >> t) {       cout <<  Error occurred ;       return 0;     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int m, ch[1002];   int gt(int bal, int prv, int st) {     if (st == m) return ch[st] = 11;     if (bal <= 0) {       for (int i = 1; i <= 10; i++) {         if (i != prv && s[i] ==  1  && bal + i > 0) {           int t = gt(bal + i, i, st + 1);           if (t) return ch[st] = i;         }       }       return 0;     }     for (int i = 1; i <= 10; i++) {       if (i != prv && s[i] ==  1  && bal - i < 0) {         int t = gt(bal - i, i, st + 1);         if (t) return ch[st] = i;       }     }     return 0;   }   int main() {     memset(ch, -1, sizeof(ch));     cin >> s >> m;     s =     + s;     int to = gt(0, 0, 0);     if (ch[0] == -1)       cout <<  NO ;     else {       int k = 0;       cout <<  YES n ;       while (k < m) {         cout << ch[k] <<    ;         k++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       char arr[] = { a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i ,                      j ,  k ,  l ,  m ,  n ,  o ,  p ,  q ,  r ,                      s ,  t ,  u ,  v ,  w ,  x ,  y ,  z };       int i = 0;       while (n--) {         cout << arr[i];         i++;         if (i == k) {           i = 0;         }       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long s[200005], e[200005];   long long win(long long s, long long e) {     if (e & 1) {       if (s & 1) return 0;       return 1;     }     if (s > e / 2) {       if (s & 1) return 1;       return 0;     }     if (s > e / 4) return 1;     return win(s, e >> 2);   }   long long lose(long long s, long long e) {     if (s > e / 2) return 1;     return win(s, e >> 1);   }   int main() {     long long i, n, j, k, t, m, w, l, cur = 0;     scanf( %lld , &t);     for (i = 1; i <= t; i++) scanf( %lld%lld , &s[i], &e[i]);     for (i = 1; i <= t; i++) {       w = win(s[i], e[i]);       l = lose(s[i], e[i]);       w ^= cur;       l ^= cur;       if (w == l) break;       if (w)         cur = 1;       else         cur = 0;     }     printf( %lld %lld n , w, l);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(0);     long long n, m;     cin >> n >> m;     vector<long long> a, b;     vector<long long> sum1, sum2;     long long prev = 0;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       prev += x;       a.push_back(x);       sum1.push_back(prev);     }     prev = 0;     for (int i = 0; i < m; i++) {       long long x;       cin >> x;       prev += x;       b.push_back(x);       sum2.push_back(prev);     }     long long z;     cin >> z;     vector<long long> dp1, dp2;     for (int l = 1; l <= n; l++) {       long long mini = sum1[l - 1];       for (int i = l; i < sum1.size(); i++) {         mini = min(sum1[i] - sum1[i - l], mini);       }       dp1.push_back(mini);     }     for (int l = 1; l <= m; l++) {       long long mini = sum2[l - 1];       for (int i = l; i < sum2.size(); i++) {         mini = min(sum2[i] - sum2[i - l], mini);       }       dp2.push_back(mini);     }     long long prod = 0;     for (long long i = 0; i < dp1.size(); i++) {       for (long long j = 0; j < dp2.size(); j++) {         if (dp1[i] * dp2[j] <= z) {           prod = max((i + 1) * (j + 1), prod);         }       }     }     cout << prod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)(1e2 + 5);   int n, m, k;   int grid[N][N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> k;     for (int(i) = (1); (i) <= (n); (i)++)       for (int(j) = (1); (j) <= (m); (j)++) cin >> grid[i][j];     int score = 0, updates = 0;     for (int(j) = (1); (j) <= (m); (j)++) {       int col_score = 0;       int col_update = 0;       int update = 0;       for (int(i) = (1); (i) <= (n); (i)++) {         if (i - 1 >= 1) update += grid[i - 1][j];         if (grid[i][j] == 1) {           int temp_score = 0;           for (int q = i; q < i + k && q <= n; q++) temp_score += grid[q][j];           if (temp_score > col_score) {             col_score = temp_score;             col_update = update;           }         }       }       score += col_score;       updates += col_update;     }     cout << score <<     << updates;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   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;     }   };   const long long MOD = 1e9 + 7;   const long long N = 1e6 + 10;   const long long INF = 1e18 + 10;   bool isPrime(long long x) {     if (x <= 1) return false;     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) return false;     }     return true;   }   vector<bool> prime(N, true);   vector<long long> primes;   void seive() {     prime[0] = prime[1] = false;     for (long long i = 2; i * i <= N; i++) {       if (prime[i]) {         for (long long j = i + i; j < N; j += i) prime[j] = false;       }     }     for (long long i = 0; i < N; i++) {       if (prime[i]) {         primes.emplace_back(i);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     seive();     long long n;     cin >> n;     if (isPrime(n)) {       cout << 1 << endl;       cout << n << endl;       return 0;     }     long long cur = n;     while (cur--) {       if (isPrime(cur)) {         debug() <<   [                  <<  cur                      :                   << (cur) <<  ]  ;         if (cur + 2 == n) {           cout << 2 << endl;           cout << 2 <<     << cur << endl;           return 0;         }         int target = n - cur;         debug() <<   [                  <<  target                      :                   << (target) <<  ]  ;         int L = 0, R = (int)primes.size() - 1;         while (L <= R) {           if (primes[L] + primes[R] == target) {             cout << 3 << endl;             cout << primes[L] <<     << primes[R] <<     << cur << endl;             return 0;           } else if (primes[L] + primes[R] > target)             R--;           else {             debug() <<   [                      <<  L                          :                       << (L)                     <<  ]                            [                      <<  R                          :                       << (R) <<  ]  ;             debug() <<   [                      <<  primes[L]                          :                       << (primes[L])                     <<  ]                            [                      <<  primes[R]                          :                       << (primes[R]) <<  ]  ;             L++;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n;     cin >> n;     char s;     long long cnt = 0;     while (cin >> s) {       cnt += s ==  8 ;     }     long long ans = 0;     for (long long i = 0; i <= cnt; ++i) {       if (min(i, (n - i) / 10) > ans) ans = min(i, (n - i) / 10);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   const int EPS = 1e-8;   const int MOD = 1000000007;   const long double PI = 3.14159265359;   const int dx4[4] = {0, 1, 0, -1};   const int dy4[4] = {-1, 0, 1, 0};   const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};   const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};   inline bool grid_inside(int x, int y, int n, int m) {     return x >= 1 && x <= n && y >= 1 && y <= m;   }   bool inrange(int a, int b, int a1, int b1) {     if (a >= a1 && a <= b1) return true;     if (b >= a1 && b <= b1) return true;     if (a1 >= a && a1 <= b) return true;     if (b1 >= a && b1 <= b) return true;     return false;   }   template <typename T>   T lcm(T a, T b) {     return (a * b) / __gcd(a, b);   }   template <typename ForwardIterator, typename T>   T first_val(ForwardIterator first, ForwardIterator last, T value) {     auto it = std::lower_bound(first, last, value);     return (it != last) ? (it - first) : -1;   }   template <typename ForwardIterator, typename T>   T last_val(ForwardIterator first, ForwardIterator last, T value) {     auto it = std::upper_bound(first, last, value);     return ((it != last) ? ((it - first) - 1) : -1);   }   template <typename T>   T Dis(T x1, T y1, T x2, T y2) {     return sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));   }   template <typename T>   T Angle(T x1, T y1, T x2, T y2) {     return atan((double)(y1 - y2) / (double)(x1 - x2));   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int Reset(int N, int pos) { return N = N & ~(1 << pos); }   bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }   template <class T, class X>   inline T togglebit(T a, X i) {     T t = 1;     return (a ^ (t << i));   }   bool compare(const pair<int, int> &i, const pair<int, int> &j) {     return i.first < j.first;   }   int doubleCompare(double x, double y) {     if (fabs(x - y) <= EPS) return 0;     if (x < y) return -1;     return 1;   }   int LSOne(long long int n) { return log2(n & -n) + 1; }   int rangeClear(int n, int i, int j) {     int ones = ~0;     int a = ones << (j + 1);     int b = (i << 2) - 1;     int mask = a | b;     int ans = n & mask;     return ans;   }   int countSetBits(int n) {     int count = 0;     while (n > 0) {       count += (n & 1);       n = n >> 1;     }     return count;   }   int getPosBit(int n, int k) { return (n & (1 << k)) != 0 ? 1 : 0; }   void setPosBit(int &n, int k) { n = n | (1 << k); }   long long int fast_power(long long int a, long long int x) {     if (x == 0)       return 1;     else if (x == 1)       return a;     else {       long long int R = fast_power(a, x >> 1);       if (!(x & 1))         return R * R;       else         return R * a * R;     }   }   long long int fast_power_unlocked(long long int a, long long int n,                                     long long int mod) {     long long int res = 1;     while (n > 0) {       if (n & 1) {         res = (res * a) % mod;       }       a = (a * a) % mod;       n = n >> 1;     }     return res;   }   long long int modInverse(long long int A, long long int M) {     return fast_power_unlocked(A, M - 2, M);   }   bool checkPrime(long long int n) {     int cnt = 0;     for (long long int i = 2; i * i <= n; i++) {       if (n % i == 0) {         if (n / i == i)           cnt++;         else           cnt += 2;       }     }     if (cnt == 2)       return true;     else       return false;   }   const int MAX_N = 1001;   void solve() {     int n, x, m;     cin >> n >> x >> m;     pair<int, int> v;     v = make_pair(x, x);     int k = 1;     while (m--) {       int a, b;       cin >> a >> b;       if (inrange(a, b, v.first, v.second)) {         if (a < v.first) v.first = a;         if (b > v.second) v.second = b;       }     }     cout << v.second - v.first + 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     ;     for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);          blockTime.second;          fprintf(stderr,  %s: %ld ms n ,  Time Taken ,                  chrono::duration_cast<chrono::milliseconds>(                      chrono::high_resolution_clock::now() - blockTime.first)                      .count()),               fflush(stderr), blockTime.second = false) {       int t;       cin >> t;       for (int i = 0; i < t; ++i) {         solve();         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     long long n, m, l;     cin >> n >> m >> l;     vector<long long> a(n);     vector<pair<long long, long long>> lr(n);     long long ans = 0, old = -1000;     long long flag = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > l) {         if (flag == 0) ans++;         flag = 1;       }       if (a[i] <= l && flag == 1) {         flag = 0;       }     }     while (m--) {       long long tp;       cin >> tp;       if (tp == 0) {         cout << ans << endl;       } else {         long long p, d;         cin >> p >> d;         if (n > 1) {           if (a[p - 1] <= l && a[p - 1] + d > l) {             if (p - 1 > 0 && p - 1 < n - 1) {               if (a[p - 2] > l && a[p] > l)                 ans--;               else if (a[p - 2] <= l && a[p] > l)                 ans += 0;               else if (a[p - 2] > l && a[p] <= l)                 ans += 0;               else                 ans++;             } else if (p - 1 == 0) {               if (a[p] > l)                 ans += 0;               else if (a[p] <= l)                 ans++;             } else {               if (a[p - 2] > l)                 ans += 0;               else if (a[p - 2] <= l)                 ans++;             }           }         } else {           if (a[p - 1] <= l && a[p - 1] + d > l) ans++;         }         a[p - 1] += d;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   char a[105][105];   int n, m;   bool u[105][105];   int main() {     memset(u, false, sizeof(u));     scanf( %d %d n , &n, &m);     for (int i = 0; i < n; i++, scanf(  n ))       for (int j = 0; j < m; j++) scanf( %c , &a[i][j]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         for (int ix = 0; ix < m; ix++)           if (ix != j && a[i][ix] == a[i][j]) u[i][ix] = u[i][j] = true;         for (int ix = 0; ix < n; ix++)           if (ix != i && a[ix][j] == a[i][j]) u[ix][j] = u[i][j] = true;       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (!u[i][j]) putchar(a[i][j]);       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[1005][1005];   long long c[1005][1005], sum[1005][1005], t[1005][1005];   int main() {     int n = 0, m = 0, a = 0, b = 0;     scanf( %d%d%d%d , &n, &m, &a, &b);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         scanf( %d , &v[i][j]);         sum[i][j] = sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] +                     (long long)v[i][j];       }     }     vector<pair<long long, pair<int, int>>> res;     set<pair<long long, pair<int, int>>> cost;     for (int i = 1; i <= n; ++i) {       deque<long long> q;       for (int j = m; j >= 1; --j) {         while (!q.empty() && v[i][q.back()] > v[i][j]) {           q.pop_back();         }         q.push_back(j);         while (q.front() >= j + b) {           q.pop_front();         }         t[i][j] = v[i][q.front()];       }     }     for (int i = 1; i <= m; ++i) {       deque<long long> q;       for (int j = n; j >= 1; --j) {         while (!q.empty() && t[q.back()][i] > t[j][i]) {           q.pop_back();         }         q.push_back(j);         while (q.front() >= j + a) {           q.pop_front();         }         c[j][i] = t[q.front()][i];       }     }     for (int i = 1; i + a - 1 <= n; ++i) {       for (int j = 1; j + b - 1 <= m; ++j) {         long long tmp = sum[i + a - 1][j + b - 1] - sum[i + a - 1][j - 1] -                         sum[i - 1][j + b - 1] + sum[i - 1][j - 1] -                         (long long)a * b * c[i][j];         cost.insert(make_pair(tmp, make_pair(i, j)));       }     }     auto it = cost.begin();     while (it != cost.end()) {       while (it != cost.end() && c[it->second.first][it->second.second] == -1) {         ++it;       }       if (it == cost.end()) {         break;       }       res.push_back(*it);       int row = it->second.first, col = it->second.second;       int rMin = max(row - a + 1, 0), cMin = max(col - b + 1, 0),           rMax = min(row + a - 1, n - (a - 1)),           cMax = min(col + b - 1, m - (b - 1));       for (int i = rMin; i <= rMax; ++i) {         for (int j = cMin; j <= cMax; ++j) {           c[i][j] = -1;         }       }     }     printf( %d n , res.size());     for (int i = 0; i < res.size(); ++i) {       printf( %d %d %I64d n , res[i].second.first, res[i].second.second,              res[i].first);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, p, s;   bool suff[2002][2002];   bool pref[2002][2002];   long long int hash1[2002][2002];   long long int hash2[2002][2002];   set<pair<int, int> > ans;   int main() {     cin >> a >> p >> s;     long long int mod1 = 1000000007;     long long int mod2 = 1000003;     for (int i = 0; i < a.size(); i++) {       pref[i][p.size() - 1] = (a[i] == p[p.size() - 1]);       suff[i][s.size() - 1] = (a[i] == s[s.size() - 1]);     }     for (int i = p.size() - 2; i >= 0; i--)       for (int j = 0; j < a.size() - 1; j++)         pref[j][i] = pref[j + 1][i + 1] && (a[j] == p[i]);     for (int i = s.size() - 2; i >= 0; i--)       for (int j = 0; j < a.size() - 1; j++)         suff[j][i] = suff[j + 1][i + 1] && (a[j] == s[i]);     int l = max(p.size(), s.size());     for (int i = 0; i < a.size(); i++) {       hash1[i][i] = a[i] -  a ;       hash2[i][i] = 0;       for (int j = i + 1; j < a.size(); j++) {         hash1[i][j] = (hash1[i][j - 1] * 26 + a[j] -  a ) % mod1;         hash2[i][j] = j - i;       }     }     for (int i = 0; i < a.size(); i++)       for (int j = i + l - 1; j < a.size(); j++)         if (pref[i][0] && suff[j - s.size() + 1][0])           ans.insert(make_pair(hash1[i][j], hash2[i][j]));     cout << ans.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[100003];   struct Node {     int val;     int val2;     Node* pt[26];   } node[100003];   int cnt;   int mex(Node* node) {     if (node->val != -1) return node->val;     int f[30] = {};     for (int i = 0; i < 26; ++i)       if (node->pt[i]) f[mex(node->pt[i])] = 1;     for (int i = 0; i < 30; ++i)       if (f[i] == 0) return node->val = i;   }   int mex2(Node* node) {     if (node->val2 != -1) return node->val2;     int f[30] = {};     int flag = 0;     for (int i = 0; i < 26; ++i)       if (node->pt[i]) {         f[mex2(node->pt[i])] = 1;         flag = 1;       }     if (!flag) return node->val2 = 1;     for (int i = 0; i < 30; ++i)       if (f[i] == 0) return node->val2 = i;   }   int main() {     cnt = 27;     int N, K;     cin >> N >> K;     for (int i = 0; i < 100003; ++i) node[i].val = node[i].val2 = -1;     for (int i = 0; i < N; ++i) {       cin >> str;       Node* now = node;       now->pt[str[0] -  a ] = node + str[0] -  a  + 1;       for (int j = 0; str[j]; ++j)         if (now->pt[str[j] -  a ])           now = now->pt[str[j] -  a ];         else           now = now->pt[str[j] -  a ] = node + cnt++;     }     if (mex(node) == 0)       cout <<  Second  << endl;     else if (K % 2 == 1 || mex2(node))       cout <<  First  << endl;     else       cout <<  Second  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pairvar {     int a;     int b;     int c;     int max;   };   bool isPrime(long long x) {     if (x == 1) {       return false;     }     long long a = (long long)x;     for (int i = 2; i <= (long long)sqrt((double)a); i++) {       if (a % i == 0) {         return false;       }     }     return true;   }   int gcd(int a, int b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   long long factorial(long long x) {     long long sum = 1;     for (long long i = 1; i <= x; i++) {       sum *= i;     }     return sum;   }   string tostr(int x) {     string s =   ;     while (x != 0) {       s += (x % 10) +  0 ;       x /= 10;     }     string t =   ;     for (int i = s.length() - 1; i >= 0; i--) {       t += s[i];     }     return t;   }   bool cmp(const pairvar &a, const pairvar &b) {     if (a.a == b.a) return a.b < b.b;     return a.a < b.a;   }   int calc(int a, int b) { return (a * b) / gcd(a, b); }   int main() {     string s;     cin >> s;     int ans = 1;     int k = s.size() - 1;     int j = 1;     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  0 ) {         k--;         j++;       } else {         if (k > j) {           ans++;           k--;           j = 1;         } else if (k == j) {           if (s[0] >= s[i]) {             j = 1;             k--;             ans++;           } else {             j++;             k--;           }         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, sum = 0;     cin >> n;     vector<long long> arr(n + 1);     for (long long i = 1; i <= n; i++) cin >> arr[i], sum += arr[i];     map<pair<long long, long long>, long long> ma;     long long m, a, b, c;     cin >> m;     while (m--) {       cin >> a >> b >> c;       if (!ma.count({a, b})) {         if (c > 0) {           arr[c]--;           if (arr[c] >= 0) sum--;         }       } else {         long long temp = ma[{a, b}];         arr[temp]++;         if (arr[temp] > 0) sum++;         if (c > 0) {           arr[c]--;           if (arr[c] >= 0) sum--;         } else {           ma.erase(ma.find({a, b}));         }       }       if (c != 0) ma[{a, b}] = c;       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   inline int read() {     register int x = 0;     register char f = 1, ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = !f;     for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^  0 );     return f ? x : -x;   }   int n, d[250005], X, vis[250005];   long long sum;   std ::vector<std ::pair<int, int> > E[250005];   std ::pair<int, int> D[250005];   void addedge(int u, int v, int w) {     E[u].push_back(std ::make_pair(v, w)), ++d[u];   }   bool cmp(std ::pair<int, int> x, std ::pair<int, int> y) {     return d[x.first] > d[y.first];   }   struct Normal_Heap {     std ::vector<long long> a;     void push(long long x) {       a.push_back(x), std ::push_heap(a.begin(), a.end());     }     long long top() { return a[0]; }     void pop() { std ::pop_heap(a.begin(), a.end()), a.pop_back(); }     long long popn() {       long long x;       return std ::pop_heap(a.begin(), a.end()), x = a[a.size() - 1],                                                  a.pop_back(), x;     }     int size() { return a.size(); }   };   struct Erase_Heap {     Normal_Heap a, b;     int sz;     long long sum;     void push(long long x) { a.push(x), ++sz, sum += x; }     void erase(long long x) { b.push(x), --sz, sum -= x; }     void pre() {       while (a.size() && b.size() && a.top() == b.top()) a.pop(), b.pop();     }     long long top() { return pre(), a.top(); }     void pop() { pre(), --sz, sum -= a.top(), a.pop(); }     int size() { return sz; }   } H[250005];   void die(int u) {     for (auto to : E[u]) {       register int v = to.first, w = to.second;       if (d[v] <= X) break;       H[v].push(w);     }   }   long long dp[250005][2];   std ::vector<long long> tmp, del;   void dfs(int u, int fa = 0) {     vis[u] = X;     int num = d[u] - X;     long long res = 0;     for (; H[u].size() > num; H[u].pop())       ;     for (auto to : E[u]) {       register int v = to.first, w = to.second;       if (v == fa) continue;       if (d[v] <= X) break;       dfs(v, u);     }     tmp.clear(), del.clear();     for (auto to : E[u]) {       register int v = to.first, w = to.second;       if (v == fa) continue;       if (d[v] <= X) break;       long long x = dp[v][1] + w - dp[v][0];       if (x <= 0) {         --num, res += dp[v][1] + w;         continue;       }       res += dp[v][0], H[u].push(x), del.push_back(x);     }     for (; H[u].size() && H[u].size() > num; H[u].pop())       tmp.push_back(H[u].top());     dp[u][0] = res + H[u].sum;     for (; H[u].size() && H[u].size() > num - 1; H[u].pop())       tmp.push_back(H[u].top());     dp[u][1] = res + H[u].sum;     for (auto i : tmp) H[u].push(i);     for (auto i : del) H[u].erase(i);   }   int main() {     n = read();     for (register int i = 1, u, v, w; i < n; ++i)       u = read(), v = read(), w = read(), addedge(u, v, w), addedge(v, u, w),       sum += w;     printf( %lld , sum);     for (register int i = 1; i <= n; ++i)       D[i] = std ::make_pair(d[i], i), std ::sort(E[i].begin(), E[i].end(), cmp);     std ::sort(D + 1, D + 1 + n);     register int i = 1;     for (X = 1; X < n; ++X) {       while (i <= n && D[i].first == X) die(D[i].second), ++i;       long long ans = 0;       for (register int j = i; j <= n; ++j) {         register int v = D[j].second;         if (vis[v] == X) continue;         dfs(v), ans += dp[v][0];       }       printf(  %lld , ans);     }     putchar(  n );   }


#include <bits/stdc++.h>   using namespace std;   const bool testing = false;   pair<long long, long long> d[100000];   int nf[100000], nb[100000];   pair<long long, long long> getmid(int a, int b) {     long long y = d[b].second - d[a].second;     long long x = d[b].first - d[a].first;     pair<long long, long long> res =         make_pair(-y + x * x + 2 * x * d[a].first, 2 * x);     return res;   }   void program() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       long long t1, t2;       cin >> t1 >> t2;       d[i] = make_pair(t1, t2);     }     std::sort(d, d + n);     int start = 0;     while (start + 1 < n && d[start + 1].first == d[start].first) start++;     {       nb[start] = -1;       int prev = start;       while (prev < n) {         int t = prev + 1;         while (t + 1 < n && d[t + 1].first == d[t].first) t++;         if (t < n) nb[t] = prev;         nf[prev] = t;         prev = t;       }     }     {       int t1 = start;       while (true) {         int t2 = nf[t1];         if (t2 == n) break;         int t3 = nf[t2];         if (t3 == n) break;         pair<long long, long long> A1 = getmid(t1, t2);         pair<long long, long long> A2 = getmid(t1, t3);         if (A2.first * A1.second <= A1.first * A2.second) {           nf[t1] = t3;           nb[t3] = t1;           if (nb[t1] != -1) t1 = nb[t1];         } else           t1 = nf[t1];       }     }     long long res = 0;     {       int t = start;       while (nf[t] != n) {         res++;         t = nf[t];       }     }     cout << res;   }   int main() {     if (!testing) {       program();       return 0;     }     FILE* fin = NULL;     fin = fopen( in.txt ,  w+ );     fprintf(fin,   n3 n-1 0 n0 2 n1 0 n );     fclose(fin);     freopen( in.txt ,  r , stdin);     printf( test case(1) => expected :  n );     printf( 2 );     printf( test case(1) => found    :  n );     program();     fin = fopen( in.txt ,  w+ );     fprintf(fin,   n5 n1 0 n1 -1 n0 -1 n-1 0 n-1 -1 n );     fclose(fin);     freopen( in.txt ,  r , stdin);     printf( test case(2) => expected :  n );     printf( 1 );     printf( test case(2) => found    :  n );     program();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     long long sum = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];     }     if (sum % 2 != 0) {       sum++;     }     long long sum1 = 0;     for (int i = 0; i < n; i++) {       sum1 += arr[i];       if (sum1 >= (sum / 2)) {         cout << i + 1 << endl;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     if (x < 0) return -x;     return x;   }   template <class T>   T sqr(T a) {     return a * a;   }   const double pi = acos(-1.0);   const double eps = 1e-8;   int a[100010];   int a1[100010];   int a2[100010];   int b;   int ar[100010];   int flag[100010];   int main() {     int i, n, m, k;     while (2 == scanf( %d%d , &n, &m)) {       int cnt = 0;       for (i = 1; i <= n + m; i++) {         if (i <= n)           scanf( %d , &a1[i]);         else           scanf( %d , &a2[i - n]);       }       k = 0;       for (i = 1; i <= n + m; i++) {         scanf( %d , &b);         if (b == 1) {           cnt++;           if (i <= n)             ar[cnt] = a1[i];           else             ar[cnt] = a2[i - n];         } else {           ++k;           if (i <= n)             a[k] = a1[i];           else             a[k] = a2[i - n];         }       }       k = 1;       for (i = 1; i <= n; i++) {         if (k + 1 <= cnt) {           if (abs(a[i] - ar[k]) <= abs(a[i] - ar[k + 1]))             flag[k]++;           else {             k++;             i--;           }         } else           flag[k]++;       }       for (i = 1; i <= cnt; i++) printf( %d  , flag[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ifstream in;   ofstream out;   const long long kk = 1000;   const long long MOD = 10e9 + 7;   long long a, b, x, y;   long long GCD(long long n, unsigned long long m) {     while (n != 0 && m != 0) {       if (n > m) {         n %= m;       } else {         m %= n;       }     }     return (n + m);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> a >> b >> x >> y;     long long x1, y1;     long long k = GCD(x, y);     x /= k;     y /= k;     cout << min(a / x, b / y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200000 + 5;   int n, ex, ey;   char s[MAXN];   struct node {     int x, y;     node() {}     node(int _x, int _y) : x(_x), y(_y) {}   } p[MAXN];   bool OK(int t) {     for (int i = 0; i + t <= n; i++) {       int px = p[i].x - p[0].x + p[n].x - p[i + t].x;       int py = p[i].y - p[0].y + p[n].y - p[i + t].y;       int tx = ex - px;       int ty = ey - py;       if (abs(tx) + abs(ty) <= t) {         return true;       }     }     return false;   }   int main() {     while (~scanf( %d , &n)) {       scanf( %s , s + 1);       scanf( %d%d , &ex, &ey);       if ((n - abs(ex) - abs(ey)) < 0) {         printf( -1 n );         continue;       }       if ((n - abs(ex) - abs(ey)) & 1) {         printf( -1 n );         continue;       }       p[0] = node(0, 0);       for (int i = 1; i <= n; i++) {         if (s[i] ==  U ) {           p[i] = node(p[i - 1].x, p[i - 1].y + 1);         } else if (s[i] ==  D ) {           p[i] = node(p[i - 1].x, p[i - 1].y - 1);         } else if (s[i] ==  L ) {           p[i] = node(p[i - 1].x - 1, p[i - 1].y);         } else if (s[i] ==  R ) {           p[i] = node(p[i - 1].x + 1, p[i - 1].y);         }       }       int l = 0, r = n;       while (l <= r) {         int mid = (l + r) >> 1;         if (OK(mid)) {           r = mid - 1;         } else {           l = mid + 1;         }       }       printf( %d n , r + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int mod = 1e9 + 7;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  w  || s[i] ==  m ) {         cout << 0;         return 0;       }     }     int a, b = 1, c = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] == s[i - 1] && (s[i] ==  n  || s[i] ==  u )) {         a = (b + c) % mod;       } else         a = b;       c = b;       b = a;     }     cout << a;   }


#include <bits/stdc++.h>   using namespace std;   long long mulMod(long long a, long long b, long long m = 1000000007) {     long long x = 0, y = a % m;     while (b > 0) {       if (b % 2 == 1) x = (x + y) % m;       y = (y * 2) % m;       b /= 2;     }     return x % m;   }   long long expMod(long long b, long long e, long long m = 1000000007) {     if (!e) return 1;     long long q = expMod(b, e / 2, m);     q = mulMod(q, q, m);     return e % 2 ? mulMod(b, q, m) : q;   }   long long invFact[20], fact[20];   long long inverso(long long x) { return expMod(x, 1000000007 - 2); }   void pre() {     fact[0] = 1;     for (int i = (1); i < (20 - 2); i++) fact[i] = (fact[i - 1] * i) % 1000000007;     invFact[20 - 3] = inverso(fact[20 - 3]);     for (int i = 20 - 3 - 1; i >= 0; i--)       invFact[i] = (invFact[i + 1] * (i + 1)) % 1000000007;     return;   }   long long comb(long long nn, long long k) {     if (k < 0 || nn < k) return 0;     return (fact[nn] * invFact[k] % 1000000007) * invFact[nn - k] % 1000000007;   }   int n;   long long win[15][15];   long long get(int mask1, int mask2) {     long long ret = 1;     for (int i = (0); i < (n); i++) {       if ((mask1 >> i) & 1) {         for (int j = (0); j < (n); j++) {           if ((mask2 >> j) & 1) {             ret = ((ret * win[i][j] % 1000000007) + 1000000007) % 1000000007;             assert(ret >= 0);           }         }       }     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     vector<long long> a(n);     for (int i = (0); i < (n); i++) cin >> a[i];     for (int i = (0); i < (n); i++)       for (int j = (0); j < (n); j++)         win[i][j] = (((a[i] * inverso(a[i] + a[j])) % 1000000007) + 1000000007) %                     1000000007;     vector<long long> proba(1 << n, 1);     long long rta = 0;     for (int mask = 1; mask < (1 << n); mask++) {       for (int submask = mask & (mask - 1); submask;            submask = (submask - 1) & mask) {         proba[mask] -= proba[submask] * get(submask, mask ^ submask);         proba[mask] = ((proba[mask] % 1000000007) + 1000000007) % 1000000007;         assert(proba[mask] >= 0);       }       rta += ((__builtin_popcount(mask) * proba[mask]) % 1000000007 *               get(mask, ((1 << n) - 1) ^ mask)) %              1000000007;       rta = ((rta % 1000000007) + 1000000007) % 1000000007;     }     cout << rta <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = int(1e5);   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   struct Node {     int to, nxt, w;   } Edge[Maxn * 2 + 5];   int tot, Head[Maxn + 5];   inline void Addedge(int x, int y, int z) {     Edge[++tot] = (Node){y, Head[x], z};     Head[x] = tot;   }   long long ans;   int n, l, w, rt, sum;   int siz[Maxn + 5], maxs[Maxn + 5], vis[Maxn + 5];   int dis1[Maxn + 5], dis2[Maxn + 5], cur, allcur;   struct Point {     int a, b, c;   } tmp[Maxn + 5], all[Maxn + 5];   inline int cmp1(Point x, Point y) { return x.a < y.a; }   inline int cmp2(Point x, Point y) { return x.a > y.a; }   int t[Maxn + 5], top;   inline void Add(int x, int y) {     while (x <= l) t[x] += y, x += (x & -x);   }   inline int Query(int x) {     int res = 0;     while (x > 0) res += t[x], x -= (x & -x);     return res;   }   inline void dfs1(int x, int f) {     siz[x] = 1, maxs[x] = 0;     for (register int i = Head[x]; i; i = Edge[i].nxt) {       int y = Edge[i].to;       if (y == f || vis[y]) continue;       dfs1(y, x);       siz[x] += siz[y];       maxs[x] = max(maxs[x], siz[y]);     }     maxs[x] = max(maxs[x], sum - siz[x]);     rt = maxs[x] < maxs[rt] ? x : rt;   }   inline void dfs2(int x, int f, int grand) {     tmp[++cur] = (Point){dis1[x], dis2[x], grand};     for (register int i = Head[x]; i; i = Edge[i].nxt) {       int y = Edge[i].to;       if (y == f || vis[y]) continue;       dis1[y] = dis1[x] + Edge[i].w;       dis2[y] = dis2[x] + 1;       dfs2(y, x, grand);     }   }   inline void Count(int x) {     int it = 1;     allcur = 0;     for (register int i = Head[x]; i; i = Edge[i].nxt) {       int y = Edge[i].to;       if (vis[y]) continue;       dis1[y] = Edge[i].w, dis2[y] = 1;       cur = 0, dfs2(y, x, y);       for (register int j = 1; j <= cur; ++j)         if (tmp[j].a <= w) all[++allcur] = tmp[j];     }     sort(all + 1, all + allcur + 1, cmp1);     for (register int i = Head[x]; i; i = Edge[i].nxt) {       int y = Edge[i].to;       if (vis[y]) continue;       dis1[y] = Edge[i].w, dis2[y] = 1;       it = 1, cur = 0, dfs2(y, x, y);       sort(tmp + 1, tmp + cur + 1, cmp2);       for (register int j = 1; j <= cur; ++j) {         while (it <= allcur && tmp[j].a + all[it].a <= w) {           if (all[it].c < y) Add(all[it].b, 1);           it++;         }         if (tmp[j].a <= w && tmp[j].b <= l) ans++;         if (tmp[j].b < l) ans += Query(l - tmp[j].b);       }       for (register int j = 1; j < it; ++j)         if (all[j].c < y) Add(all[j].b, -1);     }   }   inline void Divide(int x) {     vis[x] = 1;     Count(x);     for (register int i = Head[x]; i; i = Edge[i].nxt) {       int y = Edge[i].to;       if (vis[y]) continue;       rt = 0, maxs[0] = sum = siz[y];       dfs1(y, 0), dfs1(rt, 0);       Divide(rt);     }   }   int main() {     n = read(), l = read(), w = read();     for (register int i = 1; i < n; ++i) {       int a = read(), b = read();       Addedge(i + 1, a, b), Addedge(a, i + 1, b);     }     maxs[0] = sum = n;     dfs1(1, 0), dfs1(rt, 0);     Divide(rt);     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void splitstr(const string &s, vector<T> &out) {     istringstream in(s);     out.clear();     copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));   }   template <class T>   T read_value(string s) {     T result;     istringstream sin(s);     sin >> result;     return result;   }   string read_line() {     string ret_val;     getline(std::cin, ret_val);     return ret_val;   }   template <class T>   void init_array(T *arr, int size, T value) {     for (int i = 0; i < size; i++) arr[i] = value;   }   template <class T>   inline T gcd(T a, T b) {     return (!a) ? b : gcd(b % a, a);   }   template <class T>   inline T mod(T a, T p) {     a %= p;     return (a < 0) ? a + p : a;   }   template <class T>   inline int num_bits(T n) {     return (!n) ? 0 : 1 + numbits(n & (n - 1));   }   template <class T>   inline T inverse(T a, T m) {     a = mod<T>(a, m);     return (a == 1) ? 1 : mod((1 - m * inverse(m % a, a)) / a, m);   }   template <class T>   inline bool is_prime(T a) {     T lim = (T)sqrt((double)a);     for (T i = 2; i <= T(lim + 1E-9); i++)       if (a % i == 0) return false;     return true;   }   template <class T>   inline T power(T a, T p, T mod) {     if (!p) return 1;     T temp = power(a, p >> 1, mod);     temp = (temp * temp) % mod;     if (p & 1) temp = (temp * a) % mod;     return temp;   }   void get_primes(int start, int end, vector<int> &vi) {     int *p = new int[end + 1];     init_array<int>(p, end + 1, 0);     p[1] = 1;     for (int i = 2; i <= end; i++) {       if (!p[i]) {         if (i >= start) vi.push_back(i);         for (int j = 2 * i; j <= end; j += i) p[j] = 1;       }     }     delete[] p;   }   bool dfs(int current, int final, int total, int *visited, int **edges,            bool flow) {     if (current == final) return true;     if (visited[current]) return false;     visited[current] = true;     for (int i = 0; i < total; i++)       if (edges[current][i] && dfs(i, final, total, visited, edges, flow)) {         if (flow) {           edges[current][i]--;           edges[i][current]++;         }         return true;       }     return false;   }   int flow(int in, int out, int total, int **edges) {     int result = 0;     int *visited = new int[total];     while (init_array<int>(visited, total, 0),            dfs(in, out, total, visited, edges, true))       result++;     delete[] visited;     return result;   }   void create_set(int x, int *P, int *rank) {     P[x] = x;     rank[x] = 0;   }   int find_set(int x, int *P) {     if (x != P[x]) P[x] = find_set(P[x], P);     return P[x];   }   bool merge_sets(int x, int y, int *P, int *rank) {     int Px = find_set(x, P);     int Py = find_set(y, P);     if (Px == Py) return false;     if (rank[Px] > rank[Py])       P[Py] = Px;     else       P[Px] = Py;     if (rank[Px] == rank[Py]) rank[Py]++;     return true;   }   template <typename T>   int read_cum_freq(int index, T *tree) {     int sum = 0;     while (index) {       sum += tree[index];       index -= (index & -index);     }     return sum;   }   template <typename T>   void upd_freq(int index, int mxIndex, int value, T *tree) {     while (index <= mxIndex) {       tree[index] += value;       index += (index & -index);     }   }   template <typename T>   int read_freq(int index, T *tree) {     return read_cum_freq(index, tree) - read_cum_freq(index - 1, tree);   }   void build_failure_function(const string &str, int *temp_arr) {     temp_arr[0] = temp_arr[1] = 0;     for (int i = 2; i <= ((int)(str).size()); i++) {       temp_arr[i] = -1;       for (int ind = temp_arr[i - 1]; temp_arr[i] == -1; ind = temp_arr[ind]) {         if (str[ind] == str[i - 1]) {           temp_arr[i] = ind + 1;         } else if (ind == 0) {           temp_arr[i] = 0;         }       }     }   }   void KMP(const string &text, const string &pattern, int *res) {     int *temp_arr = new int[((int)(pattern).size()) + 1];     build_failure_function(pattern, temp_arr);     int i = 0;     int ind = 0;     while (i < ((int)(text).size())) {       if (text[i] == pattern[ind]) {         res[i] = ++ind;         if (res[i] == ((int)(pattern).size())) {           ind = temp_arr[ind];         }         i++;       } else if (ind == 0) {         res[i++] = 0;       } else {         ind = temp_arr[ind];       }     }     delete[] temp_arr;   }   void setup(int value, string name) {     string name_in = name +  .in ;     string name_out = name +  .out ;     freopen(name_in.c_str(),  r , stdin);     if (value) {       freopen(name_out.c_str(),  w , stdout);     }   }   int main() {     int n, m;     std::cin >> n >> m;     vector<string> vs(n);     for (int i = 0; i < n; i++) std::cin >> vs[i];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         bool flag = true;         for (int k = 0; k < m; k++)           if (k != j && vs[i][j] == vs[i][k]) flag = false;         for (int k = 0; k < n; k++)           if (k != i && vs[i][j] == vs[k][j]) flag = false;         if (flag) std::cout << vs[i][j];       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char first[100001], second[100001], zero[100001];   int number1[10], number2[10];   int just_zero() {     char *p1 = first, *p2 = second;     while (number1[0]--) *p1++ = *p2++ =  0 ;     return p1 - first;   }   int summary_ten(int count) {     int min_rez = -1;     int t = 0;     for (int i = 1; i < 6; i++) {       if (number1[i] && number2[10 - i]) {         int now_rez = min(number1[i], number2[9 - i]) +                       min(number2[10 - i], number1[i - 1]) -                       min(number1[i] - 1, number2[9 - i]) -                       min(number2[10 - i] - 1, number1[i - 1]);         if (now_rez < min_rez || min_rez == -1) {           t = i;           min_rez = now_rez;         }       }     }     if (t) {       number1[t]--;       number2[10 - t]--;       first[count] = t +  0 ;       second[count] = (10 - t) +  0 ;       return count + 1;     }     return count;   }   int summary_nine(int count) {     char *p1 = &first[count], *p2 = &second[count];     for (int i = 0; i < 10; i++) {       int t1 = number1[9 - i];       int t2 = number2[i];       while (t1 * t2) {         *p1++ = (9 - i) +  0 ;         *p2++ = i +  0 ;         t1--;         t2--;         number1[9 - i]--;         number2[i]--;       }     }     return p1 - first;   }   int what_else(int count) {     char *zero_p = zero;     while (number1[0] * number2[0]) {       *zero_p++ =  0 ;       number1[0]--;       number2[0]--;     }     char *p1 = &first[count], *p2 = &second[count];     for (int i = 0; i < 10; i++) {       while (number1[i]) {         *p1++ = i +  0 ;         number1[i]--;       }       while (number2[i]) {         *p2++ = i +  0 ;         number2[i]--;       }     }     return p1 - first;   }   void print_screen(int count) {     char *p1 = first + count, *p2 = second + count;     while (true) {       printf( %c , *p1);       if (p1 == first) break;       *p1--;     }     printf( %s n , zero);     while (true) {       printf( %c , *p2);       if (p2 == second) break;       *p2--;     }     printf( %s , zero);     return;   }   void maximum_sum() {     int count1 = summary_ten(0);     int count2 = count1;     if (count1) count2 = summary_nine(count1);     int count3 = what_else(count2);     print_screen(count3 - 1);     return;   }   int main() {     char str[100001];     scanf( %s , &str);     char *p = &str[0];     while (*p) {       number2[*p -  0 ]++;       number1[(*p++) -  0 ]++;     }     maximum_sum();     scanf( %s , &str);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2000;   long long calcula(long long l, long long r, long long k) {     long long d1 = -r;     long long d2 = l - r;     long long aum = d2 - d1;     long long lim1 = d1;     long long lim2 = d1 + (r * 1000000 - 1) * aum;     if (lim1 <= k && k <= lim2 && (k - d1) % aum == 0) {       long long num = (k - d1) / aum + 1;       return num;     }     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(10);     cout << fixed;     long long k;     cin >> k;     for (long long i = 1; i <= N; i++) {       for (long long j = 1; j <= N; j++) {         if (i + j > N) break;         long long aux = calcula(i, j, k);         if (aux != -1) {           cout << i + j << endl;           for (long long a = 0; a < i - 1; a++) {             cout << 0 <<    ;           }           cout << -1 <<    ;           for (long long a = 0; a < j; a++) {             cout << min(aux, 1000000ll) <<    ;             aux -= min(aux, 1000000ll);           }           cout << endl;           return 0;         }       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int cakesneeded, timek, k, timeforoven;     cin >> cakesneeded >> timek >> k >> timeforoven;     int cyclesneeded = cakesneeded / k;     if (cakesneeded % k != 0) {       cyclesneeded++;     }     int totaltime = cyclesneeded * timek;     int partialtime = totaltime - timek;     if (partialtime > timeforoven) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long w, x, y, z;     bool f = 1;     if (a == c && f) {       w = a + abs(d - b);       x = b;       y = a + abs(d - b);       z = d;       f = 0;     }     if (b == d && f) {       w = a;       x = b + abs(a - c);       y = c;       z = b + abs(a - c);       f = 0;     } else if (f) {       if (abs(a - c) == abs(b - d)) {         w = a;         x = d;         y = c;         z = b;         f = 0;       } else {         cout << -1 << endl;         ;       }     }     if (!f) cout << w <<     << x <<     << y <<     << z << endl;     ;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (b) {       swap(a %= b, b);     }     return a;   }   long long n, m, x, y, a, b, g;   double dist1(long long curstep) {     long long l1 = a / g * curstep;     long long l2 = b / g * curstep;     long long x1 = max(1ll, (x - (l1 - l1 / 2)));     if (x1 + l1 > n) {       x1 = n - l1;     }     long long x2 = x1 + l1;     long long y1 = max(1ll, (y - (l2 - l2 / 2)));     if (y1 + l2 > m) {       y1 = m - l2;     }     long long y2 = y1 + l2;     double c1 = (x1 + x2 + .0) / 2;     double c2 = (y1 + y2 + .0) / 2;     double tempdst = sqrt((c1 - x) * (c1 - x) + (c2 - y) * (c2 - y));     return tempdst;   }   int main() {     cin >> n >> m >> x >> y >> a >> b;     g = gcd(a, b);     a /= g;     b /= g;     long long step = min(n / a, m / b);     a *= step;     b *= step;     long long l1 = a;     long long l2 = b;     long long x1 = max(0ll, (x - (l1 - l1 / 2)));     if (x1 + l1 > n) {       x1 = n - l1;     }     long long x2 = x1 + l1;     long long y1 = max(0ll, (y - (l2 - l2 / 2)));     if (y1 + l2 > m) {       y1 = m - l2;     }     long long y2 = y1 + l2;     cout << x1 <<    ;     cout << y1 <<    ;     cout << x2 <<    ;     cout << y2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   long long n_r, n_g, n_b, r[maxn], g[maxn], b[maxn], ans;   void cal(long long n_r, long long n_g, long long n_b, long long r[],            long long g[], long long b[]) {     long long x, y, z, i, j = 1, k = 1;     for (i = 1; i <= n_g; ++i) {       y = g[i];       while (r[j] <= y && j <= n_r) ++j;       if (j == 1) continue;       --j;       x = r[j];       while (b[k] < y) ++k;       if (k > n_b) break;       z = b[k];       ans = min(ans, (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x));     }   }   void solve() {     ans = 0x7fffffffffffffff;     cal(n_r, n_g, n_b, r, g, b);     cal(n_r, n_b, n_g, r, b, g);     cal(n_g, n_r, n_b, g, r, b);     cal(n_g, n_b, n_r, g, b, r);     cal(n_b, n_g, n_r, b, g, r);     cal(n_b, n_r, n_g, b, r, g);     cout << ans <<   n ;   }   int main() {     int t, i, j;     ios::sync_with_stdio(false);     cin >> t;     while (t--) {       cin >> n_r >> n_g >> n_b;       for (i = 1; i <= n_r; ++i) cin >> r[i];       for (i = 1; i <= n_g; ++i) cin >> g[i];       for (i = 1; i <= n_b; ++i) cin >> b[i];       sort(r + 1, r + 1 + n_r);       sort(g + 1, g + 1 + n_g);       sort(b + 1, b + 1 + n_b);       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> e[111];   int used[111], cnt, cnt2;   void dfs(int x) {     used[x] = 1;     cnt += e[x].size();     cnt2++;     for (int i = 0; i < e[x].size(); i++)       if (used[e[x][i]] == 0) dfs(e[x][i]);   }   int main() {     int i, j, k, n, m, stop = 0;     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       e[x].push_back(y);       e[y].push_back(x);     }     for (i = 1; i <= n; i++) {       if (!used[i]) {         cnt = 0;         cnt2 = 0;         dfs(i);         if (cnt2 % 2 == 1 && cnt2 * 2 == cnt) {           stop++;         }       }     }     printf( %d n , stop + (n - stop) % 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n;   int a[200001];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       bool flag = false;       for (int i = 2; i <= n; i++)         if (abs(a[i] - a[i - 1]) > 1) {           flag = true;           printf( YES n );           printf( %d %d n , i - 1, i);           break;         }       if (!flag) printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d n , &n);     set<int> in, x;     long totalCost(0), cost(0);     while (n--) {       int a, b, c;       scanf( %d %d %d n , &a, &b, &c);       totalCost += c;       if (in.count(a) || x.count(b)) {         cost += c;         x.insert(a);         in.insert(b);       } else {         in.insert(a);         x.insert(b);       }     }     if (totalCost - cost < cost) {       cost = totalCost - cost;     }     printf( %ld n , cost);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> a;   void printall(int x, int y, bool paren = false) {     if (paren) printf( ( );     for (int i = x; i < y; i++) printf( %d-> , a[i]);     printf( %d , a[y]);     if (paren) printf( ) );   }   int main() {     scanf( %d , &n);     a.resize(n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     if (a.back() != 0) {       puts( NO );     } else {       if (n == 1 or a[n - 2] == 1) {         puts( YES );         printall(0, n - 1);       } else {         int i;         for (i = n - 3; i >= 0; i--)           if (a[i] == 0) break;         if (i < 0) {           puts( NO );         } else {           puts( YES );           if (i - 1 >= 0) {             printall(0, i - 1);             printf( -> );           }           printf( (0-> );           printall(i + 1, n - 2, true);           printf( )->0 );         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long double PI = acosl(-1);   const long long infl = 1e18;   const int nmax = 1e6 + 5;   const int MAXLG = log2(nmax) + 1;   const int N = 2e4 + 5;   struct Hopcroft_Karp {     int NIL = 0, INF = (1 << 28), match[N], dist[N], n, m;     vector<int> G[N];     void init(int lft, int rgt) {       n = lft, rgt = m;       for (int i = 0; i <= n + m + 1; i++) G[i].clear();     }     void addEdge(int u, int v) { G[u].push_back(v + n); }     bool bfs() {       queue<int> Q;       for (int i = 1; i <= n; i++) {         if (match[i] == NIL)           dist[i] = 0, Q.push(i);         else           dist[i] = INF;       }       dist[NIL] = INF;       while (!Q.empty()) {         int u = Q.front();         Q.pop();         if (u != NIL) {           for (int i = 0; i < G[u].size(); i++) {             int v = G[u][i];             if (dist[match[v]] == INF) {               dist[match[v]] = dist[u] + 1;               Q.push(match[v]);             }           }         }       }       return (dist[NIL] != INF);     }     bool dfs(int u) {       if (u != NIL) {         for (int i = 0; i < G[u].size(); i++) {           int v = G[u][i];           if (dist[match[v]] == dist[u] + 1) {             if (dfs(match[v])) {               match[v] = u;               match[u] = v;               return true;             }           }         }         dist[u] = INF;         return false;       }       return true;     }     int hopcroft_karp() {       memset(dist, 0, sizeof dist);       memset(match, 0, sizeof match);       int matching = 0;       while (bfs()) {         for (int i = 1; i <= n; i++) {           if (match[i] == NIL && dfs(i)) {             matching++;           }         }       }       return matching;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     Hopcroft_Karp carp;     int n, m;     cin >> n >> m;     vector<pair<int, pair<int, int> > > ejes;     for (int i = 0; i < m; i++) {       int u, v, d;       cin >> u >> v >> d;       ejes.push_back({d, {u, v}});     }     carp.init(n, n);     for (pair<int, pair<int, int> > pp : ejes) {       carp.addEdge(pp.second.first, pp.second.second);     }     int z = carp.hopcroft_karp();     if (z != n) cout <<  -1 n , exit(0);     sort(ejes.begin(), ejes.end());     int lo = 1, hi = 1000000000;     while (hi > lo) {       int mid = (hi + lo) / 2;       carp.init(n, n);       for (auto pp : ejes) {         if (pp.first > mid) break;         carp.addEdge(pp.second.first, pp.second.second);       }       if (carp.hopcroft_karp() == n)         hi = mid;       else         lo = mid + 1;     }     cout << lo << endl;   }


#include <bits/stdc++.h>   using namespace std;   double max(double a, double b) { return (a > b ? a : b); }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     double A[n][n];     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         cin >> A[i][j];       }     }     vector<vector<double> > DP(n, vector<double>(1 << n, 0));     DP[0][0] = 1;     for (int i = 1; i < n; ++i) {       DP[i][1 << (n - 1)] = A[0][i];     }     double mom = 0;     for (int k = 1; k < n; ++k) {       for (int i = 0; i < (1 << n); ++i) {         if (__builtin_popcount(i) != k) {           continue;         }         for (int player = 0; player < n; ++player) {           if (i & (1 << player)) {             continue;           }           double mx = 0;           DP[player][i] = 0;           for (int enemy = 0; enemy < n; ++enemy) {             mx = 0;             if (i & (1 << enemy)) {               mx += A[player][enemy] * DP[player][i - (1 << enemy)];               mx += A[enemy][player] * DP[enemy][i - (1 << enemy)];             }             DP[player][i] = max(mx, DP[player][i]);           }           if (k == n - 1) {             mom = max(DP[player][i], mom);           }         }       }     }     cout << (n == 1 ? 1 : mom) <<   n ;   }


#include <bits/stdc++.h>   int MakeTB(unsigned int *A, unsigned int *B, unsigned int *T, unsigned int N,              unsigned int StartBit) {     for (unsigned int i = 0; i < N - 1; i++)       if (A[i] == 0)         if (B[i] == 0) {           if (i > 0 && T[i] != 0) return 0;           T[i] = 0;           T[i + 1] = 0;         } else           return 0;       else if (B[i] == 0) {         if (i == 0) T[i] = StartBit;         T[i + 1] = !T[i];       } else {         if (i > 0 && T[i] != 1) return 0;         T[i] = 1;         T[i + 1] = 1;       }     return 1;   }   int MakeTWB(unsigned int *A, unsigned int *B, unsigned int *T, unsigned int N) {     unsigned int *a, *b, *t1, *t2;     a = new unsigned int[N - 1];     b = new unsigned int[N - 1];     t1 = new unsigned int[N];     t2 = new unsigned int[N];     for (unsigned int i = 0; i < N - 1; i++) {       a[i] = A[i] & 1;       b[i] = B[i] & 1;     }     if (!(MakeTB(a, b, t1, N, 0) || MakeTB(a, b, t1, N, 1))) return 0;     for (unsigned int i = 0; i < N - 1; i++) {       a[i] = A[i] >> 1;       b[i] = B[i] >> 1;     }     if (!(MakeTB(a, b, t2, N, 0) || MakeTB(a, b, t2, N, 1))) return 0;     for (unsigned int i = 0; i < N; i++) T[i] = t1[i] | (t2[i] << 1);     return 1;   }   int main(void) {     unsigned int N;     unsigned int *a, *b, *t;     scanf( %d , &N);     a = new unsigned int[N - 1];     b = new unsigned int[N - 1];     t = new unsigned int[N];     for (unsigned int i = 0; i < N - 1; i++) scanf( %d , &a[i]);     for (unsigned int i = 0; i < N - 1; i++) scanf( %d , &b[i]);     if (MakeTWB(a, b, t, N)) {       printf( YES n );       for (unsigned int i = 0; i < N; i++) printf( %i  , t[i]);     } else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp, x[1000005];   int main() {     int t1;     cin >> t1;     while (t1--) {       string s, t;       cin >> s >> t;       mp.clear();       for (int i = 0; i < s.size(); i++) mp[s[i]]++;       bool q = true;       for (int i = 0; i < t.size(); i++) {         if (mp[t[i]] == 0) {           q = false;           break;         }       }       if (q == false) {         cout << -1 << endl;         continue;       }       for (int j = 100005; j >= 1; j--) x[j].clear();       for (int i = s.size() - 1; i >= 0; i--) {         for (int j = 1; j <= 26; j++) x[i + 1][j] = x[i + 2][j];         x[i + 1][s[i] -  a  + 1] = i + 1;       }       int in = 0, ans = 0;       while (in < t.size()) {         ans++;         int ind = 0;         while (true) {           if (x[ind + 1][t[in] -  a  + 1] == 0) break;           ind = x[ind + 1][t[in] -  a  + 1];           in++;           if (in >= t.size()) break;         }         if (in >= t.size()) break;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[10001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     long long int x1 = 1, x2 = 1;     int p = k;     if (k % 2 == 0) {       k -= 1;     }     int x = 1, y = 1, res = 0;     for (int j = 1; j <= m; j++) {       for (int i = 1; i <= n; i++) {         a[i] = x;         if (a[i] == k) {           cout << i <<     << j <<    ;           p % 2 == 0 ? cout <<  R  : cout <<  L ;           return 0;         }         x += m * 2;       }       x = y + 2 * j;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 10;   int n, a[MAXN], d[MAXN];   bool pic[MAXN];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int temp;       scanf( %d , &temp);       pic[temp] = 1;     }     fill(d, d + MAXN, 1);     int ans = 0;     for (int i = 1; i < MAXN; i++) {       if (pic[i]) ans = max(ans, d[i]);       if (pic[i])         for (int j = i + i; j < MAXN; j += i) d[j] = max(d[j], d[i] + 1);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   struct BIT {     int n;     vector<int> bit;     BIT(int _n = 0) {       n = _n;       bit.assign(n + 5, 0);     }     void update(int pos, int val) {       for (; pos <= n; pos += pos & -pos) bit[pos] += val;     }     int getsum(int pos) {       int res = 0;       for (; pos; pos -= pos & -pos) res += bit[pos];       return res;     }   };   BIT bit[3];   set<int> pos[3];   int a[N];   int n, q;   int fix(char c) {     if (c ==  R ) return 0;     if (c ==  S ) return 1;     return 2;   }   int getans() {     int res = 0;     for (int x = 0; x < 3; x++)       if (pos[x].size()) {         int y = (x + 1) % 3;         int z = (x + 2) % 3;         if (!pos[y].size())           res += n * (!pos[z].size());         else {           res += pos[x].size();           if (pos[z].size()) {             int l = *pos[y].begin();             int r = *prev(pos[y].end());             int u = *pos[z].begin();             int v = *prev(pos[z].end());             if (r < v) res -= bit[x].getsum(v) - bit[x].getsum(r - 1);             if (u < l) res -= bit[x].getsum(l) - bit[x].getsum(u - 1);           }         }       }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     for (int i = 0; i < 3; i++) bit[i] = BIT(n);     for (int i = 1; i <= n; i++) {       char c;       cin >> c;       a[i] = fix(c);       pos[a[i]].insert(i);       bit[a[i]].update(i, 1);     }     cout << getans() <<   n ;     while (q--) {       int i;       char c;       cin >> i >> c;       pos[a[i]].erase(i);       bit[a[i]].update(i, -1);       a[i] = fix(c);       pos[a[i]].insert(i);       bit[a[i]].update(i, 1);       cout << getans() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ss {     long long sur, x, y, z;     ss() {}     ss(long long a, long long b, long long c, long long d) {       sur = a;       x = b;       y = c;       z = d;     }   } ans;   int n, tot, a[100], b[100];   long long x, uu, p[100], u[200000];   long long calc(long long a, long long b, long long c) {     return a * b + a * c + b * c;   }   long long getsqr(long long a) {     long long b = (long long)sqrt(a) + 1;     while (b * b > a) --b;     return b;   }   long long gettri(long long a) {     long long b = (long long)pow(a, 1.0 / 3) + 1;     while (b * b * b > a) --b;     return b;   }   void dfs(int now, long long lim, long long xx) {     if (!now) {       u[++tot] = xx;       return;     }     dfs(now - 1, lim, xx);     for (int i = 1; i <= a[now]; ++i) {       xx *= p[now];       if (xx > lim) break;       dfs(now - 1, lim, xx);     }   }   void dfs2(int now, long long lim, long long xx) {     if (!now) {       if (calc(uu, xx, x / xx / uu) < ans.sur)         ans = ss(calc(uu, xx, x / xx / uu), uu, xx, x / xx / uu);       return;     }     dfs2(now - 1, lim, xx);     for (int i = 1; i <= a[now]; ++i) {       xx *= p[now];       if (xx > lim) break;       dfs2(now - 1, lim, xx);     }   }   bool cmp(long long a, long long b) { return a > b; }   int main() {     int T;     cin >> T;     for (int test = 1; test <= T; ++test) {       cin >> n;       x = 1;       for (int i = 1; i <= n; ++i) {         cin >> p[i] >> a[i];         for (int j = 1; j <= a[i]; ++j) x *= p[i];       }       memcpy(b, a, sizeof(a));       tot = 0;       dfs(n, gettri(x), 1LL);       sort(u + 1, u + tot + 1, cmp);       ans = ss(calc(x, 1, 1), x, 1, 1);       for (int i = 1; i <= tot; ++i) {         long long vw = x / u[i], v = getsqr(vw), w = u[i];         uu = u[i];         if (calc(u[i], v, v) > ans.sur) continue;         for (int j = 1; j <= n; ++j)           while (w % p[j] == 0) {             w /= p[j];             --a[j];           }         dfs2(n, getsqr(vw), 1LL);         memcpy(a, b, sizeof(b));       }       cout << ans.sur * 2 <<     << ans.x <<     << ans.y <<     << ans.z << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int depth[200005], dad[200005];   int dep = 0;   void node_depth(vector<int> vec[], int i) {     dep = depth[i] + 1;     for (auto j : vec[i - 1]) {       if (j != dad[i]) {         depth[j] = dep;       }     }     for (auto j : vec[i - 1]) {       if (j != dad[i]) {         node_depth(vec, j);       }     }   }   int entry[200005], exiit[200005];   int timer = 0;   void ancestor(vector<int> vec[], int i) {     entry[i] = timer;     timer++;     for (auto j : vec[i - 1]) {       if (j != dad[i]) {         dad[j] = i;         ancestor(vec, j);       }     }     exiit[i] = timer;     timer++;   }   bool isParent(int a, int b) {     return (entry[a] <= entry[b] && exiit[a] >= exiit[b]);   }   signed idiot() {     depth[1] = 0;     int n, m;     cin >> n >> m;     vector<int> edge[n];     dad[1] = 1;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       edge[u - 1].push_back(v);       edge[v - 1].push_back(u);     }     ancestor(edge, 1);     node_depth(edge, 1);     while (m--) {       int k;       cin >> k;       int temp = 1;       vector<int> ve;       while (k--) {         int vi;         cin >> vi;         if (depth[vi] > depth[temp]) {           temp = vi;         }         ve.push_back(vi);       }       bool path = true;       for (auto i : ve) {         if (!isParent(dad[i], temp)) {           path = false;           break;         }       }       cout << (path ?  YES  :  NO ) <<   n ;     }     return 0;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int test_case = 1;     while (test_case--) idiot();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7, maxm = 35 * maxn;   int nxt[maxm][2], tot, a[maxn];   long long ans = 0;   void ins(int x) {     int now = 0;     for (int i = 29; i >= 0; i--) {       int go = (x >> i) & 1;       if (nxt[now][go] == 0) nxt[now][go] = ++tot;       now = nxt[now][go];     }   }   long long query(int x) {     long long ret = 0;     int now = 0;     for (int i = 29; i >= 0; i--) {       int go = (x >> i) & 1;       if (nxt[now][go])         now = nxt[now][go];       else         now = nxt[now][go ^ 1], ret |= (1 << i);     }     return ret;   }   void dfs(int l, int r, int dep) {     if (dep == -1 || l >= r) return;     int mid = l - 1;     while (mid < r && (a[mid + 1] >> dep & 1) == 0) mid++;     dfs(l, mid, dep - 1);     dfs(mid + 1, r, dep - 1);     if (mid == l - 1 || mid == r) return;     for (int i = l; i <= mid; i++) ins(a[i]);     long long ret = 1e18;     for (int i = mid + 1; i <= r; i++) ret = min(ret, query(a[i]));     ans += ret;     for (int i = 0; i <= tot; i++) nxt[i][0] = nxt[i][1] = 0;     tot = 0;   }   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     dfs(1, n, 29);     return 0 * printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long int> v(n);     for (long long int i = 0; i < n; i++) {       cin >> v[i];     }     sort((v).begin(), (v).end());     set<long long> s;     if (n == 1) {       cout << -1;     } else if (n == 2) {       s.insert(v[1] + (v[1] - v[0]));       s.insert(v[0] - (v[1] - v[0]));       if ((v[1] - v[0]) % 2 == 0) {         s.insert(v[0] + (v[1] - v[0]) / 2);       }       cout << s.size() <<   n ;       for (auto i : s) {         cout << i <<    ;       }     } else {       long long d = INT_MAX;       for (long long i = 0; i < n - 1; i++) {         d = min(d, v[i + 1] - v[i]);       }       bool missed = false;       bool noap = false;       for (long long i = 0; i < n - 1; i++) {         if (v[i + 1] == v[i] + d)           continue;         else {           if (v[i + 1] == v[i] + (d * 2)) {             if (missed == false) {               missed = true;               s.insert(v[i] + d);             } else {               noap = true;               break;             }           } else {             noap = true;             break;           }         }       }       if (noap) {         cout << 0;       } else if (missed) {         cout << 1 <<   n ;         cout << (*s.begin());       } else {         s.insert(v[0] - d);         s.insert(v[n - 1] + d);         cout << s.size() <<   n ;         for (auto i : s) {           cout << i <<    ;         }       }     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   template <class T>   bool scanff(T &ret) {     char c;     int sgn;     T bit = 0.1;     if (c = getchar(), c == EOF) return 0;     while (c !=  -  && c !=  .  && (c <  0  || c >  9 )) c = getchar();     sgn = (c ==  - ) ? -1 : 1;     ret = (c ==  - ) ? 0 : (c -  0 );     while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     if (c ==     || c ==   n ) {       ret *= sgn;       return 1;     }     while (c = getchar(), c >=  0  && c <=  9 ) ret += (c -  0 ) * bit, bit /= 10;     ret *= sgn;     return 1;   }   using namespace std;   long long dp[55][55][55];   int a[55];   int n, sum;   double ans;   int main() {     ans = 0.0;     scanff(n);     int tot = 0;     for (int i = int(1); i <= int(n); i++) scanff(a[i]), tot += a[i];     scanff(sum);     if (tot <= sum) {       printf( %.10f n , n * 1.0);       return 0;     }     for (int c = int(1); c <= int(n); c++) {       memset(dp, 0, sizeof(dp));       dp[0][0][0] = 1;       for (int i = int(1); i <= int(n); i++) {         for (int j = int(0); j <= int(i - 1); j++)           for (int k = int(0); k <= int(sum); k++) {             if (dp[i - 1][j][k]) {               dp[i][j][k] += dp[i - 1][j][k];               if (i != c && k + a[i] <= sum)                 dp[i][j + 1][k + a[i]] += dp[i - 1][j][k];             }           }       }       for (int j = int(1); j <= int(n); j++) {         for (int k = int(max(0, sum - a[c] + 1)); k <= int(50); k++) {           if (dp[n][j][k]) {             double temp = dp[n][j][k] * j;             int num = n - j;             int n1 = n - j, n2 = n;             for (int l = int(1); l <= int(num); l++) {               temp *= double(n1);               temp /= double(n2);               n1--;               n2--;             }             temp /= double(n - j);             ans += temp;           }         }       }     }     printf( %.10f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 200010;   int par[M];   int sz[M];   struct edge {     int u, v, w;     bool operator<(const edge &e) const { return w < e.w; }   };   edge E[M];   pair<int, int> q[M];   long long out[M];   int f(int u) { return par[u] = par[u] == u ? u : f(par[u]); }   int add(int u, int v) {     u = f(u);     v = f(v);     if (u == v) return 0;     par[v] = u;     sz[u] += sz[v];     return sz[u];   }   long long get(int n) {     if (n <= 0) return 0;     return ((long long)n * (long long)(n - 1)) / 2;   }   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 0; i < n - 1; i++) {       cin >> E[i].u >> E[i].v >> E[i].w;     }     for (int i = 0; i < m; i++) {       cin >> q[i].first;       q[i].second = i;     }     sort(E, E + n - 1);     sort(q, q + m);     for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1;     long long ans = 0;     int j = 0;     for (int i = 0; i < m; i++) {       while (j < n - 1) {         if (E[j].w > q[i].first) break;         int u = f(E[j].u), v = f(E[j].v);         ans -= (get(sz[u]) + get(sz[v]));         ans += get(add(u, v));         j++;       }       out[q[i].second] = ans;     }     for (int i = 0; i < m; i++) cout << out[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     for (int i = 1, j = n; i <= n / 2; ++i, --j) printf( %d %d  , i, j);     if (n % 2 == 1) printf( %d , n / 2 + 1);     return 0;   }