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


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool chkmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <class T>   inline bool chkmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   inline long long Max(long long x, long long y) { return x > y ? x : y; }   inline long long Min(long long x, long long y) { return x < y ? x : y; }   int n, m;   long long fac[1002], inv[1002];   long long dp[47][1002], ans[1002][47];   void Add(long long &x, long long y) {     x += y;     if (x >= 1000000007) x -= 1000000007;   }   long long C(int n, int m) {     if (n < 0 || m > n) return 0;     return fac[n] * inv[m] % 1000000007 * inv[n - m] % 1000000007;   }   void Init() {     fac[0] = fac[1] = 1;     for (int i = (2), i_end_ = (1002); i < i_end_; i++)       fac[i] = fac[i - 1] * i % 1000000007;     inv[0] = inv[1] = 1;     for (int i = (2), i_end_ = (1002); i < i_end_; i++)       inv[i] = (1000000007 - (1000000007 / i)) * inv[1000000007 % i] % 1000000007;     for (int i = (2), i_end_ = (1002); i < i_end_; i++)       inv[i] = inv[i] * inv[i - 1] % 1000000007;     dp[0][0] = 1;     for (int i = (1), i_end_ = (47); i < i_end_; i++)       for (int j = (i * (i + 1) / 2), j_end_ = (1002); j < j_end_; j++)         Add(dp[i][j] = dp[i][j - i], dp[i - 1][j - i]);     for (int i = (1), i_end_ = (1002); i < i_end_; i++) {       for (int k = (1), k_end_ = (47); k < k_end_; k++) {         for (int j = (k * (k + 1) / 2), j_end_ = (i); j <= j_end_; j++)           Add(ans[i][k], C(i - j + k, k) * dp[k][j] % 1000000007);         ans[i][k] = ans[i][k] * fac[k] % 1000000007;       }     }   }   int main() {     Init();     int cas;     cin >> cas;     while (cas--) {       scanf( %d%d , &n, &m);       printf( %I64d n , m >= 45 ? 0 : ans[n][m]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100 * 1000 + 19;   const int MASK = 20;   const int inf = 2e9 + 19;   long long n, m, dp[1 << MASK][MASK + 1];   string s[MAX_N];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < m; i++) {       long long tmp = 0;       for (int j = 0; j < n; j++) tmp += ((1 << j) * (s[j][i] ==  1 ));       dp[tmp][0]++;     }     for (int i = 1; i <= n; i++) {       for (int j = i; j >= 1; j--) {         for (int mask = 0; mask < (1 << n); mask++)           dp[mask][j] += dp[mask ^ (1 << (i - 1))][j - 1];       }     }     long long ans = inf;     for (int mask = 0; mask < (1 << n); mask++) {       long long sum = 0;       for (long long j = 0; j <= n; j++) sum += dp[mask][j] * min(j, n - j);       ans = min(ans, sum);     }     cout << ans;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100100;   int n, m;   long long h[MAX], t[MAX];   bool can(int cur, int last, int nxt, long long val) {     if (t[last] >= h[cur]) return val >= t[nxt] - h[cur];     if (t[nxt] <= h[cur]) return val >= h[cur] - t[last];     return val >= min((h[cur] - t[last]) + (t[nxt] - t[last]),                       (t[nxt] - h[cur]) + (t[nxt] - t[last]));   }   bool check(long long val) {     int last = 1;     for (int i = 1; i <= n; ++i) {       int j = last;       while (j <= m && can(i, last, j, val)) ++j;       last = j;     }     return last == m + 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %I64d , h + i);     for (int i = 1; i <= m; ++i) scanf( %I64d , t + i);     long long low = 0, high = 20000000000LL, mid;     while (low <= high) {       mid = (low + high) >> 1;       if (check(mid))         high = mid - 1;       else         low = mid + 1;     }     printf( %I64d n , high + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double a[1 << 19];   double ans;   int n, r, w;   int main() {     scanf( %d%d , &n, &r);     w = 1 << n;     for (register int i = 0; i < w; i++) {       scanf( %lf , &a[i]);       ans += a[i];     }     printf( %.6lf n , ans / w);     while (r--) {       int pos;       double x;       scanf( %d%lf , &pos, &x);       ans -= a[pos];       a[pos] = x;       ans += a[pos];       printf( %.6lf n , ans / w);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << to_string(h);     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     int n;     cin >> n;     vector<vector<long long>> a(n, vector<long long>(3));     for (int i = 0; i < n; ++i) {       cin >> a[i][0] >> a[i][1] >> a[i][2];     }     vector<bool> vis(n);     for (int i = 0; i < n; ++i) {       long long bonus = 0, cnt = 0;       if (vis[i]) continue;       for (int j = i + 1; j < n; ++j) {         if (vis[j]) continue;         a[j][2] -= max(0LL, (a[i][0] - cnt));         ++cnt;         a[j][2] -= bonus;         if (a[j][2] < 0) {           vis[j] = true;           bonus += a[j][1];         }       }     }     vector<int> ans;     for (int i = 0; i < n; ++i) {       if (!vis[i]) {         ans.push_back(i + 1);       }     }     cout << ((int)(ans).size()) <<   n ;     for (auto &A : ans) cout << A <<    ;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int t, l, r, m;   } op[5010];   int a[5010], b[5010], n, m;   bool solve() {     int p, i, k;     for (i = 1; i <= n; i++) {       a[i] = 1000000000;     }     memset(b, 0, sizeof(b));     for (p = 1; p <= m; p++) {       if (op[p].t == 1)         for (i = op[p].l; i <= op[p].r; i++) b[i] += op[p].m;       else         for (i = op[p].l; i <= op[p].r; i++) a[i] = min(a[i], op[p].m - b[i]);     }     memset(b, 0, sizeof(b));     for (p = 1; p <= m; p++) {       if (op[p].t == 1)         for (i = op[p].l; i <= op[p].r; i++) b[i] += op[p].m;       else {         k = -1000000007;         for (i = op[p].l; i <= op[p].r; i++) k = max(k, a[i] + b[i]);         if (k != op[p].m) return false;       }     }     return true;   }   int main() {     int i;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d%d%d%d , &op[i].t, &op[i].l, &op[i].r, &op[i].m);     }     if (!solve()) {       printf( NO n );     } else {       printf( YES n );       for (i = 1; i <= n; i++) printf( %d  , a[i]);       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int n;     int value;     vector<int> next;   } p[100010];   queue<struct point> q;   int main() {     int n, m, x, y, flag = 1, t;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d %d , &x, &y);       p[x].next.push_back(y);       p[x].n++;       p[y].next.push_back(x);       p[y].n++;     }     for (int i = 1; i <= n; i++) {       if (!flag) break;       if (p[i].n && !p[i].value) {         p[i].value = 1;         q.push(p[i]);         while (!q.empty()) {           for (int j = 0; j < q.front().n; j++) {             if (!p[q.front().next[j]].value) {               p[q.front().next[j]].value = q.front().value % 2 + 1;               q.push(p[q.front().next[j]]);             } else {               if (p[q.front().next[j]].value != q.front().value % 2 + 1) {                 flag = 0;                 break;               }             }           }           q.pop();         }       }     }     if (flag) {       int ans = 0;       for (int i = 1; i <= n; i++) {         if (p[i].value == 1) ans++;       }       printf( %d n , ans);       for (int i = 1; i <= n; i++) {         if (p[i].value == 1) {           printf( %d  , i);         }       }       printf(  n );       ans = 0;       for (int i = 1; i <= n; i++) {         if (p[i].value == 2) ans++;       }       printf( %d n , ans);       for (int i = 1; i <= n; i++) {         if (p[i].value == 2) {           printf( %d  , i);         }       }     } else {       printf( -1 );     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 16, K = 225;   struct HASH {     size_t operator()(const pair<long long, long long> &x) const {       return hash<long long>()((x.first) ^ ((x.second) << 32));     }   };   int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};   int n, m;   int len = 0;   long long pw[N];   string str[N];   unordered_map<pair<long long, long long>, int, HASH> dis;   bool good(pair<long long, long long> p, int i, int j) {     int cur = (i * m + j);     for (int k = 0; k < len - 1 - 5; k++)       if (p.first / pw[k] % K == cur) return false;     for (int k = 0; k < min(len - 1, 5); k++)       if (p.second / pw[k] % K == cur) return false;     return true;   }   bool in_bound(int i, int j) {     return i >= 0 && i < n && j >= 0 && j < m && str[i][j] !=  # ;   }   pair<long long, long long> getnxt(pair<long long, long long> p, int i, int j) {     p.first *= K;     p.first += p.second / pw[4];     p.first %= pw[max(len - 5, 0)];     p.second *= K;     p.second += (i * m + j);     p.second %= pw[min(len, 5)];     return p;   }   int main() {     pw[0] = 1;     for (int i = 1; i < 6; i++) pw[i] = pw[i - 1] * K;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> str[i];     pair<long long, long long> ori;     queue<pair<long long, long long> > que;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         char c = str[i][j];         if (c >=  1  && c <=  9 ) {           int x = c -  0 ;           len = max(len, x);           x--;           if (x >= 5)             ori.first += (i * m + j) * pw[x - 5];           else             ori.second += (i * m + j) * pw[x];         }       }     }     que.push(ori);     dis[ori] = 0;     while (!que.empty()) {       pair<long long, long long> p = que.front();       que.pop();       int curdis = dis[p];       int ci = (int)(p.second % K / m), cj = (int)(p.second % K % m);       for (int d = 0; d < 4; d++) {         int ni = ci + dx[d], nj = cj + dy[d];         if (in_bound(ni, nj) && good(p, ni, nj)) {           if (str[ni][nj] ==  @ ) {             return cout << curdis + 1 << endl, 0;           }           pair<long long, long long> nxt = getnxt(p, ni, nj);           if (!dis.count(nxt)) {             que.push(nxt);             dis[nxt] = curdis + 1;           }         }       }     }     cout <<  -1  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 5e10 + 5;   int main() {     bool flag = 0;     int n, ans = 0, k;     cin >> n;     int arr[n + 5];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     k = n / 2;     for (int i = 0; i < n / 2; i++) {       for (int j = k; j < n; j++) {         if (arr[i] * 2 <= arr[j]) {           ans++;           k = j + 1;           break;         }         if (j == n - 1) {           flag = 1;         }       }       if (flag) break;     }     cout << n - ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int val{0};   struct Triplet {     char letter;     int onePosn;     int otherPosn;   };   int findContinuous(string s) {     int j{0};     for (auto i = 0; i < s.length() - 2; i++) {       if (s[i] ==  Q  && s[i + 1] ==  A  && s[i + 2] ==  Q ) {         j++;       }     }     return j;   }   int findLastQ(string s) {     int j{0};     for (auto i = 0; i < s.length() - 1; i++) {       if (s[i] ==  Q  && s[i + 1] ==  A ) {         for (int k = i + 2; k < s.length(); k++) {           if (s[k] ==  Q ) {             j++;           }         }       }     }     return j;   }   int findFirstQ(string s) {     int j{0};     for (auto i = 0; i < s.length() - 1; i++) {       if (s[i] ==  A  && s[i + 1] ==  Q ) {         for (int k = 0; k < i; k++) {           if (s[k] ==  Q ) {             j++;           }         }       }     }     return j;   }   int findDisjoint(string s) {     int j{0};     for (auto i = 0; i < s.length(); i++) {       int before{0};       int after{0};       if (s[i] ==  A ) {         for (int k = 0; k < i; k++) {           if (s[k] ==  Q ) {             before++;           }         }         for (int k = i + 1; k < s.length(); k++) {           if (s[k] ==  Q ) {             after++;           }         }         j += before * after;       }     }     return j;   }   int main() {     string s;     cin >> s;     int n = findDisjoint(s);     cout << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class L>   bool smax(T& x, L y) {     return x < y ? (x = y, 1) : 0;   }   template <class T, class L>   bool smin(T& x, L y) {     return x > y ? (x = y, 1) : 0;   }   const int maxn = 2e5 + 17, mod = 1e9 + 7;   struct Seg {     int lazy[maxn << 2], s[maxn << 2];     void build(int l = 0, int r = maxn, int id = 1) {       s[id] = r - l;       if (r - l < 2) return;       int mid = l + r >> 1;       build(l, mid, id << 1), build(mid, r, id << 1 | 1);     }     Seg() { fill(lazy, lazy + (maxn << 2), 1), build(); }     void shift(int id) {       lazy[id << 1] = (long long)lazy[id << 1] * lazy[id] % mod,                  lazy[id << 1 | 1] =                      (long long)lazy[id << 1 | 1] * lazy[id] % mod;       s[id << 1] = (long long)s[id << 1] * lazy[id] % mod,               s[id << 1 | 1] = (long long)s[id << 1 | 1] * lazy[id] % mod;       lazy[id] = 1;     }     void add(int st, int en, int v, int l = 0, int r = maxn, int id = 1) {       if (st <= l && r <= en) {         s[id] = (long long)s[id] * v % mod,         lazy[id] = (long long)lazy[id] * v % mod;         return;       }       if (en <= l || r <= st) return;       shift(id);       int mid = l + r >> 1;       add(st, en, v, l, mid, id << 1), add(st, en, v, mid, r, id << 1 | 1);       s[id] = (s[id << 1] + s[id << 1 | 1]) % mod;     }     int get(int st, int en, int l = 0, int r = maxn, int id = 1) {       if (st <= l && r <= en) return s[id];       if (en <= l || r <= st) return 0;       shift(id);       int mid = l + r >> 1;       return (get(st, en, l, mid, id << 1) + get(st, en, mid, r, id << 1 | 1)) %              mod;     }     void add(int l, int v) { add(l, l + 1, v); }     int get(int l) { return get(l, l + 1); }   } d, po, bad;   struct Q {     int t, p, v;   } q[maxn];   int rev(int a) {     int b = mod - 2, ans = 1;     for (; b; b >>= 1) {       if (b & 1) ans = (long long)ans * a % mod;       a = (long long)a * a % mod;     }     return ans;   }   int tim, st[maxn], en[maxn], nq, deg[maxn], cnt = 1;   vector<int> g[maxn];   void dfs(int v = 0) {     st[v] = tim++;     for (auto u : g[v]) dfs(u);     en[v] = tim;   }   void DeemoLovesInit() {     int tmp;     cin >> tmp >> nq;     po.add(0, tmp);     bad.add(0, 0);     fill(deg, deg + maxn, 1);     for (int i = 0; i < nq && cin >> q[i].t; i++)       if (q[i].t == 1)         cin >> q[i].p >> q[i].v, g[--q[i].p].push_back(cnt++);       else         cin >> q[i].v, q[i].v--;     dfs();     cnt = 1;   }   int main() {     DeemoLovesInit();     for (int i = 0, t = q[i].t, v = q[i].v, p = q[i].p; i < nq;          i++, t = q[i].t, v = q[i].v, p = q[i].p)       if (t == 1) {         po.add(st[cnt],                (long long)rev(po.get(st[cnt])) * v % mod * d.get(st[p]) % mod);         bad.add(st[cnt], 0);         deg[p]++;         d.add(st[p], en[p], (long long)rev(deg[p] - 1) * deg[p] % mod);         po.add(st[p], en[p], (long long)rev(deg[p] - 1) * deg[p] % mod);         bad.add(st[p], en[p], (long long)rev(deg[p] - 1) * deg[p] % mod);         cnt++;       } else {         cout << (long long)(po.get(st[v], en[v]) - bad.get(st[v], en[v]) + mod) %                     mod * rev(d.get(st[v])) % mod * deg[v] % mod              <<   n ;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int iL = 666666;   char *iS, *iT, ibuf[iL];   inline char gc() {     if (iS == iT) {       iT = (iS = ibuf) + fread(ibuf, 1, iL, stdin);       return iS == iT ? EOF : *iS++;     }     return *iS++;   }   template <class I>   void gi(I &x) {     static char c;     static int f;     for (f = 1, c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (x = 0; c <=  9  && c >=  0 ; c = getchar()) x = x * 10 + (c & 15);     x *= f;   }   const int N = 200050;   int Ttag[N * 4], Tval[N * 4], T[N * 4][31];   int n, q, sig, d, l, r;   int cnt(int x) {     int ans = 0;     for (int i = 0; i <= 30; i++)       if (T[x][i]) ans++;     return ans;   }   void clear(int x) {     for (int i = 0; i <= 30; i++) T[x][i] = 0;     Tval[x] = Ttag[x] = 0;   }   void add(int d, int x) {     for (int i = 30; i >= 0; i--)       if ((d >> i) & 1) {         if (T[x][i])           d ^= T[x][i];         else {           T[x][i] = d;           break;         }       }   }   void Complex(int x, int lc, int rc) {     clear(x);     for (int i = 0; i <= 30; i++) add(T[lc][i], x), add(T[rc][i], x);     add(Tval[lc] ^ Tval[rc], x);     Tval[x] = Tval[lc];   }   void Complex2(int x, int rc) {     clear(N * 4 - 1);     for (int i = 0; i <= 30; i++)       add(T[x][i], N * 4 - 1), add(T[rc][i], N * 4 - 1);     add(Tval[x] ^ Tval[rc], N * 4 - 1);     Tval[N * 4 - 1] = Tval[x];     for (int i = 0; i <= 30; i++) T[x][i] = T[N * 4 - 1][i];     Tval[x] = Tval[N * 4 - 1];   }   void build(int x, int l, int r) {     clear(x);     if (l == r) {       gi(Tval[x]);       return;     }     int mid = (l + r) >> 1;     build(x << 1, l, mid);     build(x << 1 | 1, mid + 1, r);     Complex(x, x << 1, x << 1 | 1);   }   void push_down(int x) {     int lc = x << 1, rc = x << 1 | 1;     if (Ttag[x]) {       Ttag[lc] ^= Ttag[x];       Ttag[rc] ^= Ttag[x];       Tval[lc] ^= Ttag[x];       Tval[rc] ^= Ttag[x];       Ttag[x] = 0;     }   }   void change(int x, int l, int r, int lb, int rb, int d) {     if (lb <= l && r <= rb) {       Tval[x] ^= d;       Ttag[x] ^= d;       return;     }     push_down(x);     int mid = (l + r) >> 1;     if (lb <= mid) change(x << 1, l, mid, lb, rb, d);     if (rb > mid) change(x << 1 | 1, mid + 1, r, lb, rb, d);     Complex(x, x << 1, x << 1 | 1);   }   void query(int x, int l, int r, int lb, int rb) {     if (lb <= l && r <= rb) {       Complex2(0, x);       return;     }     push_down(x);     int mid = (l + r) >> 1;     if (lb <= mid) query(x << 1, l, mid, lb, rb);     if (rb > mid) query(x << 1 | 1, mid + 1, r, lb, rb);     Complex(x, x << 1, x << 1 | 1);   }   int main() {     gi(n);     gi(q);     build(1, 1, n);     while (q--) {       gi(sig);       if (sig == 1) {         gi(l);         gi(r);         gi(d);         change(1, 1, n, l, r, d);       } else {         gi(l);         gi(r);         clear(0);         query(1, 1, n, l, r);         printf( %d n , (1 << cnt(0)));       }     }     return 0;   }


#pragma comment(linker,  /stack:200000000 )       #pragma GCC optimize( Ofast )       #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )               #define _CRT_SECURE_NO_WARNINGS       # include <iostream>       # include <cmath>       # include <algorithm>       # include <stdio.h>       # include <cstdint>       # include <cstring>       # include <string>       # include <cstdlib>       # include <vector>       # include <bitset>       # include <map>       # include <queue>       # include <ctime>       # include <stack>       # include <set>       # include <list>       # include <random>       # include <deque>       # include <functional>       # include <iomanip>       # include <sstream>       # include <fstream>       # include <complex>       # include <numeric>       # include <immintrin.h>       # include <cassert>       # include <array>       # include <tuple>               #ifdef LOCAL       # include <opencv2/core/core.hpp>       # include <opencv2/highgui/highgui.hpp>       # include <opencv2/imgproc/imgproc.hpp>       #endif               using namespace std;               // Let s define unordered map       # ifdef __GNUC__       # if __cplusplus > 199711L       # include <unordered_set>       # include <unordered_map>       # else       # include <tr1/unordered_map>       # include <tr1/unordered_set>       using namespace tr1;       # endif       # else       # include <unordered_map>       # include <unordered_set>       # endif               #define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 6,5,4,3,2,1))       #define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple       #define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,_6,N,...) N       #define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))       #define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)       #define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)       #define macro_dispatcher___(macro, nargs) macro ## nargs       #define DBN1(a)           cerr<<#a<< = <<(a)<<  n        #define DBN2(a,b)         cerr<<#a<< = <<(a)<< ,  <<#b<< = <<(b)<<  n        #define DBN3(a,b,c)       cerr<<#a<< = <<(a)<< ,  <<#b<< = <<(b)<< ,  <<#c<< = <<(c)<<  n        #define DBN4(a,b,c,d)     cerr<<#a<< = <<(a)<< ,  <<#b<< = <<(b)<< ,  <<#c<< = <<(c)<< ,  <<#d<< = <<(d)<<  n        #define DBN5(a,b,c,d,e)   cerr<<#a<< = <<(a)<< ,  <<#b<< = <<(b)<< ,  <<#c<< = <<(c)<< ,  <<#d<< = <<(d)<< ,  <<#e<< = <<(e)<<  n        #define DBN6(a,b,c,d,e,f) cerr<<#a<< = <<(a)<< ,  <<#b<< = <<(b)<< ,  <<#c<< = <<(c)<< ,  <<#d<< = <<(d)<< ,  <<#e<< = <<(e)<< ,  <<#f<< = <<(f)<<  n        #define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)       #define DA(a,n) cerr<<#a<< =[ ; printarray(a,n); cerr<< ] n        #define DAR(a,n,s) cerr<<#a<< [ <<s<< - <<n-1<< ]=[ ; printarray(a,n,s); cerr<< ] n                #ifdef _MSC_VER       #define PREFETCH(ptr, rw, level) ((void)0)       #else       #define PREFETCH(ptr, rw, level) __builtin_prefetch(ptr, rw, level)       #endif               #ifdef LOCAL       #define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl       #else       #define CURTIME()       #endif               #define mp make_pair       typedef long long ll;       typedef unsigned int uint;       typedef unsigned long long ull;       typedef pair<int, int> pii;       typedef pair<long long, long long> pll;       typedef vector<int> vi;       typedef vector<long long> vll;       typedef int itn;               template<class T1, class T2, class T3>       struct triple{ T1 a; T2 b; T3 c; triple() : a(T1()), b(T2()), c(T3()) {}; triple(T1 _a, T2 _b, T3 _c) :a(_a), b(_b), c(_c){} };       template<class T1, class T2, class T3>       bool operator<(const triple<T1,T2,T3>&t1,const triple<T1,T2,T3>&t2){if(t1.a!=t2.a)return t1.a<t2.a;else if(t1.b!=t2.b)return t1.b<t2.b;else return t1.c<t2.c;}       template<class T1, class T2, class T3>       bool operator>(const triple<T1,T2,T3>&t1,const triple<T1,T2,T3>&t2){if(t1.a!=t2.a)return t1.a>t2.a;else if(t1.b!=t2.b)return t1.b>t2.b;else return t1.c>t2.c;}       #define tri triple<int,int,int>       #define trll triple<ll,ll,ll>               #define FI(n) for(int i=0;i<(n);++i)       #define FJ(n) for(int j=0;j<(n);++j)       #define FK(n) for(int k=0;k<(n);++k)       #define FL(n) for(int l=0;l<(n);++l)       #define FQ(n) for(int q=0;q<(n);++q)       #define FOR(i,a,b) for(int i = (a), __e = (int) (b); i < __e; ++i)       #define all(a) std::begin(a), std::end(a)       #define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())               #define sqr(x) ((x) * (x))       #define sqrt(x) sqrt(1.0 * (x))       #define pow(x, n) pow(1.0 * (x), n)               #define COMPARE(obj) [&](const std::decay_t<decltype(obj)>& a, const std::decay_t<decltype(obj)>& b)       #define COMPARE_BY(obj, field) [&](const std::decay_t<decltype(obj)>& a, const std::decay_t<decltype(obj)>& b) { return a.field < b.field; }               #define checkbit(n, b) (((n) >> (b)) & 1)       #define setbit(n, b) ((n) | (static_cast<std::decay_t<decltype(n)>>(1) << (b)))       #define removebit(n, b) ((n) & ~(static_cast<std::decay_t<decltype(n)>>(1) << (b)))       #define flipbit(n, b) ((n) ^ (static_cast<std::decay_t<decltype(n)>>(1) << (b)))       inline int countBits(uint v){v=v-((v>>1)&0x55555555);v=(v&0x33333333)+((v>>2)&0x33333333);return((v+(v>>4)&0xF0F0F0F)*0x1010101)>>24;}       inline int countBits(ull v){uint t=v>>32;uint p=(v & ((1ULL << 32) - 1)); return countBits(t) + countBits(p); }       inline int countBits(ll v){return countBits((ull)v); }       inline int countBits(int v){return countBits((uint)v); }       unsigned int reverseBits(uint x){ x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); return((x >> 16) | (x << 16)); }       template<class T> inline int sign(T x){ return x > 0 ? 1 : x < 0 ? -1 : 0; }       inline bool isPowerOfTwo(int x){ return (x != 0 && (x&(x - 1)) == 0); }       constexpr ll power(ll x, int p) { return p == 0 ? 1 : (x * power(x, p - 1)); }       template<class T1, class T2, class T3> T1 inline clamp(T1 x, const T2& a, const T3& b) { if (x < a) return a; else if (x > b) return b; else return x; }       unsigned long long rdtsc() { unsigned long long ret = 0;       #ifdef __clang__           return __builtin_readcyclecounter();       #endif       #ifndef _MSC_VER           asm volatile( rdtsc  :  =A  (ret) : :);       #endif           return ret; }       // Fast IO ********************************************************************************************************       const int __BS = 4096;       static char __bur[__BS + 16], *__er = __bur + __BS, *__ir = __er;       template<class T = int> T readInt() {           auto c = [&]() { if (__ir == __er) std::fill(__bur, __bur + __BS, 0), cin.read(__bur, __BS), __ir = __bur; };           c(); while (*__ir && (*__ir <  0  || *__ir >  9 ) && *__ir !=  - ) ++__ir; c();           bool m = false; if (*__ir ==  - ) ++__ir, c(), m = true;           T r = 0; while (*__ir >=  0  && *__ir <=  9 ) r = r * 10 + *__ir -  0 , ++__ir, c();           ++__ir; return m ? -r : r;       }       static char __buw[__BS + 20], *__iw = __buw, *__ew = __buw + __BS;       template<class T>       void writeInt(T x, char endc =   n ) {           if (x < 0) *__iw++ =  - , x = -x; if (x == 0) *__iw++ =  0 ;           char* s = __iw;           while (x) { T t = x / 10; char c = x - 10 * t +  0 ; *__iw++ = c; x = t; }           char* f = __iw - 1; while (s < f) swap(*s, *f), ++s, --f;           if (__iw > __ew) cout.write(__buw, __iw - __buw), __iw = __buw;           *__iw++ = endc;       }       template<class T>       void writeStr(const T& str) {           int i = 0; while (str[i]) { *__iw++ = str[i++]; if (__iw > __ew) cout.write(__buw, __iw - __buw), __iw = __buw; }       }       struct __FL__ { ~__FL__() { if (__iw != __buw) cout.write(__buw, __iw - __buw); } };       static __FL__ __flushVar__;               //STL output *****************************************************************************************************       #define TT1 template<class T>       #define TT1T2 template<class T1, class T2>       #define TT1T2T3 template<class T1, class T2, class T3>       TT1T2 ostream& operator << (ostream& os, const pair<T1, T2>& p);       TT1 ostream& operator << (ostream& os, const vector<T>& v);       TT1T2 ostream& operator << (ostream& os, const set<T1, T2>&v);       TT1T2 ostream& operator << (ostream& os, const multiset<T1, T2>&v);       TT1T2 ostream& operator << (ostream& os, priority_queue<T1, T2> v);       TT1T2T3 ostream& operator << (ostream& os, const map<T1, T2, T3>& v);       TT1T2T3 ostream& operator << (ostream& os, const multimap<T1, T2, T3>& v);       TT1T2T3 ostream& operator << (ostream& os, const triple<T1, T2, T3>& t);       template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v);       TT1T2 ostream& operator << (ostream& os, const pair<T1, T2>& p){ return os << ( <<p.first<< ,  << p.second<< ) ; }       TT1 ostream& operator << (ostream& os, const vector<T>& v){       bool f=1;os<< [ ;for(auto& i : v) { if (!f)os <<  ,  ;os<<i;f=0;}return os <<  ] ; }       template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v) {     bool f=1;os<< [ ;for(auto& i : v) { if (!f)os <<  ,  ;os<<i;f=0;}return os <<  ] ; }       TT1T2 ostream& operator << (ostream& os, const set<T1, T2>&v){    bool f=1;os<< [ ;for(auto& i : v) { if (!f)os <<  ,  ;os<<i;f=0;}return os <<  ] ; }       TT1T2 ostream& operator << (ostream& os, const multiset<T1,T2>&v){bool f=1;os<< [ ;for(auto& i : v) { if (!f)os <<  ,  ;os<<i;f=0;}return os <<  ] ; }       TT1T2T3 ostream& operator << (ostream& os, const map<T1,T2,T3>& v){ bool f = 1; os <<  [ ; for (auto& ii : v) { if (!f)os <<  ,  ; os <<  (  << ii.first <<   ->   << ii.second <<  )  ; f = 0; }return os <<  ] ; }       TT1T2 ostream& operator << (ostream& os, const multimap<T1, T2>& v){ bool f = 1; os <<  [ ; for (auto& ii : v) { if (!f)os <<  ,  ; os <<  (  << ii.first <<   ->   << ii.second <<  )  ; f = 0; }return os <<  ] ; }       TT1T2 ostream& operator << (ostream& os, priority_queue<T1, T2> v) { bool f = 1; os <<  [ ; while (!v.empty()) { auto x = v.top(); v.pop(); if (!f) os <<  ,  ; f = 0; os << x; } return os <<  ] ; }       TT1T2T3 ostream& operator << (ostream& os, const triple<T1, T2, T3>& t){ return os <<  (  << t.a <<  ,   << t.b <<  ,   << t.c <<  ) ; }       TT1T2 void printarray(const T1& a, T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cout << a[i] <<    ; cout << endl; }               //STL input *****************************************************************************************************       TT1T2T3 inline istream& operator >> (istream& os, triple<T1, T2, T3>& t);       TT1T2 inline istream& operator >> (istream& os, pair<T1, T2>& p) { return os >> p.first >> p.second; }       TT1 inline istream& operator >> (istream& os, vector<T>& v) {           if (v.size()) for (T& t : v) os >> t; else {               string s; T obj; while (s.empty()) {getline(os, s); if (!os) return os;}               stringstream ss(s); while (ss >> obj) v.push_back(obj);           }           return os;       }       TT1T2T3 inline istream& operator >> (istream& os, triple<T1, T2, T3>& t) { return os >> t.a >> t.b >> t.c; }               //Pair magic *****************************************************************************************************       #define PT1T2 pair<T1, T2>       TT1T2 inline PT1T2 operator+(const PT1T2 &p1 , const PT1T2 &p2) { return PT1T2(p1.first + p2.first, p1.second + p2.second); }       TT1T2 inline PT1T2& operator+=(PT1T2 &p1 , const PT1T2 &p2) { p1.first += p2.first, p1.second += p2.second; return p1; }       TT1T2 inline PT1T2 operator-(const PT1T2 &p1 , const PT1T2 &p2) { return PT1T2(p1.first - p2.first, p1.second - p2.second); }       TT1T2 inline PT1T2& operator-=(PT1T2 &p1 , const PT1T2 &p2) { p1.first -= p2.first, p1.second -= p2.second; return p1; }               #undef TT1       #undef TT1T2       #undef TT1T2T3               #define FREIN(FILE) freopen(FILE,  rt , stdin)       #define FREOUT(FILE) freopen(FILE,  wt , stdout)       #ifdef LOCAL       #define BEGIN_PROFILE(idx, name) int profileIdx = idx; profileName[profileIdx] = name; totalTime[profileIdx] -= rdtsc() / 1e3;       #define END_PROFILE totalTime[profileIdx] += rdtsc() / 1e3; totalCount[profileIdx]++;       #else       #define BEGIN_PROFILE(idx, name)       #define END_PROFILE       #endif               template<class T> inline void normmod(T &x, T m) { x %= m; if (x < 0) x += m; }       template<class T1, class T2> inline T2 summodfast(T1 x, T1 y, T2 m) { T2 res = x + y; if (res >= m) res -= m; return res; }       template<class T1, class T2, class T3> inline void addmodfast(T1 &x, T2 y, T3 m) { x += y; if (x >= m) x -= m; }       template<class T1, class T2, class T3> inline void submodfast(T1 &x, T2 y, T3 m) { x -= y; if (x < 0) x += m; }       #if INTPTR_MAX == INT32_MAX or !defined(__SIZEOF_INT128__)       inline ll mulmod(ll x, ll n, ll m){ ll r = 0; normmod(x, m); normmod(n, m); while (n) { if (n & 1) r += x; x += x; if (r >= m) r -= m; if (x >= m) x -= m; n /= 2; } return r; }       #else       using int128 = __int128;       inline ll mulmod(ll x, ll n, ll m){ return __int128(x) * n % m; }       #endif       inline ll powmod(ll x, ll n, ll m){ ll r = 1; normmod(x, m); while (n){ if (n & 1)r = (r*x) % m; x = (x*x) % m; n /= 2; }return r; }       inline ll powmulmod(ll x, ll n, ll m) { ll res = 1; normmod(x, m); while (n){ if (n & 1)res = mulmod(res, x, m); x = mulmod(x, x, m); n /= 2; } return res; }       template<class T> inline T gcd(T a, T b) { while (b) { a %= b; T t = a; a = b; b = t; } return a; }       inline ll lcm(ll a, ll b){ return a / gcd(a, b) * b; }       template<class T> inline T gcd(T a, T b, T c){ return gcd(gcd(a, b), c); }       ll gcdex(ll a, ll b, ll& x, ll& y) {           if (!a) { x = 0; y = 1; return b; }           ll y1; ll d = gcdex(b % a, a, y, y1); x = y1 - (b / a) * y;           return d;       }       template<class T> bool isPrime(T x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;           for (T i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; }       bool millerRabin(long long n) {           if (n <= 1000) return isPrime(n);           long long s = n - 1; int t = 0; while (s % 2 == 0) s /= 2, ++t;           for (int a : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) { if (!(a %= n)) return true;               long long f = powmulmod(a, s, n); if (f == 1 || f == n - 1) continue;               for (int i = 1; i < t; ++i) if ((f = mulmod(f, f, n)) == n - 1) goto nextp;               return false; nextp:;           } return true;       }               // Useful constants               //int some_primes[7] = {24443, 100271, 1000003, 1000333, 5000321, 98765431, 1000000123};       #define T9          1000000000       #define T18         1000000000000000000LL       #define INF         1011111111       #define LLINF       1000111000111000111LL       #define mod         1000000007       #define EPS         (double)1e-10       #define PI          3.14159265358979323846264       #define link        asaxlajrewqwe       #define rank        wahayawehasdakw       //*************************************************************************************               int32_t solve();       int32_t main(int argc, char** argv) {           ios_base::sync_with_stdio(0);cin.tie(0);       #ifdef LOCAL           //    FREIN( input.txt );           //            FREOUT( out.txt );       #endif           return solve();       }       int a[10101];       int solve() {           int n, m, c;           cin >> n >> m >> c;           FI(n) {               a[i] = INF;           }           int b = 0, e = 0;           while (m--) {       //        printarray(a, n);               int x;               cin >> x;               int pos;               if (x <= c / 2) {                   pos = int(upper_bound(a, a + b, x) - a);                   if (pos == b) {                       ++b;                   }               } else {                   pos = int(lower_bound(a + n - e, a + n, x) - a - 1);                   if (pos == n - 1 - e) {                       ++e;                   }               }       //        DBN(b, e);               a[pos] = x;               cout << pos + 1 << endl;               if (b + e == n) return 0;           }                      return 0;       }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     string a;     cin >> a;     int sz = int(a.size());     for (__typeof(sz) i = 0; i < sz; i++)       for (__typeof(sz) j = 0; j < sz; j++)         if (a.substr(0, i) + a.substr(j + 1) ==  CODEFORCES ) {           cout <<  YES n ;           return 0;         }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1e-10;   const int OO = 2147483647;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, -1, 1};   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     map<pair<long long, long long>, long long> st;     map<long long, long long> xs, ys;     long long ans = 0;     long long cnt = 0;     while (n--) {       int x, y;       cin >> x >> y;       ans += xs[x]++ + ys[y]++ - st[{x, y}]++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 1;   const int MOD = 1e9 + 7;   long long a[MAXN], b[MAXN];   bool used[MAXN];   vector<int> g[MAXN];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     long long n, m, cnt = 0, ans = 0;     bool y = 0;     cin >> n;     a[1] = 1;     for (int i = 2; i <= n; i++) {       cin >> a[i];     }     cnt = n;     while (cnt != 1) {       ans++;       b[ans] = cnt;       cnt = a[cnt];     }     reverse(b + 1, b + ans + 1);     cout << 1 <<    ;     for (int i = 1; i <= ans; i++) {       cout << b[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 * 1005;   bool bad[maxn];   vector<int> blocked;   vector<int> g[maxn];   bool seen[maxn];   int deg[maxn];   vector<int> good;   int n, m, k;   bool can(double mid) {     memset(bad, 0, sizeof(bad));     memset(deg, 0, sizeof(deg));     memset(seen, 0, sizeof(seen));     queue<int> q;     for (int i = 0; i < n; ++i) deg[i] = ((int)((g[i]).size()));     for (int i = 0; i < ((int)((blocked).size())); i++) q.push(blocked[i]);     while (!q.empty()) {       int u = q.front();       q.pop();       if (seen[u]) continue;       seen[u] = 1;       for (int i = 0; i < ((int)((g[u]).size())); i++) {         int v = g[u][i];         if (bad[v]) continue;         deg[v]--;         if (double(deg[v] / (1.0 * ((int)((g[v]).size())))) < mid) q.push(v);       }     }     good.clear();     for (int i = 0; i < n; ++i)       if (!seen[i]) good.push_back(i);     return ((int)((good).size())) > 0;   }   int main() {     int u, v;     scanf( %d %d %d , &n, &m, &k);     for (int i = 0; i < k; ++i) scanf( %d , &u), --u, blocked.push_back(u);     for (int i = 0; i < m; ++i)       scanf( %d %d , &u, &v), --u, --v, g[u].push_back(v), g[v].push_back(u);     double l = 0, r = 1.0;     double ans = 0.0;     for (int i = 0; i < 80; ++i) {       double mid = (l + r) / 2.0;       if (can(mid))         l = mid, ans = mid;       else         r = mid;     }     can(ans);     assert(((int)((good).size())) <= n - k);     assert(((int)((good).size())) != 0);     printf( %d n , ((int)((good).size())));     for (int i = 0; i < ((int)((good).size())); i++) printf( %d  , good[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace MincostMaxFlow {   const int maxn(2e5 + 5);   struct Edge {     int to, next, w, f;   };   int first[maxn], cnt, vis[maxn], dis[maxn], S, T, pe[maxn], pv[maxn], maxflow,       mincost;   Edge edge[maxn * 20];   queue<int> Q;   inline void Init(int _S, int _T) {     cnt = mincost = maxflow = 0, S = _S, T = _T;     memset(first, -1, sizeof(first));   }   inline void AddEdge(int u, int v, int w, int f) {     edge[cnt] = (Edge){v, first[u], w, f}, first[u] = cnt++;     edge[cnt] = (Edge){u, first[v], -w, 0}, first[v] = cnt++;   }   inline int SPFA() {     int e, u, v, inf;     memset(dis, 63, sizeof(dis)), inf = dis[0];     Q.push(S), dis[S] = 0, vis[S] = 1;     while (!Q.empty()) {       u = Q.front(), Q.pop();       for (e = first[u]; ~e; e = edge[e].next)         if (edge[e].f && dis[u] + edge[e].w < dis[v = edge[e].to]) {           dis[v] = dis[u] + edge[e].w, pv[v] = u, pe[v] = e;           if (!vis[v]) vis[v] = 1, Q.push(v);         }       vis[u] = 0;     }     if (dis[T] >= 0) return 0;     for (v = T; v ^ S; v = pv[v]) inf = min(inf, edge[pe[v]].f);     maxflow += inf, mincost += dis[T] * inf;     for (v = T; v ^ S; v = pv[v]) edge[pe[v]].f -= inf, edge[pe[v] ^ 1].f += inf;     return 1;   }   inline int MCMF() {     while (SPFA())       ;     return mincost;   }   }  // namespace MincostMaxFlow   using MincostMaxFlow ::AddEdge;   using MincostMaxFlow ::Init;   using MincostMaxFlow ::MCMF;   const int inf(1e7);   int n, k, a[85], c[85], S, T;   int main() {     int i, j, tmp;     scanf( %d%d , &n, &k), k = min(k, n);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (i = 1; i <= n; ++i) scanf( %d , &c[i]);     Init(S = 0, T = n + n + 2), tmp = n + n + 1, AddEdge(S, tmp, 0, k);     for (i = 1; i <= n; ++i) {       AddEdge(i, i + n, -inf, 1);       for (j = i + 1; j <= n; ++j)         if (a[j] == a[i])           AddEdge(i + n, j, 0, 1);         else           AddEdge(i + n, j, c[a[j]], 1);       AddEdge(i + n, T, 0, 1), AddEdge(tmp, i, c[a[i]], 1);     }     printf( %d n , MCMF() + n * inf);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int node[100005][2];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) scanf( %d%d , &node[i][0], &node[i][1]);     int ans = node[0][1] + node[0][0] - 1;     bool flag = 0;     for (int i = 1; i < m; i++) {       int d_val = node[i][0] - node[i - 1][0];       if (abs(node[i][1] - node[i - 1][1]) > d_val) {         flag = 1;         break;       }       ans = max(ans, node[i][1]);       ans = max(ans, max(node[i][1], node[i - 1][1]) +                          (d_val - abs(node[i][1] - node[i - 1][1])) / 2);     }     int syday = n - node[m - 1][0];     ans = max(ans, node[m - 1][1] + syday);     if (flag)       cout <<  IMPOSSIBLE  << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 600;   char graph[MAXN][MAXN];   int dx[4] = {-1, 0, 0, 1};   int dy[4] = {0, -1, 1, 0};   vector<char> op;   vector<pair<int, int> > pos;   bool visited[MAXN][MAXN];   void solve(int x, int y, int n, int m, int initX, int initY) {     visited[x][y] = true;     bool flag = false;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i];       int ny = y + dy[i];       if (nx >= 0 && nx < n && ny >= 0 && ny < m && graph[nx][ny] ==  .  &&           !visited[nx][ny]) {         if (!flag) {           op.push_back( B );           pos.push_back(make_pair(x + 1, y + 1));         }         flag = true;         solve(nx, ny, n, m, initX, initY);       }     }     if (!flag) {       if (x == initX && y == initY) {         op.push_back( B );       } else {         op.push_back( R );       }       pos.push_back(make_pair(x + 1, y + 1));     } else {       if (!(x == initX && y == initY)) {         op.push_back( D );         pos.push_back(make_pair(x + 1, y + 1));         op.push_back( R );         pos.push_back(make_pair(x + 1, y + 1));       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> graph[i][j];       }     }     memset(visited, false, sizeof(visited));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (graph[i][j] ==  .  && !visited[i][j]) {           solve(i, j, n, m, i, j);         }       }     }     int size = op.size();     printf( %d n , size);     for (int i = 0; i < size; i++) {       printf( %c %d %d n , op[i], pos[i].first, pos[i].second);     }     return 0;   }


// Author: Vinay Khilwani   // Language: C++       // @vok8: Codeforces, AtCoder, LeetCode, HackerEarth, TopCoder, Google, FB, CSES, Spoj, GitHub   // @vok_8: CodeChef, GFG   // @vok8_khilwani: HackerRank       // Never Stop Trying.   // Trying to be Better than Myself.       // while(true)   // {   //     if(AC)   //     {   //         break;   //     }   //     else if(Contest Over)   //     {   //         Try.   //         Check out Editorial.   //         Understand.   //         Find out your Mistake.   //         Learn the topic (if new).   //         Solve Problems on that topic (if new).   //         Upsolve that problem.   //         break;   //     }   //     else   //     {   //         Try.   //         Use Pen-Paper.   //         Find errors, edge cases, etc.   //         continue;   //     }   // }       // Optimizations   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( avx2 )   #pragma GCC optimize( Os )       // Libraries   #include <bits/stdc++.h>   using namespace std;   // #include <ext/pb_ds/assoc_container.hpp>    // #include <ext/pb_ds/tree_policy.hpp>    // using namespace __gnu_pbds;       // Debugging   #define dbg(a) cerr<<a<<  n ;   #define debug_a(a) for(auto x:a) {cerr<<x<<   ;} cerr<<  n ;   #define debug_b(a) for(auto x:a) {cerr<< [ <<x.first<< ,  <<x.second<< ] <<  n ;} cerr<<  n ;   #define debug_c(a) for(auto x:a) {debug_a(x)} cerr<<  n ;   #define debug_d(a) for(auto x:a) {debug_b(x)} cerr<<  n ;   #define debug_e(a) cerr<< [ <<a.first<< ,  <<a.second<< ] <<  n ;       // Defines   #define fast ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);   #define loop(i,a,n) for(ll i=a; i<n; i++)   #define rloop(i,a,n) for(int i=a; i>=n; i--)   #define fr(i,a,n,b) for(int i=a; i<n; i+=b)   #define rfr(i,a,n,b) for(int i=a; i>=n; i-=b)   #define IN cin>>   #define OUT cout<<   #define nl   n    #define sz(a) int(a.size())   #define all(a) (a).begin(),(a).end()   #define each(a,b) for(auto &a:b)   #define pb push_back   #define set_bits(a) __builtin_popcountll(a)   #define ar array   #define write(a) for(auto x:a) {OUT x<<   ;} OUT endl;   #define read(a) for(auto &x:a) {IN x;}   // #define oset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   using ll=long long int;   using ld=long double;   using pll=pair<ll,ll>;   using pii=pair<int,int>;   using vll=vector<ll>;   using vi=vector<int>;   const ll mod=(ll)(1e9)+7LL;   const ll M=998244353LL;   const int dx[4]={1,0,-1,0};   const int dy[4]={0,1,0,-1};   const ld pi=acos(-1);       // General Functions   ll gcd(ll a, ll b)   {       return (b?gcd(b,a%b):a);   }   ll P(ll B, ll power, ll modulo) //Fast Power   {       ll ans=1LL;       while(power>0LL)       {           if(power%2LL==1LL)           {               ans=(ans*B)%modulo;           }           B=(B*B)%modulo;           power/=2LL;       }       return ans;   }   bool isPrime(ll n)   {       if(n<=1LL)       {           return false;       }       if(n<=3LL)       {           return true;       }       if(n%2==0LL || n%3==0LL)       {           return false;       }       for(ll i=5LL; (i*i)<=n; i+=6LL)       {           if(n%i==0LL || n%(i+2LL)==0LL)           {               return false;           }       }       return true;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   ll get_rand(ll l, ll r)   {       uniform_int_distribution<ll> uid(l,r);       return uid(rng);   }   void vok()   {       fast       #ifndef ONLINE_JUDGE           freopen( input.txt , r ,stdin);           freopen( output.txt , w ,stdout);           freopen( error.txt , w ,stderr);       #endif   }       // Global Variables   const int mxN=int(1e5)+100;   vector<bool> cycle;   ll sizee=0;   vector<bool> vis;      // Solver Function(s)   void dfs_cycle(int u, int p, int color[], int mark[], int par[], int& cyclenumber, vi graph[])   {           // already (completely) visited vertex.       if (color[u] == 2) {           return;       }           // seen vertex, but was not completely visited -> cycle detected.       // backtrack based on parents to find the complete cycle.       if (color[u] == 1) {               cyclenumber++;           int cur = p;           mark[cur] = cyclenumber;               // backtrack the vertex which are           // in the current cycle thats found           while (cur != u) {               cur = par[cur];               mark[cur] = cyclenumber;           }           return;       }       par[u] = p;           // partially visited.       color[u] = 1;           // simple dfs on graph       for (int v : graph[u]) {               // if it has not been visited previously           if (v == par[u]) {               continue;           }           dfs_cycle(v, u, color, mark, par, cyclenumber, graph);       }           // completely visited.       color[u] = 2;   }   void dfs(int u, vi g[])   {       sizee++;       vis[u]=true;       each(x,g[u])       {           if(!vis[x] && !cycle[x])           {               dfs(x,g);           }       }   }   void solve()   {       int n;       IN n;       vi g[n+1];       loop(i,0,n)       {           int u,v;           IN u>>v;           g[u].pb(v);           g[v].pb(u);       }       if(n==3)       {           OUT 6<<nl;           return;       }       int color[n+1];       int par[n+1];       int mark[n+1];       loop(i,0,n+1)       {           color[i]=par[i]=mark[i]=0;       }       int cyclenumber = 0;       int edges = n;       dfs_cycle(1, 0, color, mark, par, cyclenumber, g);       vis=vector<bool>(n+1,false);       vll vv;       cycle=vis;       ll sz_cycle=0;       loop(i,1,n+1)       {           if(mark[i])           {               cycle[i]=true;               sz_cycle++;           }       }       ll ans=(ll)(sz_cycle)*(ll)(sz_cycle-1);       loop(i,1,n+1)       {           if(cycle[i])           {               sizee=0;                dfs(i,g);               ll add=sizee*(sizee-1)/2;               // OUT i<<   <<sizee<<nl;               if(sizee>1)               {                   vv.pb(sizee-1);                   ans+=((sizee-1)*(ll)(sz_cycle-1)*2);               }               ans+=add;               // OUT ans<<nl;               // ans+=((sizee-1)*(ll)(sz(cycle)-1)*2);               // OUT ans<<nl;           }       }       ll sum=0;       ll sq=0;       each(x,vv)       {           sum+=x;           sq+=(x*x);       }       sum*=sum;       ll temp=sum-sq;       ans+=temp;       OUT ans<<nl;   }       // Main Function   int main()   {       vok();       int t=1;       IN t;       while(t--)       {           solve();       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, h, m, l, r, x;     cin >> n >> h >> m;     vector<int> v(n, h);     for (int i = 0; i < m; i++) {       cin >> l >> r >> x;       for (int j = l - 1; j < r; j++) {         v[j] = min(v[j], x);       }     }     long long sum = 0;     for (int i = 0; i < v.size(); i++) {       sum = sum + (v[i] * v[i]);     }     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1;     cin >> s1;     int condition = 1;     for (int i = 1; i <= s1.length(); i++) {       if (s1[i] == s1[i - 1]) {         condition++;         if (condition == 7) {           cout <<  YES  << endl;           return 0;         }       } else {         condition = 1;       }     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     pair<int, int> point[n];     for (int i = 0; i < n; i++) {       cin >> point[i].first >> point[i].second;     }     sort(point, point + n,          [](pair<int, int> a, pair<int, int> b) { return a.first < b.first; });     long long ans = 0;     long long cnt = 1;     for (int i = 0; i < n - 1; i++) {       if (point[i].first == point[i + 1].first) {         cnt++;       } else {         ans += cnt * (cnt - 1) / 2;         cnt = 1;       }     }     ans += cnt * (cnt - 1) / 2;     sort(point, point + n,          [](pair<int, int> a, pair<int, int> b) { return a.second < b.second; });     cnt = 1;     for (int i = 0; i < n - 1; i++) {       if (point[i].second == point[i + 1].second) {         cnt++;       } else {         ans += cnt * (cnt - 1) / 2;         cnt = 1;       }     }     ans += cnt * (cnt - 1) / 2;     sort(point, point + n);     cnt = 1;     for (int i = 0; i < n - 1; i++) {       if (point[i] == point[i + 1]) {         cnt++;       } else {         ans -= cnt * (cnt - 1) / 2;         cnt = 1;       }     }     ans -= cnt * (cnt - 1) / 2;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int hoa = 0;     int thuong = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] >= 65 && s[i] <= 90) {         hoa++;       } else {         thuong++;       }     }     if (thuong >= hoa) {       for (int i = 0; i < s.size(); i++) {         if (s[i] >= 65 && s[i] <= 90) {           s[i] += 32;         }       }     } else {       for (int i = 0; i < s.size(); i++) {         if (s[i] >= 97 && s[i] <= 122) {           s[i] -= 32;         }       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const long long int cmod = 998244353;   const long long int N = 2e5 + 5;   const long long int inf = 1e16 + 2;   void solve(long long int ze) {     long long int n, x, t, pr = 0;     cin >> n >> x;     vector<long long int> ans;     map<long long int, long long int> check;     check[0] = 1;     check[x] = 1;     for (long long int i = 1; i < (1LL << n); i++) {       if (!check[i]) {         ans.push_back(pr ^ i);         pr = i;         check[i] = 1;         check[i ^ x] = 1;       }     }     cout << ans.size() <<   n ;     for (auto x : ans) cout << x <<    ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int testcase = 1;     long long int x = 1;     while (testcase--) {       solve(x++);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long in() {     long long x = 0;     int n = 1;     char c = getchar();     while (!isdigit(c)) {       n = (c ==  - ) ? -1 : 1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * n;   }   const int N = 80;   int n, a[N], d[5];   int f[N][N][N][2];   string s;   int NOR(int x) {     if (x < 0) return -x;     return 0;   }   void UPD(int &a, int b) {     if (a == -1)       a = b;     else       a = min(a, b);   }   int main() {     n = in();     cin >> s;     s =     + s;     for (int i = 1; i <= n; i++) {       a[i] = (s[i] ==  V ) ? 1 : (s[i] ==  K ) ? 2 : 0;       d[a[i]]++;     }     memset(f, -1, sizeof(f));     f[0][0][0][0] = f[0][0][0][1] = 0;     for (int z = 0; z <= d[0]; z++)       for (int v = 0; v <= d[1]; v++)         for (int k = 0; k <= d[2]; k++)           for (int ov = 0; ov <= 1; ov++)             if (f[z][v][k][ov] >= 0) {               for (int nd = 0; nd <= 2; nd++) {                 if (ov == 1 && nd == 2) continue;                 int Z = z + (nd == 0), V = v + (nd == 1), K = k + (nd == 2);                 int d[5];                 d[0] = z, d[1] = v, d[2] = k;                 int left = 0;                 for (int i = 1; i <= n; i++) {                   if (a[i] == nd && d[a[i]] == 0) break;                   if (d[a[i]] == 0)                     left++;                   else                     d[a[i]]--;                 }                 UPD(f[Z][V][K][(nd == 1)], f[z][v][k][ov] + left);               }             }     int res = -1;     for (int ov = 0; ov <= 1; ov++) UPD(res, f[d[0]][d[1]][d[2]][ov]);     if (res == -1)       cout << 0;     else       cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long mod1 = 998244353;   const double pie = 3.1415926535;   unsigned long long power(unsigned long long x, unsigned long long y) {     if (y == 0)       return 1;     else {       if (y % 2 == 0)         return power(x * x, y / 2);       else         return x * power(x * x, (y - 1) / 2);     }   }   long long mod_power(long long x, long long y, long long m) {     long long r = 1;     x = x % m;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) r = (r * x) % m;       y = y / 2;       x = (x * x) % m;     }     return r;   }   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   vector<long long> extended_Euclid(long long a, long long b) {     vector<long long> v(3);     if (b == 0) {       v[0] = a;       v[1] = 1;       v[2] = 0;       return v;     } else {       vector<long long> v1 = extended_Euclid(b, a % b);       v[0] = v1[0];       v[1] = v1[2];       v[2] = v1[1] - (a / b) * v1[2];       return v;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int TESTS = 1;     cin >> TESTS;     while (TESTS--) {       unsigned long long a;       cin >> a;       unsigned long long c = 0;       c = __builtin_popcount(a);       cout << power(2, c) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long binPow(long long a, long long b) {     long long x = 1, y = a;     while (b) {       if (b & 1) x = (x * y) % mod;       y = (y * y) % mod;       b >>= 1;     }     return x % mod;   }   long long inverserEuler(int n) { return binPow(n, mod - 2); }   long long C(int k, int n) {     vector<long long> f(n + 1, 1);     for (int i = 2; i <= n; i++) f[i] = (f[i - 1] * i) % mod;     return (f[n] * ((inverserEuler(f[k]) * inverserEuler(f[n - k])) % mod) %             mod) %            mod;   }   void trunghieu() {     int n;     cin >> n;     int a[n], i, j;     map<int, int> cnt;     for (i = 0; i < n; ++i) cin >> a[i], cnt[a[i]]++;     if (cnt.size() == 2) {       map<int, int>::iterator it;       it = cnt.begin();       int n1 = it->second, x1 = it->first;       it++;       int n2 = it->second, x2 = it->first;       ;       if (n1 == n2)         cout <<  YES  << endl << x1 <<     << x2;       else         cout <<  NO ;     } else       cout <<  NO ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie();     trunghieu();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, p, l, r, K;   long long int gt[100005], rev[100005], gt1[100005];   long long int mu(long long int a, long long int n, long long int K) {     if (n == 0) return 1;     long long int q = mu(a, n / 2, K);     if (n % 2 == 0) return q * q % K;     return q * q % K * a % K;   }   long long int Combi(long long int n, long long int k, long long int p) {     if (n < k || k < 0) return 0;     long long int u = gt1[n] - gt1[n - k] - gt1[k];     long long int res = gt[n] * rev[k] % K * rev[n - k] % K;     res = res * mu(p, u, K) % K;     return res;   }   long long int solve(long long int p, long long int k) {     K = 1;     long long int phi = 1;     for (int i = 1; i <= k; i++) K *= p;     phi = K / p * (p - 1);     gt[0] = rev[0] = 1;     for (int i = 1; i <= 100000; i++) {       gt1[i] = gt1[i - 1];       int j = i;       while (j % p == 0) {         j /= p;         gt1[i]++;       }       gt[i] = gt[i - 1] * 1ll * j % K;       rev[i] = mu(gt[i], phi - 1, K);     }     long long int res = 0;     for (int m = 1; m <= n; m++) {       int u = (m + l - 1) / 2 + 1;       int v = (m + r) / 2;       res =           (res + Combi(n, m, p) * (Combi(m, u, p) - Combi(m, v + 1, p)) % K + K) %           K;     }     return res;   }   vector<pair<long long int, long long int> > divi;   long long int extended_euclid(long long int a, long long int b,                                 long long int &x, long long int &y) {     long long int xx = y = 0;     long long int yy = x = 1;     while (b) {       long long int q = a / b;       long long int t = b;       b = a % b;       a = t;       t = xx;       xx = x - q * xx;       x = t;       t = yy;       yy = y - q * yy;       y = t;     }     return a;   }   long long int CRT(long long int m1, long long int r1, long long int m2,                     long long int r2) {     long long int s, t;     extended_euclid(r1, r2, s, t);     long long int K = r1 * r2;     long long int res = (m2 - m1) * s % K * r1 % K;     res = (res + m1 + K) % K;     return res;   }   long long int val[100005];   long long int mod[100005];   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> p >> l >> r;     if (p == 1) {       cout << 0 << endl;       return 0;     }     for (int i = 2; i <= p / i; i++) {       if (p % i == 0) {         int cnt = 0;         while (p % i == 0) {           p /= i;           cnt++;         }         divi.push_back(pair<long long int, long long int>(i, cnt));       }     }     if (p > 1) divi.push_back(pair<long long int, long long int>(p, 1));     for (int i = 0; i < divi.size(); i++) {       val[i] = solve(divi[i].first, divi[i].second);       mod[i] = 1;       for (int j = 1; j <= divi[i].second; j++) mod[i] *= divi[i].first;     }     long long int res = val[0];     long long int M = mod[0];     for (int i = 1; i < divi.size(); i++) {       res = CRT(res, M, val[i], mod[i]);       M *= mod[i];     }     if (l == 0) res = (res + 1) % M;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int s, n, m, t, x, y;   vector<int> ord;   vector<vector<int>> g;   bool vis[200010];   void dfs(int c) {     vis[c] = true;     for (auto &v : g[c]) {       if (!vis[v]) dfs(v);     }     ord.push_back(c);   }   int main() {     std::istream::sync_with_stdio(false);     cin >> s;     while (s--) {       cin >> n >> m;       vector<pair<int, int>> edges;       g = vector<vector<int>>(n + 1);       for (int i = 0; i < m; i++) {         cin >> t >> x >> y;         if (t == 1) {           g[x].push_back(y);         }         edges.emplace_back(x, y);       }       ord.clear();       memset(vis, 0, sizeof(vis));       for (int i = 1; i <= n; i++) {         if (!vis[i]) dfs(i);       }       vector<int> pos(n + 1);       reverse(ord.begin(), ord.end());       for (int i = 0; i < n; i++) {         pos[ord[i]] = i;       }       bool flag = false;       for (int i = 1; i <= n; i++) {         for (auto &v : g[i]) {           if (pos[i] > pos[v]) flag = true;         }       }       if (flag) {         cout <<  NO  << endl;         continue;       } else {         cout <<  YES  << endl;         for (auto &v : edges) {           if (pos[v.first] < pos[v.second]) {             cout << v.first <<     << v.second << endl;           } else {             cout << v.second <<     << v.first << endl;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, l, top, tmp, m, c[12];   bool opt[12][11][1 << 13];   void Search(int t, int v, int sum, int u, int i) {     if (v < 0) return;     if (sum >= v) opt[t][sum - v][u | (1 << t)] = 1;     if (i >= t) return;     if (((u >> i) & 1) == 1 && c[i] + 1 < c[t])       Search(t, v - c[i], sum, u ^ (1 << i), i + 1);     Search(t, v, sum, u, i + 1);   }   bool Check() {     for (int i = 0; i < l; i++)       if (c[i] == 2) return 0;     return 1;   }   int main() {     scanf( %d , &n);     l = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &tmp);       if (tmp > 1) c[l++] = tmp;     }     if (l > n / 2) {       printf( NO n );       return 0;     }     if (l == 0) {       if (n > 1)         printf( NO n );       else         printf( YES n );       return 0;     }     sort(c, c + l);     top = n - l - c[0] + 1;     opt[0][top][1] = 1;     for (int i = 1; i < l; i++)       for (int t = 0; t <= top; t++) {         m = 1 << i;         for (int u = 0; u < m; u++)           if (opt[i - 1][t][u]) Search(i, c[i] - 1, t, u, 0);       }     if (opt[l - 1][0][1 << (l - 1)] && Check())       printf( YES n );     else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     char c;     cin >> n >> m;     vector<int> rows(n), cols(m);     vector<vector<bool> > A(n);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         cin >> c;         if (c ==  * ) {           A[i].push_back(true);           rows[i]++;           cols[j]++;         } else           A[i].push_back(false);       }     long long res = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (A[i][j]) res += (cols[j] - 1) * (rows[i] - 1);     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<vector<int>> t(n);     for (int i = 0; i < m; ++i) {       int x, y;       scanf( %d %d , &x, &y);       --x, --y;       t[x].push_back(y);       t[y].push_back(x);     }     vector<int> dist(n * n, -1);     vector<pair<int, int>> parent(n * n, make_pair(-1, -1));     vector<bool> order(n * n, false);     queue<pair<int, int>> q;     q.push(make_pair(0, n - 1));     dist[n - 1] = 0;     while (!q.empty()) {       auto p = q.front();       q.pop();       if (p.first == n - 1 && p.second == 0) {         int len = dist[(n - 1) * n];         printf( %d n , len);         vector<int> r1, r2;         r1.push_back(n - 1);         r2.push_back(0);         int pos1 = n - 1, pos2 = 0;         while (pos1 != 0 || pos2 != n - 1) {           int tmp = pos1;           pos1 = parent[pos1 * n + pos2].first;           pos2 = parent[tmp * n + pos2].second;           r1.push_back(pos1);           r2.push_back(pos2);         }         for (int i = len; i >= 0; --i) printf( %d  , r1[i] + 1);         printf(  n );         for (int i = len; i >= 0; --i) printf( %d  , r2[i] + 1);         printf(  n );         return 0;       }       for (auto i : t[p.first]) {         if (order[i * n + p.second]) continue;         order[i * n + p.second] = true;         for (auto j : t[p.second]) {           if (i != j && dist[i * n + j] == -1) {             parent[i * n + j] = p;             dist[i * n + j] = dist[p.first * n + p.second] + 1;             q.push(make_pair(i, j));           }         }       }     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mo = 1e9 + 7;   const int N = 200005;   map<int, int> mx, my;   int n, x, y, dx, dy, cnt, answer;   int parent[N], Size[N];   bool flag[N];   int get_parent(int x) {     if (parent[x] == x) {       return x;     } else {       return get_parent(parent[x]);     }   }   int main() {     cin >> n;     for (int i = 1; i <= 2 * n; ++i) {       parent[i] = i;       Size[i] = 1;     }     for (int i = 1; i <= n; ++i) {       cin >> x >> y;       if (mx.find(x) != mx.end()) {         dx = mx[x];       } else {         dx = mx[x] = ++cnt;       }       if (my.find(y) != my.end()) {         dy = my[y];       } else {         dy = my[y] = ++cnt;       }       dx = get_parent(dx);       dy = get_parent(dy);       if (dx == dy) {         flag[dx] = 1;       } else {         if (Size[dx] > Size[dy]) swap(dx, dy);         parent[dx] = dy;         Size[dy] += Size[dx];         flag[dy] |= flag[dx];       }     }     answer = 1;     for (int i = 1; i <= cnt; ++i) {       if (get_parent(i) == i) {         int temp = 1;         for (int j = 1; j <= Size[i]; ++j) {           temp = temp * 2 % mo;         }         if (!flag[i]) --temp;         answer = (long long)answer * temp % mo;       }     }     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, x;     cin >> n >> x;     int mins = 0;     int prevr = 1;     for (int i = 0; i < int(n); i++) {       int l, r;       cin >> l >> r;       mins += ((l - prevr) % x + ((r - l) + 1));       prevr = r + 1;     }     cout << mins << endl;   }


#include <bits/stdc++.h>   using namespace std;   int dp[2005][2005][2][2];   int m, d, mod = 1e9 + 7;   string a, b;   int solve(int i, int mm, bool aa, bool bb) {     if (i == a.size()) return !mm;     int &x = dp[i][mm][aa][bb];     if (x != -1) return x;     x = 0;     for (int j = 0; j <= 9; j++) {       if (i % 2 && j != d || !(i % 2) && j == d) continue;       if (!aa && a[i] -  0  > j || !bb && b[i] -  0  < j) continue;       bool na = aa | a[i] -  0  < j, nb = bb | b[i] -  0  > j;       x = (x + solve(i + 1, (mm * 10 + j) % m, na, nb)) % mod;     }     return x;   }   int main() {     cin >> m >> d >> a >> b;     memset(dp, -1, sizeof dp);     cout << solve(0, 0, 0, 0);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long linf = 1e18;   const double pi = acos(-1.0);   const int MAXN = 150000 + 10;   const int MAXM = 1e5 + 10;   const double eps = 1e-8;   bool du[MAXN];   vector<int> g[MAXN];   bool vis[MAXN];   int sum;   bool flag;   void dfs(int u, int num) {     if (!flag) return;     vis[u] = 1;     ++sum;     for (int i = 0; i < g[u].size(); ++i) {       int v = g[u][i];       if (vis[v]) continue;       if (num != g[v].size()) {         flag = 0;         return;       }       dfs(v, num);     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     while (m--) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     flag = 1;     for (int i = 1; i <= n; ++i) {       if (!vis[i]) {         sum = 0;         dfs(i, g[i].size());         if (g[i].size() != sum - 1) flag = 0;       }       if (!flag) break;     }     puts(flag ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> t;     while (t--) {       string s;       cin >> s;       s =  0  + s;       s = s +  0 ;       for (int i = 1; i <= s.size(); i++) {         if (s[i] ==  ? ) {           if (s[i - 1] ==  a ) {             if (s[i + 1] ==  b ) {               s[i] =  c ;             } else {               s[i] =  b ;             }           } else {             if (s[i - 1] ==  b ) {               if (s[i + 1] ==  a ) {                 s[i] =  c ;               } else {                 s[i] =  a ;               }             } else {               if (s[i + 1] ==  b ) {                 s[i] =  a ;               } else {                 s[i] =  b ;               }             }           }         }       }       bool b = 1;       for (int i = 1; i <= s.size(); i++) {         if (s[i] == s[i - 1]) {           b = 0;         }       }       if (b) {         for (int i = 1; i <= s.size() - 2; i++) {           cout << s[i];         }       } else {         cout <<  -1 ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mas[21][21];   int n, m;   inline bool checkarr() {     for (int i = 0; i < n; i++) {       int wrongs = 0;       for (int j = 0; j < m; j++) {         if (mas[i][j] != j + 1) wrongs++;         if (wrongs > 2) return false;       }     }     return true;   }   inline void swapa(int a, int b) {     for (int j = 0; j < n; j++) {       int t = mas[j][a];       mas[j][a] = mas[j][b];       mas[j][b] = t;     }   }   int main() {     cin >> n >> m;     int i, j;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> mas[i][j];       }     }     if (checkarr()) {       cout <<  YES ;       return 0;     }     for (i = 0; i < m; i++) {       for (j = i + 1; j < m; j++) {         swapa(i, j);         if (checkarr()) {           cout <<  YES ;           return 0;         }         swapa(i, j);       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mxN = 1e5 + 5;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   signed main() {     long long n;     cin >> n;     vector<string> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i];     }     map<long long, long long> o, c;     long long per = 0;     for (long long i = 0; i < n; i++) {       string s = v[i];       stack<long long> st;       for (auto x : s) {         if (st.empty()) {           st.push(x);         } else {           if (x ==  ) ) {             if (st.top() ==  ( )               st.pop();             else               st.push(x);           } else             st.push(x);         }       }       if (st.empty())         per++;       else {         long long open = 0, closing = 0;         while (!st.empty()) {           if (st.top() ==  ) )             open++;           else             closing++;           st.pop();         }         if (open == 0) {           c[closing]++;         }         if (closing == 0) {           o[open]++;         }       }     }     long long ans = per / 2;     for (auto x : o) {       ans += min(x.second, c[x.first]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   vector<int> cur;   unordered_set<long long> bad;   unordered_set<int> was;   void err() {     cout <<  impossible  << endl;     exit(0);   }   void go(int x) {     cur.push_back(x);     vector<int> g;     for (auto it = was.begin(); it != was.end(); it++)       if (bad.count(x * 1000000ll + (*it)) == 0) g.push_back(*it);     for (int i = 0; i < g.size(); i++) was.erase(g[i]);     for (int i = 0; i < g.size(); i++) go(g[i]);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       bad.insert(x * 1000000ll + y);       bad.insert(y * 1000000ll + x);     }     for (int i = 1; i < n; i++) was.insert(i);     vector<vector<int> > comps;     for (int i = 1; i < n; i++)       if (was.count(i)) {         cur.clear();         was.erase(i);         go(i);         comps.push_back(cur);       }     int sum = 0;     for (int i = 0; i < comps.size(); i++) {       int cnt = 0;       for (int j = 0; j < comps[i].size(); j++)         if (bad.count(comps[i][j]) == 0) cnt++;       if (cnt == 0) err();       sum += cnt;     }     if (k < comps.size() || k > sum) err();     cout <<  possible  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Tp>   inline void read(Tp &x) {     static bool neg;     static char c;     x = 0, neg = 0, c = getchar();     for (; !isdigit(c); c = getchar()) {       if (c ==  - ) {         neg = 1;       }     }     for (; isdigit(c); c = getchar()) {       x = x * 10 + c -  0 ;     }     if (neg) {       x = -x;     }   }   const int INF = 0x3f3f3f3f;   const int N = 3e3 + 5;   const int M = 2e4 + 5;   const int K = 1e5 + 5;   int vis[N][N], dp[N][N];   int n, m, k;   int head[N], E = 0;   struct Edge {     int to, next;   } e[M * 2];   inline void addEdge(int u, int v) {     e[++E] = (Edge){v, head[u]};     head[u] = E;   }   namespace Trie {   unordered_map<int, unordered_map<int, unordered_set<int>>> store;   inline void set(int a, int b, int c) { store[a][b].insert(c); }   inline bool get(int a, int b, int c) { return (bool)store[a][b].count(c); }   }  // namespace Trie   int main() {     read(n), read(m), read(k);     for (int i = 0, u, v; i < m; ++i) {       read(u), read(v);       addEdge(u, v);       addEdge(v, u);     }     for (int i = 0, a, b, c; i < k; ++i) {       read(a), read(b), read(c);       Trie::set(a, b, c);     }     memset(vis, -1, sizeof(vis));     memset(dp, 0x3f, sizeof(dp));     dp[0][1] = 0;     queue<pair<int, int>> q;     q.emplace((pair<int, int>){0, 1});     while (!q.empty()) {       pair<int, int> u = q.front();       q.pop();       int a = u.first, b = u.second, c;       for (int i = head[b]; i; i = e[i].next) {         c = e[i].to;         if (vis[b][c] == -1) {           if (!Trie::get(a, b, c)) {             vis[b][c] = a;             dp[b][c] = dp[a][b] + 1;             q.emplace((pair<int, int>){b, c});           }         }       }     }     int ans = INF, ansPos;     for (int i = 1; i <= n; ++i) {       if (dp[i][n] < ans) {         ans = dp[i][n];         ansPos = i;       }     }     if (ans == INF) {       puts( -1 );       return 0;     } else {       printf( %d n , ans);       vector<int> vec;       vec.emplace_back(n);       vec.emplace_back(ansPos);       int u = ansPos, v = n;       while (u != 1) {         int t = v;         v = u;         u = vis[u][t];         vec.emplace_back(u);       }       for (auto it = vec.rbegin(); it != vec.rend(); ++it) {         printf( %d  , *it);       }     }   }


#include <bits/stdc++.h>   using namespace std;   void add(int& a, int b) {     a += b;     a = min(a, 100000000);   }   const int MX = 300005;   int root[MX];   bool is_left[MX];   vector<int> nodes[MX];   int left_size[MX], right_size[MX];   int ans = 0;   char s[MX];   vector<int> comps[MX];   int main() {     int n, k;     ignore = scanf( %d %d , &n, &k);     ignore = scanf(  %s , s + 1);     for (int i = 1; i <= k; i++) {       int c;       ignore = scanf(  %d , &c);       while (c--) {         int x;         ignore = scanf( %d , &x);         comps[x].push_back(i);       }     }     for (int i = 1; i <= k; i++) {       root[i] = i;       is_left[i] = false;       nodes[i].push_back(i);       right_size[i] = 1;     }     for (int i = 1; i <= n; i++) {       if (comps[i].size() == 1) {         int x = comps[i][0];         ans -= min(left_size[root[x]], right_size[root[x]]);         if (s[i] ==  0 ) {           if (is_left[x]) {             add(right_size[root[x]], MX);           } else {             add(left_size[root[x]], MX);           }         } else {           if (is_left[x]) {             add(left_size[root[x]], MX);           } else {             add(right_size[root[x]], MX);           }         }         ans += min(left_size[root[x]], right_size[root[x]]);       } else if (comps[i].size() == 2) {         int x = comps[i][0], y = comps[i][1];         if (root[x] != root[y]) {           ans -= min(left_size[root[x]], right_size[root[x]]);           ans -= min(left_size[root[y]], right_size[root[y]]);           if (nodes[root[x]].size() > nodes[root[y]].size()) {             swap(x, y);           }           if ((is_left[x] == is_left[y]) != (s[i] ==  1 )) {             for (int v : nodes[root[x]]) is_left[v] = !is_left[v];             swap(left_size[root[x]], right_size[root[x]]);           }           add(left_size[root[y]], left_size[root[x]]);           add(right_size[root[y]], right_size[root[x]]);           for (int v : nodes[root[x]]) {             nodes[root[y]].push_back(v);             root[v] = root[y];           }           ans += min(left_size[root[x]], right_size[root[x]]);         }       }       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   template <typename T>   T sqr(T x) {     return x * x;   }   double sind(double x) { return sin(x * PI / 180); }   double cosd(double x) { return cos(x * PI / 180); }   double tand(double x) { return tan(x * PI / 180); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int r, c, i, j, x = 0, y = 0;     cin >> r >> c;     vector<string> v;     bool mark[c + 1];     memset(mark, 0, sizeof(mark));     for (i = 0; i < r; i++) {       string s;       cin >> s;       v.push_back(s);     }     for (auto i : v) {       string s;       bool f = 1;       s = i;       for (j = 0; j < c; j++) {         if (s[j] ==  S ) {           f = 0;           mark[j] = 1;         }       }       if (f) x++;     }     for (i = 0; i < c; i++) {       if (mark[i] == 0) y++;     }     int ans = 0;     ans += x * c;     ans += y * (r - x);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Graph {     long long int v;     list<pair<long long int, long long int>> *adj;       public:     Graph(long long int v) : v(v) {       adj = new list<pair<long long int, long long int>>[v];     }     void addEdge(long long int u, long long int v, long long int w,                  bool bidir = true) {       adj[u].push_back(make_pair(v, w));       if (bidir) adj[v].push_back(make_pair(u, w));     }     void dijkstra() {       vector<long long int> distance(v, LONG_MAX);       priority_queue<pair<long long int, long long int>,                      vector<pair<long long int, long long int>>,                      greater<pair<long long int, long long int>>>           pq;       pq.push(make_pair(0, 0));       distance[0] = 0;       while (!pq.empty()) {         auto ele = pq.top();         pq.pop();         for (auto itr = adj[ele.second].begin(); itr != adj[ele.second].end();              itr++) {           long long int v = itr->first;           long long int weight = itr->second;           if (distance[ele.second] != LONG_MAX &&               distance[ele.second] + weight < distance[v]) {             distance[v] = distance[ele.second] + weight;             pq.push(make_pair(distance[v], v));           }         }       }       for (auto ele : distance) cout << ele <<    ;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long int n;     cin >> n;     vector<long long int> v(n);     for (long long int i = 0; i < n; i++) cin >> v[i];     Graph g(n);     for (long long int i = 0; i < n - 1; i++) g.addEdge(i, i + 1, 1);     for (long long int i = 0; i < n; i++)       if (i != v[i] - 1) g.addEdge(i, v[i] - 1, 1, false);     g.dijkstra();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using Long = int64_t;   constexpr Long Z = 0;   bool fire(Long N, Long M, int K, const vector<Long>& X, const vector<Long>& Y,             Long t) {     map<Long, int> xs;     map<Long, int> ys;     xs[0] = 0;     xs[N] = 0;     ys[0] = 0;     ys[M] = 0;     for (int i = 0; i < K; ++i) {       Long x = X[i];       Long y = Y[i];       xs[max(x - t, Z)] = 0;       xs[min(x + 1 + t, N)] = 0;       ys[max(y - t, Z)] = 0;       ys[min(y + 1 + t, M)] = 0;     }     int i = 0;     for (auto& p : xs) {       p.second = i++;     }     i = 0;     for (auto& p : ys) {       p.second = i++;     }     int nx = (int)xs.size();     int ny = (int)ys.size();     vector<vector<bool>> mat(ny + 1, vector<bool>(nx + 1));     for (int i = 0; i < K; ++i) {       Long x = X[i];       Long y = Y[i];       int bx = xs[max(x - t, Z)];       int ex = xs[min(x + 1 + t, N)];       int by = ys[max(y - t, Z)];       int ey = ys[min(y + 1 + t, M)];       for (int y = by; y < ey; ++y)         for (int x = bx; x < ex; ++x) mat[y][x] = 1;     }     int bx = -1;     int ex = -1;     int by = -1;     int ey = -1;     for (int y = 0; y < ny - 1; ++y) {       for (int x = 0; x < nx - 1; ++x) {         if (mat[y][x]) continue;         if (bx == -1) {           bx = x;           ex = x + 1;           by = y;           ey = y + 1;         } else {           bx = min(bx, x);           ex = max(ex, x + 1);           by = min(by, y);           ey = max(ey, y + 1);         }       }     }     if (bx == -1) return true;     Long bxx = 0, exx = N, byy = 0, eyy = M;     for (const auto& p : xs) {       if (p.second == bx) bxx = p.first;       if (p.second == ex) exx = p.first;     }     for (const auto& p : ys) {       if (p.second == by) byy = p.first;       if (p.second == ey) eyy = p.first;     }     if (exx - bxx > 2 * t + 1 || eyy - byy > 2 * t + 1) return false;     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     long N, M;     int K;     cin >> N >> M >> K;     vector<Long> X(K), Y(K);     for (int i = 0; i < K; ++i) {       cin >> X[i] >> Y[i];       --X[i];       --Y[i];     }     Long lb = -1;     Long ub = max(N, M);     while (ub - lb >= 2) {       Long mid = (ub + lb) / 2;       if (fire(N, M, K, X, Y, mid)) {         ub = mid;       } else {         lb = mid;       }     }     cout << ub <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr long long INF = 2e18;   constexpr long long MOD = 1e9 + 7;   constexpr long long MAXN = 2e5 + 3;   void solve() {     long long n;     cin >> n;     long long k;     cin >> k;     vector<long long> arr(n);     for (long long i = 0; i < n; ++i) {       long long &x = arr[i];       cin >> x;     }     vector<long long> ans(n);     set<long long> s;     set<long long> c;     for (long long i = 0; i < 256; ++i) s.emplace(i);     long long last = -INF;     long long maxx = -1;     for (long long i = 0; i < n; ++i) {       pair<long long, long long> x = pair<long long, long long>(arr[i], i);       long long v = -1;       for (long long j = arr[i]; j >= max(0ll, arr[i] - k + 1); --j) {         if (s.count(j)) {           v = j;         }         if (c.count(j)) {           v = j;           break;         }       }       for (long long i = v; i <= x.first; ++i) {         if (s.count(i)) s.erase(i);       }       c.emplace(v);       ans[i] = v;     }     for (long long x : ans) {       cout << x <<    ;     }     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[100010], s[100010], sp, cnt;   long long tot, sum, pj;   int main() {     cin >> n >> m;     for (register int i = 1; i <= n; i++) cin >> a[i], tot += a[i];     if (tot % m != 0) {       cout <<  No  << endl;       return 0;     }     pj = tot / m;     for (register int i = 1; i <= n; i++) {       sum += a[i];       if (sum == pj) {         sum = 0;         s[++cnt] = i - sp;         sp = i;       }       if (sum > pj) {         cout <<  No  << endl;         return 0;       }     }     cout <<  Yes  << endl;     for (register int i = 1; i <= cnt; i++) cout << s[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int fre[26] = {0};     for (int i = 0; i < n; i++) {       fre[s[i] -  a ] = fre[s[i] -  a ] + 1;     }     string ans =   ;     for (int i = 0; i < 26; i++) {       for (int j = 0; j < fre[i]; j++) {         ans = ans + char(97 + i);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:64000000 )   struct arc {     int f, s, prev;   } arr[300000];   int q[100005];   int beg[100005];   int kol = 0;   void add_arc(int f, int s) {     f--;     s--;     arr[kol].f = f;     arr[kol].s = s;     arr[kol].prev = beg[f];     beg[f] = kol++;     arr[kol].f = s;     arr[kol].s = f;     arr[kol].prev = beg[s];     beg[s] = kol++;   }   long long tmp[100005];   long long DFS(int pos, int fr = 0, int p = -1) {     long long child = 0, ret = 0;     int nfr = 0;     for (int i = beg[pos]; i != -1; i = arr[i].prev) {       if (arr[i].s == p) {         continue;       }       if (q[arr[i].s] > 1) {         q[arr[i].s]--;         tmp[fr + nfr] = DFS(arr[i].s, fr + nfr, pos) + 1;         child += q[arr[i].s];         nfr++;       } else {         child += q[arr[i].s];       }     }     sort(tmp + fr, tmp + fr + nfr, greater<long long>());     if (nfr >= q[pos]) {       for (int i = 0; i < q[pos]; i++) {         ret += tmp[fr + i] + 1;       }       q[pos] = 0;     } else {       for (int i = 0; i < nfr; i++) {         ret += tmp[fr + i] + 1;       }       q[pos] -= nfr;       ret += 2 * min((long long)q[pos], child);       q[pos] -= min((long long)q[pos], child);     }     return ret;   }   int main() {     memset(beg, -1, sizeof beg);     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &q[i]);     }     for (int i = 0; i < n - 1; i++) {       int f, s;       scanf( %d%d , &f, &s);       add_arc(f, s);     }     int s;     scanf( %d , &s);     s--;     if (q[s] != 0) {       cout << DFS(s) << endl;     } else {       cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100100;   const long long oo = 1e18;   int N;   long long P[MAX], D[MAX];   int L[MAX], R[MAX];   void init_L() {     stack<int> S;     for (int i = 0; i <= N + 1; ++i) {       while (S.size() >= 2) {         int x = S.top();         S.pop();         if (D[x] >= P[i] - P[S.top()]) {           S.push(x);           break;         }       }       if (!S.empty()) L[i] = S.top();       S.push(i);     }   }   void init_R() {     stack<int> S;     for (int i = N + 1; i >= 0; --i) {       while (S.size() >= 2) {         int x = S.top();         S.pop();         if (D[x] >= P[S.top()] - P[i]) {           S.push(x);           break;         }       }       if (!S.empty()) R[i] = S.top();       S.push(i);     }   }   template <class T>   struct MinQ {     deque<T> D, Q;     T top() { return D.front(); }     void push(T x) {       while (!D.empty() && x < D.back()) D.pop_back();       D.push_back(x);       Q.push_back(x);     }     void pop() {       if (D.front() == Q.front()) D.pop_front();       Q.pop_front();     }     T front() { return Q.front(); }     T empty() { return Q.empty(); }     T size() { return Q.size(); }   };   long long low(int x) {     if (x == N + 1) return -1e10;     long long ret = P[R[x]] - D[x];     return ret < P[x] ? ret : +oo;   }   long long high(int x) {     if (x == 0) return +1e10;     long long ret = P[L[x]] + D[x];     return ret > P[x] ? ret : -oo;   }   bool check(long long W) {     MinQ<long long> Q;     for (int a = 0, b = 0; a <= N; ++a) {       for (; b <= N + 1 && P[b] - P[a] <= W; ++b) Q.push(low(b));       Q.pop();       if (!Q.empty() && high(a) >= Q.top()) return true;     }     return false;   }   int main() {     scanf( %d , &N);     for (int i = 0; i <= N + 1; ++i) scanf( %lld , P + i);     for (int i = 1; i <= N; ++i) scanf( %lld , D + i), D[i] *= 2;     D[0] = D[N + 1] = oo;     init_L();     init_R();     if (R[0] != N + 1) {       puts( 0 );       return 0;     }     long long lo = 1, hi = 1e10;     while (lo < hi) {       long long mid = (lo + hi) / 2;       check(mid) ? hi = mid : lo = mid + 1;     }     printf( %.1lf n , lo / 2.0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int t, sp[N];   map<int, int> n, m, s;   vector<pair<int, int> > _n, _m, _s;   long long n_val, m_val, s_val;   void sieve(void) {     for (int i = 2; i * i < N; ++i) {       if (sp[i]) continue;       sp[i] = i;       for (int j = i * i; j < N; j += i) {         if (sp[j]) continue;         sp[j] = i;       }     }     for (int i = 2; i < N; ++i) {       if (sp[i]) continue;       sp[i] = i;     }   }   int size;   long long Less;   void backtrack(int at, long long val) {     if (at == size) {       if (val <= n_val) ++Less;       return;     }     for (int i = 0; i <= _s[at].second; ++i) {       backtrack(at + 1, val);       val *= 1LL * _s[at].first;     }     return;   }   int main() {     sieve();     scanf( %d , &t);     while (t--) {       n.clear(), m.clear(), s.clear();       _n.clear(), _m.clear(), _s.clear();       for (int i = 0; i < 3; ++i) {         int x;         scanf( %d , &x);         while (x > 1) {           int p = sp[x];           while (x % p == 0) {             ++n[p], x /= p;           }         }       }       for (int i = 0; i < 3; ++i) {         int x;         scanf( %d , &x);         while (x > 1) {           int p = sp[x];           while (x % p == 0) {             ++m[p], x /= p;           }         }       }       for (int i = 0; i < 3; ++i) {         int x;         scanf( %d , &x);         while (x > 1) {           int p = sp[x];           while (x % p == 0) {             ++s[p], x /= p;           }         }       }       ++s[2];       n_val = m_val = s_val = 1LL;       for (auto it : n) {         _n.emplace_back(it.first, it.second);         for (int i = 0; i < it.second; ++i) {           n_val *= 1LL * it.first;         }       }       for (auto it : m) {         _m.emplace_back(it.first, it.second);         for (int i = 0; i < it.second; ++i) {           m_val *= 1LL * it.first;         }       }       for (auto it : s) {         _s.emplace_back(it.first, it.second);         for (int i = 0; i < it.second; ++i) {           s_val *= 1LL * it.first;         }       }       int sz = _n.size();       long long tot = m_val;       for (int mask = 1; mask < 1 << sz; ++mask) {         int nope = 0, on = 0;         long long num = 1LL;         for (int i = 0; i < sz; ++i) {           if (!(mask & 1 << i)) continue;           ++on;           int p = _n[i].first, e = _n[i].second;           if (s[p] + 1 > e) {             nope = 1;             break;           }           for (int j = 0; j <= s[p]; ++j) {             num *= 1LL * p;           }         }         if (nope) continue;         long long cur = m_val / num;         if (on & 1) cur = -cur;         tot += cur;       }       Less = 0;       size = _s.size();       backtrack(0, 1LL);       tot += Less;       printf( %lld n , tot);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 25;   int main(int argc, char *argv[]) {     int n, k;     cin >> n >> k;     string a[n];     for (int i = (0), _b = (n); i < (_b); ++i) cin >> a[i];     uint8_t g[4];     uint32_t b[n];     for (int i = (0), _b = (n); i < (_b); ++i) {       uint8_t x = 0;       int idx = 0;       for (int j = (0), _b = (a[i].length()); j < (_b); ++j) {         if (a[i][j] ==  . ) {           g[idx] = x;           x = 0;           ++idx;         } else           x = x * 10 + a[i][j] -  0 ;       }       g[idx] = x;       b[i] = (g[0] << 24) | (g[1] << 16) | (g[2] << 8) | g[3];     }     uint32_t mask = 0xffffffff;     uint32_t ans = 0;     while (mask) {       set<uint32_t> s;       for (int i = (0), _b = (n); i < (_b); ++i) s.insert(b[i] & mask);       if (s.size() == k) ans = mask;       mask <<= 1;     }     if (!ans)       cout << -1 << endl;     else {       uint8_t a0 = (ans >> 24) & 0xff;       uint8_t a1 = (ans >> 16) & 0xff;       uint8_t a2 = (ans >> 8) & 0xff;       uint8_t a3 = ans & 0xff;       printf( %d.%d.%d.%d n , a0, a1, a2, a3);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, vector<string> > mp;   string s;   int n, pos = 0;   ;   void dfs(int lvl) {     int j = pos;     while (s[j] !=  , ) j++;     mp[lvl].push_back(s.substr(pos, j - pos));     pos = j + 1;     j++;     while (s[j] !=  , ) j++;     int ct = stoi(s.substr(pos, j - pos));     pos = j + 1;     for (int i = 1; i <= ct; i++) dfs(lvl + 1);   }   int main() {     cin >> s;     s +=  , ;     n = s.length();     while (pos < n) dfs(1);     cout << mp.size() <<   n ;     for (auto it = mp.begin(); it != mp.end(); it++) {       vector<string> vec = (*it).second;       for (string str : vec) cout << str <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double n, m, a;     cin >> n >> m >> a;     cout << (long long)(ceil(n / a) * ceil(m / a));     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   using namespace std;   long long x[3], y[3];   int main() {     for (int i = 0; i < 3; i++) cin >> x[i] >> y[i];     if (x[0] == x[1] && x[0] == x[2] || y[0] == y[1] && y[0] == y[2]) {       printf( 1 n );       return 0;     }     int perm[3] = {0, 1, 2};     long long minx = min(x[0], min(x[1], x[2]));     long long maxx = max(x[0], max(x[1], x[2]));     long long miny = min(y[0], min(y[1], y[2]));     long long maxy = max(y[0], max(y[1], y[2]));     do {       long long x1 = x[perm[0]], y1 = y[perm[0]];       long long x2 = x[perm[1]], y2 = y[perm[1]];       long long x3 = x[perm[2]], y3 = y[perm[2]];       bool gr1 = false;       bool gr2 = false;       bool gr3 = false;       if ((x1 == minx || x1 == maxx) && (y1 == miny || y1 == maxy)) gr1 = true;       if ((x2 == minx || x2 == maxx) && (y2 == miny || y2 == maxy)) gr2 = true;       if ((x3 == minx || x3 == maxx) && (y3 == miny || y3 == maxy)) gr3 = true;       if (gr1 && gr2 && gr3) {         printf( 2 );         return 0;       }       if ((x1 == x2 || y1 == y2) && gr1 && gr3 && !gr2) {         printf( 2 );         return 0;       }     } while (next_permutation(perm, perm + 3));     printf( 3 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = int(1e9 + 7);   const double PI = acos(-1.0);   const int N = 200000;   long long n, a;   long long p[N], b[N];   bool check(int x) {     long long i, m;     m = a;     for (i = 0; i < x; i++)       if (b[n - x + i] < p[i]) m -= p[i] - b[n - x + i];     return (m >= 0);   }   int main() {     long long m, l, r, i;     cin >> n >> m >> a;     for (i = 0; i < n; i++) cin >> b[i];     for (i = 0; i < m; i++) cin >> p[i];     sort(b, b + n);     sort(p, p + m);     l = 0;     r = min(n, m);     while (l < r) {       m = (l + r + 1) / 2;       if (check(m))         l = m;       else         r = m - 1;     }     m = 0;     for (i = 0; i < l; i++) m += p[i];     cout << l <<     << max(0ll, m - a);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a[2005];   char s[2005];   int f[2005 * 2][2005], h[2005], n, m, k;   void dp(int l, int r, int x) {     if (l >= r) return;     int L = ++m, R = ++m, mid = l;     for (int i = l; i < r; i++)       if (h[i] < h[mid]) mid = i;     dp(l, mid, L), dp(mid + 1, r, R);     for (int i = 0; i < mid - l + 2; i++)       for (int j = 0; j < r - mid + 1; j++)         if (i + j <= k)           f[x][i + j] = max(f[x][i + j], h[mid] * i * j + f[L][i] + f[R][j]);   }   int main() {     scanf( %d%d  , &n, &k);     for (int i = 0; i < n; i++) gets(s), a[i] = s;     sort(a, a + n);     for (int i = 0; i < n - 1; i++) {       h[i] = min(a[i].size(), a[i + 1].size());       for (int j = 0; j < h[i]; j++)         if (a[i][j] != a[i + 1][j]) h[i] = j;     }     dp(0, n - 1, 0);     printf( %d n , f[0][k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<pair<int, int> > arr(n);       for (int i = 0; i < n; i++) cin >> arr[i].first;       for (int i = 0; i < n; i++) cin >> arr[i].second;       sort(arr.begin(), arr.end());       long long int cost = 1e18;       long long int prev = 0;       for (int i = n - 1; i >= 0; i--) {         cost = min(cost, max((long long int)arr[i].first, prev));         prev += arr[i].second;       }       cost = min(cost, prev);       cout << cost << endl;     }   }