#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int res = 0;     register char c = getchar(), f = 1;     while (c < 48 || c > 57) {       if (c ==  - ) f = 0;       c = getchar();     }     while (c >= 48 && c <= 57)       res = (res << 3) + (res << 1) + (c & 15), c = getchar();     return f ? res : -res;   }   inline void write(long long x) {     register char c[21], len = 0;     if (!x) return putchar( 0 ), void();     if (x < 0) x = -x, putchar( - );     while (x) c[++len] = x % 10, x /= 10;     while (len) putchar(c[len--] + 48);   }   const int N = 1e5 + 10, L = 20;   struct node {     int sz, a[L];     inline node(int x = -1) {       if (~x) {         sz = 1;         for (int i = 0; i < L; ++i, x >>= 1) a[i] = x & 1;       } else         sz = 0, memset(a, 0, sizeof(a));     }     inline node operator+(const node& p) const {       node r = *this;       r.sz += p.sz;       for (int i = 0; i < L; ++i) r.a[i] += p.a[i];       return r;     }     inline node operator^(int x) const {       node r = *this;       for (int i = 0; i < L; ++i, x >>= 1) r.a[i] = x & 1 ? sz - a[i] : a[i];       return r;     }   } a[N], sum[N];   inline void write(const node& x) {     long long r = 0;     for (int i = 0; i < L; ++i) r += (long long)x.a[i] << i;     write(r);   }   int n, m, rt, w[N], lc[N], rc[N], tag[N], tot = 0;   inline void pu(int x) { sum[x] = sum[lc[x]] + sum[rc[x]] + a[x]; }   int build(int l, int r) {     if (l > r) return 0;     int mid = (l + r) >> 1, x = mid;     w[x] = ++tot;     lc[x] = build(l, mid - 1), rc[x] = build(mid + 1, r);     pu(x);     return x;   }   inline void add(int x, int t) {     a[x] = a[x] ^ t, sum[x] = sum[x] ^ t, tag[x] ^= t;   }   inline void pd(int x) {     if (tag[x]) add(lc[x], tag[x]), add(rc[x], tag[x]), tag[x] = 0;   }   int merge(int x, int y) {     if (!x || !y) return x | y;     if (w[x] < w[y]) {       pd(x), rc[x] = merge(rc[x], y), pu(x);       return x;     } else {       pd(y), lc[y] = merge(x, lc[y]), pu(y);       return y;     }   }   void split(int rt, int k, int& x, int& y) {     if (!rt) return x = y = 0, void();     pd(rt);     if (sum[lc[rt]].sz < k) {       x = rt;       split(rc[x], k - sum[lc[x]].sz - 1, rc[x], y);       pu(x);     } else {       y = rt;       split(lc[y], k, x, lc[y]);       pu(y);     }   }   int op, l, r, x, y, z;   int main() {     n = read();     for (int i = 1; i <= n; ++i) sum[i] = a[i] = read();     m = read();     rt = build(1, n);     while (m--) {       op = read(), l = read(), r = read();       if (op == 1) {         split(rt, r, x, z);         split(x, l - 1, x, y);         write(sum[y]), putchar(  n );         rt = merge(merge(x, y), z);       } else {         split(rt, r, x, z);         split(x, l - 1, x, y);         add(y, read());         rt = merge(merge(x, y), z);       }     }   }


#include <bits/stdc++.h>   int main(int argc, char** argv) {     int32_t num_queries;     std::cin >> num_queries;     for (int32_t i = 0; i < num_queries; i++) {       int32_t num_sticks;       std::cin >> num_sticks;       if (num_sticks == 2)         std::cout << 2 << std::endl;       else if (num_sticks % 2 == 0)         std::cout << 0 << std::endl;       else         std::cout << 1 << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read(long long a = 0) {     freopen( in ,  r , stdin);     if (a) freopen( out ,  w , stdout);   }   vector<vector<pair<long long, long long> > > ad;   long long over;   long long dfs(long long a) {     over = a;     if (ad[a].size() == 0) return 1000000007;     return min(ad[a][0].second, dfs(ad[a][0].first));   }   int main() {     long long n;     cin >> n;     long long m;     ad = vector<vector<pair<long long, long long> > >(n + 1);     cin >> m;     bool vis[10000] = {}, good[10000] = {};     while (m--) {       long long x, y, d;       cin >> x >> y >> d;       x--, y--;       vis[y] = 1;       good[x] = 1;       ad[x].push_back(make_pair(y, d));     }     vector<pair<pair<long long, long long>, long long> > ans;     for (int i = 0; i < n; i++) {       if (!vis[i] && good[i]) {         pair<pair<long long, long long>, long long> tmp;         tmp.first.first = i;         tmp.second = dfs(i);         tmp.first.second = over;         ans.push_back(tmp);       }     }     sort(ans.begin(), ans.end());     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++)       cout << ans[i].first.first + 1 <<     << ans[i].first.second + 1 <<                << ans[i].second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename U, typename V>   void Min(U &a, const V &b) {     if (a > b) a = b;   }   template <typename U, typename V>   void Max(U &a, const V &b) {     if (a < b) a = b;   }   template <typename U, typename V>   void add(U &a, const V &b) {     a = (a + b) % 1000000007;   }   template <typename U>   U gcd(U a, U b) {     if (a == 0) return b;     if (b == 0) return a;     if (a >= b)       return gcd(a % b, b);     else       return gcd(a, b % a);   }   int pow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1LL * ans * a % 1000000007;       a = 1LL * a * a % 1000000007;       b >>= 1;     }     return ans;   }   int pow(int a, long long b, int c) {     int ans = 1;     while (b) {       if (b & 1) ans = 1LL * ans * a % c;       a = 1LL * a * a % c;       b >>= 1;     }     return ans;   }   pair<int, int> a[100005];   int main() {     int ca = 0, T, i, j, k, m, n, K;     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       for (int i = 0; i < n; i++) {         scanf( %d , &m);         int mx = 0;         for (int i = 0; i < m; i++) scanf( %d , &k), k -= i, Max(mx, k);         a[i] = {mx, m};       }       sort(a, a + n);       int ans = 0;       long long cur = 0;       for (int i = 0; i < n; i++) {         if (cur >= a[i].first) {           cur += a[i].second;         } else {           ans += a[i].first - cur;           cur = a[i].first + a[i].second;         }       }       printf( %d n , ans + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   struct __timestamper {};   const int MAXN = 100100;   int val[MAXN];   long long dp[MAXN][4];   vector<int> g[MAXN];   void dfs(int v, int p) {     for (int u : g[v])       if (u != p) dfs(u, v);     long long max0 = 0, smax0 = 0, tmax0 = 0;     int max0v = -1, smax0v = -1;     long long max1 = 0, smax1 = 0;     int max1v = -1;     long long max2 = 0, smax2 = 0;     int max2v = -1;     long long max3 = 0, smax3 = 0;     for (int u : g[v])       if (u != p) {         long long t = dp[u][0];         int tv = u;         if (t > max0) {           swap(t, max0);           swap(max0v, tv);         }         if (t > smax0) {           swap(t, smax0);           swap(smax0v, tv);         }         if (t > tmax0) {           swap(t, tmax0);         }         t = dp[u][1];         if (t > max1) {           swap(t, max1);           max1v = u;         }         if (t > smax1) swap(t, smax1);         t = dp[u][2];         if (t > max2) {           swap(t, max2);           max2v = u;         }         if (t > smax2) swap(t, smax2);         t = dp[u][3];         if (t > max3) {           swap(t, max3);         }         if (t > smax3) swap(t, smax3);       }     dp[v][0] = max0 + val[v];     dp[v][1] = max(max1, max0 + smax0 + val[v]);     dp[v][2] = max2 + val[v];     if (max0v == max1v) {       dp[v][2] = max(dp[v][2], max(max0 + smax1, max1 + smax0) + val[v]);     } else {       dp[v][2] = max(dp[v][2], max0 + max1 + val[v]);     }     dp[v][3] = max3;     dp[v][3] = max(dp[v][3], max1 + smax1);     if (max0v == max2v) {       dp[v][3] = max(dp[v][3], max(max0 + smax2, max2 + smax0) + val[v]);     } else {       dp[v][3] = max(dp[v][3], max0 + max2 + val[v]);     }     for (int u : g[v])       if (u != p) {         long long cur = val[v] + dp[u][1];         if (u == max0v) {           cur += smax0 + tmax0;         } else if (u == smax0v) {           cur += max0 + tmax0;         } else {           cur += max0 + smax0;         }         dp[v][3] = max(dp[v][3], cur);       }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &val[i]);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       --a, --b;       g[a].push_back(b);       g[b].push_back(a);     }     dfs(0, -1);     printf( %lld n , *max_element(dp[0], dp[0] + 4));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 7e4;   const int INF = 1e9;   struct d {     int ad, xr;   } a[N];   stack<int> s;   vector<pair<int, int>> v;   int n;   int main() {     ios::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     int A, B;     for (int i = 0; i < n; ++i) {       cin >> A >> B;       if (A == 0) continue;       if (A == 1) s.push(i);       a[i] = {A, B};     }     while (!s.empty()) {       int x = s.top();       s.pop();       if (a[x].ad == 1) {         v.push_back({x, a[x].xr});         a[x].ad--;         --a[a[x].xr].ad;         a[a[x].xr].xr ^= x;         if (a[a[x].xr].ad == 1) s.push(a[x].xr);       }     }     cout << v.size() <<   n ;     for (auto x : v) cout << x.first <<     << x.second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& out, const pair<T1, T2>& p) {     return (out << p.first <<     << p.second << endl);   }   const int INF = 1000000017;   const long long LLINF = 1000000000000000017LL;   const long double inf = 1.0 / 0.0;   const long double eps = 1e-10;   const int MOD = 1e9 + 7;   const int MOD2 = 1e9 + 9;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     while (T--) {       int c, d;       cin >> c >> d;       if (c == d) {         if (c == 0) {           cout << 0;         } else {           cout << 1;         }       } else if (abs(c - d) % 2 == 0) {         cout << 2;       } else {         cout << -1;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3, MOD = 1e9 + 7, UNDEF = -1;   int readInt() {     bool minus = false;     int result = 0;     char ch;     ch = getchar();     while (true) {       if (ch ==  - ) break;       if (ch >=  0  && ch <=  9 ) break;       ch = getchar();     }     if (ch ==  - )       minus = true;     else       result = ch -  0 ;     while (true) {       ch = getchar();       if (ch <  0  || ch >  9 ) break;       result = result * 10 + (ch -  0 );     }     if (minus)       return -result;     else       return result;   }   char readChar() {     char result = getchar();     while (isspace(result)) {       result = getchar();     }     return result;   }   char w[N + 1][N + 1];   pair<pair<short, short>, pair<short, short> > cur;   int n, m;   int dp1[2 * N + 1][2 * N + 1], dp2[2 * N + 1][2 * N + 1];   int S[2 * N + 1], cnt[2 * N + 1];   int curx, cury;   bool ispal(string s) {     string d = s;     reverse(s.begin(), s.end());     return d == s;   }   int o(int x1, int y1) { return x1 + S[x1 + y1] - S[x1 + y1 - 1]; }   void add(int x1, int y1, int x2, int y2) {     dp1[curx][cury] += dp2[o(x1, y1)][o(x2, y2)];     if (dp1[curx][cury] >= MOD) {       dp1[curx][cury] -= MOD;     }   }   vector<pair<short, short> > p1[2 * N + 1], p2[2 * N + 1];   int main() {     n = readInt(), m = readInt();     int s = (n + m - 2) / 2;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cnt[i + j]++;         w[i][j] = readChar();         p1[i + j - 2].push_back(make_pair(i, j));         p2[n + m - 2 - (i + j - 2)].push_back(make_pair(i, j));       }     }     for (int i = 2; i <= n + m; i++) {       S[i] = S[i - 1] + cnt[i];     }     if (w[1][1] != w[n][m]) {       cout << 0;       return 0;     }     int ans = n * n + 2 * (n - 1) * n;     for (int i = s; i >= 0; i--) {       for (int j = 0; j < p1[i].size(); j++) {         for (int k = 0; k < p2[i].size(); k++) {           int x1, y1, x2, y2;           x1 = p1[i][j].first;           y1 = p1[i][j].second;           x2 = p2[i][k].first;           y2 = p2[i][k].second;           if (w[x1][y1] == w[x2][y2]) {             if (x1 <= x2 && y1 <= y2) {               if (x2 - x1 + y2 - y1 <= 1) {                 dp1[o(x1, y1)][o(x2, y2)] = 1;               } else {                 curx = o(x1, y1);                 cury = o(x2, y2);                 if (x1 == x2) {                   add(x1, y1 + 1, x2, y2 - 1);                 } else if (y1 == y2) {                   add(x1 + 1, y1, x2 - 1, y2);                 } else {                   add(x1, y1 + 1, x2 - 1, y2);                   add(x1 + 1, y1, x2, y2 - 1);                   if (y2 - 1 >= y1 + 1) {                     add(x1, y1 + 1, x2, y2 - 1);                   }                   if (x2 - 1 >= x1 + 1) {                     add(x1 + 1, y1, x2 - 1, y2);                   }                 }               }             }           }         }       }       for (int i = 0; i <= 2 * n + m; i++) {         for (int j = 0; j <= 2 * n + m; j++) {           dp2[i][j] = dp1[i][j];           dp1[i][j] = 0;         }       }     }     cout << dp2[o(1, 1)][o(n, m)];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     stringstream ss;     string x, s1, s2, s3;     long long int a1 = 0, a2 = 0, a3 = 0, sum = -1, q = 0;     cin >> x;     int z = x.size();     for (int i = 1; i < (z - 1); i++) {       for (int j = 1; j < (z - i); j++) {         q = 0;         stringstream ss1, ss2, ss3;         s1 = x.substr(0, i);         s2 = x.substr(i, j);         s3 = x.substr((i + j), (z - i - j));         if ((s1[0] ==  0  && s1.size() > 1) || (s2[0] ==  0  && s2.size() > 1) ||             (s3[0] ==  0  && s3.size() > 1))           continue;         {           ss1 << s1;           ss1 >> a1;           ss1.clear();           ss2 << s2;           ss2 >> a2;           ss2.clear();           ss3 << s3;           ss3 >> a3;           ss3.clear();           if (a1 > 1000000 || a2 > 1000000 || a3 > 1000000) continue;           q = a1 + a2 + a3;           if (q > sum) sum = q;         }       }     }     cout << sum << endl;   }


