#include <bits/stdc++.h>   using int64 = long long;   using uint64 = unsigned long long;   using uchar = unsigned char;   constexpr int maxn(200000);   constexpr int maxm(200000);   template <class _Tp>   inline void swap(_Tp& x, _Tp& y) {     _Tp z = x;     x = y;     y = z;   }   template <class _Tp>   inline _Tp Min(const _Tp& x, const _Tp& y) {     return x < y ? x : y;   }   template <class _Tp>   inline _Tp Max(const _Tp& x, const _Tp& y) {     return x > y ? x : y;   }   namespace IOManager {   constexpr int FILESZ(131072);   char buf[FILESZ];   const char *ibuf = buf, *tbuf = buf;   struct IOManager {     inline char gc() {       return (ibuf == tbuf) &&                      (tbuf = (ibuf = buf) + fread(buf, 1, FILESZ, stdin),                       ibuf == tbuf)                  ? EOF                  : *ibuf++;     }     template <class _Tp>     inline operator _Tp() {       _Tp s = 0u;       char c = gc();       for (; c < 48; c = gc())         ;       for (; c > 47; c = gc()) s = (_Tp)(s * 10u + c - 48u);       return s;     }   };   }  // namespace IOManager   IOManager::IOManager io;   struct Edge {     int v;     Edge* las;     inline Edge* init(const int& to, Edge* const& ls) {       return v = to, las = ls, this;     }   } * las[maxn], *lass[maxn];   Edge pool[maxm << 1], *alc = pool - 1;   inline uint64 C2(const int& v) { return (uint64)v * (v - 1ull) >> 1; }   inline uint64 sum(const int& l, const int& r) {     return (uint64)(l + r) * (r - l + 1ull) >> 1;   }   int d[maxn];   struct E {     int u, v;     inline void init() {       ++d[u = io];       ++d[v = io];     }   } e[maxm];   uchar tag[maxn];   int lisl[maxn], lisr[maxn];   int main() {     const int n = io, m = io;     const uint64 A = io, B = io, C = io;     E* const tl = e + m;     for (E* i = e; i != tl; ++i) i->init();     uint64 ans = 0;     for (int u = 0; u != n; ++u)       ans += (A * C2(n - u - 1) + B * u * (n - u - 1ull) + C * C2(u)) * u;     for (E* i = e; i != tl; ++i) {       const int u = i->u, v = i->v;       if (d[u] < d[v] || (d[u] == d[v] && u < v))         las[u] = (++alc)->init(v, las[u]), lass[v] = (++alc)->init(u, lass[v]);       else         las[v] = (++alc)->init(u, las[v]), lass[u] = (++alc)->init(v, lass[u]);       ans -= u < v                  ? A * sum(0, u - 1) + u * (B * u + C * v) +                        B * sum(u + 1, v - 1) + (v - u - 1ull) * (A * u + C * v) +                        C * sum(v + 1, n - 1) + (n - v - 1ull) * (A * u + B * v)                  : A * sum(0, v - 1) + v * (B * v + C * u) +                        B * sum(v + 1, u - 1) + (u - v - 1ull) * (A * v + C * u) +                        C * sum(u + 1, n - 1) + (n - u - 1ull) * (A * v + B * u);     }     for (int u = 0; u != n; ++u) {       int cntl = 0, cntr = 0;       uint64 suml = 0, sumr = 0;       for (Edge* o = las[u]; o; o = o->las)         if (o->v < u)           lisl[++cntl] = o->v, suml += A * o->v;         else           lisr[++cntr] = o->v, sumr += C * o->v;       for (Edge* o = lass[u]; o; o = o->las)         if (o->v < u)           lisl[++cntl] = o->v, suml += A * o->v;         else           lisr[++cntr] = o->v, sumr += C * o->v;       std::sort(lisl + 1, lisl + cntl + 1);       std::sort(lisr + 1, lisr + cntr + 1);       ans += suml * cntr + sumr * cntl + A * u * C2(cntr) + B * u * cntl * cntr +              C * u * C2(cntl);       suml = sumr = 0;       for (int r = 1; r <= cntl; ++r)         ans += suml + B * lisl[r] * (r - 1ull), suml += A * lisl[r];       for (int l = cntr; l; --l)         ans += sumr + B * lisr[l] * (cntr - l), sumr += C * lisr[l];     }     for (int u = 0, mn, mx; u != n; ++u) {       for (Edge* o = las[u]; o; o = o->las) tag[o->v] = 1;       for (Edge* o = las[u]; o; o = o->las)         for (Edge* oo = las[o->v]; oo; oo = oo->las)           if (tag[oo->v]) {             mn = Min(Min(u, o->v), oo->v);             mx = Max(Max(u, o->v), oo->v);             ans -= A * mn + B * (u ^ o->v ^ oo->v ^ mn ^ mx) + C * mx;           }       for (Edge* o = las[u]; o; o = o->las) tag[o->v] = 0;     }     printf( %llu , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   const int INF = 0x3f3f3f3f;   int arr[N];   int dq[N * 2];   int main() {     int n;     scanf( %d , &n);     int dl = N, dr = N - 1;     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       if (arr[i] == 1) {         dr++;         dq[dr] = i;       }     }     long long ans = 0;     int l = 0;     for (int i = n - 1; i >= 0; i--) {       int sz = dr - dl + 1;       if (arr[i] >= 3 && (arr[i] & 1)) {         ans++;         arr[i] -= 3;       }       while (dl <= dr) {         if (arr[i] <= 1) break;         if (dq[dr] >= i) {           dr--;           continue;         }         arr[dq[dr]]--;         arr[i] -= 2;         ans++;         dr--;       }       if (!arr[i]) continue;       while (l < i) {         if (!arr[l]) {           l++;           continue;         }         if (arr[l] * 2 >= arr[i]) {           ans += arr[i] / 2;           arr[l] -= arr[i] / 2;           arr[i] = 0;           if (arr[l] == 1) {             dl--;             dq[dl] = l;           }           break;         } else {           ans += arr[l];           arr[i] -= arr[l] * 2;           arr[l] = 0;           l++;         }       }       if (arr[i]) ans += arr[i] / 3;     }     printf( %I64d n , ans);     return 0;   }


