#include <bits/stdc++.h>   using namespace std;   struct E {     int a, b, c;   };   struct unionfind {     vector<int> p, s;     int c;     unionfind(int n) : p(n, -1), s(n, 1), c(n) {}     int find(int a) { return p[a] == -1 ? a : find(p[a]); }     vector<pair<int *, int>> buf;     void save(int &a) { buf.emplace_back(&a, a); }     int snapshot() { return buf.size(); }     void rollback(int w) {       while (buf.size() > w) {         int *a, b;         tie(a, b) = buf.back();         buf.pop_back();         *a = b;       }     }     bool unite(int a, int b) {       a = find(a);       b = find(b);       if (a == b) return false;       if (s[a] < s[b]) swap(a, b);       save(p[b]);       save(s[a]);       p[b] = a;       s[a] += s[b];       return true;     }     bool same(int a, int b) { return find(a) == find(b); }     int sz(int a) { return s[find(a)]; }   };   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     int n, m;     cin >> n >> m;     vector<E> raw(m);     map<int, vector<pair<int, int>>> es;     for (int i = 0; i < m; ++i) {       int a, b, c;       cin >> a >> b >> c;       a--;       b--;       es[c].push_back({a, b});       raw[i] = {a, b, c};     }     map<int, vector<pair<int, vector<int>>>> qs;     int q;     cin >> q;     vector<int> ans(q, 1);     for (int i = 0; i < q; ++i) {       int k;       cin >> k;       vector<int> idx(k);       for (int j = 0; j < k; ++j) {         cin >> idx[j];         idx[j]--;       }       sort(idx.begin(), idx.end(),            [&](int a, int b) { return raw[a].c < raw[b].c; });       for (int j = 0; j < k;) {         vector<int> w;         int r = j;         while (r < k && raw[idx[r]].c == raw[idx[j]].c) {           w.push_back(idx[r++]);         }         qs[raw[idx[j]].c].emplace_back(i, w);         j = r;       }     }     unionfind uf(n);     for (auto kv : es) {       for (auto z : qs[kv.first]) {         int s = uf.snapshot();         for (auto i : z.second) {           if (!uf.unite(raw[i].a, raw[i].b)) {             ans[z.first] = 0;           }         }         uf.rollback(s);       }       for (auto e : kv.second) {         uf.unite(e.first, e.second);       }     }     for (int i = 0; i < q; ++i) {       if (ans[i])         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   long long MOD = 1000000007;   struct mi {     long long v;     explicit operator long long() const { return v; }     mi() { v = 0; }     mi(long long _v) {       v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;       if (v < 0) v += MOD;     }     friend bool operator==(const mi &a, const mi &b) { return a.v == b.v; }     friend bool operator!=(const mi &a, const mi &b) { return !(a == b); }     friend bool operator<(const mi &a, const mi &b) { return a.v < b.v; }     mi &operator+=(const mi &m) {       if ((v += m.v) >= MOD) v -= MOD;       return *this;     }     mi &operator-=(const mi &m) {       if ((v -= m.v) < 0) v += MOD;       return *this;     }     mi &operator*=(const mi &m) {       v = v * m.v % MOD;       return *this;     }     mi &operator/=(const mi &m) { return (*this) *= inv(m); }     friend mi pow(mi a, long long p) {       mi ans = 1;       assert(p >= 0);       for (; p; p /= 2, a *= a)         if (p & 1) ans *= a;       return ans;     }     friend mi inv(const mi &a) {       assert(a.v != 0);       return pow(a, MOD - 2);     }     mi operator-() const { return mi(-v); }     mi &operator++() { return *this += 1; }     mi &operator--() { return *this -= 1; }     mi operator++(int) {       mi temp;       temp.v = v++;       return temp;     }     mi operator--(int) {       mi temp;       temp.v = v--;       return temp;     }     friend mi operator+(mi a, const mi &b) { return a += b; }     friend mi operator-(mi a, const mi &b) { return a -= b; }     friend mi operator*(mi a, const mi &b) { return a *= b; }     friend mi operator/(mi a, const mi &b) { return a /= b; }     friend ostream &operator<<(ostream &os, const mi &m) {       os << m.v;       return os;     }     friend istream &operator>>(istream &is, mi &m) {       long long x;       is >> x;       m.v = x;       return is;     }   };   void solve() {     long long n;     cin >> n;     long long m;     cin >> m;     MOD = m;     vector<mi> dp(n + 1, 0);     vector<mi> suffix(n + 2, 0);     dp[n] = 1;     suffix[n] = 1;     mi sum = 0;     for (long long i = (n)-1; i >= 1; i--) {       sum = sum + dp[i + 1];       dp[i] = sum;       for (long long j = 2; j < (n + 1); j++) {         if (i * j > n)           break;         else {           mi sf = suffix[i * j] - suffix[min(i * j + j, n + 1)];           dp[i] = dp[i] + sf;         }       }       suffix[i] = suffix[i + 1] + dp[i];     }     cout << dp[1] << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       vector<int> lx(n), ly(m);       vector<int> x(k), y(k);       for (int& i : lx) cin >> i;       for (int& i : ly) cin >> i;       for (int i = 0; i < k; i++) {         cin >> x[i] >> y[i];       }       sort(lx.begin(), lx.end()), sort(ly.begin(), ly.end());       vector<int> ind(k);       iota(ind.begin(), ind.end(), 0);       auto solve = [&](vector<int>& lx, vector<int>& y, vector<int>& x) {         long long ans = 0;         for (int i = 0, j = 0; i + 1 < lx.size(); i++) {           int c = 0;           map<int, int> com;           int l = lx[i], r = lx[i + 1];           while (j < k && x[ind[j]] <= l) j++;           while (j < k && x[ind[j]] < r) {             ans += c++;             ans -= com[y[ind[j]]]++;             j++;           }         }         return ans;       };       sort(ind.begin(), ind.end(), [&](int i, int j) { return x[i] < x[j]; });       long long ans = solve(lx, y, x);       sort(ind.begin(), ind.end(), [&](int i, int j) { return y[i] < y[j]; });       ans += solve(ly, x, y);       cout << ans <<   n ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   long long int n;   int main() {     cin >> n;     long long int s(0);     long long int i = 1;     while (true) {       s += i;       if (s >= n) {         break;       }       i++;     }     long long int sk = s - n;     if (sk != 0) {       cout << i - 1 <<   n ;     } else {       cout << i <<   n ;     }     for (long long int I = 1; I <= i; I++) {       if (I == sk) {         continue;       }       cout << I <<    ;     }     cout <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, m, t;   struct node {     int l, r;   } a[20050];   int cnt[90000], ans[20050];   bool cmp(const node &a, const node &b) { return a.l < b.l; }   int main() {     scanf( %d%d%d , &n, &m, &t);     int x, y, z;     for (int i = (1); i <= (n); i++) {       scanf( %d:%d:%d , &x, &y, &z);       int _ = x * 3600 + y * 60 + z;       a[i] = (node){_, _ + t};       cnt[_]++;       cnt[_ + t]--;     }     int sum = 0, nos = 1;     for (int i = (0); i <= (86400); i++) {       sum += cnt[i];       if (sum >= m) nos = 0;       cnt[i] = 0;     }     if (nos) {       cout <<  No solution  << endl;       return 0;     }     sort(a + 1, a + n + 1, cmp);     for (int i = (1); i <= (n); i++) cnt[a[i].r]--;     sum = 0;     int num = 0, j = 0, la = 0;     for (int i = (0); i <= (86400); i++) {       sum += cnt[i];       while (j + 1 <= n && a[j + 1].l == i) {         j++;         if (sum < m) {           sum++;           ans[la = j] = ++num;         } else {           cnt[a[la].r]++;           ans[la = j] = num;         }       }     }     cout << num << endl;     for (int i = (1); i <= (n); i++) printf( %d n , ans[i]);     return 0;   }


#pragma GCC optimize( O3 , Ofast , no-stack-protector , unroll-loops , omit-frame-pointer , inline ) //Optimization flags   #pragma GCC option( arch=native , tune=native , no-zero-upper ) //Enable AVX   // #pragma GCC target( avx2 ) //Enable AVX      #include <bits/stdc++.h>      #define int long long      using namespace std;      const int MOD = 1e9 + 7;      const int MAXN = 110;      int C[MAXN];      int B[MAXN];      int T[MAXN];      int dp[MAXN][MAXN*MAXN];      int32_t main()   {       ios_base::sync_with_stdio(0);       cin.tie(0);       int N;    cin >> N;       for(int i = 1 ; i <= N ; i++)    {     cin >> C[i];    }           for(int i = 2 ; i <= N ; i++)    {     cin >> B[i];     T[i] = T[i-1]+B[i];    }       for(int i = 1 ; i <= N ; i++)    {     T[i] += T[i-1];    }       int ini = -T[N]/N - 50;    int fin = (100*N-T[N])/N + 50;       map<int,int> mp;       for(int X = ini ; X <= fin ; X++)    {     for(int j = 0 ; j <= 10000 ; j++)     {      dp[0][j] = 1;     }        for(int i = 1 ; i <= N ; i++)     {      for(int j = 0 ; j <= 10000 ; j++)      {       dp[i][j] = 0;       if(j-T[i] >= X*i)       {        int val = 0;        if(j-C[i]-1 >= 0)val = dp[i-1][j-C[i]-1];           dp[i][j] = (dp[i-1][j]+MOD-val);        dp[i][j] %= MOD;       }      }         for(int j = 1 ; j <= 10000 ; j++)      {       dp[i][j] += dp[i][j-1];       dp[i][j] %= MOD;      }     }        mp[X] = dp[N][10000];    }       int Q;    cin >> Q;       for(int i = 1 ; i <= Q ; i++)    {     int X;     cin >> X;        if(X < ini)cout << mp[ini] <<   n ;     else if(X > fin)cout << 0 <<   n ;     else cout << mp[X] <<   n ;    }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, z;     cin >> n >> m;     z = 0;     int* a = new int[n + 1];     int* s = new int[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     s[1] = a[1];     s[0] = 0;     for (int i = 2; i <= n; i++) s[i] = a[i] + s[i - 1];     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       int v = s[r] - s[l - 1];       if (v > 0) {         z += v;       }     }     cout << z << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int sum[26];   char str[5002];   char str_list[5002][5002];   int main() {     double ans = 0.0;     scanf( %s , str), n = strlen(str);     for (int i = 0; i < 26; i++) {       int cnt = 0;       int max_total = 0;       for (int j = 0; j < n; j++)         if (str[j] ==  a  + i) {           for (int k = j; k < n; k++) str_list[cnt][k - j] = str[k];           for (int k = 0; k < j; k++) str_list[cnt][k + n - j] = str[k];           cnt++;         }       for (int j = 1; j < n; j++) {         int total = 0;         for (int k = 0; k < 26; k++) sum[k] = 0;         for (int k = 0; k < cnt; k++) sum[(int)(str_list[k][j] -  a )]++;         for (int k = 0; k < 26; k++)           if (sum[k] == 1) total++;         max_total = max(max_total, total);       }       ans += 1.0 * max_total / (1.0 * n);     }     printf( %.10lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       if (n <= 3)         cout << -1 <<   n ;       else {         if (n & 1) {           for (long long i = 1; i <= n; i++) {             if (i & 1) cout << i <<    ;           }           cout << n - 3 <<     << n - 1 <<    ;           for (long long i = n - 4; i >= 1; i--) {             if ((i & 1) == 0) cout << i <<    ;           }           cout <<   n ;         } else {           for (long long i = 1; i <= n; i++) {             if ((i & 1) == 0) cout << i <<    ;           }           cout << n - 3 <<     << n - 1 <<    ;           for (long long i = n - 4; i >= 1; i--) {             if ((i & 1)) cout << i <<    ;           }           cout <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mx[4] = {1, 0, -1, 0};   int my[4] = {0, 1, 0, -1};   void dfs(int x, int y, vector<vector<char> > &b, vector<vector<int> > &val,            int &c, int &v) {     v++;     val[x][y] = c;     for (int i = 0; i < 4; i++) {       int xt = x + mx[i];       int yt = y + my[i];       if (xt >= 0 && xt < b.size() && yt >= 0 && yt < b[0].size() &&           b[xt][yt] ==  .  && val[xt][yt] == 0) {         dfs(xt, yt, b, val, c, v);       }     }   }   int main() {     int n, m;     while (cin >> n >> m) {       vector<vector<char> > board(n, vector<char>(m,  . ));       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) cin >> board[i][j];       }       vector<vector<int> > values(n, vector<int>(m, 0));       int color = 1;       vector<int> colors(n * m, 0);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (board[i][j] ==  .  && values[i][j] == 0) {             int val = 0;             dfs(i, j, board, values, color, val);             colors[color] = val;             color++;           }         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (board[i][j] ==  . ) {             cout <<  . ;             continue;           } else {             int acu = 0;             set<int> valA;             for (int k = 0; k < 4; k++) {               int xt = i + mx[k];               int yt = j + my[k];               if (xt >= 0 && xt < board.size() && yt >= 0 &&                   yt < board[0].size() && !valA.count(values[xt][yt])) {                 acu += colors[values[xt][yt]];                 valA.insert(values[xt][yt]);               }             }             cout << (acu + 1) % 10;           }         }         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   bool isOk(char c, int v) { return v == (c ==  B  ? -1 : 1); }   int main() {     int n, m;     scanf( %d %d , &n, &m);     string a[n];     int v[n][m];     char ch;     int vx;     int nOp = 0;     for (int i = 0; i < n; i++) {       fill(v[i], v[i] + m, 0);       cin >> a[i];     }     for (int i = n - 1; i >= 0; i--)       for (int j = m - 1; j >= 0; j--) {         if (!isOk(a[i][j], v[i][j])) {           ++nOp;           vx = (a[i][j] ==  W  ? v[i][j] - 1 : v[i][j] + 1);           for (int i1 = 0; i1 <= i; i1++)             for (int j1 = 0; j1 <= j; j1++) v[i1][j1] -= vx;         }       }     printf( %d n , nOp);     return 0;     return 0;   }


