#include <bits/stdc++.h>   using namespace std;   long long P(long long m, long long n);   long long pi(long long x);   long long phi(long long m, long long n);   bool isprm[400005];   int cntprm[400005];   vector<long long> prm;   void Init() {     for (int i = 2; i <= 400000; ++i) {       isprm[i] = true;     }     for (int i = 2; i <= 400000; ++i) {       cntprm[i] = cntprm[i - 1] + isprm[i];       if (isprm[i]) {         prm.push_back(i);         for (int j = i + i; j <= 400000; j += i) isprm[j] = false;       }     }   }   long long sol(long long x) {     long long ans = 0;     long long sq = sqrt(x);     for (int i = 0; i < (int)prm.size() && prm[i] <= sq; ++i) {       long long a = prm[i], b = x / a;       if (b <= 400000)         ans += cntprm[b] - cntprm[a];       else {         ans += pi(b) - cntprm[a];       }     }     return ans;   }   int main(void) {     long long n;     Init();     cin >> n;     cout << cntprm[(int)cbrt(n)] + sol(n) <<   n ;   }   long long phi(long long m, long long n) {     if (m) {       if (n) {         if (m <= prm[n - 1])           return 1;         else {           if (prm[n - 1] * prm[n - 1] >= m)             return pi(m) - n + 1;           else             return phi(m, n - 1) - phi(m / prm[n - 1], n - 1);         }       } else {         return m;       }     } else {       return 0;     }   }   long long P(long long m, long long n) {     long long res = 0, sq = sqrt(m);     for (int i = n; i < (int)prm.size() && prm[i] <= sq; ++i) {       auto num = prm[i];       res += pi(m / num) - pi(num) + 1;     }     return res;   }   long long pi(long long x) {     if (x <= 400000)       return cntprm[x];     else {       long long n = pi(ceil(cbrt(x))), m = x;       return phi(m, n) + n - 1 - P(m, n);     }   }


#include <bits/stdc++.h>   using namespace std;   string numToBinary(int n, int digits) {     string s;     while (n) {       int bil = n % 2;       n /= 2;       s += (bil +  0 );     }     while (s.size() < digits) {       s +=  0 ;     }     reverse(s.begin(), s.end());     return s;   }   long long computeInv(const vector<int>& a) {     int sz = a.size();     int suff[sz + 1], i;     suff[sz] = 0;     for (i = sz - 1; i >= 0; i--) {       suff[i] = suff[i + 1];       if (a[i] == 0) {         suff[i]++;       }     }     long long ans = 0;     for (i = 0; i < sz; i++) {       if (a[i] == 1) {         ans += suff[i + 1];       }     }     return ans;   }   void cetak(const vector<int>& a) {     for (int i = 0; i < a.size(); i++) {       printf( %d  , a[i]);     }     printf(  n );   }   int main() {     int n, i, j;     int a[300001];     while (scanf( %d , &n) != EOF) {       for (i = 0; i < n; i++) {         scanf( %d , &a[i]);       }       vector<vector<int> > groups;       vector<int> awalMula;       for (i = 0; i < n; i++) {         awalMula.push_back(i);       }       groups.push_back(awalMula);       int sor = 0;       long long numInv = 0;       for (i = 29; i >= 0; i--) {         long long invXor = 0;         long long invOri = 0;         for (j = 0; j < groups.size(); j++) {           vector<int> inv, asli;           for (int k = 0; k < groups[j].size(); k++) {             int idx = groups[j][k];             if ((1 << i) & a[idx]) {               asli.push_back(1);               inv.push_back(0);             } else {               asli.push_back(0);               inv.push_back(1);             }           }           invOri += computeInv(asli);           invXor += computeInv(inv);         }         if (invXor < invOri) {           sor += (1 << i);           for (j = 0; j < n; j++) {             a[j] ^= (1LL << i);           }           numInv += invXor;         } else {           numInv += invOri;         }         vector<vector<int> > newGroups;         for (j = 0; j < groups.size(); j++) {           vector<int> group0, group1;           for (int k = 0; k < groups[j].size(); k++) {             int idx = groups[j][k];             int nilai;             if ((1 << i) & a[idx]) {               group1.push_back(idx);             } else {               group0.push_back(idx);             }           }           if (group1.size()) {             newGroups.push_back(group1);           }           if (group0.size()) {             newGroups.push_back(group0);           }         }         groups = newGroups;       }       printf( %lld %d n , numInv, sor);     }     return 0;   };


#include <bits/stdc++.h>   using namespace std;   const int maxn = 150000 + 7;   const long long mod = 1e9 + 7;   const long long INF = 5e18 + 7;   const int inf = 1e9 + 7;   const long long maxx = 1e6 + 700;   int main() {     int n, m, i;     scanf( %d%d , &n, &m);     i = max(2 * n, 3 * m);     while (i / 2 + i / 3 - i / 6 < n + m || i / 2 < n || i / 3 < m) {       i++;     }     printf( %d , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10010;   const int M = 15;   const double eps = 1e-7;   const int INF = 1 << 30;   int n;   struct node {     double x, y, z;     node() { x = y = z = 0; }     node(double xx, double yy, double zz) {       x = xx;       y = yy;       z = zz;     }   } poy[N], ori;   double vp, vs, prelen;   int ln;   double ABS(double x) {     while (x < 0) x = -x;     return x;   }   double dist(node a, node b) {     double tmp = 0;     tmp += (a.x - b.x) * (a.x - b.x);     tmp += (a.y - b.y) * (a.y - b.y);     tmp += (a.z - b.z) * (a.z - b.z);     return sqrt(tmp);   }   void init() {     double x, y, z;     for (int i = 1; i <= n + 1; i++) {       cin >> x >> y >> z;       poy[i] = node(x, y, z);     }     cin >> vp >> vs;     cin >> x >> y >> z;     ori = node(x, y, z);   }   bool solve() {     double t = 0;     for (int i = 2; i <= n + 1; i++) {       double len = dist(ori, poy[i]) / vp;       double edge = dist(poy[i - 1], poy[i]) / vs;       t += edge;       if ((t - len) >= -eps) {         ln = i;         prelen = t - edge;         return 1;       }     }     return 0;   }   node getmid(node a, node b) {     double xx, yy, zz;     xx = (a.x + b.x) * 0.5;     yy = (a.y + b.y) * 0.5;     zz = (a.z + b.z) * 0.5;     return node(xx, yy, zz);   }   void cal() {     node pre = poy[ln - 1];     node l = poy[ln - 1], r = poy[ln];     double t;     while (ABS(dist(l, r)) > eps) {       node mid = getmid(l, r);       double len1 = dist(ori, mid);       double len2 = dist(mid, pre);       double t1 = len1 / vp;       double t2 = len2 / vs + prelen;       t = t1;       if ((t1 - t2) < 1e-15)         r = mid;       else         l = mid;     }     printf( %.10lf n%.10lf %.10lf %.10lf n , t, l.x, l.y, l.z);   }   int main() {     while (cin >> n) {       init();       if (solve())         cout <<  YES  << endl;       else {         cout <<  NO  << endl;         continue;       }       cal();     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int MOD = 1e9 + 7;   template <typename S, typename T>   inline bool Min(S &a, const T &b) {     return a > b ? a = b, true : false;   }   template <typename S, typename T>   inline bool Max(S &a, const T &b) {     return a < b ? a = b, true : false;   }   template <typename S, typename T>   inline void Adm(S &a, const T &b) {     a = (a + b) % MOD;     if (a < 0) a += MOD;   }   template <typename S, typename T>   inline void Mum(S &a, const T &b) {     a = 1LL * a * b % MOD;   }   template <typename T>   inline bool IsPri(T x) {     if (x < 2) return false;     for (T i = 2; i * i <= x; ++i)       if (x % i == 0) return false;     return true;   }   template <typename T>   inline T Gcd(T a, T b) {     while (b) {       T t = b;       b = a % b;       a = t;     }     return a;   }   template <typename T>   inline int BitCnt(T x) {     int cnt = 0;     while (x) ++cnt, x &= x - 1;     return cnt;   }   template <typename T>   inline T MDis(T x1, T y1, T x2, T y2) {     return abs(x1 - x2) + abs(y1 - y2);   }   template <typename T>   inline T MDis(T x1, T y1, T z1, T x2, T y2, T z2) {     return abs(x1 - x2) + abs(y1 - y2) + abs(z1 - z2);   }   inline double EDis(double x1, double y1, double x2, double y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   }   inline double EDis(double x1, double y1, double z1, double x2, double y2,                      double z2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) +                 (z1 - z2) * (z1 - z2));   }   inline long long Pow(long long a, long long n) {     long long t = 1;     a %= MOD;     while (n > 0) {       if (n & 1) t = t * a % MOD;       a = a * a % MOD, n >>= 1;     }     return t % MOD;   }   inline int read() {     static char buf[1000000], *p1 = buf, *p2 = buf;     register int x = false;     register char ch =         p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)             ? EOF             : *p1++;     ;     register bool sgn = false;     while (ch !=  -  && (ch <  0  || ch >  9 ))       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     if (ch ==  - )       sgn = true,       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     while (ch >=  0  && ch <=  9 )       x = (x << 1) + (x << 3) + (ch ^ 48),       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     return sgn ? -x : x;   }   const int N = 1e3;   int n, m;   vector<int> dz;   vector<int> e[N];   int son(int x) {     int res = 0, y = x;     while (y <= n) {       res += min(x, n) - y + 1;       x = x << 1 | 1, y = y << 1;     }     return res;   }   long long ans;   int w[N];   void DFS1(int x, int fz) {     w[x] = son(dz[x]);     for (int y : e[x])       if (y != fz) {         w[x] -= son(dz[y]);         DFS1(y, x);       }   }   bool vis[N];   void DFS2(int x, int rt) {     vis[x] = 1;     Adm(ans, 1LL * w[rt] * w[x]);     for (int y : e[x])       if (!vis[y]) DFS2(y, rt);     vis[x] = 0;   }   int main() {     cin >> n >> m;     dz.push_back(1), dz.push_back(INT_MAX);     vector<pair<int, int> > edge;     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       edge.push_back({u, v});       while (u) dz.push_back(u), u >>= 1;       while (v) dz.push_back(v), v >>= 1;     }     (dz).push_back(INT_MIN), sort((dz).begin(), (dz).end()),         (dz).erase(unique((dz).begin(), (dz).end()), (dz).end());     for (int i = 1; i < ((int)(dz).size()) - 1; ++i) {       for (int j = dz[i] * 2; j <= dz[i] * 2 + 1; ++j)         if (dz[(lower_bound(dz.begin(), dz.end(), (j)) - dz.begin())] == j)           e[i].push_back((lower_bound(dz.begin(), dz.end(), (j)) - dz.begin())),               e[(lower_bound(dz.begin(), dz.end(), (j)) - dz.begin())].push_back(                   i);     }     DFS1(1, 0);     for (auto it : edge)       e[(lower_bound(dz.begin(), dz.end(), (it.first)) - dz.begin())].push_back(           (lower_bound(dz.begin(), dz.end(), (it.second)) - dz.begin())),           e[(lower_bound(dz.begin(), dz.end(), (it.second)) - dz.begin())]               .push_back(                   (lower_bound(dz.begin(), dz.end(), (it.first)) - dz.begin()));     for (int i = 1; i < ((int)(dz).size()) - 1; ++i) DFS2(i, i);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char q[7][50] = { Anka ,    Chapay ,  Cleo ,        Troll ,                     Dracul ,  Snowy ,   Hexadecimal };   map<string, int> h;   int a[3], u[7], v[3], w[7], r, rb, m[7][7];   void upd() {     int i, mx, mn, j, k;     for (i = 0; i < 3; v[i] = 0, i++)       ;     for (i = 0; i < 7; v[u[i]]++, i++)       ;     for (i = 0; i < 3; i++)       if (!v[i]) return;     for (i = 0; i < 7; w[i] = a[u[i]] / v[u[i]], i++)       ;     for (mx = w[0], mn = w[0], i = 1;          i<7; mx = w[i]> mx ? w[i] : mx, mn = w[i] < mn ? w[i] : mn, i++)       ;     for (k = 0, i = 0; i < 7; i++)       for (j = 0; j < 7; k += m[i][j] && u[i] == u[j], j++)         ;     if (mx - mn < r || (mx - mn == r && k > rb)) {       r = mx - mn;       rb = k;     }   }   void rec(int i) {     if (i == 7)       upd();     else       for (u[i] = 0; u[i] < 3; rec(i + 1), u[i]++)         ;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0), cerr <<   ;     int i, j, t;     char s[100];     for (i = 0; i < 7; h[q[i]] = i, i++)       ;     for (cin >> t; t--;) {       cin >> s;       i = h[s];       cin >> s >> s;       j = h[s];       m[i][j] = 1;     }     for (i = 0; i < 3; cin >> a[i], i++)       ;     r = 2000000010;     rec(0);     cout << r <<     << rb << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxprime = 2750131;   int prime[mxprime + 1], res;   int func(int n) {     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return n / i;   }   vector<int> ord(mxprime, false);   int vc[500001];   int main() {     int n;     cin >> n;     prime[1] = true;     map<int, int> mp;     for (int i = 2; i * i <= mxprime; i++) {       if (!prime[i]) {         for (int j = i * i; j <= mxprime; j += i) {           prime[j] = true;         }       }     }     for (int i = 2; i <= mxprime; i++) {       if (!prime[i]) {         ord[i] = ++res;       }     }     vector<int> a;     n = n * 2;     for (int i = 1; i <= n; i++) {       cin >> vc[i];       mp[vc[i]]++;     }     sort(vc + 1, vc + n + 1, greater<int>());     for (int i = 1; i <= n; i++) {       if (!mp[vc[i]]) continue;       if (!prime[vc[i]]) {         a.push_back(ord[vc[i]]);         mp[ord[vc[i]]]--;       } else {         a.push_back(vc[i]);         mp[func(vc[i])]--;       }       mp[vc[i]]--;     }     for (int i = 0; i < a.size(); i++) {       cout << a[i] <<    ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int T, n, a, b, c;   string s;   int shi, bu, jian;   int main() {     cin >> T;     while (T--) {       shi = bu = jian = 0;       cin >> n;       cin >> a >> b >> c;       cin >> s;       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  R )           shi++;         else if (s[i] ==  P )           bu++;         else           jian++;       }       if (min(a, jian) + min(b, shi) + min(c, bu) < (n + 1) / 2) {         cout <<  NO  << endl;         continue;       }       cout <<  YES  << endl;       string t =   ;       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  R  && b) {           t +=  P ;           b--;         } else if (s[i] ==  P  && c) {           t +=  S ;           c--;         } else if (s[i] ==  S  && a) {           a--;           t +=  R ;         } else {           t +=  _ ;         }       }       for (int i = 0; i != n; ++i) {         if (t[i] !=  _ ) continue;         if (a) {           t[i] =  R ;           a--;         } else if (b) {           t[i] =  P ;           b--;         } else {           t[i] =  S ;           c--;         }       }       cout << t <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 * 100 + 3, inf = 1000 * 1000 * 100;   int n, m, a[MAXN], b[MAXN], t[MAXN], ans = 0, y, z;   int main() {     cin >> n >> m >> y >> z;     for (int i = 0; i < n; i++) cin >> a[i];     b[0] = -inf;     b[m + 1] = inf;     for (int i = 1; i <= m; i++) cin >> b[i];     for (int i = 0; i <= m; i++) t[i] = -1;     for (int i = 0; i < n; i++) {       int ind = lower_bound(b, b + m + 2, a[i]) - b;       int nex = b[ind], prev = b[ind - 1];       if (nex - a[i] < a[i] - prev) {         if (t[ind] != -1) ans++;         t[ind] = nex - a[i];       } else if (nex - a[i] > a[i] - prev) {         if (t[ind - 1] != -1 && t[ind - 1] < a[i] - prev) {           ans++;         } else {           if (t[ind - 1] > a[i] - prev) ans++;           t[ind - 1] = a[i] - prev;         }       } else {         if (t[ind - 1] == -1 || t[ind - 1] == a[i] - prev) {           t[ind - 1] = a[i] - prev;         } else {           t[ind] = nex - a[i];         }       }     }     cout << ans << endl;     return 0;   }


