#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   using namespace std;   template <typename T1, typename T2>   void ckmin(T1 &a, T2 b) {     if (a > b) a = b;   }   template <typename T1, typename T2>   void ckmax(T1 &a, T2 b) {     if (a < b) a = b;   }   int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar();     return f ? -x : x;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void print(T x, char let) {     print(x), putchar(let);   }   const int mod = 998244353;   const int G = 3, Gi = 332748118;   void uad(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   int add(int x, int y) {     if ((x += y) >= mod) x -= mod;     return x;   }   int sub(int x, int y) {     if ((x -= y) < 0) x += mod;     return x;   }   int qpow(int a, int b = mod - 2) {     int res = 1;     while (b > 0) {       if (b & 1) res = 1ll * res * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return res;   }   namespace Module {   using namespace std;   const int N = 1 << 19, P = 998244353;   int Pow(long long x, int y = P - 2) {     int ans = 1;     for (; y; y >>= 1, x = x * x % P)       if (y & 1) ans = ans * x % P;     return ans;   }   int w[N];   unsigned long long F[N];   struct init {     init() {       for (int i = 1; i < N; i <<= 1) {         w[i] = 1;         int t = Pow(3, (P - 1) / i / 2);         for (int j = 1; j < i; ++j) w[i + j] = (long long)w[i + j - 1] * t % P;       }     }   } foo;   int Get(int x) {     int n = 1;     while (n <= x) n <<= 1;     return n;   }   void DFT(vector<int> &f, int n) {     if ((int)f.size() != n) f.resize(n);     for (int i = 0, j = 0; i < n; ++i) {       F[i] = f[j];       for (int k = n >> 1; (j ^= k) < k; k >>= 1)         ;     }     for (int i = 1; i < n; i <<= 1)       for (int j = 0; j < n; j += i << 1) {         int *W = w + i;         unsigned long long *F0 = F + j, *F1 = F + j + i;         for (int k = j; k < j + i; ++k, ++W, ++F0, ++F1) {           unsigned long long t = (*F1) * *W % P;           (*F1) = *F0 + P - t, (*F0) += t;         }       }     for (int i = 0; i < n; ++i) f[i] = F[i] % P;   }   void IDFT(vector<int> &f, int n) {     f.resize(n), reverse(f.begin() + 1, f.end()), DFT(f, n);     int I = 1;     for (int i = 1; i < n; i <<= 1) I = (long long)I * (P + 1) / 2 % P;     for (int i = 0; i < n; ++i) f[i] = (long long)f[i] * I % P;   }   vector<int> operator+(const vector<int> &f, const vector<int> &g) {     vector<int> ans = f;     ans.resize(max(f.size(), g.size()));     for (int i = 0; i < (int)g.size(); ++i) (ans[i] += g[i]) %= P;     return ans;   }   vector<int> operator*(const vector<int> &f, const vector<int> &g) {     vector<int> F, G;     F = f, G = g;     int p = Get(f.size() + g.size() - 2);     DFT(F, p), DFT(G, p);     for (int i = 0; i < p; ++i) F[i] = (long long)F[i] * G[i] % P;     IDFT(F, p);     return F.resize(f.size() + g.size() - 1), F;   }   vector<int> Inv(const vector<int> &f, int n = -1) {     if (n == -1) n = f.size();     if (n == 1) return {Pow(f[0])};     vector<int> ans = Inv(f, (n + 1) / 2), tmp(f.begin(), f.begin() + n);     int p = Get(n * 2 - 2);     DFT(tmp, p), DFT(ans, p);     for (int i = 0; i < p; ++i)       ans[i] = (2 - (long long)ans[i] * tmp[i] % P + P) * ans[i] % P;     IDFT(ans, p);     return ans.resize(n), ans;   }   vector<int> Mod(const vector<int> &a, const vector<int> &b) {     if (b.size() > a.size()) return a;     vector<int> A = a, B = b, iB;     int n = a.size(), m = b.size();     reverse(A.begin(), A.end()), reverse(B.begin(), B.end());     B.resize(n - m + 1), iB = Inv(B, n - m + 1);     vector<int> d = A * iB;     d.resize(n - m + 1), reverse(d.begin(), d.end());     vector<int> r = b * d;     r.resize(m - 1);     for (int i = 0; i < m - 1; ++i) r[i] = (a[i] - r[i] + P) % P;     return r;   }   vector<int> Prod(const vector<int> &a, const vector<int> &b) { return a * b; }   void wf(vector<int> &a) {     int n = a.size();     for (int i = 0; i < n; i++) a[i] = 1ll * (i + 1) * a[i + 1] % mod;     a[n - 1] = 0;   }   void jf(vector<int> &a) {     int n = a.size();     for (int i = n - 1; i >= 1; i--) a[i] = 1ll * a[i - 1] * qpow(i) % mod;     a[0] = 0;   }   vector<int> Ln(vector<int> a) {     vector<int> ta = a;     wf(ta);     int len = a.size();     a = ta * Inv(a), jf(a);     a.resize(len);     return a;   }   vector<int> Exp(vector<int> a) {     if ((int(a.size())) == 1) return vector<int>(1, 1);     int len = a.size();     vector<int> ta = a;     ta.resize((len + 1) / 2);     vector<int> tb = Exp(ta);     tb.resize(len);     vector<int> Lnb = Ln(tb);     assert(Lnb.size() == len);     for (int i = 0; i < len; i++) Lnb[i] = (a[i] - Lnb[i] + mod) % mod;     Lnb[0] = (Lnb[0] + 1) % mod;     tb = tb * Lnb;     tb.resize(len);     return tb;   }   }  // namespace Module   using Module::operator*;   const int N = 250005;   const int B = 30;   vector<int> adj[N];   int n;   int son[N];   void dfs1(int u, int fa) {     for (auto v : adj[u]) {       if (v == fa) continue;       son[u]++;       dfs1(v, u);     }   }   int two[N], len;   vector<int> solve(int l, int r) {     if (l > r) return {1};     if (l == r) return {1, mod - two[l]};     int mid = l + r >> 1;     return solve(l, mid) * solve(mid + 1, r);   }   int fac[N], inv[N];   int fuck[N];   int main() {     n = read();     inv[1] = 1;     for (int i = 2; i <= n; i++)       inv[i] = 1ull * (mod - mod / i) * inv[mod % i] % mod;     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = 1ull * fac[i - 1] * i % mod;     for (int i = 1; i <= n - 1; i++) {       int u = read(), v = read();       adj[u].push_back(v), adj[v].push_back(u);     }     dfs1(1, 0);     vector<int> ONE(n + 1);     for (int i = 1; i <= n; i++) {       if (son[i] > B) {         two[++len] = son[i];       } else {         fuck[son[i]]++;       }     }     for (int i = 1; i <= B; i++) {       int coef = 1;       for (int j = 1; j <= n; j++) {         coef = 1ull * coef * i % mod;         ONE[j] = sub(ONE[j], 1ull * fuck[i] * coef % mod * inv[j] % mod);       }     }     ONE = Module::Exp(ONE);     vector<int> TWO = solve(1, len);     vector<int> f = ONE * TWO;     int ans = 0;     for (int i = 0; i <= n - 1; i++) ans = (ans + 1ll * fac[n - i] * f[i]) % mod;     print(ans,   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200 * 1000 + 5;   vector<pair<int, int> > adj[N];   int w[N];   int d[N];   bool mark[N];   set<pair<int, int> > s;   vector<int> ans;   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> w[i];     }     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back({v, i});       adj[v].push_back({u, i});     }     for (int i = 1; i <= n; i++) {       d[i] = (int)adj[i].size() - w[i];       s.insert({d[i], i});     }     while (s.size()) {       int v = (*s.begin()).second;       s.erase(s.begin());       mark[v] = true;       if (d[v] > 0) {         cout <<  DEAD ;         return 0;       }       for (auto p : adj[v]) {         int u = p.first;         if (!mark[u]) {           s.erase({d[u], u});           d[u]--;           s.insert({d[u], u});           ans.push_back(p.second);         }       }     }     cout <<  ALIVE n ;     reverse(ans.begin(), ans.end());     for (auto x : ans) {       cout << x <<    ;     }     return 0;   }