#include <bits/stdc++.h>   #include<unordered_map>   //#pragma GCC optimize(2)   #define ll long long   #define sc(n) scanf( %d ,&n)   #define scl(n) scanf( %lld ,&n)   //#define int ll   using namespace std;   inline int rd() { int x = 0, f = 1; char c = getchar(); while (c !=  -  && c < 48)c = getchar(); if (c ==  - )f = -1, c = getchar(); while (c > 47)x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f * x; }   const int maxn = 500001, inf = 2147483647;   const ll mod = 0 ? 998244353 : 1000000007, linf = 9223372036854775807;   const double pi = acos(-1);   inline ll mi(ll a, ll b, ll mm = mod) { a %= mm; ll u = 1; while (b) { if (b & 1)u = u * a % mm; a = a * a % mm, b >>= 1; }return u; }   inline ll gcd(ll a, ll b) { ll c = a % b; while (c)a = b, b = c, c = a % b; return b; }   inline void mem(int* a, int p = 0, int len = maxn) { for (int i = 0; i < len; i++)a[i] = p; }   struct p { int r, c; }e[maxn];   static bool cmp(p i, p j) { return i.r < j.r; };   int t, n, m, a[maxn], b[maxn], c[maxn], x, y, xx, yy, su, q, k, u, l, r;   string s;   int g(int n) {    int x = 1, y = n;    while (y)     x <<= 1, y >>= 1;    x >>= 1;    return x;   }   signed main() {    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);//sf和cin混用会出错    cin >> t;    while (t--) {     cin >> n >> m;     map<int, int>ma;     for (int i = 0; i < n; i++)      cin >> a[i], ma[a[i]]++;     su = 0;     while (n) {      su++;      y = m, x = g(m);      while (x) {       while (ma[x] && y >= x)        y -= x, n--, ma[x]--;       x >>= 1;      }     }     cout << su << endl;    }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j;     long long n, a, b, ans;     long long arr[50];     arr[0] = 1;     for (i = 1; i < 40; i++) arr[i] = arr[i - 1] * 3;     scanf( %I64d , &n);     for (i = 0; i < 40; i++) {       if (n == arr[i]) {         printf( 1 n );         break;       } else if (n % arr[i] != 0) {         b = arr[i];         a = (n / arr[i]) + 1;         printf( %I64d n , a);         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans, n;   string str;   char ch[101000];   int a[101000];   void init() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ch[i];     }     for (int i = 1; i <= n; i++) {       cin >> a[i];     }   }   void work() {     int ti = 0;     for (int i = 1; ti <= n; ti++) {       if (ch[i] ==  > )         i += a[i];       else if (ch[i] ==  < ) {         i -= a[i];       }       if (i < 1 || i > n) {         cout <<  FINITE  << endl;         return;       }     }     cout <<  INFINITE  << endl;   }   int main() {     init();     work();     return 0;   }


#include <bits/stdc++.h>   #include <iostream>   using namespace std;   const int MAX_N = 1e5 + 5;   const int MAX_L = 20; // ~ Log N   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 7;   typedef long long ll;      const int mx = 5e6 + 23;   const ll mod = 1e9 + 7;      int a[mx], team[mx], org[mx];   int n, m;   ll s[2];      int seed, base;   int rnd(){     int ret = seed;     seed = (1ll * seed * base + 233) % mod;     return ret;   }      void solve() {     cin>>n>>m;     int lastp = 0;     for(int i=1,p,k,b,w;i<=m;i++){       cin>>p>>k>>b>>w;       seed = b;       base = w;       for(int j=lastp;j<p;j++){         team[j] = rnd() % 2;         s[team[j]] += (org[j] = a[j] = rnd() % k + 1);       }       lastp = p;     }     int st = 0;     if(s[team[0]] > s[!team[0]]){       s[team[0]]--;       a[0]--;       while(team[0] == team[st] && st < n)         st++;     }     int cur = st;     ll sum = 0;     if(st != n)       while(s[team[st]]){         if(team[cur] == team[st]){           sum += a[cur];           a[cur] = 0;         }         else{           ll d = min(1ll * a[cur], sum);           s[team[st]] -= d;           sum -= d;           a[cur] -= d;         }         cur = (cur + 1 == n ? 0 : cur + 1);       }       ll ans = 1;       for(int i=0;i<n;i++){         ll qwq = (((org[i] - a[i]) ^ (1ll * (i + 1) * (i + 1))) + 1) % mod;         ans = ans * qwq % mod;       }       cout<<ans;   }   int main()    {       ios_base::sync_with_stdio(false);cin.tie(NULL);             #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( error.txt ,  w , stderr);       freopen( output.txt ,  w , stdout);       #endif             int t=1;     // cin>>t;       while(t--)       {          solve();         // cout<<  n ;       }             cerr<< time taken :  <<(float)clock()/CLOCKS_PER_SEC<<  secs <<endl;       return 0;    }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   set<string> st;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       sort(s.begin(), s.end());       s.erase(unique(s.begin(), s.end()), s.end());       st.insert(s);     }     cout << st.size();   }