/*    * yaswanth phani kommineni    */   #include <bits/stdc++.h>   using namespace std;   typedef long long int ll;   #define endl   n ;         void solve(){    ll n;    cin >> n;    n*=2;    vector <ll> v(n);    map <ll,ll> m;    for(ll i=0;i<n;i++){     cin >> v[i];     m[v[i]]++;    }    sort(v.begin(),v.end());    for(ll i=0;i<n-1;i++){     auto mp = m;     auto V = v;     vector <pair<ll,ll>> ans;     ans.push_back(make_pair(v[n-1],v[i]));     mp[v[n-1]]--;     mp[v[i]]--;     ll cur = v[n-1];     while(true){      while(!V.empty() && !mp[V.back()]){       V.pop_back();      }      if(V.empty()) break;      ll last = V.back();      mp[last]--;      if(!mp[cur-last]){       break;      }      ans.push_back(make_pair(last,cur-last));      mp[cur-last]--;      cur = last;     }     if((ll)ans.size()==n/2){      cout <<  YES  << endl;      cout << ans.front().first + ans.front().second << endl;      for(auto x : ans){       cout << x.second <<     << x.first << endl;      }      return;     }    }    cout <<  NO  << endl;   }      int main(){    //freopen( input.txt , r ,stdin);    //freopen( output.txt , w ,stdout);    ios_base::sync_with_stdio(false);    cin.tie(0);    cout.tie(0);    int tc;    tc = 1;    cin >> tc;    for(int i=1;i<=tc;i++){     solve();    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int toDelete = 0, arr[1500010], N;   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin >> N;     for (int i = 0; i < N; ++i) {       int x;       cin >> x;       arr[x]++;     }     int ans = 0;     for (int i = 0; i <= 1500000; ++i) {       int val = arr[i];       int id = i;       arr[i] = 0;       while (val > 0) {         arr[id] += val % 2;         id++;         val /= 2;       }       if (arr[i]) ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& out, vector<T>& v) {     out <<  [ ;     for (auto k : v) out << k <<    ;     out <<  ] ;     return out;   }   vector<int> g[500];   string color;   bool posible = true;   void DFS(int n, int p, char c) {     if (color[n] !=  -  && color[n] != c) {       posible = false;       return;     }     if (color[n] !=  - ) return;     color[n] = c;     char nc =  1  - c +  0 ;     for (auto k : g[n])       if (k != p) DFS(k, n, nc);   }   int main() {     int n;     string in;     cin >> n >> in;     color.resize(n,  - );     for (int i = 0; i < int(n); i++) {       for (int j = int(i + 1); j < int(n); j++) {         if (in[i] > in[j]) {           g[i].push_back(j);           g[j].push_back(i);         }       }     }     for (int i = 0; i < int(n); i++)       if (color[i] ==  - ) DFS(i, -1,  0 );     if (posible)       cout <<  YES  << endl << color << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<pair<int, int> > > v(400005);   int parent[400005], low[400005], disc[400005], TIME;   bool visited[400005], road[400005];   set<int> bridge;   int SIZE;   pair<int, int> EDGE[400005];   void dfs(int a) {     TIME++;     visited[a] = true;     disc[a] = TIME, low[a] = TIME;     for (int i = 0; i < v[a].size(); i++) {       if (!visited[v[a][i].first]) {         parent[v[a][i].first] = a;         dfs(v[a][i].first);         low[a] = min(low[a], low[v[a][i].first]);         if (low[v[a][i].first] > disc[a]) bridge.insert(v[a][i].second);       } else if (v[a][i].first != parent[a])         low[a] = min(low[a], disc[v[a][i].first]);     }   }   void dfs2(int a) {     visited[a] = true;     SIZE++;     for (int i = 0; i < v[a].size(); i++)       if (bridge.count(v[a][i].second) == 0 and !visited[v[a][i].first])         dfs2(v[a][i].first);   }   void solve(int a) {     for (int i = 0; i < v[a].size(); i++) {       if (!road[v[a][i].second]) {         road[v[a][i].second] = true;         if (bridge.count(v[a][i].second) == 0)           EDGE[v[a][i].second] = make_pair(a, v[a][i].first);         else           EDGE[v[a][i].second] = make_pair(v[a][i].first, a);         solve(v[a][i].first);       }     }   }   int main() {     int n, m;     cin >> n >> m;     int MAXSIZE = 0, NODE;     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d %d , &x, &y);       v[x].push_back(make_pair(y, i)), v[y].push_back(make_pair(x, i));     }     dfs(1);     memset(visited, false, sizeof(visited));     for (int i = 0; i < n; i++) {       SIZE = 0;       if (!visited[i + 1]) dfs2(i + 1);       if (SIZE > MAXSIZE) MAXSIZE = SIZE, NODE = i + 1;     }     solve(NODE);     cout << MAXSIZE << endl;     for (int i = 0; i < m; i++)       cout << EDGE[i].first <<     << EDGE[i].second << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int INF = 0x3f3f3f3f;   const ll LINF = 0x3f3f3f3f3f3f3f3fLL;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << setprecision(10) << fixed;     int n, k;     cin >> n >> k;     vector<double> p(n);     for (auto& x : p) cin >> x;     int null = (int)count(begin(p), end(p), 0.0);     if (n - null < k) {       for (int u = 0; u < n; ++u) {         double res = p[u] == 0.0 ? 0.0 : 1.0;         cout << res <<   n ;       }       exit(0);     }     vector<int> popcount(1 << n, 0);     vector<double> sum(1 << n, 0);     for (int u = 0; u < n; ++u) sum[1 << u] = p[u];     for (int mask = 1; mask < (1 << n); ++mask) {       int lsb = mask & -mask;       popcount[mask] = 1 + popcount[mask ^ lsb];       if (mask != lsb) sum[mask] = sum[lsb] + sum[mask ^ lsb];     }     vector<double> dp(1 << n, 0);     dp[0] = 1;     for (int mask = 0; mask < (1 << n); ++mask) {       for (int u = 0; u < n; ++u) {         if ((mask >> u & 1) || p[u] == 0) continue;         int newmask = mask | (1 << u);         dp[newmask] += dp[mask] * p[u] / (1 - sum[mask]);       }     }     for (int u = 0; u < n; ++u) {       double res = 0;       for (int mask = 0; mask < (1 << n); ++mask) {         if (popcount[mask] == k && (mask >> u & 1)) res += dp[mask];       }       cout << res <<   n ;     }     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   int dis[305][305], lca[305], val[305];   int main() {     int n, x;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       lca[x] = i;       val[i] = x;     }     char s[305];     memset(dis, 0, sizeof dis);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= n; j++)         if (s[j] ==  1 ) dis[i][j] = dis[j][i] = 1;     }     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           if (dis[i][j] == 0) dis[i][j] = dis[i][k] & dis[k][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         if (dis[i][lca[j]] == 0) continue;         val[lca[j]] = val[i];         lca[val[i]] = lca[j];         val[i] = j;         lca[j] = i;       }     for (int i = 1; i <= n; i++) printf( %d%s , val[i], i == n ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e3 + 7;   long long read() {     long long res = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - ) f = -1, c = getchar();     while (isdigit(c)) res = (res << 1) + (res << 3) + c - 48, c = getchar();     return res * f;   }   long long ans;   int n, m;   long long f[maxn][maxn], g[maxn][maxn];   int main() {     n = read(), m = read();     for (int i = 2; i <= m; i++) f[1][i] = 1;     for (int i = 2; i <= n; i++)       for (int j = 2; j <= m; j++)         f[i][j] = (f[i - 1][j] + 2 * f[i][j - 1] - f[i][j - 2] + 1000000007) %                   1000000007;     for (int i = 1; i <= n; i++)       for (int j = 2; j <= m; j++) g[i][j] = (g[i - 1][j] + f[i][j]) % 1000000007;     for (int i = 1; i <= n; i++)       for (int j = 2; j <= m; j++)         (ans += f[i][j] * g[n - i + 1][j] % 1000000007 * (m - j + 1) %                 1000000007) %= 1000000007;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0, l = 0, r = 0, x = 0, c[16];     cin >> n >> l >> r >> x;     for (int i = 0; i < n; i++) cin >> c[i];     sort(c, c + n);     int total = 0, cnt = 0, ret = 0, easy = 0, hard = 0;     for (int i = 0; i < (1 << n); i++) {       total = 0, cnt = 0;       for (int j = 0; j < n; j++) {         if ((1 << j) & i) {           if (cnt == 0) {             easy = c[j];           }           total += c[j];           cnt++;           hard = c[j];         }       }       if (cnt > 1 && total >= l && total <= r && hard - easy >= x) {         ret++;       }     }     cout << ret;     return 0;   }