#include<iostream>   using namespace std;   void func(int i,int arr[],int ans[]){    if(arr[i]>=i+1){     return ;    }    if(arr[i]==0){    ans[i]=0;        func(i-1,arr,ans);        return;   }    else{     int currpos=i;int destionation=i-(arr[i]-1);     while(currpos>=0){      if(currpos!=destionation){       if(arr[currpos]>=currpos+1)       return;       if(arr[currpos]!=0){       destionation=destionation>currpos-(arr[currpos]-1)?currpos-(arr[currpos]-1):destionation;}      }      else{       if(arr[currpos]>=currpos+1)       return;       if(arr[currpos]==0 or arr[currpos]==1){       func(currpos-1,arr,ans);return;       }       destionation=destionation>currpos-(arr[currpos]-1)?currpos-arr[currpos]+1:destionation;      }      currpos-=1;     }     return ;    }   }   int main(){    int t;cin>>t;    while(t--){     int n;cin>>n;int arr[n];int ans[n];for(int i=0;i<n;i++){      cin>>arr[i];ans[i]=1;     }     func(n-1,arr,ans);     for(int i=0;i<n;i++){      cout<<ans[i]<<   ;     }    }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long ar1, long long ar2) {     return ar2 == 0 ? ar1 : gcd(ar2, ar1 % ar2);   }   long long add(long long ar1, long long ar2, long long m) {     if (ar1 >= m) ar1 %= m;     if (ar2 >= m) ar2 %= m;     if (ar1 < 0) ar1 += m;     if (ar2 < 0) ar2 += m;     long long res = ar1 + ar2;     if (res >= m or res <= -m) res %= m;     if (res < 0) res += m;     return res;   }   long long mul(long long ar1, long long ar2, long long m) {     if (ar1 >= m) ar1 %= m;     if (ar2 >= m) ar2 %= m;     if (ar1 < 0) ar1 += m;     if (ar2 < 0) ar2 += m;     long long res = ar1 * ar2;     if (res >= m or res <= -m) res %= m;     if (res < 0) res += m;     return res;   }   long long pow_mod(long long ar1, long long ar2, long long m) {     long long res = 1;     ar1 = ar1 % m;     while (ar2) {       if (ar2 & 1) res = mul(res, ar1, m);       ar2 >>= 1;       ar1 = mul(ar1, ar1, m);     }     return res;   }   long long fastexp(long long ar1, long long ar2) {     long long res = 1;     while (ar2) {       if (ar2 & 1) res = res * ar1;       ar2 >>= 1;       ar1 *= ar1;     }     return res;   }   long long gcdExtendido(long long ar1, long long ar2, long long *x,                          long long *y) {     if (ar1 == 0) {       *x = 0;       *y = 1;       return ar2;     }     long long x1, y1;     long long gcd = gcdExtendido(ar2 % ar1, ar1, &x1, &y1);     *x = y1 - (ar2 / ar1) * x1;     *y = x1;     return gcd;   }   long long modInverso(long long ar1, long long m) {     long long x, y;     long long g = gcdExtendido(ar1, m, &x, &y);     if (g != 1)       return -1;     else       return (x % m + m) % m;   }   bool sortbysec(const pair<long long, long long> &ar1,                  const pair<long long, long long> &ar2) {     return (ar1.second < ar2.second);   }   long long fact(long long n) {     if (n <= 1) return 1;     return mul(n, fact(n - 1), 1000000007);   }   bool probablyPrimeFermat(long long n, long long iter) {     if (n < 4) return n == 2 || n == 3;     for (long long i = 0; i < iter; i++) {       long long a = 2 + abs(rand() % (n - 3));       if (pow_mod(a, n - 1, n) != 1) return false;     }     return true;   }   bool checkPow2(long long n) { return (n > 0) && ((n & (n - 1)) == 0); }   signed main() {     long long t = 3;     vector<pair<long long, char> > cnt;     cnt.push_back({0,  A });     cnt.push_back({0,  B });     cnt.push_back({0,  C });     while (t--) {       string s;       cin >> s;       if (s[1] ==  > ) {         if (t == 0 && cnt[s[0] -  A ].first < cnt[s[2] -  A ].first) {           cout <<  Impossible n ;           return 0;         }         cnt[s[0] -  A ].first += cnt[s[2] -  A ].first + 1;       } else {         if (t == 0 && cnt[s[2] -  A ].first < cnt[s[0] -  A ].first) {           cout <<  Impossible n ;           return 0;         }         cnt[s[2] -  A ].first += cnt[s[0] -  A ].first + 1;       }     }     sort(cnt.begin(), cnt.end());     if (cnt[0].first == cnt[1].first || cnt[1].first == cnt[2].first) {       cout <<  Impossible n ;     } else {       for (long long i = 0; i < 3; i++) cout << cnt[i].second;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int n, z;   vector<int> x;   bool check(int p) {     for (int i = 0; i < p; i++)       if (x[n - p + i] - x[i] < z) return false;     return true;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> z;     x.resize(n);     for (int i = 0; i < n; i++) cin >> x[i];     sort((x).begin(), (x).end());     int l = 0, r = n / 2;     while (l < r) {       int m = (l + r + 1) >> 1;       if (check(m))         l = m;       else         r = m - 1;     }     cout << l;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c;     cin >> a >> b >> c;     long long d;     d = min(a, b) * 2 + c * 2;     if (a != b) {       d++;     }     cout << d;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, i, j, c;     char chr;     cin >> t;     bool first_diag, second_diag;     while (t--) {       cin >> n;       string arr[n];       vector<int> v;       c = 0;       for (i = 0; i < n; i++) cin >> arr[i];       first_diag = (arr[0][1] == arr[1][0]);       second_diag = (arr[n - 2][n - 1] == arr[n - 1][n - 2]);       if (first_diag && second_diag) {         if (arr[n - 2][n - 1] == arr[0][1]) {           c = 2;           v.push_back(1);           v.push_back(2);           v.push_back(2);           v.push_back(1);         }       } else if (first_diag) {         c = 1;         if (arr[n - 1][n - 2] == arr[0][1]) {           v.push_back(n);           v.push_back(n - 1);         } else {           v.push_back(n - 1);           v.push_back(n);         }       } else if (second_diag) {         c = 1;         if (arr[n - 1][n - 2] == arr[0][1]) {           v.push_back(1);           v.push_back(2);         } else {           v.push_back(2);           v.push_back(1);         }       } else {         c = 2;         v.push_back(1);         v.push_back(2);         if (arr[0][1] == arr[n - 2][n - 1]) {           v.push_back(n);           v.push_back(n - 1);         } else {           v.push_back(n - 1);           v.push_back(n);         }       }       cout << c <<   n ;       for (i = 0; i < c; i++) cout << v[2 * i] <<     << v[2 * i + 1] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n, m, k;     cin >> n >> m >> k;     vector<vector<int> > edges(m, vector<int>(2));     vector<vector<int> > graph(n + 1);     vector<int> degrees(n + 1, 0);     for (int i = 0; i < m; ++i) {       scanf( %d %d , &edges[i][0], &edges[i][1]);       degrees[edges[i][0]]++;       degrees[edges[i][1]]++;       graph[edges[i][0]].push_back(edges[i][1]);       graph[edges[i][1]].push_back(edges[i][0]);     }     map<pair<int, int>, bool> sorted;     for (int i = 0; i < n; ++i)       sorted.insert(make_pair(make_pair(degrees[i + 1], i + 1), 1));     vector<int> ans(m);     for (int i = m - 1; i >= 0; --i) {       while ((!sorted.empty()) and sorted.begin()->first.first < k) {         int temp = sorted.begin()->first.second;         sorted.erase(sorted.begin());         degrees[temp] = 0;         for (int i = 0; i < graph[temp].size(); ++i) {           auto it =               sorted.find(make_pair(degrees[graph[temp][i]], graph[temp][i]));           degrees[graph[temp][i]]--;           if (it != sorted.end()) {             sorted.erase(it);             if (degrees[graph[temp][i]] >= 0)               sorted.insert(make_pair(                   make_pair(degrees[graph[temp][i]], graph[temp][i]), 1));           }         }       }       ans[i] = sorted.size();       graph[edges[i][0]].pop_back();       graph[edges[i][1]].pop_back();       if (degrees[edges[i][0]] >= k and degrees[edges[i][1]] >= k) {         auto it1 = sorted.find(make_pair(degrees[edges[i][0]], edges[i][0]));         auto it2 = sorted.find(make_pair(degrees[edges[i][1]], edges[i][1]));         degrees[edges[i][0]]--;         degrees[edges[i][1]]--;         if (it1 != sorted.end()) {           sorted.erase(it1);           sorted.insert(               make_pair(make_pair(degrees[edges[i][0]], edges[i][0]), 1));         }         if (it2 != sorted.end()) {           sorted.erase(it2);           sorted.insert(               make_pair(make_pair(degrees[edges[i][1]], edges[i][1]), 1));         }       }     }     for (int i = 0; i < m; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, a, b, res;   int main() {     cin >> n >> m;     for (a = 0; a <= 1000; a++) {       for (b = 0; b <= 1000; b++) {         if (a * a + b == n && a + b * b == m) {           res++;         }       }     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 200009;   int n, q, k, x, s;   vector<pair<int, int> > p;   vector<vector<int> > pb;   set<int> last;   void solve() {     cin >> n;     p.resize(n + 1);     pb.resize(n + 1);     for (int i = 0; i < n; i++) {       cin >> x >> s;       p[i] = {x, s};       pb[x].push_back(i);     }     for (int i = 1; i <= n; i++)       if (pb[i].size() > 0) last.insert(pb[i].back());     last.insert(-1);     for (cin >> q; q; q--) {       cin >> k;       vector<int> esc(k);       for (int i = 0; i < k; i++) {         cin >> esc[i];         if (pb[esc[i]].size() > 0) last.erase(pb[esc[i]].back());       }       pair<int, int> ans = {0, 0};       if (last.size() != 1) {         auto iw = --last.end();         int win = p[*iw].first;         auto bwin = *upper_bound(pb[win].begin(), pb[win].end(), *--iw);         ans = {win, p[bwin].second};       }       cout << ans.first <<     << ans.second << endl;       for (int i = 0; i < k; i++)         if (pb[esc[i]].size() > 0) last.insert(pb[esc[i]].back());     }   }   int main() {     ios_base::sync_with_stdio(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   vector<int> gr[300005];   int n, m;   int col[300005];   void go(int now) {     for (auto to : gr[now]) {       if (col[to]) continue;       col[to] = 3 - col[now];       go(to);     }     int cnt = 0;     for (auto to : gr[now]) {       cnt += (col[to] == col[now]);     }     if (cnt > 1) col[now] = 3 - col[now];   }   int main() {     int i, j;     scanf( %d , &n);     scanf( %d , &m);     for (i = 1; i <= m; i++) {       int u, v;       scanf( %d , &u);       scanf( %d , &v);       gr[u].push_back(v);       gr[v].push_back(u);     }     for (i = 1; i <= n; i++) {       if (col[i]) continue;       col[i] = 1;       go(i);     }     for (i = 1; i <= n; i++) printf( %d , col[i] - 1);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   int n, vis[(1 << 21) + 1], col = 1, m, tw[22], cnt[(1 << 21) + 1];   long long dp[(1 << 21) + 1];   string st[55];   long long rep[(1 << 21) + 1];   int count_bit(long long x) {     int ret = 0;     while (x) {       ret++;       x ^= x & (-x);     }     return ret;   }   int main() {     cin >> n;     if (n == 1) {       printf( %.10lf n , 0.);       return 0;     }     for (int i = 0; i < 22; i++) tw[i] = 1 << i;     for (int i = 0; i < n; i++) cin >> st[i];     m = st[0].size();     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (i != j) {           int msk = 0;           for (int z = 0; z < m; z++)             if (st[i][z] == st[j][z]) msk |= tw[z];           rep[msk] |= 1ll << i;         }     for (int msk = tw[m] - 1; msk >= 0; msk--)       for (int i = 0; i < m; i++)         if (msk & tw[i]) {           rep[msk ^ tw[i]] |= rep[msk];         }     for (int msk = tw[m + 1] - 1; msk >= 0; msk--) cnt[msk] = count_bit(msk);     for (int msk = 0; msk < tw[m]; msk++) {       int c = cnt[msk];       for (int i = 0; i < m; i++)         if (!(msk & tw[i])) {           long long tmp = rep[msk] ^ rep[msk ^ tw[i]];           dp[c + 1] += count_bit(tmp);         }     }     double ans = 0;     for (int i = 1; i < m + 1; i++) {       double tmp = double(dp[i] * i) / (m - i + 1);       for (int j = 0; j < i - 1; j++) tmp *= double(i - 1 - j) / (m - j);       ans += tmp;     }     ans /= n;     printf( %.10lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using pli = pair<ll, int>;   using pil = pair<int, ll>;   using pll = pair<ll, ll>;   template <typename T>   using vec = vector<T>;   using vi = vec<int>;   using vl = vec<ll>;   template <typename T>   using que = queue<T>;   template <typename T>   using deq = deque<T>;   template <typename T>   T id(T b) {     return b;   };   template <typename T>   void chmax(T &x, T y) {     if (x < y) x = y;   }   template <typename T>   void chmin(T &x, T y) {     if (x > y) x = y;   }   template <typename S, typename K>   bool contains(S &s, K k) {     return s.find(k) != s.end();   }   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);   }   constexpr ll TEN(int n) {     if (n == 0)       return 1LL;     else       return 10LL * TEN(n - 1);   }   int main() {     fastio();     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       vi a(n);       set<int, greater<int>> s;       for (int i = 0; i < int(n); i++) {         cin >> a[i];         s.insert(a[i]);       }       map<int, int> mn, mx;       for (int i = 0; i < int(n); i++) mx[a[i]] = i;       for (int i = n - 1; i >= 0; i--) mn[a[i]] = i;       vi l((s).begin(), (s).end());       vi dp(s.size());       dp[0] = 1;       for (int i = 1; i < l.size(); i++) {         if (mn[l[i - 1]] >= mx[l[i]]) {           dp[i] = dp[i - 1] + 1;         } else {           dp[i] = 1;         }       }       cout << l.size() - *max_element((dp).begin(), (dp).end()) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = int(1e5 + 3);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     int size = s.length();     int count4 = 0;     int count7 = 0;     for (int i = 0; i < size; i++) {       if (s[i] ==  7 ) count7++;       if (s[i] ==  4 ) count4++;     }     if (count4 == 0 && count7 == 0)       cout << -1 <<   n ;     else if (count4 >= count7)       cout << 4 <<   n ;     else       cout << 7 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[4], leaf;   vector<int> son[5140];   void no() {     puts( NO );     exit(0);   }   void init() {     scanf( %d , &n);     for (int i = 0; i < 4; i++) scanf( %d , &a[i]);     for (int i = 2; i <= n; i++) {       int pi;       scanf( %d , &pi);       son[pi].push_back(i);     }     for (int i = 1; i <= n; i++)       if (son[i].empty()) leaf++;     if (leaf & 1) no();   }   int sz[5140];   vector<int> items;   int go(int now) {     int who = -1;     if (son[now].empty()) {       sz[now] = 1;       for (int i = 0; i < 4; i++)         if (now == a[i]) who = i;       return who;     }     vector<int> wt;     for (int s : son[now]) {       int ret = go(s);       if (ret == -1)         wt.push_back(sz[s]);       else {         who = ret;         if (who > 1) wt.push_back(sz[s]);       }     }     if (who == -1 or who > 1) {       sz[now] = 0;       for (auto i : wt) sz[now] += i;     } else {       for (auto i : wt) items.push_back(i);     }     return who;   }   bool dp[5140];   void knapsack(int tar) {     if (tar < 0 or tar >= 5140) no();     for (int i = 0; i <= tar; i++) dp[i] = false;     dp[0] = true;     for (auto i : items)       for (int j = tar - i; j >= 0; j--) dp[j + i] |= dp[j];     if (not dp[tar]) no();   }   void solve() {     for (int _ = 0; _ < 2; _++) {       items.clear();       int cand = (leaf - 2) >> 1;       for (int s : son[1]) {         int ret = go(s);         if (ret == -1)           items.push_back(sz[s]);         else if (ret == 2)           cand -= sz[s];       }       knapsack(cand);       swap(a[0], a[2]);       swap(a[1], a[3]);     }     puts( YES );   }   int main() {     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[2000];   void DFS(int v, int n) {     while (g[v].size() != 0) {       int x = g[v].back();       g[v].pop_back();       for (int k = 0; k < g[x].size(); k++)         if (g[x][k] == v) {           g[x].erase(g[x].begin() + k);           break;         }       DFS(x, n);       if (v != n + 1 && x != n + 1) cout << v <<     << x << endl;     }   }   int main() {     int t, n, m;     cin >> t;     for (int k = 0; k < t; k++) {       cin >> n >> m;       int odd[n];       memset(odd, 0, sizeof(odd));       int r = 0;       for (int x, y, i = 1; i <= m; i++) {         cin >> x >> y;         g[x].push_back(y);         g[y].push_back(x);       }       for (int l = 1; l <= n; l++)         if (g[l].size() % 2 == 1) {           odd[r] = l;           r++;         }       for (int o = 0; o < r; o++) {         g[odd[o]].push_back(n + 1);         g[n + 1].push_back(odd[o]);       }       cout << n - r << endl;       for (int q = 1; q <= n; q++) DFS(q, n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD(1000000007);   const int INF((1 << 30) - 1);   const int MAXN();   int main() {     int n;     scanf( %d , &n);     string a;     cin >> a;     int b[26];     for (int i = 0; i < 26; i++) b[i] = -1;     vector<int> d;     int cnt = 0;     for (int i = 0; i < a.size(); i++) {       if (b[a[i] -  a ] == -1) {         cnt++;         b[a[i] -  a ] = i;         if (d.size() < n) d.push_back(i);       }     }     if (cnt < n) {       printf( NO );     } else {       sort(d.begin(), d.end());       printf( YES n );       for (int i = 0; i < d.size() - 1; i++)         cout << a.substr(d[i], d[i + 1] - d[i]) << endl;       cout << a.substr(d[d.size() - 1], a.size() - d[d.size() - 1]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(NULL);     int n, m;     cin >> n >> m;     if (n == 1)       cout << n;     else       cout << ((m - 1) >= (n - m) ? m - 1 : m + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long double PI = acos((long double)-1);   long long cnt[32][2];   class Node {    public:     Node* child[2];     long long cnt;     Node() {       child[0] = child[1] = NULL;       cnt = 0;     }   };   class Trie {    private:     Node* root;       public:     Trie() { root = new Node(); }     void insert(long long no) {       Node* curr = root;       for (long long i = 31; i >= 0; --i) {         long long bit = (no >> i) & 1;         if (!curr->child[bit]) {           curr->child[bit] = new Node();         }         if (curr->child[0] && curr->child[1]) {           if (bit) {             cnt[i][bit] += curr->child[0]->cnt;           } else {             cnt[i][bit] += curr->child[1]->cnt;           }         }         curr = curr->child[bit];         ++curr->cnt;       }     }   };   void solve() {     long long n;     cin >> n;     Trie t;     for (long long i = 1; i <= n; ++i) {       long long x;       cin >> x;       t.insert(x);     }     long long x = 0;     long long inv = 0;     for (long long i = 31; i >= 0; --i) {       if (cnt[i][1] < cnt[i][0]) {         x += (1 << i);         inv += cnt[i][1];       } else {         inv += cnt[i][0];       }     }     cout << inv <<     << x <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:36777216 )   template <class T>   inline T &RD(T &);   template <class T>   inline void OT(const T &);   inline long long RD() {     long long x;     return RD(x);   }   inline double &RF(double &);   inline double RF() {     double x;     return RF(x);   }   inline char *RS(char *s);   template <class T0, class T1>   inline T0 &RD(T0 &x0, T1 &x1) {     RD(x0), RD(x1);     return x0;   }   template <class T0, class T1, class T2>   inline T0 &RD(T0 &x0, T1 &x1, T2 &x2) {     RD(x0), RD(x1), RD(x2);     return x0;   }   template <class T0, class T1, class T2, class T3>   inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) {     RD(x0), RD(x1), RD(x2), RD(x3);     return x0;   }   template <class T0, class T1, class T2, class T3, class T4>   inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) {     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);     return x0;   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);     return x0;   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) {     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);     return x0;   }   template <class T0, class T1>   inline void OT(const T0 &x0, const T1 &x1) {     OT(x0), OT(x1);   }   template <class T0, class T1, class T2>   inline void OT(const T0 &x0, const T1 &x1, const T2 &x2) {     OT(x0), OT(x1), OT(x2);   }   template <class T0, class T1, class T2, class T3>   inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3) {     OT(x0), OT(x1), OT(x2), OT(x3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3,                  const T4 &x4) {     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3,                  const T4 &x4, const T5 &x5) {     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3,                  const T4 &x4, const T5 &x5, const T6 &x6) {     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);   }   inline double &RF(double &a, double &b) {     RF(a), RF(b);     return a;   }   inline double &RF(double &a, double &b, double &c) {     RF(a), RF(b), RF(c);     return a;   }   inline double &RF(double &a, double &b, double &c, double &d) {     RF(a), RF(b), RF(c), RF(d);     return a;   }   inline double &RF(double &a, double &b, double &c, double &d, double &e) {     RF(a), RF(b), RF(c), RF(d), RF(e);     return a;   }   inline double &RF(double &a, double &b, double &c, double &d, double &e,                     double &f) {     RF(a), RF(b), RF(c), RF(d), RF(e), RF(f);     return a;   }   inline double &RF(double &a, double &b, double &c, double &d, double &e,                     double &f, double &g) {     RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g);     return a;   }   inline void RS(char *s1, char *s2) { RS(s1), RS(s2); }   inline void RS(char *s1, char *s2, char *s3) { RS(s1), RS(s2), RS(s3); }   template <class T>   inline void RST(T &A) {     memset(A, 0, sizeof(A));   }   template <class T>   inline void FLC(T &A, int x) {     memset(A, x, sizeof(A));   }   template <class T>   inline T &SRT(T &A) {     sort(A.begin(), A.end());     return A;   }   template <class T, class C>   inline T &SRT(T &A, C B) {     sort(A.begin(), A.end(), B);     return A;   }   template <class T>   inline T &UNQ(T &A) {     A.resize(unique(SRT(A).begin(), SRT(A).end()) - A.begin());     return A;   }   const int dx4[] = {-1, 0, 1, 0};   const int dy4[] = {0, 1, 0, -1};   const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};   const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};   const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};   const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};   const int MOD = 1000000007;   const int INF = 0x3f3f3f3f;   const long long INFF = 1LL << 60;   const double EPS = 1e-9;   const double OO = 1e15;   const double PI = acos(-1.0);   template <class T>   inline void checkMin(T &a, const T b) {     if (b < a) a = b;   }   template <class T>   inline void checkMax(T &a, const T b) {     if (a < b) a = b;   }   template <class T>   inline void checkMin(T &a, T &b, const T x) {     checkMin(a, x), checkMin(b, x);   }   template <class T>   inline void checkMax(T &a, T &b, const T x) {     checkMax(a, x), checkMax(b, x);   }   template <class T, class C>   inline void checkMin(T &a, const T b, C c) {     if (c(b, a)) a = b;   }   template <class T, class C>   inline void checkMax(T &a, const T b, C c) {     if (c(a, b)) a = b;   }   template <class T>   inline T min(T a, T b, T c) {     return min(min(a, b), c);   }   template <class T>   inline T max(T a, T b, T c) {     return max(max(a, b), c);   }   template <class T>   inline T min(T a, T b, T c, T d) {     return min(min(a, b), min(c, d));   }   template <class T>   inline T max(T a, T b, T c, T d) {     return max(max(a, b), max(c, d));   }   template <class T>   inline T sqr(T a) {     return a * a;   }   template <class T>   inline T cub(T a) {     return a * a * a;   }   inline int ceil(int x, int y) { return (x - 1) / y + 1; }   inline int sgn(double x) { return x < -EPS ? -1 : x > EPS; }   inline int sgn(double x, double y) { return sgn(x - y); }   namespace BO {   inline bool _1(int x, int i) { return bool(x & 1 << i); }   inline bool _1(long long x, int i) { return bool(x & 1LL << i); }   inline long long _1(int i) { return 1LL << i; }   template <class T>   inline bool odd(T x) {     return x & 1;   }   template <class T>   inline bool even(T x) {     return !odd(x);   }   template <class T>   inline T low_bit(T x) {     return x & -x;   }   inline int count_bits(int x) { return __builtin_popcount(x); }   inline int count_bits(long long x) { return __builtin_popcountll(x); }   }  // namespace BO   using namespace BO;   namespace NT {   inline void INC(int &a, int b) {     a += b;     if (a >= MOD) a -= MOD;   }   inline int sum(int a, int b) {     a += b;     if (a >= MOD) a -= MOD;     return a;   }   inline void DEC(int &a, int b) {     a -= b;     if (a < 0) a += MOD;   }   inline int dff(int a, int b) {     a -= b;     if (a < 0) a += MOD;     return a;   }   inline void MUL(int &a, int b) { a = (long long)a * b % MOD; }   inline int pdt(int a, int b) { return (long long)a * b % MOD; }   inline int sum(int a, int b, int c) { return sum(sum(a, b), c); }   inline int sum(int a, int b, int c, int d) { return sum(sum(a, b), sum(c, d)); }   inline int pdt(int a, int b, int c) { return pdt(pdt(a, b), c); }   inline int pdt(int a, int b, int c, int d) { return pdt(pdt(pdt(a, b), c), d); }   inline int pow(int a, int b) {     int c(1);     while (b) {       if (b & 1) MUL(c, a);       MUL(a, a), b >>= 1;     }     return c;   }   inline int pow(int a, long long b) {     int c(1);     while (b) {       if (b & 1) MUL(c, a);       MUL(a, a), b >>= 1;     }     return c;   }   template <class T>   inline T pow(T a, long long b) {     T c(1);     while (b) {       if (b & 1) c *= a;       a *= a, b >>= 1;     }     return c;   }   inline int _I(int b) {     int a = MOD, x1 = 0, x2 = 1, q;     while (true) {       q = a / b, a %= b;       if (!a) return (x2 + MOD) % MOD;       DEC(x1, pdt(q, x2));       q = b / a, b %= a;       if (!b) return (x1 + MOD) % MOD;       DEC(x2, pdt(q, x1));     }   }   inline void DIV(int &a, int b) { MUL(a, _I(b)); }   inline int qtt(int a, int b) { return pdt(a, _I(b)); }   inline int phi(int n) {     int res = n;     for (int i = 2; sqr(i) <= n; ++i)       if (!(n % i)) {         DEC(res, qtt(res, i));         do {           n /= i;         } while (!(n % i));       }     if (n != 1) DEC(res, qtt(res, n));     return res;   }   }  // namespace NT   using namespace NT;   namespace Math {   long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }   long long extendGCD(long long a, long long b, long long &x, long long &y) {     if (!b) return x = 1, y = 0, a;     long long res = extendGCD(b, a % b, x, y), tmp = x;     x = y, y = tmp - (a / b) * y;     return res;   }   long long power(long long x, long long k) {     long long res = 1;     while (k) {       if (k & 1) res *= x;       x *= x, k >>= 1;     }     return res;   }   long long powerMod(long long x, long long k, long long m) {     long long res = 1;     while (x %= m, k) {       if (k & 1) res *= x, res %= m;       x *= x, k >>= 1;     }     return res;   }   long long inverse(long long a, long long p, long long t = 1) {     long long pt = power(p, t);     long long x, y;     y = extendGCD(a, pt, x, y);     return x < 0 ? x += pt : x;   }   long long linearCongruence(long long a, long long b, long long p, long long q) {     long long x, y;     y = extendGCD(p, q, x, y);     while (b < a) b += q / y;     x *= b - a, x = p * x + a, x %= p * q;     if (x < 0) x += p * q;     return x;   }   const int PRIMERANGE = 1000000;   int prime[PRIMERANGE + 1];   int getPrime() {     memset(prime, 0, sizeof(int) * (PRIMERANGE + 1));     for (int i = 2; i <= PRIMERANGE; i++) {       if (!prime[i]) prime[++prime[0]] = i;       for (int j = 1; j <= prime[0] && prime[j] <= PRIMERANGE / i; j++) {         prime[prime[j] * i] = 1;         if (i % prime[j] == 0) break;       }     }     return prime[0];   }   int factor[100][3], facCnt;   int getFactors(int x) {     facCnt = 0;     int tmp = x;     for (int i = 1; prime[i] <= tmp / prime[i]; i++) {       factor[facCnt][1] = 1, factor[facCnt][2] = 0;       if (tmp % prime[i] == 0) factor[facCnt][0] = prime[i];       while (tmp % prime[i] == 0)         factor[facCnt][2]++, factor[facCnt][1] *= prime[i], tmp /= prime[i];       if (factor[facCnt][1] > 1) facCnt++;     }     if (tmp != 1)       factor[facCnt][0] = tmp, factor[facCnt][1] = tmp, factor[facCnt++][2] = 1;     return facCnt;   }   long long combinationModP(long long n, long long k, long long p) {     if (k > n) return 0;     if (n - k < k) k = n - k;     long long a = 1, b = 1, x, y;     int pcnt = 0;     for (int i = 1; i <= k; i++) {       x = n - i + 1, y = i;       while (x % p == 0) x /= p, pcnt++;       while (y % p == 0) y /= p, pcnt--;       x %= p, y %= p, a *= x, b *= y;       b %= p, a %= p;     }     if (pcnt) return 0;     extendGCD(b, p, x, y);     if (x < 0) x += p;     a *= x, a %= p;     return a;   }   };  // namespace Math   namespace Geo {   const double eps = 1e-8;   int dblcmp(double d) { return d < -eps ? -1 : d > eps; }   int sgn(double a) { return a < -eps ? -1 : a > eps; }   inline double sqr(double x) { return x * x; }   };  // namespace Geo   template <class T>   inline T &RD(T &x) {     char c;     for (c = getchar(); c <  - ; c = getchar())       ;     if (c ==  - ) {       x =  0  - getchar();       for (c = getchar();  0  <= c && c <=  9 ; c = getchar())         x = x * 10 +  0  - c;     } else {       x = c -  0 ;       for (c = getchar();  0  <= c && c <=  9 ; c = getchar())         x = x * 10 + c -  0 ;     }     return x;   }   inline double &RF(double &x) {     scanf( %lf , &x);     return x;   }   inline char *RS(char *s) {     scanf( %s , s);     return s;   }   int Case;   template <class T>   inline void OT(const T &x) {     cout << x << endl;   }   int n;   void solve() {     cin >> n;     vector<int> p, q;     p.clear();     q.clear();     cout << 1 <<     << n - 1 <<     << 1;     for (int i = 2; i <= n; ++i) {       p.push_back(i);       cout <<     << i;     }     cout << endl;     cout.flush();     int d, dd;     cin >> d;     while (p.size() > 1) {       q.clear();       while (p.size() - 1 >= q.size() + 1) {         q.push_back(p.back());         p.pop_back();       }       cout << 1 <<     << int(q.size()) <<     << 1;       for (int i = 0; i < int(q.size()); ++i) cout <<     << q[i];       cout << endl;       cout.flush();       cin >> dd;       if (dd == d) {         p = q;       }     }     int x = p.back();     cout << 1 <<     << n - 1 <<     << x;     for (int i = 1; i <= n; ++i)       if (i != x) {         cout <<     << i;       }     cout << endl;     cout.flush();     cin >> d;     cout << -1 <<     << d << endl;     cout.flush();   }   int main() {     cin >> Case;     while (Case--) solve();   }