#include <bits/stdc++.h>   char zebra[100005];   int max;   int main() {     scanf( %s , zebra + 1);     max = 0;     int n = strlen(zebra + 1);     int t = 0;     int ans = 0;     for (int i = 1; i <= n; i++) {       int k = 1;       while (zebra[i] != zebra[i + 1] && i + 1 <= n) {         k++;         i++;       }       if (i == n && t == 0) {         if (zebra[i] != zebra[1]) {           k++;           t++;           i = 1;         }       }       while (zebra[i] != zebra[i + 1] && i + 1 <= n) {         k++;         i++;       }       if (k > n) k = n;       if (k > ans) ans = k;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool exceed(long long x, long long y, long long m) { return x >= m / y + 1; }   struct SegTree {     int size;     vector<pair<long long, long long> > seg;     SegTree() {}     SegTree(int size) {       this->size = size;       seg.resize(1 << (size + 1));     }     pair<long long, long long> Ident() {       return pair<long long, long long>(-1e18, -1e18);     }     pair<long long, long long> ope(pair<long long, long long> a,                                    pair<long long, long long> b) {       return max(a, b);     }     void init() {       for (int i = 0; i < (1 << (size + 1)); i++) seg[i] = Ident();     }     void update(int i, pair<long long, long long> val) {       i += (1 << size);       seg[i] = val;       while (i > 1) {         i /= 2;         seg[i] = ope(seg[i * 2], seg[i * 2 + 1]);       }     }     pair<long long, long long> query(int a, int b, int k, int l, int r) {       if (b < l || r < a) return Ident();       if (a <= l && r <= b) return seg[k];       pair<long long, long long> lval = query(a, b, k * 2, l, (l + r) / 2);       pair<long long, long long> rval =           query(a, b, k * 2 + 1, (l + r) / 2 + 1, r);       return ope(lval, rval);     }     pair<long long, long long> query(int a, int b) {       if (a > b) return Ident();       return query(a, b, 1, 0, (1 << size) - 1);     }   };   long long n;   long long a[500005], b[500005];   SegTree seg(19);   bool used[500005];   long long ans[500005];   vector<long long> topo;   void dfs(int v) {     used[v] = true;     seg.update(v, pair<long long, long long>(-1e18, -1e18));     if (a[v] <= n && !used[a[v]]) dfs(a[v]);     while (1) {       pair<long long, long long> res = seg.query(1, b[v] - 1);       if (res.first <= v) break;       dfs(res.second);     }     topo.push_back(v);   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long(i) = (1); (i) <= (n); (i)++) {       cin >> a[i];       if (a[i] == -1) a[i] = n + 1;     }     for (long long(i) = (1); (i) <= (n); (i)++) b[a[i]] = i;     for (long long(i) = (1); (i) <= (n); (i)++)       if (b[i] == 0) b[i] = n + 1;     seg.init();     for (long long(i) = (1); (i) <= (n); (i)++)       seg.update(i, pair<long long, long long>(a[i], i));     for (long long(i) = (1); (i) <= (n); (i)++)       if (!used[i]) dfs(i);     reverse((topo).begin(), (topo).end());     for (long long(i) = 0; (i) < (long long)(topo).size(); (i)++)       ans[topo[i]] = i + 1;     for (long long(i) = (1); (i) <= (n); (i)++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200007;   const int mod = 998244353;   long long fast_pow(long long b, int k) {     long long s = 1;     while (k) {       if (k & 1) (s *= b) %= mod;       (b *= b) %= mod;       k >>= 1;     }     return s;   }   long long fact[maxn];   int N;   int A[maxn];   int sum[maxn], sum0[maxn];   int C[maxn];   void update(int x) {     while (x <= N) C[x]++, x += x & (-x);     return;   }   int query(int x) {     int re = 0;     while (x) re += C[x], x &= (x - 1);     return re;   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d , &A[i]);       if (A[i] == -1) A[i] = 0;       sum0[i] += sum0[i - 1] + (A[i] == 0);       if (A[i] > N) {         printf( 0 );         return 0;       }       sum[A[i]]++;     }     for (int i = 2; i <= N; i++) sum[i] += sum[i - 1];     fact[0] = 1;     for (int i = 1; i <= N; i++) fact[i] = fact[i - 1] * i % mod;     long long x, y;     long long ans = 0;     if (sum[0])       for (int i = 1; i <= N; i++) {         if (A[i] == 0) continue;         x = A[i] - sum[A[i]];         y = sum0[N] - sum0[i];         (ans += x * y % mod * fact[sum[0] - 1] % mod) %= mod;         x = (N - A[i]) - (sum[N] - sum[A[i]]);         y = sum0[i];         (ans += x * y % mod * fact[sum[0] - 1] % mod) %= mod;       }     x = 1ll * sum[0] * (sum[0] - 1) / 2 % mod;     if (sum[0] > 1)       y = fact[sum[0] - 2];     else       y = 0;     (ans += y * x % mod * x % mod) %= mod;     y = 0;     for (int i = 1; i <= N; i++) {       if (A[i] == 0) continue;       x = query(N) - query(A[i]);       (y += x) %= mod;       update(A[i]);     }     if (sum[0] > 0)       x = fact[sum[0]];     else       x = 1;     (ans += y * x % mod) %= mod;     (ans *= fast_pow(fact[sum[0]], mod - 2)) %= mod;     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int FASTBUFFER;   const int N = 1005;   const int INF = 1000000000;   char str[N][N];   int n, m, l[N], r[N];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , str[i] + 1);     }     for (int i = 1; i <= n; i++) {       int ll = m + 1, rr = 0;       for (int j = 1; j <= m; j++) {         if (str[i][j] ==  X ) {           ll = j;           break;         }       }       for (int j = m; j >= 1; j--) {         if (str[i][j] ==  X ) {           rr = j;           break;         }       }       for (int j = ll; j <= rr; j++) {         if (str[i][j] !=  X ) {           printf( -1 n );           return 0;         }       }       l[i] = ll, r[i] = rr;     }     int st, end;     for (int i = 1; i <= n; i++) {       if (l[i] != m + 1) {         st = i;         break;       }     }     for (int i = n; i >= 1; i--) {       if (l[i] != m + 1) {         end = i;         break;       }     }     for (int i = st; i <= end; i++) {       if (l[i] == m + 1) {         printf( -1 n );         return 0;       }     }     int ans1 = -1, ans2 = -1, flag = 0;     for (int i = st + 1; i <= end; i++) {       if (l[i] < l[i - 1] || r[i] < r[i - 1]) {         printf( -1 n );         return 0;       }       if (l[i] > r[i - 1]) {         printf( -1 n );         return 0;       }       if (r[i] > r[i - 1]) {         flag = 1;       }       if (l[i] > l[i - 1] && ans1 == -1) {         int last;         for (last = i - 1; last >= st; last--) {           if (r[last] != r[i]) {             break;           }         }         if (last < st) {           last++;         }         ans1 = r[last] - l[i] + 1;       }     }     int ans = INF;     if (ans1 == -1) {       if (st == end) {         printf( 1 n );         return 0;       } else {         if (flag) {           ans1 = r[st] - l[st] + 1;         } else {           printf( %d n , min(end - st + 1, r[st] - l[st] + 1));           return 0;         }       }     }     for (int ans1 = 1; ans1 <= r[st] - l[st] + 1; ans1++) {       for (int ans2 = 1; ans2 <= end - st + 1; ans2++) {         int ok = 1;         for (int i = st; i <= st + ans2 - 1; i++) {           if (l[i] != l[st]) {             ok = 0;             break;           }         }         if (ok) {           int top = st, bo = st + ans2 - 1, now = l[st];           while (bo < end) {             while (r[top] > now + ans1 - 1) {               now++;             }             top++;             bo++;             if (now + ans1 - 1 > r[top]) {               ok = 0;             }             if (now != l[bo]) {               ok = 0;             }           }           for (int i = top; i <= bo; i++) {             if (r[i] != r[top]) {               ok = 0;             }           }         }         if (ok) {           ans = min(ans, ans1 * ans2);         }       }     }     if (ans == INF) {       printf( -1 n );       return 0;     } else {       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, i, j;       cin >> n;       vector<int> icons(n);       for (i = 0; i < n; i++) {         cin >> icons[i];       }       vector<int> num;       sort(icons.begin(), icons.end());       int cnt = 1;       for (i = 1; i < icons.size(); i++) {         if (icons[i] == icons[i - 1]) {           cnt++;         } else {           num.push_back(cnt);           cnt = 1;         }       }       num.push_back(cnt);       int x = num[0] + 1;       int minNum = 1e9 + 7;       for (i = 1; i <= x; i++) {         int sum = 0;         for (j = 0; j < num.size(); j++) {           int q = ceil((float)num[j] / i);           if ((i - 1) * q > num[j]) {             sum = 1e9 + 7;             break;           }           sum += q;         }         if (sum < minNum) minNum = sum;       }       cout << minNum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = numeric_limits<int>::max();   const long long LINF = numeric_limits<long long>::max() / 2;   const double DINF = numeric_limits<double>::max();   const int ITER = 3000;   const double EPS = 1e-9;   const int MAXN = 1005;   struct addr {     int x, y;     addr(){};     addr(int a, int b) {       x = a;       y = b;     }   };   struct cell {     addr top, bot, left, right;     addr cur;     cell(){};   };   cell a[MAXN][MAXN];   int val[MAXN][MAXN];   int getVal(addr cur) { return val[cur.x][cur.y]; }   cell moveLeft(cell x) {     x = a[x.left.x][x.left.y];     return x;   }   cell moveRight(cell x) {     x = a[x.right.x][x.right.y];     return x;   }   cell moveTop(cell x) {     x = a[x.top.x][x.top.y];     return x;   }   cell moveBot(cell x) {     x = a[x.bot.x][x.bot.y];     return x;   }   string strad(addr x) {     stringstream ss;     ss <<  (  << x.x <<  ,   << x.y <<  ) ;     return ss.str();   }   void solve() {     int n, m, q;     cin >> n >> m >> q;     for (int i = 0; i < MAXN; ++i) {       for (int j = 0; j < MAXN; ++j) {         a[i][j].cur.x = i;         a[i][j].cur.y = j;         if (i > 0) a[i][j].top = addr(i - 1, j);         if (i < MAXN - 1) a[i][j].bot = addr(i + 1, j);         if (j < MAXN - 1) a[i][j].right = addr(i, j + 1);         if (j > 0) a[i][j].left = addr(i, j - 1);       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cin >> val[i][j];       }     }     cout << endl;     cell it = a[0][0];     while (q--) {       int x, y, c, d, h, w;       cin >> x >> y >> c >> d >> h >> w;       cell first = a[0][0];       cell second = a[0][0];       for (int i = 0; i < x; ++i) first = moveBot(first);       for (int i = 0; i < y; ++i) first = moveRight(first);       for (int i = 0; i < c; ++i) second = moveBot(second);       for (int i = 0; i < d; ++i) second = moveRight(second);       for (int i = 0; i < w; ++i) {         addr ftop = first.top;         addr stop = second.top;         a[ftop.x][ftop.y].bot = second.cur;         a[stop.x][stop.y].bot = first.cur;         a[first.cur.x][first.cur.y].top = stop;         a[second.cur.x][second.cur.y].top = ftop;         if (i < w - 1) {           first = moveRight(first);           second = moveRight(second);         }       }       for (int i = 0; i < h; ++i) {         addr fright = first.right;         addr sright = second.right;         a[fright.x][fright.y].left = second.cur;         a[sright.x][sright.y].left = first.cur;         a[first.cur.x][first.cur.y].right = sright;         a[second.cur.x][second.cur.y].right = fright;         if (i < h - 1) {           first = moveBot(first);           second = moveBot(second);         }       }       for (int i = 0; i < w; ++i) {         addr fbot = first.bot;         addr sbot = second.bot;         a[fbot.x][fbot.y].top = second.cur;         a[sbot.x][sbot.y].top = first.cur;         a[first.cur.x][first.cur.y].bot = sbot;         a[second.cur.x][second.cur.y].bot = fbot;         if (i < w - 1) {           first = moveLeft(first);           second = moveLeft(second);         }       }       for (int i = 0; i < h; ++i) {         addr sleft = second.left;         addr fleft = first.left;         a[fleft.x][fleft.y].right = second.cur;         a[sleft.x][sleft.y].right = first.cur;         a[first.cur.x][first.cur.y].left = sleft;         a[second.cur.x][second.cur.y].left = fleft;         if (i < h - 1) {           first = moveTop(first);           second = moveTop(second);         }       }     }     it = a[0][0];     it = moveRight(it);     it = moveBot(it);     for (int i = 0; i < n; ++i) {       cell col = it;       for (int j = 0; j < m; ++j) {         cout << getVal(col.cur) <<    ;         col = moveRight(col);       }       it = moveBot(it);       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   void print() {     int n;     cin >> n;     int arr[n], mx = 0, sum = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];       mx = max(mx, arr[i]);     }     if (mx * 2 > sum || (sum & 1))       cout <<  T  << endl;     else       cout <<  HL  << endl;   }   int main() {     int t;     cin >> t;     while (t) {       --t;       print();     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   std::ostream &operator<<(std::ostream &out, vector<T> &v) {     for (typename vector<T>::size_type i = 0; i < v.size(); ++i)       out << v[i] <<    ;     out <<   n ;     return out;   }   template <typename T>   std::ostream &operator<<(std::ostream &out, set<T> &s) {     for (auto e : s) out << e <<    ;     out <<   n ;     return out;   }   template <typename T, typename N>   std::ostream &operator<<(std::ostream &out, pair<T, N> &p) {     out <<  (  << p.first <<  ,   << p.second <<  )  ;     return out;   }   template <typename T, typename N>   std::ostream &operator<<(std::ostream &out, vector<pair<T, N> > &v) {     for (size_t i = 0; i < v.size(); ++i) cout << v[i];     out <<   n ;     return out;   }   template <typename T>   std::ostream &operator<<(std::ostream &out, vector<vector<T> > &v) {     for (size_t i = 0; i < v.size(); ++i) {       for (size_t j = 0; j < v[i].size(); ++j) {         out << v[i][j] <<    ;       }       out <<   n ;     }     return out;   }   template <typename T>   std::ostream &operator<<(std::ostream &out, vector<set<T> > &v) {     for (size_t i = 0; i < v.size(); ++i) {       out << v[i];     }     out <<   n ;     return out;   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     int total = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];       total += a[i];     }     int diff = 0;     for (int i = n - 1; i >= 0; --i) {       diff = abs(diff - a[i]);     }     cout << (total - diff) / 2 <<     << (total + diff) / 2 <<   n ;     return;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100001];   int dist[100001];   int n, m;   void bfs(int x) {     queue<int> q;     int cur, i;     memset(dist, -1, sizeof(dist));     dist[x] = 0;     q.push(x);     while (!q.empty()) {       cur = q.front();       q.pop();       for (i = 0; i < (int)g[cur].size(); i++) {         if (dist[g[cur][i]] == -1) {           dist[g[cur][i]] = dist[cur] + 1;           q.push(g[cur][i]);         }       }     }   }   int main() {     int i, a, b, x, res;     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     bfs(1);     res = 0;     x = 1;     for (i = 1; i <= n; i++) {       if (dist[i] > res) {         res = dist[i];         x = i;       }     }     bfs(x);     res = 0;     for (i = 1; i <= n; i++) {       res = max(res, dist[i]);     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     char board[9][9];     char trash;     for (long r = 0; r < 3; ++r) {       for (long x = 0; x < 3; ++x) {         for (long c = 0; c < 3; ++c) {           for (long y = 0; y < 3; ++y) cin >> board[3 * r + x][3 * c + y];           if (c == 5) cin >> trash;         }       }     }     long x, y;     cin >> x >> y;     --x, --y;     x %= 3;     y %= 3;     bool empty = false;     for (long i = 0; i < 3; ++i)       for (long j = 0; j < 3; ++j)         if (board[3 * x + i][3 * y + j] ==  . ) empty = true;     if (empty) {       for (long i = 0; i < 3; ++i)         for (long j = 0; j < 3; ++j)           if (board[3 * x + i][3 * y + j] ==  . )             board[3 * x + i][3 * y + j] =  ! ;     } else {       for (long i = 0; i < 9; ++i)         for (long j = 0; j < 9; ++j)           if (board[i][j] ==  . ) board[i][j] =  ! ;     }     for (long r = 0; r < 3; ++r) {       for (long x = 0; x < 3; ++x) {         for (long c = 0; c < 3; ++c) {           for (long y = 0; y < 3; ++y) cout << board[3 * r + x][3 * c + y];           if (c < 2) cout <<    ;         }         cout <<   n ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, p;   int main() {     map<int, int> mp;     cin >> n;     for (int i = 1; i <= 2 * n + 1; i++) {       if (p % n == 0) {         mp[n]++;       }       mp[p % n]++;       p += i - 1;     }     for (int i = 1; i <= n; i++) {       if (mp[i] == 0) {         cout <<  NO ;         return 0;       }     }     cout <<  YES           <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e2 + 5;   int N, T;   int pref[MAXN];   int ask(int l, int r) {     printf( ? %d %d n , l, r);     fflush(stdout);     int res;     scanf( %d , &res);     if (res == -1) exit(0);     return res;   }   int main() {     scanf( %d%d , &N, &T);     if (N == 1) {       printf( ! %d n , T);       fflush(stdout);       return 0;     }     int k = N % 2, curr = T;     for (int i = 1; i <= N - k; i++) {       int lft = 0, rig = 0;       bool ok = false;       while (!ok || lft || rig) {         int nxt = ask(i, i + k);         if ((curr + nxt) % 2 == (i + k) % 2) {           lft ^= 1;           if (lft && !rig) {             pref[i + k] = (i + k - nxt + T) / 2;             ok = true;           }         } else           rig ^= 1;         curr = nxt;       }     }     if (k) {       int it = 0;       while (1) {         int nxt = ask(2, N);         if (!((curr + nxt) % 2)) {           pref[1] = it ? (T - nxt + 1) / 2 : (nxt + T - N + 1) / 2;           break;         }         curr = nxt;         it ^= 1;       }     }     printf( !  );     for (int i = 1; i <= N; i++) printf( %d , pref[i] - pref[i - 1]);     puts(  );     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[3];     for (int i = 0; i < 3; i++) cin >> a[i];     sort(a, a + 3);     cout << a[2] - a[0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   clock_t start;   mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());   struct MaxFlow {     struct Edge {       long long f;       long long u;       Edge* nex;       Edge* rev;       Edge(long long _u, long long _f, Edge* _nex) : f(_f), u(_u), nex(_nex) {}     };     vector<Edge*> g;     MaxFlow(long long n) { g.resize(n); }     void AddEdge(long long v, long long u, long long f) {       g[v] = new Edge(u, f, g[v]);       g[u] = new Edge(v, 0, g[u]);       g[v]->rev = g[u];       g[u]->rev = g[v];     }     long long Flow(long long src, long long sink, long long n) {       long long flow = 0;       while (true) {         vector<Edge*> par(n);         vector<bool> vis(n, false);         vector<long long> mn(n, 0);         queue<long long> q;         q.push(src);         vis[src] = 1;         mn[src] = (long long)(2e18);         while (!q.empty()) {           long long v = q.front();           q.pop();           for (Edge* e = g[v]; e; e = e->nex) {             if (e->f <= 0) continue;             if (!vis[e->u]) {               mn[e->u] = min(mn[v], e->f);               par[e->u] = e;               vis[e->u] = 1;               q.push(e->u);             }           }         }         long long curr = sink;         long long ff = mn[sink];         if (ff == 0) break;         flow += ff;         while (curr != src) {           Edge* e = par[curr];           e->f -= ff;           e->rev->f += ff;           curr = e->rev->u;         }       }       return flow;     }   };   const long long N = 3e5 + 10;   bool pr[N];   void seive() {     for (long long i = 2; i < N; i++) {       if (pr[i]) continue;       for (long long j = i + i; j < N; j += i) pr[j] = 1;     }   }   void solve() {     long long n, k;     cin >> n >> k;     long long p[n], c[n], l[n];     for (long long i = 0; i < n; i++) {       cin >> p[i] >> c[i] >> l[i];     }     long long s = 1, e = n, ans = -1;     while (s <= e) {       long long mid = (s + e) / 2, sum = 0;       vector<pair<long long, long long> > edge;       long long mx = 0;       for (long long i = 0; i < n; i++) {         if (l[i] <= mid && c[i] != 1) {           sum += p[i];           edge.push_back({p[i], c[i]});         }         if (c[i] == 1 && l[i] <= mid) {           mx = max(mx, p[i]);         }       }       if (mx) edge.push_back({mx, 1});       sum += mx;       MaxFlow M((long long)((edge).size()) + 4);       long long src = (long long)((edge).size()),                 sink = (long long)((edge).size()) + 1;       for (long long i = 0; i < (long long)((edge).size()); i++) {         for (long long j = i + 1; j < (long long)((edge).size()); j++) {           if (!pr[edge[i].second + edge[j].second]) {             if (edge[i].second % 2)               M.AddEdge(i, j, edge[i].first);             else               M.AddEdge(j, i, edge[j].first);           }         }         if (edge[i].second % 2)           M.AddEdge(src, i, edge[i].first);         else           M.AddEdge(i, sink, edge[i].first);       }       long long flow = M.Flow(src, sink, sink + 4);       if (sum - flow >= k) {         ans = mid;         e = mid - 1;       } else         s = mid + 1;     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     start = clock();     cout << fixed << setprecision(20);     seive();     for (long long i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1 << 13;   const int N = 13;   long long dp[M][N][2][2];   bool used[M][N][2][2];   vector<int> digits_hour, digits_minuts;   long long solve(int mask, int pos, bool flag1, bool flag2) {     int h = digits_hour.size();     int min = digits_minuts.size();     if (pos == h + min) {       return 1LL;     }     long long &ans = dp[mask][pos][flag1][flag2];     if (used[mask][pos][flag1][flag2]) {       return ans;     }     used[mask][pos][flag1][flag2] = true;     if (pos >= h) {       for (int t = 0; t < 7; t++) {         int el = 1 << t;         if ((mask & el) == 0) {           if (flag2 || digits_minuts[pos - h] >= t) {             ans += solve(mask | el, pos + 1, flag1,                          flag2 || (digits_minuts[pos - h] > t));           }         }       }     } else {       for (int t = 0; t < 7; t++) {         int el = 1 << t;         if ((mask & el) == 0) {           if (flag1 || digits_hour[pos] >= t) {             ans +=                 solve(mask | el, pos + 1, flag1 || (digits_hour[pos] > t), flag2);           }         }       }     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     scanf( %d %d , &n, &m);     n--, m--;     if (n == 0) {       digits_hour.push_back(0);     }     if (m == 0) {       digits_minuts.push_back(0);     }     while (n) {       digits_hour.push_back(n % 7);       n /= 7;     }     reverse(digits_hour.begin(), digits_hour.end());     while (m) {       digits_minuts.push_back(m % 7);       m /= 7;     }     reverse(digits_minuts.begin(), digits_minuts.end());     printf( %lld n , solve(0, 0, false, false));     return 0;   }