#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     long long ans = 0;     string in;     string un =  ><+-.,[] ;     cin >> in;     for (int i = 0; i < in.size(); i++) {       ans = (16 * ans + (un.find(in[i]) + 8)) % 1000003;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     string sep;     for (const auto &x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename T, size_t size>   ostream &operator<<(ostream &os, const array<T, size> &arr) {     os <<  { ;     string sep;     for (const auto &x : arr) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr <<     << H;     dbg_out(T...);   }   auto random_address = [] {     char *p = new char;     delete p;     return (uint64_t)p;   };   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() *                  (random_address() | 1));   template <typename T>   void output_vector(const vector<T> &v, bool add_one = false, int start = -1,                      int end = -1) {     if (start < 0) start = 0;     if (end < 0) end = int(v.size());     for (int i = start; i < end; i++)       cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ?     :   n );   }   const int ATTEMPTS = 50;   int N, M;   vector<vector<int>> adj;   vector<int> tour_index;   vector<array<int, 2>> low_link;   vector<bool> in_stack;   int tour;   vector<int> tour_list;   array<int, 2> combine(array<int, 2> x, int y) {     array<int, 3> a = {x[0], x[1], y};     sort(a.begin(), a.end());     return {a[0], a[1]};   }   array<int, 2> combine(array<int, 2> x, array<int, 2> y) {     array<int, 4> a = {x[0], x[1], y[0], y[1]};     sort(a.begin(), a.end());     return {a[0], a[1]};   }   bool interesting_dfs(int node) {     tour_index[node] = tour++;     tour_list.push_back(node);     low_link[node] = {tour_index[node], tour_index[node]};     in_stack[node] = true;     for (int neighbor : adj[node])       if (tour_index[neighbor] < 0) {         if (!interesting_dfs(neighbor)) return false;         low_link[node] = combine(low_link[node], low_link[neighbor]);       } else if (in_stack[neighbor]) {         low_link[node] = combine(low_link[node], tour_index[neighbor]);       } else {         return false;       }     in_stack[node] = false;     return true;   }   vector<int> save_interesting;   bool check_interesting(int node) {     if (save_interesting[node] >= 0) return save_interesting[node];     tour_index.assign(N, -1);     low_link.resize(N);     in_stack.assign(N, false);     tour = 0;     tour_list.clear();     return (save_interesting[node] = interesting_dfs(node));   }   void run_case() {     cin >> N >> M;     adj.assign(N, {});     for (int i = 0; i < M; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       adj[u].push_back(v);     }     save_interesting.assign(N, -1);     int root = -1;     for (int iter = 0; iter < ATTEMPTS; iter++) {       root = int(rng() % N);       if (check_interesting(root)) break;       root = -1;     }     if (root < 0) {       cout << -1 <<   n ;       return;     }     vector<bool> bad(N, false);     for (int x : tour_list)       if (low_link[x][0] < tour_index[x] && low_link[x][1] < tour_index[x]) {         bad[x] = true;       } else {         assert(low_link[x][1] == tour_index[x]);         int above = tour_list[low_link[x][0]];         bad[x] = bad[above];       }     vector<int> interesting;     for (int i = 0; i < N; i++)       if (!bad[i]) interesting.push_back(i);     if (5 * int(interesting.size()) < N)       cout << -1 <<   n ;     else       output_vector(interesting, true);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int tests;     cin >> tests;     while (tests-- > 0) run_case();   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[50];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] %= m;     }     sort(a, a + n);     set<int> S1, S2;     for (int i = 0; i < n; i++) {       set<int> s = i < n / 2 ? S1 : S2;       s.insert(a[i]);       for (auto b : i < n / 2 ? S1 : S2) {         s.insert((a[i] + b) % m);       }       if (i < n / 2)         S1 = s;       else         S2 = s;     }     S1.insert(0);     S2.insert(0);     int best = 0;     for (auto b : S1) {       best = max(best, b + *(--S2.lower_bound(m - b)));     }     cout << best;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 * 100 + 10;   const int MOD = 1000 * 1000 * 1000 + 7;   long double n, m;   long double Pow(long double a, int b) {     if (b == 0) return 1;     long double x = Pow(a, b / 2);     x *= x;     if (b % 2) x *= a;     return x;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cout << fixed << setprecision(10);     cin >> m >> n;     long double ans = 0;     for (long double i = 1; i < m; i++) {       ans += Pow(i / m, n);     }     cout << m - ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     cin >> n;     long long sumX = 0;     long long sumY = 0;     long long sum = 0;     for (int i = n; i > 0; i--) {       cin >> x;       cin >> y;       sumX += x;       sum += x * x;       sumY += y;       sum += y * y;     }     printf( %I64d , (n * sum) - (sumX * sumX) - (sumY * sumY));     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2005;   bool a[MAX][MAX], row[MAX], col[MAX];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         char c;         cin >> c;         a[i][j] = (c ==  1 );       }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = n - 1; j > i; j--)         if (a[i][j] ^ row[i] ^ col[j]) {           a[i][j] = false;           row[i] = !row[i];           col[j] = !col[j];           ans++;         }     for (int i = 0; i < n; i++) {       a[i][i] ^= row[i] ^ col[i];       row[i] = col[i] = false;     }     for (int j = 0; j < n; j++)       for (int i = n - 1; i > j; i--)         if (a[i][j] ^ row[i] ^ col[j]) {           a[i][j] = false;           row[i] = !row[i];           col[j] = !col[j];           ans++;         }     for (int i = 0; i < n; i++) ans += (a[i][i] ^ row[i] ^ col[i]);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> digs;     while (n % 10 != 0) {       digs.push_back(n % 10);       n /= 10;     }     reverse(digs.begin(), digs.end());     int ans = 1;     for (int i = 0; i < digs.size(); i++) {       ans *= 2;       if (digs[i] == 7) {         ans++;       }     }     cout << ans - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   const int M = 2005;   pair<pair<int, int>, pair<int, int> > adj[N];   int dp[M];   vector<int> way[M];   bool cmp(pair<pair<int, int>, pair<int, int> > a,            pair<pair<int, int>, pair<int, int> > b) {     return a.second.second < b.second.second;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int t, d, p;       cin >> t >> d >> p;       adj[i] = make_pair(make_pair(t, i), make_pair(p, d));     }     sort(adj + 1, adj + 1 + n, cmp);     for (int i = 1; i <= n; i++) {       for (int j = adj[i].second.second - 1; j >= adj[i].first.first; j--) {         if (dp[j] < dp[j - adj[i].first.first] + adj[i].second.first) {           dp[j] = dp[j - adj[i].first.first] + adj[i].second.first;           way[j] = way[j - adj[i].first.first];           way[j].emplace_back(adj[i].first.second);         }       }     }     int ans1 = 0;     vector<int> ans2;     for (int i = 0; i <= M - 1; i++) {       if (dp[i] > ans1) {         ans1 = dp[i];         ans2 = way[i];       }     }     cout << ans1 <<   n  << ans2.size() <<   n ;     for (auto op : ans2) {       cout << op <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100 + 10;   int n, m;   int main() {     cin >> n >> m;     cout << n + m - 1 << endl;     cout <<  1 1  << endl;     for (int i = 2; i <= n; ++i) cout << i <<   1  << endl;     for (int i = 2; i <= m; ++i) cout <<  1   << i << endl;     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, ans, root;   int f[N], fa[N];   inline int read() {     int a = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       a = a * 10 + c -  0 ;       c = getchar();     }     return a * f;   }   int find(int i) { return f[i] == i ? i : f[i] = find(f[i]); }   int main() {     n = read();     for (int i = 1; i <= n; i++) f[i] = i;     for (int i = 1; i <= n; i++) {       fa[i] = read();       if (fa[i] == i) root = i;     }     for (int i = 1; i <= n; i++) {       if (i != root) {         int p = find(i), q = find(fa[i]);         if (p == q) {           ans++;           if (!root) root = i;           fa[i] = root;         } else           f[p] = q;       }     }     printf( %d n , ans);     for (int i = 1; i <= n; i++) printf( %d%c , fa[i], i == n ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int nr, N, K, ap[100009], last_N;   pair<int, int> ans[10];   struct line {     int a, b, c, init;   };   vector<line> v;   struct point {     long long a, b, c, d;     bool operator==(const point &other) const {       return (1LL * a * other.b == 1LL * b * other.a &&               1LL * c * other.d == 1LL * d * other.c);     }     bool operator<(const point &other) const {       if (1LL * a * other.b == 1LL * b * other.a)         return (1LL * c * other.d < 1LL * d * other.c);       return (1LL * a * other.b < 1LL * b * other.a);     }   };   bool OnLine(point p, line l) {     return ((long long)1LL * l.a * p.a * p.d + 1LL * l.b * p.b * p.c +                 1LL * l.c * p.b * p.d ==             0LL);   }   bool Exist_Intersection(line p, line q) {     return (1LL * p.a * q.b != 1LL * p.b * q.a);   }   point Intersect(line p, line q) {     point ans;     ans.c = (long long)1LL * q.c * p.a - 1LL * q.a * p.c;     ans.d = (long long)1LL * p.b * q.a - 1LL * q.b * p.a;     ans.a = (long long)1LL * q.c * p.b - 1LL * q.b * p.c;     ans.b = (long long)1LL * p.a * q.b - 1LL * q.a * p.b;     return ans;   }   void Push(int i, int j) { ans[++nr] = make_pair(i, j); }   void Pop() { nr--; }   bool back(int pos, int K, vector<line> v) {     if (pos == v.size()) return 1;     if (K < 0) return 0;     if (ap[pos]) return back(pos + 1, K, v);     point I;     for (int i = pos + 1; i < N; i++) {       if (ap[i]) continue;       if (Exist_Intersection(v[i], v[pos]) == 0) continue;       I = Intersect(v[i], v[pos]);       for (int j = pos; j < N; j++)         if (OnLine(I, v[j])) ap[j]++;       Push(v[pos].init, v[i].init);       if (back(pos + 1, K - 1, v) == 1) return 1;       Pop();       for (int j = pos; j < N; j++)         if (OnLine(I, v[j])) ap[j]--;     }     Push(v[pos].init, -1), ap[pos]++;     if (back(pos + 1, K - 1, v) == 1) return 1;     Pop(), ap[pos]--;     return 0;   }   bool solve(int K, vector<line> v) {     int N = v.size();     if (K >= N) {       for (int i = 0; i < N; i++) Push(v[i].init, -1);       return 1;     }     if (K < 0) return 0;     if (N <= K * K) {       if (back(0, K, v)) return 1;       return 0;     }     int M = K * K + 1, needed = K + 1;     set<point> inters;     for (int i = 0; i < M; i++)       for (int j = i + 1; j < M; j++) {         if (Exist_Intersection(v[i], v[j]) == 0) continue;         point curr = Intersect(v[i], v[j]);         if (inters.count(curr)) continue;         inters.insert(curr);         int nr = 0;         for (int p = i; p < M; p++)           if (OnLine(curr, v[p])) nr++;         if (nr >= needed) {           vector<line> apel;           for (int p = 0; p < N; p++)             if (!OnLine(curr, v[p])) apel.push_back(v[p]);           Push(v[i].init, v[j].init);           if (solve(K - 1, apel)) return 1;           Pop();           return 0;         }       }     return 0;   }   int main() {     scanf( %d %d , &N, &K);     for (int i = 1; i <= N; i++) {       line curr;       scanf( %d %d %d , &curr.a, &curr.b, &curr.c), curr.init = i;       v.push_back(curr);     }     if (solve(K, v)) {       printf( YES n );       printf( %d n , nr);       for (int i = 1; i <= nr; i++)         printf( %d %d n , ans[i].first, ans[i].second);       return 0;     }     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 50;   const int INF = 1e9 + 7;   struct Edge {     int from, to, cap, flow, cost;     Edge(int from, int to, int cap, int flow, int cost)         : from(from), to(to), cap(cap), flow(flow), cost(cost) {}   };   struct MCMF {     vector<Edge> edge;     vector<int> g[maxn];     int a[maxn], p[maxn], c[maxn], inq[maxn], n;     void init(int n) {       this->n = n;       edge.clear();       for (int i = 0; i <= n; i++) g[i].clear();     }     void addedge(int from, int to, int cap, int cost) {       edge.push_back(Edge(from, to, cap, 0, cost));       edge.push_back(Edge(to, from, 0, 0, -cost));       int m = edge.size();       g[from].push_back(m - 2);       g[to].push_back(m - 1);     }     bool bellmanford(int s, int t, int limit_flow, int &flow, long long &cost) {       memset(a, 0, sizeof(a));       memset(c, 126, sizeof(c));       memset(inq, 0, sizeof(inq));       queue<int> q;       a[s] = INF;       c[s] = 0;       inq[s] = 1;       q.push(s);       while (!q.empty()) {         int x = q.front();         inq[x] = 0;         q.pop();         for (int i = 0; i < g[x].size(); i++) {           Edge &e = edge[g[x][i]];           if (e.cap > e.flow && c[e.to] > c[x] + e.cost) {             c[e.to] = c[x] + e.cost;             p[e.to] = g[x][i];             a[e.to] = min(a[x], e.cap - e.flow);             if (!inq[e.to]) {               q.push(e.to);               inq[e.to] = 1;             }           }         }       }       if (c[t] >= INF) return false;       if (a[t] + flow > limit_flow) a[t] = limit_flow - flow;       for (int i = t; i != s; i = edge[p[i]].from) {         edge[p[i]].flow += a[t];         edge[p[i] ^ 1].flow -= a[t];       }       flow += a[t];       cost += (long long)c[t] * a[t];       return true;     }     int solve(int s, int t, int limit_flow, long long &cost) {       int flow = 0;       cost = 0;       while (flow < limit_flow && bellmanford(s, t, limit_flow, flow, cost))         ;       return flow;     }   } solver;   struct tree {     vector<int> g[maxn];     int need[maxn], id[maxn], father[maxn];     int n;     void init(int n) {       this->n = n;       memset(need, 0, sizeof(need));       for (int i = 0; i <= n; i++) g[i].clear();     }     void add(int u, int v) {       g[u].push_back(v);       g[v].push_back(u);     }     void update(int k, int x) { need[k] = x; }     void _dfs(int s) { dfs(s, -1); }     void dfs(int u, int fa) {       if (fa != -1) id[u] = id[fa];       if (need[u]) id[u] = u;       father[u] = fa;       for (int i = 0; i < g[u].size(); i++) {         int v = g[u][i];         if (v == fa) continue;         dfs(v, u);       }     }     int _dfs2(int u) { return dfs2(u, father[u], u); }     int dfs2(int u, int fa, int cur) {       if (u != cur && need[u]) return need[u];       int ret = 0;       for (int i = 0; i < g[u].size(); i++) {         int v = g[u][i];         if (v == fa) continue;         ret += dfs2(v, u, cur);       }       return ret;     }     void debug() {       for (int i = 1; i <= n; i++) printf( %d  , need[i]);       printf(  n );       for (int i = 1; i <= n; i++) printf( %d  , id[i]);       printf(  n );     }   } cand1, cand2;   int a[maxn];   int main() {     int n, x, y, q, u, v, k, p;     scanf( %d%d%d , &n, &x, &y);     solver.init(2 * n + 2);     int s = 0, t = 2 * n + 1;     cand1.init(n);     cand2.init(n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       scanf( %d%d , &u, &v);       cand1.add(u, v);     }     for (int i = 1; i < n; i++) {       scanf( %d%d , &u, &v);       cand2.add(u, v);     }     scanf( %d , &q);     for (int i = 0; i < q; i++) {       scanf( %d%d , &k, &p);       cand1.update(k, p);     }     scanf( %d , &q);     for (int i = 0; i < q; i++) {       scanf( %d%d , &k, &p);       cand2.update(k, p);     }     cand1._dfs(x);     cand2._dfs(y);     int flows = 0;     bool flag = true;     for (int i = 1; i <= n; i++) {       if (cand1.need[i]) {         solver.addedge(s, i, cand1.need[i] - cand1._dfs2(i), 0);         if (cand1.need[i] - cand1._dfs2(i) < 0) flag = false;         flows += cand1.need[i] - cand1._dfs2(i);       }     }     int flowt = 0;     for (int i = 1; i <= n; i++) {       if (cand2.need[i]) {         solver.addedge(i + n, t, cand2.need[i] - cand2._dfs2(i), 0);         if (cand2.need[i] - cand2._dfs2(i) < 0) flag = false;         flowt += cand2.need[i] - cand2._dfs2(i);       }     }     for (int i = 1; i <= n; i++)       solver.addedge(cand1.id[i], cand2.id[i] + n, 1, -a[i]);     long long cost;     if (!flag || flows != flowt || solver.solve(s, t, INF, cost) != flows)       printf( -1 n );     else       printf( %I64d n , -cost);     return 0;   }