#include <bits/stdc++.h>   const int MOD = 998244353;   int prefix[505];   int dp[505];   void addmod(int& x, int y) { x = (x + y) % MOD; }   int main() {     int N, K;     scanf( %d %d , &N, &K);     dp[0] = 1;     for (int k = 1; k <= N; k++) {       for (int i = 1; i <= N; i++) {         dp[i] = 0;         for (int j = 1; j <= std::min(i, k); j++) {           addmod(dp[i], dp[i - j]);         }       }       prefix[k] = dp[N];     }     int j = N;     int total = 0;     for (int i = 1; i <= N; i++) {       while (i * j >= K) j--;       addmod(total, int64_t(prefix[i] + MOD - prefix[i - 1]) * prefix[j] % MOD);     }     printf( %d n , total * 2 % MOD);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, n, l, miao, lala;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     cin.ignore();     while (n--) {       char s[105];       miao = 0;       lala = 0;       cin.getline(s, 105);       int l = strlen(s);       if (l > 4 && s[0] ==  m  && s[1] ==  i  && s[i + 2] ==  a  &&           s[i + 3] ==  o  && s[i + 4] ==  . )         miao = 1;       if (l > 4 && s[l - 5] ==  l  && s[l - 4] ==  a  && s[l - 3] ==  l  &&           s[l - 2] ==  a  && s[l - 1] ==  . )         lala = 1;       if (miao == 1 && lala == 1 || miao == 0 && lala == 0)         cout <<  OMG>.< I don t know! n ;       else if (miao == 1)         cout <<  Rainbow s n ;       else if (lala == 1)         cout <<  Freda s n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int kval(int a) {     if (a == 0) return 10;     int kvala = a;     if (kvala % 10)       kvala = 10 + ((kvala / 10) * 10) - kvala;     else       kvala = 0;     return kvala;   }   int compare(int a, int b) {     if (kval(a) >= kval(b))       return 0;     else       return 1;   }   int main() {     int num, k, t;     vector<int> v2;     cin >> num >> t;     long long sum = 0;     for (int i = 0; i < num; i++) {       cin >> k;       sum = sum + (k / 10);       if (k < 100) v2.push_back(k);     }     int i;     int size = v2.size();     sort(v2.begin(), v2.end(), compare);     for (i = 0; i < size; i++) {       if (v2[i] % 10) {         if (kval(v2[i]) <= t) {           t = t - kval(v2[i]);           v2[i] += kval(v2[i]);           sum++;         } else           break;       }     }     if (i == size) {       sort(v2.begin(), v2.end());       for (int i = size - 1; i >= 0; i--) {         if (v2[i] < 100) {           int val = v2[i] + t;           if (val >= 100) val = 100;           sum += ((val - v2[i]) / 10);           t = t - (val - v2[i]);         } else           continue;       }     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int z;   struct pi {     bool operator()(const pair<int, int>& p, const pair<int, int>& q) {       if (0) {       } else if (abs(p.first - z) < abs(q.first - z)) {         return 1;       } else if (abs(p.first - z) > abs(q.first - z)) {         return 0;       } else {         if (0) {         } else if (p.first < q.first) {           return 0;         } else if (p.first > q.first) {           return 1;         } else {           if (0) {           } else if (p.first > z) {             if (p.second < q.second) {               return 1;             } else {               return 0;             }           } else if (p.first < z) {             if (p.second < q.second) {               return 0;             } else {               return 1;             }           } else {             return 0;           }         }       }     }   };   int main() {     int i;     int n, k;     while (cin >> n >> k) {       string s[10];       cin >> s[0];       for (i = 1; i < 10; ++i) s[i] = s[0];       pair<int, int> a[10][10100];       for (i = 0; i < n; ++i) a[0][i] = make_pair(s[0][i] -  0 , i);       for (i = 1; i < 10; ++i) copy(a[0], a[0] + n, a[i]);       int mn = 1 << 30, mnz;       for (z = 0; z < 10; ++z) {         sort(a[z], a[z] + n, pi());         int sm = 0;         for (i = 0; i < k; ++i) {           sm += abs(a[z][i].first - z);           s[z][a[z][i].second] =  0  + z;         }         if (0) {         } else if (mn > sm) {           mn = sm;           mnz = z;         } else if (mn < sm) {         } else {           if (s[mnz] > s[z]) mnz = z;         }       }       cout << mn << endl;       cout << s[mnz] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n], b[n];       for (long long i = 0; i < n; i++) cin >> a[i];       for (long long i = 0; i < n; i++) cin >> b[i];       sort(a, a + n);       sort(b, b + n);       for (long long i = 0; i < n; i++) {         cout << a[i] <<    ;       }       cout << endl;       for (long long i = 0; i < n; i++) cout << b[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, y;   long long c;   string s;   long long ans = 1e16;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> x >> y;     cin >> s;     s =  1  + s;     for (long long i = 1; i <= n; i++)       if (s[i] ==  0  and s[i - 1] ==  1 ) c++;     for (long long i = 0; i < c; i++) ans = min(ans, i * x + (c - i) * y);     if (c == 0) ans = 0;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long long N = 2005, inf = 1e15;   long long dp[N][N], suffix1[N][26], suffix2[N][26];   long long n;   string s, t;   long long dpsolve(long long i, long long j) {     if (j == 0) {       return 0;     }     if (dp[i][j] != -1) return dp[i][j];     long long ans = inf;     if (i > 0) {       ans = min(ans, 1 + dpsolve(i - 1, j));       if (s[i] == t[j]) ans = min(ans, dpsolve(i - 1, j - 1));     }     if (suffix1[i + 1][t[j] -  a ] >= suffix2[j][t[j] -  a ])       ans = min(ans, dpsolve(i, j - 1));     dp[i][j] = ans;     return ans;   }   void solve() {     cin >> n;     cin >> s;     cin >> t;     s =     + s;     t =     + t;     for (long long i = n; i >= 1; i--) {       for (long long j = 0; j < 26; j++) {         suffix1[n + 1][j] = suffix2[n + 1][j] = 0;         suffix1[i][j] = (s[i] -  a  == j) + suffix1[i + 1][j];         suffix2[i][j] = (t[i] -  a  == j) + suffix2[i + 1][j];       }     }     for (long long i = 0; i <= n; i++)       for (long long j = 0; j <= n; j++) dp[i][j] = -1;     bool flag = true;     for (long long j = 0; j < 26; j++)       if (suffix1[1][j] != suffix2[1][j]) flag = false;     if (!flag)       cout <<  -1 n ;     else {       long long ans = dpsolve(n, n);       cout << ans <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 105;   bool dmy[MAXN][MAXN][MAXN];   void dfs(int d, int m, int y, int bd, int bm, int by) {     if (dmy[bd][bm][by]) return;     dmy[bd][bm][by] = true;     if (bm > 12) return;     if (bd > 31) return;     if (!(by % 4) && bm == 2 && bd > 29) return;     if ((by % 4) && bm == 2 && bd >= 29) return;     if (y - by == 18) {       if (bm < m) {         puts( YES );         exit(0);       } else {         if (bm == m && bd <= d) {           puts( YES );           exit(0);         }       }     }     if (y - by > 18) {       puts( YES );       exit(0);     }     dfs(d, m, y, by, bd, bm);     dfs(d, m, y, bm, by, bd);     dfs(d, m, y, bd, by, bm);     dfs(d, m, y, by, bm, bd);     dfs(d, m, y, bm, bd, by);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int d, m, y, bd, bm, by;     string s;     cin >> s;     d = (s[0] -  0 ) * 10 + (s[1] -  0 );     m = (s[3] -  0 ) * 10 + (s[4] -  0 );     y = (s[6] -  0 ) * 10 + (s[7] -  0 );     cin >> s;     bd = (s[0] -  0 ) * 10 + (s[1] -  0 );     bm = (s[3] -  0 ) * 10 + (s[4] -  0 );     by = (s[6] -  0 ) * 10 + (s[7] -  0 );     dfs(d, m, y, by, bd, bm);     dfs(d, m, y, bm, by, bd);     dfs(d, m, y, bd, by, bm);     dfs(d, m, y, by, bm, bd);     dfs(d, m, y, bm, bd, by);     dfs(d, m, y, bd, bm, by);     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   long long n, sum, arr[N], cnt;   int main() {     scanf( %lld , &n);     for (int i = 0; i < n; ++i) {       scanf( %lld , &arr[i]);       sum += arr[i];     }     sort(arr, arr + n);     for (int i = 0; i < n - 1; ++i) {       if (arr[i] == arr[i + 1]) {         cnt++;         if (i && arr[i - 1] == arr[i] - 1) return puts( cslnb ), 0;         if (cnt > 1) return puts( cslnb ), 0;         if (arr[i] == 0) return puts( cslnb ), 0;       }     }     sum -= n * (n - 1) / 2;     if (sum & 1)       puts( sjfnb );     else       puts( cslnb );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     scanf( %d%d%d , &a, &b, &c);     if (a > b) swap(a, b);     if (b - a >= c) {       printf( %d n , (a + c) * 2);       return 0;     }     if (b - a < c) {       c -= b - a;       printf( %d n , b * 2 + (c / 2) * 2);       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[200050];   int b[200050];   int c[200050];   int now[200050];   int tot[200050];   int ans[200050];   int n, m, cnt, p;   int main() {     int i, j;     while (scanf( %d %d %d , &n, &m, &p) != EOF) {       for (i = 0; i < n; i++) scanf( %d , a + i);       for (i = 0; i < m; i++) scanf( %d , b + i);       if (1 + (long long)p * (m - 1) > n) {         printf( 0 n );         continue;       }       sort(b, b + m);       for (i = 0; i < m; i++) c[i] = b[i];       int sz = unique(c, c + m) - c;       for (i = 0; i < sz; i++) {         tot[i] = upper_bound(b, b + m, c[i]) - lower_bound(b, b + m, c[i]);       }       cnt = 0;       for (i = 0; i < p; i++) {         memset(now, 0, sizeof(now));         int l, r;         l = i;         r = i - p;         while (r < n) {           r += p;           if (r >= n) continue;           int k = lower_bound(c, c + sz, a[r]) - c;           if (a[r] != c[k]) {             while (l != r) {               int kk = lower_bound(c, c + sz, a[l]) - c;               now[kk] = 0;               l += p;             }             l += p;             continue;           }           now[k]++;           if (now[k] > tot[k]) {             while (now[k] > tot[k]) {               int kk = lower_bound(c, c + sz, a[l]) - c;               now[kk]--;               l += p;             }           }           if ((r - l) / p + 1 == m) {             ans[cnt++] = l;             int kk = lower_bound(c, c + sz, a[l]) - c;             now[kk]--;             l += p;           }         }       }       printf( %d n , cnt);       if (cnt) {         sort(ans, ans + cnt);         printf( %d , ans[0] + 1);         for (i = 1; i < cnt; i++) printf(  %d , ans[i] + 1);         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   const int Maxn = 500010;   using namespace std;   multiset<long long> S;   int n, m;   long long t[Maxn];   void add(int pos, int x) {     for (; pos <= m; pos += pos & -pos) {       t[pos] += x;     }   }   long long query(int pos) {     long long ans = 0;     for (; pos; pos ^= pos & -pos) ans += t[pos];     return ans;   }   char c[Maxn];   int num[Maxn], b[Maxn];   int Get_ans() {     if (S.size() == 0) return 0;     multiset<long long>::iterator x = S.begin(), y;     int cnt = 0;     while (x != S.end()) {       int pos = lower_bound(b + 1, b + m + 1, *x) - b;       if (x != S.begin()) {         long long sum = query(pos - 1);         if (sum * 2 < *x) cnt++;       }       long long sum = query(pos);       x = S.upper_bound(sum * 2);       if (x == S.end()) break;     }     return S.size() - cnt - 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       cin >> c[i] >> num[i];       b[i] = num[i];     }     sort(b + 1, b + n + 1);     m = unique(b + 1, b + n + 1) - b - 1;     for (int i = 1; i <= n; i++) {       int w = lower_bound(b + 1, b + m + 1, num[i]) - b;       if (c[i] ==  + ) {         S.insert(num[i]);         add(w, num[i]);         printf( %d n , Get_ans());       } else {         multiset<long long>::iterator ite = S.find(num[i]);         S.erase(ite);         add(w, -num[i]);         printf( %d n , Get_ans());       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> vec, ves;   int main() {     int n, m, f = 0, w = 0;     bool p = false, t = false;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> m;       if (m == 0) t = true;       for (int j = 0; j < vec.size(); j++) {         p = false;         if (m == vec[j]) {           ves[j]++;           p = true;           break;         }       }       if (p == false) {         vec.push_back(m);         ves.push_back(1);       }     }     for (int i = 0; i < vec.size(); i++) {       if (vec[i] != 0 && ves[i] > 2) {         cout << -1;         return 0;       } else if (ves[i] == 2 && vec[i] != 0)         w++;     }     cout << w;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> q[200010], g[200010];   int n, m, a[200010], b[200010];   unsigned long long A, B, C, ans;   unsigned long long calc(unsigned long long a, unsigned long long b,                           unsigned long long c) {     unsigned long long s[3] = {a, b, c};     sort(s, s + 3);     return s[0] * A + s[1] * B + s[2] * C;   }   int main() {     scanf( %d%d , &n, &m);     scanf( %lld%lld%lld , &A, &B, &C);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &a[i], &b[i]);       if (a[i] > b[i]) swap(a[i], b[i]);       q[a[i]].push_back(b[i]), q[b[i]].push_back(a[i]);     }     for (int i = 0; i < n; i++) {       ans += (unsigned long long)i * A *              ((unsigned long long)(n - i - 1) * (n - i - 2) / 2LL);       ans += (unsigned long long)i * B * ((unsigned long long)(i) * (n - i - 1));       ans +=           (unsigned long long)i * C * ((unsigned long long)(i) * (i - 1) / 2LL);     }     for (int i = 1; i <= m; i++) {       ans -= (unsigned long long)a[i] * a[i] * B +              (unsigned long long)a[i] * b[i] * C +              (unsigned long long)a[i] * (a[i] - 1) / 2LL * A;       ans -= (unsigned long long)(b[i] - a[i] - 1) * a[i] * A +              (unsigned long long)(b[i] - a[i] - 1) * b[i] * C +              (unsigned long long)(b[i] - a[i] - 1) * (a[i] + b[i]) / 2LL * B;       ans -= (unsigned long long)(n - b[i] - 1) * a[i] * A +              (unsigned long long)(n - b[i] - 1) * b[i] * B +              (unsigned long long)(n - b[i] - 1) * (n + b[i]) / 2LL * C;     }     for (int i = 0; i < n; i++) sort(q[i].begin(), q[i].end());     for (int i = 0; i < n; i++) {       unsigned long long pre = 0, pre_tot = 0;       for (int j = 0; j < q[i].size(); j++) {         int to = q[i][j];         if (to > i) continue;         ans += pre_tot * i * C + pre * A + to * pre_tot * B;         pre += to;         pre_tot++;       }       unsigned long long nex = 0, nex_tot = 0;       for (int j = 0; j < q[i].size(); j++) {         int to = q[i][j];         if (to < i) continue;         ans += nex_tot * i * A + nex * B + to * nex_tot * C;         nex += to;         nex_tot++;       }       ans += pre_tot * nex_tot * i * B + pre_tot * nex * C + nex_tot * pre * A;     }     for (int i = 1; i <= m; i++) {       if (q[a[i]].size() < q[b[i]].size())         g[a[i]].push_back(b[i]);       else         g[b[i]].push_back(a[i]);     }     for (int i = 0; i < n; i++) sort(g[i].begin(), g[i].end());     for (int i = 1; i <= m; i++) {       int t1 = 0, t2 = 0;       while (t1 < g[a[i]].size() && t2 < g[b[i]].size()) {         if (g[a[i]][t1] < g[b[i]][t2])           t1++;         else if (g[a[i]][t1] > g[b[i]][t2])           t2++;         else {           ans -= calc(a[i], b[i], g[a[i]][t1]);           t1++, t2++;         }       }     }     printf( %llu n , ans);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 2010;   int n;   string s;   int a[N], tot, vis[N];   bitset<N> d, ba[N], sel[N];   void Trans(string s) {     reverse(s.begin(), s.end());     while (s.size() % 8) s +=  0 ;     int L = s.size() / 8;     for (int i = 0; i < L; i++) {       a[i] = 0;       for (int j = 7; ~j; j--) a[i] = a[i] * 10 + s[i * 8 + j] -  0 ;     }     long long S = 0;     tot = 0;     while (L) {       S = 0;       for (int i = L - 1; ~i; i--) {         S = S * 100000000LL + a[i];         a[i] = S >> 32;         S %= (1LL << 32);       }       for (int i = 0; i < 32; i++) d[tot++] = ((S >> i) & 1);       while (L && a[L - 1] == 0) --L;     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       Trans(s);       bitset<N> ns;       int flg = 1;       for (int j = tot - 1; ~j; j--)         if (d[j])           if (vis[j]) {             d ^= ba[j];             ns ^= sel[j];           } else {             flg = 0;             ns.flip(i);             ba[j] = d;             sel[j] = ns;             vis[j] = 1;             break;           }       if (!flg) {         cout << 0 << endl;         continue;       } else {         cout << ns.count() <<    ;         for (int i = 0; i < N; i++)           if (ns[i]) cout << i <<    ;         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const long long mod = 1000000007;   const int N = 201000;   int n, y[N];   double k;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &y[i]);     int b = -1;     for (int i = 2; i < n; ++i)       if ((long long)(y[i] - y[0]) * (i - 1) != (long long)(y[i] - y[1]) * i) {         b = i;         break;       }     if (~b) {       bool ans = 0, tans = 1;       for (int i = 2; i < n; ++i)         if (i != b) {           bool t =               (long long)(y[i] - y[0]) * (i - 1) != (long long)(y[i] - y[1]) * i;           bool s = (long long)(y[i] - y[b]) != (long long)(y[1] - y[0]) * (i - b);           if (s && t) {             tans = 0;             break;           }         }       ans |= tans;       tans = 1;       for (int i = 2; i < n; ++i)         if (i != b) {           bool t =               (long long)(y[i] - y[0]) * (i - b) != (long long)(y[i] - y[b]) * i;           bool s =               (long long)(y[i] - y[1]) * b != (long long)(y[b] - y[0]) * (i - 1);           if (s && t) {             tans = 0;             break;           }         }       ans |= tans;       tans = 1;       for (int i = 2; i < n; ++i)         if (i != b) {           bool t = (long long)(y[i] - y[1]) * (i - b) !=                    (long long)(y[i] - y[b]) * (i - 1);           bool s =               (long long)(y[i] - y[0]) * (b - 1) != (long long)(y[b] - y[1]) * i;           if (s && t) {             tans = 0;             break;           }         }       ans |= tans;       puts(ans ?  Yes  :  No );     } else {       puts( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   inline T lowbit(T x) {     return x & -x;   }   template <typename S, typename T>   void debug(S s, T t) {     cerr << s <<   ==   << t <<   n ;   }   template <typename T>   void debug(T t) {     cerr << t <<   n ;   }   template <typename T>   void debug(T t[], long long st, long long ed) {     for (long long i = st; i <= ed; ++i) {       cerr << t[i] <<    ;     }     cerr <<   n ;   }   template <typename T>   void debug(const vector<T>& t) {     for (long long i = 0; i < t.size(); ++i) cerr << t[i] <<    ;     cerr <<   n ;   }   const long long N = 2e5 + 10;   void solve() {     long long x, y;     cin >> x >> y;     if (y < x)       cout << x + y <<   n ;     else if (x == y)       cout << x <<   n ;     else       cout << y - (y % x) / 2 <<   n ;   }   signed main() {     long long _;     cin >> _;     while (_--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100005], tmp[100005], b[100005];   bool die[100005];   int n, m;   vector<long long> candidate;   bool solve(int pos) {     candidate.clear();     for (int i = 1; i <= n; i++)       if ((!die[i]) && (a[i] & (1ll << pos))) {         candidate.push_back(a[i]);         die[i] = true;       }     for (int i = 1; i <= m; i++) tmp[i] = b[i];     int len_tmp = m;     int cur = 1;     m = 0;     for (int i = 0; i < candidate.size(); i++) {       b[++m] = candidate[i];       while (cur <= len_tmp && !(tmp[cur] & (1ll << pos))) {         b[++m] = tmp[cur];         cur++;       }       if (cur > len_tmp && i != candidate.size() - 1) return false;       b[++m] = tmp[cur];       cur++;     }     while (cur <= len_tmp) {       b[++m] = tmp[cur];       cur++;     }     return true;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 59; i >= 0; i--)       if (!solve(i)) {         printf( No );         return 0;       }     cout <<  Yes n ;     for (int i = 1; i <= n; i++) cout << b[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   long long modpow(long long a, long long b, long long m = 998244353) {     a %= m;     long long res = 1;     while (b) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long bpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long modinv(long long a) { return modpow(a, 998244353 - 2, 998244353); }   void graph(vector<vector<int> > &adj, int m) {     int x, y;     for (int i = 0; i < m; i++) {       cin >> x >> y;       adj[x - 1].push_back(y - 1);       adj[y - 1].push_back(x - 1);     }   }   const int N = 23;   struct NTT {     int root, root_1, root_pw = 1 << N, c = (998244353 - 1) >> N;     NTT(bool init = true) {       if (init) {         vector<int> pf;         int n = 998244353 - 1, phi = n;         for (int i = 2; i * i <= n; i++) {           if (n % i == 0) {             pf.push_back(i);             while (n % i == 0) n /= i;           }         }         if (n > 1) pf.push_back(n);         for (int r = 2; r <= phi; r++) {           bool ok = true;           for (auto &x : pf) {             if (modpow(r, phi / x) == 1) {               ok = false;               break;             }           }           if (ok) {             root = modpow(r, c), root_1 = modinv(root);             break;           }         }       }     }     void transform(vector<int> &a, bool invert) {       int n = a.size();       for (int i = 1, j = 0; i < n; i++) {         int bit = n >> 1;         for (; j & bit; bit >>= 1) j ^= bit;         j ^= bit;         if (i < j) swap(a[i], a[j]);       }       for (int len = 2; len <= n; len <<= 1) {         int wlen = invert ? root_1 : root;         for (int i = len; i < root_pw; i <<= 1)           wlen = (int)(1LL * wlen * wlen % 998244353);         for (int i = 0; i < n; i += len) {           int w = 1;           for (int j = 0; j < len / 2; j++) {             int u = a[i + j], v = (int)(1LL * a[i + j + len / 2] * w % 998244353);             a[i + j] = u + v < 998244353 ? u + v : u + v - 998244353;             a[i + j + len / 2] = u - v >= 0 ? u - v : u - v + 998244353;             w = (int)(1LL * w * wlen % 998244353);           }         }       }       if (invert) {         int n_1 = modinv(n);         for (int &x : a) x = (int)(1LL * x * n_1 % 998244353);       }     }     vector<int> multiply(vector<int> const &a, vector<int> const &b) {       vector<int> fa(a.begin(), a.end()), fb(b.begin(), b.end());       int n = 1, total = a.size() + b.size();       while (n < total) n <<= 1;       fa.resize(n);       fb.resize(n);       transform(fa, false);       transform(fb, false);       for (int i = 0; i < n; i++) fa[i] = (fb[i] * 1LL * fa[i]) % 998244353;       transform(fa, true);       fa.resize(total - 1);       return fa;     }   };   NTT ntt;   vector<int> exp(vector<int> &a, int n) {     if (n == 1) return a;     vector<int> res = exp(a, n / 2);     res = ntt.multiply(res, res);     if (n & 1) {       res = ntt.multiply(res, a);     }     return res;   }   void solve() {     int n, k, x;     cin >> n >> k;     vector<int> coeff(10, 0);     for (int i = 0; i < k; i++) cin >> x, coeff[x] = 1;     x = n / 2;     vector<int> power = exp(coeff, x);     long long ans = 0;     ;     for (auto &k : power) ans = (ans + k * 1LL * k) % 998244353;     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1, tt = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int st, en;   } TV[200010];   bool cmp(node a, node b) {     if (a.st == b.st) {       return a.en < b.en;     }     return a.st < b.st;   }   int main() {     int n;     int tv1, tv2;     int flag;     cin >> n;     tv1 = -1;     tv2 = -1;     flag = 1;     for (int i = 0; i < n; i++) {       cin >> TV[i].st >> TV[i].en;     }     sort(TV, TV + n, cmp);     for (int i = 0; i < n && flag; i++) {       if (tv1 < TV[i].st) {         tv1 = TV[i].en;       } else {         if (tv2 < TV[i].st) {           tv2 = TV[i].en;         } else {           flag = 0;         }       }     }     if (flag) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   ifstream fin( input.txt );   ofstream fout( output.txt );   bool isPrime(int x) {     if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;     for (int i = 5; i * i <= x; i += 6)       if (x % i == 0 || x % (i + 2) == 0) return 0;     return 1;   }   int NumDigits(int x) {     return (         x < 10             ? 1             : (x < 100                    ? 2                    : (x < 1000                           ? 3                           : (x < 10000                                  ? 4                                  : (x < 100000                                         ? 5                                         : (x < 1000000                                                ? 6                                                : (x < 10000000                                                       ? 7                                                       : (x < 100000000                                                              ? 8                                                              : (x < 1000000000                                                                     ? 9                                                                     : 10)))))))));   }   inline void boostIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);   }   long long int Pow10[19] = {       (long long int)1,    (long long int)1e1,  (long long int)1e2,       (long long int)1e3,  (long long int)1e4,  (long long int)1e5,       (long long int)1e6,  (long long int)1e7,  (long long int)1e8,       (long long int)1e9,  (long long int)1e10, (long long int)1e11,       (long long int)1e12, (long long int)1e13, (long long int)1e14,       (long long int)1e15, (long long int)1e16, (long long int)1e17,       (long long int)1e18};   long long int gcd(long long int a, long long int b) {     return b ? gcd(b, a % b) : a;   }   long long int lcm(long long int a, long long int b) {     return a * b / gcd(a, b);   }   long long Mod = 998244353;   template <class T>   struct Fenwick {     vector<T> V;     Fenwick(long long n) : V(n) {}     void add(size_t i, T x) {       for (; i < V.size(); i |= i + 1) V[i] += x;     }     T sum(long long i) {       T r = T();       for (--i; i >= 0; i = (i & (i + 1)) - 1) r += V[i];       return r;     }     T sum(long long l, long long r) { return sum(r) - sum(l); }   };   long long mul(long long a, long long b, long long c = 1, long long d = 1,                 long long e = 1, long long g = 1) {     a %= Mod;     b %= Mod;     c %= Mod;     d %= Mod;     e %= Mod;     g %= Mod;     return (a * b % Mod * c % Mod * d % Mod * e % Mod * g % Mod);   }   long long Pow(long long a, long long b) {     if (b == 0) return 1;     if (b % 2 == 0) {       long long x = Pow(a, b / 2);       return mul(x, x);     } else {       long long x = Pow(a, b / 2);       return mul(a, x, x);     }   }   long long inf = 1e18;   struct My {     long long a = inf;     long long b = inf;     long long solved = 0;     long long fee = 0;   };   struct comp {     bool operator()(My const& a, My const& b) const {}   };   struct Tree {     long long n = 1;     vector<long long> t;     Tree(long long nn) {       while (n < nn) n *= 2;       t.assign(n * 2, 0);     }     Tree(vector<long long>& A) {       while (n < A.size()) n *= 2;       t.assign(n * 2, 0);       for (long long i = 0; i < (A.size()); ++i) {         t[i + n] = A[i];       }       for (long long i = A.size() - 1; i >= 1; --i) {         t[i] = t[i + i] + t[i + i + 1];       }     }     long long get(long long i) {       long long res = t[i += n];       for (i /= 2; i; i /= 2) {         res += t[i];       }       return res;     }     void set(long long l, long long r, long long x) {       for (l += n, r += n; l <= r; l /= 2, r /= 2) {         if (l & 1) t[l++] += x;         ;         if (~r & 1) t[r--] += x;       }     }   };   long long gcdex(long long a, long long b, long long& x, long long& y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = gcdex(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   long long mypow(long long a, long long b = Mod - 2, long long k = Mod) {     if (b == 0) return 1;     long long tmp = mypow(a, b / 2, k);     if ((b % 2) == 1)       return mul(tmp, tmp, a);     else       return mul(tmp, tmp);   }   long long mypow2(long long a, long long m = Mod) {     long long x, y;     long long g = gcdex(a, m, x, y);     x = (x % m + m) % m;     return x;   }   int32_t main() {     boostIO();     long long T;     cin >> T;     for (long long t = 0; t < T; ++t) {       long long n;       cin >> n;       vector<long long> A(n);       long long Sum = 0;       long long Xor = 0;       for (long long i = 0; i < (n); ++i) {         cin >> A[i];         Sum += A[i];         Xor ^= A[i];       }       vector<long long> ans;       bitset<64> B = Xor;       long long Add = 0;       for (long long i = 1; i < 55; ++i) {         if (B[i] == 0) {           Add += (1LL << i);         }       }       if (B[0] == 1) Add += 1;       ans.push_back(Add);       Sum += Add;       Xor ^= Add;       long long dif = Xor * 2 - Sum;       ans.push_back(dif / 2);       ans.push_back(dif / 2);       Sum += dif / 2;       Sum += dif / 2;       Xor ^= dif / 2;       Xor ^= dif / 2;       if (Xor * 2 != Sum) {         cerr <<  ERROR  <<   n ;         return 0;       }       cerr <<  ans =  ;       cout << ans.size() <<   n ;       for (auto x : ans) {         cout << x <<    ;       }       cout <<   n ;     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   const int Maxn=2021;   const int Mod=998244353;   int C[Maxn<<1|5][Maxn<<1|5];   int w[Maxn+5][Maxn+5];   int sum[Maxn+5][Maxn+5];   int ans;   void init(){    C[0][0]=1;    for(int i=1;i<=(Maxn<<1);i++){     C[i][0]=C[i][i]=1;     for(int j=1;j<i;j++){      C[i][j]=(C[i-1][j]+C[i-1][j-1])%Mod;     }    }   }   void solve(int n,int m,int k){    for(int i=1;i<=n;i++){     for(int j=1;j<=m;j++){      int t_1=C[i-1+m-j][m-j],t_2=C[i+j-1][j-1];      w[i][j]=1ll*t_1*t_2%Mod;      sum[i][j]=(sum[i][j-1]+w[i][j])%Mod;     }    }    for(int i=1;i<n;i++){     for(int j=1;j<m;j++){      ans=(ans+1ll*w[i][j]*sum[n-i][m-j])%Mod;      if(k==1){       ans=(ans-1ll*w[i][j]*w[n-i][m-j]%Mod+Mod)%Mod;      }     }    }   }   int main(){    init();    int n,m;    scanf( %d%d ,&n,&m);    solve(n,m,1);    solve(m,n,0);    ans=(ans<<1)%Mod;    printf( %d n ,ans);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N_ = 1050;   int N;   int P[N_];   char S[N_];   int group[N_];   int find_group(int x) {     if (x == group[x]) return x;     return group[x] = find_group(group[x]);   }   void merge_group(int a, int b) {     a = find_group(a);     b = find_group(b);     if (a != b) group[a] = b;   }   vector<int> pos[N_];   int cnt[N_];   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) group[i] = i;     for (int i = 1; i <= N; i++) scanf( %d , &P[i]);     for (int i = 1; i <= N; i++) {       scanf( %s , S + 1);       for (int j = 1; j <= N; j++)         if (S[j] ==  1 ) merge_group(i, j);     }     for (int i = 1; i <= N; i++) pos[find_group(i)].push_back(P[i]);     for (int i = 1; i <= N; i++) sort(pos[i].begin(), pos[i].end());     for (int i = 1; i <= N; i++) {       int g = find_group(i);       printf( %d%c , pos[g][cnt[g]++], (i == N) ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a, b, c, d, n, i, cnt = 0, snt = 0;   float f, flo, fload = 0;   string s, h, o, name;   int main() {     ios_base::sync_with_stdio(0);     setlocale(LC_ALL,  Russian );     ;     string t;     size_t i;     getline(cin, t,   n );     while ((i = t.find(   )) != string::npos) t.erase(i, 1);     s = t;     reverse(s.begin(), s.end());     for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);     for (int i = 0; i < s.size(); i++) {       if (s[i] >= 65 and s[i] <= 122) {         if (s[i] ==  a  or s[i] ==  e  or s[i] ==  u  or s[i] ==  i  or             s[i] ==  y  or s[i] ==  o ) {           cout <<  YES ;           ;           return 0;           ;         } else {           cout <<  NO ;           ;           return 0;           ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = int(3e5) + 5, inf = int(1e9) + 5;   int H[maxn], sz[maxn], start[maxn], en[maxn], res[maxn];   pair<int, int> st[4 * maxn];   vector<pair<pair<int, int>, int>> Q;   vector<int> dis, graph[maxn];   inline int left(int node) { return (node << 1); }   inline int right(int node) { return (node << 1) + 1; }   void upd(int node, int L, int R, int idx, pair<int, int> v) {     if (L == R) {       st[node] = v;     } else {       if (idx <= (L + R) / 2)         upd(left(node), L, (L + R) / 2, idx, v);       else         upd(right(node), (L + R) / 2 + 1, R, idx, v);       st[node] = max(st[left(node)], st[right(node)]);     }   }   pair<int, int> qry(int node, int L, int R, int a, int b) {     if (a > R || b < L)       return {-inf, -inf};     else if (a <= L && R <= b)       return st[node];     else       return max(qry(left(node), L, (L + R) / 2, a, b),                  qry(right(node), (L + R) / 2 + 1, R, a, b));   }   void dfs(int node, int ht) {     sz[node] = 1, H[node] = ht;     start[node] = int(dis.size());     dis.push_back(node);     for (auto it : graph[node]) {       dfs(it, ht + 1);       sz[node] += sz[it];     }     en[node] = int(dis.size()) - 1;   }   int main(void) {     int n, q, p, node;     scanf( %d%d , &n, &q);     for (int i = 0; i < 4 * maxn; i++) st[i] = {-inf, -inf};     for (int i = 1; i < n; i++) {       scanf( %d , &p);       p--;       graph[p].push_back(i);     }     dfs(0, 0);     for (int i = 0; i < q; i++) {       scanf( %d , &node);       node--;       Q.push_back({{sz[node] / 2, node}, i});     }     vector<pair<int, int>> szs;     for (int i = 0; i < n; i++) szs.push_back({sz[i], i});     sort(szs.rbegin(), szs.rend()), sort(Q.rbegin(), Q.rend());     int ptr = 0;     for (auto it : Q) {       if (ptr != n) {         while (szs[ptr].first > it.first.first) {           int node = szs[ptr].second;           upd(1, 0, int(dis.size()) - 1, start[node], {H[node], node});           ptr++;           if (ptr == n) break;         }       }       res[it.second] = qry(1, 0, int(dis.size()) - 1, start[it.first.second],                            en[it.first.second])                            .second;     }     for (int i = 0; i < q; i++) printf( %d n , res[i] + 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, a, c1 = 0, c2 = 0;     vector<int> v;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       if (x & 1) {         x /= 2;         for (int j = 1; j <= x; j++) {           cin >> a;           c1 += a;         }         cin >> a;         v.push_back(a);         for (int j = 1; j <= x; j++) {           cin >> a;           c2 += a;         }       } else {         x /= 2;         for (int j = 1; j <= x; j++) {           cin >> a;           c1 += a;         }         for (int j = 1; j <= x; j++) {           cin >> a;           c2 += a;         }       }     }     sort(v.begin(), v.end());     int i = v.size() - 1;     while (i >= 0) {       c1 += v[i];       i--;       if (i == -1) break;       c2 += v[i];       i--;     }     cout << c1 <<     << c2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     long long x, y;     Point() {}     Point(long long a, long long b) : x(a), y(b) {}     Point operator-(Point b) { return Point(x - b.x, y - b.y); }   };   long long cross(Point x, Point y) { return x.x * y.y - x.y * y.x; }   Point st[100005];   int top;   long long calc(Point x, long long k) { return x.x * k + x.y; }   void insert(Point p) {     while (top > 1 && cross(p - st[top], st[top] - st[top - 1]) >= 0) top--;     st[++top] = p;   }   int a[100005], b[100005], num[100005];   long long up[100005];   void convex(int n, int m, long long lb, long long rb) {     long long s = 0;     for (int i = 1; i <= n; i++) s += a[i];     top = 0;     for (int i = n; i >= 0; i--) {       insert(Point(n - i, s));       s -= a[i];     }     int r = 1;     for (int i = 1; i <= m; i++) {       while (r < top && calc(st[r + 1], m - i) <= calc(st[r], m - i)) r++;       up[i] = max(up[i], lb - calc(st[r], m - i));     }     s = 0;     for (int i = 1; i <= n; i++) s += b[i];     top = 0;     for (int i = n; i >= 0; i--) {       insert(Point(n - i, s));       s -= b[i];     }     r = 1;     for (int i = 1; i <= m; i++) {       while (r < top && calc(st[r + 1], m - i) <= calc(st[r], m - i)) r++;       up[i] = max(up[i], rb - calc(st[r], m - i));     }   }   bool solve1(int n, long long rb) {     long long s1 = 0, s2 = 0, maxn = 0;     int last2 = 0;     for (int i = 1; i <= n; i++)       if (num[i] != -1) {         if (maxn > num[i]) return 0;         s1 += num[i];         s2 += (long long)(i - last2 - 1) * (num[i] - maxn);         if (s1 < up[i]) {           if (s1 + s2 < up[i]) return 0;           s2 -= up[i] - s1;           s1 = up[i];         }         last2 = i;         maxn = num[i];       } else {         s1 += maxn;         if (s1 < up[i]) {           if (s1 + s2 >= up[i]) {             s2 -= up[i] - s1;             s1 = up[i];           } else {             long long v = up[i] - s1 - s2, t = (v + i - last2 - 1) / (i - last2);             maxn += t;             s1 = up[i];             s2 = t * (i - last2) - v;           }         }       }     return s1 <= rb && (s1 + s2 >= rb || num[n] != -1);   }   int solve2(int n, int k, long long rb) {     long long s1 = 0, s2 = 0, maxn = 0;     int last2 = 0;     for (int i = 1; i <= n - k; i++)       if (num[i] != -1) {         s1 += num[i];         s2 += (long long)(i - last2 - 1) * (num[i] - maxn);         if (s1 < up[i]) {           s2 -= up[i] - s1;           s1 = up[i];         }         last2 = i;         maxn = num[i];       } else {         s1 += maxn;         if (s1 < up[i]) {           if (s1 + s2 >= up[i]) {             s2 -= up[i] - s1;             s1 = up[i];           } else {             long long v = up[i] - s1 - s2, t = (v + i - last2 - 1) / (i - last2);             maxn += t;             s1 = up[i];             s2 = t * (i - last2) - v;           }         }       }     long long t = -1;     for (int i = n - k + 1; i <= n; i++)       if (num[i] != -1) {         if (t == -1)           t = num[i];         else if (t != num[i])           return -1;       }     if (t == -1) t = (rb - s1) / k;     long long v = rb - (long long)t * k;     if (s1 > v || maxn > t) return -1;     return (s1 + s2 + (long long)(n - k - last2) * (t - maxn) >= v) ? t : -1;   }   int main() {     memset(num, 255, sizeof(num));     int n, m;     scanf( %d%d , &n, &m);     long long lb = 0, s = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i], &b[i]);       lb += a[i];       s += b[i];     }     sort(a + 1, a + n + 1);     sort(b + 1, b + n + 1);     int k;     scanf( %d , &k);     for (int i = 1; i <= k; i++) {       int x, y;       scanf( %d%d , &x, &y);       num[m - x + 1] = y;     }     long long rb = 0;     scanf( %lld , &rb);     if (lb > rb || s < rb) {       puts( -1 -1 );       return 0;     }     convex(n, m, lb, rb);     if (!solve1(m, rb)) {       puts( -1 -1 );       return 0;     }     int l = 1, r = m;     while (l < r) {       int mid = ((l + r) >> 1) + 1;       if (solve2(m, mid, rb) != -1)         l = mid;       else         r = mid - 1;     }     int ans = solve2(m, l, rb);     printf( %d %d n , l, ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     long q;     scanf( %ld , &q);     while (q--) {       long n;       scanf( %ld , &n);       long div = n / 4;       if (n <= 3 || n == 5 || n == 7 || n == 11) {         puts( -1 );         continue;       }       if (n & 1) {         --div;       }       printf( %ld n , div);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int mynum(int x, int y) {     int temp;     stringstream ss;     ss << (s.substr(x, y - x));     ss >> temp;     if (temp > 1000000 || (y - x != 1 && s[x] ==  0 ) || x == y) return -1;     return temp;   }   int main() {     int mx = -1, x, y, z;     cin >> s;     for (int i = 0; i < s.length(); i++) {       for (int j = i + 1; j < s.length(); j++) {         x = mynum(0, i);         y = mynum(i, j);         z = mynum(j, s.length());         if (x != -1 && y != -1 && z != -1 && x + y + z > mx) mx = x + y + z;       }     }     cout << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 * 100 + 5;   int n, l, k;   long long a[maxn];   void input() {     scanf( %d %d , &n, &l);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     scanf( %d , &k);   }   long long first() {     long long javab = 0, MAX = 0, x;     int y;     set<pair<long long, int> > second, t;     for (int i = 0; i < l; i++)       if (a[i] < 0) second.insert(make_pair(a[i], i));     while ((int)second.size() > k) {       t.insert(*(--second.end()));       second.erase(--second.end());     }     for (int i = 0; i < l; i++) {       if (second.find(make_pair(a[i], i)) == second.end())         javab += a[i];       else         javab -= a[i];     }     MAX = abs(javab);     for (int i = l; i < n; i++) {       if (second.find(make_pair(a[i - l], i - l)) == second.end()) {         t.erase(make_pair(a[i - l], i - l));         javab -= a[i - l];       } else {         javab += a[i - l];         second.erase(make_pair(a[i - l], i - l));       }       if (a[i] < 0) {         javab -= a[i];         second.insert(make_pair(a[i], i));       } else         javab += a[i];       if ((int)t.size()) {         x = t.begin()->first;         y = t.begin()->second;         javab -= (2 * x);         second.insert(make_pair(x, y));         t.erase(make_pair(x, y));       }       while ((int)second.size() > k) {         x = (--second.end())->first;         y = (--second.end())->second;         t.insert(make_pair(x, y));         javab += (2 * x);         second.erase(make_pair(x, y));       }       MAX = max(MAX, javab);     }     return MAX;   }   void output() {     long long javab = first();     for (int i = 0; i < n; i++) a[i] *= -1;     printf( %lld n , max(javab, first()));   }   int main() {     ios::sync_with_stdio(false);     input();     output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     return (b == 0LL ? a : gcd(b, a % b));   }   long double dist(long double x, long double arayikhalatyan, long double x2,                    long double y2) {     return sqrt((x - x2) * (x - x2) +                 (arayikhalatyan - y2) * (arayikhalatyan - y2));   }   long long int S(long long int a) { return (a * (a + 1LL)) / 2LL; }   mt19937 rnd(363542);   char vow[] = { a ,  e ,  i ,  o ,  u };   int dx[] = {0, -1, 0, 1, -1, -1, 1, 1, 0};   int dy[] = {-1, 0, 1, 0, -1, 1, -1, 1, 0};   const int N = 5e5 + 30;   const long long int mod = 998244353;   const long double pi = acos(-1);   const long double e = 1e-13;   long long int bp(long long int a, long long int b = mod - 2LL) {     long long int ret = 1;     while (b) {       if (b & 1) ret *= a, ret %= mod;       a *= a;       a %= mod;       b >>= 1;     }     return ret;   }   ostream& operator<<(ostream& c, pair<int, int> a) {     c << a.first <<     << a.second;     return c;   }   struct pt {     long long int x, y;     int ind;     int bl;     bool operator==(const pt& a) { return ind == a.ind; }     bool operator<(const pt& b) {       if (x == b.x) return y < b.y;       return x < b.x;     }   };   int n, m, t, k;   vector<int> g[N];   int sz[N];   unordered_map<int, int> mp[N];   bool stg(int v) {     vector<int> fp;     for (int p : g[v])       if (sz[p] >= k - 1) fp.push_back(p);     for (int i = 0; i < fp.size(); i++)       for (int j = i + 1; j < fp.size(); j++)         if (!mp[fp[i]][fp[j]]) return 0;     return 1;   }   void cl() {     for (int i = 1; i <= n; i++) {       mp[i].clear();       g[i].clear();       sz[i] = 0;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> t;     while (t--) {       cin >> n >> m >> k;       for (int i = 0; i < m; i++) {         int a, b;         cin >> a >> b;         mp[a][b] = 1;         mp[b][a] = 1;         g[a].push_back(b);         g[b].push_back(a);       }       if (k > 500) {         cout << -1 << endl;         cl();         continue;       }       queue<int> q, q1;       for (int i = 1; i <= n; i++) {         sz[i] = g[i].size();         if (sz[i] < k) q.push(i);       }       int qn = n;       while (q.size()) {         int v = q.front();         qn--;         sz[v] = 0;         q.pop();         for (auto p : g[v]) {           sz[p]--;           if (sz[p] == k - 1) q.push(p);         }       }       if (qn) {         cout << 1 <<     << qn << endl;         for (int i = 1; i <= n; i++)           if (sz[i] >= k) cout << i <<    ;         cl();         cout <<   n ;         continue;       }       for (int i = 1; i <= n; i++) {         sz[i] = g[i].size();         if (sz[i] < k - 1)           q.push(i);         else if (sz[i] == k - 1)           q1.push(i);       }       bool bl = 0;       while ((int)q.size() + (int)q1.size()) {         if (q.size()) {           int v = q.front();           sz[v] = 0;           q.pop();           for (auto p : g[v]) {             sz[p]--;             if (sz[p] == k - 1)               q1.push(p);             else if (sz[p] == k - 2)               q.push(p);           }         } else {           int v = q1.front();           q1.pop();           if (sz[v] < k - 1) {             continue;           }           if (stg(v)) {             cout << 2 << endl;             cout << v <<    ;             for (int p : g[v])               if (sz[p] >= k - 1) cout << p <<    ;             cout <<   n ;             bl = 1;             break;           }           q.push(v);         }       }       if (!bl) cout << -1 << endl;       cl();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int size = 31;   const int mod = 1e8 + 7;   long long hash1[maxn], jec[maxn], hash2[maxn];   int cnt[maxn];   char s[maxn];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s + 1);     jec[0] = 1;     for (int i = 1; i <= n; ++i) jec[i] = jec[i - 1] * size % mod;     for (int i = 1; i <= n; ++i) cnt[i] = cnt[i - 1] + !(s[i] -  0 );     for (int i = 1; i <= n; ++i) {       if (s[i] ==  0 ) {         hash1[i] = hash1[i - 1] * size + ((i & 1) +  0 );         hash2[i] = hash2[i - 1] * size + !(i & 1) +  0 ;         hash1[i] %= mod;         hash2[i] %= mod;       } else {         hash1[i] = hash1[i - 1];         hash2[i] = hash2[i - 1];       }     }     int q;     scanf( %d , &q);     while (q--) {       int l, r, len;       scanf( %d%d%d , &l, &r, &len);       long long p, pp;       if (l & 1)         p = (hash1[l + len - 1] -              hash1[l - 1] * jec[cnt[l + len - 1] - cnt[l - 1]] % mod + mod) %             mod;       else         p = (hash2[l + len - 1] -              hash2[l - 1] * jec[cnt[l + len - 1] - cnt[l - 1]] % mod + mod) %             mod;       if (r & 1)         pp = (hash1[r + len - 1] -               hash1[r - 1] * jec[cnt[r + len - 1] - cnt[r - 1]] % mod + mod) %              mod;       else         pp = (hash2[r + len - 1] -               hash2[r - 1] * jec[cnt[r + len - 1] - cnt[r - 1]] % mod + mod) %              mod;       if (p == pp)         printf( Yes n );       else         printf( No n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int FFTMOD = 119 << 23 | 1;   const int INF = (int)1e9 + 23111992;   const long long LINF = (long long)1e18 + 23111992;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return val < a ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   inline unsigned long long isqrt(unsigned long long k) {     unsigned long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }   inline int sign(long double x, long double y) { return sign(x - y); }   mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());   inline int mrand() { return abs((int)mt()); }   void chemthan() {     int n;     cin >> n;     vector<long long> a(n);     for (int i = (0); i < (n); ++i) cin >> a[i];     vector<int> vals;     for (int i = (0); i < (n); ++i) vals.push_back(i);     vector<int> pv_order(n), dp(n + 1);     for (int k = (1); k < (63); ++k) {       sort((vals).begin(), (vals).end(), [&](int u, int v) {         return make_pair(a[u] & (1LL << k) - 1, pv_order[u]) <                make_pair(a[v] & (1LL << k) - 1, pv_order[v]);       });       int x = 0, y = 0;       for (int i = (0); i < (n); ++i) {         if (!(((a[i]) >> (k - 1)) & 1)) {           x++;         }       }       vector<int> st(n + 1 << 1);       auto upd = [&](int p, int val) {         for (st[p += n + 1] = val; 1 < p;)           p >>= 1, st[p] = min(st[p << 1], st[p << 1 | 1]);       };       auto query = [&](int l, int r) {         int res = INF;         for (l += n + 1, r += n + 2; l < r; l >>= 1, r >>= 1) {           if (l & 1) chkmin(res, st[l++]);           if (r & 1) chkmin(res, st[--r]);         }         return res;       };       for (int i = (0); i < (n + 1); ++i) upd(i, dp[i]);       vector<int> ndp(n + 1);       int lo = 0;       int hi = n;       if (1 < k && !(((a[vals[0]]) >> (k - 1)) & 1)) {         hi = pv_order[vals[0]] - 1;       }       ndp[0] = x + (1 < k ? query(lo, hi) : 0);       for (int i = (1); i < (n + 1); ++i) {         int lo = pv_order[vals[i - 1]];         int hi = n;         if (i < n && (((a[vals[i - 1]]) >> (k - 1)) & 1) ==                          (((a[vals[i]]) >> (k - 1)) & 1)) {           hi = pv_order[vals[i]] - 1;         }         if (!(((a[vals[i - 1]]) >> (k - 1)) & 1)) {           x--;           ndp[i] = x + (1 < k ? query(lo, hi) : 0);           if (i == n || (((a[vals[i]]) >> (k - 1)) & 1)) {             chkmin(ndp[i], n - y + (1 < k ? query(0, hi) : 0));           }         } else {           y++;           ndp[i] = n - y + (1 < k ? query(lo, hi) : 0);         }       }       for (int i = (0); i < (n); ++i) {         pv_order[vals[i]] = i + 1;       }       dp = ndp;     }     cout << dp.back() <<   n ;   }   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(0), cin.tie(0);     if (argc > 1) {       assert(freopen(argv[1],  r , stdin));     }     if (argc > 2) {       assert(freopen(argv[2],  wb , stdout));     }     chemthan();     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const pair<int, int> queen[8] = {pair<int, int>(-1, 0), pair<int, int>(-1, 1),                                    pair<int, int>(0, 1),  pair<int, int>(1, 1),                                    pair<int, int>(1, 0),  pair<int, int>(1, -1),                                    pair<int, int>(0, -1), pair<int, int>(-1, -1)};   const int maxN = 1e5 + 11;   int N, A[maxN], BIT[maxN];   vector<int> pos[maxN];   pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {     return pair<int, int>(a.first + b.first, a.second + b.second);   }   void update(int x, int v) {     for (int i = x; i <= N; i += i & (i ^ (i - 1))) BIT[i] += v;   }   int get_BIT(int x) {     int res = 0;     for (int i = x; i >= 1; i -= i & (i ^ (i - 1))) res += BIT[i];     return res;   }   int get_BIT(int l, int r) { return get_BIT(r) - get_BIT(l - 1); }   int main() {     cin >> N;     for (int i = 1; i <= N; i++) cin >> A[i], pos[A[i]].push_back(i);     long long ans = 0;     for (int i = 1; i <= N; i++) update(i, 1);     for (int i = 1, p = 1; i <= 1e5; i++) {       if (pos[i].empty()) continue;       int q = lower_bound(pos[i].begin(), pos[i].end(), p) - pos[i].begin();       for (int j = 0; j < (int)pos[i].size(); j++) {         q %= (int)pos[i].size();         if (p <= pos[i][q])           ans += get_BIT(p, pos[i][q]);         else           ans += get_BIT(1, pos[i][q]) + get_BIT(p, N);         update(pos[i][q], -1);         p = pos[i][q];         q++;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long N = 10000000000000000;   int points = 0;   int main() {     long long xo, yo, ax, ay, bx, by;     cin >> xo >> yo >> ax >> ay >> bx >> by;     long long x, y, t;     cin >> x >> y >> t;     long long X[100], Y[100];     X[0] = xo, Y[0] = yo;     for (int i = 1; i < 55; i++) {       X[i] = ax * X[i - 1] + bx;       Y[i] = ay * Y[i - 1] + by;       points++;       if (X[i] >= N || Y[i] >= N) break;     }     long long maxi = 0;     for (int i = 0; i <= points; i++) {       for (int j = 0; j <= points; j++) {         long long tmpx = X[i], tmpy = Y[i], tt = t, ans = 0;         tt -= abs(X[i] - x) + abs(y - Y[i]);         if (tt >= 0) ans = 1;         int k = i + 1;         if (i > j) k = i - 1;         for (;;) {           if ((k > i && k > j) || (k < i && k < j)) break;           long long curx = X[k], cury = Y[k];           tt -= abs(tmpx - curx) + abs(tmpy - cury);           tmpx = curx, tmpy = cury;           if (tt < 0) break;           ans++;           if (i <= j)             k++;           else             k--;         }         maxi = max(maxi, ans);       }     }     cout << maxi << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int maxn = 1500 + 5;   int count(vector<int>& rec, vector<int>& temp, int l, int h) {     if (h - l < 1) return 0;     int m = (l + h) / 2;     int ans = count(rec, temp, l, m) + count(rec, temp, m + 1, h);     int a = l, b = m + 1;     int i = l;     for (i = l; i < h; ++i) {       if (a > m || b > h) break;       if (temp[a] > temp[b]) {         ans += m - a + 1;         rec[i] = temp[b];         ++b;       } else {         rec[i] = temp[a];         ++a;       }     }     while (a <= m) {       rec[i++] = temp[a++];     }     while (b <= h) {       rec[i++] = temp[b++];     }     for (int i = l; i <= h; ++i) {       temp[i] = rec[i];     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> pr(n), tem(n);     for (int i = 0; i < n; ++i) {       cin >> pr[i];       tem[i] = pr[i];     }     int toi = count(pr, tem, 0, n - 1);     toi %= 2;     int m;     cin >> m;     while (m--) {       int l, r;       cin >> l >> r;       int le = r - l + 1;       int res = le * (le - 1) / 2;       toi += res;       toi %= 2;       if (toi == 0)         cout <<  even n ;       else         cout <<  odd n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e8 + 5;   long long MAX = 1e9;   long long MOD = 1e9 + 7;   long long Mod = 1e9 + 7;   double EPS = 0.0001;   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }   const int dx[] = {1, -1, 0, 0, 0, 0};   const int dy[] = {0, 0, 1, -1, 0, 0};   int main() {     int wait;     long long n, k;     int prin = 0;     scanf( %I64d , &n);     scanf( %I64d , &k);     long long check = k * (k - 1);     if (check < n) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     for (long long i = 1; i < k + 1; i++) {       for (long long j = i + 1; j < k + 1; j++) {         cout << i <<     << j << endl;         prin++;         if (prin == n) return 0;         cout << j <<     << i << endl;         prin++;         if (prin == n) return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000LL * 1000000LL * 1000000LL;   int n, k;   int tyl, l, sum;   int T[1000][1000];   int main() {     scanf( %d %d , &n, &k);     tyl = n * n;     for (int i = 1; i <= n; i++) {       for (int j = n; j >= k; j--) {         T[i][j] = tyl;         tyl--;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (j == k) {           sum += T[i][j];         }         if (T[i][j] == 0) {           l++;           T[i][j] = l;         }       }     }     printf( %d n , sum);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         printf( %d  , T[i][j]);       }       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     vector<long long> cnt(26, 0);     for (auto x : s) {       cnt[x -  a ]++;     }     deque<long long> d;     for (long long i = 0; i < 26; i++) {       if (cnt[i]) {         d.push_back(i);       }     }     deque<long long> ans;     if ((long long)d.size() == 2) {       if (d[0] + 1 == d[1]) {         cout <<  No answer  <<   n ;         return;       }       ans = d;     } else if ((long long)d.size() == 3) {       if (d[0] + 1 == d[1] && d[1] + 1 == d[2]) {         cout <<  No answer  <<   n ;         return;       } else if (d[0] + 1 == d[1]) {         ans.push_back(d[0]);         ans.push_back(d[2]);         ans.push_back(d[1]);       } else {         ans.push_back(d[1]);         ans.push_back(d[0]);         ans.push_back(d[2]);       }     } else {       long long fl = 1;       while ((long long)d.size() > 1) {         if (fl) {           ans.push_back(d.front());           d.pop_front();         } else {           ans.push_back(d.back());           d.pop_back();         }         fl ^= 1;       }       ans.push_front(d[0]);     }     for (auto x : ans) {       for (long long i = 0; i < cnt[x]; i++) {         cout << (char)(x +  a );       }     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tc;     tc = 1;     cin >> tc;     for (int i = 1; i <= tc; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, -1, 0, 1};   int dy[] = {1, 0, -1, 0};   int c[2010][2010], edge[2010];   long double s[2010], C[2010][2010];   int main(int argc, char *argv[]) {     int n, k;     scanf( %d%d , &n, &k);     for (int i = (1); i <= (n); ++i) {       C[i][0] = 1;       for (int j = (1); j <= (i); ++j) C[i][j] = C[i][j - 1] * (i - j + 1) / j;     }     for (int i = (1); i <= (n - 1); ++i)       for (int j = (i + 1); j <= (n); ++j) {         scanf( %d , &c[i][j]);         c[j][i] = c[i][j];       }     long double m = 0;     for (int i = (1); i <= (n); ++i) {       edge[i] = 0;       for (int j = (1); j <= (n); ++j)         if (c[i][j] >= 0 && i != j) edge[i]++;       s[i] = 0;       if (edge[i] < k) continue;       s[i] = C[edge[i]][k];       m += s[i];     }     long double ans = 0;     for (int i = (1); i <= (n); ++i) {       if (edge[i] <= 0) continue;       long double p = (s[i] * k) / (m * edge[i]);       long double sum = 0;       for (int j = (1); j <= (n); ++j)         if (c[i][j] >= 0 && i != j) sum += (long double)c[i][j];       ans += sum * p;     }     ans = ans + 1e-5;     printf( %I64d n , (long long)ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, h, a;     vector<int> home, away;     cin >> n;     vector<int> cnt(100000, 0);     vector<int> ans_home(n, 0);     vector<int> ans_away(n, 0);     for (int i = 0; i < n; i++) {       cin >> h >> a;       home.push_back(h);       away.push_back(a);     }     for (int i = 0; i < n; i++) cnt[home[i] - 1]++;     for (int i = 0; i < n; i++) {       ans_home[i] = n - 1 + cnt[away[i] - 1];       ans_away[i] = 2 * (n - 1) - ans_home[i];     }     for (int i = 0; i < n; i++) cout << ans_home[i] <<     << ans_away[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const int inf = 1e9;   const int N = 1e5;   vector<long long int> tot(N);   vector<bool> vis(N);   vector<int> adj[N];   void dfs(int node) {     vis[node] = true;     for (auto &i : adj[node]) {       if (!vis[i]) {         dfs(i);         tot[node] += tot[i];       }     }     if ((int)adj[node].size() == 1 && node != 0) tot[node]++;   }   void solve() {     vector<tuple<int, int, long long int, int>> vc;     int n, u, v, x;     long long int s, w;     cin >> n >> s;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v >> w >> x;       u--, v--;       adj[u].push_back(v);       adj[v].push_back(u);       vc.push_back({u, v, w, x});     }     dfs(0);     int cnt = 0;     long long int sum = 0;     priority_queue<tuple<long long int, long long int, long long int>> q1, q2;     for (auto &i : vc) {       u = get<0>(i);       v = get<1>(i);       w = get<2>(i);       x = get<3>(i);       long long int tp = min(tot[u], tot[v]);       sum += tp * w;       if (x == 1)         q1.push({tp * w - tp * (w / 2), tp, w / 2});       else         q2.push({tp * w - tp * (w / 2), tp, w / 2});     }     long long int r1, r2, r3;     while (sum > s) {       tuple<long long int, long long int, long long int> x;       tuple<long long int, long long int, long long int> y;       r1 = r2 = r3 = 0;       if (!q1.empty()) x = q1.top();       if (!q2.empty()) y = q2.top();       if (!q1.empty()) {         long long int a = get<0>(x);         long long int b = get<1>(x);         long long int c = get<2>(x);         r1 = a;         q1.pop();         if (q1.empty())           r3 = b * c - b * (c / 2);         else {           r3 = max(get<0>(q1.top()), b * c - b * (c / 2));         }         q1.push(x);       }       if (!q2.empty()) r2 = get<0>(y);       if (r1 >= r2 || sum - r1 <= s) {         cnt++;         long long int a = get<0>(x);         long long int b = get<1>(x);         long long int c = get<2>(x);         sum -= a;         q1.pop();         q1.push({b * c - b * (c / 2), b, c / 2});       } else {         if (r1 + r3 >= r2) {           long long int a = get<0>(x);           long long int b = get<1>(x);           long long int c = get<2>(x);           sum -= a;           q1.pop();           q1.push({b * c - b * (c / 2), b, c / 2});           cnt++;         } else {           long long int a = get<0>(y);           long long int b = get<1>(y);           long long int c = get<2>(y);           sum -= a;           q2.pop();           q2.push({b * c - b * (c / 2), b, c / 2});           cnt += 2;         }       }     }     cout << cnt <<   n ;     for (int i = 0; i < n; i++) {       tot[i] = 0;       vis[i] = false;       adj[i].clear();     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   void Get(int &T) {     char C;     bool F = 0;     for (; C = getchar(), C <  0  || C >  9 ;)       if (C ==  - ) F = 1;     for (T = C -  0 ; C = getchar(), C >=  0  && C <=  9 ; T = T * 10 + C -  0 )       ;     F && (T = -T);   }   int L[2005][2005];   int R[2005][2005];   bool Rot;   int N, M, K;   int GetL(int X, int Y) {     if (L[X][Y] == Y) return Y;     return L[X][Y] = GetL(X, L[X][Y]);   }   int GetR(int X, int Y) {     if (R[X][Y] == Y) return Y;     return R[X][Y] = GetR(X, R[X][Y]);   }   void Init() {     Get(N);     Get(M);     Get(K);     if (N > M) {       std::swap(N, M);       Rot = 1;     }     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M + 1; j++) L[i][j] = R[i][j] = j;   }   int Ans;   int AnsX, AnsY;   int X0, Y0;   void Fresh(int X, int Y) {     if (X < 1 || X > N) return;     if (Y < 1 || Y > M) return;     int Dis = std::abs(X - X0) + std::abs(Y - Y0);     if (Rot) {       std::swap(X, Y);     }     if (Ans > Dis) {       Ans = Dis;       AnsX = X;       AnsY = Y;     } else if (Ans == Dis) {       if (AnsX > X) {         AnsX = X;         AnsY = Y;       } else if (AnsX == X && AnsY > Y) {         AnsX = X;         AnsY = Y;       }     }   }   void Work() {     for (int k = 1; k <= K; k++) {       Ans = 0x2f2f2f2f;       Get(X0);       Get(Y0);       if (Rot) std::swap(X0, Y0);       for (int d = 0; d <= Ans; d++) {         int X;         int Y;         if (X0 - d > 0) {           X = X0 - d;           Y = L[X][Y0];           Fresh(X, Y);           Y = R[X][Y0];           Fresh(X, Y);         }         if (X0 + d <= N) {           X = X0 + d;           Y = L[X][Y0];           Fresh(X, Y);           Y = R[X][Y0];           Fresh(X, Y);         }       }       printf( %d %d n , AnsX, AnsY);       if (Rot) {         std::swap(AnsX, AnsY);       }       L[AnsX][AnsY] = L[AnsX][AnsY - 1];       R[AnsX][AnsY] = R[AnsX][AnsY + 1];       for (int j = AnsY + 1; L[AnsX][j] != j; j++) L[AnsX][j] = L[AnsX][AnsY];       for (int j = AnsY - 1; L[AnsX][j] != j; j--) R[AnsX][j] = R[AnsX][AnsY];     }   }   int main() {     Init();     Work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f;   const double eps = 1e-6;   const long long mod = 1000000007;   inline string getstr(string &s, long long l, long long r) {     string ret =   ;     for (long long i = l; i <= r; i++) ret.push_back(s[i]);     return ret;   }   long long modpow(long long x, long long y, long long md = mod) {     long long ret = 1;     do {       if (y & 1) ret = (long long)ret * x % md;       x = (long long)x * x % md;     } while (y >>= 1);     return ret;   }   long long n, mn;   vector<pair<long long, long long> > g[3003];   long long dfs(long long x, long long p, long long cur, long long mv) {     long long ret = 0;     mn = min(mn, cur - mv);     for (auto to : g[x])       if (to.first != p) {         ret += (to.second > 0);         ret += dfs(to.first, x, cur - to.second, max(mv, cur - to.second));       }     return ret;   }   signed main() {     cin >> n;     for (long long i = 1; i < n; i++) {       long long x, y;       cin >> x >> y;       g[x].push_back(make_pair(y, -1));       g[y].push_back(make_pair(x, 1));     }     long long ans = 1e9;     for (long long i = 1; i <= n; i++) {       mn = inf;       ans = min(ans, dfs(i, -1, 0, 0) + mn);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<int, int>> vp;   int chk() {     bool ok = true;     int d = vp[2].first - vp[1].first;     for (int i = 2; i < n; i++)       if (vp[i].first - vp[i - 1].first != d) ok = false;     if (ok) {       printf( %d n , vp[0].second + 1);       exit(0);     }     d = vp[2].first - vp[0].first;     ok = true;     for (int i = 3; i < n; ++i)       if (vp[i].first - vp[i - 1].first != d) ok = false;     if (ok) {       printf( %d n , vp[1].second + 1);       exit(0);     }     d = vp[1].first - vp[0].first;     int cnt = 0, index = 0;     ok = true;     for (int i = 1; i < n; i++) {       if (vp[i].first - vp[i - 1].first == d) continue;       cnt++;       if (i == n - 1 or vp[i + 1].first - vp[i - 1].first != d) ok = false;       index = vp[i].second;       i++;     }     if (ok and cnt == 1) {       cout << index + 1 << endl;       exit(0);     }   }   int main() {     scanf( %d , &n);     vp.resize(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &vp[i].first);       vp[i].second = i;     }     sort(begin(vp), end(vp));     chk();     if (n < 4) return !printf( 1 n );     reverse(begin(vp), end(vp));     chk();     cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int buff1, buff2;   void solution(vector<int> v) {     map<int, int> counter;     for (int n : v) counter[n]++;     vector<int> counts;     for (auto it : counter) {       counts.push_back(it.second);     }     sort(counts.begin(), counts.end(), greater<int>());     int cur = INT_MAX, ret = 0;     for (int n : counts) {       if (cur <= 1) {         break;       }       cur = min(cur - 1, n);       ret += cur;     }     cout << ret << endl;   }   int main() {     int nTest;     cin >> nTest;     for (int i = 0; i < nTest; i++) {       int N;       cin >> N;       vector<int> v;       for (int i = 0; i < N; i++) {         cin >> buff1;         v.push_back(buff1);       }       solution(v);     }     return 0;   }


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