#include <bits/stdc++.h>   char putnb[20];   using namespace std;   const long long mod = 1e9 + 7;   const long long mod2 = 1999999973;   const int infs = 1e8;   const long long inf = 1e18;   const int N = 200000;   long long A[N + 5];   long long dp[N + 5][2];   bool vis[N + 5][2];   bool solved[N + 5][2];   long long n;   long long solve(long long pos, int state) {     if (pos <= 0 || pos > n) return 0;     if (vis[pos][state] && !solved[pos][state]) return -1;     vis[pos][state] = true;     if (pos == 1) {       if (state) return 0 - inf;       return -1;     }     if (solved[pos][state]) return dp[pos][state];     if (!state) {       long long v1 = solve(pos + A[pos], 1);       if (v1 == -1)         dp[pos][state] = -1;       else         dp[pos][state] = v1 + A[pos];     } else {       long long v2 = solve(pos - A[pos], 0);       if (v2 == -1)         dp[pos][state] = -1;       else         dp[pos][state] = v2 + A[pos];     }     solved[pos][state] = true;     return dp[pos][state];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     cin >> n;     for (int i = 2; i <= n; ++i) cin >> A[i];     for (int i = 1; i <= n - 1; ++i) {       long long res = solve(1 + i, 1);       if (res == -1)         cout << res <<   n ;       else if (res >= 0)         cout << res + i <<   n ;       else if (res < 0)         cout << (res + inf + 2 * i) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int X = 1e5 + 9;   const long long inf = (1ll << 60);   int n, sum, a[109], b[109], c[109];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       b[a[i]]++;     }     for (int i = 0; i < n; i++) {       cin >> a[i];       c[a[i]]++;     }     for (int i = 1; i <= 5; i++) {       if ((b[i] + c[i]) % 2 == 1) {         puts( -1 );         return 0;       }     }     for (int i = 1; i <= 5; i++) {       sum += (abs(c[i] - b[i]) / 2);     }     cout << sum / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 200010, MaxB = 500, MaxA = 1000010, mod = 1000000007;   struct Query {     int l, r, id;     bool operator<(const Query &a) const { return r < a.r; }   } q[MaxN];   int n, m, a[MaxN];   vector<pair<int, int> > f[MaxN];   int last[MaxA];   int prime[MaxA], ptot, minp[MaxA];   int inv[MaxA];   bool notp[MaxA];   void init(int n) {     for (int i = 2; i <= n; ++i) {       if (!notp[i]) {         prime[++ptot] = i;         minp[i] = i;       }       for (int j = 1; j <= ptot && prime[j] * i <= n; ++j) {         notp[prime[j] * i] = 1;         minp[prime[j] * i] = prime[j];         if (i % prime[j] == 0) break;       }     }     inv[1] = 1;     for (int i = 2; i <= n; ++i)       inv[i] = mod - 1ll * (mod / i) * inv[mod % i] % mod;   }   int ans[MaxN];   int c[MaxN];   void modify(int x, int v) {     for (; x <= n; x += (x & -x)) c[x] = 1ll * c[x] * v % mod;   }   int query(int x) {     int ret = 1;     for (; x; x -= (x & -x)) ret = 1ll * ret * c[x] % mod;     return ret;   }   int main() {     scanf( %d , &n);     int mx = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);       mx = max(mx, a[i]);     }     init(mx);     for (int i = 1; i <= n; ++i) {       int x = a[i];       while (x != 1) {         int prod = 1, t = minp[x];         while (x % t == 0) {           x /= t;           prod *= t;         }         f[i].push_back(make_pair(t, prod));       }     }     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &q[i].l, &q[i].r);       q[i].id = i;     }     sort(q + 1, q + m + 1);     for (int i = 0; i <= n; ++i) c[i] = 1;     int node = 0;     for (int i = 1; i <= n; ++i) {       for (auto t : f[i]) {         modify(1, t.second);         modify(last[t.first] + 1, 1ll * (t.first - 1) * inv[t.first] % mod);         modify(i + 1, inv[t.second / t.first * (t.first - 1)]);         last[t.first] = i;       }       while (node < m && q[node + 1].r == i) {         ++node;         ans[q[node].id] = query(q[node].l);       }     }     for (int i = 1; i <= m; ++i) printf( %d n , ans[i]);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   inline void splay(int &v) {     v = 0;     char c = 0;     int p = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) p = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       v = (v << 3) + (v << 1) + c -  0 ;       c = getchar();     }     v *= p;   }   const int N = 800010;   int v[N], a[N], n, m, mi;   vector<int> vv[N];   void build(int l, int r, int w) {     if (l == r) return v[w] = a[l], void();     int mid = l + r >> 1;     build(l, mid, w << 1);     build(mid + 1, r, w << 1 | 1);     v[w] = min(v[w << 1], v[w << 1 | 1]);   }   void get(int l, int r, int w, int L, int R) {     if (L <= l && r <= R) {       mi = min(mi, v[w]);       return;     }     int mid = l + r >> 1;     if (L <= mid) get(l, mid, w << 1, L, R);     if (R > mid) get(mid + 1, r, w << 1 | 1, L, R);   }   int getmi(int l, int r) {     mi = 1 << 30;     if (l > r) return mi;     get(1, n, 1, l, r);     return mi;   }   int now = -1;   int main() {     splay(n), splay(m);     a[0] = 1;     for (int i = 1; i <= n; i++) {       splay(a[i]);       if (!a[i]) {         a[i] = a[i - 1];         now = i;       }       vv[a[i]].push_back(i);     }     build(1, n, 1);     for (int i = 1; i <= m; i++) {       for (int j = 0; j < (int)(vv[i].size()) - 1; j++) {         int x = getmi(vv[i][j] + 1, vv[i][j + 1] - 1);         if (x < i) puts( NO ), exit(0);       }     }     bool flag = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == m) flag = 1;     }     if (!flag) {       if (now != -1)         a[now] = m;       else         puts( NO ), exit(0);     }     puts( YES );     for (int i = 1; i <= n; i++) {       printf( %d%c , a[i],    n [i == n]);     }   }


#include <bits/stdc++.h>   using LL = long long;   const int maxn = 1011000;   const LL mod = 1e9 + 7;   int seed = 29, n;   char str[maxn];   LL base[maxn], Hash[maxn];   int ans[maxn];   void init() {     memset(base, 0, sizeof(base));     base[0] = 1;     for (int i = 1; i < maxn; i++) {       base[i] = base[i - 1] * seed;       base[i] %= mod;     }   }   void init_hash() {     memset(Hash, 0, sizeof(Hash));     for (int i = n - 1; i >= 0; i--) {       Hash[i] = Hash[i + 1] * seed + str[i] -  a  + 1;       Hash[i] %= mod;     }   }   LL get_hash(int i, int len) {     auto ans = Hash[i] - Hash[i + len] * base[len];     ans %= mod;     if (ans < 0) ans += mod;     return ans;   }   int main() {     init();     while (std::cin >> n) {       std::cin >> str;       init_hash();       memset(ans, -1, sizeof(ans));       int cur = -1;       for (int i = (n - 1) / 2; i >= 0; i--) {         cur += 2;         if (2 * i == n - 1) {           cur = -1;         }         while (cur != -1 && get_hash(i, cur) != get_hash(n - i - cur, cur))           cur -= 2;         ans[i] = cur;       }       for (int i = 0; i <= (n - 1) / 2; i++) {         std::cout << ans[i] <<    ;       }       std::cout << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long sum = 0, ff = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) ff = -1;       ch = getchar();     }     while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();     return sum * ff;   }   const long long N = 5005;   long long A, B, n, lcs[N][N], f[N];   char ch[N];   signed main() {     n = read();     A = read();     B = read();     scanf( %s , ch + 1);     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= n; j++)         if (ch[i] == ch[j])           lcs[i][j] = lcs[i - 1][j - 1] + 1;         else           lcs[i][j] = 0;     for (long long i = 1; i <= n; i++) {       f[i] = f[i - 1] + A;       for (long long j = 1; j < i; j++)         if (lcs[i][j] <= i - j) f[i] = min(f[i], f[i - lcs[i][j]] + B);     }     printf( %lld n , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gi() {     char cc = getchar();     long long cn = 0, flus = 1;     while (cc <  0  || cc >  9 ) {       if (cc ==  - ) flus = -flus;       cc = getchar();     }     while (cc >=  0  && cc <=  9 ) cn = cn * 10 + cc -  0 , cc = getchar();     return cn * flus;   }   const long long P = 998244353;   long long fpow(long long x, long long k) {     long long ans = 1, base = x;     while (k) {       if (k & 1) ans = 1ll * ans * base % P;       base = 1ll * base * base % P, k >>= 1;     }     return ans;   }   const long long N = 3e5 + 5;   long long m, n, a[N], fac[N], inv[N];   long long C(long long x, long long y) {     return fac[x] * inv[y] % P * inv[x - y] % P;   }   signed main() {     m = gi(), n = m * 2;     for (register long long i = (1); i <= (n); ++i) a[i] = gi();     sort(a + 1, a + n + 1);     fac[0] = inv[0] = 1;     for (register long long i = (1); i <= (n); ++i) fac[i] = fac[i - 1] * i % P;     for (register long long i = (1); i <= (n); ++i) inv[i] = fpow(fac[i], P - 2);     long long ans = 0;     for (register long long i = (1); i <= (n); ++i) {       long long z = a[i] * C(n - 1, m - 1);       if (i <= m)         ans = (ans - z + P) % P;       else         ans = (ans + z + P) % P;     }     cout << ans * 2 % P << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int M = (1e5 + 10 + N) * 2;   const int inf = 0x3f3f3f3f;   int n, m, S, T;   struct node {     int u, v, w;   } Edge[N];   bool cmp(node &a, node &b) { return a.w < b.w; }   int h[N], tot, e[M], f[M], ne[M];   int d[N], cur[N];   void add(int u, int v, int w) {     e[tot] = v, f[tot] = w, ne[tot] = h[u], h[u] = tot++;     e[tot] = u, f[tot] = 0, ne[tot] = h[v], h[v] = tot++;   }   bool bfs() {     queue<int> q;     q.push(S);     memset(d, -1, sizeof d);     d[S] = 0;     cur[S] = h[S];     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = h[u]; ~i; i = ne[i]) {         int v = e[i];         if (d[v] == -1 && f[i]) {           d[v] = d[u] + 1;           cur[v] = h[v];           if (v == T) return true;           q.push(v);         }       }     }     return false;   }   int dfs(int u, int limit) {     if (u == T) return limit;     int flow = 0;     for (int i = cur[u]; ~i && flow < limit; i = ne[i]) {       cur[u] = i;       int v = e[i];       if (d[v] == d[u] + 1 && f[i]) {         int t = dfs(v, min(f[i], limit - flow));         flow += t;         f[i] -= t;         f[i ^ 1] += t;       }     }     return flow;   }   int dinic() {     int flow, res = 0;     while (bfs()) {       while (flow = dfs(S, inf)) res += flow;     }     return res;   }   bool check(int mid) {     S = 0, T = 2 * n + 1;     for (int i = 0; i <= T; i++) h[i] = -1;     tot = 0;     for (int i = 1; i <= n; i++) add(S, i, 1);     for (int j = 1; j <= n; j++) add(n + j, T, 1);     for (int i = 1; i <= m; i++) {       if (Edge[i].w > mid) break;       add(Edge[i].u, n + Edge[i].v, Edge[i].w);     }     return dinic() == n;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++)       scanf( %d%d%d , &Edge[i].u, &Edge[i].v, &Edge[i].w);     sort(Edge + 1, Edge + 1 + m, cmp);     int l = 1, r = Edge[m].w;     int ans = -1;     while (l <= r) {       int mid = (l + r) / 2;       if (check(mid)) {         r = mid - 1;         ans = mid;       } else         l = mid + 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1000 + 5;   int n;   int mat[NMAX][NMAX];   vector<pair<int, int> > sol;   void DEI(int l, int r, int insert_type) {     if (r - l + 1 < 3) return;     int k;     for (k = l + 1; k <= r - 1; ++k)       if (mat[l][k] && mat[k][r]) break;     if (insert_type == 0) sol.push_back(make_pair(l, r));     mat[l][r] = mat[r][l] = false;     mat[1][k] = mat[k][1] = true;     DEI(l, k, insert_type);     DEI(k, r, insert_type);     if (insert_type == 1) sol.push_back(make_pair(1, k));   }   void solve(int type) {     memset(mat, 0, sizeof mat);     vector<int> graph1;     for (int i = 1; i < n - 2; ++i) {       int a, b;       cin >> a >> b;       mat[a][b] = mat[b][a] = true;     }     for (int i = 1; i <= n; ++i) mat[i][i % n + 1] = mat[i % n + 1][i] = true;     for (int i = 1; i <= n; ++i)       if (mat[1][i]) graph1.push_back(i);     for (int i = 1; i < graph1.size(); ++i) DEI(graph1[i - 1], graph1[i], type);   }   int main() {     cin >> n;     solve(0);     solve(1);     cout << sol.size() <<   n ;     for (auto it : sol) cout << it.first <<     << it.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename C>   void ma(C& a, C b) {     if (a < b) a = b;   }   template <typename C>   void mi(C& a, C b) {     if (a > b) a = b;   }   int cas, n, l[251], r[251], w[251], roz[251];   void licz_roz(int nr) {     if (w[nr] == -1) {       licz_roz(l[nr]);       licz_roz(r[nr]);       if (roz[r[nr]] & 1) swap(l[nr], r[nr]);       roz[nr] = 1 + roz[l[nr]] + roz[r[nr]];     } else       roz[nr] = 0;   }   int dp[251][2][3];   int ak[251][2][3];   inline int mima(int a, int b, bool jak) { return ((a > b) ^ jak) ? a : b; }   inline int mima3(int a, int b, int c, bool jak) {     return mima(mima(a, b, jak), c, jak);   }   int dfs(int nr, bool kto, int pas) {     if (w[nr] != -1) return w[nr];     if (roz[nr] == 1) return mima(w[l[nr]], w[r[nr]], kto ^ (pas == 2));     int& res = dp[nr][kto][pas];     if (ak[nr][kto][pas] == cas) return res;     ak[nr][kto][pas] = cas;     if (pas) {       if (roz[nr] & 1) {         res = dfs(nr, !kto, 0);         if (roz[l[nr]] & 1) {           int pom =               mima(dfs(l[nr], kto, 0),                    dfs(r[nr], !kto, roz[l[nr]] == 1 && pas == 1 ? 2 : 1), !kto);           res = mima(res, pom, kto);           pom = mima(dfs(r[nr], kto, 0),                      dfs(l[nr], !kto, roz[r[nr]] == 1 && pas == 1 ? 2 : 1), !kto);           res = mima(res, pom, kto);         } else {           if (roz[r[nr]]) {             int pom =                 mima(dfs(l[nr], !kto, 0),                      dfs(r[nr], kto, roz[l[nr]] == 0 && pas == 1 ? 2 : 1), !kto);             res = mima(res, pom, kto);           }           if (roz[l[nr]]) {             int pom =                 mima(dfs(r[nr], !kto, 0),                      dfs(l[nr], kto, roz[r[nr]] == 0 && pas == 1 ? 2 : 1), !kto);             res = mima(res, pom, kto);           }         }       } else {         res = mima(dfs(r[nr], kto, 0),                    dfs(l[nr], kto, roz[r[nr]] == 0 && pas == 1 ? 2 : 1), kto);       }     } else {       if (roz[nr] & 1) {         if (roz[l[nr]] & 1)           res = mima(dfs(l[nr], kto, 1), dfs(r[nr], kto, 1), kto);         else           res = mima(dfs(l[nr], kto, 0), dfs(r[nr], kto, 0), kto);       } else {         int pom = mima(dfs(l[nr], kto, 0), dfs(r[nr], !kto, 0), !kto);         int pom2 = mima(dfs(l[nr], !kto, 1), dfs(r[nr], kto, 1), !kto);         res = mima(pom, pom2, kto);       }     }     return res;   }   void test() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &w[i]);       if (w[i] == -1) {         scanf( %d , &l[i]);         scanf( %d , &r[i]);       }     }     licz_roz(0);     printf( %d n , dfs(0, 0, 0));   }   int main() {     int _;     scanf( %d , &_);     for (cas = 1; cas <= _; cas++) test();   }