#include <bits/stdc++.h>   int n, m;   int a[2000];   int b[2000];   int can[2000];   using namespace std;   int main() {     int c = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i != j && !can[j] && b[i] == a[j]) {           can[j] = 1;           c++;         }       }     }     cout << n - c << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     int sum1 = 0, sum2 = 0, sum3 = 0;     int flag1 = 1, flag2 = 0, flag3 = 0;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       if (flag1) {         sum1 += a;         flag1 = 0;         flag2 = 1;         continue;       }       if (flag2) {         sum2 += a;         flag2 = 0;         flag3 = 1;         continue;       }       if (flag3) {         sum3 += a;         flag3 = 0;         flag1 = 1;         continue;       }     }     if (sum1 > sum2 && sum1 > sum3) {       cout <<  chest n ;     } else if (sum2 > sum1 && sum2 > sum3) {       cout <<  biceps n ;     } else {       cout <<  back n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long binpow(long long a, long long b) {     long long res = 1;     while (b != 0) {       if (b & 1) res *= a, res %= 1000000007;       a *= a, a %= 1000000007;       b >>= 1;     }     return res % 1000000007;   }   void fastio() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void solve() {     long long a, b, c;     cin >> a >> b >> c;     long long x = a + 2 * b + 3 * c;     if (x % 2 == 0)       cout << 0 <<   n ;     else       cout << 1 <<   n ;   }   signed main() {     fastio();     long long t;     cin >> t;     for (long long i = 1; i <= t; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   int fn[2][MAXN], a[2][MAXN], ans[MAXN], fans[MAXN];   void add(int p, int val, int id) {     for (++p; p < MAXN; p += p & (-p)) fn[id][p] += val;   }   int get(int p, int id) {     int res = 0;     for (; p > 0; p -= p & (-p)) res += fn[id][p];     return res;   }   int calc(int ind, int n) {     if (ind == n) return 0;     int rem = calc(ind + 1, n), REM = 0;     int id1 = get(a[0][ind], 0), id2 = get(a[1][ind], 01);     if (id1 + id2 + rem >= n - ind) REM = 1;     ans[ind] = (id1 + id2 + rem) % (n - ind);     add(a[0][ind], 1, 0);     add(a[1][ind], 1, 1);     return REM;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[0][i];     for (int i = 0; i < n; i++) cin >> a[1][i];     calc(0, n);     for (int i = 0; i < n; i++) {       int num = ans[i] + 1;       int l = -1, r = n - 1;       while (r - l > 1) {         int mid = (l + r) / 2;         if (get(mid + 1, 0) >= num)           r = mid;         else           l = mid;       }       fans[i] = r;       add(r, -1, 0);     }     for (int i = 0; i < n; i++) cout << fans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 100005;   int n;   char s[MAXN];   int B = 0, R = 0;   int main() {     while (scanf( %d , &n) != EOF) {       scanf( %s , s);       int res = 0;       B = 0, R = 0;       char pre;       for (int i = 0; i < n; i++) {         if (i == 0) {           pre = s[0];           continue;         }         if (s[i] != pre) {           pre = s[i];           continue;         }         if (s[i] ==  r ) {           if (R == 0) {             res++;             pre =  b ;             B++;           } else {             pre =  b ;             R--;           }         } else {           if (B == 0) {             res++;             pre =  r ;             R++;           } else {             pre =  r ;             B--;           }         }       }       int ans = res;       res = 0;       B = 0, R = 0;       for (int i = 0; i < n; i++) {         if (i == 0) {           if (s[0] ==  b ) {             pre =  r ;             R++;             res++;           } else {             pre =  b ;             B++;             res++;           }           continue;         }         if (s[i] != pre) {           pre = s[i];           continue;         }         if (s[i] ==  r ) {           if (R == 0) {             res++;             pre =  b ;             B++;           } else {             pre =  b ;             R--;           }         } else {           if (B == 0) {             res++;             pre =  r ;             R++;           } else {             pre =  r ;             B--;           }         }       }       printf( %d n , res < ans ? res : ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mx = (1e5) + 1;   const long long mod = 1000000007;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int a, b, x;     cin >> a >> b >> x;     if (x % 2 == 0) {       if (a > b) {         for (int i = 0; i < x / 2; i++) {           cout <<  01 ;         }         cout << string(b - x / 2,  1 );         cout << string(a - x / 2,  0 );       } else {         for (int i = 0; i < x / 2; i++) {           cout <<  10 ;         }         cout << string(a - x / 2,  0 );         cout << string(b - x / 2,  1 );       }     } else if (a > b) {       for (int i = 0; i < x / 2; i++) {         cout <<  01 ;       }       cout << string(a - x / 2,  0 );       cout << string(b - x / 2,  1 );     } else {       for (int i = 0; i < x / 2; i++) {         cout <<  10 ;       }       cout << string(b - x / 2,  1 );       cout << string(a - x / 2,  0 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, i, x, y, z, suma;   pair<int, pair<int, int> > r1, r2, tr0, v[35];   map<pair<int, pair<int, int> >, pair<int, pair<int, int> > > mp;   pair<int, pair<int, int> > make_triplet(int x, int y, int z) {     return make_pair(x, make_pair(y, z));   }   int getSum(int bts) {     int S = 0;     int j = 0;     for (j = 0; j < m; j++)       if ((1 << j) & bts) S += v[j + 1].first;     return S;   }   void bck1(int pas, int s1, int s2, int s3, int bt1, int bt2, int bt3) {     if (pas > m) return;     if (pas == m) {       int minim = min(s1, min(s2, s3));       pair<int, pair<int, int> > sum =           make_triplet(s1 - minim, s2 - minim, s3 - minim);       pair<int, pair<int, int> > bt = make_triplet(bt1, bt2, bt3);       int S = -((1 << 30) - 1 + (1 << 30));       if (mp.count(sum)) S = getSum(mp[sum].first);       if (S < s1) mp[sum] = bt;       return;     }     int i = pas + 1;     bck1(pas + 1, s1 + v[i].first, s2 + v[i].second.first, s3, bt1 + (1 << pas),          bt2 + (1 << pas), bt3);     bck1(pas + 1, s1 + v[i].first, s2, s3 + v[i].second.second, bt1 + (1 << pas),          bt2, bt3 + (1 << pas));     bck1(pas + 1, s1, s2 + v[i].second.first, s3 + v[i].second.second, bt1,          bt2 + (1 << pas), bt3 + (1 << pas));   }   void bck2(int pas, int s1, int s2, int s3, int bt1, int bt2, int bt3) {     if (pas > k) return;     if (pas == k) {       int maxim = max(s1, max(s2, s3));       pair<int, pair<int, int> > sum =           make_triplet(maxim - s1, maxim - s2, maxim - s3);       if (mp.count(sum)) {         pair<int, pair<int, int> > sum1 = mp[sum];         int S = getSum(sum1.first);         if (S + s1 > suma) {           suma = S + s1;           r1 = sum1;           r2 = make_triplet(bt1, bt2, bt3);         }       }       return;     }     int i = pas + m + 1;     bck2(pas + 1, s1 + v[i].first, s2 + v[i].second.first, s3, bt1 + (1 << pas),          bt2 + (1 << pas), bt3);     bck2(pas + 1, s1 + v[i].first, s2, s3 + v[i].second.second, bt1 + (1 << pas),          bt2, bt3 + (1 << pas));     bck2(pas + 1, s1, s2 + v[i].second.first, s3 + v[i].second.second, bt1,          bt2 + (1 << pas), bt3 + (1 << pas));   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d%d , &x, &y, &z);       v[i] = make_triplet(x, y, z);     }     m = (n + 1) / 2;     bck1(0, 0, 0, 0, 0, 0, 0);     k = n - m;     suma = -((1 << 30) - 1 + (1 << 30));     bck2(0, 0, 0, 0, 0, 0, 0);     if (r1.first || r1.second.first || r1.second.second) {       for (i = 0; i < m; i++) {         if ((1 << i) & r1.first) printf( L );         if ((1 << i) & r1.second.first) printf( M );         if ((1 << i) & r1.second.second) printf( W );         printf(  n );       }       for (i = 0; i < k; i++) {         if ((1 << i) & r2.first) printf( L );         if ((1 << i) & r2.second.first) printf( M );         if ((1 << i) & r2.second.second) printf( W );         printf(  n );       }     } else       printf( Impossible );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void PAUSE() {     char tmp;     cin >> tmp;   }   int main() {     int f1 = 0, f2 = 0, f3 = 0;     char s[101];     cin >> s;     int i = 0;     while (s[i] !=   0 ) {       if (s[i] -  0  >= 0 && s[i] -  0  <= 9) f1 = 1;       if (s[i] >=  a  && s[i] <=  z ) f2 = 1;       if (s[i] >=  A  && s[i] <=  Z ) f3 = 1;       i++;     }     if (f1 && f2 && f3 && i >= 5)       cout <<  Correct ;     else       cout <<  Too weak ;     PAUSE();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void yes() { cout <<  YES  <<   n ; }   void no() { cout <<  NO  <<   n ; }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void main_() {     string s;     cin >> s;     int n;     n = s.size();     int a, b, c;     a = b = c = 0;     for (int i = 0; i < n; i++) {       if (s[i] <=  z  && s[i] >=  a )         a++;       else if (s[i] <=  Z  && s[i] >=  A )         b++;       else         c++;     }     if (a > 0 && b > 0 && c > 0) {       cout << s <<   n ;       return;     }     if (a * b || b * c || c * a) {       if (a * b) {         if (a > 1) {           for (int i = 0; i < n; i++) {             if (s[i] <=  z  && s[i] >=  a ) {               s[i] =  1 ;               cout << s <<   n ;               return;             }           }         } else {           for (int i = 0; i < n; i++) {             if (s[i] <=  Z  && s[i] >=  A ) {               s[i] =  1 ;               cout << s <<   n ;               return;             }           }         }       } else if (b * c) {         if (b > 1) {           for (int i = 0; i < n; i++) {             if (s[i] <=  Z  && s[i] >=  A ) {               s[i] =  a ;               cout << s <<   n ;               return;             }           }         } else {           for (int i = 0; i < n; i++) {             if (s[i] <=  9  && s[i] >=  0 ) {               s[i] =  a ;               cout << s <<   n ;               return;             }           }         }       } else {         if (a > 1) {           for (int i = 0; i < n; i++) {             if (s[i] <=  z  && s[i] >=  a ) {               s[i] =  A ;               cout << s <<   n ;               return;             }           }         } else {           for (int i = 0; i < n; i++) {             if (s[i] <=  9  && s[i] >=  0 ) {               s[i] =  A ;               cout << s <<   n ;               return;             }           }         }       }     } else {       if (a) {         s[0] =  A ;         s[1] =  1 ;         cout << s <<   n ;         return;       }       if (b) {         s[0] =  a ;         s[1] =  1 ;         cout << s <<   n ;         return;       } else {         s[0] =  a ;         s[1] =  B ;         cout << s <<   n ;         return;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int test = 1;     cin >> test;     while (test--) {       main_();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void parr(int arr[], int n, string name) {     int i;     for (i = 0; i < n; i++) cout << arr[i] <<    ;     cout <<   n ;   }   long long int fn(int arr[], int n) {     int i;     long long int pre[n];     sort(arr, arr + n, greater<int>());     pre[0] = arr[0];     for (i = 1; i < n; i++) pre[i] = pre[i - 1] + arr[i];     cout <<   n ;     long long int ans = 0;     for (i = 0; i < n; i++) ans += pre[i];     for (i = 1; i < n; i++) ans += arr[i];     return ans;   }   int main() {     int n;     cin >> n;     int arr[n];     int i;     for (i = 0; i < n; i++) cin >> arr[i];     long long int ans = fn(arr, n);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, count = 0;     cin >> n;     pair<int, int> a[3005];     set<pair<int, int>> s;     for (int i = 0; i < n; i++) {       cin >> x >> y;       a[i] = pair<int, int>(x, y);       s.insert(a[i]);     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         x = a[i].first + a[j].first;         y = a[i].second + a[j].second;         if (x % 2 == 0 && y % 2 == 0) {           x /= 2;           y /= 2;           count += (s.find(pair<int, int>(x, y)) != s.end());         }       }     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1e5 + 50;   const int inf = 1e8 + 10;   int l[maxn], e[maxn];   int bs(int a[], int x, int n) {     int l = 0, r = n;     int m;     while (l < r) {       m = (l + r) / 2;       if (a[m] >= x)         r = m;       else         l = m + 1;     }     return l;   }   int get_dis(int x1, int x2, int t) { return abs(x1 - t) + abs(x2 - t); }   int main() {     int n, m;     int cl, ce;     int v;     cin >> n >> m >> cl >> ce >> v;     l[0] = e[0] = -inf;     for (int i = 1; i <= cl; ++i) scanf( %d , &l[i]);     for (int i = 1; i <= ce; ++i) scanf( %d , &e[i]);     l[cl + 1] = e[ce + 1] = inf * 2;     int q;     scanf( %d , &q);     while (q--) {       int x1, x2, y1, y2;       scanf( %d %d %d %d , &y1, &x1, &y2, &x2);       int dy = abs(y1 - y2);       if (!dy) {         printf( %d n , abs(x1 - x2));         continue;       }       int ans = inf * 4;       int a = bs(l, x1, cl + 2);       ans = min(ans, dy + min(get_dis(x1, x2, l[a]), get_dis(x1, x2, l[a - 1])));       a = bs(l, x2, cl + 2);       ans = min(ans, dy + min(get_dis(x1, x2, l[a]), get_dis(x1, x2, l[a - 1])));       int b = bs(e, x1, ce + 2);       ans = min(ans, (dy + v - 1) / v +                          min(get_dis(x1, x2, e[b]), get_dis(x1, x2, e[b - 1])));       b = bs(e, x2, ce + 2);       ans = min(ans, (dy + v - 1) / v +                          min(get_dis(x1, x2, e[b]), get_dis(x1, x2, e[b - 1])));       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1234567;   int fenw[N];   void modify(int x, int v) {     while (x < N) {       fenw[x] += v;       x = (x | (x - 1)) + 1;     }   }   int find_sum(int x) {     int v = 0;     while (x > 0) {       v += fenw[x];       x &= x - 1;     }     return v;   }   int a[N], b[N], dir[N];   int k;   vector<int> ret;   vector<int> g[N];   void solve(int root, int to) {     if (root > to) {       return;     }     if (root == to) {       ret.push_back(root);       return;     }     int sz = g[root].size();     int sfrom = root;     int sto = to;     for (int q = 0; q < sz; q++) {       int j = g[root][q];       if (dir[j] == 0) {         if (b[j] > sfrom) {           sfrom = b[j];         }       }       if (dir[j] == 1) {         if (b[j] - 1 < sto) {           sto = b[j] - 1;         }       }       modify(a[j], -1);       modify(b[j], 1);     }     int parity = 0;     while (sfrom <= sto) {       if (parity) {         if (find_sum(sfrom) == 0) {           solve(root + 1, sfrom);           ret.push_back(root);           solve(sfrom + 1, to);           return;         }         sfrom++;       } else {         if (find_sum(sto) == 0) {           solve(root + 1, sto);           ret.push_back(root);           solve(sto + 1, to);           return;         }         sto--;       }       parity ^= 1;     }     puts( IMPOSSIBLE );     exit(0);   }   int main() {     int n;     scanf( %d %d , &n, &k);     char foo[42];     for (int i = 1; i <= n; i++) {       fenw[i] = 0;       g[i].clear();     }     for (int i = 0; i < k; i++) {       scanf( %d %d %s , a + i, b + i, foo);       if (a[i] < 1 || a[i] > n || b[i] < 1 || b[i] > n || b[i] <= a[i]) {         puts( IMPOSSIBLE );         return 0;       }       dir[i] = (foo[0] ==  L  ? 0 : 1);       modify(a[i], 1);       modify(b[i], -1);       g[a[i]].push_back(i);     }     ret.clear();     solve(1, n);     for (int i = 0; i < n - 1; i++) {       printf( %d  , ret[i]);     }     printf( %d n , ret[n - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string str, txt;   int main() {     while (cin >> str) {       int ind = -1;       int n = str.size();       for (int i = n - 1; i >= 0; i--)         if (str[i] ==  2 ) ind = i;       if (ind == -1) {         sort(str.begin(), str.end());         txt = str;       } else {         txt =   ;         for (int i = 0; i < ind; i++)           if (str[i] ==  0 ) txt +=  0 ;         for (int i = 0; i < n; i++)           if (str[i] ==  1 ) txt +=  1 ;         for (int i = ind; i < n; i++)           if (str[i] !=  1 ) txt += str[i];       }       cout << txt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int abs(int x) { return x > 0 ? x : (-x); }   int len[505], rod[505], flag[505], mask[505];   int main() {     int n, m, x, y, x1, y1, i, j, x0, y0;     while (scanf( %d%d , &n, &m) != EOF) {       scanf( %d%d , &x1, &y1);       x0 = x1, y0 = y1;       for (i = 1; i < n; i++) {         scanf( %d%d , &x, &y);         if (x == x1) {           len[i] = abs(y - y1);           y1 = y;         } else {           len[i] = abs(x - x1);           x1 = x;         }       }       if (x == x0)         len[0] = len[n] = abs(y - y0);       else         len[0] = len[n] = abs(x - x0);       for (i = 1; i <= m; i++) scanf( %d , &rod[i]);       if (n & 1) {         printf( NO n );         continue;       }       memset(mask, -1, sizeof(mask));       memset(flag, 0, sizeof(flag));       int cnt = 0;       for (i = 0; i < n; i += 2) {         for (j = 1; j <= m; j++) {           if (!flag[j] && len[i] + len[i + 1] == rod[j]) {             flag[j] = 1;             mask[i] = j;             cnt++;             break;           }         }       }       if (cnt == n / 2) {         printf( YES n );         for (i = 0; i < n - 1; i++) printf( %d  , mask[i]);         printf( %d n , mask[i]);       } else {         cnt = 0;         memset(mask, -1, sizeof(mask));         memset(flag, 0, sizeof(flag));         for (i = 1; i < n; i += 2)           for (j = 1; j <= m; j++)             if (!flag[j] && len[i] + len[i + 1] == rod[j]) {               flag[j] = 1;               mask[i] = j;               cnt++;               break;             }         if (cnt == n / 2) {           printf( YES n );           for (i = 0; i < n - 1; i++) printf( %d  , mask[i]);           printf( %d n , mask[i]);         } else           printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int m, n, row[1010], col[1010], ans = 0, sum = 0;     char a[1010][1010];     cin >> m >> n;     memset(row, 0, sizeof row);     memset(col, 0, sizeof col);     for (long long int i = 0; i < m; i++)       for (long long int j = 0; j < n; j++) {         cin >> a[i][j];         if (a[i][j] ==  * ) {           row[i]++;           col[j]++;         }       }     for (long long int i = 0; i < n; i++) {       sum = 0;       for (long long int j = 0; j < m; j++) {         if (a[j][i] ==  * ) sum = sum + row[j] - 1;       }       ans = ans + sum * (col[i] - 1);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long quick(long long x, long long m) {     long long ans = 1;     while (m > 0) {       if (m % 2 == 1) ans *= x;       x = x * x;       m = m / 2;     }     return ans;   }   int main() {     long long a, b, k;     scanf( %lld%lld%lld , &a, &b, &k);     int flag = 0;     long long ans;     for (int i = 0;; i++) {       ans = quick(k, i);       if (ans >= a && ans <= b) {         flag++;         if (flag == 1)           printf( %lld , ans);         else           printf(  %lld , ans);       }       if (b / k < ans) break;     }     if (flag == 0) printf( -1 );     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool Geo(vector<int>& a) {     int n = a.size();     if (n == 1) return true;     if (n == 2) {       if (a[0] == 0 && a[1] != 0) return false;       return true;     }     if (a[1] == 0) {       for (int i = 2; i < n; ++i)         if (a[i] != 0) return false;       return true;     }     if (a[0] == 0) return false;     for (int i = 2; i < n; ++i)       if (a[i] * a[0] != a[i - 1] * a[1]) return false;     return true;   }   bool Spr(vector<int>& a, int nr) {     vector<int> b;     for (int i = 0; i < a.size(); ++i)       if (i != nr) b.push_back(a[i]);     return Geo(b);   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     if (Geo(a)) {       cout <<  0 ;       return 0;     }     if (n == 2) {       cout <<  1 ;       return 0;     }     int odp = 2;     vector<bool> pref(n, false), suf(n, false);     if (a[0] == 0 && a[1] == 0) {       pref[0] = true;       for (int i = 1; i < n; ++i)         if (pref[i - 1] && a[i] == 0) pref[i] = true;       if (a[n - 1] == 0) suf[n - 1] = true;       for (int i = n - 2; i >= 0; --i)         if (suf[i + 1] && a[i] == 0) suf[i] = true;     }     if (a[0] != 0 && a[1] == 0) {       pref[0] = true;       for (int i = 1; i < n; ++i)         if (pref[i - 1] && a[i] == 0) pref[i] = true;       if (a[n - 1] == 0) suf[n - 1] = true;       for (int i = n - 2; i >= 0; --i)         if (suf[i + 1] && a[i] == 0) suf[i] = true;     }     if (a[0] != 0 && a[1] != 0) {       pref[0] = true;       pref[1] = true;       for (int i = 2; i < n; ++i)         if (pref[i - 1] && a[i] * a[0] == a[i - 1] * a[1]) pref[i] = true;       suf[n - 1] = true;       for (int i = n - 2; i >= 0; --i)         if (suf[i + 1] && a[i] * a[1] == a[i + 1] * a[0]) suf[i] = true;     }     for (int i = 2; i < n - 1; ++i)       if (pref[i - 1] && suf[i + 1] && a[i + 1] * a[0] == a[i - 1] * a[1])         odp = 1;     if (Spr(a, 0) || Spr(a, 1) || Spr(a, n - 1)) odp = 1;     cout << odp;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   const long long MOD = 1e9 + 7;   const long long maxn = 1e5 + 7;   const long long maxm = 2e5 + 7;   struct Edge {     int end, idx, label, vis;   };   vector<Edge> adj[maxn];   vector<int> deg[maxn];   int n, ans[maxn], vis[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n;     for (int i = 0; i <= n - 2; i++) {       int u, v;       cin >> u >> v;       Edge e;       e.idx = i;       e.end = u;       adj[v].push_back(e);       e.end = v;       adj[u].push_back(e);     }     for (int i = 1; i <= n; i++) {       deg[adj[i].size()].push_back(i);     }     int maxUsed = 0;     for (int d = 1; d <= n - 1; d++) {       for (int u : deg[d]) {         for (Edge e : adj[u]) {           if (!vis[e.end]) {             ans[e.idx] = maxUsed;             maxUsed++;           }         }         vis[u] = true;       }     }     for (int i = 0; i <= n - 2; i++) {       cout << ans[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i += 2) ans += n - i + 1;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int l;     int r;     int val;   };   node tree[800010];   vector<int> pre[200010];   int ary[200010];   int n, q;   void pushup(int cur) {     tree[cur].val = min(tree[2 * cur].val, tree[2 * cur + 1].val);   }   void build(int l, int r, int cur) {     int m;     tree[cur].l = l;     tree[cur].r = r;     tree[cur].val = 0;     if (l == r) {       tree[cur].val = ary[l];       return;     }     m = (l + r) / 2;     build(l, m, 2 * cur);     build(m + 1, r, 2 * cur + 1);     pushup(cur);   }   int query(int pl, int pr, int cur) {     int res;     if (pl <= tree[cur].l && tree[cur].r <= pr) return tree[cur].val;     res = 1000000;     if (pl <= tree[2 * cur].r) res = min(res, query(pl, pr, 2 * cur));     if (pr >= tree[2 * cur + 1].l) res = min(res, query(pl, pr, 2 * cur + 1));     return res;   }   int main() {     int i, j, flag, p, l, r, res;     scanf( %d%d , &n, &q);     flag = 0;     for (i = 1; i <= n; i++) {       scanf( %d , &ary[i]);       if (ary[i] != 0) flag = 1;     }     if (flag == 0) {       printf( YES n );       for (i = 1; i <= n; i++) {         printf( %d  , q);       }       printf(  n );       return 0;     }     flag = 0;     for (i = 1; i <= n; i++) {       if (ary[i] == q) {         flag = 1;         break;       }     }     if (flag == 0) {       p = 0;       for (i = 1; i <= n; i++) {         if (ary[i] != 0)           p = ary[i];         else {           if (flag == 0) {             ary[i] = q;             flag = 1;           } else             ary[i] = p;         }       }       p = 0;       for (i = n; i >= 1; i--) {         if (ary[i] != 0)           p = ary[i];         else           ary[i] = p;       }     } else {       p = 0;       for (i = 1; i <= n; i++) {         if (ary[i] != 0)           p = ary[i];         else           ary[i] = p;       }       p = 0;       for (i = n; i >= 1; i--) {         if (ary[i] != 0)           p = ary[i];         else           ary[i] = p;       }     }     flag = 0;     for (i = 1; i <= n; i++) {       if (ary[i] == q) {         flag = 1;         break;       }     }     if (flag == 0) {       printf( NO n );       return 0;     }     for (i = 1; i <= n; i++) {       pre[ary[i]].push_back(i);     }     build(1, n, 1);     flag = 1;     for (i = 1; i <= q; i++) {       if (pre[i].size() > 1) {         for (j = 1; j < pre[i].size(); j++) {           l = pre[i][j - 1] + 1, r = pre[i][j] - 1;           if (l <= r) {             res = query(l, r, 1);             if (res < i) {               flag = 0;               break;             }           }         }         if (flag == 0) break;       }     }     if (flag) {       printf( YES n );       for (i = 1; i <= n; i++) {         printf( %d  , ary[i]);       }       printf(  n );     } else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> domain;   int domain_index(int x) {     int id = lower_bound(domain.begin(), domain.end(), x) - domain.begin();     assert(domain[id] == x);     return id;   }   struct Seg {     Seg *lc, *rc;     int L, M, R;     int sum, val;     Seg(int l, int r) : L(l), R(r) {       lc = rc = NULL;       M = (L + R) / 2;       sum = 0;       val = -1;       if (L < R) {         lc = new Seg(L, M);         rc = new Seg(M + 1, R);       }     }     void upd() {       sum = lc->sum + rc->sum;       val = max(lc->val, rc->val);     }     void add(int p, int v) {       if (L == R) {         sum += v;         return;       }       if (p <= M)         lc->add(p, v);       else         rc->add(p, v);       upd();     }     void update_maximum(int p, int v) {       if (L == R) {         val = max(val, v);         return;       }       if (p <= M)         lc->update_maximum(p, v);       else         rc->update_maximum(p, v);       upd();     }     int range_sum(int l, int r) {       if (l <= L && R <= r) return sum;       int ans = 0;       if (l <= M) ans += lc->range_sum(l, r);       if (r > M) ans += rc->range_sum(l, r);       return ans;     }     int range_max(int l, int r) {       if (l > r) return -1;       if (l <= L && R <= r) return val;       int ans = -1;       if (l <= M) ans = max(ans, lc->range_max(l, r));       if (r > M) ans = max(ans, rc->range_max(l, r));       return ans;     }   };   struct Leader {     bool is_query;     int lo, hi, id, ans;     int a, r, v;     bool operator<(const Leader &t) const {       if (r != t.r) return r < t.r;       return is_query > t.is_query;     }   };   bool comp(const Leader &a, const Leader &b) {     if (a.is_query != b.is_query) return a.is_query > b.is_query;     return a.id < b.id;   }   int main() {     int n, k;     cin >> n >> k;     vector<pair<int, int> > input(n);     vector<Leader> leaders(n);     for (int i = 0; i < n; ++i) scanf( %d , &leaders[i].r);     for (int i = 0; i < n; ++i) scanf( %d , &leaders[i].a);     for (int i = 0; i < n; ++i) {       domain.push_back(leaders[i].a);       domain.push_back(leaders[i].a - k);       domain.push_back(leaders[i].a + k);       input[i].first = leaders[i].r;       input[i].second = leaders[i].a;     }     sort(domain.begin(), domain.end());     domain.erase(unique(domain.begin(), domain.end()), domain.end());     sort(leaders.begin(), leaders.end());     Seg evaluate_leaders(0, domain.size() - 1);     int l = 0;     for (Leader &leader : leaders) {       while (l < n && leaders[l].r <= leader.r) {         evaluate_leaders.add(domain_index(leaders[l].a), 1);         ++l;       }       leader.v = evaluate_leaders.range_sum(domain_index(leader.a - k),                                             domain_index(leader.a + k));       leader.a = domain_index(leader.a);       leader.is_query = false;     }     int q;     cin >> q;     vector<Leader> queries(q);     for (int i = 0; i < q; ++i) {       int a, b;       scanf( %d %d , &a, &b);       --a, --b;       int min_age = domain_index(max(input[a].second, input[b].second) - k);       int max_age = domain_index(min(input[a].second, input[b].second) + k);       int min_resp = max(input[a].first, input[b].first);       queries[i].lo = min_age;       queries[i].hi = max_age;       queries[i].r = min_resp;       queries[i].id = i;       queries[i].is_query = true;       leaders.push_back(queries[i]);     }     sort(leaders.rbegin(), leaders.rend());     Seg find_leader(0, domain.size() - 1);     for (auto &leader : leaders) {       if (leader.is_query)         leader.ans = find_leader.range_max(leader.lo, leader.hi);       else         find_leader.update_maximum(leader.a, leader.v);     }     sort(leaders.begin(), leaders.end(), comp);     for (int i = 0; i < q; ++i) printf( %d n , leaders[i].ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string a, b;     cin >> a >> b;     string aa =   , bb =   ;     int i = 0;     for (; i < a.size(); i++) {       if (a[i] !=  0 ) break;     }     for (; i < a.size(); i++) aa += a[i];     i = 0;     for (; i < b.size(); i++) {       if (b[i] !=  0 ) break;     }     for (; i < b.size(); i++) bb += b[i];     int mx = max((int)aa.size(), (int)bb.size());     bb = string(mx - bb.size(),  0 ) + bb;     aa = string(mx - aa.size(),  0 ) + aa;     for (int i = 0; i < aa.size(); i++) {       if (aa[i] == bb[i]) continue;       if (aa[i] > bb[i]) {         cout <<  > ;         return 0;       } else if (aa[i] < bb[i]) {         cout <<  < ;         return 0;       }     }     cout <<  = ;   }


