#include <bits/stdc++.h>   using namespace std;   const int mod = 1000 * 1000 * 1000 + 7;   const int INF = 1e9 + 100;   const long long LINF = 1e18 + 100;   long long x, k;   const int n = 1e5;   vector<long long> divs;   vector<long long> ddv[7010];   vector<long long> fk[7010];   void getnxt(const vector<long long> &cur, vector<long long> &res) {     res.clear();     for (int ptr = 0; ptr < (int)cur.size() && (int)res.size() < n; ptr++) {       int p = lower_bound((divs).begin(), (divs).end(), cur[ptr]) - divs.begin();       for (int i = 0; i < (int)ddv[p].size() && (int)res.size() < n; i++)         res.push_back(ddv[p][i]);     }   }   void get2i(const vector<long long> &cur, vector<long long> &res) {     res.clear();     for (int i = (0); i < (7010); i++) fk[i].clear();     int cnum = 0;     for (long long u : cur) {       int p = lower_bound((divs).begin(), (divs).end(), u) - divs.begin();       fk[cnum].push_back(u);       if (p == cnum) cnum++;     }     for (int ptr = 0; ptr < (int)cur.size() && (int)res.size() < n; ptr++) {       int p = lower_bound((divs).begin(), (divs).end(), cur[ptr]) - divs.begin();       for (int i = 0; i < (int)fk[p].size() && (int)res.size() < n; i++)         res.push_back(fk[p][i]);     }     vector<long long> cop;     cop.swap(res);     getnxt(cop, res);   }   void getkth(vector<long long> &res, int k) {     if (k == 1) {       res = divs;       return;     }     getkth(res, k / 2);     vector<long long> cop;     cop.swap(res);     get2i(cop, res);     if (k % 2 == 0) return;     cop.clear();     cop.swap(res);     getnxt(cop, res);   }   int32_t main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> x >> k;     if (k == 0) return cout << x <<   n , 0;     if (x == 1) {       return cout <<  1 n , 0;     }     if (k > n) {       for (int i = (0); i < (n); i++) cout <<  1  ;       cout <<   n ;       return 0;     }     for (long long i = 1; i * i <= x; i++) {       if (x % i == 0) {         divs.push_back(i);         if (i * i != x) divs.push_back(x / i);       }     }     sort((divs).begin(), (divs).end());     for (int i = (0); i < ((int)divs.size()); i++) {       for (int j = (0); j < (i + 1); j++) {         if (divs[i] % divs[j] == 0) ddv[i].push_back(divs[j]);       }     }     vector<long long> ans;     getkth(ans, k);     for (long long u : ans) cout << u <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353, INF = 1e18;   vector<int> f;   int n;   int getsum(int i) {     int sum = 0;     i += 1;     while (i > 0) {       sum += f[i];       i -= (i & (-i));     }     return sum;   }   void update(int i, int val) {     i += 1;     while (i <= n + 1 && i > 0) {       f[i] += val;       i += (i & (-i));     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int q;     cin >> n >> q;     f.resize(n + 2, 0);     for (int i = 0; i < n; i++) {       int d;       cin >> d;       update(d, 1);     }     while (q--) {       int k;       cin >> k;       if (k > 0) {         update(k, 1);       } else {         k *= -1;         int l = 0, r = n;         while (l < r) {           int m = (l + r) / 2;           int p = getsum(m);           if (p >= k)             r = m;           else             l = m + 1;         }         update(l, -1);       }     }     int ans = 0;     for (int i = 2; i <= n + 1; i++)       if (f[i] > 0) {         ans = i - 1;         break;       }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read_string_to_vector(vector<string> &vec) {     string str;     getline(cin, str);     vec.push_back(str);   }   template <typename T>   inline void read_digit_to_vector(vector<T> &vec) {     T t;     cin >> t;     vec.push_back(t);   }   template <typename T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   long long n;   long long answ;   int main() {     scanf( %lld , &n);     while (n--) {       long long a;       scanf( %lld , &a);       answ ^= (a & 1) ^ 1;       printf(answ ?  1 n  :  2 n );     }     return 0;   }


#pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   #include <bits/stdc++.h>    using namespace std;       typedef long long ll;   #define S second   #define v vector   #define dbg(x)              cout<<#x<< = <<(x)<<endl;   #define dbg2(x,y)           cout<<#x<< = <<(x)<<   <<#y<< = <<(y)<<endl;   #define dbg3(x,y,z)         cout<<#x<< = <<(x)<<   <<#y<< = <<(y)<<   <<#z<< = <<(z)<<endl;   #define dbg4(x,y,z,w)       cout<<#x<< = <<(x)<<   <<#y<< = <<(y)<<   <<#z<< = <<(z)<<   <<#w<< = <<(w)<<endl;   #define mp make_pair   #define pb push_back   #define endl                  n    #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)          int main()   {    fast_cin();    ll t;    cin >> t;    while (t--)    {        ll x;        ll i;        ll n, flag = 0, mx = 0, mn = 1e10 + 1;        ll k;           cin >> n >> k;        set<ll> s1;        for (i = 0; i < n; i++)        {            cin >> x;            s1.insert(x);      }   ll z =-1;   ll mex = 0;   for (auto it = s1.begin(); it != s1.end();it++)   {   if(*it==z+1)       z++;   else   {       mex = z+1;   }      }   mex = z + 1;   if(k==0)       cout << s1.size() << endl;   else if(mex==*s1.rbegin())   {       cout << s1.size() << endl;      }   else   {       if(mex>*s1.rbegin())           cout << s1.size() + k << endl;   else   {       ll a = (mex + *s1.rbegin());   if(a%2)   {       a = a / 2;       a++;   }   else   {       a /= 2;   }   s1.insert(a);   cout << s1.size() << endl;      }   }      }   return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     vector<char> base(k,  ? );     for (long long i = 0; i < n; i++) {       if (s[i] ==  1 ) {         if (base[i % k] ==  1 ) {           continue;         }         if (base[i % k] ==  0 ) {           cout <<  NO  << endl;           return;         }         if (base[i % k] ==  ? ) {           base[i % k] =  1 ;         }       } else if (s[i] ==  0 ) {         if (base[i % k] ==  0 ) {           continue;         }         if (base[i % k] ==  1 ) {           cout <<  NO  << endl;           return;         }         if (base[i % k] ==  ? ) {           base[i % k] =  0 ;         }       } else {       }     }     long long zero = 0, one = 0;     for (long long i = 0; i < k; i++) {       if (base[i] ==  0 )         zero++;       else if (base[i] ==  1 )         one++;     }     if (one <= k / 2 && zero <= k / 2)       cout <<  YES  << endl;     else {       cout <<  NO  << endl;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     long long x, y;     bool operator<(const point& t) const {       if (x == t.x) return y < t.y;       return x < t.x;     }     bool operator==(const point& t) const { return x == t.x && y == t.y; }   };   const long long INF = 1e18;   const long long mod = 1e9 + 7;   const long long MAXN = 1e6 + 69;   long long q = 1, m, n, x, y, z, k, l;   point a[MAXN];   string s;   set<point> ans;   vector<point> X;   vector<point> solve(const vector<point>& X) {     if (X.size() <= 1) return X;     long long mid = X.size() / 2;     vector<point> a, b;     for (long long i = 0; i < mid; i++) {       a.push_back(X[i]);     }     for (long long i = mid; i < X.size(); i++) {       b.push_back(X[i]);     }     a = solve(a);     b = solve(b);     long long middle = (a.back().x + b[0].x) / 2;     vector<point> res;     for (long long i = 0; i < a.size(); i++) {       res.push_back(a[i]);       res.push_back({middle, a[i].y});     }     for (long long i = 0; i < b.size(); i++) {       res.push_back(b[i]);       res.push_back({middle, b[i].y});     }     sort(res.begin(), res.end());     res.resize(unique(res.begin(), res.end()) - res.begin());     return res;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; i++)       cin >> a[i].x >> a[i].y, ans.insert({a[i]});     sort(a + 1, a + n + 1);     for (long long i = 1; i <= n; i++) X.push_back(a[i]);     vector<point> ans = solve(X);     cout << ans.size() <<   n ;     for (point u : ans) cout << u.x <<     << u.y <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long n, m, u, v, st, cnt, a[N], check[N], num[N], low[N];   long long sz[N], val[N], sub[N], good[N];   vector<int> adj[N];   vector<pair<int, int> > edge;   map<pair<int, int>, bool> bridge;   void dfs(int u, int p) {     check[u] = 1;     num[u] = low[u] = ++cnt;     for (int v : adj[u]) {       if (check[v] == 0) {         dfs(v, u);         low[u] = min(low[u], low[v]);         if (num[u] < low[v]) {           bridge[{u, v}] = bridge[{v, u}] = 1;         }       } else {         if (v != p) {           low[u] = min(low[u], num[v]);         }       }     }   }   void dfs1(int u) {     check[u] = cnt;     val[cnt] += a[u];     for (int v : adj[u]) {       if (check[v] == 0) {         dfs1(v);       }     }   }   void dfs2(int u, int p) {     good[u] = (sz[u] > 1);     sub[u] = 0;     for (int v : adj[u]) {       if (v != p) {         dfs2(v, u);         good[u] |= good[v];         sub[u] = max(sub[u], sub[v]);       }     }     sub[u] += val[u];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);       edge.push_back({u, v});     }     cin >> st;     dfs(st, st);     for (int i = 1; i <= n; i++) {       check[i] = 0;       adj[i].clear();     }     for (auto tmp : edge) {       u = tmp.first;       v = tmp.second;       if (bridge[{u, v}] == 0) {         adj[u].push_back(v);         adj[v].push_back(u);       }     }     cnt = 0;     for (int i = 1; i <= n; i++) {       if (check[i] == 0) {         cnt++;         dfs1(i);       }     }     for (int i = 1; i <= n; i++) {       adj[i].clear();       sz[check[i]]++;     }     for (auto tmp : edge) {       u = tmp.first;       v = tmp.second;       if (bridge[{u, v}] == 1) {         adj[check[u]].push_back(check[v]);         adj[check[v]].push_back(check[u]);       }     }     int root = check[st];     dfs2(root, root);     long long ans = 0, mx = 0;     for (int i = 1; i <= cnt; i++) {       if (good[i] == 1) {         ans += val[i];       } else {         mx = max(mx, sub[i]);       }     }     cout << ans + mx;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &f) {     f = 0;     _T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) fu = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   template <typename T>   struct hash_map_t {     vector<T> v, val, nxt;     vector<int> head;     int mod, tot, lastv;     T lastans;     bool have_ans;     hash_map_t(int md = 0) {       head.clear();       v.clear();       val.clear();       nxt.clear();       tot = 0;       mod = md;       nxt.resize(1);       v.resize(1);       val.resize(1);       head.resize(mod);       have_ans = 0;     }     bool count(int x) {       int u = x % mod;       for (register int i = head[u]; i; i = nxt[i]) {         if (v[i] == x) {           have_ans = 1;           lastv = x;           lastans = val[i];           return 1;         }       }       return 0;     }     void ins(int x, int y) {       int u = x % mod;       nxt.push_back(head[u]);       head[u] = ++tot;       v.push_back(x);       val.push_back(y);     }     int qry(int x) {       if (have_ans && lastv == x) return lastans;       count(x);       return lastans;     }   };   const int N = 4e5 + 5;   struct edge_t {     int u, v, next;   } G[N << 1];   int maxn[N << 2], head[N], siz[N], ans[N], tops[N];   int n, tot, dfn;   inline void addedge(int u, int v) {     G[++tot] = (edge_t){u, v, head[u]}, head[u] = tot;     G[++tot] = (edge_t){v, u, head[v]}, head[v] = tot;   }   void update(int u) { maxn[u] = max(maxn[u << 1], maxn[u << 1 | 1]); }   void change(int u, int l, int r, int x, int y) {     if (l == r) {       maxn[u] = y;       return;     }     int mid = (l + r) >> 1;     if (mid >= x)       change(u << 1, l, mid, x, y);     else       change(u << 1 | 1, mid + 1, r, x, y);     update(u);   }   int query(int u, int l, int r, int L, int R) {     if (l > r) return 0;     if (l <= L && R <= r) return maxn[u];     int mid = (L + R) >> 1, ans = 0;     if (mid >= l) ans = max(ans, query(u << 1, l, r, L, mid));     if (mid + 1 <= r) ans = max(ans, query(u << 1 | 1, l, r, mid + 1, R));     return ans;   }   void dfs1(int u, int fa) {     tops[u] = ++dfn;     siz[u] = 1;     for (register int i = head[u]; i; i = G[i].next) {       int v = G[i].v;       if (v == fa) continue;       dfs1(v, u);       siz[u] += siz[v];     }     if (siz[u] <= (n >> 1)) change(1, 1, n, tops[u], siz[u]);   }   void dfs2(int u, int fa, int mx) {     bool qaq = 1;     if (n - siz[u] > (n >> 1) && max(max(query(1, 1, tops[u] - 1, 1, n),                                          query(1, tops[u] + siz[u], n, 1, n)),                                      mx) >= n - siz[u] - (n >> 1))       ans[u] = 1;     if (n - siz[u] <= (n >> 1))       mx = max(mx, n - siz[u]);     else       qaq = 0;     if (siz[u] <= (n >> 1)) change(1, 1, n, tops[u], 0);     for (register int i = head[u]; i; i = G[i].next) {       int v = G[i].v;       if (v == fa) continue;       dfs2(v, u, mx);       if (siz[v] > (n >> 1)) {         qaq = 0;         if (query(1, tops[u], tops[u] + siz[u] - 1, 1, n) >= siz[v] - (n >> 1))           ans[u] = 1;       }     }     if (qaq) ans[u] = 1;     if (siz[u] <= (n >> 1)) change(1, 1, n, tops[u], siz[u]);   }   int main() {     read(n);     for (register int i = 1; i < n; i++) {       int u, v;       read(u);       read(v);       addedge(u, v);     }     dfs1(1, 0);     dfs2(1, 0, 0);     for (register int i = 1; i <= n; i++) print(ans[i], i == n ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string str[100];   int func(string s1, string s2) {     int i, j, k;     int l1 = s1.length(), l2 = s2.length();     if (l1 != l2) return -1;     for (i = 0; i < l1; ++i) {       for (j = i, k = 0; k < l1; ++k, ++j) {         j = j % l1;         if (s1[k] != s2[j]) break;       }       if (k == l1) return i;     }     return -1;   }   int main() {     int i, j, k;     int n, cnt;     cin >> n;     for (i = 0; i < n; ++i) cin >> str[i];     int mn = 1000000000;     for (i = 0; i < n; ++i) {       cnt = 0;       for (j = 0; j < n; ++j) {         if (i == j) continue;         k = func(str[i], str[j]);         if (k == -1) {           printf( -1 n );           return 0;         }         cnt += k;       }       mn = min(mn, cnt);     }     cout << mn << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e4 + 10, M = 32, INF = 1e9 + 10;   int a, b, n;   int dp[N][M];   long long mypw(long long a, int b) {     double ans = pow(a, b);     if (ans > INF) {       return INF;     }     long long ret = 1;     while (b--) ret = ret * a;     return ret;   }   int check(int a, int b) {     if (a < N && b < M && dp[a][b] != -1) return dp[a][b];     if (a == 1 && mypw(a + 1, b) >= n) {       return 2;     }     if (b == 1 && mypw(a, b + 1) >= n) {       return !((n - a) & 1);     }     if (mypw(a, b) >= n) return dp[a][b] = 1;     int a1 = check(a + 1, b);     int a2 = check(a, b + 1);     if (a1 == 0 || a2 == 0) return dp[a][b] = 1;     if (a1 == 2 || a2 == 2) return dp[a][b] = 2;     return dp[a][b] = 0;   }   int main() {     scanf( %d%d%d , &a, &b, &n);     memset(dp, -1, sizeof(dp));     int t = check(a, b);     if (t == 1)       puts( Masha );     else if (t == 0)       puts( Stas );     else       puts( Missing );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const int INFMEM = 63;   const int INF = 1061109567;   const long long LINF = 4557430888798830399LL;   const double DINF = numeric_limits<double>::infinity();   const long long MOD = 1000000007;   const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};   const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};   const double PI = 3.141592653589793;   inline void open(string a) {     freopen((a +  .in ).c_str(),  r , stdin);     freopen((a +  .out ).c_str(),  w , stdout);   }   inline void fasterios() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   long long cnt[1000005];   pair<long long, long long> isi[100005];   bool isAscent[100005];   int main() {     fasterios();     long long n;     cin >> n;     long long cntascent = 0;     for (int i = 1; i <= n; i++) {       long long k;       cin >> k;       pair<long long, long long> cur;       long long pre = -1;       bool ascent = 0;       for (int j = 1; j <= k; j++) {         long long tmp;         cin >> tmp;         if (j == 1) {           cur.first = cur.second = tmp;           pre = tmp;         } else {           if (pre < tmp) ascent = 1;           pre = tmp;         }         cur.first = min(cur.first, tmp);         cur.second = max(cur.second, tmp);       }       isi[i] = cur;       if (!ascent) cnt[cur.first]++;       isAscent[i] = ascent;       cntascent += ascent;     }     for (int i = 0; i <= 1000000; i++) cnt[i] += cnt[i - 1];     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (isAscent[i]) {         ans += n;         continue;       }       long long now = isi[i].second;       ans += cnt[now - 1];       ans += cntascent;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> m;   vector<int> fr;   int v[100100];   int main() {     int n;     scanf( %d  , &n);     int mf = 0;     for (int i = 0; i < n; i++) {       int t;       scanf( %d  , &t);       v[i] = t;       m[t]++;       mf = max(mf, m[t]);     }     sort(begin(v), end(v));     fr.assign(mf + 2, 0);     for (auto& it : m) {       fr[it.second - 1]++;     }     int rs = 0;     int ma = 0;     for (int i = fr.size() - 2; i >= 0; i--) {       fr[i] = fr[i + 1] + fr[i];     }     for (int i = 0; i < fr.size(); i++) {       rs += fr[i];       ma = max(ma, rs - i - 1);     }     printf( %d n , ma);   }