#include <bits/stdc++.h>   using namespace std;   int cost[15][2][2];   string a[15];   int dp[15][2], topFloor;   int memoize(int floor, int dir) {     if (floor > topFloor) {       return 0;     }     if (floor == topFloor) {       return cost[floor][dir][dir];     }     if (dp[floor][dir] != -1) return dp[floor][dir];     int ans = 2000000000;     ans = min(memoize(floor + 1, dir ^ 1) + 1 + cost[floor][dir][dir ^ 1],               memoize(floor + 1, dir) + 1 + cost[floor][dir][dir]);     return dp[floor][dir] = ans;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     reverse(a, a + n);     m += 2;     topFloor = -1;     for (int i = 0; i < n; i++) {       bool present = false;       int mini = m + 5, maxi = -1;       for (int j = 0; j < m; j++) {         if (a[i][j] ==  1 ) {           present = true;           mini = min(mini, j);           maxi = max(maxi, j);         }       }       if (present) {         topFloor = i;         cost[i][0][0] = maxi * 2;         cost[i][1][1] = (m - 1 - mini) * 2;       }       cost[i][0][1] = m - 1;       cost[i][1][0] = m - 1;     }     if (topFloor != -1) {       cost[topFloor][0][0] /= 2;       cost[topFloor][1][1] /= 2;     }     memset(dp, -1, sizeof(dp));     int ans = memoize(0, 0);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<string> S;   string rotate1(string s) {     string s1 = s;     s1[1] = s[2];     s1[2] = s[4];     s1[4] = s[5];     s1[5] = s[1];     return s1;   }   string rotate2(string s) {     string s1 = s;     s1[0] = s[1];     s1[1] = s[3];     s1[3] = s[4];     s1[4] = s[0];     return s1;   }   set<pair<string, bool> > poszlo;   void go(string s, bool sel) {     if (!poszlo.insert(make_pair(s, sel)).second) return;     S.insert(s);     if (sel) {       s = rotate2(s);       go(s, 0);       s = rotate2(s);       go(s, 0);       s = rotate2(s);       go(s, 0);     } else {       s = rotate1(s);       go(s, 1);       s = rotate1(s);       go(s, 1);       s = rotate1(s);       go(s, 1);     }   }   int main() {     string s;     cin >> s;     sort(s.begin(), s.end());     int res = 0;     do {       if (S.insert(s).second) res++;       poszlo.clear();       go(s, 0);       go(s, 1);     } while (next_permutation(s.begin(), s.end()));     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int INF = 0x3f3f3f3f;   int INF2 = 0x7fffffff;   long long LNF = 0x3f3f3f3f3f3f3f3f;   long long LNF2 = 0x7fffffffffffffff;   long long n, k, M, D;   long long ans;   int main() {     scanf( %I64d%I64d%I64d%I64d , &n, &k, &M, &D);     for (int i = (1); i <= (D); ++i) {       if (i * k - k + 1 > n) break;       long long c = n / (i * k - k + 1);       c = min(c, M);       ans = max(ans, c * i);     }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, r;     cin >> n >> m >> r;     int min1 = 1001;     int max1 = 0;     int a, b;     for (int i = 0; i < n; i++) {       cin >> a;       min1 = min(a, min1);     }     for (int i = 0; i < m; i++) {       cin >> b;       max1 = max(b, max1);     }     int d = r / min1;     if (min1 > max1) {       cout << r << endl;       return 0;     }     int cost = (d * max1 + r % min1);     if (cost > r) {       cout << cost << endl;     } else {       cout << r << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     float square = sqrt(n);     float csquare = ceil(square);     if ((csquare == square) || (csquare - square <= 0.5)) {       cout << 4 * csquare;     } else if (csquare - square > 0.5) {       cout << 2 * (csquare + (csquare - 1));     }     return 0;   }


#include <bits/stdc++.h>   const int Mod = (int)1e9 + 7;   const int MX = 1073741822;   const long long MXLL = 4611686018427387903;   const int Sz = 2e5 + 1;   using namespace std;   inline void Read_rap() {     ios_base ::sync_with_stdio(0);     cin.tie(0);   }   int n;   int a[Sz];   long long dp[Sz][20][2], lca[Sz][20][2], sum[Sz][20][2];   vector<int> g[Sz];   void dfs(int v, int pr) {     for (int i = 0; i < 20; i++) dp[v][i][((a[v] & (1 << i)) > 0)]++;     for (auto to : g[v]) {       if (to != pr) {         dfs(to, v);         for (int i = 0; i < 20; i++) {           for (int j = 0; j < 2; j++) {             bool bit = (a[v] & (1 << i)) > 0;             bool b = (j ^ bit);             dp[v][i][b] += dp[to][i][j];           }         }       }     }     for (auto to : g[v]) {       if (to != pr) {         for (int i = 0; i < 20; i++) {           for (int j = 0; j < 2; j++) {             for (int k = 0; k < 2; k++) {               bool bit = (a[v] & (1 << i)) > 0;               bool b = (j ^ k ^ bit);               lca[v][i][b] += sum[v][i][j] * dp[to][i][k];             }           }           for (int j = 0; j < 2; j++) sum[v][i][j] = sum[v][i][j] + dp[to][i][j];         }       }     }   }   int main() {     Read_rap();     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(1, 1);     long long ans = 0;     for (int i = 0; i < 20; i++)       for (int v = 1; v <= n; v++)         ans = (ans + (dp[v][i][1] + lca[v][i][1]) * (1ll << i));     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[55][55];   int main() {     int cs;     scanf( %d , &cs);     while (cs--) {       int n, m;       scanf( %d %d , &n, &m);       int col = 0, row = 0;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           scanf( %d , &a[i][j]);         }       }       for (int i = 0; i < n; i++) {         bool flag = true;         for (int j = 0; j < m; j++) {           if (a[i][j] & 1) {             flag = false;             break;           }         }         if (flag) row++;       }       for (int i = 0; i < m; i++) {         bool flag = true;         for (int j = 0; j < n; j++) {           if (a[j][i] & 1) {             flag = false;             break;           }         }         if (flag) col++;       }       if (min(col, row) % 2)         puts( Ashish );       else         puts( Vivek );     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   char s[200];   int main() {     int T;     scanf( %d , &T);     for (int t = 1; t <= T; t++) {       bool num = 0, xx = 0, dx = 0;       vector<int> res;       scanf( %s , s + 1);       int len = strlen(s + 1);       for (int i = 1; i <= len; i++) {         if (isdigit(s[i])) {           if (!num)             num = 1;           else             res.push_back(i);         }         if (isalpha(s[i])) {           if (s[i] == tolower(s[i])) {             if (!xx)               xx = 1;             else               res.push_back(i);           } else {             if (!dx)               dx = 1;             else               res.push_back(i);           }         }       }       int cnt = 1;       if (num == 0) s[res.back()] =  1 , res.pop_back();       if (xx == 0) s[res.back()] =  a , res.pop_back();       if (dx == 0) s[res.back()] =  A , res.pop_back();       printf( %s n , s + 1);     }   }


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