#include <bits/stdc++.h>   using std::map;   long long n;   long long p2[100005 * 2] = {1};   long long fa[100005 * 2], size[100005 * 2], p[100005 * 2];   long long vis[100005 * 2];   map<long long, long long> mx, my;   long long cnt;   long long ans = 1;   long long getfa(long long x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }   int main() {     scanf( %I64d , &n);     for (long long i = 1; i <= n * 2; i++) {       fa[i] = i;       size[i] = 1;       p2[i] = (p2[i - 1] * 2) % ((int)1e9 + 7);     }     long long x, y, px, py, fx, fy;     for (long long i = 1; i <= n; i++) {       scanf( %I64d %I64d , &x, &y);       if (mx.find(x) == mx.end()) {         mx[x] = ++cnt;       }       if (my.find(y) == my.end()) {         my[y] = ++cnt;       }       px = mx[x];       py = my[y];       fx = getfa(px);       fy = getfa(py);       if (fx == fy) {         p[fx] = 1;       } else {         fa[fx] = fy;         size[fy] += size[fx];         p[fy] |= p[fx];       }       getfa(px);     }     for (long long i = 1; i <= cnt; i++) {       long long fi = getfa(i);       if (vis[fi]) continue;       vis[fi] = 1;       if (p[fi]) {         ans *= p2[size[fi]];       } else {         ans *= (p2[size[fi]] - 1);       }       ans %= ((int)1e9 + 7);     }     printf( %I64d n , ans);   }


//愿你和你重要的人能够重逢！   #include<bits/stdc++.h>   using namespace std;   template<typename T>inline void read(T &x)   {    x=0;char c=getchar(),f=0;    for(;c<48||c>57;c=getchar()) if(!(c^45)) f=1;    for(;c>=48&&c<=57;c=getchar()) x=(x<<1)+(x<<3)+(c^48);    f?x=-x:0;   }   long long l,r,st,t,x,y;set<long long>s;   int main()   {    read(st),read(l),read(r),read(t),read(x),read(y);    if(x>y)    {     if((x-y<2e18/t&&st-l>=t*(x-y))&&st+y<=r) puts( Yes );     else if(x-y<2e18/t&&st-l>=t*x-(t-1)*y) puts( Yes );     else puts( No );     return 0;    }    long long qwq=st,tp;qwq=l+(qwq-l)%x,t-=(st-qwq)/x;    if(t<=0) return puts( Yes ),0;else if(qwq+y>r) return puts( No ),0;    while(t>0)    {     qwq+=y;if(qwq>r) return puts( No ),0;else tp=qwq,qwq=l+(qwq-l)%x,t-=(tp-qwq)/x;     if(t<=0) return puts( Yes ),0;else if(s.count(qwq)) return puts( Yes ),0;else s.insert(qwq);    }    return puts( Yes ),0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, maxi;   string s =  ABRACADABRA ;   int main() {     cin >> n;     maxi = 0;     while (n--) {       cin >> x;       maxi = max(maxi, x);     }     cout << (maxi ^ x) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, w[200200], h[200200], W, a[200200], maxH, maxH2, id;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &w[i], &h[i]);       if (h[i] > maxH) {         maxH = h[i];         id = i;       }       W += w[i];     }     for (int i = 1; i <= n; ++i) {       if (i != id) maxH2 = max(maxH2, h[i]);     }     for (int i = 1; i <= n; ++i) {       if (h[i] == maxH)         printf( %d  , maxH2 * (W - w[i]));       else         printf( %d  , maxH * (W - w[i]));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[4], i, j, min = 1000, x, y;     for (i = 0; i < 4; i++) {       cin >> a[i];       if (min > a[i]) min = a[i];     }     cin >> x >> y;     if (x >= min) {       cout << 0;       return 0;     } else if (y < min) {       cout << y - x + 1;     } else {       cout << min - x;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y) {     long long int one = 1;     if (!y)       return one;     else if (y == 1)       return x;     else {       long long int y1 = power(x, y >> 1);       long long int y2 = y1 * y1;       if (y & 1)         return x * y2;       else         return y2;     }   }   bool comp(pair<int, int> a, pair<int, int> b) {     if (a.first != b.first)       return a.first < b.first;     else       return a.second > b.second;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, mx;     cin >> n >> mx;     long long int a[n];     map<long long int, long long int> occ;     for (int i = 0; i < n; i++) cin >> a[i], occ[a[i]]++;     long long int allow = 8 * mx;     allow /= n;     if (allow > 20) {       cout << 0;       return 0;     }     long long int dis = power(2, allow);     vector<pair<int, int> > give;     for (auto v : occ) give.push_back(make_pair(v.first, v.second));     long long int n1 = give.size();     sort(give.begin(), give.end(), comp);     long long int ans = INT_MAX;     long long int presum[n1];     presum[0] = give[0].second;     for (int i = 1; i < n1; i++) presum[i] = presum[i - 1] + give[i].second;     if (n1 <= dis) {       cout << 0;       return 0;     }     for (int i = 0; i <= n1 - dis; i++) {       int rem = 0;       if (i == 0)         rem = presum[i + dis - 1];       else         rem = presum[i + dis - 1] - presum[i - 1];       if (n - rem < ans) ans = n - rem;     }     cout << ans;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int MAX = 2e5 + 5;   const long long MAX2 = 11;   const long long MOD = 998244353;   const long long MOD2 = 1000000006;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 316;   int n, q, push_front[MAX], le[MAX], ri[MAX], l[MAX], r[MAX], cl[MAX], jlh[MAX],       cnt, a, b, len, id, ls;   long long hs[MAX], x[MAX], key, tmp, pj, t2;   bool z[MAX], st;   char c;   pair<long long, int> res;   inline pair<long long, int> f(int a, int b) {     if (a > b) return {0, 0};     int len = b - a + 1;     return {x[b] - x[a - 1] * hs[len], len};   }   inline pair<long long, int> comp(int a, int b) {     tmp = pj = st = 0;     if (z[a]) {       if (ri[a] - a + 1 & 1) ++pj;       a = ri[a] + 1;     }     if (z[b]) {       if (b - le[b] + 1 & 1) st = 1;       b = le[b] - 1;     }     if (cl[a] == cl[b]) {       tmp = l[a] + r[b] - jlh[cl[a]];       if (st) tmp *= key;       return {tmp, 1 + pj + st};     }     res = f(cl[a] + 1, cl[b] - 1);     tmp = (l[a] * hs[res.second] + res.first) * key + r[b];     if (st) tmp *= key;     return {tmp, cl[b] - cl[a] + 1 + pj + st};   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     key = 2000003153;     cin >> n;     hs[0] = 1;     for (int i = 1; i <= n; ++i) {       cin >> c, z[i] = (c ==  1 ), push_front[i] = push_front[i - 1] + z[i],                 hs[i] = hs[i - 1] * key;       if (z[i]) {         st ^= 1;         if (le[i - 1])           le[i] = le[i - 1];         else           le[i] = i;       } else {         if (st) {           jlh[id] = cnt;           x[id] = x[id - 1] * key + cnt;           st = cnt = 0;         }         if (cnt == 0) ++id;         ++cnt, r[i] = cnt;         cl[i] = id;       }     }     if (cnt) x[id] = x[id - 1] * key + cnt, jlh[id] = cnt;     ls = id;     cnt = 0;     for (int i = n; i >= 1; --i) {       if (z[i]) {         if (ri[i + 1])           ri[i] = ri[i + 1];         else           ri[i] = i;       } else {         if (cl[i] != ls) cnt = 0, ls = cl[i];         l[i] = ++cnt;       }     }     cin >> q;     while (q--) {       cin >> a >> b >> len;       if (push_front[a + len - 1] - push_front[a - 1] !=           push_front[b + len - 1] - push_front[b - 1]) {         cout <<  No n ;         continue;       }       if (push_front[a + len - 1] - push_front[a - 1] == 0 ||           push_front[a + len - 1] - push_front[a - 1] == len) {         cout <<  Yes n ;         continue;       }       if (comp(a, a + len - 1) == comp(b, b + len - 1))         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }


#include <iostream>   #include <cmath>   using namespace std;   int t, n, a[105];   int main(){    cin>>t;    while(t--){     cin>>n;     int suc = 0;     for(int i=0; i<n; i++)      cin>>a[i];     for(int i=0; i<n; i++){      int k = (int)sqrt((double)a[i]);      if(k*k != a[i]){       suc = 1;       break;      }     }     if(suc)      cout<< YES <<endl;     else      cout<< NO <<endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2600, MAXL = 10000 * 5 + 10, MAXALP = 26;   int n, f[MAXN][MAXN], cnt[MAXALP], p[MAXN][MAXN];   char str[MAXL];   pair<int, int> Tohka;   string Houki;   void Print(const pair<int, int> &a, int res) {     if (res <= 0) return;     if (p[a.first][a.second] == -1)       Print(make_pair(a.first - 1, a.second), res);     else if (p[a.first][a.second] == 1)       Print(make_pair(a.first, a.second + 1), res);     else {       Print(make_pair(a.first - 1, a.second + 1),             res - 2 + (a.first == a.second));       if (res <= 100) Houki += str[a.first];     }   }   int main() {     scanf( %s , str + 1);     n = strlen(str + 1);     if (n >= 2600) {       for (int i = 1; i <= n; ++i) ++cnt[str[i] -  a ];       for (int i = 0; i < MAXALP; ++i)         if (cnt[i] >= 100) {           for (int j = 0; j < 100; ++j) printf( %c ,  a  + i);           exit(0);         }     }     for (int i = 1; i <= n; ++i)       for (int j = n; j >= i; --j) {         f[i][j] = f[i - 1][j], p[i][j] = -1;         if (f[i][j] < f[i][j + 1]) f[i][j] = f[i][j + 1], p[i][j] = 1;         if (str[i] == str[j] && f[i][j] < f[i - 1][j + 1] + 1)           f[i][j] = f[i - 1][j + 1] + 1, p[i][j] = 0;         if (f[i][j] * 2 - (i == j) >             f[Tohka.first][Tohka.second] * 2 - (Tohka.first == Tohka.second))           Tohka = make_pair(i, j);       }     Print(Tohka,           f[Tohka.first][Tohka.second] * 2 - (Tohka.first == Tohka.second));     string rev =         Houki.substr(0, Houki.size() - (Tohka.first == Tohka.second &&                                         f[Tohka.first][Tohka.second] * 2 -                                                 (Tohka.first == Tohka.second) <=                                             100));     reverse(rev.begin(), rev.end());     Houki += rev;     cout << Houki << endl;     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int ls[N << 2], rs[N << 2], rt[N << 2], sum[N << 2];   int rcnt;   void update(int &rt, int l, int r, int pos) {     if (rt == 0) rt = ++rcnt;     if (l == r) {       sum[rt]++;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid) {       update(ls[rt], l, mid, pos);     } else {       update(rs[rt], mid + 1, r, pos);     }     sum[rt] = sum[ls[rt]] + sum[rs[rt]];   }   int query(int &rt, int l, int r, int ql, int qr) {     if (rt == 0) return 0;     if (ql <= l && qr >= r) return sum[rt];     int mid = (l + r) >> 1, res = 0;     if (ql <= mid) res += query(ls[rt], l, mid, ql, qr);     if (qr > mid) res += query(rs[rt], mid + 1, r, ql, qr);     return res;   }   int n, k;   struct node {     int x, r, f;     bool operator<(const node &z) const { return r > z.r; }   } a[N];   const int low = 1000000000;   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d %d %d , &a[i].x, &a[i].r, &a[i].f);     }     sort(a + 1, a + n + 1);     long long ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j = a[i].f - k; j <= a[i].f + k; ++j) {         if (j < 1 || j > 10000) continue;         ans += query(rt[j], 1, low, max(1, a[i].x - a[i].r),                      min(low, a[i].x + a[i].r));       }       update(rt[a[i].f], 1, low, a[i].x);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-12;   const int N = 100000 + 10;   long double sqr(long double x) { return x * x; }   struct PT {     long double x, y;     PT(long double x = 0, long double y = 0) : x(x), y(y) {}     void in() {       double xx, yy;       scanf( %lf%lf , &xx, &yy);       x = xx, y = yy;     }   } P[N];   bool operator<(const PT& p1, const PT& p2) {     if (fabs(p1.x - p2.x) > EPS) return p1.x < p2.x;     return p1.y + EPS < p2.y;   }   bool operator==(const PT& p1, const PT& p2) {     return fabs(p1.x - p2.x) < EPS && fabs(p1.y - p2.y) < EPS;   }   PT operator+(PT p1, PT p2) { return PT(p1.x + p2.x, p1.y + p2.y); }   PT operator-(PT p1, PT p2) { return PT(p1.x - p2.x, p1.y - p2.y); }   PT operator*(PT p, long double c) { return PT(p.x * c, p.y * c); }   PT operator/(PT p, long double c) { return PT(p.x / c, p.y / c); }   long double dis(PT p) { return sqrt(sqr(p.x) + sqr(p.y)); }   long double dis2(PT p) { return sqr(p.x) + sqr(p.y); }   long double dis2(PT p1, PT p2) { return sqr(p1.x - p2.x) + sqr(p1.y - p2.y); }   long double dis(PT p1, PT p2) { return sqrt(dis2(p1, p2)); }   long double vect(PT p1, PT p2) { return p1.x * p2.y - p2.x * p1.y; }   long double scal(PT p1, PT p2) { return p1.x * p2.x + p1.y * p2.y; }   long double getAngle(PT p) { return atan2(p.y, p.x); }   long double vect(PT p, PT p1, PT p2) { return vect(p1 - p, p2 - p); }   long double scal(PT p, PT p1, PT p2) { return scal(p1 - p, p2 - p); }   long double getAngle(PT p, PT p1, PT p2) {     return acos(scal(p, p1, p2) / dis(p, p1) / dis(p, p2));   }   long double disToLineSgn(PT p, PT p1, PT p2) {     return vect(p, p1, p2) / dis(p1, p2);   }   long double r[N];   PT P1, P2;   vector<pair<long double, long double> > vec[2];   int main() {     P1.in(), P2.in();     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       P[i].in();       double rr;       scanf( %lf , &rr);       r[i] = rr;     }     PT M = (P1 + P2) / 2;     long double a = dis(P1, P2) / 2;     int flg = 0;     for (int i = 0; i < n; i++) {       long double d = disToLineSgn(P[i], P1, P2);       long double l2 = dis2(M, P[i]);       long double p = l2 - sqr(a) - sqr(r[i]);       long double A = 4 * (sqr(d) - sqr(r[i]));       long double B = -4 * d * p;       long double C = sqr(p) - 4 * sqr(a * r[i]);       long double D = B * B - 4 * A * C;       if (D < EPS) continue;       long double x1 = (-B - sqrt(D)) / (2 * A), x2 = (-B + sqrt(D)) / (2 * A);       if (x2 < EPS)         vec[0].push_back(pair<long double, long double>(-x2, -x1));       else if (x1 > -EPS)         vec[1].push_back(pair<long double, long double>(x1, x2));       else {         flg = 1;         vec[0].push_back(pair<long double, long double>(0, -x1));         vec[1].push_back(pair<long double, long double>(0, x2));       }     }     if (!flg) return printf( %.10lf n , (double)a), 0;     for (int i = 0; i < 2; i++) sort(vec[i].begin(), vec[i].end());     long double ans = 1e60;     for (int i = 0; i < 2; i++) {       long double prv = EPS * 2;       for (auto it : vec[i]) {         if (it.first < prv - EPS)           prv = max(prv, it.second);         else {           ans = min(ans, prv);           break;         }       }       ans = min(ans, prv);     }     printf( %.10lf n , (double)sqrt(sqr(ans) + sqr(a)));   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-12;   const int inf = 2000000000;   const long long int infLL = (long long int)2e18;   long long int MOD = 1000000007;   int MOD1 = 1000000007;   int MOD2 = 1000000009;   inline bool checkBit(long long int n, long long int i) {     return n & (1LL << i);   }   inline long long int setBit(long long int n, long long int i) {     return n | (1LL << i);     ;   }   inline long long int resetBit(long long int n, long long int i) {     return n & (~(1LL << i));   }   int dx[] = {0, 0, +1, -1};   int dy[] = {+1, -1, 0, 0};   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline bool isLeapYear(long long int year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline void normal(long long int &a) {     a %= MOD;     (a < 0) && (a += MOD);   }   inline long long int modMul(long long int a, long long int b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a * b) % MOD;   }   inline long long int modAdd(long long int a, long long int b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a + b) % MOD;   }   inline long long int modSub(long long int a, long long int b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long int modPow(long long int b, long long int p) {     long long int r = 1LL;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1LL;     }     return r;   }   inline long long int modDiv(long long int a, long long int b) {     return modMul(a, modPow(b, MOD - 2));   }   bool comp(const pair<long long int, pair<long long int, long long int> > &p1,             const pair<long long int, pair<long long int, long long int> > &p2) {     return p1.first > p2.first;   }   bool comp1(const pair<long long int, long long int> &p1,              const pair<long long int, long long int> &p2) {     if (p1.first == p2.first) {       return p1.second > p2.second;     }     return p1.first < p2.first;   }   long long int converter(string a) {     long long int i, mul = 1, r, t, ans = 0LL;     if (a.length() == 0) return 0;     for (i = a.length() - 1; i >= 0; i--) {       t = a[i] -  0 ;       r = t % 10;       ans += (mul * r);       mul = mul * 10;     }     return ans;   }   int msb(unsigned x) {     union {       double a;       int b[2];     };     a = x;     return (b[1] >> 20) - 1023;   }   const int MAX = (int)2e5 + 5;   const int sz = (int)5e5 + 5;   int on[MAX], a[MAX], n, big[sz], cnt[sz];   long long int ans, tot;   void process() {     int i, j;     for (i = 2; i < sz; ++i) {       if (big[i]) continue;       for (j = i; j < sz; j += i) {         big[j] = i;       }     }   }   long long int cal(long long int val) { return (val * (val - 1)) / 2LL; }   void doo(int val, int pass) {     vector<int> store;     while (val > 1) {       int p = big[val];       store.push_back(p);       while (val % p == 0) val = val / p;     }     int nn = store.size(), i, j;     for (i = 1; i < (1 << nn); ++i) {       long long int now = 1LL;       for (j = 0; j < nn; ++j) {         if (i & (1 << j)) now *= store[j];       }       if (pass == 1) {         if (__builtin_popcountll(i) & 1)           ans += cnt[now];         else           ans -= cnt[now];         cnt[now]++;       } else {         cnt[now]--;         if (__builtin_popcountll(i) & 1)           ans -= cnt[now];         else           ans += cnt[now];       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int q, i, x;     process();     ans = 0LL;     cin >> n >> q;     for (i = 1; i <= n; ++i) cin >> a[i];     for (i = 1; i <= q; ++i) {       cin >> x;       if (on[x] == true)         doo(a[x], -1), --tot, on[x] = false;       else {         doo(a[x], 1), ++tot, on[x] = true;       }       cout << cal(tot) - ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int num = 0;     int a[100];     int i = 0;     int m = 0;     int yushu;     char hex[16] = { 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,                      8 ,  9 ,  A ,  B ,  C ,  D ,  E ,  F };     scanf( %d , &num);     if (num == 0) {       printf( 1 n );       return 0;     }     while (num > 0) {       yushu = num % 16;       a[i++] = yushu;       num = num / 16;     }     int output = 0;     for (i = i - 1; i >= 0; i--) {       m = a[i];       if (hex[m] ==  0 ) output++;       if (hex[m] ==  4 ) output++;       if (hex[m] ==  6 ) output++;       if (hex[m] ==  8 ) output += 2;       if (hex[m] ==  9 ) output++;       if (hex[m] ==  A ) output++;       if (hex[m] ==  B ) output += 2;       if (hex[m] ==  D ) output++;     }     printf( %d n , output);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const int mod = inf + 7;   const double eps = 1e-9;   const double pi = acos(-1.0);   int n, ind = -1;   int a[100100], b[100100];   pair<int, int> c[100100];   int v[100100], pos[100100];   vector<pair<int, int> > ans;   bool is_happy(int x) {     if (x == 0) return true;     int c = x % 10;     if (c != 4 && c != 7) return false;     return is_happy(x / 10);   }   void sw(int x, int y) {     if (x == y) return;     ans.push_back(make_pair(x, y));     swap(a[x], a[y]);     pos[a[x]] = x;     pos[a[y]] = y;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       b[i] = a[i];       c[i] = make_pair(a[i], i);       if (is_happy(a[i])) ind = i;     }     sort(b, b + n);     bool ok = 1;     for (int i = 0; i < n; i++) ok &= (a[i] == b[i]);     if (ok) {       printf( 0 n );       return 0;     }     if (ind == -1) {       if (ok)         printf( 0 n );       else         printf( -1 n );       return 0;     }     sort(c, c + n);     for (int i = 0; i < n; i++) a[c[i].second] = i;     for (int i = 0; i < n; i++) pos[a[i]] = i;     int x = a[ind];     for (int i = 0; i < n; i++) {       if (i == x) continue;       if (a[i] == i) continue;       int target = pos[i];       sw(ind, i);       ind = i;       sw(ind, target);       ind = target;     }     printf( %d n , (int)ans.size());     for (__typeof(ans.begin()) it = ans.begin(); it != ans.end(); it++) {       printf( %d %d n , it->first + 1, it->second + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100010], b[100010], ja[100010];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ja[a[i]] = i;     }     for (int i = 2; i <= n; i++) {       if (ja[i] > ja[i - 1])         b[i] = 1;       else         b[i] = 0;     }     int ad = 0;     for (int i = 1; i <= n; i++) {       int j = i;       while (b[j] == 1) j++;       ad = max(ad, j - i + 1);       i = j;     }     cout << n - ad << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 80005, maxe = 3000005, maxs = 80005, INF = 0x3f3f3f3f;   int n, q, N, m, S, T, a[maxn];   struct event {     int x, l, r, f;     event(int _x = 0, int _l = 0, int _r = 0, int _f = 0)         : x(_x), l(_l), r(_r), f(_f) {}     bool operator<(const event &b) const {       return x < b.x || x == b.x && f > b.f;     }   } E[maxs];   int son[maxe], nxt[maxe], lnk[maxn], flw[maxe], cap[maxe], tot = 1;   inline void add(int x, int y, int f) {     son[++tot] = y;     nxt[tot] = lnk[x];     lnk[x] = tot;     flw[tot] = 0;     cap[tot] = f;     son[++tot] = x;     nxt[tot] = lnk[y];     lnk[y] = tot;     flw[tot] = 0;     cap[tot] = 0;   }   int d[maxn], que[maxn], pos[maxn];   bool bfs() {     memset(d, 63, sizeof(d));     int hed = 0, til = 1;     que[1] = S;     d[S] = 0;     while (hed != til) {       int x = que[++hed];       for (int j = lnk[x]; j; j = nxt[j])         if (d[son[j]] == INF && flw[j] < cap[j])           d[que[++til] = son[j]] = d[x] + 1;     }     return d[T] != INF;   }   int dfs(int x, int flow) {     if (x == T || flow == 0) return flow;     int res = 0, f;     for (int &j = pos[x]; j; j = nxt[j])       if (d[son[j]] == d[x] + 1 &&           (f = dfs(son[j], min(flow, cap[j] - flw[j]))) > 0) {         flw[j] += f;         flw[j ^ 1] -= f;         res += f;         flow -= f;         if (flow == 0) break;       }     return res;   }   int dinic() {     int ans = 0;     while (bfs()) {       memcpy(pos, lnk, sizeof(lnk));       ans += dfs(S, INF);     }     return ans;   }   int ls[maxs], rs[maxs], Rx, Ry;   void build(int &x, int l, int r, int d) {     x = ++N;     if (l == r) {       if (d)         add(x, T, 1);       else         add(S, x, 1);       return;     }     int mid = l + r >> 1;     build(ls[x], l, mid, d);     build(rs[x], mid + 1, r, d);     if (d)       add(x, ls[x], INF), add(x, rs[x], INF);     else       add(ls[x], x, INF), add(rs[x], x, INF);   }   void qry(int x, int l, int r, int ql, int qr, int z, int d) {     if (ql <= l && r <= qr) {       if (d)         add(z, x, INF);       else         add(x, z, INF);       return;     }     if (qr < l || r < ql) return;     int mid = l + r >> 1;     qry(ls[x], l, mid, ql, qr, z, d);     qry(rs[x], mid + 1, r, ql, qr, z, d);   }   void cover(int x, int l, int r) {     for (int i = l; i <= r; i++) a[i] = x;   }   void work(int x, int l, int r) {     for (int i = l, j = l; i <= r; i = j) {       while (j <= r && a[i] == a[j]) j++;       N++;       qry(Rx, 1, n, a[i] + 1, x, N, 0);       qry(Ry, 1, n, i, j - 1, N, 1);     }   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= q; i++) {       int x, y, xx, yy;       scanf( %d%d%d%d , &x, &y, &xx, &yy);       E[++m] = event(x - 1, y, yy, 0);       E[++m] = event(xx, y, yy, 1);     }     S = ++N;     T = ++N;     build(Rx, 1, n, 0);     build(Ry, 1, n, 1);     sort(E + 1, E + 1 + m);     for (int i = 1; i <= m; i++)       if (E[i].f)         cover(E[i].x, E[i].l, E[i].r);       else         work(E[i].x, E[i].l, E[i].r);     work(n, 1, n);     printf( %d , dinic());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-8;   const int N = 1e5 + 10;   int n, q;   int sgn(long double x) { return x < -EPS ? -1 : x > EPS; }   struct Point {     Point() {}     long double x, y;     Point(long double x, long double y) : x(x), y(y) {}     void read() { cin >> x >> y; }     Point operator-(const Point& p) { return Point(x - p.x, y - p.y); }     long double operator*(const Point& p) { return x * p.x + y * p.y; }     long double operator^(const Point& p) { return x * p.y - y * p.x; }     long double length() { return hypotl(x, y); }   } poly[N];   using Vec = Point;   long double getIntersection(Point p, Vec v, Point q, Vec w) {     return (w ^ (p - q)) / (v ^ w);   }   long double work(Point p, Vec v) {     long double ret = 0;     vector<pair<long double, int> > pos;     for (int i = 1; i <= n; i++) {       int s1 = sgn(v ^ (poly[i] - p));       int s2 = sgn(v ^ (poly[i + 1] - p));       if (s1 == s2) continue;       long double o = getIntersection(p, v, poly[i], poly[i + 1] - poly[i]);       if (s1 > s2)         pos.push_back({o, s1 && s2 ? 2 : 1});       else         pos.push_back({o, s1 && s2 ? -2 : -1});     }     sort(pos.begin(), pos.end());     int flag = 0;     for (int i = 0; i + 1 < pos.size(); i++) {       flag += pos[i].second;       if (flag) ret += pos[i + 1].first - pos[i].first;     }     return ret * v.length();   }   int main() {     ios ::sync_with_stdio(false);     cin >> n >> q;     for (int i = 1; i <= n; i++) poly[i].read();     poly[n + 1] = poly[1];     while (q--) {       Point a, b;       a.read();       b.read();       cout << fixed << setprecision(20) << work(a, b - a) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     cin >> test;     while (test--) {       int i, n, k;       string s;       cin >> n;       cin >> s;       vector<pair<string, int> > ans;       for (i = 0; i < n; i++) {         string sl = s.substr(0, i);         string sr = s.substr(i, n - i);         if (i % 2 != n % 2) reverse(sl.begin(), sl.end());         ans.push_back(make_pair(sr + sl, i + 1));       }       sort(ans.begin(), ans.end());       cout << ans[0].first << endl << ans[0].second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string n, m;     int w = 0, b[10000];     cin >> n;     for (int i = 0; i < n.length(); i++) {       if (n.substr(i, 1) ==  r ) cout << i + 1 << endl;     }     for (int i = n.length() - 1; i >= 0; i--) {       if (n.substr(i, 1) ==  l ) cout << i + 1 << endl;     }     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned int max_ID(long long int a[], long long int b[], unsigned int n) {     unsigned int max_ID;     unsigned long long int max;     max_ID = 0;     max = pow(a[0] - b[0], 2);     for (unsigned int i = 1; i < n; i++) {       if (pow(a[i] - b[i], 2) > max) {         max_ID = i;         max = pow(a[i] - b[i], 2);       }     }     return max_ID;   }   int main() {     unsigned int n, k1, k2, ID;     unsigned long long int sum = 0;     cin >> n >> k1 >> k2;     long long int a[n], b[n];     for (unsigned int i = 0; i < n; i++) cin >> a[i];     for (unsigned int i = 0; i < n; i++) cin >> b[i];     while (k1 > 0 || k2 > 0) {       ID = max_ID(a, b, n);       if (pow((a[ID] - 1) - b[ID], 2) < pow(a[ID] - b[ID], 2)) {         if (k1 > 0) {           a[ID]--;           k1--;           continue;         }       }       if (pow(a[ID] - (b[ID] + 1), 2) < pow(a[ID] - b[ID], 2)) {         if (k2 > 0) {           b[ID]++;           k2--;           continue;         }       }       if (pow(a[ID] - (b[ID] - 1), 2) < pow(a[ID] - b[ID], 2)) {         if (k2 > 0) {           b[ID]--;           k2--;           continue;         }       }       if (pow((a[ID] + 1) - b[ID], 2) < pow(a[ID] - b[ID], 2)) {         if (k1 > 0) {           a[ID]++;           k1--;           continue;         }       }       if (pow(a[ID] - b[ID], 2) == 0) {         if (k1 > 0) {           a[ID]++;           k1--;         } else if (k2 > 0) {           b[ID]++;           k2--;         }       }     }     for (unsigned int i = 0; i < n; i++) {       sum += pow(a[i] - b[i], 2);     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   template <class T>   void Swap(T& a, T& b) {     a ^= b;     b ^= a;     a ^= b;   }   template <class type>   void show(type name) {     for (auto& nm : name) cerr << nm <<    ;     cerr <<   n ;   }   using lng = long long;   using ivec = vector<int>;   const int mxn = 10;   int check(ivec& nums, int n) {     int ans = 1e9;     for (int i = 0; i < (1 << (int)nums.size()); ++i) {       int cnt = 0;       for (int j = 0; j < (int)nums.size(); ++j) {         if ((i & (1 << j)) > 0) cnt += ceil(pow(3, nums[j]));       }       if (cnt >= n) ans = min(ans, cnt);     }     return ans;   }   int main() {     int q, n;     cin >> q;     while (q--) {       cin >> n;       ivec nums(min(n, mxn) + 1);       iota(begin(nums), end(nums), 0);       cout << check(nums, n) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     string s;     cin >> s;     int c[2];     c[0] = c[1] = 0;     const int m[] = {2, 1};     for (int i = 0; i < s.size(); i++) {       int d = s[i] -  0 ;       cout << ((c[d]++ * m[d]) % 4) + 1 <<     << d + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void __p(T a) {     cout << a;   }   template <typename T, typename F>   void __p(pair<T, F> a) {     cout <<  { ;     __p(a.first);     cout <<  , ;     __p(a.second);     cout <<  } n ;   }   template <typename T>   void __p(std::vector<T> a) {     cout <<  { ;     for (auto it = a.begin(); it < a.end(); it++)       __p(*it), cout <<  ,} n [it + 1 == a.end()];   }   template <typename T, typename... Arg>   void __p(T a1, Arg... a) {     __p(a1);     __p(a...);   }   template <typename Arg1>   void __f(const char *name, Arg1 &&arg1) {     cout << name <<   :  ;     __p(arg1);     cout <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char *names, Arg1 &&arg1, Args &&...args) {     int bracket = 0, i = 0;     for (;; i++)       if (names[i] ==  ,  && bracket == 0)         break;       else if (names[i] ==  ( )         bracket++;       else if (names[i] ==  ) )         bracket--;     const char *comma = names + i;     cout.write(names, comma - names) <<   :  ;     __p(arg1);     cout <<   |  ;     __f(comma + 1, args...);   }   void setIO(string s =   ) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin.exceptions(cin.failbit);     if (((int)(s).size())) {       freopen((s +  .in ).c_str(),  r , stdin);       freopen((s +  .out ).c_str(),  w , stdout);     }   }   const int dx[] = {1, 0, 0, -1};   const int dy[] = {0, -1, 1, 0};   const char C[] = { D ,  L ,  R ,  U };   signed main() {     setIO();     int n, m, K;     cin >> n >> m >> K;     if (K & 1) return cout <<  IMPOSSIBLE , 0;     char a[n][m];     int dis[n][m];     int si = -1, sj = -1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> a[i][j];         dis[i][j] = 1e9;         if (a[i][j] ==  X ) {           si = i, sj = j;           dis[si][sj] = 0;         }       }     }     priority_queue<pair<int, array<int, 2> > > q;     q.push({0, {si, sj}});     while (((int)(q).size())) {       int res = -q.top().first, i = q.top().second[0], j = q.top().second[1];       q.pop();       if (res != dis[i][j]) continue;       for (int k = 0; k < 4; ++k) {         int ni = i + dx[k], nj = j + dy[k];         if (ni >= 0 && ni < n && nj >= 0 && nj < m && a[ni][nj] !=  * ) {           if (dis[ni][nj] > dis[i][j] + 1) {             dis[ni][nj] = dis[i][j] + 1;             q.push({-dis[ni][nj], {ni, nj}});           }         }       }     }     int i = si, j = sj;     string ans;     for (int x = K - 1; x >= 0; --x) {       for (int k = 0; k < 4; ++k) {         int ni = i + dx[k], nj = j + dy[k];         if (ni >= 0 && ni < n && nj >= 0 && nj < m && a[ni][nj] !=  * ) {           if (dis[ni][nj] <= x) {             i = ni, j = nj;             ans.push_back(C[k]);             break;           }         }       }     }     if (((int)(ans).size()) < K) {       return cout <<  IMPOSSIBLE , 0;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       vector<string> v(n);       string s;       for (int i = 0; i < n; ++i) {         cin >> v[i];         for (int j = 0; j < v[i].size(); ++j) {           if (v[i][j] >=  A  && v[i][j] <=  Z ) v[i][j] = v[i][j] -  A  +  a ;         }       }       cin >> s;       string ans = s;       for (int j = 0; j < s.size(); ++j) {         if (s[j] >=  A  && s[j] <=  Z ) s[j] = s[j] -  A  +  a ;       }       char lovable;       cin >> lovable;       if (lovable >=  A  && lovable <=  Z ) lovable = lovable -  A  +  a ;       vector<pair<int, int> > segments;       for (int i = 0; i < n; ++i)         for (int j = 0; j + v[i].size() <= s.size(); ++j)           if (s.substr(j, v[i].size()) == v[i])             segments.push_back(make_pair(j, j + v[i].size() - 1));       sort(segments.begin(), segments.end());       vector<pair<int, int> > final_segments;       for (int i = 0; i < segments.size();) {         pair<int, int> curr = segments[i];         int j = i;         while (j < segments.size() && segments[j].first <= curr.second) {           curr.second = max(curr.second, segments[j].second);           ++j;         }         final_segments.push_back(curr);         i = j;       }       for (int i = 0; i < final_segments.size(); ++i) {         for (int j = final_segments[i].first; j <= final_segments[i].second;              ++j) {           char c = ans[j];           if (c >=  A  && c <=  Z ) c = c -  A  +  a ;           if (c == lovable) {             char c_inv;             for (int i = 0; i < 26; ++i) {               if ( a  + i != lovable) {                 c_inv =  a  + i;                 break;               }             }             if (ans[j] >=  A  && ans[j] <=  Z )               ans[j] = c_inv -  a  +  A ;             else               ans[j] = c_inv;           } else {             if (ans[j] >=  A  && ans[j] <=  Z )               ans[j] = lovable -  a  +  A ;             else               ans[j] = lovable;           }         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   struct heap {     int heapsize;     int arr[100009];   };   void max_heapify(struct heap *c, int i, int *array) {     if (c->heapsize == 0) return;     int smallest, tmp;     if (((2 * i) <= c->heapsize) && (array[c->arr[2 * i]] > array[c->arr[i]]))       smallest = 2 * i;     else       smallest = i;     if (((2 * i + 1) <= c->heapsize) &&         (array[c->arr[2 * i + 1]] > array[c->arr[smallest]]))       smallest = 2 * i + 1;     if (smallest == i) return;     tmp = c->arr[i];     c->arr[i] = c->arr[smallest];     c->arr[smallest] = tmp;     max_heapify(c, smallest, array);     return;   };   int extract_max(struct heap *c, int *array) {     if (c->heapsize == 0) return 0;     int max;     max = c->arr[1];     c->arr[1] = c->arr[c->heapsize];     (c->heapsize)--;     max_heapify(c, 1, array);     return max;   };   void insert(struct heap *c, int *array, int key) {     int tmp;     c->heapsize = c->heapsize + 1;     c->arr[c->heapsize] = key;     int j = c->heapsize;     while (j > 1) {       if (array[c->arr[j]] > array[c->arr[j / 2]]) {         tmp = c->arr[j];         c->arr[j] = c->arr[j / 2];         c->arr[j / 2] = tmp;         j = j / 2;       } else         return;     }     return;   };   int main() {     int n, i, j, tmp;     scanf( %d , &n);     int array[n + 5];     struct heap aux;     aux.heapsize = 0;     char a[n + 5];     for (i = 1; i <= n; i++) {       scanf( %d , &array[i]);       a[i] = 48;     }     for (i = 1; i <= n; i++) {       if (array[i] != 0) {         insert(&aux, array, i);       } else if (array[i] == 0) {         j = 3;         while (j--) {           tmp = extract_max(&aux, array);           if (tmp > 0) a[tmp] = 49;         }         aux.heapsize = 0;       }     }     int count = 0;     for (i = 1; i <= n; i++) {       if (array[i] > 0 && a[i] == 49) {         count = count + 1;         if (count % 3 == 1)           printf( pushStack n );         else if (count % 3 == 2)           printf( pushQueue n );         else if (count % 3 == 0)           printf( pushFront n );       } else if (array[i] > 0 && a[i] == 48)         printf( pushBack n );       else if (array[i] == 0) {         if (count == 0)           printf( 0 n );         else if (count == 1) {           printf( 1 popStack n );           count = count - 1;         } else if (count == 2) {           printf( 2 popStack popQueue n );           count = count - 2;         } else if (count >= 3) {           printf( 3 popStack popQueue popFront n );           count = count - 3;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 10;   const long long mod = 1e9 + 7;   const long long inf = 1e18 + 10;   long long n, L, k;   string s, ans[N];   int ptr;   void doIt(int l, int r) {     if (l + 1 == r) {       while (ans[l].size() < L) ans[l] += s[ptr], ptr++;       return;     }     char last = s[ptr];     while (1) {       for (int i = l; i < r; i++) {         if (s[ptr] != last) {           doIt(i, r);           return;         }         if (ans[i].size() == L) return;         ans[i] += s[ptr];         last = s[ptr];         ptr++;       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> L >> k >> s;     sort(s.begin(), s.end());     doIt(0, k);     for (int i = 0; i < n; i++)       while (ans[i].size() < L) ans[i] += s[ptr], ptr++;     sort(ans, ans + n);     for (int i = 0; i < n; i++) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int l[100100];   int d[100100];   map<int, vector<int> > p;   int cntd[202] = {0};   int main(int argc, char** argv) {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> l[i];     for (int i = 0; i < n; i++) cin >> d[i];     for (int i = 0; i < n; i++) {       cntd[d[i]]++;       p[l[i]].push_back(d[i]);     }     int sumcnt = 0;     int sumval = 0;     int ans = 1e9;     int m = n;     for (map<int, vector<int> >::reverse_iterator it = p.rbegin(); it != p.rend();          it++) {       int j = 0;       for (int i = 0; i < it->second.size(); i++) {         cntd[it->second[i]]--;       }       j = 0;       int need = m - (2 * (it->second.size())) + 1;       int deleted = 0;       while (j <= 201 && need > 0) {         if (cntd[j] != 0) {           deleted += ((min(need, cntd[j])) * j);           need -= min(need, cntd[j]);         }         j++;       }       ans = min(ans, sumval + deleted);       m -= it->second.size();       for (int i = 0; i < it->second.size(); i++) {         sumval += (it->second[i]);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long long infl = 2e18;   const long long infi = 1e9;   const long long mod = 1000000007;   auto clk = clock();   mt19937_64 rang(       chrono::high_resolution_clock::now().time_since_epoch().count());   long long rng(long long lim) {     uniform_int_distribution<long long> uid(0, lim - 1);     return uid(rang);   }   long long powm(long long a, long long b) {     long long res = 1;     a %= mod;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   const long long N = 55;   long long dp[N][N][N][4];   vector<long long> sg[4];   long long knap[4][N][N * N];   long long fact[N];   long long inpe[N];   long long answ[N][N][N * N];   struct base {     long double x, y;     base() { x = y = 0; }     base(long double _x, long double _y) { x = _x, y = _y; }     base(long double _x) { x = _x, y = 0; }     void operator=(long double _x) { x = _x, y = 0; }     long double real() { return x; }     long double imag() { return y; }     base operator+(const base& b) { return base(x + b.x, y + b.y); }     void operator+=(const base& b) { x += b.x, y += b.y; }     base operator*(const base& b) {       return base(x * b.x - y * b.y, x * b.y + y * b.x);     }     void operator*=(const base& b) {       long double p = x * b.x - y * b.y, q = x * b.y + y * b.x;       x = p, y = q;     }     void operator/=(long double k) { x /= k, y /= k; }     base operator-(const base& b) { return base(x - b.x, y - b.y); }     void operator-=(const base& b) { x -= b.x, y -= b.y; }     base conj() { return base(x, -y); }     base operator/(long double k) { return base(x / k, y / k); }     void Print() { cerr << x <<   +   << y <<  i n ; }   };   long double PI = 2.0 * acosl(0.0);   const long long MAXN = 14;   const long long maxn = (1 << MAXN);   base W[maxn], invW[maxn], P1[maxn], Q1[maxn];   void precompute_powers() {     for (long long i = 0; i < maxn / 2; i++) {       long double ang = (2 * PI * i) / maxn;       long double _cos = cos(ang), _sin = sin(ang);       W[i] = base(_cos, _sin);       invW[i] = base(_cos, -_sin);     }   }   void fft(vector<base>& a, bool invert) {     long long n = (long long)a.size();     for (long long i = 1, j = 0; i < n; ++i) {       long long bit = n >> 1;       for (; j >= bit; bit >>= 1) j -= bit;       j += bit;       if (i < j) swap(a[i], a[j]);     }     for (long long len = 2; len <= n; len <<= 1) {       for (long long i = 0; i < n; i += len) {         long long ind = 0, add = maxn / len;         for (long long j = 0; j < len / 2; ++j) {           base u = a[i + j],                v = (a[i + j + len / 2] * (invert ? invW[ind] : W[ind]));           a[i + j] = (u + v);           a[i + j + len / 2] = (u - v);           ind += add;         }       }     }     if (invert)       for (long long i = 0; i < n; ++i) a[i] /= n;   }   void mul_big_mod(vector<long long>& a, vector<long long>& b, long long mod) {     long long n1 = a.size(), n2 = b.size();     long long final_size = a.size() + b.size() - 1;     long long n = 1;     while (n < final_size) n <<= 1;     vector<base> P(n), Q(n);     long long SQRTMOD = (long long)sqrt(mod) + 10;     for (long long i = 0; i < n1; i++)       P[i] = base(a[i] % SQRTMOD, a[i] / SQRTMOD);     for (long long i = 0; i < n2; i++)       Q[i] = base(b[i] % SQRTMOD, b[i] / SQRTMOD);     fft(P, 0);     fft(Q, 0);     base A1, A2, B1, B2, X, Y;     for (long long i = 0; i < n; i++) {       X = P[i];       Y = P[(n - i) % n].conj();       A1 = (X + Y) * base(0.5, 0);       A2 = (X - Y) * base(0, -0.5);       X = Q[i];       Y = Q[(n - i) % n].conj();       B1 = (X + Y) * base(0.5, 0);       B2 = (X - Y) * base(0, -0.5);       P1[i] = A1 * B1 + A2 * B2 * base(0, 1);       Q1[i] = A1 * B2 + A2 * B1;     }     for (long long i = 0; i < n; i++) P[i] = P1[i], Q[i] = Q1[i];     fft(P, 1);     fft(Q, 1);     a.resize(final_size);     for (long long i = 0; i < final_size; i++) {       long long x = (long long)(P[i].real() + 0.5);       long long y = (long long)(P[i].imag() + 0.5) % mod;       long long z = (long long)(Q[i].real() + 0.5);       a[i] = (x + ((y * SQRTMOD + z) % mod) * SQRTMOD) % mod;     }   }   void solve() {     precompute_powers();     fact[0] = 1;     for (long long i = 1; i < N; i++) fact[i] = (fact[i - 1] * i) % mod;     dp[0][0][0][0] = 1;     for (long long i = 0; i <= 50; i++)       for (long long j = 0; j <= 50; j++)         for (long long k = 0; k <= 50; k++) {           for (long long l = 0; l <= 3; l++)             if (l != 1) {               dp[i + 1][j][k][1] += dp[i][j][k][l];               dp[i + 1][j][k][1] %= mod;             }           for (long long l = 0; l <= 3; l++)             if (l != 2) {               dp[i][j + 1][k][2] += dp[i][j][k][l];               dp[i][j + 1][k][2] %= mod;             }           for (long long l = 0; l <= 3; l++)             if (l != 3) {               dp[i][j][k + 1][3] += dp[i][j][k][l];               dp[i][j][k + 1][3] %= mod;             }         }     long long n, t;     cin >> n >> t;     for (long long i = 1; i <= n; i++) {       long long ti, gi;       cin >> ti >> gi;       sg[gi].push_back(ti);     }     for (long long j = 1; j <= 3; j++) {       knap[j][0][0] = 1;       for (long long i : sg[j]) {         for (long long l = ((long long)sg[j].size()) - 1; l >= 0; l--)           for (long long k = t - i; k >= 0; k--) {             knap[j][l + 1][k + i] += knap[j][l][k];             knap[j][l + 1][k + i] %= mod;           }       }     }     for (long long i = 1; i <= 3; i++)       for (long long j = 0; j <= ((long long)sg[i].size()); j++)         for (long long k = 0; k <= t; k++)           knap[i][j][k] = (knap[i][j][k] * fact[j]) % mod;     long long ans = 0;     if (((long long)sg[1].size()) > ((long long)sg[3].size())) {       swap(sg[1], sg[3]);       swap(knap[1], knap[3]);     }     if (((long long)sg[2].size()) > ((long long)sg[3].size())) {       swap(sg[2], sg[3]);       swap(knap[2], knap[3]);     }     vector<long long> ho1(t + 1), ho2(t + 1), res;     for (long long i = 0; i <= ((long long)sg[1].size()); i++) {       for (long long j = 0; j <= ((long long)sg[2].size()); j++) {         ho1.resize(t + 1);         for (long long k = 0; k <= t; k++) {           ho1[k] = knap[1][i][k];           ho2[k] = knap[2][j][k];         }         mul_big_mod(ho1, ho2, mod);         for (long long k = 0; k <= t; k++) answ[i][j][k] = ho1[k];       }     }     for (long long i = 0; i <= ((long long)sg[1].size()); i++) {       for (long long j = 0; j <= ((long long)sg[2].size()); j++) {         for (long long k = 0; k <= ((long long)sg[3].size()); k++) {           for (long long l = 0; l <= t; l++) {             long long o = t - l;             long long te =                 dp[i][j][k][0] + dp[i][j][k][1] + dp[i][j][k][2] + dp[i][j][k][3];             te = (te * answ[i][j][l]) % mod;             ans = (ans + te * knap[3][k][o]) % mod;           }         }       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     srand(chrono::high_resolution_clock::now().time_since_epoch().count());     cout << fixed << setprecision(10);     long long t = 1;     for (long long i = 1; i <= t; i++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   void solve() {     long long int a, s;     cin >> a >> s;     vector<long long int> b;     while (s) {       long long int x = a % 10;       long long int y = s % 10;       if (y >= x) {         b.push_back(y - x);       } else {         s /= 10;         y += 10 * (s % 10);         if (y > x && y <= 18 && y >= 10) {           b.push_back(y - x);         } else {           cout << -1 <<   n ;           return;         }       }       s /= 10;       a /= 10;     }     if (a) {       cout << -1 <<   n ;       return;     }     while (b.back() == 0) b.pop_back();     reverse((b).begin(), (b).end());     for (long long int x : b) cout << x;     cout <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int T = 1;     cin >> T;     for (long long int i = 1; i <= T; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       int n, p;       scanf( %d%d , &n, &p);       for (int i = 0; i < n; i++) printf( %d %d n , i + 1, (i + 1) % n + 1);       for (int i = 0; i < n; i++) printf( %d %d n , i + 1, (i + 2) % n + 1);       int k = 3;       while (p) {         for (int i = 0; i < n && p + 0; i++) {           p--;           printf( %d %d n , i + 1, (i + k) % n + 1);         }         k++;       }     }   }


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