#include <bits/stdc++.h>   using namespace std;   long long numC[200011];   long long numQ[200011];   long long numBC[200011];   long long numBQ[200011];   long long numQC[200011];   long long numQQ[200011];   long long triple(int n) {     if (n < 0) return 0;     if (n == 1) return 3;     if (n == 0) return 1;     long long temp = triple(n / 2);     long long res = (temp * temp) % 1000000007;     if (n % 2 == 0)       return res;     else       return (res * 3) % 1000000007;   }   int main() {     int n;     string str;     cin >> n >> str;     int qNum = 0;     for (int i = 0; i < n; i++)       if (str[i] ==  ? ) qNum++;     for (int i = n - 1; i >= 0; i--) {       if (str[i] ==  c )         numC[i] = numC[i + 1] + 1;       else         numC[i] = numC[i + 1];     }     for (int i = n - 1; i >= 0; i--) {       if (str[i] ==  ? )         numQ[i] = numQ[i + 1] + 1;       else         numQ[i] = numQ[i + 1];     }     for (int i = n - 1; i >= 0; i--) {       if (str[i] ==  b )         numBC[i] = numBC[i + 1] + numC[i + 1];       else         numBC[i] = numBC[i + 1];       numBC[i] %= 1000000007;     }     for (int i = n - 1; i >= 0; i--) {       if (str[i] ==  b )         numBQ[i] = numBQ[i + 1] + numQ[i + 1];       else         numBQ[i] = numBQ[i + 1];       numBQ[i] %= 1000000007;     }     for (int i = n - 1; i >= 0; i--) {       if (str[i] ==  ? )         numQC[i] = numQC[i + 1] + numC[i + 1];       else         numQC[i] = numQC[i + 1];       numQC[i] %= 1000000007;     }     for (int i = n - 1; i >= 0; i--) {       if (str[i] ==  ? )         numQQ[i] = numQQ[i + 1] + numQ[i + 1];       else         numQQ[i] = numQQ[i + 1];       numQQ[i] %= 1000000007;     }     long long t1 = 0;     for (int i = n - 1; i >= 0; i--)       if (str[i] ==  a ) t1 += numBC[i + 1];     t1 %= 1000000007;     long long t2 = 0;     for (int i = n - 1; i >= 0; i--)       if (str[i] ==  a ) t2 += numQC[i + 1];     for (int i = n - 1; i >= 0; i--)       if (str[i] ==  a ) t2 += numBQ[i + 1];     for (int i = n - 1; i >= 0; i--)       if (str[i] ==  ? ) t2 += numBC[i + 1];     t2 %= 1000000007;     long long t3 = 0;     for (int i = n - 1; i >= 0; i--)       if (str[i] ==  a ) t3 += numQQ[i + 1];     for (int i = n - 1; i >= 0; i--)       if (str[i] ==  ? ) t3 += numBQ[i + 1];     for (int i = n - 1; i >= 0; i--)       if (str[i] ==  ? ) t3 += numQC[i + 1];     t3 %= 1000000007;     long long t4 = 0;     for (int i = n - 1; i >= 0; i--)       if (str[i] ==  ? ) t4 += numQQ[i + 1];     t4 %= 1000000007;     long long ans = (t1 * triple(qNum)) % 1000000007 +                     (t2 * triple(qNum - 1)) % 1000000007 +                     (t3 * triple(qNum - 2)) % 1000000007 +                     (t4 * triple(qNum - 3)) % 1000000007;     cout << ans % 1000000007;   }