#include <bits/stdc++.h>   void swap(int *, int *);   int main() {     int i, j, k;     int n;     scanf( %d , &n);     int arr[n];     for (i = 0; i < n; i++) {       scanf( %d , &arr[i]);     }     int limit = n / 2;     for (i = 0; i < limit; i++) {       if (i % 2 == 0) {         swap(&arr[i], &arr[n - i - 1]);       }     }     for (i = 0; i < n; i++) {       printf( %d  , arr[i]);     }   }   void swap(int *a, int *b) {     int t;     t = *a;     *a = *b;     *b = t;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     int a, b, a_min, b_min;     scanf( %d %d , &a_min, &b_min);     for (int i = 1; i < n; i++) {       scanf( %d %d , &a, &b);       if (a * b_min < a_min * b) {         a_min = a;         b_min = b;       }     }     double c = m * a_min / (b_min * 1.0f);     printf( %f n , c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   struct P {     long long x, y;     bool a;     P() {}     P(long long _x, long long _y, bool _a) : x(_x), y(_y), a(_a) {}     long long operator^(const P &t) const { return x * t.y - y * t.x; }     bool operator<(const P &t) const {       if (y == t.y) return x < t.x;       return y < t.y;     }     P operator-(const P &t) const { return P(x - t.x, y - t.y, 0); }   } p[N];   int n, m;   bool flag[N];   int st[N], tops;   void granhamScan() {     st[0] = 0;     tops = 1;     for (int i = 1; i < m; ++i) {       while (tops >= 2 && ((p[st[tops - 1]] - p[st[tops - 2]]) ^                            (p[i] - p[st[tops - 1]])) < 0) {         flag[st[tops - 1]] = false;         tops--;       }       st[tops++] = i;       flag[i] = true;     }     for (int i = m - 1; i >= 0; --i) {       if (flag[i]) continue;       while (tops >= 2 && ((p[st[tops - 1]] - p[st[tops - 2]]) ^                            (p[i] - p[st[tops - 1]])) < 0) {         flag[st[tops - 1]] = false;         tops--;       }       st[tops++] = i;       flag[i] = true;     }   }   bool check() {     for (int i = 0; i < tops; ++i) {       if (!p[st[i]].a) return 0;     }     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       p[i] = P(x, y, 1);     }     scanf( %d , &m);     m += n;     for (int i = n; i < m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       p[i] = P(x, y, 0);     }     sort(p, p + m);     p[m] = p[0];     granhamScan();     if (check())       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long double EPS = 1e-6;   const int N = 200020, MOD = 998244353;   int n, k;   long long a[N + 20], fact[N + 20], inv[N + 20];   long long qpow(long long a, long long b, long long p = MOD) {     long long ans = 1;     for (; b; b >>= 1) {       if (b & 1) ans = ans * a % p;       a = a * a % p;     }     return ans % p;   }   void prework() {     fact[0] = 1;     for (int i = 1; i <= N; i++) fact[i] = fact[i - 1] * i % MOD;     inv[N - 1] = qpow(fact[N - 1], MOD - 2) % MOD;     for (int i = N - 2; ~i; i--) inv[i] = inv[i + 1] * (i + 1) % MOD;   }   long long C(int n, int m) {     if (n - m < 0 || m < 0) return 0;     return fact[n] % MOD * inv[m] % MOD * inv[n - m] % MOD % MOD;   }   int main() {     prework();     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     long long ans = 0;     int c = 0, m = 0;     a[n + 1] = a[1];     for (int i = 1; i <= n; i++)       if (a[i] != a[i + 1]) m++;     for (int i = 0; i <= m / 2; i++) {       ans += C(m, i) % MOD * C(m - i, i) % MOD * qpow(k - 2, m - 2 * i) % MOD;       ans %= MOD;     }     ans = (qpow(k, m) - ans + MOD) % MOD * qpow(2, MOD - 2) % MOD;     cout << ans % MOD * qpow(k, n - m) % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> A;   vector<pair<int, int> > M;   vector<int> PP;   int turn;   set<int> Go;   int ans(int x) {     cout << x + 1 << endl;     if (Go.empty()) exit(0);     cin >> x;     return x - 1;   }   signed main() {     ;     cin >> n >> m;     A.resize(n << 1);     for (auto &x : A) cin >> x;     M.resize(m);     for (auto &x : M) cin >> x.first >> x.second, x.first--, x.second--;     PP.assign(n << 1, -1);     for (auto x : M) PP[x.first] = x.second, PP[x.second] = x.first;     for (int i = 0; i < n << 1; i++) {       Go.insert(i);     }     cin >> turn;     if (turn == 1) {       for (auto x : M) {         if (A[x.first] > A[x.second]) {           ans(x.first);           Go.erase(x.first);           Go.erase(x.second);         } else {           ans(x.second);           Go.erase(x.first);           Go.erase(x.second);         }       }       while (Go.size()) {         int mx = -1, r = -1;         for (auto &x : Go) {           if (mx < A[x]) mx = A[x], r = x;         }         Go.erase(r);         Go.erase(ans(r));       }     } else {       int x;       cin >> x;       x--;       Go.erase(x);       while (PP[x] != -1) {         Go.erase(PP[x]);         x = ans(PP[x]);         Go.erase(x);       }       for (auto x : M) {         if (!Go.count(x.first)) continue;         if (A[x.first] > A[x.second]) {           ans(x.first);           Go.erase(x.first);           Go.erase(x.second);         } else {           ans(x.second);           Go.erase(x.first);           Go.erase(x.second);         }       }       while (Go.size()) {         int mx = -1, r = -1;         for (auto &x : Go) {           if (mx < A[x]) mx = A[x], r = x;         }         Go.erase(r);         Go.erase(ans(r));       }     }   }