#include <bits/stdc++.h>   using namespace std;   string name[1010];   int score[1010];   bool good[1010];   map<string, int> mp;   int main(void) {     int N, i;     cin >> N;     for ((i) = 0; (i) < (int)(N); (i)++) cin >> name[i] >> score[i];     for ((i) = 0; (i) < (int)(N); (i)++) mp[name[i]] += score[i];     int M = 0;     for (__typeof((mp).begin()) itr = (mp).begin(); itr != (mp).end(); itr++)       M = max(M, (itr->second));     for ((i) = 0; (i) < (int)(N); (i)++) good[i] = (mp[name[i]] == M);     mp.clear();     for ((i) = 0; (i) < (int)(N); (i)++) {       mp[name[i]] += score[i];       if (good[i] && mp[name[i]] >= M) break;     }     cout << name[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 10;   long long n, m, a, b;   long long arr[maxn][maxn];   long long sum[maxn][maxn];   long long Min[maxn][maxn];   set<pair<long long, pair<long long, long long> > > s;   multiset<long long> s_;   long long minr[maxn][maxn];   long long ground[maxn][maxn];   vector<pair<long long, pair<long long, long long> > > ans;   inline long long find_sum(pair<long long, long long> fi,                             pair<long long, long long> se) {     long long ret = sum[fi.first][fi.second];     ret += sum[se.first + 1][se.second + 1];     ret -= sum[se.first + 1][fi.second];     ret -= sum[fi.first][se.second + 1];     return ret;   }   inline void make_sum() {     for (int i = n; i >= 1; --i)       for (int j = m; j >= 1; --j)         sum[i][j] = sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1] + arr[i][j];   }   inline void update_minr() {     for (int i = 1; i <= n; ++i) {       s_.clear();       for (int j = 1; j <= b; ++j) s_.insert(arr[i][j]);       for (int j = 1; j <= m - b + 1; ++j) {         long long mini = *s_.begin();         minr[i][j] = mini;         s_.erase(s_.find(arr[i][j]));         s_.insert(arr[i][j + b]);       }     }   }   inline void make_Min() {     update_minr();     for (int j = 1; j <= m - b + 1; ++j) {       s_.clear();       for (int i = 1; i <= a; ++i) s_.insert(minr[i][j]);       for (int i = 1; i <= n - a + 1; ++i) {         long long mini = *s_.begin();         Min[i][j] = mini;         s_.erase(s_.find(minr[i][j]));         s_.insert(minr[i + a][j]);       }     }   }   vector<pair<long long, pair<long long, long long> > > v;   int vis[maxn][maxn];   inline void remove(long long r, long long c) {     for (int i = r; i <= r + a - 1; ++i)       for (int j = c; j <= c + b - 1; ++j) vis[i][j] = 1;     for (int i = r - 1; i >= 1 && i >= r - a + 1; --i)       for (int j = c; j <= c + b - 1; ++j) vis[i][j] = 1;     for (int i = r; i <= r + a - 1; ++i)       for (int j = c - 1; j >= 1 && j >= c - b + 1; --j) vis[i][j] = 1;     for (int i = r - 1; i >= 1 && i >= r - a + 1; --i)       for (int j = c - 1; j >= 1 && j >= c - b + 1; --j) vis[i][j] = 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> a >> b;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) cin >> arr[i][j];     make_sum();     make_Min();     for (int i = 1; i <= n - a + 1; ++i)       for (int j = 1; j <= m - b + 1; ++j)         ground[i][j] =             find_sum(pair<long long, long long>(i, j),                      pair<long long, long long>(i + a - 1, j + b - 1)) -             (a * b * Min[i][j]);     v.clear();     for (int i = 1; i <= n - a + 1; ++i)       for (int j = 1; j <= m - b + 1; ++j)         v.push_back(pair<long long, pair<long long, long long> >(             ground[i][j], pair<long long, long long>(i, j)));     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); ++i)       if (vis[v[i].second.first][v[i].second.second] == 0) {         long long X, Y;         X = v[i].second.first;         Y = v[i].second.second;         ans.push_back(pair<long long, pair<long long, long long> >(             ground[X][Y], pair<long long, long long>(X, Y)));         remove(X, Y);       }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i)       cout << ans[i].second.first <<     << ans[i].second.second <<                << ans[i].first << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int test;     cin >> test;     while (test--) {       cin >> n;       vector<int> a;       int mini = -1;       int ii;       for (ii = 2; ii * ii < n; ii++) {         if (n % ii != 0) continue;         if (mini < 0) mini = ii;         a.push_back(ii);         a.push_back(n / ii);       }       if (ii * ii == n) a.push_back(ii);       a.push_back(n);       bool pk = true;       for (int x : a) {         if (x % mini != 0) {           pk = false;           break;         }       }       if (pk) {         for (int x : a) cout << x <<    ;         cout <<   n ;         cout << 0 <<   n ;         continue;       }       if (a.size() == 3) {         for (int x : a) cout << x <<    ;         cout <<   n ;         cout << 1 <<   n ;         continue;       }       vector<int> primes;       int m = n;       int cnt = 2;       while (cnt * cnt <= m) {         if (m % cnt == 0) {           primes.push_back(cnt);           while (m % cnt == 0) m /= cnt;         }         cnt++;       }       if (m > 1) primes.push_back(m);       map<int, bool> ma;       for (int pi = 0; pi + 1 < primes.size(); pi++) {         ma[primes[pi]] = true;         ma[primes[pi] * primes[pi + 1]] = true;       }       ma[primes.back()] = true;       ma[n] = true;       vector<bool> was(a.size(), false);       for (int i = 0; i < a.size(); i++) {         if (ma[a[i]]) was[i] = true;       }       vector<int> ans;       for (int pi = 0; pi + 1 < primes.size(); pi++) {         ans.push_back(primes[pi]);         for (int i = 0; i < a.size(); i++) {           if (!was[i] && a[i] % primes[pi] == 0 &&               a[i] != primes[pi + 1] * primes[pi]) {             was[i] = true;             ans.push_back(a[i]);           }         }         ans.push_back(primes[pi + 1] * primes[pi]);       }       ans.push_back(primes.back());       for (int i = 0; i < a.size(); i++) {         if (!was[i] && a[i] % primes.back() == 0) {           was[i] = true;           ans.push_back(a[i]);         }       }       ans.push_back(n);       for (int x : ans) cout << x <<    ;       cout <<   n ;       cout << 0 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int longestSubstring(string s) {     int i, j;     int l = s.length();     int maxi = 0;     map<string, int> mpp;     for (i = 0; i < l; i++) {       string temp =   ;       for (j = i; j < l; j++) {         temp += s[j];         mpp[temp]++;         maxi = max(maxi, mpp[temp]);       }     }     auto it = mpp.begin();     int len = 0;     string ans =   ;     while (it != mpp.end()) {       if (it->second >= 2) {         string temp = it->first;         if (temp.length() > len) {           ans = temp;           len = temp.length();         } else if (temp.length() == len) {           if (temp < ans) ans = temp;         }       }       it++;     }     return len;   }   int main() {     string s;     cin >> s;     int ans = longestSubstring(s);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n;   struct node {     int pos, len;     friend bool operator<(node a, node b) { return a.len > b.len; }   } f[100005];   vector<int> po;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x = i * 2 - 1;       f[i].pos = x;       scanf( %d , &f[i].len);     }     sort(f + 1, f + n + 1);     int jl = 0;     for (int i = 1; i <= n; i++) {       po.push_back(f[i].pos);       if (i == 1)         jl = f[i].pos;       else {         printf( %d %d n , jl, f[i].pos);         jl = f[i].pos;       }     }     for (int i = 1; i <= n; i++) {       int now = f[i].pos + 1;       int len = f[i].len;       if (len - 1 + i <= po.size()) {         printf( %d %d n , now, po[i + len - 2]);         if (len - 1 + i == po.size()) po.push_back(now);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   bool mini(T1 &a, T2 b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <typename T1, typename T2>   bool maxi(T1 &a, T2 b) {     if (a < b) {       a = b;       return true;     }     return false;   }   const int N = 2e5 + 5;   const int oo = 1e9;   struct segtree {     int n;     vector<int> st;     vector<int> lz;     segtree(int _n) {       n = _n;       st.assign(4 * n + 5, 0);       lz.assign(4 * n + 5, 0);     }     void push(int id) {       for (int i = (id << 1); i <= (id << 1 | 1); i++) {         st[i] += lz[id];         lz[i] += lz[id];       }       lz[id] = 0;     }     void update(int id, int l, int r, int u, int v, int val) {       if (l > v || r < u) return;       if (l >= u && r <= v) return (void)(st[id] += val, lz[id] += val);       int mid = (l + r) >> 1;       push(id);       update(id << 1, l, mid, u, v, val);       update(id << 1 | 1, mid + 1, r, u, v, val);       st[id] = max(st[id << 1], st[id << 1 | 1]);     }     void update(int l, int r, int val) { update(1, 1, n, l, r, val); }     int getmax(int id, int l, int r, int u, int v) {       if (l > v || r < u) return 0;       if (l >= u && r <= v) return st[id];       int mid = (l + r) >> 1;       int lnode = getmax(id << 1, l, mid, u, v);       int rnode = getmax(id << 1 | 1, mid + 1, r, u, v);       return max(lnode, rnode);     }     int getmax(int l, int r) { return getmax(1, 1, n, l, r); }   };   segtree st[2] = {segtree(N << 1), segtree(N << 1)};   vector<int> r[2][N << 1];   pair<int, int> seg[N];   int dp[2][N << 1];   int c[N];   int n;   bool upd[2][N << 1];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     vector<int> val;     for (int i = 1; i <= n; i++) {       cin >> seg[i].first >> seg[i].second >> c[i];       c[i]--;       val.push_back(seg[i].first);       val.push_back(seg[i].second);     }     sort(val.begin(), val.end());     val.resize(unique(val.begin(), val.end()) - val.begin());     for (int i = 1; i <= n; i++) {       seg[i].first =           lower_bound(val.begin(), val.end(), seg[i].first) - val.begin() + 1;       seg[i].second =           lower_bound(val.begin(), val.end(), seg[i].second) - val.begin() + 1;       r[c[i]][seg[i].first].push_back(seg[i].second);     }     for (int i = (n << 1); i >= 0; i--) {       for (int j = 0; j <= 1; j++) dp[j][i] = st[j ^ 1].getmax(i, n << 1);       for (int j = 0; j <= 1; j++)         for (int x : r[j][i]) {           if (!upd[j][x]) {             st[j].update(x, x, dp[j][x]);             upd[j][x] = true;           }           st[j].update(x, n << 1, 1);         }     }     cout << max(dp[0][0], dp[1][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int a[100001], b[100001], c[100001];   vector<int> rev[100001];   vector<int> e[100001];   int get(int far) {     int cur = k;     for (int i = 1; i <= n; i++) {       int x = e[i].back();       rev[x].push_back(i);     }     priority_queue<int, vector<int>, greater<int> > q;     for (int i = 1; i <= n; i++) {       if (cur >= a[i])         cur += b[i];       else {         while (!q.empty() && cur < a[i]) q.pop(), cur++;         if (cur < a[i]) return -1;         cur += b[i];       }       for (int j = 0; j < rev[i].size(); j++) q.push(c[rev[i][j]]), cur--;     }     int ans = 0;     while (cur < 0) q.pop(), cur++;     while (!q.empty()) ans += q.top(), q.pop();     return ans;   }   signed main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %d%d%d , &a[i], &b[i], &c[i]);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       if (u > v) swap(u, v);       e[u].push_back(v);     }     for (int i = 1; i <= n; i++) {       e[i].push_back(i);       sort(e[i].begin(), e[i].end());     }     int ans = get(n);     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7, N = 2e5;   int mul(int a, int b) { return (a * 1LL * b) % mod; }   int mul2(int a, int b) { return (a * 1LL * b) % (mod - 1); }   int Pow(int v, long long p) {     int ans = 1;     while (p) {       if (p & 1) {         ans = mul(ans, v);       }       p /= 2;       v = mul(v, v);     }     return ans;   }   long long F(int n) { return n * 1LL * (n + 1) / 2; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     map<int, int> p;     while (n--) {       int x;       cin >> x;       ++p[x];     }     int mult = 1, sum = 1, last = 1;     for (auto e : p) {       last = Pow(last, e.second + 1);       mult = Pow(Pow(e.first, F(e.second)), sum);       sum = mul2(sum, e.second + 1);       last = mul(mult, last);     }     cout << last;     return 0;   }