#include <bits/stdc++.h>   using namespace std;   int sol[123123];   int on[123123];   int matrix[142][142];   int matrix_2[142][142];   int main() {     int n, m, h;     cin >> n >> m >> h;     for (int i = 1; i <= m; i++) cin >> on[i];     for (int i = 1; i <= n; i++) cin >> sol[i];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> matrix[i][j];         matrix_2[i][j] = 31231212;       }     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++)         if (matrix_2[j][i] > on[i]) matrix_2[j][i] = on[i];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (matrix_2[i][j] > sol[i]) matrix_2[i][j] = sol[i];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++)         if (matrix[i][j])           cout << matrix_2[i][j] <<    ;         else           cout <<  0  ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   const int MAX_N = 1e5 + 7;   void solve() {     int n;     cin >> n;     vector<int> a(n);     vector<int> srt(n + 1);     srt.assign(n + 1, 0);     for (long long i = 0; i < int(n); i++) {       cin >> a[i];       srt[a[i]]++;     }     int res = 0;     for (int i = 0; i < n; ++i) {       long long sum = 0, cnt = 0;       for (int j = i; j < n; ++j) {         sum += a[j];         cnt++;         if (sum <= n && srt[sum] > 0 && cnt > 1) {           res += srt[sum];           srt[sum] = 0;         }       }     }     cout << res <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 155;   int f[maxn][maxn * maxn], a[maxn];   int n, K, s, ans = 2e9, cur;   void solve() {     sort(a + 1, a + n + 1);     ans = 0;     for (int i = 1; i <= K; i++) ans += a[i];     printf( %d n , ans);   }   int main() {     scanf( %d%d%d , &n, &K, &s);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     if (s >= n * (n - 1) / 2) {       solve();       return 0;     }     memset(f, 0x3f, sizeof f);     f[0][0] = 0;     for (int j = 1; j <= n; j++)       for (int i = K - 1; i >= 0; i--)         for (int k = 0; k <= min(s, n * i); k++)           f[i + 1][k + j - (i + 1)] =               min(f[i + 1][k + j - (i + 1)], f[i][k] + a[j]);     for (int i = 0; i <= s; i++) ans = min(ans, f[K][i]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long one = 1;   const long long INF = 2e18;   const long long MOD = 1e9 + 7;   const long long N = 40040 + 10;   const long long nul = 0;   signed main() {     vector<long long> cnt(6);     for (long long &i : cnt) cin >> i;     vector<pair<pair<long long, long long>, long long> > smth;     long long n;     cin >> n;     map<string, long long> dict;     dict[ S ] = 0;     dict[ M ] = 1;     dict[ L ] = 2;     dict[ XL ] = 3;     dict[ XXL ] = 4;     dict[ XXXL ] = 5;     bool can = 0;     vector<string> sz = { S ,  M ,  L ,  XL ,  XXL ,  XXXL };     vector<string> ans(n);     for (long long i = 0; i < n; i++) {       string s;       cin >> s;       string now =   ;       pair<long long, long long> q;       bool flag = 0;       for (char i : s) {         if (i ==  , ) {           q.first = dict[now];           now =   ;           flag = 1;         } else {           now += i;         }       }       if (flag) {         q.second = dict[now];         if (q.second < q.first) {           swap(q.first, q.second);         }         smth.push_back({q, i});       } else {         if (cnt[dict[now]] == 0) {           can = 1;         } else {           cnt[dict[now]]--;           ans[i] = now;         }       }     }     if (can)       cout <<  NO n ;     else {       sort((smth).begin(), (smth).end());       for (auto i : smth) {         long long one = i.first.first, two = i.first.second;         if (cnt[one] == 0) {           if (cnt[two] == 0) {             can = 1;             break;           } else {             ans[i.second] = sz[two];             cnt[two]--;           }         } else {           ans[i.second] = sz[one];           cnt[one]--;         }       }       if (can)         cout <<  NO n ;       else {         cout <<  YES n ;         for (auto i : ans) cout << i << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   inline int IN() {     char c;     register int first = 0;     for (; (c = getchar()) < 48 && c ^  -  || c > 57;)       ;     bool f = c ==  - ;     if (f) (c = getchar());     for (; c > 47 && c < 58; (c = getchar()))       first = (first << 3) + (first << 1) + c - 48;     if (f) first = -first;     return first;   }   inline void glance() { freopen( ha.in ,  r , stdin); }   int root, last, node, n, ans, L, R, seg_node, go[400010][26];   vector<int> li[400010];   typedef int Arr[400010];   Arr len, par, dp, rt, sky, sad;   int l[8000000], r[8000000];   inline void init() { node = root = last = 1; }   inline void append(int w) {     int p = last, u = ++node;     len[u] = len[p] + 1;     sad[u] = 1;     sky[u] = len[u];     for (; p && !go[p][w]; p = par[p]) go[p][w] = u;     if (!p)       par[u] = root;     else {       int t = go[p][w];       if (len[t] == len[p] + 1)         par[u] = t;       else {         int nt = ++node;         for (int _r = 26, i = 0; i < _r; ++i) go[nt][i] = go[t][i];         len[nt] = len[p] + 1;         par[nt] = par[t];         par[t] = par[u] = nt;         sky[nt] = len[u];         for (; p && go[p][w] == t; p = par[p]) go[p][w] = nt;       }     }     last = u;   }   int Merge(int u, int v) {     if (!u || !v) return u + v;     int first = ++seg_node;     l[first] = Merge(l[u], l[v]);     r[first] = Merge(r[u], r[v]);     return first;   }   void ins(int v, int &u, int ll, int rr, int pos) {     u = ++seg_node;     l[u] = l[v];     r[u] = r[v];     if (ll == rr) return;     int mm = ll + rr >> 1;     if (pos <= mm)       ins(l[v], l[u], ll, mm, pos);     else       ins(r[v], r[u], mm + 1, rr, pos);   }   bool Qs(int u, int ll, int rr) {     if (!u) return 0;     if (L <= ll && rr <= R) return 1;     int mm = ll + rr >> 1;     bool res = 0;     if (L <= mm) res = Qs(l[u], ll, mm);     if (R > mm) res = res || Qs(r[u], mm + 1, rr);     return res;   }   void dfs(int u) {     for (int v : li[u]) dfs(v), rt[u] = Merge(rt[u], rt[v]);     if (sad[u]) ins(rt[u], rt[u], 1, n, sky[u]);   }   void DFS(int u, int jc) {     for (int v : li[u]) {       if (u == root) {         dp[v] = 1;         DFS(v, v);       } else {         L = sky[v] - len[v] + len[jc];         R = sky[v] - 1;         if (L <= R && Qs(rt[jc], 1, n))           ans = max(ans, dp[v] = dp[jc] + 1), DFS(v, v);         else           DFS(v, jc);       }     }   }   int main() {     n = IN();     init();     for (char c; isalpha((c = getchar()));) append(c -  a );     for (int _r = node, i = 2; i <= _r; ++i) li[par[i]].push_back(i);     dfs(root);     ans = 1;     DFS(root, 0);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N, tot = 0, i, temp1, temp2, temp3, fin;     char inp1[1005], inp2[1005];     scanf( %d%s%s , &N, inp1, inp2);     for (i = 0; i < N; i++) {       temp1 = abs(inp1[i] - inp2[i]);       temp2 = abs( 9  - inp1[i]) + (inp2[i] -  0 ) + 1;       temp3 = abs(inp1[i] -  0 ) + ( 9  - inp2[i]) + 1;       fin = min(min(temp1, temp2), temp3);       tot += fin;     }     printf( %d n , tot);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   const int N = 2e3 + 7, Max = 1e6 + 7;   int n, m, res;   pii a[N], b[N];   int surf[Max];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       res = 1e9;       fill(surf, surf + Max, 0);       cin >> n >> m;       for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;       for (int i = 1; i <= m; ++i) cin >> b[i].first >> b[i].second;       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= m; ++j)           if (a[i].first <= b[j].first && a[i].second <= b[j].second)             surf[b[j].second - a[i].second] =                 max(surf[b[j].second - a[i].second], b[j].first - a[i].first + 1);       for (int i = Max - 2; i >= 0; --i) {         surf[i] = max(surf[i], surf[i + 1]);         res = min(res, i + surf[i]);       }       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[110];   int b[110];   int main() {     int n, m;     int maxx;     int maxx1;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       maxx = 1;       maxx1 = 0;       for (int j = 1; j <= n; j++) {         scanf( %d , &a[j]);         if (a[j] > maxx1) {           maxx = j;           maxx1 = a[j];         }       }       b[maxx]++;     }     maxx = 1;     maxx1 = 0;     for (int i = 1; i <= n; i++) {       if (b[i] > maxx1) {         maxx = i;         maxx1 = b[i];       }     }     printf( %d n , maxx);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       if (n % 2 == 0)         cout << n / 2 <<     << n / 2 <<   n ;       else {         long long int x = -1;         for (long long int i = 3; i <= sqrt(n); i += 2) {           if (n % i == 0) {             x = i;             break;           }         }         if (x == -1)           cout << n - 1 <<     << 1 <<   n ;         else {           long long int y = n / x;           cout << y * 1 <<     << y * (x - 1) <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   int m, d;   long long int memo[2000][2000][2][2];   long long int dp(int i, int rem, bool hf, bool lf) {     if (i >= a.length()) {       if (rem == 0) {         return 1;       }       return 0;     }     if (memo[i][rem][hf][lf] != -1) return memo[i][rem][hf][lf];     int lo = 0;     int hi = 9;     if (lf) lo = b[i] -  0 ;     if (hf) hi = a[i] -  0 ;     long long int ans = 0;     if (i % 2 == 0) {       for (int j = lo; j <= hi; j++) {         if (j == d) continue;         ans += dp(i + 1, (rem * 10 + j) % m, hf & (j == (a[i] -  0 )),                   lf & (j == (b[i] -  0 )));         ans %= 1000000007;       }     } else {       if ((d >= lo) && (d <= hi))         ans += dp(i + 1, (rem * 10 + d) % m, hf & (d == (a[i] -  0 )),                   lf & (d == (b[i] -  0 )));       ans %= 1000000007;     }     memo[i][rem][hf][lf] = ans;     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> m >> d;     cin >> b >> a;     for (int i = 0; i < 2000; i++) {       for (int j = 0; j < 2000; j++) {         for (int k = 0; k < 2; k++) {           for (int l = 0; l < 2; l++) {             memo[i][j][k][l] = -1;           }         }       }     }     cout << dp(0, 0, 1, 1) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     vector<int> a;     int temp = 0, sumb = 0, sumc = 0;     for (int i = 0; i < t; i++) {       cin >> temp;       a.push_back(temp);     }     for (int i = 0; i < t; i++) {       int tem = 0;       if (a[0] < a[a.size() - 1]) {         tem = a[a.size() - 1];         a.erase(a.end() - 1);       } else if (a[0] > a[a.size() - 1]) {         tem = a[0];         a.erase(a.begin() + 0);       }       if (i % 2 == 0)         sumb += tem;       else         sumc += tem;     }     if (t % 2 != 0)       cout << sumb + a[0] <<     << sumc << endl;     else       cout << sumb <<     << sumc + a[0] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long double PI = acosl(-1.0);   const long double E = 1e-15;   mt19937_64 rnd(time(0));   long long n, m, r, pr[100001], dp[100001];   pair<long long, pair<long long, long long> > a[100001];   long long binpow(long long h, long long r, long long md = MOD) {     bool t = 0;     if (h < 0) t = 1, h = -h;     if (r % 2 == 0) t = 0;     long long l = 1;     while (r) {       if (r & 1) l *= h, l %= md;       h *= h;       h %= md;       r /= 2;     }     if (t) l = -l;     return l;   }   long long gcd(int x, int y) {     if (x < y) swap(x, y);     while (x && y) {       x %= y;       swap(x, y);     }     return x + y;   }   void solve() {     cin >> r >> n;     a[0].second = make_pair(1, 1);     long long ans = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i].first >> a[i].second.first >> a[i].second.second;       long long o = 0;       for (int j = i - 1; j >= max(i - r * 2, 0ll); j--)         if (abs(a[i].second.first - a[j].second.first) +                 abs(a[i].second.second - a[j].second.second) <=             a[i].first - a[j].first) {           o = max(o, dp[j] + 1);         }       if (i > r * 2) o = max(o, pr[i - r * 2] + 1);       if (o == 0) o = -1e9;       pr[i] = max(pr[i - 1], o);       dp[i] = o;       ans = max(ans, o);     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int maxn = 403;   int n, m;   int a[maxn][maxn];   void read() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];   }   int min_r[maxn];   long long s[maxn * maxn][7];   int find_first_bit(long long num) { return 63 - __builtin_clzll(num & -num); }   int find_last_bit(long long num) { return 63 - __builtin_clzll(num); }   int find_prev(int c, int idx) {     int pos = idx / 63;     idx %= 63;     long long left = (s[c][pos] & ((1ll << idx) - 1));     if (left) return pos * 63 + find_last_bit(left);     for (int i = pos - 1; i >= 0; i--)       if (s[c][i]) return i * 63 + find_last_bit(s[c][i]);     return -1;   }   int find_next(int c, int idx) {     int pos = idx / 63;     idx %= 63;     long long curr = (s[c][pos] >> (idx + 1));     if (curr) return pos * 63 + idx + 1 + find_first_bit(curr);     for (int i = pos + 1; i < 7; i++)       if (s[c][i]) return i * 63 + find_first_bit(s[c][i]);     return -1;   }   void solve() {     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) min_r[j] = m + 1;       for (int j = 1; j < maxn * maxn; j++)         for (int k = 0; k < 7; k++) s[j][k] = 0;       for (int j = i; j <= n; j++) {         for (int k = 1; k <= m; k++) {           int pos = (k - 1) / 63, r = (k - 1) % 63;           if (s[a[j][k]][pos] & (1ll << r))             min_r[k] = k;           else {             s[a[j][k]][pos] ^= (1ll << r);           }         }         for (int k = 1; k <= m; k++) {           int f1 = find_prev(a[j][k], k - 1), f2 = find_next(a[j][k], k - 1);           if (f1 != -1) min_r[f1 + 1] = min(min_r[f1 + 1], k);           if (f2 != -1) min_r[k] = min(min_r[k], f2 + 1);         }         int curr = m + 1;         for (int k = m; k >= 1; k--) {           curr = min(curr, min_r[k]);           ans = max(ans, (curr - k) * (j - i + 1));         }       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     read();     solve();   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m, x;     cin >> n >> x >> m;     long long a, b;     long long mn = 1e9 + 1, mx = 1;     bool f = false;     while (m--) {       cin >> a >> b;       if (!f) {         if (x >= a && x <= b) {           f = true;           mn = a;           mx = b;         }       } else {         if (a < mn && b >= mn) {           mn = a;         }         if (b > mx && a <= mx) {           mx = b;         }       }     }     if (f == false) {       cout <<  1 n ;     } else {       cout << (mx - mn) + 1 <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long T;     cin >> T;     while (T--) solve();   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = double;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cout << *it <<   =   << a << endl;     err(++it, args...);   }   const ll MODBASE = 1000000007LL;   const int MAXN = 100010;   const int MAXM = 110;   const int MAXK = 110;   string s, t;   int f[26];   set<pair<int, int> > se;   int main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     cin >> s >> t;     for (int i = (0); i <= (25); i++) f[i] = -1;     for (int i = (0); i <= (int((s).size()) - 1); i++)       if (s[i] != t[i]) f[s[i] -  a ] = t[i] -  a ;     for (int i = (0); i <= (25); i++)       if (f[i] != -1) {         if (f[f[i]] == -1) {           f[f[i]] = i;         } else if (f[f[i]] != i) {           cout << -1;           return 0;         }       }     for (int i = (0); i <= (int((s).size()) - 1); i++)       if (f[s[i] -  a ] != -1) s[i] = char(f[s[i] -  a ] +  a );     if (s == t) {       for (int i = (0); i <= (25); i++)         if (f[i] != -1) {           if (i < f[i])             se.insert(pair<int, int>(i, f[i]));           else             se.insert(pair<int, int>(f[i], i));         }       cout << int((se).size()) <<   n ;       for (__typeof((se).begin()) it = (se).begin(); it != (se).end(); it++)         cout << char(it->first +  a ) <<     << char(it->second +  a ) <<   n ;     } else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   const int N = 7 + 1e9;   using namespace std;   const int p = 1e6 + 10;   int arr[p];   int power(int x, int y);   void pre() {     int j = 1;     for (int i = 1; i < p; i++) {       if (i % 3 != 0) {         if (i % 10 != 3) {           arr[j] = i;           j++;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     pre();     long long T;     cin >> T;     while (T--) {       long long n;       cin >> n;       cout << arr[n] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1234567;   const int MOD = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s, a, t;     cin >> s;     vector<string> v;     for (int i = 0; i < 10; i++) {       cin >> a;       v.push_back(a);     }     for (int i = 0; i < s.size(); i += 10) {       t = s.substr(i, 10);       for (int j = 0; j < 10; j++)         if (v[j].compare(t) == 0) {           cout << j;           break;         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T gi() {     T f = 1, x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return f * x;   }   const int INF = 0x3f3f3f3f, N = 200003, M = N << 1;   int n, m, c[N];   long long tr[N << 2], dp[N], lz[N << 2];   struct Node {     int l, p;   };   vector<Node> a[N];   inline int ls(int p) { return p << 1; }   inline int rs(int p) { return p << 1 | 1; }   inline void pushup(int p) { tr[p] = max(tr[ls(p)], tr[rs(p)]); }   inline void pushdown(int p) {     if (lz[p]) {       tr[ls(p)] += lz[p], lz[ls(p)] += lz[p];       tr[rs(p)] += lz[p], lz[rs(p)] += lz[p];       lz[p] = 0;     }   }   void modify(int ql, int qr, long long val, int l, int r, int p) {     if (ql <= l && r <= qr) {       tr[p] += val, lz[p] += val;       return;     }     pushdown(p);     int mid = (l + r) >> 1;     if (ql <= mid) modify(ql, qr, val, l, mid, ls(p));     if (qr > mid) modify(ql, qr, val, mid + 1, r, rs(p));     pushup(p);   }   long long query(int ql, int qr, int l, int r, int p) {     if (ql <= l && r <= qr) return tr[p];     int mid = (l + r) >> 1;     long long ans = 0;     if (ql <= mid) ans = query(ql, qr, l, mid, ls(p));     if (qr > mid) ans = max(ans, query(ql, qr, mid + 1, r, rs(p)));     return ans;   }   int main() {     n = gi<int>(), m = gi<int>();     for (int i = 1; i <= n; i += 1) c[i] = gi<int>();     while (m--) {       int l = gi<int>(), r = gi<int>(), p = gi<int>();       a[r].push_back((Node){l, p});     }     long long sum = 0, res = 0;     for (int i = 1; i <= n + 1; i += 1) {       res += c[i];       dp[i] = max(dp[i - 1], query(1, max(1, i - 1), 1, n, 1));       modify(1, i, -c[i], 1, n, 1);       for (auto x : a[i]) modify(1, x.l, x.p, 1, n, 1), sum += x.p;       dp[i] = max(dp[i], sum - res);       modify(i, i, dp[i - 1], 1, n, 1);     }     printf( %lld n , dp[n + 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<string> s(n);     for (string &e : s) cin >> e;     vector<vector<int> > a(n, vector<int>(m, 0));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);     vector<int> dp(1 << n, (1 << 30));     vector<vector<int> > cost(n, vector<int>(m, 0)), masks(n, vector<int>(m, 0));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int max_a = 0;         for (int k = 0; k < n; k++)           if (s[i][j] == s[k][j]) {             max_a = max(max_a, a[k][j]);             cost[i][j] += a[k][j];             masks[i][j] |= (1 << k);           }         cost[i][j] -= max_a;       }     dp[0] = 0;     for (int mask = 1; mask < (1 << n); mask++) {       int j = 0;       for (; j < n; j++)         if (mask & (1 << j)) break;       for (int i = 0; i < m; i++) {         dp[mask] = min(dp[mask], dp[mask & (mask ^ masks[j][i])] + cost[j][i]);         dp[mask] = min(dp[mask], dp[mask ^ (1 << j)] + a[j][i]);       }     }     printf( %d n , dp[(1 << n) - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long;   using ulint = unsigned long long;   const int T = 10;   lint dp[T], nxt[T];   void relax(lint &x, lint y) { x = max(x, y); }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     fill(begin(dp), end(dp), -1);     fill(begin(nxt), end(nxt), -1);     int n;     cin >> n;     dp[0] = 0;     while (n--) {       int k;       cin >> k;       vector<lint> cards[4];       for (int i = 0; i < k; i++) {         int c, d;         cin >> c >> d;         cards[c].push_back(d);       }       for (auto &vec : cards) {         sort(vec.begin(), vec.end(), greater<lint>());       }       for (int i = 0; i < T; i++) {         if (dp[i] == -1) continue;         bool flag1 = i + 1 >= T;         bool flag2 = i + 2 >= T;         bool flag3 = i + 3 >= T;         relax(nxt[i], dp[i]);         if (cards[1].size() >= 1)           relax(nxt[(i + 1) % T], dp[i] + cards[1][0] * (flag1 + 1));         if (cards[2].size() >= 1)           relax(nxt[(i + 1) % T], dp[i] + cards[2][0] * (flag1 + 1));         if (cards[3].size() >= 1)           relax(nxt[(i + 1) % T], dp[i] + cards[3][0] * (flag1 + 1));         if (cards[1].size() >= 2)           relax(nxt[(i + 2) % T],                 dp[i] + cards[1][0] * (flag2 + 1) + cards[1][1]);         if (cards[1].size() >= 1 && cards[2].size() >= 1)           relax(nxt[(i + 2) % T], dp[i] + cards[1][0] + cards[2][0] +                                       max(cards[1][0], cards[2][0]) * flag2);         if (cards[1].size() >= 3)           relax(nxt[(i + 3) % T],                 dp[i] + cards[1][0] * (flag3 + 1) + cards[1][1] + cards[1][2]);       }       copy(begin(nxt), end(nxt), begin(dp));     }     cout << *max_element(begin(dp), end(dp)) << endl;   }