#include <bits/stdc++.h>   int ss[250000], ff[250000], cc[250000], rr[250000], ii[250000];   int compare(const void *a, const void *b) {     int i = *(int *)a;     int j = *(int *)b;     return rr[i] - rr[j];   }   int main() {     static int aa[400];     typedef int ian[400];     static ian dp_[400], dq_[400], *dp = dp_, *dq = dq_, *tmp;     int n, m, h, h_, i, r, s, f;     long long v;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) scanf( %d , &aa[i]);     for (h = 0; h < m; h++) {       scanf( %d%d%d%d , &ss[h], &ff[h], &cc[h], &rr[h]);       ss[h]--;       ff[h]--;       ii[h] = h;     }     qsort(ii, m, sizeof *ii, compare);     for (s = 0; s < n; s++)       for (f = s + 1; f < n; f++) dp[s][f] = aa[f] - aa[s];     v = 0;     for (r = 0, h_ = 0; r <= n; r++) {       while (h_ < m && rr[h = ii[h_]] == r) {         long long x;         if (v < (x = (long long)dp[ss[h]][ff[h]] * cc[h])) v = x;         h_++;       }       for (s = 0; s < n; s++) {         i = s;         for (f = s + 1; f < n; f++) {           while (i < f && dp[s][i] < aa[f] - aa[i]) i++;           dq[s][f] = aa[f] - aa[i - 1];           if (dq[s][f] > dp[s][i]) dq[s][f] = dp[s][i];         }       }       tmp = dp;       dp = dq;       dq = tmp;     }     printf( %lld n , v);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int ans;   inline int f(int n) {     int rt = 0;     for (int i = 0; n / pow(k, i) != 0; i++) rt += n / pow(k, i);     return rt;   }   void bin_search() {     int s = 1, e = n;     int m;     while (s <= e) {       m = (s + e) / 2;       if (f(m) >= n) {         e = m - 1;         ans = m;       } else         s = m + 1;     }   }   int main() {     cin >> n >> k;     bin_search();     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f[200][200], a[200], x[200], y[200], d;   int n;   long long dist(int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]); }   int main() {     cin >> n >> d;     for (int i = 2; i <= n - 1; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];     memset(f, 61, sizeof(f));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (i != j) f[i][j] = dist(i, j) * d - a[i];     for (int i = 1; i <= n; i++) f[i][i] = 0;     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) f[i][j] = min(f[i][j], f[i][k] + f[k][j]);     if (f[1][n] <= 0)       cout << 0;     else       cout << f[1][n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 4e5 + 10;   int sum[mx];   int x[mx];   int n, m;   void add(int x) {     while (x <= 2 * n + 1) {       sum[x]++;       x += x & (-x);     }   }   int query(int x) {     int ans = 0;     while (x) {       ans += sum[x];       x -= x & (-x);     }     return ans;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &x[i]);     int cnt = n + 1;     long long int a = 0, b = 0;     add(cnt);     for (int i = 1; i <= n; i++) {       if (x[i] < m)         cnt--;       else         cnt++;       a += query(cnt - 1);       add(cnt);     }     cnt = n + 1;     memset(sum, 0, sizeof(sum));     add(cnt);     for (int i = 1; i <= n; i++) {       if (x[i] <= m)         cnt--;       else         cnt++;       b += query(cnt - 1);       add(cnt);     }     printf( %I64d n , a - b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void topsort(long long int s, vector<vector<long long int>> &graph,                vector<long long int> &vis, vector<long long int> &ans) {     vis[s] = 1;     for (long long int i = 0; i < graph[s].size(); i++) {       if (vis[graph[s][i]] == 0) topsort(graph[s][i], graph, vis, ans);     }     ans.push_back(s);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     vector<long long int> v;     for (long long int i = 0; i < n; i++) {       long long int num;       cin >> num;       v.push_back(num);     }     vector<vector<long long int>> graph(n);     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < n; j++) {         if ((v[i] % 3 == 0 && v[j] == v[i] / 3) || v[j] == v[i] * 2)           graph[i].push_back(j);       }     }     vector<long long int> ans;     vector<long long int> vis(n, 0);     for (long long int i = 0; i < n; i++) {       if (vis[i] == 0) topsort(i, graph, vis, ans);     }     reverse(ans.begin(), ans.end());     for (long long int i = 0; i < ans.size(); i++) {       cout << v[ans[i]] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 11;   set<int> ans;   int n, m, len;   int a[N], b[N], c[N], p[N];   inline void manacher() {     c[0] = -2;     for (register int i = 0; i <= n + n - 2; ++i) c[++len] = b[i], c[++len] = -1;     c[len + 1] = -3;     int id = 0, mx = 0;     for (register int i = 1; i <= len; ++i) {       if (mx > i)         p[i] = min(mx - i, p[id + id - i]);       else         p[i] = 1;       while (c[i + p[i]] == c[i - p[i]]) ++p[i];       if (p[i] + i > mx) id = i, mx = i + p[i];     }   }   int main() {     scanf( %d%d , &n, &m);     for (register int i = 0; i <= n - 1; ++i) scanf( %d , a + i);     sort(a, a + n);     for (register int i = 1; i <= n; ++i)       b[i - 1] = (a[i % n] - a[i - 1] + m) % m;     for (register int i = 0; i <= n - 1; ++i) b[i + n] = b[i];     manacher();     for (int i = 2; i <= len; i += 2)       if (p[i] / 2 >= n / 2 &&           (a[(i / 2 - 1 + n) % n] + a[(i / 2 + 1) % n]) % m ==               a[i / 2 % n] * 2 % m)         ans.insert(a[i / 2 % n] * 2 % m);     if (n % 2 == 0) {       for (int i = 1; i <= len; i += 2)         if (p[i] >= n) ans.insert((a[i / 2 % n] + a[(i / 2 + 1) % n]) % m);     }     printf( %d n , ans.size());     for (auto v : ans) printf( %d  , v);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000000 + 1;   int a[MAXN], parent[MAXN], rnk[MAXN], p[10 * MAXN];   int n;   void make_set(int v) {     parent[v] = v;     rnk[v] = 0;   }   int find_set(int v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_sets(int u, int v) {     u = find_set(u);     v = find_set(v);     if (u != v) {       if (rnk[u] < rnk[v]) swap(u, v);       parent[v] = u;       if (rnk[u] == rnk[v]) ++rnk[u];     }   }   int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }   bool check(int m[3]) {     return gcd(m[0], m[1]) == 1 && gcd(m[1], m[2]) == 1 && gcd(m[0], m[2]) == 1;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       make_set(i);       p[a[i]] = i + 1;     }     sort(a, a + n);     for (int i = 2; i * i <= 2 * a[n - 1]; ++i)       for (int j = 1; j < i; ++j) {         int t[3] = {i * i - j * j, 2 * i * j, i * i + j * j};         if (!check(t)) continue;         int pos[3];         for (int k = 0; k < 3; ++k)           if (t[k] <= a[n - 1]) pos[k] = p[t[k]];         if (t[0] <= a[n - 1] && t[1] <= a[n - 1] && pos[0] && pos[1])           union_sets(pos[0] - 1, pos[1] - 1);         if (t[1] <= a[n - 1] && t[2] <= a[n - 1] && pos[1] && pos[2])           union_sets(pos[1] - 1, pos[2] - 1);         if (t[0] <= a[n - 1] && t[2] <= a[n - 1] && pos[0] && pos[2])           union_sets(pos[0] - 1, pos[2] - 1);       }     set<int> f;     for (int i = 0; i < n; ++i) f.insert(find_set(i));     printf( %d , f.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> edges;   vector<int> g[300001];   int police[300001];   int nearest[300001];   int stat[300001];   void dfs1(int beta, int baap) {     int mini = (police[beta] ? 0 : (int)1e9), minpos = (police[beta] ? beta : -1);     for (int i = 0; i < g[beta].size(); i++) {       int pota = g[beta][i];       if (pota == baap) continue;       dfs1(pota, beta);       if (mini > 1 + nearest[pota]) {         mini = 1 + nearest[pota];         minpos = stat[pota];       }     }     nearest[beta] = mini;     stat[beta] = minpos;   }   void dfs2(int beta, int baap) {     int up = (baap == -1 ? (int)1e9 : 1 + nearest[baap]);     if (up < nearest[beta]) {       nearest[beta] = up;       stat[beta] = stat[baap];     }     for (int i = 0; i < g[beta].size(); i++) {       int pota = g[beta][i];       if (pota == baap) continue;       dfs2(pota, beta);     }   }   int main() {     int n, k, d;     scanf( %d %d %d , &n, &k, &d);     for (int i = 0; i < k; i++) {       int x;       scanf( %d , &x);       police[x] = 1;     }     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d %d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);       edges.push_back(make_pair(x, y));     }     dfs1(1, -1);     dfs2(1, -1);     vector<int> ans;     for (int i = 0; i < n - 1; i++) {       int u = edges[i].first, v = edges[i].second;       if (stat[u] != stat[v]) ans.push_back(i + 1);     }     printf( %d n , (int)ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %d  , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void _split(vector<string>& vc, const string& str, char ch) {     string temp;     for (int i = 0; i <= str.size(); i++)       if (i == str.size() || str[i] == ch) {         vc.emplace_back(temp);         temp =   ;       } else {         temp += str[i];       }   }   void _output(vector<string>::iterator _) {     cerr <<   n ;     cerr.flush();   }   template <typename T, typename... Args>   void _output(vector<string>::iterator it, T val, Args... args) {     cerr << *it <<   =   << val <<      ;     _output(++it, args...);   }   const size_t MAX_N = 1000 + 5;   int n, a[MAX_N], b[MAX_N], cnt[MAX_N];   bool used[MAX_N];   inline bool check() {     int cnt = 0;     memset(used, 0, sizeof used);     for (int i = 0; i < n; i++)       if (a[i] != b[i]) cnt++;     if (cnt != 1) return false;     for (int i = 0; i < n; i++) used[a[i]] = true;     for (int i = 1; i <= n; i++)       if (!used[i]) return false;     return true;   }   int main() {     int diff_cnt = 0, i, j, k;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , a + i);     for (i = 0; i < n; i++) scanf( %d , b + i);     for (i = 0; i < n; i++) diff_cnt += a[i] != b[i];     if (!diff_cnt) {       for (i = 0; i < n; i++) cnt[a[i]]++;       for (i = 0; i < n; i++) cnt[b[i]]++;       for (j = 1; j <= n; j++)         if (cnt[j] == 4) break;       for (k = 1; k <= n; k++)         if (cnt[k] == 0) break;       for (i = 0; i < n; i++)         if (a[i] == j) {           printf( %d  , k);           break;         } else {           printf( %d  , a[i]);         }       for (; i < n; i++) printf( %d  , a[i]);     } else if (diff_cnt == 1) {       for (i = 0; i < n; i++)         if (a[i] == b[i]) cnt[a[i]]++;       for (j = 1; j <= n; j++)         if (!cnt[j]) break;       for (i = 0; i < n; i++)         if (a[i] == b[i])           printf( %d  , a[i]);         else           printf( %d  , j);     } else {       vector<int> lft, pos;       for (i = 0; i < n; i++)         if (a[i] == b[i])           cnt[a[i]]++;         else           pos.emplace_back(i);       for (i = 1; i <= n; i++)         if (!cnt[i]) lft.emplace_back(i);       for (int x : pos)         for (int l : lft)           if (l != a[x]) {             int t = a[x];             a[x] = l;             if (check()) {               for (i = 0; i < n; i++) printf( %d  , a[i]);               return 0;             }             a[x] = t;           }     }   }