#include <bits/stdc++.h>   using namespace std;   template <class T1>   void deb(T1 e1) {     cout << e1 << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   template <class T>   T gcd(const T a, const T b) {     return (b ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(const T a, const T b) {     return (a / gcd<T>(a, b) * b);   }   struct node {     long long x, y;     node() {}     node(long long x, long long y) : x(x), y(y) {}     bool operator<(const node& p) const { return x < p.x; }   };   string s1, s2;   long long convert_10(long long n, string s) {     long long l;     l = s.size() - 1;     long long x = 1, y = 0, p;     for (long long i = l; i >= 0; i--) {       if (s[i] >=  0  && s[i] <=  9 )         p = s[i] -  0 ;       else         p = 10 + s[i] -  A ;       y += x * p;       x *= n;     }     return y;   }   string convert_base(long long n, long long x) {     string s =   ;     while (x > 0) {       long long y = x % n;       x /= n;       char c;       if (y > 9)         c =  A  + (y - 10);       else         c =  0  + y;       s = c + s;     }     if (s ==   ) s =  0 ;     return s;   }   string convert_roman(long long n) {     string s =   ;     string one[10] = {  ,  I ,  II ,  III ,  IV ,  V ,  VI ,  VII ,  VIII ,  IX };     string ten[10] = {  ,  X ,  XX ,  XXX ,  XL ,  L ,  LX ,  LXX ,  LXXX ,  XC };     string hundred[10] = {  ,   C ,   CC ,   CCC ,   CD ,                            D ,  DC ,  DCC ,  DCCC ,  CM };     string thousand[4] = {  ,  M ,  MM ,  MMM };     s += thousand[n / 1000];     n %= 1000;     s += hundred[n / 100];     n %= 100;     s += ten[n / 10];     n %= 10;     s += one[n];     return s;   }   long long convert_num(string s) {     long long x = 0;     for (long long i = 0; i < s.size(); i++) x = x * 10 + s[i] -  0 ;     return x;   }   int main() {     long long i, j, k, l, x, y, z, t, m, n;     cin >> n >> s1 >> s2;     x = convert_10(n, s2);     string s;     if (s1 ==  R ) {       s = convert_roman(x);     } else {       y = convert_num(s1);       s = convert_base(y, x);     }     deb(s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int arr[N], f[N];   int main() {     int n;     scanf( %d , &n);     set<int> st;     for (int i = 1; i <= n; ++i) {       st.insert(i);       scanf( %d , arr + i);     }     st.insert(n + 1);     int q;     scanf( %d , &q);     int t, x, v;     while (q--) {       scanf( %d , &t);       if (t == 1) {         scanf( %d %d , &x, &v);         int cur = *st.lower_bound(x);         while (v && cur <= n) {           if (f[cur] + v < arr[cur]) {             f[cur] += v;             v = 0;           } else {             v -= (arr[cur] - f[cur]);             f[cur] = arr[cur];             st.erase(cur);             cur = *st.lower_bound(x);           }         }       } else {         scanf( %d , &x);         printf( %d n , f[x]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   #define F first   #define S second   #define pb push_back   #define ll long long   #define all(x) x.begin() , x.end()   #define rep(i,s,e) for (int i = s; i < e; ++i)   #define rev(i,s,e) for (int i = s; i > e; --i)      const int N = 2e5 + 99 ;            int main() {       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);   #ifdef CLion       freopen( input.txt  ,  r  , stdin);   //    freopen( output.txt ,  w  , stdout);   #endif          int t; cin >> t;       while ( t-- ){           int n ; cin >> n;           vector<int> vec(n);           for ( int &i : vec ){               cin >> i;           }           sort( all(vec) );           cout << n - (upper_bound(all(vec) , vec.front()) - vec.begin()) <<   n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     long long g = n - 1, res = 0;     while (g > 0 && k > 0) {       res += g * 2 - 1;       k--;       g -= 2;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> tmp;   vector<vector<int>> sol[4];   int lov[7][7];   int hero(string s) {     if (s ==  Troll ) return 0;     if (s ==  Dracul ) return 1;     if (s ==  Anka ) return 2;     if (s ==  Snowy ) return 3;     if (s ==  Hexadecimal ) return 4;     if (s ==  Chapay )       return 5;     else       return 6;   }   void rec(int i, int a, int b, int c) {     if (i == 7) {       int z[] = {a, b, c};       sort(z, z + 3);       if (z[2] == 5 && z[1] == 1 && z[0] == 1) sol[0].push_back(tmp);       if (z[2] == 4 && z[1] == 2 && z[0] == 1) sol[1].push_back(tmp);       if (z[2] == 3 && z[1] == 3 && z[0] == 1) sol[2].push_back(tmp);       if (z[2] == 3 && z[1] == 2 && z[0] == 2) sol[3].push_back(tmp);       return;     }     tmp.push_back(1);     rec(i + 1, a + 1, b, c);     tmp.pop_back();     tmp.push_back(2);     rec(i + 1, a, b + 1, c);     tmp.pop_back();     tmp.push_back(3);     rec(i + 1, a, b, c + 1);     tmp.pop_back();   }   int main() {     rec(0, 0, 0, 0);     int arr[4][3];     pair<int, int> exp[3];     int mini = 1e9, maxi = 0;     set<int> minI;     arr[0][0] = 5, arr[0][1] = 1, arr[0][2] = 1;     arr[1][0] = 4, arr[1][1] = 2, arr[1][2] = 1;     arr[2][0] = 3, arr[2][1] = 3, arr[2][2] = 1;     arr[3][0] = 3, arr[3][1] = 2, arr[3][2] = 2;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string s, tmp, s2;       cin >> s >> tmp >> s2;       int x = hero(s), y = hero(s2);       lov[x][y] = 1;     }     for (int i = 0; i < 3; i++) {       cin >> exp[i].second;       exp[i].first = i;     }     for (int i = 0; i < 4; i++) {       int a = 0;       do {         int ans[3] = {};         for (int j = 0; j < 3; j++) ans[j] = exp[j].second / arr[i][j];         sort(ans, ans + 3);         if (ans[2] - ans[0] < mini) minI.clear();         if (ans[2] - ans[0] <= mini) minI.insert(i);         mini = min(ans[2] - ans[0], mini);         a++;       } while (next_permutation(exp, exp + 3));     }     for (set<int>::iterator it = minI.begin(); it != minI.end(); it++) {       for (int i = 0; i < sol[*it].size(); i++) {         int tmpA = 0;         for (int x = 0; x < 7; x++) {           for (int y = 0; y < 7; y++) {             if (x != y && sol[*it][i][x] == sol[*it][i][y] && lov[x][y]) tmpA++;           }         }         maxi = max(tmpA, maxi);       }     }     cout << mini <<     << maxi << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n;     scanf( %d , &n);     for (i = 1; i <= 4; ++i) {       int m1, m2, a, b;       scanf( %d%d , &a, &b);       m1 = min(a, b);       scanf( %d%d , &a, &b);       m2 = min(a, b);       if (m1 + m2 <= n) {         printf( %d %d %d n , i, m1, n - m1);         return 0;       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   const double EPS = 1e-9;   const char *crop[3] = { Carrots ,  Kiwis ,  Grapes };   int m, n, nw, nq;   int main() {     scanf( %d%d%d%d , &m, &n, &nw, &nq);     set<int> waste[40000];     for (int i = (0); i < (nw); ++i) {       int x, y;       scanf( %d%d , &y, &x);       x--, y--;       waste[y].insert(x);     }     int hd[40000];     for (int i = 0, tmp = 0; i < m; i++) {       hd[i] = tmp;       tmp = (tmp + (n - waste[i].size())) % 3;     }     for (int i = (0); i < (nq); ++i) {       int x, y;       scanf( %d%d , &y, &x);       x--, y--;       if (waste[y].count(x) == 1) {         puts( Waste );       } else {         int tmp = distance(waste[y].begin(), waste[y].lower_bound(x));         tmp = x - tmp;         tmp = (hd[y] + tmp) % 3;         puts(crop[tmp]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 100000000;   const double eps = 1e-10;   const int MAXN = 110;   set<int> sx, sy;   int in[10][2];   set<int>::iterator it1, it2;   int main() {     int x, y;     for (int i = 0; i < (8); ++i) {       scanf( %d%d , &x, &y);       in[i][0] = x;       in[i][1] = y;       if (!sx.count(x)) sx.insert(x);       if (!sy.count(y)) sy.insert(y);     }     if ((int)sx.size() != 3 || (int)sy.size() != 3)       printf( %s n ,  ugly );     else {       int mat[5][5];       memset(mat, 0, sizeof(mat));       int cnt = 0, f = 1;       map<int, int> xx, yy;       for (__typeof((sx).begin()) it1 = (sx).begin(); it1 != (sx).end(); it1++)         xx[(*it1)] = cnt++;       cnt = 0;       for (__typeof((sy).begin()) it2 = (sy).begin(); it2 != (sy).end(); it2++)         yy[(*it2)] = cnt++;       for (int i = 0; i < (8); ++i) mat[xx[in[i][0]]][yy[in[i][1]]] = 1;       for (int i = 0; i < (3); ++i) {         for (int j = 0; j < (3); ++j) {           if (i == 1 && j == 1 && mat[i][j]) f = 0;           if ((i != 1 || j != 1) && !mat[i][j]) f = 0;         }       }       if (f)         printf( %s n ,  respectable );       else         printf( %s n ,  ugly );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     long long int a, b, c;     cin >> t;     while (t--) {       cin >> a >> b >> c;       long long int max_val = (a + c);       long long int min_val = b;       if (a + c <= b) {         cout << 0 << endl;       } else if (b + c < a) {         cout << c + 1 << endl;       } else {         long long int ans = (max_val - min_val + 1) / 2;         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110;   long long read(void) {     char ch = getchar();     long long sum = 0;     bool f = 0;     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) {       f = 1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) sum = sum * 10 + ch -  0 , ch = getchar();     if (f) sum = -sum;     return sum;   }   int T, n, m;   string st;   int col[N][N];   int tA;   struct node {     int x1, y1, x2, y2, x3, y3;   } que[N * N * 3];   void update(int x, int y) {     if (x + 1 <= n) {       if (y + 1 <= m) {         que[++tA] = (node){x, y, x, y + 1, x + 1, y + 1};         que[++tA] = (node){x, y, x + 1, y, x + 1, y + 1};         que[++tA] = (node){x, y, x + 1, y, x, y + 1};       } else {         que[++tA] = (node){x, y, x, y - 1, x + 1, y - 1};         que[++tA] = (node){x, y, x + 1, y, x + 1, y - 1};         que[++tA] = (node){x, y, x + 1, y, x, y - 1};       }     } else {       if (y + 1 <= m) {         que[++tA] = (node){x, y, x, y + 1, x - 1, y + 1};         que[++tA] = (node){x, y, x - 1, y, x - 1, y + 1};         que[++tA] = (node){x, y, x - 1, y, x, y + 1};       } else {         que[++tA] = (node){x, y, x, y - 1, x - 1, y - 1};         que[++tA] = (node){x, y, x - 1, y, x - 1, y - 1};         que[++tA] = (node){x, y, x - 1, y, x, y - 1};       }     }   }   void solve(void) {     n = read();     m = read();     tA = 0;     for (int i = 1; i <= n; i++) {       cin >> st;       for (int j = 1; j <= m; j++) col[i][j] = (st[j - 1] ==  0 ) ? 0 : 1;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (col[i][j] == 1) update(i, j);     printf( %d n , tA);     for (int i = 1; i <= tA; i++)       printf( %d %d %d %d %d %d n , que[i].x1, que[i].y1, que[i].x2, que[i].y2,              que[i].x3, que[i].y3);     return;   }   int main() {     T = read();     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int a[5];     int Min;     while (scanf( %d%d%d%d%d , a, a + 1, a + 2, a + 3, a + 4) != EOF) {       Min = a[0];       if (a[1] < Min) Min = a[1];       if (a[2] / 2 < Min) Min = a[2] / 2;       if (a[3] / 7 < Min) Min = a[3] / 7;       if (a[4] / 4 < Min) Min = a[4] / 4;       printf( %d n , Min);     }     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long int gcd(long long int a, long long int b) {     if (a < b)       return gcd(b, a);     else if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long int isPrime(long long int n) {     long long int p = (long long int)sqrt(n);     for (int i = (2); i <= (p); i += (1))       if (n % i == 0) return 0;     return 1;   }   long long int pow(long long int b, long long int e) {     if (e == 0)       return 1;     else if (e % 2 == 0) {       long long int a = pow(b, e / 2);       return a * a;     } else {       long long int a = pow(b, e / 2);       return b * a * a;     }   }   long long int powm(long long int x, long long int y,                      long long int m = 1000000007) {     x = x % m;     long long int res = 1;     while (y) {       if (y & 1) res = res * x;       res %= m;       y = y >> 1;       x = x * x;       x %= m;     }     return res;   }   long long int modInverse(long long int a, long long int m) {     return powm(a, m - 2, m);   }   void solve() {     long long int x, y;     cin >> x >> y;     long long int c[7];     for (int i = (1); i <= (6); i += (1)) cin >> c[i];     long long int ans = LLONG_MAX;     int isnegx = 1, isnegy = 1;     if (x < 0) isnegx = -1;     if (y < 0) isnegy = -1;     swap(x, y);     if (x >= 0 and y >= 0) {       if (x <= y) {         ans = min({ans, c[1] * x + (y - x) * c[6], c[1] * y + (y - x) * c[5],                    c[2] * x + c[6] * y});       } else {         ans = min({ans, c[1] * x + (x - y) * c[3], c[1] * y + (x - y) * c[2],                    c[2] * x + c[6] * y});       }     } else if (x <= 0 and y <= 0) {       x *= -1;       y *= -1;       if (x <= y) {         ans = min({ans, c[4] * x + (y - x) * c[3], c[4] * y + (y - x) * c[2],                    c[5] * x + c[3] * y});       } else {         ans = min({ans, c[4] * x + (x - y) * c[6], c[4] * y + (x - y) * c[5],                    c[5] * x + c[3] * y});       }     } else {       x = isnegx * abs(x);       y = isnegy * abs(y);       if (x <= 0) {         x *= -1;         ans = min({ans, c[1] * x + (x + y) * c[3], c[4] * y + (x + y) * c[2],                    c[2] * x + c[3] * y});       } else {         y *= -1;         ans = min({ans, c[4] * x + (x + y) * c[6], c[1] * y + (x + y) * c[5],                    c[5] * x + c[6] * y});       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int T;     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ar[1000001], x, ars[1000001];   int main() {     cin >> n >> x;     for (int i = 0; i < n; i++) {       cin >> ar[i];       ars[ar[i]]++;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       ars[ar[i]]--;       ans += (ars[(ar[i] ^ x)]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   const int MaxN = 300;   using namespace std;   int n, m;   long long K;   int A1[MaxN + 5][2], A3[MaxN + 5][MaxN + 5];   const long long INF = 1e18;   long long A2[MaxN + 5][MaxN + 5];   int fail[MaxN + 5];   void Get(string s) {     int z = (int)s.length();     fail[0] = 0;     for (int i = 1; i < z; i++) {       int j = fail[i - 1];       while (j > 0 && s[j] != s[i]) j = fail[j - 1];       if (s[j] == s[i]) j++;       fail[i] = j;     }     for (int i = 0; i <= z; i++) {       for (int j = 0; j < 2; j++) {         if (i < z && s[i] == char( 0  + j))           A1[i][j] = i + 1;         else if (i == 0)           A1[i][j] = 0;         else           A1[i][j] = A1[fail[i - 1]][j];       }     }     for (int i = 0; i <= z; i++) {       for (int j = 0; j < 2; j++) {         A3[i][j] = A1[i][j];         A2[i][j] = (A3[i][j] == z ? 1 : 0);       }     }     for (int i = 2; i <= n; i++) {       for (int j = 0; j <= z; j++) {         A3[j][i] = A3[A3[j][i - 2]][i - 1];         A2[j][i] = min((A2[j][i - 2] + A2[A3[j][i - 2]][i - 1]), INF);       }     }   }   int main() {     while (~scanf( %d%lld%d , &n, &K, &m)) {       string res =   ;       for (int i = 0; i < m; i++) {         if (res !=   ) Get(res);         int x = 0;         if (res !=    && A3[0][n] == i) x = 1;         if (K == 1 && x == 1) break;         K -= x;         Get(res +  0 );         long long tmp = A2[0][n];         if (K > tmp) {           res +=  1 ;           K -= tmp;         } else           res +=  0 ;       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, i;   int digits(int n) {     int d = 0;     while (n) {       n /= 10;       d++;     }     return d;   }   int main() {     cin >> a >> b;     c = a;     d = digits(b);     for (i = 1; b; i++) {       c += (b % 10) * (int)floor(pow((double)10, (double)d - i));       b /= 10;     }     cout << c;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     multiset<int> Q;     cin >> n;     long long ans = 0;     long long times = 0;     bool b = false;     int count = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (Q.size() == 0 || (*Q.begin()) > x) {         Q.insert(x);       } else {         ans += x - *Q.begin();         if (b) {           times += 2;           count++;           if (count == 2) {             b = false;             count = 0;           }         } else           b = true;         Q.erase(Q.begin());         Q.insert(x);         Q.insert(x);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int x = 0;     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   const int maxn = 2e5 + 5, inf = 1e9;   struct Data {     int next, to, w;   };   struct LinkTable {     Data data[maxn];     int head[maxn], cnt;     void add(int x, int y, int w) {       data[++cnt] = (Data){head[x], y, w};       head[x] = cnt;     }   } E, R;   struct DP {     int sum, id, lca;   } f[maxn], g[maxn];   int N, K, mx[5], mi[5], ret[maxn], fa[maxn], w[maxn];   bool mark[maxn];   int update(int &x, int y) {     if (x < y) return x = y, 1;     if (x == y) return 0;     return -1;   }   void F(int x) {     int sum = mark[x] ? 0 : -inf, id = x;     for (int i = E.head[x]; i; i = E.data[i].next)       if (E.data[i].to != fa[x]) {         Data &e = E.data[i];         fa[e.to] = x;         w[e.to] = e.w;         F(e.to);         if (update(sum, f[e.to].sum + e.w) == 1)           id = f[e.to].id;         else if (!update(sum, f[e.to].sum + e.w))           id = x;       }     f[x].sum = sum;     f[x].id = id;     f[x].lca = x;   }   void G(int x) {     g[x] = g[fa[x]];     g[x].sum += w[x];     if (mark[fa[x]] && w[x] > g[x].sum)       g[x].sum = w[x], g[x].id = g[x].lca = fa[x];     for (int i = R.head[fa[x]]; i; i = R.data[i].next)       if (R.data[i].to != x) {         Data &e = R.data[i];         if (update(g[x].sum, f[e.to].sum + e.w + w[x]) == 1)           g[x].id = f[e.to].id, g[x].lca = fa[x];         else if (update(g[x].sum, f[e.to].sum + e.w + w[x]) == 0)           g[x].id = g[x].lca = fa[x];       }     for (int i = 0; i < 3; ++i) mi[i] = 0, mx[i] = -inf;     for (int i = E.head[x]; i; i = E.data[i].next)       if (E.data[i].to != fa[x]) {         Data &e = E.data[i];         if (update(mx[0], f[e.to].sum + e.w) == 1) {           mx[2] = mx[1], mi[2] = mi[1];           mx[1] = mx[0], mi[1] = mi[0];           mi[0] = e.to;         } else if (update(mx[1], f[e.to].sum + e.w) == 1)           mx[2] = mx[1], mi[2] = mi[1], mi[1] = e.to;         else if (update(mx[2], f[e.to].sum + e.w) == 1)           mi[2] = e.to;       }     for (int i = 0; i < 3; ++i)       if (mi[i]) R.add(x, mi[i], w[mi[i]]);     for (int i = E.head[x]; i; i = E.data[i].next)       if (E.data[i].to != fa[x]) G(E.data[i].to);   }   void init() {     N = read(), K = read();     for (int i = 1; i <= K; ++i) mark[read()] = true;     for (int i = 1, u, v, w; i < N; ++i)       u = read(), v = read(), w = read(), E.add(u, v, w), E.add(v, u, w);     g[0].sum = -inf;   }   void dfs(int x) {     for (int i = E.head[x]; i; i = E.data[i].next)       if (E.data[i].to != fa[x]) {         Data &e = E.data[i];         dfs(e.to);         ret[x] += ret[e.to];       }   }   void solve() {     for (int i = 1; i <= N; ++i)       if (mark[i] && f[i].sum != g[i].sum)         if (f[i].sum > g[i].sum)           ++ret[f[i].id], --ret[f[i].lca];         else           ++ret[g[i].id], --ret[g[i].lca], ++ret[i], --ret[fa[g[i].lca]];     dfs(1);     int sum = -inf, once = 0;     for (int i = 1; i <= N; ++i)       if (!mark[i])         if (ret[i] > sum)           sum = ret[i], once = 1;         else if (ret[i] == sum)           ++once;     printf( %d %d n , sum, once);   }   int main() {     init();     F(1), G(1);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5;   const int INF = 0x3f3f3f3f;   long long get(long long n) {     long long res = 2;     long long ans = 0;     while (res <= n) {       ans += n / res;       res *= 2;     }     return ans;   }   int main() {     long long n;     cin >> n;     long long m = n;     long long ans = n;     long long p = 1;     while (p < n) {       ans += ((n - (p + 1)) / (2 * p) * p) + p;       p *= 2;     }     cout << ans - n << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k;     cin >> n >> k;     set<int> s;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       s.insert(a);     }     if (s.size() > k) {       cout << -1 << endl;       return;     }     cout << n * k << endl;     for (int i = 0; i < n; i++) {       for (int b : s) cout << b <<    ;       for (int j = 0; j < k - (int)s.size(); j++) cout << 1 <<    ;     }     cout << endl;   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long parent[100];   long nm[100];   vector<long> v[100];   long pp(long z) {     if (parent[z] == z) {       return z;     } else {       parent[z] = pp(parent[z]);     }   }   int main() {     long i, j, k, l, m, n, p, two, one;     scanf( %ld%ld , &n, &m);     for (i = 1; i <= n; i++) parent[i] = i;     for (i = 1; i <= m; i++) {       scanf( %ld%ld , &k, &l);       parent[l] = k;     }     for (i = 1; i <= n; i++) {       k = pp(i);     }     for (i = 1; i <= n; i++) {       nm[parent[i]]++;       if (nm[parent[i]] > 3) {         printf( -1 n );         return 0;       }     }     l = one = two = 0;     for (i = 1; i <= n; i++) {       if (nm[i] == 3) {         k = 0;         for (j = 1; j <= n; j++) {           if (parent[j] == i) {             v[l].push_back(j);             parent[j] = -1;             k++;           }         }         nm[i] = -1;         l++;       }       if (nm[i] == 2)         two++;       else if (nm[i] == 1)         one++;     }     if (one >= two) {       if ((one - two) % 3) {         printf( -1 n );         return 0;       }       while (two) {         for (i = 1; i <= n; i++) {           if (nm[i] == 2) {             for (j = 1; j <= n; j++) {               if (nm[j] == 1) {                 for (k = 1; k <= n; k++) {                   if (parent[k] == j) {                     v[l].push_back(k);                     nm[j] = -1;                     parent[k] = -1;                     break;                   }                 }                 break;               }             }             for (j = 1; j <= n; j++) {               if (parent[j] == i) {                 v[l].push_back(j);                 parent[j] = -1;               }             }             nm[i] = -1;             two--;             one--;             l++;             break;           }         }       }       while (one) {         k = 0;         for (i = 1; i <= n; i++) {           if (nm[i] == 1) {             v[l].push_back(i);             nm[i] = -1;             k++;             one--;             if (k == 3) {               l++;               break;             }           }         }       }       for (i = 0; i < l; i++) printf( %ld %ld %ld n , v[i][0], v[i][1], v[i][2]);     } else {       printf( -1 n );       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int compare(const void* pa, const void* pb) {     long long int p1 = *(const long long int*)pa;     long long int p2 = *(const long long int*)pb;     if (p1 < p2)       return 1;     else if (p1 > p2)       return -1;     else if (p1 == p2)       return 0;   }   long long int arr[200500], s[200500][2], ans[200500];   int main() {     int j, t, n;     cin >> t;     while (t--) {       int p = 0, x, y, a1, b1, a, b, low, high, mx, l = 0, m = 0, h = 0, w = -1;       long long sum = 0, k;       cin >> n;       for (j = 0; j < n; j++) cin >> arr[j];       cin >> x >> a;       cin >> y >> b;       cin >> k;       a1 = a;       b1 = b;       qsort(arr, n, sizeof(arr[0]), compare);       while (1) {         if (a < b) {           s[p][0] = a;           s[p][1] = x;           p++;           a += a1;         } else if (b < a) {           s[p][0] = b;           s[p][1] = y;           p++;           b += b1;         } else {           s[p][0] = a;           s[p][1] = x + y;           p++;           a += a1;           b += b1;         }         if (a > n && b > n) break;       }       low = min(x, y);       high = max(x, y);       mx = x + y;       for (j = 0; j < p; j++) {         if (s[j][1] == low) {           sum += (arr[l] / 100) * (s[j][1] - ans[l]);           ans[l] = low;           l++;         } else if (s[j][1] == high) {           sum += (arr[h] / 100) * (s[j][1] - ans[h]);           ans[h] = high;           if (h != l) {             sum += (arr[l] / 100) * (low - ans[l]);             ans[l] = low;           }           h++;           l++;         } else if (s[j][1] == mx) {           sum += (arr[m] / 100) * (s[j][1] - ans[m]);           ans[m] = mx;           if (m != h) {             sum += (arr[h] / 100) * (high - ans[h]);             ans[h] = high;           }           if (h != l) {             sum += (arr[l] / 100) * (low - ans[l]);             ans[l] = low;           }           m++;           h++;           l++;         }         if (sum >= k) {           w = s[j][0];           break;         }       }       cout << w <<   n ;       for (j = 0; j < n; j++) {         s[j][0] = 0;         s[j][1] = 0;         arr[j] = 0;         ans[j] = 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char s[505];   int sz;   int val[505];   int ch[505][11];   void insert() {     int f, k = 0;     scanf( %s%d , s, &f);     for (int i = 0; s[i]; ++i) {       int c = s[i] -  0 ;       if (!ch[k][c]) ch[k][c] = ++sz;       k = ch[k][c];     }     val[k] += f;   }   void init() {     scanf( %d%d , &n, &m);     while (n--) insert();   }   int dep[505];   int dp[505][505][15], f[505][15];   void dfs(int i) {     if (val[i])       for (int l = 0; l <= dep[i]; ++l)         for (int k = 0; k <= m; ++k) dp[i][l][k] = l * val[i];     for (int c = 0; c < 11; ++c) {       int j = ch[i][c];       if (!j) continue;       dep[j] = dep[i] + 1;       dfs(j);       memcpy(f, dp[i], sizeof(f));       memset(dp[i], 0x3f, sizeof(dp[i]));       for (int l = 0; l <= dep[i]; ++l)         for (int k = m; ~k; --k)           for (int p = 0; p <= k; ++p) {             dp[i][l][k] = min(dp[i][l][k], f[l][k - p] + dp[j][l + 1][p]);             if (p) dp[i][l][k] = min(dp[i][l][k], f[l][k - p] + dp[j][0][p - 1]);           }     }   }   void solve() {     dfs(0);     printf( %d n , dp[0][0][m]);   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int LEN = (int)1e5;   int n;   long long a[LEN];   vector<int> g[60];   int bfs(int r, int t) {     queue<int> q;     static int d[LEN];     memset(d, 0, sizeof d);     q.push(r);     d[r] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int j = 0; (1ll << j) <= a[u]; j++)         if ((1ll << j) & a[u])           for (auto v : g[j])             if (!d[v] && !(v == t && u == r)) {               d[v] = d[u] + 1;               if (v == t) return d[v] > 2 ? d[v] : INT_MAX;               q.push(v);             }     }     return INT_MAX;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       for (int j = 0; (1ll << j) <= a[i]; j++)         if ((1ll << j) & a[i]) g[j].push_back(i);       ;       ;     }     for (int i = 0; i < 60; i++)       if ((int)(g[i]).size() >= 3) {         cout << 3;         return 0;       }     int ans = INT_MAX;     for (int i = 0; i < 60; i++)       if ((int)(g[i]).size() > 1) {         a[g[i][0]] &= ~(1ll << i);         ans = min(ans, bfs(g[i][0], g[i][1]));         a[g[i][0]] |= 1ll << i;       }     cout << (ans < INT_MAX ? ans : -1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int s[10], a, b, c;     cin >> a >> b >> c;     s[0] = a + (b * c);     s[1] = a * (b + c);     s[2] = a * b * c;     s[3] = (a + b) * c;     s[4] = a + b + c;     s[5] = (a * b) + c;     sort(s, s + 5, greater<int>());     cout << s[0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T __trace(string s, T x) {     cerr << s << x << endl;     return x;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (T x : v) os << x <<    ;     return os;   }   template <class T>   istream& operator>>(istream& is, vector<T>& v) {     for (T& x : v) is >> x;     return is;   }   void run() {     long long n;     cin >> n;     map<pair<long long, long long>, long long> m;     long long ans = 0;     for (long long i = 0; i < (n); i++) {       long long h, mi;       cin >> h >> mi;       m[make_pair(h, mi)]++;       ans = max(ans, m[make_pair(h, mi)]);     }     cout << ans << endl;   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void _read(T& x) {     char ch = getchar();     bool sign = true;     while (!isdigit(ch)) {       if (ch ==  - ) sign = false;       ch = getchar();     }     for (x = 0; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch -  0 ;     if (!sign) x = -x;   }   bool mark[1505];   int n, ans[1505], lim;   int d[5] = {0, 1, 5, 10, 50};   void dfs(int id, int x, int tot) {     if (x == lim + 1) {       mark[tot] = true;       return;     }     for (int i = id; i <= 4; i++) dfs(i, x + 1, tot + d[i]);   }   int main() {     cin >> n;     for (int i = 1; i <= 30; i++) {       lim = i;       memset(mark, 0, sizeof(mark));       dfs(1, 1, 0);       int temp = 0;       for (int j = 1; j <= i * 50; j++)         if (mark[j]) temp++;       ans[i] = temp;     }     if (n <= 12) {       cout << ans[n];       return 0;     }     cout << 1ll * 49 * (n - 12) + ans[12];   }