#include <bits/stdc++.h>   int n, m, mo;   int sz[111111], ace[111111];   int ancestor(int x) { return x - ace[x] ? ace[x] = ancestor(ace[x]) : x; }   int mul(int x, int y) { return (int)((long long int)x * y % mo); }   int main() {     scanf( %d%d%d , &n, &m, &mo);     if (mo == 1) {       puts( 0 );       return 0;     }     for (int i = 1; i <= n; i++) ace[i] = i;     while (m--) {       int x, y;       scanf( %d%d , &x, &y);       ace[ancestor(x)] = ancestor(y);     }     for (int i = 1; i <= n; i++) sz[ancestor(i)]++;     int res = 1, w = 0;     for (int i = 1; i <= n; i++)       if (sz[i]) {         res = mul(res, sz[i]);         w++;       }     if (w == 1)       puts( 1 );     else {       for (w -= 2; w; w--) res = mul(res, n);       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   const int mod = 1e9 + 7;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   void exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0;     } else {       exgcd(b, a % b, x, y);       long long temp = x;       x = y;       y = temp - a / b * y;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long x, y, a, b, c;     cin >> a >> b >> c;     c = -c;     long long d = gcd(a, b);     if (c % d != 0) {       cout << -1 <<   n ;       return 0;     }     exgcd(a, b, x, y);     cout << x * (c / d) <<     << y * (c / d) <<   n ;   }