#include <bits/stdc++.h>   const double EPS = 0.0000000001;   const long long mod1 = 998244353;   const long long mod2 = 1000000007;   const long long mod3 = 1000000009;   const long long mod4 = 228228227;   const long long inf = 100000000000000;   using namespace std;   signed main() {     long long t;     cin >> t;     for (long long q = 0; q < t; q++) {       long long n, a, b;       cin >> n >> a >> b;       vector<long long> v(n);       for (long long i = 0; i < n; i++) cin >> v[i];       sort(v.begin(), v.end());       long long dp[n];       dp[0] = v[0];       for (long long i = 1; i < n; i++) {         dp[i] = inf;         if ((i - b) == -1) {           dp[i] = v[i];         }         if ((i - b) >= 0) dp[i] = dp[i - b] + v[i];         dp[i] = min(dp[i], dp[i - 1] + v[i]);       }       for (long long i = n - 1; i >= 0; i--) {         if (dp[i] <= a) {           cout << i + 1 << endl;           break;         }       }       if (dp[0] > a) cout << 0 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   class Triplet {    public:     long long x;     long long y;     long long gcd;   };   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   Triplet extendedEuclid(long long a, long long b) {     if (b == 0) {       Triplet ans;       ans.gcd = a;       ans.x = 1;       ans.y = 0;       return ans;     }     Triplet smallAns = extendedEuclid(b, a % b);     Triplet ans;     ans.gcd = smallAns.gcd;     ans.x = smallAns.y;     ans.y = smallAns.x - (a / b) * smallAns.y;     return ans;   }   long long modulo(long long a, long long m) {     Triplet ans = extendedEuclid(a, m);     return ans.x;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, a;       cin >> n >> a;       long long arr[n];       long long maxi = 0;       bool found = false;       for (long long i = 0; i < n; i++) {         cin >> arr[i];         if (found) continue;         if (a % arr[i] == 0) {           if (a / arr[i] == 1) {             found = true;             maxi = arr[i];           }         }         maxi = max(maxi, arr[i]);       }       if (found) {         cout <<  1 n ;         continue;       } else {         if (maxi > a) {           cout <<  2 n ;           continue;         } else {           long long ans = (a / maxi);           if (a % maxi != 0) ans++;           cout << ans << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     cin >> q;     while (q--) {       long long pos;       cin >> pos;       if (pos == 1) {         cout << 1 << endl;         continue;       }       long long total = 0;       long long ant = 0;       long long desloc = 1;       long long vezes = 1;       while (true) {         ant += desloc;         if (total + ant > pos) break;         total += ant;         vezes++;         if (vezes == 10 or vezes == 100 or vezes == 1000 or vezes == 10000 or             vezes == 100000 or vezes == 1000000 or vezes == 10000000)           desloc++;       }       if (total == pos) {         cout << (vezes - 1) % 10 << endl;       } else {         bool ok = false;         for (int j = vezes;; j++) {           for (int i = 1; i <= vezes; i++) {             long long digitos = log10(i) + 1;             if (total + digitos < pos) {               total += digitos;             } else {               string base = to_string(i);               for (long long i = 0; i < base.size(); i++) {                 if (i + 1LL + total == pos) {                   ok = true;                   cout << base[i] << endl;                   break;                 }               }             }             if (ok) break;           }           if (ok) break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x;   long long f[1510], g[1510];   long long sum[1510];   int main() {     memset(f, 0, sizeof(f));     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %d , &x);       sum[0] = x;       for (int j = 1; j < m; ++j) {         scanf( %d , &x);         sum[j] = sum[j - 1] + x;       }       if (i == 0) {         for (int j = 0; j < m; ++j) f[j] = sum[j];       } else if ((i & 1) == 1) {         long long cm = f[m - 1];         for (int j = m - 2; j >= 0; --j) {           g[j] = sum[j] + cm;           cm = max(cm, f[j]);         }         for (int j = 0; j < m - 1; ++j) f[j] = g[j];       } else {         long long cm = f[0];         for (int j = 1; j < m; ++j) {           g[j] = sum[j] + cm;           cm = max(cm, f[j]);         }         for (int j = 1; j < m; ++j) f[j] = g[j];       }     }     long long ans = -9999999999999999ll;     if ((n & 1) == 0) {       for (int i = 0; i < m - 1; ++i) ans = max(f[i], ans);     } else {       for (int i = 1; i < m; ++i) ans = max(f[i], ans);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool yes(int a, int b, bool vis[10]) {     long long int temp = a;     while (temp > 0) {       int r = temp % 10;       if (vis[r] == true) {         return true;       }       temp /= 10;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     bool vis[10];     for (int i = 0; i <= 9; i++) {       vis[i] = false;     }     long long int temp = n;     while (n > 0) {       int r = n % 10;       vis[r] = true;       n /= 10;     }     n = temp;     long long int cnt = 0;     for (long long int i = 1; i * i <= n; i++) {       if (n % i == 0) {         if (yes(i, n, vis)) {           cnt++;         }         if (i * i != n) {           if (yes(n / i, n, vis)) {             cnt++;           }         }       }     }     cout << cnt <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   queue<int> que;   int n, k;   int main() {     while (cin >> n >> k) {       if (k == 0) {         cout << 1;         for (int i = 2; i < 2 * n + 1; i++) cout <<     << i;         cout << endl;         continue;       }       cout << k + 1;       for (int i = 1; i < 2 * n + 1; i++)         if (i != k + 1) que.push(i);       while (!que.empty()) {         cout <<     << que.front();         que.pop();       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100000];   int brr[100000];   int crr[100000];   int main() {     int n, l;     cin >> n >> l;     int flag = 0;     for (int i = 0; i < n; i++) cin >> arr[i];     for (int j = 0; j < n; j++) cin >> brr[j];     for (int i = 0; i < n; i++) {       crr[arr[i]] = 1;     }     int s = arr[0];     int x;     int fans = 1;     int z = 1;     if ((l - arr[n - 1] - 1) + (arr[0] - 0 + 1) == brr[1] - brr[0]) {       s = arr[n - 1];       for (int i = 1; i < n; i++) {         int diff = brr[i] - brr[i - 1];         s = (diff + s) % l;         if (crr[s] == 0) {           fans = 0;           break;         }       }       if (fans == 1) flag = 1;     }     z = 1;     while (z < n && flag == 0) {       int f2 = 1;       int f3 = 1;       while (z < n) {         if (arr[z] - arr[z - 1] == brr[1] - brr[0]) {           f2 = 0;           break;         }         z++;       }       if (f2 == 0) {         s = arr[z - 1];         for (int i = 1; i < n && f3; i++) {           int diff = brr[i] - brr[i - 1];           s = (diff + s) % l;           if (crr[s] == 0) {             f3 = 0;             break;           }         }         if (f3) {           z = n;           flag = 1;         }       }       z++;     }     if (n == 1)       cout <<  YES ;     else if (flag == 1)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5000 * 100 + 5;   int n, m, a, b, c, av, bv, cv, t, h[N], cnt, par[N], y, ans[N], cntA, col,       ca[N], o, uwu;   vector<int> adj[N], pa;   bool mark[N], vis[N], flag2, g[N];   void bfs(int v) {     queue<int> q;     par[v] = -1;     q.push(v);     flag2 = false;     while (q.size() && !flag2) {       v = q.front();       q.pop();       for (auto u : adj[v])         if (!par[u]) {           par[u] = v, q.push(u);           if (adj[u].size() % 3 == 1 && !flag2) y = u, flag2 = true;         }     }   }   void dfs3(int v, int co, int p = -1) {     pa.push_back(v);     if (!flag2)       for (auto u : adj[v])         if (u == bv && u != p) {           for (auto i : pa) vis[i] = true;           flag2 = true, uwu++;         }     for (auto u : adj[v])       if (u != p && !flag2 && ca[u] == co) dfs3(u, co, v), pa.pop_back();   }   void dfs(int v) {     ca[v] = col;     for (auto u : adj[v])       if (!ca[u] && u != bv) dfs(u);   }   void dfs2(int v, int p = -1) {     ans[cntA++] = v;     g[v] = true;     int l = 0;     bool flag = false;     for (auto u : adj[v])       if (h[u] > h[l] && u != p) {         l = u;       }     if (!cnt && l)       for (int i = 0; i < cntA; i++) {         if (l == ans[i]) flag = true;         if (flag) mark[ans[i]] = true, cnt++;       }     for (auto u : adj[v])       if (!cnt && !h[u] && adj[u].size() % 3 == 2)         h[u] = h[v] + 1, dfs2(u, v), ans[--cntA] = 0;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     cin >> t;     for (o = 1; o <= t; o++) {       cin >> n >> m;       for (int i = 0, v, u; i < m; i++) {         cin >> v >> u;         adj[v].push_back(u);         adj[u].push_back(v);       }       for (int i = 1; i <= n; i++) {         if (adj[i].size() % 3 == 0)           a++, av = i;         else if (adj[i].size() % 3 == 1)           b++, bv = i;         else           c++, cv = i;       }       if (a) {         if (n == 1)           cout <<  NO n ;         else {           cout <<  YES n  << n - 1 <<   n ;           for (int i = 1; i <= n; i++)             if (i != av) cout << i <<    ;         }       } else if (b > 1) {         bfs(bv);         while (par[y] != -1) mark[y] = true, y = par[y], cntA++;         mark[y] = true, cntA++;         if (cntA == n)           cout <<  NO n ;         else {           cout <<  YES n  << n - cntA <<   n ;           for (int i = 1; i <= n; i++)             if (!mark[i]) cout << i <<    ;           cout <<   n ;         }       } else {         fill(h, h + n + 1, 0);         cnt = 0;         for (int i = 1; i <= n; i++)           if (!g[i] && adj[i].size() % 3 == 2) h[i] = 1, cntA = 0, dfs2(i);         if (cnt == n)           cout <<  NO n ;         else if (cnt) {           cout <<  YES n  << n - cnt <<   n ;           for (int i = 1; i <= n; i++)             if (!mark[i]) cout << i <<    ;           cout <<   n ;         } else if (!cnt) {           bool flag = true;           if (b != 1) flag = false;           if (adj[bv].size() < 4) flag = false;           if (flag) {             cntA = 0, flag2 = false, col = 1;             fill(vis, vis + n + 1, false);             fill(h, h + n + 1, 0);             uwu = 0;             for (int i = 1; i <= n; i++) {               if (i != bv && !ca[i]) dfs(i), col++;             }             for (int i = 1; i < col && uwu < 2; i++) {               cntA = 0, flag2 = false, pa.clear();               dfs3(bv, i);             }             cnt = 0;             for (int i = 1; i <= n; i++) {               if (vis[i]) cnt++;             }             if (cnt == n || uwu != 2)               cout <<  NO n ;             else {               cout <<  YES n  << n - cnt <<   n ;               for (int i = 1; i <= n; i++)                 if (!vis[i]) cout << i <<    ;               cout <<   n ;             }           } else             cout <<  NO n ;         }       }       for (int i = 0; i <= n; i++)         adj[i].clear(), h[i] = par[i] = 0, vis[i] = mark[i] = false, ans[i] = 0,                         g[i] = false, ca[i] = 0;       a = b = c = av = bv = cv = 0, cnt = 0, y = 0, flag2 = false, cntA = 0;     }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return a * (b / gcd(a, b)); }   int cx[] = {-1, 1, 0, 0, 1, 1, -1, -1};   int cy[] = {0, 0, -1, 1, -1, 1, -1, 1};   bool is_possible(long long left, long long rigth) {     if (left <= rigth) return true;     return false;   }   int main() {     ios::sync_with_stdio(0);     int n;     long long l = -2 * 1000000000, number, r = 2 * 1000000000;     string option, answer;     cin >> n;     for (int i = (0), _b = ((n)-1); i <= _b; i++) {       cin >> option >> number >> answer;       if (option ==  >= ) {         if (answer ==  Y )           l = max(l, number);         else           r = min(r, number - 1);       } else if (option ==  <= ) {         if (answer ==  Y )           r = min(r, number);         else           l = max(l, number + 1);       } else if (option ==  > ) {         if (answer ==  Y )           l = max(l, number + 1);         else           r = min(r, number);       } else {         if (answer ==  Y )           r = min(r, number - 1);         else           l = max(l, number);       }       if (!is_possible(l, r)) {         cout <<  Impossible  << endl;         return 0;       }     }     cout << r << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long llinf = LLONG_MAX;   const int inf = INT_MAX;   const int nmax = 1e6 + 5;   const int mod = 1e9 + 7;   using namespace std;   int i, ans, x;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     cout.tie(0);     cin >> s;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  M )         x++;       else if (x)         ans = max(ans + 1, x);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100100];   bool c;   int main() {     cin >> n;     if (n == 1 || n == 2) {       cout << 0;       return 0;     }     for (int i = 1; i <= n; i++) cin >> a[i];     vector<int> cch;     vector<int> chh;     vector<int> aas;     aas.push_back(a[1]);     aas.push_back(a[2]);     aas.push_back(a[3]);     cch = aas;     sort(cch.begin(), cch.end());     chh = cch;     reverse(chh.begin(), chh.end());     if ((aas != cch) && (aas != chh)) {       cout << 3 << endl;       cout << 1 <<     << 2 <<     << 3;       return 0;     }     if (a[1] < a[2] || a[2] < a[3]) c = true;     if (a[1] == a[2] && a[2] == a[3]) {       int q = 4;       while (a[q] == a[3]) q++;       if (q == n) {         cout << 0;         return 0;       }       if (a[3] < a[q]) c = true;     }     for (int i = 4; i <= n; i++) {       if (((a[i] < a[i - 1]) && c) || ((a[i] > a[i - 1]) && (!c))) {         cout << 3 << endl << 1 <<     << i - 1 <<     << i;         return 0;       }     }     cout << 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, lst[3], mx[2];   long long ans, pos[300005];   char color;   inline char get() {     char in = getchar();     while (in !=  R  && in !=  G  && in !=  B ) {       in = getchar();     }     return in;   }   inline void did(int opt, int nowpos) {     if (lst[opt] != 0) {       ans += pos[nowpos] - pos[lst[opt]];       mx[opt] =           (mx[opt] > pos[nowpos] - pos[lst[opt]] ? mx[opt]                                                  : pos[nowpos] - pos[lst[opt]]);     }     lst[opt] = nowpos;   }   inline void did2(int nowpos) {     if (lst[2] != 0) {       ans += (0 < pos[nowpos] - pos[lst[2]] - mx[0] - mx[1]                   ? 0                   : pos[nowpos] - pos[lst[2]] - mx[0] - mx[1]);     }     lst[2] = nowpos;     mx[0] = 0;     mx[1] = 0;   }   int main() {     scanf( %d , &n);     for (register int i = 1; i <= n; i++) {       scanf( %d , &pos[i]);       color = get();       switch (color) {         case  R :           did(0, i);           break;         case  B :           did(1, i);           break;         case  G :           did(0, i);           did(1, i);           did2(i);           break;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s[6], S;   bool F;   int main() {     cin >> S;     for (int i = 1; i <= 5; ++i) cin >> s[i];     for (int i = 1; i <= 5; ++i)       if (s[i][0] == S[0] || s[i][1] == S[1]) F = 1;     puts(F ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX_A = 1e7;   const int N = 500000;   bool sieve[MX_A + 1];   pair<int, int> pr[MX_A + 1];   int a1[N], a2[N], arr[N];   void handleven(int i) {     int num = arr[i];     while (num % 2 == 0) num /= 2;     if (num != 1) {       a1[i] = 2;       a2[i] = num;     } else {       a1[i] = a2[i] = -1;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     for (int i = 2; i <= MX_A; i++) {       if (sieve[i]) continue;       for (int j = i; j <= MX_A; j += i) {         if (!pr[j].second) {           if (!pr[j].first) {             pr[j].first = i;           } else {             pr[j].second = i;           }         }         sieve[j] = true;       }     }     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i < n; i++) {       int num = arr[i];       if (arr[i] % 2 == 0) {         while (num % 2 == 0) num /= 2;         if (num != 1) {           a1[i] = 2;           a2[i] = num;         } else {           a1[i] = a2[i] = -1;         }       } else if (pr[arr[i]].second) {         a1[i] = pr[arr[i]].first;         a2[i] = pr[arr[i]].second;       } else {         a1[i] = a2[i] = -1;       }     }     for (int i = 0; i < n; i++) {       cout << a1[i] <<    ;     }     cout <<   n ;     for (int i = 0; i < n; i++) {       cout << a2[i] <<    ;     }     return 0;   }