#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n, m;   int a[maxn];   int b[maxn];   int ans[maxn];   int main() {     cin >> n >> m;     int num = 0;     for (int i = 0; i < m; i++) {       scanf( %d , a + i);       if (b[a[i]] == 0) num++;       b[a[i]]++;       if (num == n) {         ans[i] = 1;         num = 0;         for (int j = 1; j <= n; j++) {           b[j]--;           if (b[j] > 0) num++;         }       } else {         ans[i] = 0;       }     }     for (int i = 0; i < m; i++) {       printf( %d , ans[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 myrand(time(0));   bool isprime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i += 6) {       if (n % i == 0 || n % (i + 2) == 0) return false;     }     return true;   }   long long modexp(long long a, long long b, long long m) {     long long r = 1;     a = a % m;     while (b > 0) {       if (b & 1) r = (r * a) % m;       b = b >> 1;       a = (a * a) % m;     }     return r % m;   }   long long builtin_popcount(long long x) {     long long cnt = 0;     for (long long i = 60; i >= 0; i--) {       if ((1LL << i) & x) cnt++;     }     return cnt;   }   long long addmod(long long a, long long b) {     a %= 1000000007;     b %= 1000000007;     return (a + b) % 1000000007;   }   long long mulmod(long long a, long long b) {     a %= 1000000007;     b %= 1000000007;     return (a * b) % 1000000007;   }   long long submod(long long a, long long b) {     a %= 1000000007;     b %= 1000000007;     a -= b;     if (a < 0) a += 1000000007;     return a % 1000000007;   }   struct CustomCompare {     bool operator()(pair<long long, long long> a, pair<long long, long long> b) {       return a.first < b.first;     }   };   long long n, m, d;   vector<vector<long long> > g;   vector<long long> arr;   void dfs(long long src, vector<long long> &dp, long long par = -1) {     dp[src] = (par != -1 ? dp[par] + 1LL : 0LL);     for (auto x : g[src]) {       if (x != par) dfs(x, dp, src);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> d;     g = vector<vector<long long> >(n);     arr = vector<long long>(m);     vector<long long> vis(n, 0);     for (int i = 0; i < m; i++) cin >> arr[i], arr[i]--, vis[arr[i]] = 1;     for (int i = 1; i < n; i++) {       long long u, v;       cin >> u >> v;       --u, --v;       g[u].push_back(v), g[v].push_back(u);     }     vector<long long> dp(n, 0);     dfs(0, dp);     long long a = -1, mx = -1000000007;     for (int i = 0; i < n; i++) {       if (mx < dp[i] && vis[i]) {         mx = dp[i];         a = i;       }       dp[i] = 0;     }     dfs(a, dp);     long long b = -1;     mx = -1000000007;     for (int i = 0; i < n; i++) {       if (mx < dp[i] && vis[i]) {         mx = dp[i];         b = i;       }     }     vector<long long> dp2(n);     dfs(b, dp2);     long long ans = 0;     for (int i = 0; i < n; i++)       if (dp[i] <= d && dp2[i] <= d) ans++;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   template <typename... T>   void rd(T&... args) {     ((cin >> args), ...);   }   template <typename... T>   void wr(T... args) {     ((cout << args <<    ), ...);     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       vector<int> a(n), l(n);       for (auto& i : a) cin >> i;       for (auto& i : l) cin >> i;       vector<int> tmp;       for (int i = 0; i < n; i++) {         if (!l[i]) {           tmp.push_back(a[i]);         }       }       sort(tmp.begin(), tmp.end());       for (int i = 0; i < n; i++) {         if (l[i])           cout << a[i] <<    ;         else {           cout << tmp.back() <<    ;           tmp.pop_back();         }       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x;     cin >> x;     int sum = 0, s;     s = x.size();     for (int i = 0; i < x.size(); i++) {       if (x[i] == x[s - i - 1] &&           (x[i] ==  A  || x[i] ==  H  || x[i] ==  I  || x[i] ==  M  ||            x[i] ==  O  || x[i] ==  T  || x[i] ==  U  || x[i] ==  V  ||            x[i] ==  W  || x[i] ==  X  || x[i] ==  Y ))         sum++;     }     if (sum == s) {       cout <<  YES ;       return 0;     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     vector<long long> v;     long long last;     int q, a, b, lo, hi, one, two;     long double aa, bb;     cin >> q;     cout << fixed;     cout << setprecision(6);     while (q--) {       cin >> a;       if (a == 1) {         cin >> b;         if (v.size() == 0) {           v.push_back(b);         } else {           v.push_back(b);           v.back() += v[v.size() - 2];         }       } else {         lo = 0;         hi = v.size() - 2;         if (hi < 0) {           cout << (long double)0 <<   n ;           continue;         }         last = v.back() - v[v.size() - 2];         while (lo < hi) {           one = ((hi - lo) / 3) + lo;           two = hi - ((hi - lo) / 3);           aa = (long double)(v[one] + last) / (long double)(one + 2);           bb = (long double)(v[two] + last) / (long double)(two + 2);           if (aa < bb) {             hi = two - 1;           } else {             lo = one + 1;           }         }         aa = (long double)(v[lo] + last) / (long double)(lo + 2);         aa = (long double)last - aa;         cout << aa <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n;   int main() {     cin >> n;     long long int cnt = 0, c;     for (long long int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) cnt++;     }     if (cnt == 0) {       cout << n;       goto skip;     }     for (long long int i = 2; i <= sqrt(n); i++)       if (n % i == 0) {         c = i;         break;       }     while (n % c == 0) {       n /= c;     }     if (n == 1) {       cout << c;     } else {       cout << 1;     }   skip:;     return 0;   }


#include <bits/stdc++.h>   template <typename T>   T gcd(T a, T b) {     if (!b) return a;     return gcd(b, a % b);   }   template <typename T>   T lcm(T a, T b) {     return a * b / gcd(a, b);   }   template <typename T>   void chmin(T& a, T b) {     a = (a > b) ? b : a;   }   template <typename T>   void chmax(T& a, T b) {     a = (a < b) ? b : a;   }   int in() {     int x;     scanf( %d , &x);     return x;   }   using namespace std;   const int MAXN = 502;   int N, M;   int P[MAXN][MAXN];   vector<int> G[MAXN], GA[MAXN];   vector<int> comp;   bool vis[MAXN];   int color[MAXN];   void dfs(int x) {     vis[x] = true;     for (int i = 0; i < (int)GA[x].size(); i++) {       int u = G[x][i];       if (!vis[u]) {         dfs(u);       }     }   }   bool dfs_color(int node, int c) {     if (color[node] != 0) {       if (color[node] == c) {         return true;       } else {         return false;       }     }     color[node] = c;     for (int i = 0; i < (int)GA[node].size(); i++) {       if (!dfs_color(GA[node][i], -c)) {         return false;       }     }     return true;   }   int main(void) {     cin >> N >> M;     string S(N,  b );     for (int i = 0; i < M; i++) {       int A, B;       cin >> A >> B;       A -= 1;       B -= 1;       P[A][B] = 1;       P[B][A] = 1;       G[A].push_back(B);       G[B].push_back(A);     }     bool valid = true;     for (int i = 0; i < N; i++) {       for (int j = i; j < N; j++) {         if (i != j && !P[i][j]) {           GA[i].push_back(j);           GA[j].push_back(i);         }       }     }     for (int i = 0; i < N; i++) {       if (!vis[i] && GA[i].size() > 0) {         comp.push_back(i);       }     }     for (int i = 0; i < (int)comp.size(); i++) {       if (color[comp[i]] == 0 && !dfs_color(comp[i], 1)) {         valid = false;       }     }     for (int i = 0; i < N; i++) {       if (color[i] == -1) {         S[i] =  a ;       }       if (color[i] == 1) {         S[i] =  c ;       }     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         if (i != j) {           if (P[i][j] && abs(S[i] - S[j]) > 1) {             valid = false;           }           if (!P[i][j] && abs(S[i] - S[j]) <= 1) {             valid = false;           }         }       }     }     if (valid) {       cout <<  Yes n  << S <<   n ;     } else {       cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int add(int x, int y) { return ((x + y) % 998244353 + 998244353) % 998244353; }   int mul(int x, int y) { return (long long)x * y % 998244353; }   int mypow(int x, int c) {     int ret = 1;     while (c > 0) {       if (c & 1) {         ret = mul(ret, x);       }       c /= 2;       x = mul(x, x);     }     return ret;   }   int seg[200002 * 4], ad[200002 * 4], mm[200002 * 4];   void init(int pos, int l, int r) {     mm[pos] = 1;     if (l == r) {       return;     }     int mid = (l + r) / 2;     init(pos * 2, l, mid);     init(pos * 2 + 1, mid + 1, r);   }   void push(int pos, int l, int r) {     seg[pos] = mul(seg[pos], mm[pos]);     seg[pos] = add(seg[pos], mul(r - l + 1, ad[pos]));     if (l != r) {       mm[pos * 2] = mul(mm[pos], mm[pos * 2]);       mm[pos * 2 + 1] = mul(mm[pos], mm[pos * 2 + 1]);       ad[pos * 2] = add(mul(ad[pos * 2], mm[pos]), ad[pos]);       ad[pos * 2 + 1] = add(mul(ad[pos * 2 + 1], mm[pos]), ad[pos]);     }     mm[pos] = 1;     ad[pos] = 0;   }   void update(int pos, int l, int r, int ql, int qr, int m, int a) {     push(pos, l, r);     if (r < ql || qr < l) {       return;     }     if (ql <= l && r <= qr) {       mm[pos] = mul(mm[pos], m);       ad[pos] = add(mul(m, ad[pos]), a);       push(pos, l, r);       return;     }     int mid = (l + r) / 2;     update(pos * 2, l, mid, ql, qr, m, a);     update(pos * 2 + 1, mid + 1, r, ql, qr, m, a);     seg[pos] = add(seg[pos * 2], seg[pos * 2 + 1]);   }   int query(int pos, int l, int r, int ql, int qr) {     push(pos, l, r);     if (r < ql || qr < l) {       return 0;     }     if (ql <= l && r <= qr) {       return seg[pos];     }     int mid = (l + r) / 2;     return add(query(pos * 2, l, mid, ql, qr),                query(pos * 2 + 1, mid + 1, r, ql, qr));   }   set<pair<int, int> > s[200002];   void solve() {     int n, q;     scanf( %d %d  , &n, &q);     init(1, 1, n);     for (int i = n; i; --i) {       s[i].insert({n + 2, 0});     }     while (q--) {       int type, l, r;       scanf( %d %d %d  , &type, &l, &r);       if (type == 1) {         int x;         scanf( %d  , &x);         int ml = l, mr = r;         int cur = l;         set<pair<int, int> >::iterator it = s[x].lower_bound({l + 1, 0});         if (it != s[x].begin()) {           it = prev(it);           pair<int, int> t = *it;           if (t.second + 1 >= l) {             ml = min(ml, t.first);             mr = max(mr, t.second);             s[x].erase(it);             update(1, 1, n, l, min(r, t.second), 2, 0);             cur = t.second + 1;           }         }         while (true) {           set<pair<int, int> >::iterator it = s[x].lower_bound({cur, 0});           pair<int, int> tmp = *it;           if (tmp.first <= r + 1) {             if (cur < tmp.first) {               update(1, 1, n, cur, min(r, tmp.first - 1), 1, 1);             }             if (tmp.first <= r) {               update(1, 1, n, tmp.first, min(tmp.second, r), 2, 0);             }             cur = tmp.second + 1;             mr = max(mr, tmp.second);             s[x].erase(it);           } else {             if (cur <= r) {               update(1, 1, n, cur, r, 1, 1);             }             break;           }         }         s[x].insert({ml, mr});       } else {         printf( %d n , query(1, 1, n, l, r));       }     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b;     cin >> a >> b;     if (b / 2 >= a)       cout << (b % (b / 2 + 1));     else       cout << b % a;     cout <<   n ;     return;   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     long long t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 15;   const int M = 20;   bool used[N];   vector<int> adj[N];   int a[N], b[N], w[N];   int out[N];   int dsu[N];   int f(int x) { return dsu[x] == x ? x : dsu[x] = f(dsu[x]); }   bool merge(int id) {     int u = f(a[id]), v = f(b[id]);     if (u != v) {       dsu[u] = v;       return true;     }     return false;   }   int anc[N][M], wa[N][M];   int depth[N];   void construct(int node, int par) {     for (int i = 1; i < M; ++i) {       anc[node][i] = anc[anc[node][i - 1]][i - 1];       wa[node][i] = max(wa[node][i - 1], wa[anc[node][i - 1]][i - 1]);     }     for (int eid : adj[node]) {       int ch = a[eid] ^ b[eid] ^ node;       if (ch != par) {         depth[ch] = depth[node] + 1;         anc[ch][0] = node;         wa[ch][0] = w[eid];         construct(ch, node);       }     }   }   pair<int, int> getAnc(int x, int y) {     if (depth[x] < depth[y]) swap(x, y);     int diff = depth[x] - depth[y], ret = 0;     for (int i = 0; i < M; ++i) {       if (diff & (1 << i)) {         ret = max(ret, wa[x][i]);         x = anc[x][i];       }     }     if (x != y) {       for (int i = M - 1; i >= 0; --i) {         if (anc[x][i] != anc[y][i]) {           ret = max(ret, max(wa[x][i], wa[y][i]));           x = anc[x][i];           y = anc[y][i];         }       }       ret = max(ret, max(wa[x][0], wa[y][0]));       x = anc[x][0];     }     return {ret, x};   }   multiset<int> g[N];   vector<int> ed[N];   void dfs(int node, int par) {     for (int eid : adj[node]) {       int ch = a[eid] ^ b[eid] ^ node;       if (ch != par) {         dfs(ch, node);         out[eid] = g[ch].size() == 0 ? -1 : (*g[ch].begin()) - 1;         if (g[node].size() < g[ch].size()) {           swap(g[node], g[ch]);         }         for (int x : g[ch]) g[node].insert(x);       }     }     for (int val : ed[node]) {       assert(g[node].find(val) != g[node].end());       g[node].erase(g[node].find(val));       assert(g[node].find(val) != g[node].end());       g[node].erase(g[node].find(val));     }   }   void solve2() {     int n, m;     scanf( %d %d , &n, &m);     vector<pair<int, int> > edges;     for (int i = 0; i < m; ++i) {       scanf( %d %d %d  , &a[i], &b[i], &w[i]);       edges.push_back({w[i], i});     }     for (int i = n; i; --i) dsu[i] = i;     sort(edges.begin(), edges.end());     for (int i = 0; i < m; ++i) {       int id = edges[i].second;       if (merge(id)) {         used[id] = true;         adj[a[id]].push_back(id);         adj[b[id]].push_back(id);       }     }     construct(1, 0);     for (int i = 0; i < m; ++i) {       if (!used[i]) {         pair<int, int> tmp = getAnc(a[i], b[i]);         out[i] = tmp.first - 1;         g[a[i]].insert(w[i]);         g[b[i]].insert(w[i]);         ed[tmp.second].push_back(w[i]);       }     }     dfs(1, 0);     for (int i = 0; i < m; ++i) {       printf( %d n , out[i]);     }   }   void solve() { solve2(); }   int main() {     solve();     return 0;   }


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