#include <bits/stdc++.h>   using namespace std;   int ans[500][500], st[500][500];   vector<pair<int, int> > go[500][500];   vector<vector<int> > cc;   vector<int> c;   int mv[1 << 20];   int it;   void pr(int n, int k) {     if (k == 1) {       c.push_back(n);       mv[(((c[4] * 16 + c[3]) * 16 + c[2]) * 16 + c[1]) * 16 + c[0]] = it;       cc.push_back(c);       it++;       c.pop_back();       return;     }     for (int j = 0; j <= n; j++) {       c.push_back(j);       pr(n - j, k - 1);       c.pop_back();     }   }   int kkk[5] = {1, 16, 256, 4096, 65536};   void get_int(int &ans) {     ans = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) {       ans = ans * 10 + c -  0 ;       c = getchar();     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     pr(8, 5);     queue<pair<int, int> > pp;     for (int j = 0; j < cc.size(); j++) {       vector<int> vv = cc[j];       int cnum = (((vv[4] * 16 + vv[3]) * 16 + vv[2]) * 16 + vv[1]) * 16 + vv[0];       bool ok = true;       for (int q = 0; q < cc.size(); q++) {         bool ok1 = true;         for (int ii = 1; ii < 5; ii++) {           if (cc[j][ii]) {             ok = false;             for (int jj = 1; jj < 5; jj++) {               if (cc[q][jj]) {                 ok1 = false;                 cnum -= kkk[ii];                 cnum += kkk[(ii + jj) % 5];                 go[q][mv[cnum]].push_back(make_pair(j, q));                 st[j][q]++;                 cnum += kkk[ii];                 cnum -= kkk[(ii + jj) % 5];               }             }             if (ok) {               ans[j][q] = 1;               pp.push(make_pair(j, q));             } else if (ok1) {               ans[j][q] = 2;               pp.push(make_pair(j, q));             }           }         }       }     }     while (!pp.empty()) {       int j = pp.front().first;       int q = pp.front().second;       pp.pop();       for (auto v : go[j][q]) {         if (ans[v.first][v.second]) continue;         if (ans[j][q] == 2) {           ans[v.first][v.second] = 1;           pp.push(v);           continue;         }         st[v.first][v.second]--;         if (st[v.first][v.second] == 0) {           ans[v.first][v.second] = 2;           pp.push(v);           continue;         }       }     }     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int f;       cin >> f;       int a = 0, b = 0;       for (int j = 0; j < 8; j++) {         int k;         cin >> k;         a += (1 << (k * 4));       }       for (int j = 0; j < 8; j++) {         int k;         cin >> k;         b += (1 << (k * 4));       }       int k1 = mv[a], k2 = mv[b];       if (f == 0) {         if (ans[k1][k2] == 1) cout <<  Alice  <<   n ;         if (ans[k1][k2] == 2) cout <<  Bob  <<   n ;         if (ans[k1][k2] == 0) cout <<  Deal  <<   n ;       } else {         swap(k1, k2);         if (ans[k1][k2] == 2) cout <<  Alice  <<   n ;         if (ans[k1][k2] == 1) cout <<  Bob  <<   n ;         if (ans[k1][k2] == 0) cout <<  Deal  <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i;   int a, b, c, d;   vector<long long> v;   long long ans;   void add(int a, int b) {     ans += a - b;     v.push_back(a + b);   }   void add_stack() {     if (a + b >= c + d) {       add(a, b);       add(c, d);       return;     }     if (a > d) add(a - d, d - a);     if (b > c) add(c - b, b - c);   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d%d%d , &a, &b, &c, &d);       add_stack();     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     long long sgn = 1;     for (auto e : v) {       ans += sgn * e;       sgn *= -1;     }     printf( %lld , ans / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 4005;   int read() {     int x = 0, f = 1;     char c;     while ((c = getchar()) <  0  || c >  9 ) {       if (c ==  - ) f = -1;     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return x * f;   }   int n, m, t, a[M], s[M], siz[M], ch[M][2];   long long dp[M][M];   void upd(long long &x, long long y) { x = max(x, y); }   void dfs(int u) {     dp[u][0] = 0;     if (!u) return;     int ls = ch[u][0], rs = ch[u][1];     dfs(ls);     dfs(rs);     siz[u] = 1 + siz[ls] + siz[rs];     for (int i = 0; i <= siz[ls]; i++)       for (int j = 0; j <= siz[rs]; j++)         upd(dp[u][i + j], dp[ls][i] + dp[rs][j] - 2ll * i * j * a[u]);     for (int i = siz[u] - 1; i >= 0; i--)       upd(dp[u][i + 1], dp[u][i] + (m - 2 * i - 1ll) * a[u]);   }   signed main() {     n = read();     m = read();     memset(dp, -0x3f, sizeof dp);     for (int i = 1; i <= n; i++) {       a[i] = read();       while (t > 0 && a[s[t]] > a[i]) ch[i][0] = s[t--];       if (t) ch[s[t]][1] = i;       s[++t] = i;     }     dfs(s[1]);     printf( %lld n , dp[s[1]][m]);   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q, l, r;   double d, s, t, x, y;   int tree[2000010 * 4], pl[2000010 * 4], pr[2000010 * 4], cnt = 1;   bool flag[2000010 * 4];   void change(int l, int r, int id, int l1, int r1) {     if (l >= l1 && r <= r1) {       tree[id] = r - l + 1;       flag[id] = 1;       return;     }     if (flag[id]) return;     int mid = (l + r) >> 1;     if (l1 <= mid) {       if (pl[id] == 0) pl[id] = ++cnt;       change(l, mid, pl[id], l1, r1);     }     if (r1 > mid) {       if (pr[id] == 0) pr[id] = ++cnt;       change(mid + 1, r, pr[id], l1, r1);     }     tree[id] = tree[pl[id]] + tree[pr[id]];   }   int dist(int l, int r, int l1, int r1) {     int l2 = max(l, l1);     int r2 = min(r, r1);     return r2 - l2 + 1;   }   int query(int l, int r, int id, int l1, int r1) {     if (l1 > r1) return 0;     if (l >= l1 && r <= r1) return tree[id];     if (flag[id]) return dist(l, r, l1, r1);     int mid = (l + r) >> 1;     int res = 0;     if (l1 <= mid && pl[id]) res += query(l, mid, pl[id], l1, r1);     if (r1 > mid && pr[id]) res += query(mid + 1, r, pr[id], l1, r1);     return res;   }   int main() {     scanf( %lf%lf%lf , &d, &s, &t);     d *= -1.0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &l, &r);       change(1, 0x3FFFFFFF, 1, l, r - 1);     }     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %lf%lf , &x, &y);       double ts = (y + d) / y;       double l1 = x + (s - x) / ts;       double r1 = x + (t - x) / ts;       int l2 = ceil(l1);       int r2 = floor(r1);       double ans = 0;       if (l2 == r2 + 1) {         if (query(1, 0x3FFFFFFF, 1, l2 - 1, l2 - 1)) ans = r1 - l1;       } else {         ans += query(1, 0x3FFFFFFF, 1, l2, r2 - 1);         if (query(1, 0x3FFFFFFF, 1, l2 - 1, l2 - 1)) ans += l2 * 1.0 - l1;         if (query(1, 0x3FFFFFFF, 1, r2, r2)) ans += r1 - r2 * 1.0;       }       ans *= ts;       printf( %.6lf n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   map<string, string> m;   int main() {     int n;     string j, x;     cin >> n;     while (n--) {       cin >> j >> x;       if (m.count(j) == 0)         m[x] = j;       else {         m[x] = m[j];         m.erase(j);       }     }     cout << m.size() << endl;     map<string, string>::iterator it;     for (it = m.begin(); it != m.end(); it++) {       cout << it->second <<     << it->first << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int cnt, lst, fa[N * 2], len[N * 2], ch[N * 2][26];   long long w[N * 2], ans;   int od[N * 2], rk[N * 2], l = 1;   char s[N];   void Init() { cnt = lst = 1; }   void Insert(int c) {     int p = lst, np = lst = ++cnt;     len[np] = len[p] + 1;     while (p && ch[p][c] == 0) ch[p][c] = np, p = fa[p];     if (!p)       fa[np] = 1;     else {       int q = ch[p][c], nq;       if (len[q] == len[p] + 1)         fa[np] = q;       else {         len[nq = ++cnt] = len[p] + 1;         fa[nq] = fa[q];         fa[q] = fa[np] = nq;         memcpy(ch[nq], ch[q], sizeof(ch[q]));         while (ch[p][c] == q) ch[p][c] = nq, p = fa[p];       }     }   }   int n;   int main() {     Init();     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s + l);       l += strlen(s + l);       s[l++] =  # ;     }     for (int i = 1, j = 0, x, p; i <= n; i++) {       lst = 1;       for (j += 1; s[j] !=  # ; j++) {         Insert(s[j] -  a );       }     }     for (int i = 1, j = 0, x, p; i <= n; i++) {       scanf( %d , &x);       for (p = 1, j += 1; s[j] !=  # ; j++) {         p = ch[p][s[j] -  a ];         w[p] += x;       }     }     for (int i = 1; i <= cnt; i++) rk[len[i]] += 1;     for (int i = 1; i <= cnt; i++) rk[i] += rk[i - 1];     for (int i = 1; i <= cnt; i++) od[rk[len[i]]--] = i;     for (int i = cnt; i >= 1; i--) w[fa[od[i]]] += w[od[i]];     for (int i = 2; i <= cnt; i++) ans = max(ans, len[i] * w[i]);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, m, ans;   vector<vector<int>> gh, used;   int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};   int dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};   bool onseg(double x1, double y1, double x2, double y2, double x, double y) {     double d1 = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));     double d2 = sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));     double d3 = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));     return abs(d3 - d2 - d1) < 1e-9;   }   void bfs(int y, int x) {     if (gh[y][x] == 0) return;     if (used[y][x]) return;     used[y][x] = true;     vector<pair<int, int>> todo, temp, bunch;     int cx, cy, nx, ny;     todo.push_back({y, x});     bunch.push_back({y, x});     while (true) {       if (todo.empty()) break;       for (int i = 0; i < todo.size(); i++) {         cy = todo[i].first, cx = todo[i].second;         for (int j = 0; j < 8; j++) {           ny = cy + dy[j];           nx = cx + dx[j];           if (ny >= 0 && ny < n && nx >= 0 && nx < m) {             if (used[ny][nx] == 0) {               temp.push_back({ny, nx});               bunch.push_back({ny, nx});               used[ny][nx] = 1;             }           }         }       }       todo = temp;       temp.clear();     }     if (bunch.size() % 4) return;     int len = bunch.size() / 4;     int topx, topy, btx, bty;     topx = bunch[0].second, topy = bunch[0].first;     btx = topx + len, bty = topy + len;     bool sq = true;     for (int j = 1; j < bunch.size(); j++) {       int nx = bunch[j].second, ny = bunch[j].first;       if (!onseg(topx, topy, btx, topy, nx, ny) &&           !onseg(topx, topy, topx, bty, nx, ny) &&           !onseg(btx, bty, btx, topy, nx, ny) &&           !onseg(btx, bty, topx, bty, nx, ny)) {         sq = false;         break;       }     }     if (sq) {       ans++;       return;     }     sq = true;     topx = bunch[0].second, topy = bunch[0].first;     btx = topx, bty = topy + 2 * len;     for (int j = 1; j < bunch.size(); j++) {       int nx = bunch[j].second, ny = bunch[j].first;       if (!onseg(topx, topy, topx - len, topy + len, nx, ny) &&           !onseg(topx, topy, topx + len, topy + len, nx, ny) &&           !onseg(btx, bty, topx - len, topy + len, nx, ny) &&           !onseg(btx, bty, topx + len, topy + len, nx, ny)) {         sq = false;         break;       }     }     if (sq) {       ans++;     }   }   void solve() {     cin >> n >> m;     gh = used = vector<vector<int>>(n, vector<int>(m));     ans = 0;     char ch;     int val;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> ch;         val = ch -  0 ;         if (val == 0) used[i][j] = 1;         gh[i][j] = val;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++)         if (used[i][j] == 0) bfs(i, j);     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2000;   int N;   int board[MAX_N][MAX_N];   int cur[MAX_N][MAX_N];   int row[MAX_N], col[MAX_N];   char buf[MAX_N + 10];   void pb(int arr[MAX_N][MAX_N]) {     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         printf( %d , arr[i][j]);       }       puts(  );     }   }   int solve() {     int ans = 0;     for (int i = N - 1; i > 0; i--) {       for (int j = 0; j < N - i; j++) {         int y = i + j, x = j;         cur[y][x] = row[y] ^ col[x];         if (cur[y][x] ^ board[y][x]) {           ans++;           cur[y][x] ^= 1;           row[y] ^= 1;           col[x] ^= 1;         }       }     }     for (int i = 0; i < N; i++) {       if (col[i] ^ row[i]) {         board[i][i] ^= 1;       }     }     memset(col, 0, sizeof(col));     memset(row, 0, sizeof(row));     for (int j = N - 1; j > 0; j--) {       for (int i = 0; i < N - j; i++) {         int y = i, x = j + i;         cur[y][x] = row[y] ^ col[x];         if (cur[y][x] ^ board[y][x]) {           ans++;           cur[y][x] ^= 1;           row[y] ^= 1;           col[x] ^= 1;         }       }     }     for (int i = 0; i < N; i++) {       if (row[i] ^ col[i] ^ board[i][i]) {         ans++;       }     }     return ans;   }   int main() {     scanf(  %d  , &N);     for (int i = 0; i < N; i++) {       scanf(  %s  , buf);       for (int j = 0; j < N; j++) {         board[i][j] = buf[j] & 1;       }     }     printf( %d n , solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e3 + 5;   const int P = 998244353;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   struct BinaryIndexTree {     int n, a[MAXN];     void init(int x) {       n = x;       memset(a, 0, sizeof(a));     }     void modify(int x, int d) {       for (int i = x; i <= n; i += i & -i) a[i] += d;     }     int query(int x) {       int ans = 0;       for (int i = x; i >= 1; i -= i & -i) ans += a[i];       return ans;     }     int query(int l, int r) {       int ans = 0;       for (int i = r; i >= 1; i -= i & -i) ans += a[i];       for (int i = l - 1; i >= 1; i -= i & -i) ans -= a[i];       return ans;     }   } BIT[3];   int n, a[MAXN][MAXN], dp[MAXN][MAXN], power[MAXN];   void update(int &x, int y) {     x += y;     if (x >= P) x -= P;   }   int main() {     read(n), dp[0][0] = 1;     for (int i = 1; i <= n; i++) {       dp[i][0] = 1ll * i * dp[i - 1][0] % P;       for (int j = 1; j <= i; j++)         dp[i][j] = (dp[i][j - 1] - dp[i - 1][j - 1] + P) % P;     }     power[0] = 1;     for (int i = 1; i <= n; i++) power[i] = 1ll * power[i - 1] * dp[n][n] % P;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) read(a[i][j]);     int ans = 0;     BIT[0].init(n);     for (int i = n; i >= 1; i--) {       BIT[0].modify(a[1][i], 1);       update(ans, 1ll * BIT[0].query(a[1][i] - 1) * dp[n - i][0] % P *                       power[n - 1] % P);     }     for (int i = 2; i <= n; i++) {       bool visa[MAXN], visb[MAXN];       memset(visa, 0, sizeof(visa));       memset(visb, 0, sizeof(visb));       BIT[0].init(n), BIT[1].init(n);       for (int j = n; j >= 1; j--) {         visb[a[i][j]] = true;         if (!visa[a[i][j]])           BIT[0].modify(a[i][j], 1);         else           BIT[1].modify(a[i][j], 1);         int cnt = BIT[1].query(n);         update(ans, 1ll * BIT[0].query(a[i][j] - 1) * dp[n - j][cnt] % P *                         power[n - i] % P);         if (cnt)           update(ans, 1ll * BIT[1].query(a[i][j] - 1) * dp[n - j][cnt - 1] % P *                           power[n - i] % P);         if (a[i][j] > a[i - 1][j] && visb[a[i - 1][j]]) {           if (visa[a[i - 1][j]])             update(ans, P - 1ll * dp[n - j][cnt - 1] * power[n - i] % P);           else             update(ans, P - 1ll * dp[n - j][cnt] * power[n - i] % P);         }         if (!visb[a[i - 1][j]])           visa[a[i - 1][j]] = true;         else {           visa[a[i - 1][j]] = true;           BIT[0].modify(a[i - 1][j], -1);           BIT[1].modify(a[i - 1][j], 1);         }       }     }     writeln(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, x;     cin >> n, x = n;     long long cnt = 0, d = n;     for (int i = 2; 1LL * i * i <= x; i++) {       if (x % i == 0) {         cnt++, d = i;         while (x % i == 0) x /= i;       }       if (cnt > 2) break;     }     if (x > 1) cnt++;     if (cnt <= 1)       cout << d;     else       cout << 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1E-8;   inline bool eq(double a, double b) { return a - b < EPS && b - a < EPS; }   inline bool ne(double a, double b) { return a + EPS < b || b + EPS < a; }   inline bool ls(double a, double b) { return a + EPS < b; }   inline bool gr(double a, double b) { return b + EPS < a; }   inline bool le(double a, double b) { return a - EPS < b; }   inline bool ge(double a, double b) { return b - EPS < a; }   int arr[1111][1111];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         scanf( %d , &arr[i][j]);       }     }     int sum = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         sum = (sum + arr[i][j] * arr[j][i]) & 1;       }     }     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int ctrl;       scanf( %d , &ctrl);       if (ctrl == 3)         putchar( 0  + sum);       else {         scanf( %d , &ctrl);         sum = 1 - sum;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline long long read() {     long long x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long a) {     if (a < 0) {       a = -a;       putchar( - );     }     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void wri(long long a) {     write(a);     putchar(   );   }   inline void writeln(long long a) {     write(a);     puts(  );   }   const int N = 1 << 17 | 2, mod = 998244353;   int sum, A[N], B[N], C[N], f[N];   long long ksm(long long a, int b) {     a %= mod;     int ans = 1;     for (; b; b >>= 1) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;     }     return ans;   }   void FWT(int *a, int n) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < (1 << n); j++)         if (j >> i & 1) {           int x = a[j];           a[j] = a[j ^ (1 << i)] >= x ? a[j ^ (1 << i)] - x                                       : a[j ^ (1 << i)] - x + mod;           a[j ^ (1 << i)] = a[j ^ (1 << i)] + x >= mod ? a[j ^ (1 << i)] + x - mod                                                        : a[j ^ (1 << i)] + x;         }     }   }   void ba(int &a) {     if (a > mod / 2) a = a - mod;   }   signed main() {     int n = read(), k = read();     int x = read(), y = read(), z = read();     for (int i = 0; i < n; i++) {       int a = read(), b = read() ^ a, c = read() ^ a;       sum ^= a;       A[b]++;       B[c]++;       C[b ^ c]++;     }     FWT(A, k);     FWT(B, k);     FWT(C, k);     for (int i = 0; i < (1 << k); i++) {       int t1 = n, t2 = A[i], t3 = B[i], t4 = C[i];       ba(t2);       ba(t3);       ba(t4);       f[i] = ksm((long long)x + y + z, (t1 + t2 + t3 + t4) / 4) *              ksm((long long)x + y - z, (t1 + t2 - t3 - t4) / 4) % mod *              ksm((long long)x - y + z, (t1 - t2 + t3 - t4) / 4) % mod *              ksm((long long)x - y - z, (t1 - t2 - t3 + t4) / 4) % mod;       f[i] = (f[i] + mod) % mod;     }     FWT(f, k);     long long in = ksm(1 << k, mod - 2);     for (int i = 0; i < (1 << k); i++) f[i] = f[i] * in % mod;     for (int i = 0; i < (1 << k); i++) {       wri(f[i ^ sum]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 28;   vector<int> g[N];   int vis[2000000];   int main() {     int k, n;     string ss, s;     cin >> k >> ss;     for (int i = 0; i < k; ++i) s += ss;     for (int i = 0; i != s.size(); ++i) g[s[i] -  a ].push_back(i);     cin >> n;     vector<int>::iterator it;     for (int i = 0; i < n; ++i) {       cin >> k >> ss;       it = g[ss[0] -  a ].begin();       g[ss[0] -  a ].erase(it + k - 1);     }     memset(vis, 0, sizeof(vis));     for (int i = 0; i < 26; ++i)       for (int j = 0; j < g[i].size(); ++j) vis[g[i][j]] = 1;     for (int i = 0; i != s.size(); ++i)       if (vis[i]) cout << s[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   int n, m;   int adj[N][N], d[N][N];   bool check(int a, int b) {     if (a >= 0 && a < n && b >= 0 && b < m && adj[a][b] != -1) return 1;     return 0;   }   void bfs(int x, int y) {     d[x][y] = 0;     queue<pair<int, int> > q;     q.push({x, y});     while (!q.empty()) {       int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};       pair<int, int> p = q.front();       q.pop();       for (int i = 0; i < 4; i++) {         int ii = dir[i][0] + p.first;         int jj = dir[i][1] + p.second;         if (check(ii, jj) && d[ii][jj] == -1) {           q.push({ii, jj});           d[ii][jj] = d[p.first][p.second] + 1;         }       }     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) d[i][j] = -1;     pair<int, int> e, s;     char c;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> c;         if (c ==  E ) {           e.first = i;           e.second = j;           adj[i][j] = 0;         } else if (c ==  S ) {           s.first = i;           s.second = j;           adj[i][j] = 0;         } else if (c ==  T )           adj[i][j] = -1;         else           adj[i][j] = (c -  0 );       }     }     bfs(e.first, e.second);     int len = d[s.first][s.second];     long long int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (d[i][j] != -1 && d[i][j] <= len) ans += adj[i][j];     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline string GetString() {     char S[1000005];     scanf( %s , S);     string ret = S;     return ret;   }   inline char getc() {     char c =    ;     while (c ==     || c ==   t  || c ==   r  || c ==   n ) c = getchar();     return c;   }   template <typename t>   t getnum() {     t res = 0;     char c;     int sign = 1;     while (1) {       c = getchar();       if (c ==     || c ==   n )         continue;       else         break;     }     if (c ==  + ) {     } else if (c ==  - )       sign = -1;     else       res = c -  0 ;     while (1) {       c = getchar();       if (c >=  0  && c <=  9 )         res = res * 10 + c -  0 ;       else         break;     }     return res * sign;   }   int main(int argc, char** argv) {     int n = getnum<int>();     int m = getnum<int>();     int i = getnum<int>();     int j = getnum<int>();     int a = getnum<int>();     int b = getnum<int>();     int satu = 10000000, dua = 10000000, tiga = 10000000, empat = 10000000;     if ((i - 1) % a == 0 && (j - 1) % b == 0) {       int x = (i - 1) / a, y = (j - 1) / b;       if (x % 2 == y % 2) satu = max(x, y);     }     if ((i - 1) % a == 0 && (m - j) % b == 0) {       int x = (i - 1) / a, y = (m - j) / b;       if (x % 2 == y % 2) dua = max(x, y);     }     if ((n - i) % a == 0 && (j - 1) % b == 0) {       int x = (n - i) / a, y = (j - 1) / b;       if (x % 2 == y % 2) tiga = max(x, y);     }     if ((n - i) % a == 0 && (m - j) % b == 0) {       int x = (n - i) / a, y = (m - j) / b;       if (x % 2 == y % 2) empat = max(x, y);     }     int ans = min(satu, min(dua, min(tiga, empat)));     if (ans != 0 && (a > n - 1 || b > m - 1)) ans = 10000000;     if (ans == 10000000)       puts( Poor Inna and pony! );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[1003][1003];   int n, m;   int dp[1003][1003];   int vis[1003][1003];   int dx[4] = {0, 1, 0, -1};   int dy[4] = {1, 0, -1, 0};   int dfs(int i, int j, int x) {     if (vis[i][j] == 2) {       printf( Poor Inna! n );       exit(0);     }     if (dp[i][j] != -1) return dp[i][j];     vis[i][j] = 2;     int temp2 = 0;     int temp3 = 0;     if (arr[i][j] == 3) temp3 = 1;     for (int k = 0; k < 4; k++) {       int ee = i + dx[k];       int rr = j + dy[k];       if (ee >= 0 & ee < n && rr >= 0 && rr < m && arr[ee][rr] == (x + 1) % 4) {         temp2 = max(temp2, dfs(ee, rr, (x + 1) % 4));       }     }     temp2 += temp3;     vis[i][j] = 1;     if (arr[i][j] == 0) dp[i][j] = temp2;     return temp2;   }   int main() {     char temp;     for (int i = 0; i < 1003; i++)       for (int j = 0; j < 1003; j++) {         dp[i][j] = -1;         vis[i][j] = 0;       }     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> temp;         if (temp ==  D ) arr[i][j] = 0;         if (temp ==  I ) arr[i][j] = 1;         if (temp ==  M ) arr[i][j] = 2;         if (temp ==  A ) arr[i][j] = 3;       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (arr[i][j] == 0 && vis[i][j] == 0) {           int temp1 = dfs(i, j, 0);         }       }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (ans < dp[i][j]) ans = dp[i][j];     if (ans == 0)       printf( Poor Dima! n );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ex, ey;   bool a[207][207];   bool vis[207][207];   int dx[4] = {0, 0, 1, -1};   int dy[4] = {-1, 1, 0, 0};   int bfs() {     queue<pair<int, int>> q;     vis[100][100] = true;     q.push(make_pair(100, 100));     int dep = 0;     while (int(q.size())) {       int size = int(q.size());       while (size--) {         pair<int, int> top = q.front();         q.pop();         vis[top.first][top.second] = true;         if (top.first == ex && top.second == ey) return dep;         for (int i = 0; i < int(4); i++) {           int nx = top.first + dx[i];           int ny = top.second + dy[i];           if (a[nx][ny] && !vis[nx][ny]) {             q.push(make_pair(nx, ny));           }         }       }       dep++;     }     return -1;   }   int main() {     string second;     cin >> second;     ex = ey = 100;     for (int i = 0; i < int(int(second.size())); i++) {       a[ex][ey] = true;       if (second[i] ==  R ) ex++;       if (second[i] ==  L ) ex--;       if (second[i] ==  U ) ey--;       if (second[i] ==  D ) ey++;       if (a[ex][ey]) {         puts( BUG );         return 0;       }     }     a[ex][ey] = true;     int ans = bfs();     ans < int(second.size()) ? puts( BUG ) : puts( OK );   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 513;   int N, ans[MAXN];   multiset<int> m;   int gcd(int a, int b) {     if (a < b) swap(a, b);     if (b == 0) return a;     return gcd(b, a % b);   }   void solve() {     for (int k = N; k >= 1; k--) {       ans[k] = -(*m.begin());       m.erase(m.find(-ans[k]));       for (int i = k + 1; i <= N; i++) {         m.erase(m.find(-gcd(ans[k], ans[i])));         m.erase(m.find(-gcd(ans[k], ans[i])));       }     }   }   int main() {     scanf( %d , &N);     int x;     for (int i = 1; i <= N * N; i++) {       scanf( %d , &x);       m.insert(-x);     }     solve();     for (int i = 1; i <= N; i++) printf( %d%c , ans[i],    n [i == N]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-6;   const long double pi = acos(-1.0);   int dx[] = {0, 1, 0, -1, 1, 1, -1, -1, 0},       dy[] = {1, 0, -1, 0, 1, -1, 1, -1, 0};   int aq[5][5];   int main() {     int n;     cin >> n;     for (int i = 0; i < (int)(n); ++i) {       int x, y;       cin >> x >> y;       aq[x - 1][y - 1] = aq[y - 1][x - 1] = 1;     }     int ap = 0, nap = 0;     for (int i = 0; i < (int)(5); ++i)       for (int j = 0; j < (int)(i); ++j)         for (int k = 0; k < (int)(j); ++k) {           if (aq[i][j] && aq[j][k] && aq[k][i]) ap = 1;           if (!aq[i][j] && !aq[j][k] && !aq[k][i]) nap = 1;         }     if (ap || nap)       cout <<  WIN  << endl;     else       cout <<  FAIL  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int64_t INF = 0x3f3f3f3f;   const int64_t INFLL = 0x3f3f3f3f3f3f3f3f;   const int64_t MOD = 1e9 + 7;   const double EPS = 1e-9;   const double PI = acos(-1);   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int64_t rand(int64_t x, int64_t y) {     return uniform_int_distribution<int64_t>(x, y)(rng);   }   int64_t mul(int64_t a, int64_t b) {     int64_t ret = (1ll * (a % MOD) * (b % MOD)) % MOD;     return (ret + MOD) % MOD;   }   int64_t add(int64_t a, int64_t b) {     int64_t ret = (1ll * (a % MOD) + (b % MOD)) % MOD;     return (ret + MOD) % MOD;   }   int64_t pow_exp(int64_t n, int64_t p) {     if (!p) return 1;     if (p & 1) return mul(n, pow_exp(n, p - 1));     int64_t tmp = pow_exp(n, p / 2);     return mul(tmp, tmp);   }   const int64_t MAX = 2e5 + 10;   const int64_t NMAX = 2e5 + 10;   const int64_t MMAX = 2e5 + 10;   const int64_t LOG_MAX = ceil(log2(double(NMAX)));   const int64_t BLOCK = ceil(sqrt(double(NMAX)));   int64_t n;   string str[20];   map<int64_t, vector<int64_t> > mp[20];   int64_t tot[20];   int64_t mem[1 << 20];   int64_t go(int64_t msk, int64_t sm) {     if (msk + 1 == 1 << n) {       return 0;     }     int64_t &ret = mem[msk];     if (ret + 1) return ret;     int64_t ans = 0;     for (int64_t i = 0; i < n; i++)       if (((msk >> i) & 1) == 0) {         int64_t mn = mp[i].begin()->first;         if (sm + mn >= 0) {           int64_t cans = 0;           cans += go(msk ^ (1 << i), sm + tot[i]);           auto it = mp[i].find(-sm);           if (it != mp[i].end()) cans += it->second.size();           ans = max(ans, cans);         } else {           auto it = mp[i].find(-sm);           if (it == mp[i].end()) {             continue;           }           if (it == mp[i].begin()) {             int64_t cans = it->second.size();             ans = max(ans, cans);           } else {             auto &v = mp[i][-sm];             int64_t r = (--it)->second.front();             int64_t cans = lower_bound(v.begin(), v.end(), r) - v.begin();             ans = max(ans, cans);           }         }       }     return ret = ans;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (int64_t i = 0; i < n; i++) {       cin >> str[i];     }     for (int64_t i = 0; i < n; i++) {       int64_t sm = 0;       for (int64_t j = 0; j < str[i].size(); j++) {         sm += str[i][j] ==  (  ? +1 : -1;         mp[i][sm].push_back(j);       }       tot[i] = sm;     }     memset(mem, -1, sizeof mem);     cout << go(0, 0) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const double inf = 1e10;   int n, m, q, Eu[N], Ev[N], all[N], vis[N];   vector<int> V;   map<pair<int, int>, int> F, S;   struct P {     double x, y;   } p[N];   inline P operator+(const P& a, const P& b) { return (P){a.x + b.x, a.y + b.y}; }   inline P operator-(const P& a, const P& b) { return (P){a.x - b.x, a.y - b.y}; }   inline double operator*(const P& a, const P& b) {     return a.x * b.y - b.x * a.y;   }   inline double operator/(const P& b, const P& a) {     return atan2(b.y - a.y, b.x - a.x);   }   inline bool operator<(const P& a, const P& b) {     return a.x != b.x ? a.x < b.x : a.y < b.y;   }   inline double crs(P p, P a, P b) { return (a - p) * (b - p); }   struct E {     int v;     double a;   };   inline bool operator<(const E& a, const E& b) { return a.a < b.a; }   vector<E> G[N];   inline void add(int u, int v) {     G[u].push_back((E){v, p[v] / p[u]});     F[make_pair(u, v)] = 0;   }   int dfs(int x, int p) {     vis[x] = 1;     int s = 1;     for (int i = 0; i < G[x].size(); i++) {       int y = G[x][i].v;       if (!vis[y]) s += dfs(y, x);     }     if (p) {       F[make_pair(p, x)] += s;       F[make_pair(x, p)] -= s;     }     return s;   }   inline int calc(int a, int b, int c) {     return ((p[b] / p[a]) < (p[c] / p[a]) ? 0 : all[a]) + S[make_pair(a, c)] -            S[make_pair(a, b)] - F[make_pair(a, c)];   }   int main() {     scanf( %d%d , &n, &m);     int T = n + 1;     p[T] = (P){-inf, 0};     for (int i = 1; i <= m; i++) scanf( %d%d , &Eu[i], &Ev[i]);     for (int i = 1; i <= n; i++) scanf( %lf%lf , &p[i].x, &p[i].y);     for (int i = 1; i <= m; i++) add(Eu[i], Ev[i]), add(Ev[i], Eu[i]);     int x = 1;     for (int i = 2; i <= n; i++)       if (p[i] < p[x]) x = i;     add(T, x);     add(x, T);     dfs(T, 0);     for (int i = 1; i <= n + 1; i++) sort(G[i].begin(), G[i].end());     for (int i = 1; i <= n + 1; i++) {       int x = i;       S[make_pair(i, i)] = 0;       for (int j = 0; j < G[i].size(); j++) {         int y = G[i][j].v;         all[i] += F[make_pair(i, y)];         S[make_pair(i, y)] = S[make_pair(i, x)] + F[make_pair(i, y)];         x = y;       }     }     scanf( %d , &q);     while (q--) {       int k;       scanf( %d , &k);       V.clear();       for (int i = 1, x; i <= k; i++) scanf( %d , &x), V.push_back(x);       int ans = 0, cc = V.size();       double s = 0;       p[0] = (P){0, 0};       for (int i = 0; i < cc; i++)         s += crs(p[0], p[V[i ? i - 1 : cc - 1]], p[V[i]]);       if (s > 0) reverse(V.begin(), V.end());       for (int i = 0; i < cc; i++)         ans += calc(V[i], V[i ? i - 1 : cc - 1], V[(i + 1) % cc]);       printf( %d n , ans + cc);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b, c, d, flag = 0;     scanf( %d %d %d %d , &a, &b, &c, &d);     if (a + b > c && b + c > a && c + a > b)       flag = 1;     else if (b + c > d && c + d > b && d + b > c)       flag = 1;     else if (c + d > a && d + a > c && a + c > d)       flag = 1;     else if (a + b > d && b + d > a && d + a > b)       flag = 1;     if (flag == 1)       printf( TRIANGLE );     else {       if (a + b == c || b + c == a || c + a == b)         flag = 2;       else if (b + c == d || c + d == b || d + b == c)         flag = 2;       else if (c + d == a || d + a == c || a + c == d)         flag = 2;       else if (a + b == d || b + d == a || d + a == b)         flag = 2;     }     if (flag == 2)       printf( SEGMENT );     else if (flag == 0)       printf( IMPOSSIBLE );   }