#include <bits/stdc++.h>   const unsigned long long mod = 1e9 + 7;   using namespace std;   const int N = 1e3 + 5;   const double esp = 1e-5;   int n, x, pos, lsum = -1, rsum;   unsigned long long f[N], a[N];   unsigned long long qpow(unsigned long long a, unsigned long long b) {     unsigned long long ans = 1, base = a;     while (b) {       if (b & 1) ans = (ans * base % mod + mod) % mod;       base = (base * base % mod + mod) % mod;       b >>= 1;     }     return ans;   }   void init() {     f[0] = 1;     for (int i = 1; i <= 1000; i++) f[i] = f[i - 1] * i % mod, a[i - 1] = i - 1;   }   unsigned long long cal(unsigned long long n, unsigned long long m) {     return 1ll *            (f[n] * qpow(f[m], mod - 2) % mod * qpow(f[n - m], mod - 2) % mod);   }   void find() {     int l = 0;     int r = n;     while (l < r) {       int mid = (l + r) >> 1;       if (mid <= pos) {         l = mid + 1;         lsum++;       } else {         r = mid;         rsum++;       }     }   }   int main() {     init();     scanf( %d%d%d , &n, &x, &pos);     find();     unsigned long long ans = f[rsum] * cal(n - x, rsum) % mod * f[lsum] % mod *                              cal(x - 1, lsum) % mod * f[n - lsum - rsum - 1] %                              mod;     printf( %lld , ans % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long INF = 1e18;   const int MAXN = 1e5 + 5;   long long i, j, m, n, k, t, d;   long long ans;   long long x[MAXN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> d;     for (i = 1; i <= n; i++) {       cin >> x[i];     }     for (i = 1; i <= n; i++) {       long long low = i + 2, high = n, mid, ok = -1;       while (low <= high) {         mid = (low + high) / 2;         if (x[mid] - x[i] <= d) {           ok = mid;           low = mid + 1;         } else {           high = mid - 1;         }       }       if (ok == -1) continue;       ans += (ok - i) * (ok - i - 1) / 2;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int h[100010], res[100010];   int main() {     int n, i;     while (scanf( %d , &n) != EOF) {       memset(h, 0, sizeof(h));       memset(res, 0, sizeof(res));       for (i = 1; i <= n; i++) {         scanf( %d , &h[i]);       }       int temp = 0;       for (i = 1; i <= n; i++) {         temp = min(temp, h[i] - i);         res[i] = i + temp;       }       temp = n + 1;       for (i = n; i >= 1; i--) {         temp = min(temp, h[i] + i);         res[i] = min(res[i], temp - i);       }       int ans = 0;       for (i = 1; i <= n; i++) {         ans = max(ans, res[i]);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     while (k--) {       int n;       cin >> n;       vector<int> h(n);       for (int i = 0; i < n; i++) cin >> h[i];       sort(h.begin(), h.end());       reverse(h.begin(), h.end());       int ans = 0;       for (int i = 0; i < n; i++) {         int w1 = i + 1;         if (h[i] >= w1) {           ans = max(ans, w1);         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[505];   int m, b[505];   int sumA[505];   int sumB[505];   int dp[505][505];   struct Answer {     int p;     char c;     Answer(void){};     Answer(int x, char y) {       p = x;       c = y;     }   } stk[505];   int tot = 0;   int tree[505];   int lowbit(int x) { return x & -x; }   int query(int p) {     int r = 0;     while (p) {       r += tree[p];       p -= lowbit(p);     }     return r;   }   void add(int p) {     while (p <= n) {       tree[p] += 1;       p += lowbit(p);     }   }   void dfs(int l, int r) {     if (l == r) return;     if (dp[l + 1][r] && sumA[r] - sumA[l] > a[l]) {       dfs(l + 1, r);       stk[++tot] = Answer(l,  L );     } else {       dfs(l, r - 1);       stk[++tot] = Answer(r,  R );     }   }   signed main(void) {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     scanf( %d , &m);     for (int i = 1; i <= m; ++i) scanf( %d , b + i);     memset(sumA, 0, sizeof(sumA));     memset(sumB, 0, sizeof(sumB));     for (int i = 1; i <= n; ++i) sumA[i] = sumA[i - 1] + a[i];     for (int i = 1; i <= m; ++i) sumB[i] = sumB[i - 1] + b[i];     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= n; ++i) dp[i][i] = 1;     for (int i = 1; i < n; ++i)       for (int j = 1; i + j <= n; ++j) {         if (sumA[i + j] - sumA[j] > a[j]) dp[j][i + j] |= dp[j + 1][i + j];         if (sumA[i + j - 1] - sumA[j - 1] > a[i + j])           dp[j][i + j] |= dp[j][i + j - 1];       }     bool flag = true;     for (int i = 1, j = 1, k; i <= m; ++i) {       for (k = j; k <= n && sumA[k] != sumB[i]; ++k)         ;       if (k > n) {         flag = false;         break;       }       if (i == m && k != n) {         flag = false;         break;       }       if (!dp[j][k]) {         flag = false;         break;       }       dfs(j, k);       j = k + 1;     }     if (!flag) return puts( NO ), 0;     puts( YES );     memset(tree, 0, sizeof(tree));     for (int i = 1; i <= tot; ++i) {       int q = query(stk[i].p);       add(stk[i].p);       stk[i].p -= q;       if (stk[i].c ==  L )         ++stk[i].p;       else         --stk[i].p;     }     for (int i = 1; i <= tot; ++i) printf( %d %c n , stk[i].p, stk[i].c);   }


#include <bits/stdc++.h>   using namespace std;   int cmp(int a, int b) { return a > b; }   int main() {     int i, j, m, n, sm = 0, sn = 0, num[110], e[110];     string s;     map<string, int> mapp;     map<string, int>::iterator it;     scanf( %d%d , &m, &n);     for (i = 0; i < m; i++) {       scanf( %d , &num[i]);     }     sort(num, num + m, cmp);     for (i = 0; i < n; i++) {       cin >> s;       for (it = mapp.begin(); it != mapp.end(); it++) {         if (it->first == s) {           it->second++;           break;         }       }       if (it == mapp.end()) mapp.insert(pair<string, int>(s, 1));     }     for (it = mapp.begin(), i = 0; it != mapp.end(); ++it, i++) {       e[i] = it->second;     }     sort(e, e + i, cmp);     n = i;     for (i = 0; i < n; i++) {       sm += e[i] * num[i];       sn += e[i] * num[m - i - 1];     }     printf( %d %d , sn, sm);   }


#include <bits/stdc++.h>   int ans[1000006];   int dij[1000006];   int mmax;   void dfs(int now, int num) {     dij[num] = now;     for (int i = 2; i < now; i++) {       if (now % i == 0) {         dfs(now / i, num + 1);       }     }     dij[++num] = 1;     if (num > mmax) {       mmax = num;       for (int i = 0; i <= num; i++) ans[i] = dij[i];     }     return;   }   int main() {     int n;     scanf( %d , &n);     mmax = 0;     if (n == 1)       printf( 1 n );     else {       dfs(n, 0);       for (int i = 0; i <= mmax; i++) printf( %d  , ans[i]);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   int num[maxn], ans;   void Solve() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , num + i);     sort(num + 1, num + 1 + n);     int nn = unique(num + 1, num + 1 + n) - (num + 1);     for (int i = 1; i <= nn; i++) {       int j = num[i] << 1;       int pos = lower_bound(num + 1, num + 1 + nn, j) - num;       while (num[pos - 1] < j && pos <= nn) {         ans = max(ans, num[pos - 1] % num[i]);         pos = lower_bound(num + pos + 1, num + 1 + nn, j) - num;         j += num[i];       }       ans = max(ans, num[pos - 1] % num[i]);     }     printf( %d , ans);   }   int main() {     Solve();     getchar();     getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     if (N == 1) {       cout <<  ! 1  << endl;       return 0;     }     vector<int> res(N);     for (;;) {       int x = 0, y = 0;       for (int i = 0; i < N; ++i) {         if (x == 0 && res[i] == 0) {           x = i + 1;         } else if (res[i] == 0) {           y = i + 1;           break;         }       }       if (y == 0) break;       int z, w;       cout <<  ?   << x <<     << y << endl;       cin >> z;       cout <<  ?   << y <<     << x << endl;       cin >> w;       if (z == 0) {         res[y - 1] = w;       } else if (w == 0) {         res[x - 1] = z;       } else if (z > w) {         res[x - 1] = z;       } else {         res[y - 1] = w;       }     }     set<int> a;     for (int i = 1; i <= N; ++i) a.insert(i);     for (auto x : res) a.erase(x);     for (auto& x : res)       if (x == 0) x = *a.begin();     cout <<  ! ;     for (auto x : res) cout <<     << x;     cout << endl;   }