#include<bits/stdc++.h>   using namespace std;   typedef long long int ll;   #define MAX 2000000000   vector<ll> feaseable;   void setfun(){       for(ll i = 3; i<MAX; i+=2){           ll sq = i * i;           if(sq>MAX){               break;           }           ll c = (sq + 1)/2;           feaseable.push_back(c);       }   }      int main(){       int t;       cin>>t;       setfun();       while(t--){           int n;           cin>>n;           auto x = upper_bound(feaseable.begin(),feaseable.end(),n);           int ans = x - feaseable.begin();           cout<<ans<<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, k, a;     cin >> n >> k >> a;     long n_moves;     cin >> n_moves;     set<pair<long, long> > s;     s.insert(make_pair(n, 1));     long max_ships = (n + 1) / (a + 1);     for (int i = 1; i <= n_moves; i++) {       long x;       cin >> x;       set<pair<long, long> >::iterator it = s.lower_bound(make_pair(x, -1));       long l = it->second;       long r = it->first;       max_ships -= (r - l + 2) / (a + 1);       if ((x - 1) >= l) {         max_ships += ((x - 1) - l + 2) / (a + 1);       }       if ((x + 1) <= r) {         max_ships += (r - (x + 1) + 2) / (a + 1);       }       if (max_ships < k) {         cout << i;         return 0;       }       s.erase(it);       if ((x - 1) >= l) s.insert(make_pair(x - 1, l));       if ((x + 1) <= r) s.insert(make_pair(r, x + 1));     }     cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   int parent[150000];   int size[150000];   long long int edges[150000];   struct dsu {     void init(int n) {       for (int i = 0; i < n; ++i) {         parent[i] = i;         size[i] = 1;         edges[i] = 0;       }     }     int p(int x) {       if (parent[x] == x) return x;       return parent[x] = p(parent[x]);     }     void unite(int x, int y) {       int supx = p(x);       int supy = p(y);       if (supx != supy) {         if (size[supx] > size[supy]) {           parent[supy] = supx;           size[supx] += size[supy];           edges[supx] += edges[supy] + 1;         } else {           parent[supx] = supy;           size[supy] += size[supx];           edges[supy] += edges[supx] + 1;         }       } else {         edges[supx]++;       }     }   };   int n, m, x, y;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n >> m;     dsu d;     d.init(n);     for (int i = 0; i < m; ++i) {       cin >> x >> y;       x--;       y--;       d.unite(x, y);     }     for (int i = 0; i < n; ++i) {       if (parent[i] == i) {         long long int ed = edges[i];         long long int vertices = size[i];         if (ed != (vertices * (vertices - 1)) / 2) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 100000007;   const int M = 100005;   const double pi = acos(-1);   struct pt {     long long x, y, EWGDFGdfgfsdhfdshfdhf;     bool operator<(const pt &a) const { return (x < a.x); }     bool operator>(const pt &a) const { return (x > a.x); }   };   long long CAlASFSAF[100050], n, m, k;   set<pt> u[200050];   set<pt> d[200050];   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     cin >> m;     cin >> k;     for (int i = 1; i <= k; i++) {       pt p;       cin >> p.x;       cin >> p.y;       p.EWGDFGdfgfsdhfdshfdhf = i;       u[p.y - p.x + 100000].insert(p);       d[p.y + p.x].insert(p);     }     pt now, lst;     now.x = 0;     now.y = 0;     now.EWGDFGdfgfsdhfdshfdhf = 0;     long long xPXPXPPXXPXP = 1, nowdy = 1;     for (int i = 1; i <= k; i++) CAlASFSAF[i] = -1;     CAlASFSAF[0] = 0;     long long NTNTNFN = 0, PLOPLO = 0;     set<pt>::iterator ite;     while (true) {       lst = now;       if (nowdy == 1) {         if (xPXPXPPXXPXP == 1) {           while (!u[now.y - now.x + 100000].empty()) {             lst = now;             NTNTNFN = PLOPLO;             now = *(u[now.y - now.x + 100000].begin());             PLOPLO = NTNTNFN + abs(now.x - lst.x);             if (CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] == -1)               CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] = PLOPLO;             u[now.y - now.x + 100000].erase(u[now.y - now.x + 100000].begin());           }         } else {           while (!d[now.y + now.x].empty()) {             lst = now;             NTNTNFN = PLOPLO;             ite = d[now.y + now.x].end();             ite--;             now = *ite;             PLOPLO = NTNTNFN + abs(now.x - lst.x);             if (CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] == -1)               CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] = PLOPLO;             d[now.y + now.x].erase(ite);           }         }       } else {         if (xPXPXPPXXPXP == 1) {           while (!d[now.y + now.x].empty()) {             lst = now;             NTNTNFN = PLOPLO;             now = *(d[now.y + now.x].begin());             PLOPLO = NTNTNFN + abs(now.x - lst.x);             if (CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] == -1)               CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] = PLOPLO;             d[now.y + now.x].erase(d[now.y + now.x].begin());           }         } else {           while (!u[now.y - now.x + 100000].empty()) {             lst = now;             NTNTNFN = PLOPLO;             ite = u[now.y - now.x + 100000].end();             ite--;             now = *ite;             PLOPLO = NTNTNFN + abs(now.x - lst.x);             if (CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] == -1)               CAlASFSAF[now.EWGDFGdfgfsdhfdshfdhf] = PLOPLO;             u[now.y - now.x + 100000].erase(ite);           }         }       }       pt tr = now;       tr.x += (xPXPXPPXXPXP * min(abs(now.x - (xPXPXPPXXPXP == 1 ? n : 0)),                                   abs(now.y - (nowdy == 1 ? m : 0))));       tr.y += (nowdy * min(abs(now.x - (xPXPXPPXXPXP == 1 ? n : 0)),                            abs(now.y - (nowdy == 1 ? m : 0))));       tr.EWGDFGdfgfsdhfdshfdhf = 0;       PLOPLO = PLOPLO + abs(tr.x - now.x);       if (((tr.x == 0) || (tr.x == n)) && ((tr.y == 0) || (tr.y == m))) break;       if (((xPXPXPPXXPXP == 1) && (tr.x == n)) ||           ((xPXPXPPXXPXP == -1) && (tr.x == 0)))         xPXPXPPXXPXP *= (-1);       if (((nowdy == 1) && (tr.y == m)) || ((nowdy == -1) && (tr.y == 0)))         nowdy *= (-1);       now = tr;     }     for (int i = 1; i <= k; i++) {       cout << CAlASFSAF[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n, count = 0, count1 = 0, x = 0;     cin >> m >> n;     int a[m][n], b[m][n];     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         cin >> b[i][j];         a[i][j] = 1;       }     }     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         if (b[i][j] == 0) {           for (int k = 0; k < n; k++) {             if (a[i][k] == 1) {               a[i][k] = 0;               count++;               if (count == n * m) break;             }           }           for (int k = 0; k < m; k++) {             if (a[k][j] == 1) {               a[k][j] = 0;               count++;               if (count == n * m) break;             }           }         }         if (count == n * m) break;       }       if (count == n * m) break;     }     if (count == n * m) {       for (int i = 0; i < m; i++) {         for (int j = 0; j < n; j++) {           if (b[i][j] == 1) {             cout <<  NO ;             count = 0;             break;           }         }         if (count == 0) break;       }       if (count != 0) {         cout <<  YES  << endl;         for (int i = 0; i < m; i++) {           for (int j = 0; j < n; j++) cout << a[i][j] <<    ;           cout << endl;         }       }     } else {       for (int i = 0; i < m; i++) {         for (int j = 0; j < n; j++) {           x = 0;           if (b[i][j] == 1) {             for (int k = 0; k < m; k++) x = x || a[k][j];             for (int k = 0; k < n; k++) x = x || a[i][k];             if (x != 1) {               cout <<  NO ;               count1++;               break;             }           }         }         if (count1 > 0) break;       }       if (count1 == 0) {         cout <<  YES  << endl;         for (int i = 0; i < m; i++) {           for (int j = 0; j < n; j++) {             cout << a[i][j] <<    ;           }           cout << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long int getLength(long long int x) {     long long int c = 0;     while (x > 0) {       c++;       x /= 10;     }     return c;   }   int main() {     long long int n, k, i, j;     cin >> n >> k;     long long int a[n], lengths[n];     for (i = 0; i < n; i++) {       cin >> a[i];       lengths[i] = getLength(a[i]);     }     vector<vector<long long int>> v(11);     long long int l, m;     for (i = 0; i < n; i++) {       l = lengths[i];       m = a[i] % k;       v[l].push_back(m);     }     for (i = 0; i <= 10; i++) {       sort(v[i].begin(), v[i].end());     }     long long int ans = 0, avail, req;     for (i = 0; i < n; i++) {       for (j = 1; j <= 10; j++) {         avail = (a[i] % k * ((long long int)(pow(10, j)) % k)) % k;         req = (k - avail) % k;         auto l = lower_bound(v[j].begin(), v[j].end(), req);         auto r = upper_bound(v[j].begin(), v[j].end(), req);         ans += (r - l);         if (lengths[i] == j && (avail + a[i] % k) % k == 0) --ans;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long int eet(long long int a, long long int b, long long int *x,                     long long int *y) {     if (a == 0) {       *x = 0;       *y = 1;       return b;     }     long long int x1, y1;     long long int gcd = eet(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   int main() {     long long int n, m, i, j, k, cnt = 0, sum = 0, mn = INT_MAX, ind,                                  rem = 1000000007, ok = 0, size, lcm,                                  mx = INT_MIN, diff, num, x, y, z, ee;     int flag = 0, t = 1;     string s, str, s1, s2, s3;     char ch;     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     while (t--) {       long long int a, b, c;       cin >> a >> b >> c;       c = -c;       long long int GCD = eet(a, b, &x, &y);       if (c % GCD != 0) {         cout << -1;         return 0;       }       long long int mul = c / GCD;       cout << x * mul <<     << y * mul;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long ans;   vector<long long> all, aa, bb;   int main() {     aa.clear();     bb.clear();     all.clear();     long long a, b;     cin >> a >> b;     ans = 2 * (a + b + 1);     for (long long i = 1; i * i <= (a + b); i++)       if ((a + b) % i == 0) all.push_back(i);     for (long long i = 1; i * i <= a; i++)       if (a % i == 0) aa.push_back(i);     for (long long i = 1; i * i <= b; i++)       if (b % i == 0) bb.push_back(i);     int now1 = 0, now2 = 0;     while (now1 < aa.size() && now2 < all.size()) {       if (aa[now1] <= all[now2] && (a / aa[now1]) <= (a + b) / (all[now2])) {         ans = min(ans, 2 * (all[now2] + (a + b) / all[now2]));         now2++;       } else if (aa[now1] > all[now2])         now2++;       else         now1++;     }     now1 = 0, now2 = 0;     while (now1 < bb.size() && now2 < all.size()) {       if (bb[now1] <= all[now2] && (b / bb[now1]) <= (a + b) / (all[now2])) {         ans = min(ans, 2 * (all[now2] + (a + b) / all[now2]));         now2++;       } else if (bb[now1] > all[now2])         now2++;       else         now1++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, d;   int v[50 + 5];   bool F[5000000 + 5];   int main() {     scanf( %d%d , &n, &d);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     F[0] = true;     int sum = 0;     for (int i = 1; i <= n; i++) {       sum += v[i];       for (int j = sum; j >= v[i]; j--) F[j] |= F[j - v[i]];     }     int ans = 0, day = 0;     bool found = false;     while (1) {       for (int i = d; i >= 1; i--) {         if (F[ans + i]) {           ans += i;           day++;           found = true;           break;         }       }       if (!found)         break;       else         found = false;     }     printf( %d %d n , ans, day);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000010;   unordered_map<int, vector<pair<int, int> > > rows;   unordered_map<int, vector<pair<int, int> > > cols;   int n, m;   int cnum;   map<pair<int, int>, int> id;   map<pair<int, int>, vector<pair<int, int> > > adj1;   unordered_map<int, vector<int> > adj2;   int dp[MAXN];   void fgreat(const vector<pair<int, int> >& v, int row, int col) {     int sz = v.size();     for (int i = 0; i < (sz - 1); ++i)       if (v[i].first < v[i + 1].first) {         if (row == -1) {           adj2[id[make_pair(v[i + 1].second, col)]].push_back(               id[make_pair(v[i].second, col)]);         } else {           adj2[id[{row, v[i + 1].second}]].push_back(               id[make_pair(row, v[i].second)]);         }       }   }   void fequal(const vector<pair<int, int> >& v, int row, int col) {     int sz = v.size();     for (int i = 0; i < (sz - 1); ++i)       if (v[i].first == v[i + 1].first) {         if (row == -1) {           adj1[{v[i].second, col}].push_back(make_pair(v[i + 1].second, col));           adj1[{v[i + 1].second, col}].push_back(make_pair(v[i].second, col));         } else {           adj1[{row, v[i].second}].push_back(make_pair(row, v[i + 1].second));           adj1[{row, v[i + 1].second}].push_back(make_pair(row, v[i].second));         }       }   }   void dfs(int sx, int sy) {     id[{sx, sy}] = cnum;     const auto& v = adj1[{sx, sy}];     for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)       if (!id.count(*it)) {         dfs(it->first, it->second);       }   }   int solve(int id) {     int& ans = dp[id];     if (ans != -1) return ans;     ans = 0;     const auto& v = adj2[id];     for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)       ans = max(ans, solve(*it));     return ++ans;   }   int main() {     scanf(  %d %d , &(n), &(m));     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (m); ++j) {         int x;         scanf(  %d , &(x));         rows[i].push_back(make_pair(x, j));         cols[j].push_back(make_pair(x, i));       }     for (__typeof((rows).begin()) it = (rows).begin(); it != (rows).end(); ++it) {       auto& v = it->second;       sort(v.begin(), v.end());     }     for (__typeof((cols).begin()) it = (cols).begin(); it != (cols).end(); ++it) {       auto& v = it->second;       sort(v.begin(), v.end());     }     for (__typeof((rows).begin()) it = (rows).begin(); it != (rows).end(); ++it) {       fequal(it->second, it->first, -1);     }     for (__typeof((cols).begin()) it = (cols).begin(); it != (cols).end(); ++it) {       fequal(it->second, -1, it->first);     }     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (m); ++j)         if (!id.count({i, j})) {           dfs(i, j);           ++cnum;         }     for (__typeof((rows).begin()) it = (rows).begin(); it != (rows).end(); ++it) {       fgreat(it->second, it->first, -1);     }     for (__typeof((cols).begin()) it = (cols).begin(); it != (cols).end(); ++it) {       fgreat(it->second, -1, it->first);     }     memset(dp, -1, sizeof(dp));     for (int i = 0; i < (n); ++i) {       for (int j = 0; j < (m); ++j) {         if (j) printf(   );         printf( %d , solve(id[{i, j}]));       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string c1, c2;   int main() {     int x;     cin >> c1 >> c2;     for (int i = 0; i < c1.size(); i++) {       if (c1[i] < 92) {         c1[i] += 32;       }       if (c2[i] < 92) {         c2[i] += 32;       }     }     if (c1 < c2) {       x = -1;     } else if (c1 > c2) {       x = 1;     } else {       x = 0;     }     printf( %d n , x);     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 10010100;   const int MAZN = 301010;   int ch[MAXN][3];   int n, cnt, cout[MAXN];   int arr[MAZN];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);     }     for (int i = 1; i <= n; i++) {       int tem, p = 0;       scanf( %d , &tem);       for (int k = 29; k >= 0; k--) {         int tmp = (tem >> k) & 1;         if (ch[p][tmp])           p = ch[p][tmp];         else           p = ch[p][tmp] = ++cnt;         cout[p]++;       }     }     for (int i = 1; i <= n; i++) {       int x = arr[i];       int ans = 0, p = 0;       for (int j = 29; j >= 0; j--) {         int tmp = (x >> j) & 1;         if (ch[p][tmp] && cout[ch[p][tmp]]) {           p = ch[p][tmp];         } else {           p = ch[p][!tmp];           ans += (1 << j);         }         cout[p]--;       }       printf( %d  , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, ans = 0;     string s;     cin >> n;     while (cin >> s) {       int cnt = 0;       for (int i = 0; i < s.length(); ++i) {         if (s[i] >=  A  && s[i] <=  Z ) {           ++cnt;         }       }       ans = max(ans, cnt);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gi() {     char cc = getchar();     int cn = 0, flus = 1;     while (cc <  0  || cc >  9 ) {       if (cc ==  - ) flus = -flus;       cc = getchar();     }     while (cc >=  0  && cc <=  9 ) cn = cn * 10 + cc -  0 , cc = getchar();     return cn * flus;   }   const int N = 1e5 + 5;   int n, m, q, L[N];   struct SegmentBeats {     int bef, mx, se, tot, tag;   } tr[N << 2];   void cmax(int &x, int y) { x = (x < y) ? y : x; }   inline void pushup(int x) {     tr[x].tot = tr[x].se = 0,     tr[x].mx = max(tr[(x << 1)].mx, tr[(x << 1 | 1)].mx);     if (tr[x].mx == tr[(x << 1)].mx)       tr[x].tot += tr[(x << 1)].tot, cmax(tr[x].se, tr[(x << 1)].se);     else       cmax(tr[x].se, tr[(x << 1)].mx);     if (tr[x].mx == tr[(x << 1 | 1)].mx)       tr[x].tot += tr[(x << 1 | 1)].tot, cmax(tr[x].se, tr[(x << 1 | 1)].se);     else       cmax(tr[x].se, tr[(x << 1 | 1)].mx);     tr[x].bef = tr[x].mx;   }   inline void push(int x, int k) { tr[x].mx = k, tr[x].tag = k; }   inline void pushmark(int x) {     if (!tr[x].tag) return;     if (tr[(x << 1)].mx == tr[x].bef) push((x << 1), tr[x].tag);     if (tr[(x << 1 | 1)].mx == tr[x].bef) push((x << 1 | 1), tr[x].tag);     tr[x].tag = 0, tr[x].bef = tr[x].mx;   }   int query(int x, int l, int r, int k) {     if (l == r) return tr[x].mx;     int mid = (l + r) >> 1;     pushmark(x);     if (k <= mid)       return query((x << 1), l, mid, k);     else       return query((x << 1 | 1), mid + 1, r, k);   }   void update(int x, int l, int r, int k, int d) {     if (l == r) return tr[x].mx = d, tr[x].se = 0, tr[x].tot = 1, void();     int mid = (l + r) >> 1;     pushmark(x);     if (k <= mid)       update((x << 1), l, mid, k, d);     else       update((x << 1 | 1), mid + 1, r, k, d);     pushup(x);   }   void modify(int x, int l, int r, int ql, int qr, int y, int z) {     if (tr[x].mx < y || r < ql || qr < l) return;     if ((ql <= l && r <= qr) && (tr[x].se < y && tr[x].mx >= y))       return push(x, z);     int mid = (l + r) >> 1;     pushmark(x);     modify((x << 1), l, mid, ql, qr, y, z),         modify((x << 1 | 1), mid + 1, r, ql, qr, y, z), pushup(x);   }   vector<pair<int, int> > p[N];   int ans[N];   signed main() {     n = gi(), m = gi();     int x, y;     for (int i = (1); i <= (m); ++i) x = gi(), y = gi(), L[y] = x;     q = gi();     for (int i = (1); i <= (q); ++i)       x = gi(), y = gi(), p[y].push_back(make_pair(x, i));     for (int i = (1); i <= (n); ++i) {       update(1, 1, n, i, i);       if (L[i]) modify(1, 1, n, 1, L[i], L[i], i);       for (auto u : p[i]) ans[u.second] = query(1, 1, n, u.first);     }     for (int i = (1); i <= (q); ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   const int N = 3003;   const long long mod = 998244353;   using namespace std;   int n;   int c;   int a[N];   int p[N];   int res[N];   int d[N][N];   int g[N][N];   int f1[N][1 << 12];   void upd(int &x, int y) {     x += y;     if (x >= mod) {       x -= mod;     } else if (x < 0) {       x += mod;     }   }   void solve1() {     int nj, nk, last = (1 << c) - 1;     for (int i = 1; i <= n; i++) {       for (int j = (i - 1) / c; j >= 0; j--) {         for (int k = last - 1; k >= 0; k--) {           nj = j;           nk = k | (1 << a[i]);           if (nk == last) {             nj += 1;             nk = 0;             upd(d[i][nj], f1[j][k]);           }           upd(f1[nj][nk], f1[j][k]);         }       }       if (c == 1) {         upd(d[i][1], 1);         upd(f1[1][0], 1);       } else {         upd(f1[0][1 << a[i]], 1);       }     }   }   long long pw(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) {         res = res * x % mod;       }       x = x * x % mod;       n /= 2;     }     return res;   }   int t[N];   int inv[N];   void solve2() {     for (int i = 1; i < n; i++) {       inv[i] = pw(p[i] - 1, mod - 2);     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < c; j++) {         t[j] = 0;       }       int j = i - 1;       int sad = c;       while (j < n && sad) {         j += 1;         t[a[j]] += 1;         sad -= t[a[j]] == 1;       }       if (sad) {         break;       }       long long res = 1;       for (int h = 0; h < c; h++) {         res = res * (p[t[h]] - 1) % mod;       }       sad = 1;       for (; j <= n; j++) {         res = res * inv[t[a[j]]] % mod;         g[i][j] = res;         if (sad) {           sad = 0;         } else {           t[a[j]] += 1;         }         res = res * (p[t[a[j]]] - 1) % mod;       }     }     d[0][0] = 1;     int k = n / c;     d[0][0] = 1;     long long sum, MOD = mod, MOD2 = mod * mod;     for (int r = 1; r <= k; r++) {       d[0][r] = 0;       for (int i = r * c - 1; i < n; i++) {         sum = 0;         for (int j = i; j >= (r - 1) * c; j--) {           sum += 1LL * g[j + 1][i + 1] * d[j][r - 1];           if (sum >= MOD2) sum -= MOD2;         }         d[i + 1][r] = (sum % MOD);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> c;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i] -= 1;     }     p[0] = 1;     for (int i = 1; i <= n; i++) {       p[i] = p[i - 1];       upd(p[i], p[i]);     }     if (c <= 10) {       solve1();     } else {       solve2();     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         upd(res[j], 1ll * d[i][j] * p[n - i] % mod);       }     }     res[0] = p[n];     upd(res[0], -1);     for (int i = 0; i <= n; i++) {       upd(res[i], -res[i + 1]);       cout << res[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10;   const long long inf = 0x3f3f3f3f3f3f3f3f;   string s;   int a[maxn];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int flag = 0;       int n;       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       for (int i = 1; i < n; i++) {         if (a[i] - a[i - 1] == 1) {           flag = 1;           break;         }       }       if (flag)         cout << 2 << endl;       else         cout << 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int MOD = 1000000007;   void solve() {     int n;     cin >> n;     vector<vector<int>> dp(4, vector<int>(n + 1, 0));     dp[3][0] = 1;     for (int i = 1; i < n + 1; i++)       for (int j = 0; j < 4; j++)         for (int k = 0; k < 4; k++)           if (k != j) dp[j][i] = (dp[j][i] + dp[k][i - 1]) % MOD;     cout << dp[3][n] <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long l, r, n, k;   string Bad;   int ask(long long l, long long r) {     cout << l <<     << r << endl;     cout.flush();     cin >> Bad;     if (Bad[0] ==  B ) exit(0);     if (Bad[0] ==  Y ) {       if (l == r) exit(0);       return 1;     }     return 0;   }   int main() {     srand(2109888);     cin >> n >> k;     l = 1;     r = n;     while (l <= r) {       long long mid = (l + r) >> 1;       if (ask(l, mid))         r = mid;       else         l = mid + 1;       l = max(1ll, l - k);       r = min(n, r + k);       mid = l + rand() % (r - l + 1);       ask(mid, mid);       l = max(1ll, l - k);       r = min(n, r + k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nn = 100005;   const double eps = 1e-10;   struct point {     double x, y;   } a[nn], b[nn];   int n, m, t, l[nn], r[nn];   int h[nn], p[nn];   double R, c[nn];   inline double cp(const point &x, const point &y, const point &z) {     return (x.x - z.x) * (y.y - z.y) - (x.y - z.y) * (y.x - z.x);   }   inline double dis(const point &x, const point &y) {     return sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y));   }   inline bool cmp(const point &x, const point &y) {     double z = cp(x, y, a[1]);     if (z > eps) return 1;     if (z < -eps) return 0;     return dis(x, a[1]) < dis(y, a[1]);   }   void init() {     scanf( %d%lf , &n, &R);     for (int i = 1; i <= n; ++i) {       scanf( %lf%lf , &a[i].x, &a[i].y);       if (a[i].y < a[1].y || (a[i].y < a[1].y + eps && a[i].x < a[1].x))         swap(a[i], a[1]);     }     sort(a + 2, a + n + 1, cmp);     b[m = 1] = a[1];     for (int i = 2; i <= n; ++i) {       for (; m > 1 && cp(a[i], b[m], b[m - 1]) > -eps; --m)         ;       b[++m] = a[i];     }   }   inline void change(int x, int y) {     swap(p[h[x]], p[h[y]]);     swap(h[x], h[y]);   }   void up(int x) {     for (; x > 1 && c[h[x]] > c[h[x >> 1]]; x >>= 1) change(x, x >> 1);   }   void down(int x) {     for (int y = x << 1; y <= t; x = y, y = x << 1) {       if (y < t && c[h[y]] < c[h[y + 1]]) ++y;       if (c[h[x]] < c[h[y]])         change(x, y);       else         break;     }   }   inline void calc(int x) {     point y = b[l[x]], z = b[r[x]];     c[x] = dis(y, z) * dis(b[x], y) * dis(b[x], z) / (2 * abs(cp(y, z, b[x])));     up(p[x]);   }   inline double count(int x, int y) {     double z = 2 * asin(dis(b[x], b[y]) / (2 * R));     return R * R / 2 * (z - sin(z));   }   void work() {     for (int i = 1; i <= m; ++i) {       h[i] = p[i] = i;       l[i] = i - 1, r[i] = i + 1;     }     t = m;     l[1] = m;     r[m] = 1;     for (int i = 1; i <= m; ++i) calc(i);     while (c[h[1]] > R) {       int i = h[1];       l[r[i]] = l[i];       r[l[i]] = r[i];       change(1, t--);       down(1);       calc(l[i]);       calc(r[i]);     }     int j = h[1];     double s = count(j, l[j]) + count(j, r[j]);     for (int i = r[j]; r[i] != j; i = r[i])       s += abs(cp(b[i], b[r[i]], b[j])) / 2 + count(i, r[i]);     printf( %.10lf n , s);   }   int main() {     init();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int k;       cin >> k;       int days[14];       int ones = 0;       for (int i = 0; i < 7; i++) {         cin >> days[i];         if (days[i]) ones++;         days[i + 7] = days[i];       }       int ans = 0;       int left = 0;       if (k % ones == 0) {         ans = 7 * (k / ones - 1);         left = ones;       } else {         ans = 7 * (k / ones);         left = k % ones;       }       int c = 0, mini = INT_MAX;       for (int i = 0; i < 14; i++) {         if (!days[i]) continue;         int c = 0, c2 = 0;         for (int j = i; j < 14; j++) {           if (days[j] == 1) c++;           c2++;           if (c == left) {             mini = min(mini, c2);             break;           }         }       }       cout << mini + ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int c[10000007];   vector<pair<int, int> > x;   int temp;   vector<int> vt;   int main() {     scanf( %d %d %d , &m, &k, &n);     for (int i = 0; i < m; i++) {       scanf( %d , &temp);       c[temp]++;       if (c[temp] > n) {         printf( -1 n );         return 0;       }     }     for (int i = 0; i < k; i++) {       scanf( %d , &temp);       x.push_back(make_pair(temp, i));     }     sort(x.begin(), x.end());     int cur = 0;     int remain = 0;     for (int i = 0; i < k; i++) {       while (cur <= x[i].first) {         remain += n - c[cur];         cur++;       }       if (remain) {         remain--;         vt.push_back(x[i].second);       }     }     printf( %d n , vt.size());     for (int i = 0; i < vt.size(); i++) printf( %d  , vt[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[55][55];   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   int n, T, m;   inline int valid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   int cyc[55][55][4][2] = {};   int main(void) {     scanf( %d%d , &n, &T);     for (int i = 0; i < n; i++) scanf( %s , a[i]);     m = strlen(a[0]);     int x = 0, y = 0, DP = 0, CP = 0;     int Cx = -dy[DP] * (CP ? -1 : 1), Cy = dx[DP] * (CP ? -1 : 1);     int Dx = dx[DP], Dy = dy[DP];     for (int step = 1; step <= T; step++) {       while (valid(x + Dx, y + Dy) && a[x + Dx][y + Dy] == a[x][y])         x += Dx, y += Dy;       while (valid(x + Cx, y + Cy) && a[x + Cx][y + Cy] == a[x][y])         x += Cx, y += Cy;       if (cyc[x][y][DP][CP]) {         int ii = step - cyc[x][y][DP][CP];         while (step + ii <= T) step += ii;       } else         cyc[x][y][DP][CP] = step;       if (!valid(x + Dx, y + Dy) || a[x + Dx][y + Dy] ==  0 ) {         if (CP == 0)           CP = 1;         else if (CP == 1) {           DP = (DP + 1) % 4;           CP = 0;         }         Cx = -dy[DP] * (CP ? -1 : 1), Cy = dx[DP] * (CP ? -1 : 1);         Dx = dx[DP], Dy = dy[DP];       } else         x += Dx, y += Dy;     }     printf( %c n , a[x][y]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int f = 1, r = 0;     char ch = getchar();     while (!isdigit(ch)) f ^= ch ==  - , ch = getchar();     while (isdigit(ch)) r = (r << 1) + (r << 3) + (ch ^ 48), ch = getchar();     return f ? r : -r;   }   const int N = 3005, M = 305;   int n, m, cnt[N];   double f[M][N], g[N], d[N], sv[N], siv[N], val[N];   double ans, p[N][M];   inline void upd(int x) {     memcpy(g, f[x], sizeof(g));     f[x][0] = 0;     for (int i = 1; i <= n; i++)       f[x][i] = f[x][i - 1] * (1 - p[i][x]) + g[i - 1] * p[i][x];     cnt[x]++, sv[x] += f[x][n];     siv[x] += f[x][n] * cnt[x];     double E = siv[x] + cnt[x] * (1 - sv[x]);     d[x] = E - val[x], val[x] = E;   }   int main() {     n = read(), m = read();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) p[i][j] = read() / 1000.;     for (int i = 1; i <= m; i++) {       f[i][0] = 1;       for (int j = 1; j <= n; j++) f[i][j] = f[i][j - 1] * (1 - p[j][i]);       sv[i] = f[i][n], upd(i);     }     for (int i = 1; i <= n; i++) {       int k = 0;       for (int j = 1; j <= m; j++)         if (d[k] < d[j]) k = j;       if (!k) break;       ans += d[k], upd(k);     }     return printf( %.12lf n , ans), 0;   }