#include <bits/stdc++.h>   int main() {     int life[200001], N, a, i;     for (i = 0; i < 200001; i++) life[i] = 0;     scanf( %d , &N);     for (i = 0; i < N; i++) {       scanf( %d , &a);       if (a != 0) life[a + 100000] = 1;     }     int diff = 0;     for (i = 0; i < 200001; i++) diff += life[i];     printf( %d n , diff);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     string s;     cin >> s;     while (m--) {       int a1, a2;       char a3, a4;       scanf( %d %d %c %c , &a1, &a2, &a3, &a4);       a1--;       a2--;       while (a1 <= a2) {         if (s[a1] == a3) s[a1] = a4;         a1++;       }     }     cout << s <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int num[27];   int num2[27];   inline int idx(char a) { return a -  a ; }   char sa[5555], sb[5555], sans1[5555], sans2[5555], sans[5555];   inline char rev(int id) { return  a  + id; }   int lena, lenb;   bool ans1, ans2;   int main() {     scanf( %s , sa);     scanf( %s , sb);     ans1 = false;     ans2 = false;     memset(num, 0, sizeof(num));     memset(num2, 0, sizeof(num2));     lena = strlen(sa);     lenb = strlen(sb);     for (int i = 0; i < lena; i++) {       num[idx(sa[i])]++;       num2[idx(sa[i])]++;     }     if (lena > lenb) {       int flag = 1;       for (int i = 0; i < lenb; i++) {         sans1[i] = sb[i];         if (!num[idx(sb[i])]) {           flag = 0;           break;         } else {           num[idx(sb[i])]--;         }       }       if (flag) {         ans1 = true;         int tl = lenb;         for (int i = 0; i < 26; i++) {           while (num[i]) {             num[i]--;             sans1[tl++] = rev(i);           }         }         sans1[tl] =   0 ;       }     }     for (int i = 0; i < 26; i++) num[i] = num2[i];     int lastmch = -1;     for (int i = 0; i < lenb; i++) {       if (num[idx(sb[i])]) {         num[idx(sb[i])]--;         sans2[i] = sb[i];         lastmch = i;       } else {         int tl = i;         int fg = 0;         for (int j = idx(sb[i]) + 1; j < 26; j++) {           if (num[j]) {             fg = 1;             num[j]--;             sans2[tl++] = rev(j);             break;           }         }         if (!fg) {           for (int k = i - 1; k >= 0; k--) {             tl = k;             if (tl >= 0) {               num[idx(sb[k])]++;               for (int j = idx(sb[k]) + 1; j < 26; j++) {                 if (num[j]) {                   lastmch = k - 1;                   fg = 1;                   num[j]--;                   sans2[tl++] = rev(j);                   break;                 }               }             }             if (fg) break;           }         }         if (fg) {           ans2 = true;           for (int j = 0; j < 26; j++) {             while (num[j]) {               num[j]--;               sans2[tl++] = rev(j);             }           }         }         sans2[tl] =   0 ;         break;       }     }     if (lastmch == lenb - 1 && ans2 == 0) {       int i = lenb;       int fg = 0;       int tl;       for (int k = i - 1; k >= 0; k--) {         tl = k;         if (tl >= 0) {           num[idx(sb[k])]++;           for (int j = idx(sb[k]) + 1; j < 26; j++) {             if (num[j]) {               lastmch = k - 1;               fg = 1;               num[j]--;               sans2[tl++] = rev(j);               break;             }           }         }         if (fg) break;       }       if (fg) {         ans2 = true;         for (int j = 0; j < 26; j++) {           while (num[j]) {             num[j]--;             sans2[tl++] = rev(j);           }         }       }       sans2[tl] =   0 ;     }     int fg = 0;     if (ans1 == false && ans2 == false) {       cout << -1 << endl;       return 0;     }     if (ans1) {       fg = 1;       strcpy(sans, sans1);     }     if (fg && ans2) {       if (strcmp(sans1, sans2) > 0) {         strcpy(sans, sans2);       } else {         strcpy(sans, sans1);       }     } else if (ans2) {       strcpy(sans, sans2);     }     puts(sans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200100;   int arr[MAXN], tmp[MAXN];   vector<int> ve[MAXN];   map<pair<int, int>, vector<int> > mapa;   int ind[MAXN];   vector<int> out[MAXN];   int sol = 0;   vector<int> t1, t2;   vector<int> comp;   map<int, int> aaa;   void tour(int x, int i) {     while (ind[x] < ve[x].size()) {       int y = ve[x][ind[x]++];       int ind = mapa[{x, y}].back();       mapa[{x, y}].pop_back();       tour(y, ind);     }     out[sol].push_back(i);     return;   }   int main() {     ios_base::sync_with_stdio(false);     int n, s;     cin >> n >> s;     for (int i = (0); i < (n); i++) {       cin >> arr[i];       comp.push_back(arr[i]);     }     sort(comp.begin(), comp.end());     comp.resize(unique(comp.begin(), comp.end()) - comp.begin());     for (int i = (0); i < (comp.size()); i++) {       aaa[comp[i]] = i;     }     for (int i = (0); i < (n); i++) {       arr[i] = aaa[arr[i]];       tmp[i] = arr[i];     }     sort(tmp, tmp + n);     for (int i = (0); i < (n); i++) {       if (arr[i] != tmp[i]) {         mapa[{tmp[i], arr[i]}].push_back(i);         ve[tmp[i]].push_back(arr[i]);       }     }     int uk = 0;     for (int i = (0); i < (n); i++) {       tour(tmp[i], i);       out[sol].pop_back();       if (out[sol].size()) {         reverse(out[sol].begin(), out[sol].end());         uk += out[sol].size();         sol++;       }     }     if (uk > s) {       cout <<  -1 n ;       return 0;     }     int m = min(sol, s - uk);     for (int i = (0); i < (m); i++) {       sol--;       for (int x : out[sol]) t1.push_back(x);       t2.push_back(out[sol][0]);     }     if (m == 1) sol++;     if (m <= 1) {       cout << sol << endl;       for (int i = (0); i < (sol); i++) {         cout << out[i].size() <<   n ;         for (int x : out[i]) cout << x + 1 <<    ;         cout <<   n ;       }     } else {       reverse(t2.begin(), t2.end());       cout << sol + 2 << endl;       cout << t1.size() << endl;       for (int x : t1) cout << x + 1 <<    ;       cout << endl;       cout << t2.size() << endl;       for (int x : t2) cout << x + 1 <<    ;       cout << endl;       for (int i = (0); i < (sol); i++) {         cout << out[i].size() <<   n ;         for (int x : out[i]) cout << x + 1 <<    ;         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m;     cin >> n >> m;     set<long long> s;     vector<long long> ar(n + 1, 0);     for (long long i = 0; i < n; i++) {       s.insert(i + 1);     }     for (long long i = 1; i <= m; i++) {       long long li, ri, xi;       vector<long long> temp;       cin >> li >> ri >> xi;       auto itl = s.lower_bound(li);       auto itr = s.upper_bound(ri);       for (auto it = itl; it != itr && (*it) <= ri; it++) temp.push_back(*it);       for (auto i : temp) {         if (i != xi) {           s.erase(i);           ar[i] = xi;         }       }     }     for (long long i = 1; i <= n; i++) cout << ar[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000002;   const long long INFLL = 100000000000000000ll;   const long long MOD = 1000000007;   int Cycle[100005], N, Real[100005], Pos[100005], V[100005], P[100005][20],       D[100005], Edg, K;   long long M[100005];   vector<int> E[100005], E2[100005];   void dfs(int n, int p, int from) {     if (Real[n] != n) return;     if (Pos[n] > 0) {       Cycle[n] = 1;       for (int i = (Pos[n] + 1); i <= (p - 1); i++) Real[V[i]] = n;       return;     }     Pos[n] = p;     V[p] = n;     for (int v : E[n])       if (v != from) dfs(v, p + 1, n);   }   void dfs2(int n, int p, int d, long long mult) {     D[n] = d;     M[n] = mult;     P[n][0] = p;     for (int v : E2[n])       if (v != p) dfs2(v, n, d + 1, mult + Cycle[v]);   }   int lca(int a, int b) {     if (D[a] > D[b]) return lca(b, a);     int diff = D[b] - D[a];     for (int i = (0); i <= (17); i++)       if (diff & (1 << i)) b = P[b][i];     if (a == b) return a;     for (int i = (17); i >= (0); i--)       if (P[a][i] != P[b][i]) a = P[a][i], b = P[b][i];     return P[a][0];   }   long long exp(long long n, int e) {     if (e == 0) return 1;     if (e % 2) return (exp(n, e - 1) * n) % MOD;     long long q = exp(n, e / 2);     return (q * q) % MOD;   }   int main() {     cin >> N >> Edg;     for (int i = (1); i <= (Edg); i++) {       int a, b;       scanf( %d %d , &a, &b);       E[a].push_back(b), E[b].push_back(a);     }     for (int i = (1); i <= (N); i++) Real[i] = i;     dfs(1, 1, 0);     for (int i = (1); i <= (N); i++)       for (int v : E[i]) {         int v1 = Real[i];         int v2 = Real[v];         if (v1 != v2) E2[v1].push_back(v2);       }     dfs2(Real[1], 0, 1, Cycle[Real[1]]);     for (int j = (1); j <= (17); j++)       for (int i = (1); i <= (N); i++) P[i][j] = P[P[i][j - 1]][j - 1];     cin >> K;     for (int kk = (1); kk <= (K); kk++) {       int a, b;       scanf( %d %d , &a, &b);       a = Real[a], b = Real[b];       if (a == b) {         printf( 2 n );         continue;       }       int l = lca(a, b);       int par = P[l][0];       long long val = M[a] + M[b] - M[par] - M[par] - Cycle[l];       printf( %I64d n , exp(2, val));     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 20;   const int X = 1 << MAXN;   int N, M, K;   long long a[MAXN];   long long p[MAXN][MAXN];   long long dp[MAXN][X + 5];   long long max(long long a, long long b) { return a > b ? a : b; }   int main() {     scanf( %d %d %d , &N, &M, &K);     for (int i = 1; i <= N; i++) scanf( %I64d , &a[i]);     int u, v;     long long w;     for (int i = 0; i < K; i++) {       scanf( %d %d %I64d , &u, &v, &w);       p[u][v] = w;     }     for (int i = 1; i <= N; i++) dp[i][1 << i - 1] = a[i];     long long ans = 0;     int cnt;     for (int i = 0; i < (1 << N); i++) {       cnt = 0;       for (int j = 1; j <= N; j++) {         if (i & (1 << j - 1)) {           cnt++;           for (int k = 1; k <= N; k++)             if (!(i & (1 << k - 1)))               dp[k][i | (1 << k - 1)] =                   max(dp[k][i | (1 << k - 1)], dp[j][i] + a[k] + p[j][k]);         }       }       if (cnt == M) {         for (int j = 1; j <= N; j++)           if (i & (1 << j - 1)) ans = max(ans, dp[j][i]);       }     }     printf( %I64d , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 4e5 + 5, M = 998244353, OO = 0x3f3f3f3f;   int t, n;   int a[N], b[N];   bool ok;   set<pair<int, int>> st;   map<pair<int, int>, int> ma;   int main() {     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < n; ++i) cin >> a[i];       for (int i = 0; i < n; ++i) cin >> b[i];       if (n % 2 == 1 && a[n / 2] != b[n / 2]) {         cout <<  No  << endl;         continue;       }       for (int i = 0; i < n / 2; ++i) {         st.insert({a[i], a[n - i - 1]});         ma[{a[i], a[n - i - 1]}]++;       }       ok = 1;       for (int i = 0; i < n / 2; ++i) {         if (st.count({b[i], b[n - i - 1]})) {           ma[{b[i], b[n - i - 1]}]--;           if (!ma[{b[i], b[n - i - 1]}]) st.erase({b[i], b[n - i - 1]});         } else if (st.count({b[n - i - 1], b[i]})) {           ma[{b[n - i - 1], b[i]}]--;           if (!ma[{b[n - i - 1], b[i]}]) st.erase({b[n - i - 1], b[i]});         } else           ok = 0;       }       if (ok)         cout <<  Yes  << endl;       else         cout <<  No  << endl;       st.clear();       ma.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     set<int> s;     cin >> n;     int i, j;     for (i = 0; i < n; i++) {       cin >> j;       if (j != 0) s.insert(j);     }     cout << s.size();   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 20;   long long n, m, k;   long long col[N];   vector<long long> g[N];   struct edge {     long long u, v;   } e[N];   long long ans;   long long dead[N];   map<pair<long long, long long>, bool> vis;   map<pair<long long, long long>, vector<pair<long long, long long>>>       edges_between;   long long par[N], f[N];   vector<pair<long long, long long>> parhistory, fhistory;   long long root(long long v, bool save_history = 0) {     if (par[v] < 0) return v;     if (save_history) {       parhistory.push_back({v, par[v]});       fhistory.push_back({v, f[v]});     }     long long res = root(par[v], save_history);     f[v] ^= f[par[v]];     par[v] = res;     return res;   }   inline long long merge(long long u, long long v, bool save_history = 0) {     long long ru = root(u, save_history), rv = root(v, save_history);     if (ru == rv) {       if (f[u] == f[v]) return -1;       return 0;     }     if (save_history) {       parhistory.push_back({ru, -1});       fhistory.push_back({ru, 0});     }     if (f[u] == f[v])       f[ru] = 1;     else       f[ru] = 0;     par[ru] = rv;     return 1;   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (long long i = 0; i < n; i++) cin >> col[i], col[i]--;     for (long long i = 0; i < m; i++) {       cin >> e[i].u >> e[i].v;       e[i].u--, e[i].v--;       g[e[i].u].push_back(e[i].v);       g[e[i].v].push_back(e[i].u);     }     memset(par, -1, sizeof par);     for (long long i = 0; i < m; i++) {       long long u = e[i].u, v = e[i].v;       if (col[u] == col[v]) {         if (merge(u, v) == -1) dead[col[u]] = 1;       }     }     long long cnt = 0;     for (long long i = 0; i < k; i++) cnt += (!dead[i]);     for (long long i = 0; i < n; i++) root(i);     ans = 1ll * cnt * (cnt - 1) / 2;     for (long long i = 0; i < m; i++) {       long long u = e[i].u, v = e[i].v;       if (col[u] == col[v]) continue;       if (dead[col[u]] || dead[col[v]]) continue;       long long x = col[u], y = col[v];       if (x > y) swap(x, y);       edges_between[{x, y}].push_back({u, v});       vis[{x, y}] = 1;     }     for (auto p : vis) {       long long x = p.first.first, y = p.first.second;       ans--;       bool ok = 1;       for (pair<long long, long long> ed : edges_between[{x, y}]) {         if (merge(ed.first, ed.second, 1) == -1) {           ok = 0;           break;         }       }       while (parhistory.size()) {         pair<long long, long long> p = parhistory.back();         par[p.first] = p.second;         parhistory.pop_back();       }       while (fhistory.size()) {         pair<long long, long long> p = fhistory.back();         f[p.first] = p.second;         fhistory.pop_back();       }       ans += ok;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1000 * 100 + 10;   int m[Maxn], c[Maxn], eatd[Maxn];   int ans;   int INF = 1000 * 1000 * 10 + 10;   int main() {     int N, M, y;     cin >> N >> M >> y >> y;     for (int i = 0; i < N; i++) cin >> m[i];     c[0] = -INF;     c[M + 1] = INF;     for (int i = 1; i <= M; i++) cin >> c[i];     for (int i = 0; i < Maxn; i++) eatd[i] = INF;     for (int i = 0; i < N; i++) {       int ind = lower_bound(c, c + M + 2, m[i]) - c;       if (m[i] - c[ind - 1] < c[ind] - m[i]) {         if (eatd[ind - 1] < m[i] - c[ind - 1])           ans++;         else {           if (eatd[ind - 1] > m[i] - c[ind - 1] && eatd[ind - 1] != INF) ans++;           eatd[ind - 1] = m[i] - c[ind - 1];         }       } else if (m[i] - c[ind - 1] > c[ind] - m[i]) {         if (eatd[ind] != INF) ans++;         eatd[ind] = c[ind] - m[i];       } else {         if (eatd[ind - 1] == INF || eatd[ind - 1] == m[i] - c[ind - 1])           eatd[ind - 1] = m[i] - c[ind - 1];         else           eatd[ind] = c[ind] - m[i];       }     }     if (M == 0)       cout << N;     else       cout << ans;     return 0;   }