#include <bits/stdc++.h>   const long long int mod = 1e9 + 7;   using namespace std;   long long int p, q, r, s;   long long int len(long long int x) {     long long int count = 0;     while (x > 0) {       x = x / 10;       count++;     }     return count;   }   long long int fx(long long int x) {     long long int count = 9;     if (x <= 9) return x;     p = len(x);     q = x % 10;     x /= 10;     r = x / pow(10, p - 2);     s = pow(10, p - 2);     x = x % s;     if (p == 2) {       count += r;       if (q < r) count--;       return count;     }     for (int i = (1); i <= (p - 2); i++) count += 9 * pow(10, i - 1);     count += (r - 1) * pow(10, p - 2);     count += x + 1;     if (q < r) count--;     return count;   }   int main() {     long long int y, z;     cin >> y >> z;     long long int temp = fx(z) - fx(y - 1);     cout << temp << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, t, a[200010], f[200010];   long long ans;   struct nood {     int x, id;   } b[200010];   int cmp(nood a, nood b) { return a.x > b.x; }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i].x = a[i];       b[i].id = i;     }     sort(b + 1, b + n + 1, cmp);     for (int i = 1; i <= m * k; i++) {       f[b[i].id] = 1;       ans = ans + b[i].x;     }     printf( %lld n , ans);     for (int i = 1; i <= n; i++) {       if (f[i] == 1) t++;       if (t == m + 1) {         printf( %d  , i - 1);         t = 1;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long int tc, n, m, k;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n;     long long int k1, k2;     cin >> k1;     queue<long long int> q1;     for (__typeof(k1) i = (0) - ((0) > (k1)); i != (k1) - ((0) > (k1));          i += 1 - 2 * ((0) > (k1))) {       long long int a;       cin >> a;       q1.push(a);     }     cin >> k2;     queue<long long int> q2;     for (__typeof(k2) i = (0) - ((0) > (k2)); i != (k2) - ((0) > (k2));          i += 1 - 2 * ((0) > (k2))) {       long long int a;       cin >> a;       q2.push(a);     }     long long int af = q1.front();     long long int bf = q2.front();     long long int sa = ((int)(q1).size());     long long int sb = ((int)(q2).size());     long long int ans = 0;     while (((int)(q1).size()) && ((int)(q2).size())) {       long long int a = q1.front();       long long int b = q2.front();       if ((ans > 4e7)) {         cout << -1;         return 0;       }       if (a < b) {         q2.push(a);         q2.push(b);       } else {         q1.push(b);         q1.push(a);       }       q1.pop();       q2.pop();       ans++;     }     cout << ans <<    ;     if (((int)(q1).size()) == 0)       cout << 2;     else       cout << 1;     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, h, a, b, k, s[10001];   int main() {     scanf( %lld%lld%lld%lld%lld , &n, &h, &a, &b, &k);     for (int i = 1; i <= k; i++) {       long long u1, v1, u2, v2;       scanf( %lld%lld%lld%lld , &u1, &v1, &u2, &v2);       if (u1 == u2)         s[i] = abs(v1 - v2);       else if ((a < v1 && v1 < b) || (a < v2 && v2 < b))         s[i] = abs(u1 - u2) + abs(v1 - v2);       else         s[i] = min(abs(u1 - u2) + abs(v1 - a) + abs(v2 - a),                    abs(u1 - u2) + abs(v1 - b) + abs(v2 - b));     }     for (int i = 1; i <= k; i++) printf( %lld n , s[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int h[N], e[2 * N], ne[2 * N], w[2 * N], idx;   int dist[N][N];   int n, m, k;   bool st[N];   pair<int, int> q[N];   void add(int a, int b, int c) {     e[idx] = b;     ne[idx] = h[a];     w[idx] = c;     h[a] = idx++;   }   priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>       heap;   void dijkstra(int start, int dist[]) {     memset(st, 0, sizeof st);     dist[start] = 0;     heap.push({0, start});     while (heap.size()) {       int t = heap.top().second;       heap.pop();       if (st[t]) continue;       st[t] = 1;       for (int i = h[t]; i != -1; i = ne[i]) {         int j = e[i];         if (dist[j] > dist[t] + w[i]) {           dist[j] = dist[t] + w[i];           heap.push({dist[j], j});         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie(0);     int T = 1;     while (T--) {       memset(dist, 0x3f, sizeof dist);       memset(h, -1, sizeof h);       cin >> n >> m >> k;       for (int i = 1; i <= m; i++) {         int a, b, c;         cin >> a >> b >> c;         add(a, b, c), add(b, a, c);       }       for (int i = 1; i <= k; i++) cin >> q[i].first >> q[i].second;       for (int i = 1; i <= n; i++) dijkstra(i, dist[i]);       long long ans = 1e18;       for (int i = 0; i < idx; i += 2) {         int a = e[i], b = e[i ^ 1];         long long now = 0;         for (int j = 1; j <= k; j++) {           int from = q[j].first, to = q[j].second;           now +=               min(min(dist[from][a] + dist[b][to], dist[from][b] + dist[a][to]),                   dist[from][to]);         }         ans = min(ans, now);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const int N = 1e5 + 5;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n];       long long nem = 0, ans = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] > 0) {           nem += a[i];         } else {           if (nem < -a[i]) {             ans += -a[i] - nem;             nem = 0;           } else {             nem = nem + a[i];           }         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int main() {     cin >> n >> k;     int total = (n * (n - 1)) / 2;     if (total >= n * k) {       total = n * k;       cout << total <<   n ;       int nod1 = 1;       int nod2 = nod1 + 1;       int cate = 0;       while (total > 0) {         cate++;         if (nod2 > n) nod2 = 1;         cout << nod1 <<     << nod2 <<   n ;         if (cate == k) {           nod1++;           nod2 = nod1 + 1;           cate = 0;         } else           nod2++;         total--;       }     } else       cout << -1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long mx = 1e3 + 4;   vector<vector<long long>> dist;   vector<vector<bool>> col;   queue<pair<long long, long long>> vis;   long long n, m, t;   long long expo_pow(long long x, long long y) {     if (y == 0) return 1;     y = y % (mod - 1);     x %= mod;     if (y == 0) y = mod - 1;     long long res = 1;     while (y) {       if (y & 1) res = (res * x) % mod;       x = (x * x) % mod;       y >>= 1;     }     return res;   }   void solve() {     cin >> n >> m >> t;     col.resize(n + 1, vector<bool>(m + 1));     dist.resize(n + 1, vector<long long>(m + 1));     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         dist[i][j] = -1;         char tmp;         cin >> tmp;         col[i][j] = (tmp ==  1 );       }     }     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         if (i != 1 and col[i - 1][j] == col[i][j]) {           dist[i][j] = 0;           vis.push({i, j});         } else if (i != n and col[i + 1][j] == col[i][j]) {           dist[i][j] = 0;           vis.push({i, j});         } else if (j != 1 and col[i][j - 1] == col[i][j]) {           dist[i][j] = 0;           vis.push({i, j});         } else if (j != m and col[i][j + 1] == col[i][j]) {           dist[i][j] = 0;           vis.push({i, j});         }       }     }     while (!vis.empty()) {       auto cur = vis.front();       vis.pop();       if (cur.first != 1 and dist[cur.first - 1][cur.second] == -1) {         dist[cur.first - 1][cur.second] = dist[cur.first][cur.second] + 1;         vis.push({cur.first - 1, cur.second});       }       if (cur.first != n and dist[cur.first + 1][cur.second] == -1) {         dist[cur.first + 1][cur.second] = dist[cur.first][cur.second] + 1;         vis.push({cur.first + 1, cur.second});       }       if (cur.second != 1 and dist[cur.first][cur.second - 1] == -1) {         dist[cur.first][cur.second - 1] = dist[cur.first][cur.second] + 1;         vis.push({cur.first, cur.second - 1});       }       if (cur.second != m and dist[cur.first][cur.second + 1] == -1) {         dist[cur.first][cur.second + 1] = dist[cur.first][cur.second] + 1;         vis.push({cur.first, cur.second + 1});       }     }     while (t--) {       long long x, y, p;       cin >> x >> y >> p;       if (dist[x][y] == -1) {         cout << col[x][y] <<   n ;         continue;       }       if (p <= dist[x][y]) {         cout << col[x][y] <<   n ;         continue;       }       long long tmp = p - dist[x][y];       if (tmp % 2) {         cout << !col[x][y] <<   n ;       } else {         cout << col[x][y] <<   n ;       }     }   }   signed main() {     long long test = 1;     long long i = 1;     while (test--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int n;     cin >> n;     int ats = 0;     list<int> kruv;     int kur = 1;     for (int i = 0; i < 2 * n; i++) {       string c;       cin >> c;       if (c[0] ==  a ) {         int nr;         cin >> nr;         kruv.push_front(nr);       } else {         if (kruv.size() > 0 and *kruv.begin() != kur) {           ats++;           kruv.erase(kruv.begin(), kruv.end());         } else if (kruv.size() > 0)           kruv.erase(kruv.begin());         kur++;       }     }     cout << ats;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool issub(string s, string t) {     int cur = 0;     for (char c : s) {       if (c == t[cur]) cur++;       if (cur == t.size()) return true;     }     return false;   }   int main() {     int q, i;     cin >> q;     while (q--) {       string s, t, p;       cin >> s >> t >> p;       int a[26], flag = 0;       memset(a, 0, sizeof(a));       for (char c : s) a[c -  a ]++;       for (char c : p) a[c -  a ]++;       for (char c : t) a[c -  a ]--;       for (i = 0; i < 26; i++) {         if (a[i] < 0) {           flag = 1;         }       }       if (flag == 0 && issub(t, s) == true) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long siv[1000006];   long long prime[1000006];   void seive() {     for (long long i = 2; i < 1000006; i++) {       prime[i] = prime[i - 1];       if (!siv[i]) {         prime[i]++;         for (long long j = i + i; j < 1000006; j += i) siv[j] = 1;       }     }   }   void solve() {     long long t;     t = 1;     cin >> t;   t:     seive();     while (t--) {       long long n;       cin >> n;       long long a = sqrt(n);       cout << prime[n] - prime[a] + 1 <<   n ;     }   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     }     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long T, x, y, k;     cin >> T;     while (T--) {       cin >> x >> y >> k;       long long minSt = (y * k) + k - 1;       long long st = 1;       long long count = minSt / (x - 1);       if (minSt % (x - 1) != 0) {         cout << count + k + 1 << endl;       } else         cout << count + k << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int par[N], par1[N], T, vis[N], n, m, w[N], x[N], y[N];   bool ans[N];   vector<pair<int, int>> e[N], q[N];   int get(int u) { return u == par[u] ? u : par[u] = get(par[u]); }   int gett(int u) {     return (vis[u] != T ? vis[u] = T, par1[u] = par[u] : 0),            (u == par1[u] ? u : par1[u] = gett(par1[u]));   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) par[i] = i;     for (int i = 0, a, b, c; i < m; i++)       scanf( %d%d%d , x + i, y + i, w + i), e[w[i]].push_back({--x[i], --y[i]});     scanf( %d , &n);     for (int i = 0, a, b; i < n; i++) {       scanf( %d , &a);       while (a--) scanf( %d , &b), --b, q[w[b]].push_back({i, b});     }     for (int i = 1, last; i < N; i++) {       last = -1;       for (auto j : q[i]) {         if (last != j.first) T++, last = j.first;         int a = gett(x[j.second]), b = gett(y[j.second]);         if (a == b)           ans[last] = 1;         else           par1[a] = b;       }       for (auto j : e[i]) par[get(j.second)] = get(j.first);     }     for (int i = 0; i < n; i++) puts(ans[i] ?  NO  :  YES );   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   inline long long inl() {     long long x;     scanf( %I64d , &x);     return x;   }   inline double ind() {     double x;     scanf( %lf , &x);     return x;   }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int power(int x, int n) {     if (n == 0)       return 1;     else if (n % 2 == 0) {       int y = power(x, n / 2);       return y * y;     } else       return x * power(x, n - 1);   }   char s[2];   int n, k;   long long ans;   int lastp, lastb, lastr;   int pf, rf, bf;   int c, v, g;   int main() {     n = in();     int lastb, lastp, lastr;     for (int i = 0; i < n; i++) {       scanf( %d %s , &k, s);       if (s[0] ==  P  || s[0] ==  R ) {         if (rf) {           ans += k - lastr;           c = max(c, k - lastr);         }         rf = 1;         lastr = k;       }       if (s[0] ==  P  || s[0] ==  B ) {         if (bf) {           ans += k - lastb;           v = max(v, k - lastb);         }         bf = 1;         lastb = k;       }       if (s[0] ==  P ) {         if (pf) {           ans += min(0, k - g - c - v);         }         pf = 1;         g = k;         c = v = 0;       }     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110;   int n, m, a, b, cnt, Newid, Size[N], id[N], nid[N], ans[N];   struct edge {     int x, y, z;     bool operator<(const edge &rhs) const { return z < rhs.z; }   } e[N << 2];   int tot = 0, head[N], to[N << 2], nxt[N << 2], len[N << 2];   void add_edge(int x, int y, int z) {     nxt[++tot] = head[x];     to[tot] = y;     len[tot] = z;     head[x] = tot;   }   int fa[N];   int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }   void Krusual() {     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       int x = getfa(e[i].x), y = getfa(e[i].y);       if (e[i].z == b || x == y) continue;       fa[y] = fa[x];     }   }   priority_queue<pair<int, pair<int, int>>> q;   int dis[1 << 18][80];   bool vis[1 << 18][80];   void Dijkstra() {     memset(dis, 0x3f, sizeof(dis));     memset(vis, 0, sizeof(vis));     q.push(make_pair(0, make_pair(0, 1)));     dis[0][1] = 0;     while (!q.empty()) {       int now = -q.top().first;       pair<int, int> u = q.top().second;       q.pop();       ans[u.second] = min(ans[u.second], now);       if (vis[u.first][u.second]) continue;       vis[u.first][u.second] = 1;       for (int i = head[u.second]; i; i = nxt[i]) {         int v = to[i];         if (id[v] == id[u.second] && len[i] == b) continue;         if (nid[v] && (u.first & (1 << nid[v]))) continue;         int S = u.first;         if (nid[u.second] && nid[v] != nid[u.second]) S |= (1 << nid[u.second]);         if (dis[u.first][u.second] + len[i] < dis[S][v]) {           dis[S][v] = dis[u.first][u.second] + len[i];           q.push(make_pair(-dis[S][v], make_pair(S, v)));         }       }     }   }   int main() {     cin >> n >> m >> a >> b;     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &e[i].x, &e[i].y, &e[i].z);       add_edge(e[i].x, e[i].y, e[i].z);       add_edge(e[i].y, e[i].x, e[i].z);     }     sort(e + 1, e + m + 1);     Krusual();     for (int i = 1; i <= n; i++) {       Size[getfa(i)]++;       if (fa[i] == i) id[i] = ++cnt;     }     for (int i = 1; i <= n; i++) id[i] = id[getfa(i)];     for (int i = 1; i <= n; i++)       if (Size[i] >= 4) nid[i] = ++Newid;     for (int i = 1; i <= n; i++) nid[i] = nid[getfa(i)];     memset(ans, 0x3f, sizeof(ans));     Dijkstra();     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int k1, k2;   long long int dp[101][101][11][11];   long long int rec(long long int n1, long long int n2, long long int x,                     long long int y) {     if (n1 == 0 && n2 == 0) return 1;     if (dp[n1][n2][x][y] != -1) return dp[n1][n2][x][y];     long long int a1 = 0, a2 = 0;     if (x > 0 && n1 > 0) a1 = rec(n1 - 1, n2, x - 1, k2);     if (y > 0 && n2 > 0) a2 = rec(n1, n2 - 1, k1, y - 1);     return dp[n1][n2][x][y] = (a1 + a2) % 100000000;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, -1, sizeof(dp));     long long int n1, n2;     cin >> n1 >> n2 >> k1 >> k2;     cout << rec(n1, n2, k1, k2);     return 0;   }