#include <bits/stdc++.h>   long long cacu(long long l, long long r) {     return (r + l) / 2 * ((r - l) / 2 + 1);   }   int main() {     int q, l, r;     scanf( %d , &q);     while (q--) {       long long ans;       scanf( %d%d , &l, &r);       ans = cacu(l + (l & 1), r - (r & 1));       ans -= cacu(l | 1, r - !(r & 1));       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   template <typename T>   void chmin(T &x, const T &y) {     if (x > y) x = y;   }   template <typename T>   void chmax(T &x, const T &y) {     if (x < y) x = y;   }   template <typename T>   T gcd(T x, T y) {     return y ? gcd(y, x % y) : x;   }   const int mod = 998244353;   template <typename T>   void Mod(T &x) {     while (x >= mod) x -= mod;   }   long long qk(long long x, long long y) {     long long r = 1;     for (; y; y >>= 1) {       if (y & 1) r = (r * x) % mod;       x = (x * x) % mod;     }     return r;   }   map<int, vector<int>> dps;   int cal(int a, int b, int c, int d) {     int x = d + b - a;     if (x < 0) return 0;     int k = d + c;     chmin(x, k);     if (dps.count(k)) return dps[k][x];     auto &dp = dps[k];     dp.resize(k + 1);     int t = 0, w = 1;     for (int i = 0; i <= k; ++i) {       Mod(t += w);       dp[i] = t;       w = (long long)w * (k - i) % mod;       w = (long long)w * qk(i + 1, mod - 2) % mod;     }     return dp[x];   }   void solve(int times) {     string s;     cin >> s;     int n = s.length();     int a = 0, b = 0, c = 0, d = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  ) )         ++b;       else if (s[i] ==  ? )         ++d;     }     long long ans = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  ( ) {         ++a;       } else if (s[i] ==  ? ) {         ++c;         --d;       } else if (s[i] ==  ) ) {         --b;       }       if (s[i] ==  ( ) {         Mod(ans += cal(a, b, c, d));       } else if (s[i] ==  ? ) {         ++a;         --c;         Mod(ans += cal(a, b, c, d));         ++c;         --a;       }     }     cout << ans << endl;   }   void Init() {}   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int times = 1;     {       solve(times++);       Init();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   const double EPS = 1e-10;   const double PI = acos(-1.0);   const int INF = 1 << 29;   const int mod = 1000000007;   const int MAX_V = 1000 + 10;   const int MAX_M = 10000 + 10;   const int maxm = 1 + 5;   const int maxn = 50000 + 5;   int used[20];   int n;   int main() {     scanf( %d , &n);     int i, j, sum = 0, a;     memset(used, 0, sizeof(used));     for (int i = 0; i < n; i++) {       scanf( %d , &a);       sum += a;       used[a]++;     }     if (used[0] == 0)       cout << -1 << endl;     else {       int flag = 0;       if (sum % 3 == 1) {         if (used[1] + used[4] + used[7]) {           for (int i = 1; i <= 7; i += 3) {             if (used[i]) {               used[i]--, sum -= i;               break;             }           }         } else if (used[2] + used[5] + used[8] >= 2) {           for (j = 1, i = 2; i <= 8; i += 3) {             while (used[i] && j <= 2) used[i]--, sum -= i, j++;           }         }       }       if (sum % 3 == 2) {         if (used[2] + used[5] + used[8]) {           for (i = 2; i <= 8; i += 3)             if (used[i]) {               used[i]--, sum -= i;               break;             }         } else if (used[1] + used[4] + used[7] >= 2) {           for (j = 1, i = 1; i <= 7; i += 3)             while (used[i] && j <= 2) used[i]--, sum -= i, j++;         } else           flag = 1;       }       if (!flag) {         if (used[1] + used[2] + used[3] + used[4] + used[5] + used[6] + used[7] +             used[8] + used[9]) {           for (i = 9; i >= 0; i--)             while (used[i]--) printf( %d , i);           printf(  n );         } else           printf( 0 n );       } else         printf( 0 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   list<int> adj[1000005];   int T[1000005];   bool visited[1000005];   bool uniq[1000005];   int rev[10000005];   void dfs(int v) {     visited[v] = true;     for (list<int>::iterator it = adj[v].begin(); it != adj[v].end(); it++) {       if (!visited[*it]) dfs(*it);     }   }   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     scanf( %d , &N);     for (int i = 0; i < (N); i++) scanf( %d , &T[i]);     sort(T, T + N);     T[N] = -1;     for (int i = 0; i < (10000001); i++) rev[i] = N;     for (int i = 0; i < (N); i++) rev[T[i]] = i;     int temp[3];     int v[3];     for (int i = 1; i <= 5000; i += 2)       for (int j = 2; i * i + j * j <= T[N - 1]; j += 2) {         if (gcd(i, j) > 1) continue;         temp[0] = abs(i * i - j * j);         temp[1] = i * i + j * j;         temp[2] = 2 * i * j;         for (int t = 0; t < (3); t++) v[t] = rev[temp[t]];         for (int u = 0; u < (3); u++)           for (int s = 0; s < (u); s++) {             if ((T[v[u]] == temp[u]) && (T[v[s]] == temp[s])) {               adj[v[u]].push_back(v[s]);               adj[v[s]].push_back(v[u]);             }           }       }     for (int i = 1; i <= T[N - 1]; i += 2)       for (int j = 2; i * j <= T[N - 1]; j += 2) {         if (gcd(i, j) > 1) continue;         long long int L1 = abs(i * (long long int)i - j * (long long int)j);         long long int L2 = 2 * i * j;         if (L1 > 10000000 || L2 > 10000000) continue;         int v1 = rev[L1];         int v2 = rev[L2];         if ((T[v1] == L1) && (T[v2] == L2)) {           adj[v1].push_back(v2);           adj[v2].push_back(v1);         }       }     for (int i = 0; i < (N); i++) visited[i] = false;     int result = 0;     for (int i = 0; i < (N); i++)       if (!visited[i]) {         result++;         dfs(i);       }     printf( %d n , result);   }