#include <bits/stdc++.h>   using namespace std;   set<string> S;   void flip(string& s1) {     char temp = s1[0];     for (int i = 1; i < 4; i++) s1[i - 1] = s1[i];     s1[3] = temp;     return;   }   bool isFirst(string s1) {     for (int i = 0; i < 4; i++) {       if (S.find(s1) != S.end()) return false;       flip(s1);     }     return true;   }   int main() {     int N, result(0);     string s1, s2;     cin >> N;     cin >> s1 >> s2;     s1 += s2[1];     s1 += s2[0];     if (isFirst(s1)) {       S.insert(s1);       result++;     }     for (int i = 1; i < N; i++) {       cin >> s1;       cin >> s1 >> s2;       s1 += s2[1];       s1 += s2[0];       if (isFirst(s1)) {         S.insert(s1);         result++;       }     }     cout << result << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline void Boost() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const int NMax = 1e5 + 50;   struct Event {     int d, w, t;     bool operator<(const Event &e) const {       if (w != e.w) return w > e.w;       return d > e.d;     }   };   vector<int> DP, jump;   map<Event, int> Map;   vector<Event> v[NMax];   int main() {     Boost();     int n, k, m;     cin >> n >> m >> k;     DP.resize(n);     jump.resize(n);     for (int i = 0; i < n; ++i) jump[i] = i + 1;     for (int i = 0; i < k; ++i) {       int s, t, d, w;       cin >> s >> t >> d >> w;       v[s - 1].push_back({d, w, 1});       v[t].push_back({d, w, 0});     }     for (int i = 0; i < n; ++i) {       for (auto x : v[i]) {         if (x.t == 1) {           if (Map.count(x)) {             ++Map[x];           } else {             Map[x] = 1;           }         } else {           --Map[x];           if (Map[x] == 0) {             Map.erase(x);           }         }       }       if (!Map.empty()) {         DP[i] = (*Map.begin()).first.w;         jump[i] = (*Map.begin()).first.d;       }     }     vector<long long int> ans[m + 1];     for (auto &x : ans) x.resize(n + 1, LLONG_MAX);     ans[0][0] = 0;     for (int i = 0; i <= n; ++i) {       for (int j = 1; j <= m && i; ++j) {         ans[j][i] = min(ans[j][i], ans[j - 1][i - 1]);       }       for (int j = 0; j <= m && i < n; ++j) {         if (ans[j][i] == LLONG_MAX) continue;         ans[j][jump[i]] = min(ans[j][jump[i]], ans[j][i] + DP[i]);       }     }     long long int ret = ans[0][n];     for (int i = 0; i <= m; ++i) {       ret = min(ret, ans[i][n]);     }     cout << ret;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2510;   const int INF = 0x3f3f3f3f;   int prime[400];   bool isprime[N];   int k;   void init() {     k = 0;     for (int i = 2; i <= N; i++) {       if (!isprime[i]) {         prime[k++] = i;         for (int j = i + i; j <= N; j += i) isprime[j] = 1;       }     }   }   char s[N];   int ma[N * 2][N * 2], pre[N * 2][N * 2];   int main() {     init();     memset(pre, 0, sizeof(pre));     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i < 2 * N; i++) {       if (i <= n) scanf( %s , s + 1);       int tmp = 0;       for (int j = 1; j <= m; j++) {         if (i > n)           ma[i][j] = 0;         else {           if (s[j] ==  0 )             ma[i][j] = 0;           else {             ma[i][j] = 1;             tmp++;           }         }         pre[i][j] = tmp + pre[i - 1][j];       }       for (int j = m + 1; j < N * 2; j++) {         pre[i][j] = tmp + pre[i - 1][j];       }     }     int ans = INF;     for (int f = 0; f < k; f++) {       int p = prime[f];       int res = 0;       for (int i = p; i < n + p; i += p) {         for (int j = p; j < m + p; j += p) {           int ff = pre[i][j] + pre[i - p][j - p] - pre[i][j - p] - pre[i - p][j];           res = res + min(p * p - ff, ff);         }       }       ans = min(ans, res);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Node {    public:     int vol, l, r, tot;     Node(int val) {       tot = vol = val;       l = r = 0;     }     Node() {       tot = vol = 0;       l = r = 0;     }   };   int main() {     int H, q;     cin >> H >> q;     vector<Node> tree(1);     string s;     int v, val;     for (int query = 0; query < q; ++query) {       cin >> s;       if (s[0] ==  a ) {         cin >> v >> val;         vector<int> vbit;         while (v) {           vbit.push_back(v % 2);           v /= 2;         }         int it = 0;         for (int h = (int)vbit.size() - 2; h >= 0; --h) {           if (!tree[it].r) {             tree[it].l = tree.size();             tree[it].r = tree.size() + 1;             tree.resize(tree.size() + 2);           }           tree[it].tot += val;           int nextit = tree[it].l;           if (vbit[h]) {             nextit = tree[it].r;           }           it = nextit;         }         tree[it].vol += val;         tree[it].tot += val;       } else {         double res = 0.;         int it = 0;         int ma = 0;         int h = H;         for (; h > 0 && tree[it].r; --h) {           int nextit = tree[it].r;           if (tree[it].vol + tree[tree[it].r].tot > tree[tree[it].l].tot) {             res += max(ma, tree[it].vol + tree[tree[it].r].tot) *                    (double)(1 << (h - 1));             ma = max(ma, tree[it].vol + tree[tree[it].l].tot);           } else {             res += max(ma, tree[it].vol + tree[tree[it].l].tot) *                    (double)(1 << (h - 1));             ma = max(ma, tree[it].vol + tree[tree[it].r].tot);             nextit = tree[it].l;           }           it = nextit;         }         res += max(ma, tree[it].vol) * (double)(1 << h);         printf( %lf n , res / (1 << (H)));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     cin >> n;     long long int a, c1 = 0, c2 = 0, c3 = 0;     vector<long long int> v1;     vector<long long int> v2;     vector<long long int> v3;     for (int i = 1; i <= n; i++) {       cin >> a;       if (a == 0) {         v3.push_back(a);       } else if (a > 0) {         v2.push_back(a);       } else {         v1.push_back(a);       }     }     if (v2.size() == 0) {       for (int i = 0; i < 2; i++) {         v2.push_back(v1.back());         v1.pop_back();       }     }     if (v1.size() % 2 == 0) {       v3.push_back(v1.back());       v1.pop_back();     }     cout << v1.size() <<    ;     for (int i = 0; i < v1.size(); i++) cout << v1[i] <<    ;     cout << endl;     cout << v2.size() <<    ;     for (int i = 0; i < v2.size(); i++) cout << v2[i] <<    ;     cout << endl;     cout << v3.size() <<    ;     for (int i = 0; i < v3.size(); i++) cout << v3[i] <<    ;     cout << endl;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int w, h;     cin >> w >> h;     int ans = 1;     for (int i = 0; i < w + h; i++) {       ans = (ans * 2) % 998244353;     }     cout << ans % 998244353 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int sum = 0;     string s;     for (int i = 0; i < n; i++) {       cin >> s;       if (s ==  Icosahedron )         sum += 20;       else if (s ==  Dodecahedron )         sum += 12;       else if (s ==  Octahedron )         sum += 8;       else if (s ==  Cube )         sum += 6;       else if (s ==  Tetrahedron )         sum += 4;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(                   chrono::high_resolution_clock::now().time_since_epoch())                   .count());   const long long int N = 20005;   const long long int LG = 22;   long long int n, m;   long long int power(long long int x, long long int y, long long int m) {     if (y == 0) return 1;     long long int p = power(x, y / 2, m) % m;     p = (p * p) % m;     return (y % 2 == 0) ? p : (x * p) % m;   }   long long int fact[N], ifact[N];   void proecss() {     fact[0] = 1;     for (long long int i = 1; i < N; i++)       fact[i] = (fact[i - 1] * i) % 1000000007;     for (long long int i = 0; i < N; i++)       ifact[i] = power(fact[i], 1000000007 - 2, 1000000007);   }   long long int nCr(long long int n, long long int r) {     if (r > n) return 0;     if (r == n) return 1;     long long int ans = (ifact[n - r] * ifact[r]) % 1000000007;     ans = (ans * fact[n]) % 1000000007;     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     proecss();     cin >> n >> m;     long long int b[n + 5], a[n + 5];     for (long long int i = 1; i <= n; i++) {       long long int nn = n - i + 1;       long long int rr = m - 1;       b[i] = nCr(nn + rr - 1, rr);       a[i] = nCr(i + rr - 1, rr);     }     for (long long int i = n - 1; i >= 1; i--)       b[i] += b[i + 1], b[i] %= 1000000007;     long long int ans = 0;     for (long long int i = 1; i <= n; i++) {       ans = (ans + (a[i] * b[i]) % 1000000007) % 1000000007;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string out;   long long int T;   unsigned canDo1[5000 / 32 + 1], canDo2[5000 / 32 + 1];   unsigned *cd1 = canDo1, *cd2 = canDo2, *sw;   int A[5000];   list<int> P;   int N;   void process() {     cin >> N;     N *= 2;     P.clear();     for (int i = 0; i < N; i++) cin >> A[i];     int ps = 0, p = 0;     for (int i = 0; i < N; i++)       if (A[i] <= A[ps])         p++;       else         P.push_back(p), ps = i, p = 1;     P.push_back(p);     for (int i = 0; i <= N / 32 + 1; i++) cd1[i] = cd2[i] = 0;     cd1[0] = cd2[0] = 1;     for (int p : P) {       for (int i = 0; i <= N; i++)         if ((cd2[i / 32] & 1 << i % 32) ||             (i >= p && (cd2[(i - p) / 32] & 1 << (i - p) % 32)))           cd1[i / 32] |= 1 << i % 32;       sw = cd1, cd1 = cd2, cd2 = sw;     }     out += (cd2[N / 2 / 32] & 1 << N / 2 % 32) ?  YES n  :  NO n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> T;     for (int t = 1; t <= T; t++) process();     cout << out;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long n, k, bd, s, ar[6000], ans, calc[1200000];   long lst[1200000];   long del;   long q;   void check(long mod) {     del = 0;     for (int i = 1; i <= n; i++) {       q = ar[i] % mod;       if (lst[q] == mod)         ++del;       else         lst[q] = mod;       if (del > k) break;     }     if (del <= k) ans = mod;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k;     if (k == 0) bd = 0;     if (k == 1) bd = 1;     if (k == 2) bd = 3;     if (k == 3) bd = 6;     if (k == 4) bd = 10;     for (int i = 1; i <= n; i++) cin >> ar[i];     sort(ar + 1, ar + n + 1);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) calc[ar[j] - ar[i]]++;     ans = 0;     for (int mod = 1; mod <= 1000001; mod++) {       s = 0;       if (ans > 0) break;       for (int p = mod; p <= 1000001; p += mod) {         s += calc[p];         if (s > bd) break;       }       if (s <= bd) check(mod);     }     cout << ans << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline istream &operator>>(istream &s, vector<T> &v) {     for (T &t : v) {       s >> t;     }     return s;   }   template <typename T>   inline ostream &operator<<(ostream &s, const vector<T> &v) {     for (int i = 0; i < int(v.size()); ++i) {       s << (    + !i) << v[i];     }     return s;   }   template <typename T>   inline T fromString(const string &s) {     T res;     istringstream iss(s);     iss >> res;     return res;   };   template <typename T>   inline string toString(const T &a) {     ostringstream oss;     oss << a;     return oss.str();   };   const long long mod = 1000000007;   const long long INF = 1e18;   int main() {     long long t;     t = 1;     cin >> t;     while (t--) {       long long n;       cin >> n;       char s[2][n];       for (int i = (0); i < (2); i++) {         for (int j = (0); j < (n); j++) {           cin >> s[i][j];         }       }       long long f = 0;       for (int i = (0); i < (1); i++) {         for (int j = (0); j < (n); j++) {           if (s[i][j] ==  1  && s[i + 1][j] ==  1 ) {             f = 1;           }         }       }       if (f) {         cout <<  NO               <<   n ;       } else {         cout <<  YES               <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, q, k;   struct node {     int c[2], fa, siz, tot;     int val, id, mid, mv;     bool rev;     node() { rev = false; }   } t[600010];   void maintain(int rt) {     t[rt].siz = t[t[rt].c[0]].siz + t[t[rt].c[1]].siz + t[rt].tot;     t[rt].mid = t[rt].id;     t[rt].mv = t[rt].val;     if (t[rt].c[0] && t[t[rt].c[0]].mv < t[rt].mv)       t[rt].mv = t[t[rt].c[0]].mv, t[rt].mid = t[t[rt].c[0]].mid;     if (t[rt].c[1] && t[t[rt].c[1]].mv < t[rt].mv)       t[rt].mv = t[t[rt].c[1]].mv, t[rt].mid = t[t[rt].c[1]].mid;     return;   }   bool isroot(int k) { return (t[t[k].fa].c[0] != k && t[t[k].fa].c[1] != k); }   void connect(int k, int f, int p) {     t[k].fa = f;     t[f].c[p] = k;     return;   }   int id(int k) { return (t[t[k].fa].c[0] == k ? 0 : 1); }   void rotate(int x) {     int y = t[x].fa, z = t[y].fa, fx = id(x), fy = id(y);     if (!isroot(y)) t[z].c[fy] = x;     t[x].fa = z;     connect(t[x].c[fx ^ 1], y, fx);     connect(y, x, fx ^ 1);     maintain(y);     maintain(x);     return;   }   void pushdown(int rt) {     if (!t[rt].rev) return;     t[t[rt].c[0]].rev ^= 1;     t[t[rt].c[1]].rev ^= 1;     swap(t[rt].c[0], t[rt].c[1]);     t[rt].rev = false;     return;   }   stack<int> s;   void splay(int x) {     s.push(x);     for (int i = x; !isroot(i); i = t[i].fa) s.push(t[i].fa);     while (!s.empty()) {       pushdown(s.top());       s.pop();     }     while (!isroot(x)) {       int y = t[x].fa;       if (isroot(y)) {         rotate(x);         break;       }       if (id(x) == id(y)) {         rotate(y);         rotate(x);       } else {         rotate(x);         rotate(x);       }     }     return;   }   void access(int k) {     for (int i = 0; k; i = k, k = t[k].fa) {       splay(k);       t[k].tot += t[t[k].c[1]].siz;       t[k].tot -= t[i].siz;       t[k].c[1] = i;       maintain(k);     }     return;   }   void makeroot(int k) {     access(k);     splay(k);     t[k].rev ^= 1;     return;   }   void link(int x, int y) {     makeroot(x);     makeroot(y);     t[x].fa = y;     t[y].tot += t[x].siz;     maintain(y);     return;   }   void cut(int x, int y) {     makeroot(x);     access(y);     splay(x);     t[x].c[1] = 0;     t[y].fa = 0;     t[x].siz -= t[y].siz;     maintain(x);     return;   }   struct edge {     int u, v, t;     bool del;   } es[600010];   int en = 0;   int main() {     scanf( %d%d%d , &n, &q, &k);     int ecur = 0;     int cur = 1;     int ty, x, y;     for (int i = 1; i <= n; ++i)       t[i].siz = t[i].tot = 1, t[i].val = t[i].mv = 0x3f3f3f3f;     for (int i = 1; i <= q; ++i) {       scanf( %d , &ty);       if (ty == 1) {         scanf( %d%d , &x, &y);         es[++en] = (edge){x, y, cur, false};         makeroot(x);         access(y);         splay(x);         int v = y;         while (t[v].fa) v = t[v].fa;         if (v == x) {           splay(y);           int cute = t[y].mid;           cut(es[cute].u, cute + n);           cut(es[cute].v, cute + n);           es[cute].del = true;         }         t[en + n].siz = 1;         t[en + n].val = cur;         t[en + n].id = en;         t[en + n].mv = cur;         t[en + n].mid = en;         link(x, en + n);         link(y, en + n);       }       if (ty == 2) {         scanf( %d , &x);         makeroot(x);         printf( %d n , t[x].siz);       }       if (ty == 3) {         ++cur;         while (ecur < en && es[ecur + 1].t <= cur - k) {           ++ecur;           if (!es[ecur].del) {             cut(es[ecur].u, ecur + n);             cut(es[ecur].v, ecur + n);           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using std::cerr;   const int N = 998244, M = 1001;   int n, m, d[N], las[N], seq[N], cnt[M][M], blo, x[N], y[N];   inline void add(int a, int b, int val) { seq[a] += val, seq[b + 1] -= val; }   signed main() {     std::ios::sync_with_stdio(0);     scanf( %d%d , &n, &m), blo = sqrt(m);     for (int i = 1; i <= n; i++) scanf( %d%d , &x[i], &y[i]);     int op, k;     for (int now = 1; now <= m; now++) {       scanf( %d%d , &op, &k);       if (op == 1) {         if (x[k] + y[k] <= blo) {           for (int i = x[k]; i < x[k] + y[k]; i++)             cnt[x[k] + y[k]][(now + i) % (x[k] + y[k])]++;         } else           for (int i = now + x[k]; i <= m; i += x[k] + y[k])             add(i, i + y[k] - 1, 1);         las[k] = now;       } else {         if (x[k] + y[k] <= blo) {           for (int i = x[k]; i < x[k] + y[k]; i++)             cnt[x[k] + y[k]][(las[k] + i) % (x[k] + y[k])]--;         } else {           for (int i = las[k] + x[k]; i <= m; i += x[k] + y[k]) {             if (i + y[k] - 1 < now) continue;             if (i <= now && i + y[k] - 1 >= now)               add(now, i + y[k] - 1, -1);             else               add(i, i + y[k] - 1, -1);           }         }       }       int ans = 0;       for (int i = 2; i <= blo; i++) {         ans += cnt[i][now % i];       }       seq[now] += seq[now - 1];       printf( %d n , ans + seq[now]);     }   }