#include <bits/stdc++.h>   const int MAXN = 1000;   int ba[MAXN], bb[MAXN];   int a, b, da, db, t, x, l1, l2;   int main() {     scanf( %d %d %d %d %d %d , &x, &t, &a, &b, &da, &db);     int tm = 0;     while (a >= 0) {       ba[l1++] = a;       a -= da;       tm++;       if (tm >= t) break;     }     tm = 0;     while (b >= 0) {       bb[l2++] = b;       b -= db;       tm++;       if (tm >= t) break;     }     for (int i = 0; i < l1; i++)       if (ba[i] == x) {         printf( YES n );         return 0;       }     if (x == 0) {       printf( YES n );       return 0;     }     for (int i = 0; i < l2; i++)       if (bb[i] == x) {         printf( YES n );         return 0;       }     for (int i = 0; i < l1; i++)       for (int j = 0; j < l2; j++)         if (ba[i] + bb[j] == x) {           printf( YES n );           return 0;         }     printf( NO n );     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Item {     int id, t, d, p;     Item(int _id = 0, int _t = 0, int _d = 0, int _p = 0)         : id(_id), t(_t), d(_d), p(_p) {}     bool operator<(const Item &rhs) const { return d < rhs.d; }   };   constexpr int kN = 101, kT = 2001;   Item a[kN];   int dp[kN][kT];   int tk[kN][kT];   int main() {     int n;     scanf( %d , &n);     int t, d, p;     for (int i = 0; i < n; ++i) {       scanf( %d %d %d , &t, &d, &p);       a[i] = Item(i + 1, t, d, p);     }     sort(a, a + n);     for (int i = 0; i < n; ++i) {       for (int j = 0; j + a[i].t < a[i].d; ++j) {         if (dp[i][j] + a[i].p > dp[i + 1][j + a[i].t]) {           dp[i + 1][j + a[i].t] = dp[i][j] + a[i].p;           tk[i + 1][j + a[i].t] = 1;         }       }       for (int j = 0; j < kT; ++j) {         if (dp[i][j] > dp[i + 1][j]) {           dp[i + 1][j] = dp[i][j];           tk[i + 1][j] = 0;         }       }     }     int x = 0;     for (int i = 0; i < a[n - 1].d; ++i) {       if (dp[n][i] > dp[n][x]) {         x = i;       }     }     printf( %d n , dp[n][x]);     vector<int> ans;     for (int i = n; i > 0; --i) {       if (tk[i][x]) {         ans.push_back(a[i - 1].id);         x -= a[i - 1].t;       }     }     reverse(ans.begin(), ans.end());     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); ++i) {       printf( %d  , ans[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     set<int> s;     while (1) {       int k = s.size();       s.insert(n);       int m = s.size();       if (k == m) break;       n = n + 1;       while (n % 10 == 0) {         n = n / 10;       }     }     cout << s.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     return a.first > b.first;   }   long long findBest(vector<pair<long long, long long> >& ps, long long x) {     long long res = 0;     for (long long i = 0; i < ps.size(); i++) {       long long num = ps[i].second;       long long diff = ps[i].first;       if (x - num >= 0) {         res += (num * diff);         x -= num;       } else {         res += (x * diff);         break;       }     }     return res;   }   int main() {     long long n, s;     cin >> n >> s;     vector<pair<long long, long long> > ps;     long long total = 0;     long long positives = 0;     long long pieces = 0;     for (long long i = 0; i < n; i++) {       long long num, a, b;       cin >> num >> a >> b;       ps.push_back(make_pair(a - b, num));       total += num * b;       pieces += num;       if (a - b > 0) {         positives += num;       }     }     sort(ps.begin(), ps.end(), comp);     long long pizzas = (pieces % s == 0) ? (pieces / s) : (pieces / s + 1);     long long extra = pizzas * s - pieces;     long long best = total;     if (positives > 0) {       best = max(best, findBest(ps, positives / s * s) + total);       if (positives % s != 0) {         long long x = max(positives, (positives / s + 1) * s - extra);         best = max(best, findBest(ps, x) + total);       }     }     cout << best << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int i;     int num;   } a[1005];   bool cmp(node x, node y) { return x.num < y.num; }   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, m;       scanf( %d %d , &n, &m);       int i, j;       int ans = 0;       for (i = 1; i <= n; i++) {         scanf( %d , &a[i].num);         a[i].i = i;         ans += a[i].num;       }       if (m < n || n <= 2) {         printf( -1 n );         continue;       }       ans *= 2;       sort(a + 1, a + 1 + n, cmp);       int num = a[1].num + a[2].num;       ans += (m - n) * num;       printf( %d n , ans);       for (i = 2; i <= n; i++) {         printf( %d %d n , i - 1, i);       }       printf( 1 %d n , n);       for (i = 0; i < (m - n); i++) {         if (a[1].i > a[2].i)           printf( %d %d n , a[2].i, a[1].i);         else           printf( %d %d n , a[1].i, a[2].i);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 + 7, MAX_SUM = 10 * 1000 + 7,             DELTA = 1000 * 1000 * 1000 + 7;   long long inputArray[MAXN], numberOfSubarrays[MAXN][2 * MAX_SUM], PSum;   int main() {     int numberOfInput;     cin >> numberOfInput;     for (int i = 0; i < numberOfInput; ++i) {       cin >> inputArray[i];       PSum += inputArray[i];     }     numberOfSubarrays[0][MAX_SUM + inputArray[0]] =         numberOfSubarrays[0][MAX_SUM - inputArray[0]] = 1;     for (int i = 1; i < numberOfInput; ++i) {       for (int j = 0; j < 2 * MAX_SUM; ++j) {         numberOfSubarrays[i][j] += numberOfSubarrays[i - 1][j - inputArray[i]];       }       for (int j = 2 * MAX_SUM - 1; j >= 0; --j) {         numberOfSubarrays[i][j] += numberOfSubarrays[i - 1][j + inputArray[i]];         numberOfSubarrays[i][j] %= DELTA;       }       numberOfSubarrays[i][MAX_SUM + inputArray[i]] =           numberOfSubarrays[i][MAX_SUM + inputArray[i]] + 1;       numberOfSubarrays[i][MAX_SUM - inputArray[i]] =           numberOfSubarrays[i][MAX_SUM - inputArray[i]] + 1;     }     long long ans = 0;     for (int i = 0; i < numberOfInput; ++i) {       ans += numberOfSubarrays[i][MAX_SUM];       ans %= DELTA;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   struct heap {     vector<pair<int, int> > v;     int loc[N];     heap() {       v.push_back(make_pair(-1, -1));       memset(loc, -1, sizeof loc);     }     void push(pair<int, int> p) {       int cur;       cur = v.size();       loc[p.second] = cur;       v.push_back(p);       while (v[cur] < v[cur >> 1]) {         swap(v[cur], v[cur >> 1]);         swap(loc[v[cur].second], loc[v[cur >> 1].second]);         cur >>= 1;       }     }     void pop() {       if (empty()) return;       swap(v[1], v.back());       loc[v[1].second] = 1;       loc[v.back().second] = -1;       v.pop_back();       int cur = 1;       while ((cur << 1) < v.size()) {         if ((cur << 1) + 1 == v.size()) {           if (v[cur] > v[cur << 1])             swap(v[cur], v[cur << 1]),                 swap(loc[v[cur].second], loc[v[cur << 1].second]);           break;         }         if (v[cur] < min(v[cur << 1], v[(cur << 1) + 1])) break;         if (v[cur << 1] < v[(cur << 1) + 1]) {           swap(v[cur], v[cur << 1]);           swap(loc[v[cur].second], loc[v[cur << 1].second]);           cur <<= 1;         } else {           swap(v[cur], v[(cur << 1) + 1]);           swap(loc[v[cur].second], loc[v[(cur << 1) + 1].second]);           cur = (cur << 1) + 1;         }       }     }     pair<int, int> top() { return v[1]; }     bool empty() { return v.size() == 1; }   };   int n, m;   vector<int> bad[N];   vector<pair<int, int> > v[N];   int d[N];   heap pq;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       --a, --b;       v[a].push_back(make_pair(b, c));       v[b].push_back(make_pair(a, c));     }     for (int i = 0; i < n; i++) {       int num;       cin >> num;       while (num--) {         int a;         cin >> a;         bad[i].push_back(a);       }     }     for (int i = 0; i < n; i++) d[i] = 0x3f3f3f3f;     d[0] = 0;     pq.push(make_pair(0, 0));     while (!pq.empty()) {       pair<int, int> tp = pq.top();       pq.pop();       int t = tp.first;       int cur = tp.second;       if (t != d[cur]) continue;       int j = 0;       while (j < bad[cur].size() && bad[cur][j] < t) j++;       while (j < bad[cur].size() && bad[cur][j] == t) t++, j++;       for (int i = 0; i < v[cur].size(); i++) {         int to = v[cur][i].first, cost = v[cur][i].second;         if (t + cost < d[to]) {           d[to] = t + cost;           pq.push(make_pair(d[to], to));         }       }     }     if (d[n - 1] >= 0x3f3f3f3f)       puts( -1 );     else       cout << d[n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1111;   const int INF = 0x7f7f7f7f;   int cases;   const double EPS = 1e-8;   inline int sgn(double a) { return a < -EPS ? -1 : a > EPS; }   int main() {     double s, a, b, c;     cin >> s >> a >> b >> c;     if (!sgn(a) && !sgn(b) && !sgn(c)) {       puts( 1.0 0.0 0.0 );     } else {       double ts = s / (a + b + c);       printf( %.10f %.10f %.10f n , a * ts, b * ts, c * ts);     }   }