#include <bits/stdc++.h>   using namespace std;   int n;   void solve() {     if (n <= 3)       printf( NO n );     else if (n == 4) {       printf( YES n );       printf( 2 * 3 = 6 n );       printf( 6 * 4 = 24 n );       printf( 24 * 1 = 24 n );     } else if (n == 5) {       printf( YES n );       printf( 1 + 5 = 6 n );       printf( 3 - 2 = 1 n );       printf( 6 * 1 = 6 n );       printf( 6 * 4 = 24 n );     } else if (n >= 6) {       printf( YES n );       printf( 3 - 2 = 1 n );       printf( 1 - 1 = 0 n );       printf( 4 * 6 = 24 n );       printf( 5 * 0 = 0 n );       int i = 7;       while (i <= n) {         printf( %d * 0 = 0 n , i);         i++;       }       printf( 24 + 0 = 24 n );     } else       printf( NO n );   }   int main() {     while (scanf( %d , &n) != EOF) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = LONG_LONG_MAX;   const long long NINF = LONG_LONG_MIN;   const long long mmod = 1000000007;   int32_t main() {     long long k;     cin >> k;     while (k-- > 0) {       long long n;       cin >> n;       string s, t;       cin >> s >> t;       vector<long long> cnt(26, 0);       for (long long i = 0; i < n; i++) {         cnt[s[i] -  a ]++;         cnt[t[i] -  a ]++;       }       bool found = true;       for (long long i = 0; i < 26; i++)         if (cnt[i] & 1) found = false;       if (found) {         vector<pair<long long, long long>> ans;         for (long long i = 0; i < n - 1; i++) {           if (s[i] != t[i]) {             bool f = false;             for (long long j = i + 1; j < n; j++) {               if (t[j] == t[i]) {                 swap(s[i], t[j]);                 f = true;                 ans.emplace_back(i + 1, j + 1);                 break;               }             }             if (!f) {               for (long long j = i + 1; j < n; j++) {                 if (s[j] == t[i]) {                   swap(s[j], t[j]);                   swap(s[i], t[j]);                   ans.emplace_back(j + 1, j + 1);                   ans.emplace_back(i + 1, j + 1);                   break;                 }               }             }           }         }         cout <<  YES  << endl;         cout << (long long)ans.size() << endl;         for (pair<long long, long long> x : ans)           cout << x.first <<     << x.second << endl;       } else {         cout <<  No  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long p, k;   vector<int> v;   int main() {     cin >> p >> k;     v.push_back(p % k);     long long a0 = -p / k;     while (1) {       long long a1 = -a0 / k;       while (a1 * k + a0 < 0) a1++;       while (a1 * k + a0 >= k) a1--;       if (a1 < k && a1 >= 0) {         v.push_back(a0 + k * a1);         v.push_back(a1);         break;       }       v.push_back(a0 + k * a1);       a0 = a1;     }     while (v.back() == 0) v.pop_back();     printf( %d n , v.size());     for (int i = 0; i < v.size(); ++i) printf( %d  , v[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long a[200010];   long long vis[200010];   long long cnt[200010];   long long n;   long long max_n = 0;   void solve(long long pos) {     vis[pos]++;     long long temp1 = pos;     long long temp2 = pos;     long long step1 = 0;     long long step2 = 0;     while (temp1 <= max_n) {       temp1 <<= 1;       step1++;       vis[temp1]++;       cnt[temp1] += step1;     }     while (temp2) {       if ((temp2 & 1) && (temp2 != 1)) {         temp2 >>= 1;         step2++;         vis[temp2]++;         cnt[temp2] += step2;         long long temp3 = temp2;         long long step3 = step2;         while (temp3 <= max_n) {           temp3 <<= 1;           step3++;           vis[temp3]++;           cnt[temp3] += step3;         }       } else {         temp2 >>= 1;         step2++;         vis[temp2]++;         cnt[temp2] += step2;       }     }   }   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       max_n = max(a[i], max_n);     }     memset(vis, 0, sizeof(vis));     memset(cnt, 0, sizeof(cnt));     for (long long i = 1; i <= n; i++) solve(a[i]);     long long ans = 1 << 29;     for (long long i = 1; i <= 2 * max_n - 1; i++) {       if (vis[i] == n) ans = min(ans, cnt[i]);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   int read() {     int x = 0, y = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) y = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     return x * y;   }   void print(int x) {     if (x < 0) {       putchar( 0 );       return;     }     if (x < 10) {       putchar(x +  0 );       return;     }     print(x / 10);     putchar(x % 10 +  0 );   }   int n, x, maxx;   int main() {     n = read();     for (int _ = 0; _ < n; _++) x = read(), maxx = maxx > x ? maxx : x;     print(maxx - 25);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int x, y, tx, ty, vis[N];   int chk(int x, int y) {     for (int i = 0; i < 7; i++) vis[i] = 0;     for (int i = 1; i <= tx; i++) ++vis[x % 7], x /= 7;     for (int i = 1; i <= ty; i++) ++vis[y % 7], y /= 7;     for (int i = 0; i < 7; i++)       if (vis[i] > 1) return 0;     return 1;   }   int main() {     scanf( %d%d , &x, &y), --x, --y;     if ((long long)x * y > 6543210) return puts( 0 ), 0;     for (int i = x; i; i /= 7) ++tx;     for (int i = y; i; i /= 7) ++ty;     tx = max(tx, 1), ty = max(ty, 1);     int ans = 0;     for (int i = 0; i <= x; i++)       for (int j = 0; j <= y; j++) ans += chk(i, j);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 207;   const int M = 1507;   const int inf = INT_MAX;   int nx[M], to[M], head[N], cap[M], fl[M], who[N][N], vis[N], es = 2;   int a[N], b[N];   int n, m, s, t, turn = 1;   int dfs(int u, int mini) {     vis[u] = turn;     if (u == t) return mini;     for (int e = head[u]; e; e = nx[e]) {       int v = to[e];       if (vis[v] != turn && cap[e] - fl[e]) {         int k = dfs(v, min(mini, cap[e] - fl[e]));         if (k != inf) {           fl[e] += k;           fl[e ^ 1] -= k;           return k;         }       }     }     return inf;   }   int maxflow() {     int mf = 0, k;     while ((k = dfs(s, inf)) != inf) {       turn++;       mf += k;     }     return mf;   }   int addedge(int u, int v, int _cap) {     who[u][v] = es;     to[es] = v;     nx[es] = head[u];     head[u] = es;     cap[es] = _cap;     fl[es++] = 0;     to[es] = u;     nx[es] = head[v];     head[v] = es;     cap[es] = 0;     fl[es++] = 0;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , a + i);     for (int i = 0; i < n; i++) scanf( %d , b + i);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--;       v--;       addedge(u, v + n, inf);       addedge(v, u + n, inf);     }     s = 2 * n;     t = 2 * n + 1;     int sa = 0, sb = 0;     for (int i = 0; i < n; i++) {       sa += a[i];       sb += b[i];       addedge(i, i + n, inf);       addedge(s, i, a[i]);       addedge(i + n, t, b[i]);     }     int res = maxflow();     if (res == sa && res == sb) {       printf( YES n );       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++)           printf( %d%c , fl[who[i][j + n]],    n [j == n - 1]);     } else       puts( NO );   }