#include <bits/stdc++.h>      #define all(v) (v).begin(), (v).end()   #define sortv(v) sort(all(v))   #define uniqv(v) (v).erase(unique(all(v)), (v).end())   #define pb push_back   #define FI first   #define SE second   #define lb lower_bound   #define ub upper_bound   #define mp make_pair   #define test 1   #define TEST if(test)       using namespace std;       typedef long long ll;   typedef pair<int, int> pii;   typedef pair<ll, ll> pll;   typedef vector<int> vi;       const int MOD = 1000000007; // 998244353   const int INF = 2e9;   const ll INFLL = 1e18;   const int MAX_N = 100;      int T;   int N, K;   int h[MAX_N+1];      int main(){    scanf( %d , &T);    while(T--){     scanf( %d%d , &N, &K);     for(int i=1; i<=N; i++){      scanf( %d , &h[i]);     }     bool tf = true;     int ans = 0;     for(int i=1; i<=K; i++){      int pos = 1;      while(pos!=N){       if(h[pos]>=h[pos+1]) pos++;       else break;      }      if(pos==N){       tf = false;       printf( -1 n );       break;      }else{       ans = pos;       h[pos]++;      }     }     if(tf){      printf( %d n , ans);     }    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f(int n, vector<int> &a);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i <= n - 1; i++) {         cin >> a[i];       }       cout << f(n, a) <<   n ;     }     return 0;   }   int f(int n, vector<int> &a) {     sort(a.begin(), a.end());     bool flag = 0;     for (int k = 1; k <= 1023; k++) {       flag = 0;       for (int i = 0; i <= n - 1; i++) {         int x = a[i] ^ k;         if (!binary_search(a.begin(), a.end(), x)) {           flag = 1;           break;         }       }       if (flag == 0) {         return k;       }     }     return -1;   }


#include <bits/stdc++.h>   using namespace std;   int oo = (int)1e9;   int get(string str) {     int f = 0;     for (int i = 0; i < (int)str.size(); ++i) {       if (str[i] !=  - ) {         if (str[i] != str[0]) f = 1;       }     }     if (f == 0) return f;     for (int i = 1; i < (int)str.size(); ++i) {       if (str[i] !=  - ) {         if (str[i] >= str[i - 1 - (i == 3 || i == 6)]) f = 2;       }     }     return f;   }   int main() {     int n;     cin >> n;     string cn;     vector<string> vs(n);     vector<vector<int> > cnt(n, vector<int>(3, 0));     for (int i = 0; i < n; ++i) {       int s;       cin >> s >> vs[i];       for (int j = 0; j < s; ++j) {         cin >> cn;         cnt[i][get(cn)]++;       }     }     vector<vector<int> > res(3);     for (int i = 0; i < 3; ++i) {       int mx = 0;       for (int j = 0; j < n; ++j) {         mx = max(mx, cnt[j][i]);       }       for (int j = 0; j < n; ++j) {         if (cnt[j][i] == mx) {           res[i].push_back(j);         }       }     }     cout <<  If you want to call a taxi, you should call:  ;     for (int i = 0; i < (int)res[0].size(); ++i) {       if (i) cout <<  ,  ;       cout << vs[res[0][i]];     }     cout <<  . nIf you want to order a pizza, you should call:  ;     for (int i = 0; i < (int)res[1].size(); ++i) {       if (i) cout <<  ,  ;       cout << vs[res[1][i]];     }     cout <<  . nIf you want to go to a cafe with a wonderful girl, you should                call:  ;     for (int i = 0; i < (int)res[2].size(); ++i) {       if (i) cout <<  ,  ;       cout << vs[res[2][i]];     }     cout <<  .  << endl;     return 0;   }