#include<iostream>   #include<cstdio>   #include<algorithm>   #include<cmath>   #include<cstring>   #include<queue>   #define ll long long   using namespace std;   const int N=310,M=100005,mod=1e9+7;   int n,tot;   ll inv,ans;   int head[N],ver[M],Nxt[M],dep[N],fa[N][20];   ll f[N][N];   void add(int x,int y){    ver[++tot]=y;    Nxt[tot]=head[x];    head[x]=tot;   }   void dfs(int u,int now){    dep[u]=now;    for(int i=head[u];i;i=Nxt[i]){     int y=ver[i];     if(y==fa[u][0]) continue;     fa[y][0]=u;     for(int j=1;j<=18;j++){      fa[y][j]=fa[fa[y][j-1]][j-1];     }     dfs(y,now+1);    }   }   int LCA(int x,int y){    if(dep[x]<dep[y]) swap(x,y);    for(int j=18;j>=0;j--){     if(dep[fa[x][j]]>=dep[y]) x=fa[x][j];    }    if(x==y) return x;    for(int j=18;j>=0;j--){     if(fa[x][j]!=fa[y][j]){      x=fa[x][j];y=fa[y][j];     }    }    return fa[x][0];   }   ll ksm(ll x,ll p){    ll sum=1;    while(p){     if(p&1) sum=sum*x%mod;     x=x*x%mod;     p>>=1;    }    return sum;   }   int main()   {    scanf( %d ,&n);        inv=ksm(2,mod-2);        for(int i=1;i<=n;i++){     f[i][0]=1;     f[0][i]=0;    }        for(int i=1;i<=n;i++){     for(int j=1;j<=n;j++){      f[i][j]=(f[i-1][j]+f[i][j-1])*inv%mod;     }    }        for(int i=1;i<n;i++){     int x,y;     scanf( %d%d ,&x,&y);     add(x,y);add(y,x);    }        for(int i=1;i<=n;i++){     memset(fa,0,sizeof(fa));     memset(dep,0,sizeof(dep));     dfs(i,1);        //  for(int j=1;j<=n;j++){   //   printf( %d %d n ,j,dep[j]);   //  }           for(int j=1;j<=n;j++){      for(int k=j+1;k<=n;k++){       int lca=LCA(j,k);   //    printf( 以%d为根 %d 和 %d 的 LCA 是%d n ,i,j,k,lca);       ans=(ans+f[dep[j]-dep[lca]][dep[k]-dep[lca]])%mod;      }     }    }        printf( %lld n ,ans*ksm(n,mod-2)%mod);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int lcp[25][25];   int b[25];   string s[25];   int ans = 0;   void BT(int now, int n, int k) {     if (now == n) {       int have = 0;       for (int i = 0; i < n; i++)         for (int j = i + 1; j < n; j++)           if (b[i] && b[j]) have += lcp[i][j];       ans = max(ans, have);       return;     }     b[now] = 0;     if (n - now > k) BT(now + 1, n, k);     if (k) {       b[now] = 1;       BT(now + 1, n, k - 1);     }   }   int main() {     ios::sync_with_stdio(false);     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> s[i];       for (int j = 0; j < i; j++) {         int k;         for (k = 0; k < s[i].length() && k < s[j].length() && s[i][k] == s[j][k];              k++)           ;         lcp[i][j] = lcp[j][i] = k;       }     }     BT(0, n, k);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<double, double> arr[1000];   int n;   double m, r;   void solve() {     vector<pair<int, int> > v;     double h = m;     int t = 0;     while (h > 0) {       int best_i = -1;       for (int i = 0; i < n; ++i) {         if (arr[i].first >= h) {           if (best_i == -1) {             best_i = i;           } else {             if (arr[i].second > arr[best_i].second) {               best_i = i;             }           }         }       }       if (best_i == -1 && r >= 0) {         printf( NO );         return;       }       if (best_i > -1) {         r -= arr[best_i].second;         arr[best_i].first = -10;         v.push_back(make_pair(t, best_i + 1));       }       h += r;       h = min(h, m);       t++;     }     printf( YES n );     printf( %d %d n , t, int(v.size()));     for (int i = 0; i < int(v.size()); ++i) {       printf( %d %d n , v[i].first, v[i].second);     }   }   int main() {     scanf( %d%lf%lf , &n, &m, &r);     for (int i = 0; i < n; ++i) {       double p, d;       scanf( %lf%lf , &p, &d);       arr[i].first = m / 100 * p;       arr[i].second = d;     }     solve();     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:128777216 )   const int null = 0;   using namespace std;   template <class T>   int size(const T &a) {     return int(a.size());   }   template <class T>   T abs(const T &a) {     return (a < 0 ? -a : a);   }   template <class T>   T sqr(const T &a) {     return a * a;   }   const int max_n = 52, mod = 1000000007;   int dist[max_n][max_n][2];   int dp[max_n][max_n][2];   bool was[max_n][max_n][2];   struct Pos {     int i, j, s;     int d;     void init(int i, int j, int s, int d) {       this->i = i;       this->j = j;       this->s = s;       this->d = d;       was[i][j][s] = true;       dist[i][j][s] = d;     }   } q[max_n * max_n * 2];   int cmn[max_n][max_n];   int main() {     int n, k;     scanf( %d %d , &n, &k);     for (int i = 0; i <= n; i++) {       cmn[0][i] = 1;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cmn[i][j] = cmn[i - 1][j - 1] + cmn[i][j - 1];       }     }     k /= 50;     int c0 = 0, c1 = 0;     for (int i = 0; i < n; i++) {       int t;       scanf( %d , &t);       if (t == 50) {         c0++;       } else {         c1++;       }     }     q[0].init(0, 0, 1, 0);     dp[0][0][1] = 1;     for (int d = 0, u = 1; d < u; d++) {       Pos p = q[d];       int mc0, mc1;       if (p.s) {         mc0 = c0 - p.i;         mc1 = c1 - p.j;       } else {         mc0 = p.i;         mc1 = p.j;       }       long long cnt = dp[p.i][p.j][p.s];       for (int i = 0; i <= mc0; i++) {         for (int j = 0; j <= mc1; j++) {           if (i + j > 0 && i + j * 2 <= k) {             int c0, c1, s0 = p.s ^ 1;             if (p.s) {               c0 = p.i + i;               c1 = p.j + j;             } else {               c0 = p.i - i;               c1 = p.j - j;             }             long long cur = cnt * cmn[i][mc0] % mod * cmn[j][mc1] % mod;             if (!was[c0][c1][s0]) {               q[u++].init(c0, c1, s0, p.d + 1);               dp[c0][c1][s0] = cur;             } else if (p.d + 1 == dist[c0][c1][s0]) {               dp[c0][c1][s0] = (cur + dp[c0][c1][s0]) % mod;             }           }         }       }     }     if (!was[c0][c1][0]) {       printf( -1 n0 n );       return 0;     }     printf( %d n%d n , dist[c0][c1][0], dp[c0][c1][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   using vi = vector<int>;   const int N = 4e5;   vi cnt(N, 0);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int a;     cin >> a;     string s;     cin >> s;     int n = s.size();     for (int i = 0; i < n; i++) {       int sum = 0;       for (int j = i; j < n; j++) {         sum += int(s[j] -  0 );         cnt[sum]++;       }     }     ll ans = 0;     if (a == 0) {       for (int i = 0; i < N; i++) ans += cnt[i];       ans = 2 * cnt[0] * ans - 1LL * cnt[0] * cnt[0];     } else {       for (int i = 1; i < N; i++) {         if (a % i) continue;         int b = a / i;         if (b >= N) continue;         ans += 1LL * cnt[i] * cnt[b];       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int f = 1, res = 0, ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch - 48, ch = getchar();     return f * res;   }   int _sta[1 << 8];   inline void write(int val) {     if (!val) {       putchar( 0 );       return;     }     if (val < 0) putchar( - ), val = -val;     *_sta = 0;     while (val > 0) _sta[++*_sta] = val % 10, val /= 10;     for (int i = *_sta, _Lim = 1; i >= _Lim; i--) putchar(_sta[i] + 48);   }   const long long INF = 1e18;   long long Exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1, y = 0;       return a;     }     int res = Exgcd(b, a % b, x, y);     int x_ = x;     x = y;     y = x_ - a / b * y;     return res;   }   int n, m, k;   long long Cal(long long x, long long y) {     long long a, b;     long long gcd = Exgcd(2 * n, 2 * m, a, b);     long long lcm = 1LL * 2 * n * 2 * m / gcd;     if (a < 0)       a = -a;     else       a = 2 * m / gcd - a;     if ((x - y) % gcd != 0) return INF;     x += 1LL * (x - y) / gcd * a * 2 * n;     x -= x / lcm * lcm;     if (x < 0) x += lcm;     return x;   }   int main() {     n = read();     m = read();     k = read();     while (k--) {       int x = read(), y = read();       long long Ans = INF;       Ans = min(Ans, Cal(x, y));       Ans = min(Ans, Cal(x, 2 * m - y));       Ans = min(Ans, Cal(2 * n - x, y));       Ans = min(Ans, Cal(2 * n - x, 2 * m - y));       if (Ans < INF)         printf( %I64d n , Ans);       else         printf( -1 n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int SZ = 2000010;   const int INF = 1e9 + 10;   const int mod = 1e9 + 7;   const long double eps = 1e-8;   long long read() {     long long n = 0;     char a = getchar();     bool flag = 0;     while (a >  9  || a <  0 ) {       if (a ==  - ) flag = 1;       a = getchar();     }     while (a <=  9  && a >=  0 ) {       n = n * 10 + a -  0 , a = getchar();     }     if (flag) n = -n;     return n;   }   vector<int> g2[SZ];   vector<int> g[SZ];   int n, m, q;   int ccnt = 0;   int dfn[SZ], low[SZ], dfs_clock;   stack<int> S;   bool cut[SZ], ins[SZ];   void Tarjan(int u, int f) {     dfn[u] = low[u] = ++dfs_clock;     S.push(u);     ins[u] = 1;     int child = 0;     for (int i = 0; i < g2[u].size(); i++) {       int v = g2[u][i];       if (v == f) continue;       if (!dfn[v]) {         child++;         Tarjan(v, u);         low[u] = min(low[u], low[v]);         if (low[v] >= dfn[u]) {           ccnt++;           cut[u] = 1;           int x;           do {             x = S.top();             S.pop();             ins[x] = 0;             g[ccnt + n].push_back(x);             g[x].push_back(ccnt + n);           } while (x != v && !S.empty());           g[ccnt + n].push_back(u);           g[u].push_back(ccnt + n);         }       } else if (ins[v]) {         low[u] = min(low[u], dfn[v]);       }     }     if (f == 0 && child == 1) cut[u] = 0;   }   int anc[SZ][22], deep[SZ];   void dfsLca(int u, int f) {     deep[u] = deep[f] + 1;     anc[u][0] = f;     for (int i = 1; anc[u][i - 1]; i++) anc[u][i] = anc[anc[u][i - 1]][i - 1];     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == f) continue;       dfsLca(v, u);     }   }   int askLca(int u, int v) {     if (deep[u] < deep[v]) swap(u, v);     int dd = deep[u] - deep[v];     for (int i = 20; i >= 0; i--)       if (dd >> i & 1) u = anc[u][i];     if (u == v) return u;     for (int i = 20; i >= 0; i--)       if (anc[u][i] != anc[v][i]) u = anc[u][i], v = anc[v][i];     return anc[u][0];   }   int main() {     n = read(), m = read(), q = read();     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       g2[x].push_back(y);       g2[y].push_back(x);     }     Tarjan(1, 0);     n += ccnt;     dfsLca(1, 0);     while (q--) {       int x = read(), y = read();       int lca = askLca(x, y);       int ans = deep[x] + deep[y] - 2 * deep[lca];       printf( %d n , ans / 2);     }     return 0;   }


#include <iostream>   #include <cmath>      using namespace std;      int main() {       int t;              cin >> t;              while(t--)       {           int xa, ya, xb, yb, xf, yf;                      cin >> xa >> ya >> xb >> yb >> xf >> yf;                      if(xa==xb && xb==xf && yf > ya && yf < yb)           {               cout << abs(yb-ya) + 2 << endl;               continue;           }                      else if(xa==xb && xb==xf && yf < ya && yf > yb)           {               cout << abs(yb-ya) + 2 << endl;               continue;           }                      else if(ya==yb && yb==yf && xf>xa && xf<xb)           {               cout << abs(xb-xa) + 2 << endl;               continue;           }                      else if(ya==yb && yb==yf && xf<xa && xf>xb)           {               cout << abs(xb-xa) + 2 << endl;               continue;           }                      else           {               cout << abs(xb-xa) + abs(yb-ya) << endl;               continue;           }       }   }