#include <bits/stdc++.h>   int main() {     int n, t, pos = 0;     std::cin >> n >> t;     std::vector<std::pair<int, int> > vec;     for (int i = 0; i < n; i++) {       int x, y;       std::cin >> x >> y;       vec.push_back(std::make_pair(x, y));     }     std::sort(vec.begin(), vec.end());     for (int i = 0; i < n - 1; i++) {       int temp = 2 * vec[i + 1].first - 2 * vec[i].first - vec[i + 1].second -                  vec[i].second;       if (temp >= 2 * t) {         pos++;       }       if (temp > 2 * t) {         pos++;       }     }     std::cout << pos + 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long MOD = 1e8 + 7;   const unsigned long long base = 71;   const unsigned long long max_n = 2e5 + 400;   unsigned long long n, m, k, q;   string s;   unsigned long long pw[2 * max_n + 200];   unsigned long long save[20][2 * max_n + 200];   unsigned long long seg[10 * max_n], lazy[10 * max_n];   void init(unsigned long long v, unsigned long long b, unsigned long long e) {     lazy[v] = -1;     if (b == e) {       seg[v] = s[b];       return;     }     unsigned long long mid = (b + e) / 2;     init(v << 1, b, mid);     init(v << 1 ^ 1, mid + 1, e);     seg[v] = (seg[v << 1] * pw[e - mid] + seg[v << 1 ^ 1]) % MOD;   }   void shift(unsigned long long v, unsigned long long b, unsigned long long e,              unsigned long long mid) {     if (lazy[v] == -1) return;     lazy[v << 1] = lazy[v << 1 ^ 1] = lazy[v];     seg[v << 1] = save[lazy[v]][mid - b];     seg[v << 1 ^ 1] = save[lazy[v]][e - mid - 1];     lazy[v] = -1;   }   void update(unsigned long long v, unsigned long long b, unsigned long long e,               unsigned long long l, unsigned long long r,               unsigned long long val) {     if (b > r || l > e) return;     if (l <= b && e <= r) {       seg[v] = save[val][e - b];       lazy[v] = val;       return;     }     unsigned long long mid = (b + e) / 2;     shift(v, b, e, mid);     update(v << 1, b, mid, l, r, val);     update(v << 1 ^ 1, mid + 1, e, l, r, val);     seg[v] = (seg[v << 1] * pw[e - mid] + seg[v << 1 ^ 1]) % MOD;   }   unsigned long long get(unsigned long long v, unsigned long long b,                          unsigned long long e, unsigned long long l,                          unsigned long long r) {     if (b > r || l > e) return 0;     if (l <= b && e <= r) return seg[v];     unsigned long long mid = (b + e) / 2;     shift(v, b, e, mid);     unsigned long long first = get(v << 1, b, mid, l, r);     unsigned long long second = get(v << 1 ^ 1, mid + 1, e, l, r);     first = (first * pw[max(0, int(min(r, e) - mid))] + second) % MOD;     return first;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     cin >> n >> m >> k;     q = m + k;     cin >> s;     pw[0] = 1;     for (unsigned long long i = 1; i < max_n; i++)       pw[i] = (pw[i - 1] * base) % MOD;     for (unsigned long long i = 0; i < 10; i++) {       save[i][0] = i + 48;       for (unsigned long long j = 1; j < max_n; j++)         save[i][j] = (save[i][j - 1] * base + (i + 48)) % MOD;     }     init(1, 0, n - 1);     while (q--) {       unsigned long long type, l, r;       cin >> type >> l >> r;       l--, r--;       if (type == 1) {         unsigned long long c;         cin >> c;         update(1, 0, n - 1, l, r, c);         continue;       }       bool fl = 0;       unsigned long long d;       cin >> d;       if (d == r - l + 1) fl = 1;       if (!fl) fl = get(1, 0, n - 1, l, r - d) == get(1, 0, n - 1, l + d, r);       if (fl)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2E5 + 77;   void putint(int x) {     static bool first = true;     if (first) {       printf( %d , x);       first = false;     } else       printf(  %d , x);   }   struct QUERY {     int t, r;   } Q[maxn];   int cnt = 0;   int N, M, A[maxn], B[maxn], pb = 0;   int main() {     scanf( %d%d , &N, &M);     for (int i = 0; i < N; ++i) scanf( %d , A + i);     for (int i = 0; i < M; ++i) {       int t, r;       scanf( %d%d , &t, &r);       while (cnt && r >= Q[cnt - 1].r) --cnt;       if (!cnt || t != Q[cnt - 1].t) Q[cnt++] = (QUERY){t, r};     }     Q[cnt] = (QUERY){0, 0};     sort(A, A + Q[0].r);     int ptr[2] = {0, Q[0].r - 1}, d = Q[0].t == 1;     for (int i = 0; i < cnt; ++i) {       for (int j = Q[i].r; j > Q[i + 1].r; --j) {         B[pb++] = A[ptr[d]];         ptr[d] += d ? -1 : 1;       }       d ^= 1;     }     for (int i = Q[0].r - 1; i >= 0; --i) putint(B[i]);     for (int i = Q[0].r; i < N; ++i) putint(A[i]);     printf(  n );   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:136777216 )   using namespace std;   int bits(int x) { return x == 0 ? 0 : 1 + bits(x & (x - 1)); }   const double PI = acos(-1.0);   const double eps = 1e-9;   const int INF = 1000000000;   string nextString() {     char buf[1000000];     scanf( %s , buf);     return buf;   }   int dx[] = {0, 1, 0, -1};   int dy[] = {1, 0, -1, 0};   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   string month[] = { January ,    February ,  March ,     April ,                      May ,        June ,      July ,      August ,                      September ,  October ,   November ,  December };   int main() {     string s = nextString();     int start;     for (int(i) = 0; (i) < (12); (i)++)       if (s == month[i]) start = i;     int n;     scanf( %d , &n);     int end = (n + start) % 12;     printf( %s n , month[end].c_str());     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int mod = (int)1e9 + 7;   const long long INF = 1000000000000000000LL;   const int WASTE = (int)2e5;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int x, y, p, q;       cin >> x >> y >> p >> q;       if (!p) {         cout << (x == 0 ? 0 : -1) <<   n ;         continue;       }       if (p == q) {         if (x == y)           cout << 0 <<   n ;         else           cout << -1 <<   n ;         continue;       }       int i = (x + p - 1) / p;       int i1 = (y - x - p + q - 1) / (q - p);       cout << (q * 1LL * max(i, i1) - y) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     for (int i = 0; i < T; i++) {       long long int n, x;       cin >> n >> x;       cout << 2 * x << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3;   int n, x[N], d[N], i, j;   int main() {     cin >> n;     for (i = 0; i < n; i++) cin >> x[i] >> d[i];     for (i = 0; i < n; i++)       for (j = i + 1; j < n; j++)         if (x[i] + d[i] == x[j] && x[j] + d[j] == x[i]) return cout <<  YES , 0;     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 205;   int n;   char s[N];   bool ck(int l, int r) {     int a = 0, b = 0, c = 0, d = 0;     for (int i = l; i <= r; i++) {       if (s[i] ==  U )         a++;       else if (s[i] ==  D )         b++;       else if (s[i] ==  L )         c++;       else         d++;     }     if (a == b && c == d)       return 1;     else       return 0;   }   int main() {     scanf( %d , &n);     scanf( %s , s);     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = i; j < n; j++) ans += ck(i, j);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x;     cin >> x;     string ans, in, dec, exp;     int flag = 0;     for (int i = 0; i < x.length(); i++) {       if (x[i] ==  . )         flag = 1;       else if (x[i] ==  e )         flag = 2;       else if (flag == 0)         in += x[i];       else if (flag == 1)         dec += x[i];       else if (flag == 2)         exp += x[i];     }     int e = stoi(exp);     ans += in;     if (e <= dec.length()) {       ans += dec.substr(0, e);       if (e < dec.length()) {         ans +=  . ;         ans += dec.substr(e, dec.length());       }     } else {       ans += dec;       ans += string(e - dec.length(),  0 );     }     flag = 0;     if (dec.length() < 2 && stoi(dec) == 0 && e == 0) ans = in;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int limN = 2e5 + 5;   char s[limN];   char arr[2000];   int bu[400];   int main() {     int t;     scanf( %d , &t);     for (int i = 0; i < t; i++) {       scanf( %s , s);       for (int j = 0; j < 2000; j++) arr[j] =  . ;       for (int j = 0; j < 400; j++) bu[j] = 0;       int n = strlen(s);       int ini = 500;       int fin = 500;       bool f = true;       arr[ini] = s[0];       bu[s[0]]++;       int pos = ini;       for (int j = 1; j < n; j++) {         if (j == 1) {           fin++;           arr[fin] = s[j];           bu[s[j]]++;           pos = fin;           continue;         }         if (arr[pos - 1] == s[j]) {           pos--;           continue;         }         if (arr[pos + 1] == s[j]) {           pos++;           continue;         }         if (bu[s[j]] > 0) {           f = false;           break;         } else {           if (pos == ini) {             ini--;             arr[ini] = s[j];             bu[s[j]]++;             pos--;           } else if (pos == fin) {             fin++;             arr[fin] = s[j];             bu[s[j]]++;             pos++;           } else {             f = false;             break;           }         }       }       if (!f) {         printf( NO n );       } else {         printf( YES n );         for (int j = ini; j <= fin; j++) {           printf( %c , arr[j]);         }         for (int j =  a ; j <=  z ; j++) {           if (bu[j] == 0) {             printf( %c , j);           }         }         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxv = 110;   int n, m;   int val[Maxv][Maxv * Maxv];   int org[Maxv][Maxv];   int dp[Maxv][Maxv * Maxv];   int Len[Maxv];   int main() {     int i, j, k;     cin >> n >> m;     for (i = 1; i <= n; i++) {       scanf( %d , &Len[i]);       for (j = 1; j <= Len[i]; j++) scanf( %d , &org[i][j]);       int sum1 = 0;       for (j = 0; j <= Len[i]; j++) {         int sum2 = 0;         sum1 += org[i][j];         for (k = Len[i] + 1; k > j; k--) {           sum2 += org[i][k];           int tcost = j + Len[i] + 1 - k;           val[i][tcost] = max(sum1 + sum2, val[i][tcost]);         }       }       for (k = m; k >= 1; k--) {         for (j = 0; j <= Len[i] && j <= k; j++) {           dp[i][k] = max(dp[i][k], dp[i - 1][k - j] + val[i][j]);         }       }     }     printf( %d n , dp[n][m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, x, a[100005], ct[100005];   int main() {     cin >> n >> x;     for (long long int i = 1; i <= n; ++i) cin >> a[i], ct[a[i]]++;     sort(a + 1, a + n + 1);     long long int ans = 0;     for (long long int i = 1; i <= n; ++i) {       long long int ch = x ^ a[i];       if (ch == a[i]) {         ans += (ct[ch] - 1);       } else if (ch <= 100000)         ans += ct[ch];     }     cout << ans / 2;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     long long a, b;     cin >> a >> b;     if (a < b)       puts( -1 );     else       printf( %.12f n , (a + b) / (2. * ((a + b) / (2 * b))));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Mod = (int)1e9 + 7;   const int MX = 1073741822;   const long long MXLL = 4e18;   const int Sz = 1110111;   inline void Read_rap() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   inline void randomizer3000() {     unsigned int seed;     asm( rdtsc  :  =A (seed));     srand(seed);   }   void files(string problem) {     if (fopen((problem +  .in ).c_str(),  r )) {       freopen((problem +  .in ).c_str(),  r , stdin);       freopen((problem +  .out ).c_str(),  w , stdout);     }   }   void localInput(const char in[] =  s ) {     if (fopen(in,  r )) {       freopen(in,  r , stdin);     } else       cerr <<  Warning: Input file not found  << endl;   }   int n;   const int N = 302;   int pref[N][N];   int dp[N][N];   int a[N];   int plen[N], len[N];   int main() {     Read_rap();     cin >> n;     for (int i = 1; i <= n; i++) {       static string s;       cin >> s;       static map<string, int> id;       if (!id.count(s)) id[s] = (int)(id.size());       a[i] = id[s];       len[i] = (int)(s.size());     }     for (int i = n; i >= 1; i--)       for (int j = n; j >= 1; j--)         if (a[i] == a[j]) pref[i][j] = pref[i + 1][j + 1] + 1;     for (int i = 1; i <= n; i++) plen[i] = plen[i - 1] + len[i];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= i; j++) {         int len = i - j + 1;         for (int p = len; p < j; p++) {           int q = p - len + 1;           if (pref[j][q] >= len) dp[i][j] = max(dp[i][j], dp[p][q] + 1);         }       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= i; j++) {         int len = i - j + 1;         if (dp[i][j]) {           int cost = len - 1 + plen[i] - plen[j - 1] - len;           ans = max(ans, cost * (dp[i][j] + 1));         }       }     }     int sum = accumulate(len + 1, len + n + 1, 0) + n - 1;     cout << sum - ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long ask(long long a, long long b, long long c, long long d) {     long long res;     cout <<  ?   << a <<     << b <<     << c <<     << d << endl;     cout.flush();     cin >> res;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     long long x1 = -1;     long long x2 = -1;     long long y1 = -1;     long long y2 = -1;     for (int i = 1; i < n; i++) {       if (ask(i, 1, i, n) % 2 == 1) {         if (x1 == -1)           x1 = i;         else {           x2 = i;           break;         }       }     }     if (x1 == -1) {       for (int i = 1; i < n; i++) {         if (ask(1, i, n, i) % 2 == 1) {           if (y1 == -1)             y1 = i;           else {             y2 = i;             break;           }         }       }       if (y2 == -1) y2 = n;       long long low = 1;       long long high = n;       x1 = n;       while (low <= high) {         long long mid = (low + high) / 2;         if (ask(low, y1, mid, y1) % 2 == 1) {           high = mid - 1;           x1 = min(x1, mid);         } else {           low = mid + 1;         }       }       x2 = x1;     } else {       if (x2 == -1) x2 = n;       long long low = 1;       long long high = n;       y1 = n;       while (low <= high) {         long long mid = (low + high) / 2;         if (ask(x1, low, x1, mid) % 2 == 1) {           y1 = min(y1, mid);           high = mid - 1;         } else {           low = mid + 1;         }       }       low = 1;       high = n;       y2 = n;       while (low <= high) {         long long mid = (low + high) / 2;         if (ask(x2, low, x2, mid) % 2 == 1) {           y2 = min(y2, mid);           high = mid - 1;         } else {           low = mid + 1;         }       }     }     cout <<  !   << x1 <<     << y1 <<     << x2 <<     << y2 << endl;     cout.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[111111];   int y[111111];   int main() {     int i, n, m, t;     long long xx = 0, yy = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &t);       x[t] = i;       y[t] = n - i + 1;     }     scanf( %d , &m);     for (i = 1; i <= m; i++) {       scanf( %d , &t);       xx += x[t];       yy += y[t];     }     cout << xx <<     << yy << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T t) {     return t < 0 ? -t : t;   }   const unsigned long long modn = 1000000007;   inline unsigned long long mod(unsigned long long x) { return x % modn; }   const int MAX = 100009;   int deg[MAX], ok[MAX];   vector<int> adj[MAX];   void dfs(int u, int p) {     if (deg[u] > 3) return;     ok[u]++;     if (deg[u] == 3) return;     for (int v : adj[u])       if (v != p) dfs(v, u);   }   int main() {     int i, n, a, b;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) {       scanf( %d %d , &a, &b);       adj[--a].push_back(--b);       adj[b].push_back(a);       deg[a]++;       deg[b]++;     }     for (i = 0; i < n; i++)       if (deg[i] == 1) dfs(i, -1);     for (i = 0; i < n; i++)       if (deg[i] == 3 && ok[i] <= 1) ok[i] = 0;     for (i = 0; i < n; i++) {       if (ok[i]) continue;       int ct = 0;       for (int v : adj[i])         if (!ok[v]) ct++;       if (ct > 2) break;     }     if (i < n)       puts( No );     else       puts( Yes );   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   int n;   pair<long long, long long> a[maxn + 1];   pair<long long, long long> b;   priority_queue<long long, vector<long long>, greater<long long> > q;   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     return a > b;   }   int main() {     int ans;     scanf( %d n , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &a[i - 1].first, &a[i - 1].second);     }     b = a[0];     sort(a + 1, a + n, cmp);     int i = 1;     for (; i <= n && a[i].first > b.first; i++)       q.push(a[i].second - a[i].first + 1);     ans = i;     int lans = 0;     while (!q.empty()) {       long long k = q.top();       q.pop();       if (k > b.first) break;       b.first -= k;       lans++;       for (; i <= n && a[i].first > b.first; i++)         q.push(a[i].second - a[i].first + 1);       ans = min(ans, i - lans);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int acc[1002], s[1002];   int main() {     int n, t;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t;       s[t]++;     }     for (int i = 1; i < 1002; i++) {       acc[i] = acc[i - 1] + s[i];     }     int d;     cin >> d;     int total = 0;     for (int i = d + 1; i < 1002; i++) {       if (acc[i] - acc[i - d - 1] > total) total = acc[i] - acc[i - d - 1];     }     cout << total << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     std::map<long, long> map;     long q, id, leftMAX = 0, rightMAX = 0, firstTime = 0;     char c;     std::cin >> q;     while (q--) {       std::cin >> c >> id;       if (!firstTime--) {         map.insert(std::pair<long, long>(id, 0));       } else {         if (c ==  ? )           std::cout << std::min(map[id] - leftMAX, rightMAX - map[id])                     << std::endl;         else if (c ==  R )           map.insert(std::pair<long, long>(id, ++rightMAX));         else           map.insert(std::pair<long, long>(id, --leftMAX));       }     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   vector<int> up, down;   int main() {     int T, n;     char ch;     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       up.clear();       down.clear();       for (int i = 1; i < n; i += 2) {         printf( ? %d %d n , i, i + 1);         fflush(stdout);         cin >> ch;         if (ch ==  < )           down.push_back(i), up.push_back(i + 1);         else           down.push_back(i + 1), up.push_back(i);       }       if (n & 1) down.push_back(n), up.push_back(n);       int Min = down[0], Max = up[0];       for (int i = 1; i < down.size(); i++) {         printf( ? %d %d n , Min, down[i]);         fflush(stdout);         cin >> ch;         if (ch ==  > ) Min = down[i];       }       for (int i = 1; i < up.size(); i++) {         printf( ? %d %d n , Max, up[i]);         fflush(stdout);         cin >> ch;         if (ch ==  < ) Max = up[i];       }       printf( ! %d %d n , Min, Max);       fflush(stdout);     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long a, long b) { return ((a * b) / gcd(a, b)); }   long long a[100000];   int main() {     long long i, j, k, l, m, n, maxx = 0, g = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (i = 0; i < n; i++) {       while (a[i] % 2 == 0) {         a[i] /= 2;       }       while (a[i] % 3 == 0) {         a[i] /= 3;       }     }     sort(a, a + n);     if (a[0] == a[n - 1])       cout <<  Yes  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     long long a, b, c;     cin >> a >> b >> c;     if (a > b) swap(a, b);     cout << a + min(c, a + b) + min(b, a + c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read(long long &x) { scanf( %lld , &x); }   void read(long long &x, long long &y) { scanf( %lld%lld , &x, &y); }   void read(long long &x, long long &y, long long &z) {     scanf( %lld%lld%lld , &x, &y, &z);   }   void print(long long x) { printf( %lld  , x); }   void println(long long x) { printf( %lld n , x); }   const long long N = 300100;   long long q, n, a[N], ans, b[N], sz;   int main() {     cin >> q;     for (; q--;) {       read(n);       for (long long i = 1; i <= n; i++) read(a[i]);       sort(a + 1, a + n + 1);       sz = 0;       for (long long i = 1; i <= n; i++)         if (i == 1 || a[i] != a[i - 1]) b[++sz] = a[i];       reverse(b + 1, b + sz + 1);       for (long long i = 1; i <= sz; i++) a[i] = b[i];       n = sz;       ans = a[1];       for (long long i = 1; i <= min(59LL, n); i++)         for (long long j = i + 1; j <= (i + 59LL, n); j++)           if (a[i] % a[j] != 0) ans = max(ans, a[i] + a[j]), j = n;       for (long long i = 1; i <= min(59LL, n); i++) {         if (i + 2 <= n && a[i] + a[i + 1] + a[i + 2] <= ans) break;         for (long long j = i + 1; j <= (i + 59LL, n); j++)           if (a[i] % a[j] != 0) {             if (j < n && a[i] + a[j] + a[j + 1] <= ans) break;             for (long long k = j + 1; k <= min(j + 59LL, n); k++)               if (a[i] % a[k] != 0 && a[j] % a[k] != 0)                 ans = max(ans, a[i] + a[j] + a[k]), k = n;           }       }       println(ans);     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v);   template <typename A, typename B>   ostream &operator<<(ostream &cout, pair<A, B> const &p) {     return cout <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v) {     cout <<  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) cout <<  ,  ;       cout << v[i];     }     return cout <<  ] ;   }   template <typename A, typename B>   istream &operator>>(istream &cin, pair<A, B> &p) {     cin >> p.first;     return cin >> p.second;   }   mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());   void usaco(string filename) {     freopen((filename +  .in ).c_str(),  r , stdin);     freopen((filename +  .out ).c_str(),  w , stdout);   }   const long double pi = 3.14159265358979323846;   long long n, m, q, k, l, r, x, y, z;   const long long template_array_size = 1e6 + 16318;   long long a[template_array_size];   long long b[template_array_size];   long long c[template_array_size];   string second, t;   long long ans = 0;   string op[5005];   string val[5005];   pair<long long, long long> dep[5005];   map<string, long long> rev;   long long dp[5005];   long long check(long long x, long long p, long long t) {     if (x == -1) return t;     if (dp[x] != -1) return dp[x];     if (op[x] ==  = )       return dp[x] = val[x][p] -  0 ;     else if (op[x] ==  OR )       return dp[x] = check(dep[x].first, p, t) | check(dep[x].second, p, t);     else if (op[x] ==  AND )       return dp[x] = check(dep[x].first, p, t) & check(dep[x].second, p, t);     else       return dp[x] = check(dep[x].first, p, t) ^ check(dep[x].second, p, t);   }   void solve(int tc = 0) {     cin >> n >> m;     string v;     getline(cin, v);     rev[ ? ] = -1;     for (long long i = 0; i < n; i++) {       vector<string> x;       getline(cin, v);       istringstream is(v);       while (is >> v) {         x.push_back(v);       }       rev[x[0]] = i;       if (x.size() == 3) {         op[i] =  = ;         val[i] = x[2];       } else {         op[i] = x[3];         dep[i] = {rev[x[2]], rev[x[4]]};       }     }     string rmin =   , rmax =   ;     for (long long i = 0; i < m; i++) {       long long c0 = 0, c1 = 0;       memset(dp, -1, sizeof(dp));       for (long long j = 0; j < n; j++) {         c0 += check(j, i, 0);       }       memset(dp, -1, sizeof(dp));       for (long long j = 0; j < n; j++) {         c1 += check(j, i, 1);       }       if (c0 == c1) {         rmin +=  0 ;         rmax +=  0 ;       } else if (c0 < c1) {         rmin +=  0 ;         rmax +=  1 ;       } else {         rmin +=  1 ;         rmax +=  0 ;       }     }     cout << rmin <<   n  << rmax <<   n ;   }   int main() {     { ios_base::sync_with_stdio(false); }     { cin.tie(NULL); }     cout << setprecision(15) << fixed;     int tc = 1;     for (int t = 0; t < tc; t++) solve(t);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, pos, n, cnt, sz, dummy;     vector<int> ans;     long long k, tot = 0, examine[100005], temp;     scanf( %d %I64d , &n, &k);     for (i = 0; i < n; ++i) {       scanf( %I64d , &examine[i]);       tot += examine[i];     }     if (tot < k)       printf( -1 n );     else if (tot == k)       printf(  n );     else {       dummy = n;       while (k > (long long)n) {         temp = k / (long long)n;         k = k % (long long)n;         cnt = 0;         for (i = 0; i < dummy; ++i) {           if (examine[i] != 0) {             if ((long long)examine[i] <= temp) {               k += (long long)(temp - (long long)examine[i]);               examine[i] = 0;               ++cnt;             } else               examine[i] -= temp;           }         }         n -= cnt;       }       pos = 0;       if (k != 0) {         while (k != 0) {           if (examine[pos] > 0) {             --examine[pos];             --k;           }           ++pos;         }       }       for (i = pos; i < dummy; ++i)         if (examine[i] > 0) ans.push_back(i + 1);       for (i = 0; i < pos; ++i)         if (examine[i] > 0) ans.push_back(i + 1);       sz = ans.size();       for (i = 0; i < (sz - 1); ++i) printf( %d  , ans[i]);       printf( %d n , ans[sz - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     string s;     cin >> s;     long long l = s.length();     bool visit[256];     memset(visit, false, sizeof(visit));     int dis = 0, i;     for (i = 0; i < l; i++) {       if (!visit[s[i]]) {         visit[s[i]] = true;         dis++;       }     }     if (dis == 1) {       cout << ((l * (l + 1)) / 2) % 998244353;       return 0;     }     int s_cnt = 1, e_cnt = 1;     i = 1;     int j = l - 2;     for (; i < l; i++) {       if (s[i] == s[0])         s_cnt++;       else         break;     }     for (; j >= 0; j--) {       if (s[j] == s[n - 1])         e_cnt++;       else         break;     }     if (s[0] != s[l - 1]) {       cout << (e_cnt + s_cnt + 1) % 998244353;     } else {       cout << (long long)((long long)(s_cnt + 1) % 998244353 *                           (long long)(e_cnt + 1) % 998244353) %                   998244353;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int Nmax = 100005;   int count_one(vector<int> s) {     int ct = 0;     int i = 0;     while (i < s.size()) {       if (s[i] == 1) ++ct;       ++i;     }     return ct;   }   int count_zero(string s, int index) {     int i = 0;     int ct = 0;     while (s[i] !=  1  && i < s.length()) {       ++ct;       ++i;     }   }   int gcd(int a, int b) {     if (a == 0) {       return b;     }     return gcd(b % a, a);   }   bool isPrime(int n) {     for (int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return 0;     return 1;   }   void binaryRepresentation(int x) {     for (int i = 31; i >= 0; i--) {       if (x & (1 << i))         cout <<  1 ;       else         cout <<  0 ;     }   }   void DFS(vector<vector<int> > &adj, int u, vector<bool> &visit,            vector<int> &dist, vector<int> &freq) {     visit[u] = true;     for (int i = 0; i < adj[u].size(); i++) {       int x = adj[u][i];       if (!visit[x]) {         dist[x] = dist[u] + 1;         freq[u]++;         DFS(adj, adj[u][i], visit, dist, freq);       }     }   }   bool check(string a, string b) {     vector<int> first(26, 0);     vector<int> second(26, 0);     for (int i = 0; i < a.length(); i++) {       first[a[i] -  a ]++;       second[b[i] -  a ]++;     }     if (first != second)       return false;     else       return true;   }   long long combination(long long n, long long r) {     if (r == n || r == 0) {       return 1;     }     return combination(n - 1, r - 1) + combination(n - 1, r);   }   bool cmp(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second == b.second) return a.first < b.first;     return a.second > b.second;   }   int main() {     ios_base::sync_with_stdio(false);     long long n, k;     cin >> n >> k;     vector<int> ar(n);     map<long long, long long> right;     map<long long, long long> left;     for (long long i = 0; i < n; i++) {       cin >> ar[i];     }     long long ans = 0;     for (long long i = n - 1; i >= 0; i--) {       ans += right[ar[i] * k];       right[ar[i]] += left[ar[i] * k];       left[ar[i]]++;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long base = 133;   unsigned long long hash1[200005][26], hash2[200005][26], Pow[200005];   int n, m;   char str1[200005], str2[200005];   int main() {     scanf( %d%d , &n, &m);     scanf( %s%s , str1 + 1, str2 + 1);     Pow[0] = 1;     for (int i = 1; i <= n; i++) {       Pow[i] = Pow[i - 1] * base;     }     for (int i = 0; i < 26; i++) {       for (int j = 1; j <= n; j++) {         hash1[j][i] = hash1[j - 1][i] * base + (str1[j] -  a  == i);       }     }     for (int i = 0; i < 26; i++) {       for (int j = 1; j <= m; j++) {         hash2[j][i] = hash2[j - 1][i] * base + (str2[j] -  a  == i);       }     }     vector<int> vec;     for (int i = 1; i <= n - m + 1; i++) {       int cnt = 0;       for (int x = 0; x < 26; x++) {         if (cnt != x) break;         for (int y = 0; y < 26; y++) {           if (hash2[m][x] == hash1[i + m - 1][y] - hash1[i - 1][y] * Pow[m]) {             if (hash2[m][y] == hash1[i + m - 1][x] - hash1[i - 1][x] * Pow[m]) {               cnt++;               break;             }           }         }       }       if (cnt == 26) vec.push_back(i);     }     int sz = vec.size();     printf( %d n , sz);     for (int i = 0; i < sz; i++) {       printf( %d  , vec[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5, INF = -1e9;   long long down[N], mx[N], up[N], dp[N], sum[N];   unordered_map<long long, vector<long long>> mp[N];   long long n, m, pre[N], suf[N], ans[N];   vector<pair<long long, long long>> adj[N];   bool mark[N];   void dfs_down(long long u, long long par) {     down[u] = up[u] = mark[u] ? 0 : INF;     for (auto x : adj[u]) {       long long v = x.first, w = x.second;       if (v == par) continue;       dfs_down(v, u);       mp[u][down[v] + w].push_back(v);       down[u] = max(down[u], down[v] + w);     }     pre[0] = suf[adj[u].size() - 1] = INF;     for (long long i = 0; i < adj[u].size(); i++) {       long long v = adj[u][i].first, w = adj[u][i].second;       pre[i + 1] = v ^ par ? max(pre[i], down[v] + w) : pre[i];     }     for (long long i = adj[u].size() - 1; i; i--) {       long long v = adj[u][i].first, w = adj[u][i].second;       suf[i - 1] = v ^ par ? max(suf[i], down[v] + w) : suf[i];     }     for (long long i = 0; i < adj[u].size(); i++)       if (adj[u][i].first ^ par) mx[adj[u][i].first] = max(suf[i], pre[i]);   }   void dfs_up(long long u, long long par) {     for (auto x : adj[u]) {       long long v = x.first, w = x.second;       if (v == par) continue;       up[v] = max(up[v], max(up[u], mx[v]) + w);       dfs_up(v, u);     }   }   void dfs1(long long u, long long par) {     if (mark[u] && up[u] > down[u]) dp[u]++;     for (auto x : adj[u]) {       long long v = x.first, w = x.second;       if (v == par) continue;       dfs1(v, u);       ans[u] += dp[v];       if (up[u] > mx[v]) dp[u] += dp[v];       if (up[u] < mx[v]) {         long long sz = mp[u][mx[v]].size();         if (down[v] + w == mx[v]) sz--;         if (sz ^ 1) continue;         for (long long s : mp[u][mx[v]])           if (s ^ v) sum[s] += dp[v];       }     }   }   void dfs2(long long u, long long par) {     if (mark[u] && down[u] > up[u]) sum[u]++;     if (mp[u][down[u]].size() == 1) sum[mp[u][down[u]][0]] += sum[u];     for (auto x : adj[u])       if (x.first ^ par) dfs2(x.first, u);     ans[u] += sum[u];   }   inline void read_input() {     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long v;       cin >> v;       mark[--v] = true;     }     for (long long i = 1; i < n; i++) {       long long u, v, w;       cin >> u >> v >> w;       adj[--u].push_back({--v, w});       adj[v].push_back({u, w});     }   }   inline void solve() {     dfs_down(0, 0);     dfs_up(0, 0);     dfs1(0, 0);     dfs2(0, 0);   }   inline void write_output() {     long long mx = 0, cnt = 0;     for (long long u = 0; u < n; u++) {       if (mark[u]) continue;       if (mx < ans[u]) {         mx = ans[u];         cnt = 0;       }       if (mx == ans[u]) cnt++;     }     cout << mx <<     << cnt << endl;   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     read_input(), solve(), write_output();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( -O2 )   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   t ;     err(++it, args...);   }   template <typename T1, typename T2>   ostream& operator<<(ostream& c, pair<T1, T2>& v) {     c <<  (  << v.first <<  ,  << v.second <<  ) ;     return c;   }   template <template <class...> class TT, class... T>   ostream& operator<<(ostream& out, TT<T...>& c) {     out <<  {  ;     for (auto& x : c) out << x <<    ;     out <<  } ;     return out;   }   const int LIM = 1e5 + 5, MOD = 1e9 + 7;   int t, n, m, k, x, y;   struct Gaussbase2 {     int numofbits = 31;     int rk = 0;     vector<int> Base;     Gaussbase2() { Base.assign(numofbits, 0); }     Gaussbase2& operator=(Gaussbase2& g) {       for (int i = 0; i < numofbits; i++) Base[i] = g.Base[i];       rk = g.rk;     }     bool canbemade(int x) {       for (int i = numofbits - 1; i >= 0; i--) x = min(x, x ^ Base[i]);       return x == 0;     }     void Add(int x) {       for (int i = numofbits; i >= 0; i--) {         if ((x >> i) & 1) {           if (!Base[i]) {             Base[i] = x;             rk++;             return;           } else             x ^= Base[i];         }       }     }   } g;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     int tot = 0;     for (int i = 0; i < n; i++) {       cin >> x;       tot ^= x;       g.Add(x);     }     if (tot == 0)       cout << -1 <<   n ;     else       cout << g.rk <<   n ;     return 0;   }