#include <bits/stdc++.h>   int n, m, a, b, c;   int ans[110][110];   int find(int i, int j) {     for (int k = 1; k <= 10; k++) {       if (k != ans[i][j - 1] && k != ans[i - 1][j] && k != ans[i + 1][j - 1] &&           k != ans[i - 1][j + 1])         return k;     }   }   void output() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) printf( %c , ans[i][j] +  a  - 1);       printf(  n );     }   }   int getans(int n, int m, int a, int b, int c) {     if (b < 0) return 0;     int test = c * 4 + (a / 2) * 4 + (b / 2) * 4;     if (test < n * m) return 0;     for (int i = 1; i < n; i += 2) {       for (int j = 1; j < m; j += 2) {         if (c > 0) {           ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 1][j + 1] =               find(i, j);           c--;         } else if (a >= 2) {           ans[i][j] = ans[i][j + 1] = find(i, j);           ans[i + 1][j] = ans[i + 1][j + 1] = find(i + 1, j);           a -= 2;         } else {           ans[i][j] = ans[i + 1][j] = find(i, j);           ans[i][j + 1] = ans[i + 1][j + 1] = find(i, j + 1);           b -= 2;         }       }     }     return 1;   }   int main() {     while (scanf( %d %d %d %d %d , &n, &m, &a, &b, &c) != EOF) {       memset(ans, 0, sizeof(ans));       if (n % 2 == 1 && m % 2 == 1)         printf( IMPOSSIBLE n );       else if (n % 2 == 0 && m % 2 == 1) {         if (b * 2 < n)           printf( IMPOSSIBLE n );         else {           int found = 1;           b -= n / 2;           found = getans(n, m - 1, a, b, c);           for (int i = 1; i < n; i += 2) ans[i][m] = ans[i + 1][m] = find(i, m);           if (found == 0)             printf( IMPOSSIBLE n );           else             output();         }       } else if (n % 2 == 1 && m % 2 == 0) {         if (a * 2 < m)           printf( IMPOSSIBLE n );         else {           int found = 1;           a -= m / 2;           found = getans(n - 1, m, a, b, c);           for (int i = 1; i < m; i += 2) ans[n][i] = ans[n][i + 1] = find(n, i);           if (found == 0)             printf( IMPOSSIBLE n );           else             output();         }       } else {         int found = getans(n, m, a, b, c);         if (found == 0)           printf( IMPOSSIBLE n );         else           output();       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   bool ok(string s) {     if (s ==   ) return false;     if (s.length() == 1 && s[0] ==  0 ) return true;     if (s[0] ==  0 ) return false;     for (char c : s) {       if (c <  0  || c >  9 ) return false;     }     return true;   }   void cal(string s) {     if (ok(s))       a += s +  , ;     else       b += s +  , ;   }   void go(string &ret) {     if (ret ==   )       ret =  - ;     else {       ret =     + ret;       ret[ret.length() - 1] =    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s, t =   ;     cin >> s;     for (char c : s) {       if (c ==  ,  || c ==  ; ) {         cal(t);         t =   ;       } else {         t += c;       }     }     cal(t);     go(a);     go(b);     cout << a <<   n  << b;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int getRand(int l, int r) {     uniform_int_distribution<int> uid(l, r);     return uid(rng);   }   unordered_map<string, int> X;   long long get_sum(long long n) {     if (n == 1) {       return 1;     }     return get_sum(n / 2) + n;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, num;     long long n, sum = 0, temp;     string str;     cin >> t;     while (t--) {       sum = 0;       temp = 1;       cin >> n;       while (n > 0) {         temp = 1;         while (temp <= n) {           temp *= 2;         }         sum += get_sum(temp / 2);         n = n - (temp / 2);       }       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   const long long int inf = 1e18;   vector<long long int> v, arr;   void pf() {}   long long int sqrtfun(long long int num) {     long long int lo = 0, hi = (long long int)2e9, mid;     if (num == 1) return num;     while (lo + 1 < hi) {       mid = lo + hi >> 1LL;       if (mid * mid == num)         return mid;       else if (mid * mid > num)         hi = mid;       else         lo = mid;     }     return (mid * mid > num) ? mid - 1 : mid;   }   long long int get(long long int r) {     int ans = upper_bound(arr.begin(), arr.end(), r) - arr.begin();     return ans + sqrtfun(r) - 1;   }   void solve() {     for (long long int i = 2; i <= N; i++) {       for (long long int j = i * i * i; j <= inf; j *= i) {         long long int x = sqrtfun(j);         if (x * x != j) v.push_back(j);         if (inf / i < j) break;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int t, l, r, ans = 0;     cin >> t;     solve();     sort(v.begin(), v.end());     for (auto i : v) {       if (arr.empty())         arr.push_back(i);       else if (arr.back() != i)         arr.push_back(i);     }     while (t--) {       cin >> r;       cout << r - get(r) - 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long call(long long n) {     if (n == 1)       return 1;     else       return n + call(n / 2);   }   void fun() {     long long n;     cin >> n;     cout << call(n);   }   int main() {     long long t;     cin >> t;     while (t--) {       fun();       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[4] = {1, -1, 0, 0};   int dy[4] = {0, 0, 1, -1};   long long gcd(long long a, long long b) {     for (; b; a %= b, swap(a, b))       ;     return a;   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       string n;       int k;       cin >> n;       cin >> k;       while (true) {         set<char> s;         for (int i = 0; i < n.size(); i++) s.insert(n[i]);         if (s.size() <= k) {           cout << n <<   n ;           break;         }         s.clear();         int ptr = 0;         while (true) {           s.insert(n[ptr]);           if (s.size() > k) {             while (n[ptr] ==  9 ) ptr--;             n[ptr]++;             for (int i = ptr + 1; i < n.size(); i++) n[i] =  0 ;             break;           }           ptr++;         }       }     }   }


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


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   long long powMod(long long x, long long y) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * x) % ((long long)1e9 + 7);       }       y /= 2;       x = (x * x) % ((long long)1e9 + 7);     }     return p;   }   long long CpowMod(long long x, long long y, long long w) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * x) % w;       }       y /= 2;       x = (x * x) % w;     }     return p;   }   long long invMod(long long x) { return powMod(x, ((long long)1e9 + 7) - 2); }   long long CinvMod(long long x, long long w) { return CpowMod(x, w - 2, w); }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long exGcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       y = 0;       x = 1;       return a;     }     long long xtmp, ytmp;     long long g = exGcd(b, a % b, xtmp, ytmp);     x = ytmp;     y = xtmp - (a / b) * ytmp;     return g;   }   void solve() {     long long t;     cin >> t;     while (t--) {       long long n;       long long x;       cin >> n >> x;       long long cnt = 0, eve = 0;       for (long long i = 0; i <= n - 1; i++) {         long long y;         cin >> y;         if (y % 2)           cnt++;         else           eve++;       }       if (cnt == 0) {         cout <<  NO  <<   n ;         continue;       }       long long mn;       if (x % 2 == 1) {         mn = 0;       } else         mn = 1;       if (cnt % 2 == 0) {         x -= (cnt - 1);       } else         x -= cnt;       x = max(mn, x);       if (eve >= x) {         cout <<  YES  <<   n ;       } else         cout <<  NO  <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     fastio();     int n, m, temp;     cin >> n >> m;     vector<int> boys(n);     vector<int> girls(m);     int hb;     cin >> hb;     for (int i = 0; i < hb; i++) cin >> temp, boys[temp] = 1;     int hg;     cin >> hg;     for (int i = 0; i < hg; i++) cin >> temp, girls[temp] = 1;     int len = 100 * 100;     int a, b;     for (int i = 0; i < len; i++) {       a = i % n;       b = i % m;       if (boys[a] == 1 || girls[b] == 1) boys[a] = 1, girls[b] = 1;     }     for (int i = 0; i < n; i++)       if (boys[i] == 0) {         cout <<  No n ;         return 0;       }     for (int i = 0; i < m; i++)       if (girls[i] == 0) {         cout <<  No n ;         return 0;       }     cout <<  Yes n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(int x, pair<int, int> a) { return a.first <= x && x <= a.second; }   signed main() {     int n;     scanf( %d , &n);     vector<pair<int, pair<int, int>>> vert;     vector<pair<int, pair<int, int>>> hor;     while (n--) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       if (x1 > x2) swap(x1, x2);       if (y1 > y2) swap(y1, y2);       if (x1 == x2) {         vert.push_back({x1, {y1, y2}});       } else {         hor.push_back({y1, {x1, x2}});       }     }     if (signed(hor.size()) < signed(vert.size())) swap(hor, vert);     vector<bitset<5000>> inter(signed(vert.size()));     for (int i = 0; i < signed(vert.size()); ++i)       for (int j = 0; j < signed(hor.size()); ++j)         inter[i][j] = check(hor[j].first, vert[i].second) &&                       check(vert[i].first, hor[j].second);     long long ans = 0;     for (int i = 0; i < signed(vert.size()); ++i)       for (int j = i + 1; j < signed(vert.size()); ++j) {         int cnt = (inter[i] & inter[j]).count();         ans += cnt * (cnt - 1) / 2;       }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int f(long long int a, long long int b) {     long long int z = b, x = 0;     while (z > 1) {       z /= 2;       x++;     }     long long int y = pow(2, x);     if (a == b)       return a;     else if (y <= a)       return f(a - y, b - y) + y;     else if (pow(2, x + 1) - 1 <= b)       return pow(2, x + 1) - 1;     else       return y - 1;   }   int main() {     long long int i, n, a, b;     cin >> n;     while (n--) {       cin >> a >> b;       long long int x = f(a, b);       cout << x << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, a, cnt = 0, tmp;     scanf( %lld%lld%lld , &n, &m, &a);     cnt = (m / a) * (n / a);     if (n % a != 0) cnt += (m / a);     if (m % a != 0) cnt += (n / a);     if (m % a != 0 && n % a != 0) cnt += 1;     printf( %lld n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int number[120], prime[120], primecounter = 0;   void sieve() {     for (int i = 0; i <= 100; i++) number[i] = 1;     number[0] = 0;     number[1] = 0;     for (int i = 4; i <= 100; i = i + 2) number[i] = 0;     for (int i = 3; i * i <= 100; i = i + 2) {       for (int j = 2 * i; j <= 100; j = j + i) {         if (number[j] == 1) number[j] = 0;       }     }     for (int i = 2; i <= 100; i = i + 1) {       if (number[i] == 1) {         primecounter++;         prime[primecounter] = i;       }     }   }   int main(void) {     sieve();     char line[50];     int save[100 + 20];     int yes = 0, no = 0, s;     for (int i = 1; prime[i] <= 53; i++) {       printf( %d n , prime[i]);       fflush(stdout);       scanf( %s , line);       if (strcmp( yes , line) == 0) {         yes++;         s = prime[i];       } else         no++;     }     if (yes == 0) {       printf( prime n );       fflush(stdout);       return 0;     } else if (yes > 1) {       printf( composite n );       fflush(stdout);       return 0;     } else if (yes == 1) {       int v = s * s;       if (v <= 100) {         printf( %d n , v);         fflush(stdout);         scanf( %s , line);         if (strcmp( yes , line) == 0) {           printf( composite n );           fflush(stdout);           return 0;         } else {           printf( prime n );           fflush(stdout);           return 0;         }       } else {         printf( prime n );         fflush(stdout);         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   template <typename first, typename second>   ostream& operator<<(ostream& os, const pair<first, second>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  , ;       os << *it;     }     return os <<  ] ;   }   template <typename T>   ostream& operator<<(ostream& os, const multiset<T>& v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename first, typename second>   ostream& operator<<(ostream& os, const map<first, second>& v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   void faltu() { cerr <<   n ; }   template <typename T>   void faltu(T a[], int n) {     for (int i = 0; i < n; ++i) cerr << a[i] <<    ;     cerr <<   n ;   }   template <typename T, typename... hello>   void faltu(T arg, const hello&... rest) {     cerr << arg <<    ;     faltu(rest...);   }   inline bool checkBit(long long n, int i) { return n & (1LL << i); }   inline long long setBit(long long n, int i) {     return n | (1LL << i);     ;   }   inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }   const int mx = 1e6 + 5;   int n, k;   int a[mx];   struct Vertex {     Vertex() {}     int zero = -1, one = -1;     int dp_zero = 0, dp_one = 0;   };   vector<Vertex> trie;   void add(int num, int node, int pos) {     if (pos == -1) {       ++trie[node].dp_one;       return;     }     if (checkBit(num, pos)) {       if (trie[node].one == -1) {         trie[node].one = (int)trie.size();         int node_child = (int)trie.size();         trie.push_back(Vertex());         add(num, node_child, pos - 1);       } else {         int node_child = trie[node].one;         add(num, node_child, pos - 1);       }       ++trie[node].dp_one;     } else {       if (trie[node].zero == -1) {         trie[node].zero = (int)trie.size();         int node_child = (int)trie.size();         trie.push_back(Vertex());         add(num, node_child, pos - 1);       } else {         int node_child = trie[node].zero;         add(num, node_child, pos - 1);       }       ++trie[node].dp_zero;     }   }   long long ans = 0;   int amount;   void dfs(int num, int node, int pos) {     if (pos == -1) {       ans += trie[node].dp_one;       return;     }     if (checkBit(k, pos)) {       if (checkBit(num, pos)) {         if (trie[node].zero != -1) {           int node_child = trie[node].zero;           if (pos == 0) amount = trie[node].dp_zero;           dfs(num, node_child, pos - 1);         }       } else {         if (trie[node].one != -1) {           int node_child = trie[node].one;           if (pos == 0) amount = trie[node].dp_one;           dfs(num, node_child, pos - 1);         }       }     } else {       if (checkBit(num, pos)) {         ans += trie[node].dp_zero;         int node_child = trie[node].one;         if (pos == 0) amount = trie[node].dp_one;         if (node_child != -1) dfs(num, node_child, pos - 1);       } else {         ans += trie[node].dp_one;         int node_child = trie[node].zero;         if (pos == 0) amount = trie[node].dp_zero;         if (node_child != -1) dfs(num, node_child, pos - 1);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> k;     trie.push_back(Vertex());     add(0, 0, 30);     for (int i = 1; i <= n; ++i) cin >> a[i];     long long Xor = 0;     for (int i = 1; i <= n; ++i) {       Xor ^= a[i];       dfs(Xor, 0, 30);       add(Xor, 0, 30);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<char, int> > vec(100);   int n;   bool check(vector<bool> &bitmask) {     bool flag = 1;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (vec[i].first == vec[j].first) {           if (vec[i].second != vec[j].second) {             if (bitmask[vec[i].second - 1] == 1 ||                 bitmask[vec[j].second - 1] == 1) {               continue;             } else {               flag = 0;               return flag;             }           } else {             continue;           }         } else {           if (vec[i].second == vec[j].second) {             if ((vec[i].first ==  R  || vec[j].first ==  R ) && bitmask[5] == 1) {               continue;             } else if ((vec[i].first ==  G  || vec[j].first ==  G ) &&                        bitmask[6] == 1) {               continue;             } else if ((vec[i].first ==  B  || vec[j].first ==  B ) &&                        bitmask[7] == 1) {               continue;             } else if ((vec[i].first ==  Y  || vec[j].first ==  Y ) &&                        bitmask[8] == 1) {               continue;             } else if ((vec[i].first ==  W  || vec[j].first ==  W ) &&                        bitmask[9] == 1) {               continue;             } else {               flag = 0;               return flag;             }           } else {             if ((vec[i].first ==  R  || vec[j].first ==  R ) && bitmask[5] == 1) {               continue;             } else if ((vec[i].first ==  G  || vec[j].first ==  G ) &&                        bitmask[6] == 1) {               continue;             } else if ((vec[i].first ==  B  || vec[j].first ==  B ) &&                        bitmask[7] == 1) {               continue;             } else if ((vec[i].first ==  Y  || vec[j].first ==  Y ) &&                        bitmask[8] == 1) {               continue;             } else if ((vec[i].first ==  W  || vec[j].first ==  W ) &&                        bitmask[9] == 1) {               continue;             } else if (bitmask[vec[i].second - 1] == 1 ||                        bitmask[vec[j].second - 1] == 1) {               continue;             } else {               flag = 0;               return flag;             }           }         }       }     }     return flag;   }   int solve() {     vector<bool> counter(10, 0);     int ans = 100;     while (1) {       if (check(counter)) {         int cnt = 0;         for (int i = 0; i < 10; i++) {           if (counter[i] == 1) {             cnt++;           }         }         ans = min(ans, cnt);       }       int i = 0;       while (i < 10 && counter[i] == 1) counter[i++] = 0;       if (i == 10) break;       counter[i] = 1;     }     return ans;   }   int main() {     int t = 1;     while (t--) {       cin >> n;       for (int i = 0; i < n; i++) {         cin >> vec[i].first >> vec[i].second;       }       int ans = solve();       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300000;   int n, m, q, p[MAXN + 3], rk[MAXN + 3], dia[MAXN + 3], type, x, y,       dist[MAXN + 3];   bool flag[MAXN + 3];   vector<int> adj[MAXN + 3];   int ceil(int n) {     if (!n) return 0;     return (n - 1) / 2 + 1;   }   int find(int x) { return (p[x] == x ? x : (p[x] = find(p[x]))); }   void join(int x, int y) {     x = find(x);     y = find(y);     if (x == y) return;     if (rk[x] < rk[y]) swap(x, y);     rk[x] += rk[y];     p[y] = x;   }   void join2(int x, int y) {     x = find(x);     y = find(y);     if (x == y) return;     if (rk[x] < rk[y]) swap(x, y);     dia[x] = max(max(dia[x], dia[y]), ceil(dia[x]) + ceil(dia[y]) + 1);     rk[x] += rk[y];     p[y] = x;   }   int calDia(int p) {     queue<int> q;     q.push(p);     flag[p] = true;     dist[p] = 0;     int u, v;     while (!q.empty()) {       u = q.front();       q.pop();       for (int i = 0; i < (int)adj[u].size(); ++i) {         v = adj[u][i];         if (!flag[v]) {           flag[v] = true;           dist[v] = dist[u] + 1;           q.push(v);         }       }     }     q.push(u);     flag[u] = false;     dist[u] = 0;     while (!q.empty()) {       u = q.front();       q.pop();       for (int i = 0; i < (int)adj[u].size(); ++i) {         v = adj[u][i];         if (flag[v]) {           flag[v] = false;           dist[v] = dist[u] + 1;           q.push(v);         }       }     }     return dist[u];   }   int main() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= n; ++i) p[i] = i, rk[i] = 1;     for (int i = 1; i <= m; ++i) {       scanf( %d %d , &x, &y);       join(x, y);       adj[x].push_back(y);       adj[y].push_back(x);     }     for (int i = 1; i <= n; ++i)       if (find(i) == i) {         dia[i] = calDia(i);       }     while (q-- > 0) {       scanf( %d %d , &type, &x);       if (type == 1) {         printf( %d n , dia[find(x)]);       } else {         scanf( %d , &y);         join2(x, y);       }     }     return 0;   }