#include <bits/stdc++.h>   using namespace std;   vector<vector<int64_t>> board, vis, diag1, diag2;   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     int64_t n;     cin >> n;     for (int64_t i = 0; i < n; i++) {       vector<int64_t> temp;       vector<int64_t> zero;       for (int64_t j = 0; j < n; j++) {         int64_t t;         cin >> t;         temp.push_back(t);         zero.push_back(0);       }       board.push_back(temp);       vis.push_back(zero);       diag1.push_back(zero);       diag2.push_back(zero);     }     for (int64_t i = 0; i < n; i++) {       for (int64_t j = 0; j < n; j++) {         if (vis[i][j]) continue;         int64_t t1 = i, t2 = j, s = 0;         while (1) {           vis[t1][t2] = 1;           s += board[t1][t2];           t1 -= -1;           t2 -= -1;           if (t1 >= n || t2 >= n) break;         }         t1 = i, t2 = j;         while (1) {           diag1[t1][t2] = s;           t1 -= -1;           t2 -= -1;           if (t1 >= n || t2 >= n) break;         }       }     }     for (int64_t i = 0; i < n; i++)       for (int64_t j = 0; j < n; j++) vis[i][j] = 0;     for (int64_t i = 0; i < n; i++) {       for (int64_t j = 0; j < n; j++) {         if (vis[i][j]) continue;         int64_t t1 = i, t2 = j, s = 0;         while (1) {           vis[t1][t2] = 1;           s += board[t1][t2];           t1 -= -1;           t2 += -1;           if (t1 >= n || t2 < 0) break;         }         t1 = i, t2 = j;         while (1) {           diag2[t1][t2] = s;           t1 -= -1;           t2 += -1;           if (t1 >= n || t2 < 0) break;         }       }     }     int64_t m1 = 0, m2 = 0, x1 = 0, x2 = 0, y1 = 0, y2 = 0;     for (int64_t i = 0; i < n; i++) {       for (int64_t j = 0; j < n; j++) {         int64_t tmp = diag1[i][j] + diag2[i][j] - board[i][j];         if ((i + j) % 2) {           if (tmp >= m1) {             m1 = tmp;             x1 = i + 1;             y1 = j + 1;           }         } else {           if (tmp >= m2) {             m2 = tmp;             x2 = i + 1;             y2 = j + 1;           }         }       }     }     cout << m1 + m2 << endl;     cout << x1 <<     << y1 <<     << x2 <<     << y2;   }


#include <bits/stdc++.h>   using namespace std;   void boost() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   void free() {     freopen( A.in ,  r , stdin);     freopen( A.out ,  w , stdout);   }   int a[100001];   int main() {     boost();     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     long long ans = 1, h = a[0];     ans += h;     for (int i = 1; i < n; i++) {       if (a[i] >= h)         ans += (a[i] - h + 1), h = a[i];       else if (a[i] < h)         ans += (h - a[i] + 1), h = a[i];       ans++;     }     cout << ans, exit(0);   }


#include <bits/stdc++.h>   using namespace std;   inline void read(long long &num) {     num = 0;     long long f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       num = num * 10 + c - 48;       c = getchar();     }     num *= f;   }   const long long maxn = 1e5 + 7;   long long n, a[maxn], al, t;   signed main() {     read(n);     al = 0;     for (long long i = 1; i <= n; ++i) read(a[i]), al ^= a[i];     if (!(n & 1) && al) {       puts( NO );       return 0;     }     if (!(n & 1)) --n;     puts( YES );     cout << n - 1 << endl;     for (long long i = 1; i <= n - 2; i += 2)       cout << i <<     << i + 1 <<     << i + 2 << endl;     for (long long i = 1; i <= n - 2; i += 2)       cout << i <<     << i + 1 <<     << n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1000000007;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int l = 1, h, i, n, x, t, q, y = -1, z = 0, a = 0, b = 0, c = 0, k,                   sum = 0, m, d = 0, r, w, j, ans, s, mini = INT_MAX,                   maxi = INT_MIN;     bool cou;     float kl;     long long int count = 0;     t = 1;     vector<bool> sie(1000001, 0);     char cg;     string str, std;     a = 1;     while (t--) {       cin >> n >> m;       vector<int> vec(n);       map<int, bool> mp;       for (i = 0; i < n; ++i) cin >> vec[i];       for (i = 0; i < m; ++i) {         cin >> x;         mp[x] = 1;       }       for (i = 0; i < n; ++i) {         if (mp[vec[i]]) cout << vec[i] <<    ;       }     }   }


#include <bits/stdc++.h>   #include<stdlib.h>   using namespace std;   #define pb push_back   #define ll long long   #define ff first   #define ss second   #define ppb pop_back   #define mp make_pair   #define vl vector<ll>   #define vi vector<int>   #define endl   n    #define all(x) x.begin(), x.end()   #define deb(x) cout << #x <<     << x << endl;   #define f(i, n) for(i=0; i<n; i++)   #define F(i, k, n) for(i=k; i<n; i++)   #define max(a,b) (a<b?b:a)   #define min(a,b) (a>b?b:a)   #define INF 1001001001   #define PI 3.1415926535897932384626   #define MOD 1000000007      void FAST() {     ios::sync_with_stdio(0);    cin.tie(0);    cout.tie(0);   }      // template<typename... T>   // void read(T&... args) {   //  FAST();   //  ((cin >> args), ...);   // }      // template<typename... T>   // void write(T&&... args) {    //  FAST();   //  ((cout << args <<    ), ...);   // }      // template<typename T>   // T gcd(T a, T b) {   //     if (b == 0)    //         return a;    //     return gcd(b, a % b);     // }       // template <typename T>   // void printContainer(T &v){   //     for(auto i : v){   //         cout<<i<<   ;    //     }   //     cout <<endl;   // }      int main() {    FAST();    //code       ll t;       cin>>t;       ll p;       f(p,t){           string s;           cin>>s;           ll i, a1=0, x1=0, x2=0, a2=0,b1=0,b2=0;           f(i,s.size()){               if(s[i]== ( ){                   a1++;                   x1++;               }               else if(s[i]== )  && x1>0){                   a2++;                   x1--;               }               else if(s[i]== [ ){                   b1++;                   x2++;               }               else if(s[i]== ]  && x2>0){                   b2++;                   x2--;               }           }           cout<<min(a1,a2)+min(b1,b2)<<endl;              }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long N = 1e5 + 5;   map<long long, long long> freq, freq2;   void func1(long long a[], long long n) {     int i = 0, j = 0;     while (i < n) {       if (a[i] == 0) {         i++;         continue;       }       j = i;       while (j < n && a[j] != 0) {         j++;       }       for (int p = 1; p <= (j - i); p++) {         freq[p] += (j - i) - p + 1;       }       i = j;     }   }   void func2(long long a[], long long n) {     int i = 0, j = 0;     while (i < n) {       if (a[i] == 0) {         i++;         continue;       }       j = i;       while (j < n && a[j] != 0) {         j++;       }       for (int p = 1; p <= (j - i); p++) {         freq2[p] += (j - i) - p + 1;       }       i = j;     }   }   int main() {     long long n, a[N], b[N], r = 0, c = 0, ans = 0, cnt = 0, sum = 0, k, m;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     func1(a, n);     func2(b, m);     for (int p = 1; p <= sqrt(k); p++) {       if (k % p == 0) {         ans += freq[p] * freq2[k / p];         if (p != (k / p)) ans += freq[k / p] * freq2[p];       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   const long long intmax = 2147483647;   const long long intmin = -2147483648;   const long long mod2 = 998244353;   const long long mod = 1e9 + 7;   const long long N = 3e5;   long long fact[N];   long long add(long long a, long long b, long long p = mod) {     long long res = (a % p + b % p) % p;     return res;   }   long long sub(long long a, long long b, long long p = mod) {     long long res = (a % p - b % p + p) % p;     return res;   }   long long mul(long long a, long long b, long long p = mod) {     long long res = ((a % p) * (b % p)) % p;     return res;   }   void factorial(long long n, long long p = mod) {     fact[0] = 1;     for (long long i = 1; i < n; i++) {       fact[i] = mul(i, fact[i - 1], p);     }   }   long long binExp(long long x, long long y, long long p = mod) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long modInv(long long i, long long p = mod) { return binExp(i, p - 2, p); }   long long ncr(long long n, long long r, long long p = mod) {     if (n < r) return 0;     if (r == 0) return 1;     return (fact[n] * modInv(fact[r], p) % p * modInv(fact[n - r], p) % p) % p;   }   long long divi(long long a, long long b, long long p = mod) {     long long binv = modInv(b, p);     long long res = ((a % p) * (binv % p)) % p;     return res;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (auto &i : v) in >> i;     return in;   }   template <typename T>   ostream &operator<<(ostream &ost, vector<T> v) {     if (&ost == &cerr) {       cerr <<  { ;       long long cnt = v.size();       for (auto x : v) {         cerr << x;         cnt--;         if (cnt) cerr <<  ,  ;       }       cerr <<  } ;     } else       for (auto i : v) ost << i <<    ;     return ost;   }   template <typename T>   ostream &operator<<(ostream &ost, set<T> s) {     if (&ost == &cerr) {       cerr <<  { ;       long long cnt = s.size();       for (auto x : s) {         cerr << x;         cnt--;         if (cnt) cerr <<  ,  ;       }       cerr <<  } ;     } else       for (auto i : s) ost << i <<    ;     return ost;   }   template <typename U, typename V>   ostream &operator<<(ostream &ost, map<U, V> &m) {     if (&ost == &cerr) {       cerr <<  { ;       long long cnt = m.size();       for (auto x : m) {         cerr << x;         cnt--;         if (cnt) cerr <<  ,  ;       }       cerr <<  } ;     } else       for (auto i : m) ost << i;     return ost;   }   template <typename U, typename V>   istream &operator>>(istream &in, pair<U, V> &p) {     in >> p.first >> p.second;     return in;   }   template <typename U, typename V>   ostream &operator<<(ostream &ost, pair<U, V> p) {     if (&ost == &cerr)       ost <<  {  << p.first <<  :   << p.second <<  } ;     else       ost << p.first <<     << p.second <<    ;     return ost;   }   template <typename... T>   void read(T &...args) {     ((cin >> args), ...);   }   template <typename... T>   void print(T... args) {     ((cout << args <<    ), ...);     cout <<   n ;   }   void solution() {     long long ans = -1;     long long n, m;     read(n, m);     ;     vector<long long> x(n);     cin >> x;     vector<vector<long long> > a(n, vector<long long>(m));     for (long long i = 0; 0 <= n ? i < n : i >= n; 0 < n ? i += 1 : i -= 1)       for (long long j = 0; 0 <= m ? j < m : j >= m; 0 < m ? j += 1 : j -= 1) {         scanf( %1d , &a[i][j]);       }     vector<long long> best;     for (long long mask = 0; 0 <= 1 << n ? mask < 1 << n : mask >= 1 << n;          0 < 1 << n ? mask += 1 : mask -= 1) {       vector<long long> val(m);       for (long long i = 0; 0 <= n ? i < n : i >= n; 0 < n ? i += 1 : i -= 1) {         for (long long j = 0; 0 <= m ? j < m : j >= m; 0 < m ? j += 1 : j -= 1) {           if (a[i][j]) {             val[j] += ((mask >> i) & 1) ? +1 : -1;           }         }       }       vector<long long> p(m);       iota(p.begin(), p.end(), 0LL);       long long res = 0;       for (long long i = 0; 0 <= n ? i < n : i >= n; 0 < n ? i += 1 : i -= 1)         res += ((mask >> i) & 1) ? -x[i] : x[i];       sort(p.begin(), p.end(),            [&](long long a, long long b) { return val[a] < val[b]; });       for (long long i = 0; 0 <= m ? i < m : i >= m; 0 < m ? i += 1 : i -= 1) {         res += val[p[i]] * (i + 1);       }       if (res > ans) ans = res, best = p;     }     vector<long long> ansPerm(m);     for (long long i = 0; 0 <= m ? i < m : i >= m; 0 < m ? i += 1 : i -= 1)       ansPerm[best[i]] = i + 1;     cout << ansPerm <<   n ;   }   signed main() {     long long test = 1;     cin >> test;     for (long long t = 1; t <= test; t++) {       solution();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a, x, b, y;     cin >> n >> a >> x >> b >> y;     while (a != x && b != y) {       if (a == b) break;       a = (a % n) + 1;       if (b == 1)         b = n;       else         b--;     }     if (a == b)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   const int mod = 1e9 + 7;   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0)       if (b & 1) {         res = (long long)(res * 1ll * a);         --b;       } else {         a = (long long)(a * 1ll * a);         b >>= 1;       }     return (long long)res;   }   vector<vector<int>> g;   vector<bool> used;   int pred = -1;   int timer = 0;   vector<int> tin, tout;   void dfs(int v, int p = -1) {     used[v] = true;     tin[v] = timer;     timer++;     for (auto to : g[v]) {       if (!used[to]) dfs(to);     }     tout[v] = timer;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     cin >> q;     while (q--) {       int n, a, b, da, db;       cin >> n >> a >> b >> da >> db;       vector<vector<int>> g;       g.resize(n);       for (int i = 0; i < n - 1; i++) {         int u, v;         cin >> u >> v;         u--;         v--;         g[u].push_back(v);         g[v].push_back(u);       }       if (da * 2 >= db) {         cout <<  Alice  << endl;         continue;       }       int starta = a - 1;       int startb = b - 1;       vector<bool> used(n);       queue<int> q;       used[starta] = true;       q.push(starta);       vector<int> d(n);       while (!q.empty()) {         int v = q.front();         q.pop();         for (auto to : g[v]) {           if (!used[to]) {             used[to] = true;             q.push(to);             d[to] = d[v] + 1;           }         }       }       int ind_max = 0;       int maxi = 0;       for (int i = 0; i < n; i++) {         if (d[i] > maxi) {           maxi = d[i];           ind_max = i;         }       }       if (abs(d[startb]) <= da) {         cout <<  Alice  << endl;         continue;       }       used.clear();       used.resize(n);       used[ind_max] = true;       q.push(ind_max);       d.clear();       d.resize(n);       while (!q.empty()) {         int v = q.front();         q.pop();         for (auto to : g[v]) {           if (!used[to]) {             used[to] = true;             q.push(to);             d[to] = d[v] + 1;           }         }       }       int ans = 0;       for (int i = 0; i < n; i++) {         ans = max(ans, d[i]);       }       if (double(ans) / da > 2.0) {         cout <<  Bob  << endl;       } else {         cout <<  Alice  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans % m;   }   using namespace std;   bool B[100], G[100];   int main() {     int n, m;     cin >> n >> m;     int b;     cin >> b;     for (int(i) = (0); (i) < (b); (i)++) {       int first;       cin >> first;       B[first] = 1;     }     int g;     cin >> g;     for (int(i) = (0); (i) < (g); (i)++) {       int first;       cin >> first;       G[first] = 1;     }     for (int(i) = (0); (i) < (10000000); (i)++)       B[i % n] = G[i % m] = B[i % n] | G[i % m];     bool boys = 1, girls = 1;     for (int(i) = (0); (i) < (n); (i)++) boys &= B[i];     for (int(i) = (0); (i) < (m); (i)++) girls &= G[i];     if (boys && girls)       cout <<  Yes  <<   n ;     else       cout <<  No  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, lim;   struct node {     int to;     int val;   };   stack<int> ans;   vector<node> g[5500];   int f[5500][5500];   int fa[5500][5500];   void dfs(int u, int dep) {     for (int i = 0; i != g[u].size(); i++) {       int& co = g[u][i].val;       int& v = g[u][i].to;       if (f[dep][u] + co <= lim && f[dep][u] + co < f[dep + 1][v]) {         fa[v][dep] = u;         f[dep + 1][v] = f[dep][u] + co;         dfs(v, dep + 1);       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &lim);     int t1, t2, t3;     for (int i = 0; i != m; i++) {       scanf( %d%d%d , &t1, &t2, &t3);       g[t1].push_back(node{t2, t3});     }     memset(f, 0x7f, sizeof(f));     f[1][1] = 0;     dfs(1, 1);     int i = n;     while (!fa[n][i]) i--;     cout << i + 1 << endl;     ans.push(n);     while (fa[n][i]) {       ans.push(fa[n][i]);       n = fa[n][i];       i--;     }     cout << ans.top();     ans.pop();     while (!ans.empty()) {       cout <<     << ans.top();       ans.pop();     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long LINF = 334ll << 53;   const int INF = 15 << 26;   const long long MOD = 1E9 + 7;   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int n, q;     cin >> n >> q;     vector<int> t(n), s(n), d(n);     priority_queue<pair<int, int>, vector<pair<int, int>>,                    greater<pair<int, int>>>         used;     priority_queue<int, vector<int>, greater<int>> aval;     for (int(i) = 0; (i) < (n); ++(i)) aval.push(i + 1);     for (int(i) = 0; (i) < (q); ++(i)) {       int now, s, t, ans = 0;       cin >> now >> s >> t;       while (!used.empty()) {         if (used.top().first > now) break;         aval.push(used.top().second);         used.pop();       }       if (aval.size() < s) {         cout << -1 << endl;       } else {         for (int(j) = 0; (j) < (s); ++(j)) {           ans += aval.top();           used.push(make_pair(now + t, aval.top()));           aval.pop();         }         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   using ll = long long;   using ld = long double;   template <typename T>   using mat = vector<vector<T> >;   template <int mod>   struct modint {     int x;     modint() : x(0) {}     modint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}     modint &operator+=(const modint &p) {       if ((x += p.x) >= mod) x -= mod;       return *this;     }     modint &operator-=(const modint &p) {       if ((x += mod - p.x) >= mod) x -= mod;       return *this;     }     modint &operator*=(const modint &p) {       x = (int)(1LL * x * p.x % mod);       return *this;     }     modint &operator/=(const modint &p) {       *this *= p.inverse();       return *this;     }     modint operator-() const { return modint(-x); }     modint operator+(const modint &p) const { return modint(*this) += p; }     modint operator-(const modint &p) const { return modint(*this) -= p; }     modint operator*(const modint &p) const { return modint(*this) *= p; }     modint operator/(const modint &p) const { return modint(*this) /= p; }     bool operator==(const modint &p) const { return x == p.x; }     bool operator!=(const modint &p) const { return x != p.x; }     modint inverse() const {       int a = x, b = mod, u = 1, v = 0, t;       while (b > 0) {         t = a / b;         swap(a -= t * b, b);         swap(u -= t * v, v);       }       return modint(u);     }     modint pow(int64_t n) const {       modint ret(1), mul(x);       while (n > 0) {         if (n & 1) ret *= mul;         mul *= mul;         n >>= 1;       }       return ret;     }     friend ostream &operator<<(ostream &os, const modint &p) { return os << p.x; }     friend istream &operator>>(istream &is, modint &a) {       int64_t t;       is >> t;       a = modint<mod>(t);       return (is);     }     static int get_mod() { return mod; }   };   ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }   ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T &a, const T &b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   template <typename T>   T mypow(T x, ll n) {     T ret = 1;     while (n > 0) {       if (n & 1) (ret *= x);       (x *= x);       n >>= 1;     }     return ret;   }   ll modpow(ll x, ll n, const ll mod) {     ll ret = 1;     while (n > 0) {       if (n & 1) (ret *= x);       (x *= x);       n >>= 1;       x %= mod;       ret %= mod;     }     return ret;   }   uint64_t my_rand(void) {     static uint64_t x = 88172645463325252ULL;     x = x ^ (x << 13);     x = x ^ (x >> 7);     return x = x ^ (x << 17);   }   template <typename T>   struct edge {     int src, to;     T cost;     edge(int to, T cost) : src(-1), to(to), cost(cost) {}     edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}     edge &operator=(const int &x) {       to = x;       return *this;     }     operator int() const { return to; }   };   template <typename T>   using Edges = vector<edge<T> >;   template <typename T>   using WeightedGraph = vector<Edges<T> >;   using UnWeightedGraph = vector<vector<int> >;   const long double eps = 0.001;   const long double PI = 3.141592653589793;   void solve() {     ll x, y;     cin >> x >> y;     if (x > y) swap(x, y);     ll a, b;     cin >> a >> b;     if (a * 2 > b) {       cout << x * b + (y - x) * a << endl;     } else {       cout << (x + y) * a << endl;     }   }   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     cout << setprecision(20);     int t;     cin >> t;     for (int _ = (0), max_i = (t); _ < max_i; _++) {       solve();     }   }


#include <bits/stdc++.h>   const int mod = 998244353;   using namespace std;   inline int read() {     int f = 1, x = 0;     char s = getchar();     while (!isdigit(s)) {       if (s ==  - ) f = -1;       s = getchar();     }     while (isdigit(s)) {       x = (x << 1) + (x << 3) + (s ^ 48), s = getchar();     }     return x * f;   }   int n, a[500100], is[500100], prime[500100], tot, ans1[500100], ans2[500100];   inline void init(void) {     for (int i = 2; i <= 4000; i++) {       if (!is[i]) prime[++tot] = i;       for (int j = 1; j <= tot && i * prime[j] <= 4000; j++) {         is[i * prime[j]] = 1;         if (i % prime[j] == 0) break;       }     }   }   inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   signed main(void) {     n = read();     init();     for (int i = 1; i <= n; i++) {       ans1[i] = ans2[i] = -1;       a[i] = read();       int t = a[i];       for (int j = 1; j <= tot; j++) {         int mul = 1;         while (t % prime[j] == 0) t /= prime[j], mul *= prime[j];         if (mul != 1 && a[i] / mul != 1) ans1[i] = mul, ans2[i] = a[i] / mul;       }       if (t != 1 && a[i] / t != 1) ans1[i] = t, ans2[i] = a[i] / t;     }     for (int i = 1; i <= n; i++) printf( %d  , ans1[i]);     puts(  );     for (int i = 1; i <= n; i++) printf( %d  , ans2[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     string name;     int version;   };   int main(void) {     int n;     cin >> n;     map<pair<string, int>, vector<pair<string, int> > > m;     pair<string, int> init;     for (int i = 0; i < n; i++) {       pair<string, int> cur;       cin >> cur.first >> cur.second;       cur.second *= -1;       if (i == 0) init = cur;       int k;       cin >> k;       for (int j = 0; j < k; j++) {         pair<string, int> node;         cin >> node.first >> node.second;         node.second *= -1;         m[cur].push_back(node);       }     }     set<string> names;     set<pair<string, int> > ans;     set<pair<string, int> > layer;     names.insert(init.first);     layer.insert(init);     while (!layer.empty()) {       set<pair<string, int> > new_layer;       for (set<pair<string, int> >::iterator it = layer.begin();            it != layer.end(); it++) {         for (int k = 0; k < m[*it].size(); k++) {           new_layer.insert(m[*it][k]);         }       }       layer.clear();       for (set<pair<string, int> >::iterator it = new_layer.begin();            it != new_layer.end(); it++) {         if (names.find(it->first) != names.end()) continue;         names.insert(it->first);         ans.insert(*it);         layer.insert(*it);       }     }     cout << ans.size() << endl;     for (set<pair<string, int> >::iterator it = ans.begin(); it != ans.end();          it++) {       cout << it->first <<     << -it->second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, l = -1, j, p, m;     long k;     cin >> n >> k;     long long a[k];     for (long i = 0; i < k; i++) {       cin >> a[i];       j = n / a[i];       if ((j * a[i]) > l) {         l = j * a[i];         p = i + 1;         m = j;       }     }     cout << p <<     << m << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (T& x : v) is >> x;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] << (i + 1 == (int)v.size() ?    :    );     }     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const pair<T, U>& p) {     os <<  (  << p.first <<  ,  << p.second <<  ) ;     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const map<T, U>& m) {     os <<  { ;     for (auto itr = m.begin(); itr != m.end();) {       os <<  (  << itr->first <<  ,  << itr->second <<  ) ;       if (++itr != m.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const unordered_map<T, U>& m) {     os <<  { ;     for (auto itr = m.begin(); itr != m.end();) {       os <<  (  << itr->first <<  ,  << itr->second <<  ) ;       if (++itr != m.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& s) {     os <<  { ;     for (auto itr = s.begin(); itr != s.end();) {       os << *itr;       if (++itr != s.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const multiset<T>& s) {     os <<  { ;     for (auto itr = s.begin(); itr != s.end();) {       os << *itr;       if (++itr != s.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const unordered_set<T>& s) {     os <<  { ;     for (auto itr = s.begin(); itr != s.end();) {       os << *itr;       if (++itr != s.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const deque<T>& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] << (i + 1 == (int)v.size() ?    :    );     }     return os;   }   template <int i, typename T>   void print_tuple(ostream&, const T&) {}   template <int i, typename T, typename H, class... Args>   void print_tuple(ostream& os, const T& t) {     if (i) os <<  , ;     os << get<i>(t);     print_tuple<i + 1, T, Args...>(os, t);   }   template <typename... Args>   ostream& operator<<(ostream& os, const tuple<Args...>& t) {     os <<  { ;     print_tuple<0, tuple<Args...>, Args...>(os, t);     return os <<  } ;   }   void debug_out() { cerr <<   n ; }   template <class Head, class... Tail>   void debug_out(Head&& head, Tail&&... tail) {     cerr << head;     if (sizeof...(Tail) > 0) cerr <<  ,  ;     debug_out(move(tail)...);   }   template <typename T>   T gcd(T x, T y) {     return y != 0 ? gcd(y, x % y) : x;   }   template <typename T>   T lcm(T x, T y) {     return x / gcd(x, y) * y;   }   int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }   int topbit(long long t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }   int botbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); }   int botbit(long long a) { return a == 0 ? 64 : __builtin_ctzll(a); }   int popcount(signed t) { return __builtin_popcount(t); }   int popcount(long long t) { return __builtin_popcountll(t); }   bool ispow2(int i) { return i && (i & -i) == i; }   template <class T>   T ceil(T x, T y) {     assert(y >= 1);     return (x > 0 ? (x + y - 1) / y : x / y);   }   template <class T>   T floor(T x, T y) {     assert(y >= 1);     return (x > 0 ? x / y : (x - y + 1) / y);   }   template <class T1, class T2>   inline bool chmin(T1& a, T2 b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T1, class T2>   inline bool chmax(T1& a, T2 b) {     if (a < b) {       a = b;       return true;     }     return false;   }   const int INF = 1e9;   const long long IINF = 1e18;   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   const char dir[4] = { D ,  R ,  U ,  L };   const long long MOD = 1000000007;   const int MAX_X = 2010;   void solve() {     int n;     cin >> n;     vector<int> dp(MAX_X, INF), ndp(MAX_X, INF);     dp[0] = 0;     for (; n--;) {       int a;       cin >> a;       for (int i = 0; i < MAX_X; i++) {         if (dp[i] == INF) continue;         if (i + a < MAX_X) chmin(ndp[i + a], max(0, dp[i] - a));         chmin(ndp[max(0, i - a)], dp[i] + a);         dp[i] = INF;       }       swap(dp, ndp);     }     int ans = INF;     for (int i = 0; i < MAX_X; i++) chmin(ans, i + dp[i]);     cout << ans <<   n ;   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int t;     cin >> t;     for (; t--;) solve();     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   int n, m, ans, flag;   bool vis[10];   string fac[7] = { 1869 ,  1968 ,  1689 ,  6198 ,  8691 ,  8916 ,  1896 };   string s, ss, anss, xx =  0000 ;   int main() {     int i, j, t, pos, x, y, u, v, w;     while (cin >> s) {       memset(vis, 0, sizeof(vis));       ss =   ;       for (i = 0; i < s.length(); i++) {         if (s[i] ==  1 ) {           if (!vis[1])             vis[1] = 1;           else             ss += s[i];         } else if (s[i] ==  6 ) {           if (!vis[6])             vis[6] = 1;           else             ss += s[i];         } else if (s[i] ==  8 ) {           if (!vis[8])             vis[8] = 1;           else             ss += s[i];         } else if (s[i] ==  9 ) {           if (!vis[9])             vis[9] = 1;           else             ss += s[i];         } else           ss += s[i];       }       flag = 0;       for (i = 0; i < ss.length(); i++) {         if (ss[i] !=  0 ) {           flag = 1;           char c = ss[i];           ss[i] = ss[0];           ss[0] = c;         }       }       if (!flag) {         cout <<  1869  << ss << endl;       } else {         t = 0;         for (i = 0; i < ss.length(); i++) {           t = (t * 10 + ss[i] -  0 ) % 7;         }         for (i = 0; i < 4; i++) {           t = (t * 10 + xx[i] -  0 ) % 7;         }         if (t) t = 7 - t;         cout << ss << fac[t] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int MN = 1 << 8;   int exp(int x, int n) {     int ret = 1;     while (n) {       if (n & 1) ret = 1LL * ret * x % mod;       x = 1LL * x * x % mod;       n >>= 1;     }     return ret;   }   int inv(int x) { return exp(x, mod - 2); }   int fact[MN], invf[MN];   int comb(int n, int k) {     return 1LL * fact[n] * invf[k] % mod * invf[n - k] % mod;   }   int fa[MN];   void init() {     for (int i = 0; i < MN; i++) fa[i] = i;   }   int find(int u) {     if (fa[u] == u)       return u;     else       return fa[u] = find(fa[u]);   }   void mrg(int u, int v) {     u = find(u);     v = find(v);     if (u == v) return;     fa[v] = u;   }   int cc[MN][MN];   int dp(int n, int k) {     int &ret = cc[n][k];     if (ret != -1) return ret;     if (k == 0) return ret = n == 0;     ret = 0;     for (int i = 1; i <= n; i++) {       ret +=           1LL * comb(n - 1, i - 1) * fact[i - 1] % mod * dp(n - i, k - 1) % mod;       ret %= mod;     }     return ret;   }   int N;   int A[MN], B[MN], del[MN], chk[MN], tcnt[3], ans[MN];   int main() {     fact[0] = 1;     for (int i = 1; i < MN; i++) {       fact[i] = 1LL * fact[i - 1] * i % mod;     }     for (int i = 0; i < MN; i++) {       invf[i] = inv(fact[i]);     }     memset(cc, -1, sizeof(cc));     scanf( %d , &N);     for (int i = 0; i < N; i++) {       scanf( %d , &A[i]);       A[i]--;     }     for (int i = 0; i < N; i++) {       scanf( %d , &B[i]);       B[i]--;     }     int ccnt = 0;     init();     for (int i = 0; i < N; i++) {       if (A[i] != -1 && B[i] != -1) {         if (find(A[i]) == find(B[i])) {           del[find(A[i])] = 1;           ccnt++;         } else           mrg(A[i], B[i]);       }     }     vector<int> V;     for (int i = 0; i < N; i++)       if (!del[i] && fa[i] == i) V.push_back(i);     if (V.size() == 0) {       for (int i = 0; i < N; i++) {         printf( %d  , (N - i == ccnt));       }       return 0;     }     for (int i = 0; i < N; i++) {       if (A[i] != -1 && B[i] == -1) {         chk[find(A[i])] |= 1;       }       if (A[i] == -1 && B[i] != -1) {         chk[find(B[i])] |= 2;       }     }     for (int i = 0; i < V.size(); i++) {       tcnt[chk[V[i]]]++;     }     for (int i = 1; i <= (int)V.size() - tcnt[3]; i++) {       int tmp = 0;       for (int j = 0; j <= min(tcnt[1], tcnt[2]); j++) {         if (j % 2)           tmp += mod - 1LL * comb(tcnt[1], j) * comb(tcnt[2], j) % mod * fact[j] %                            mod * dp((int)V.size() - tcnt[3] - j, i) % mod;         else           tmp += 1LL * comb(tcnt[1], j) * comb(tcnt[2], j) % mod * fact[j] % mod *                  dp((int)V.size() - tcnt[3] - j, i) % mod;         tmp %= mod;       }       ans[ccnt + i] = tmp;     }     for (int i = 0; i < N; i++) {       printf( %d  , 1LL * ans[N - i] * fact[tcnt[0]] % mod);     }   }


#include <bits/stdc++.h>   using namespace std;   int zero(int n) {     if (n == 0) return 0;     if (n % 10 == 0) return zero(n / 10);     return 10 * zero(n / 10) + (n % 10);   }   int main() {     int a, b;     cin >> a >> b;     if (zero(a) + zero(b) == zero(a + b)) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   bool chmin(T1 &a, T2 b) {     return b < a && (a = b, true);   }   template <class T1, class T2>   bool chmax(T1 &a, T2 b) {     return a < b && (a = b, true);   }   struct MaxFlow {     struct edge {       int to, cap, rev;     };     vector<int> dist, it;     vector<vector<edge>> g;     MaxFlow(int n) : g(n), dist(n), it(n) {}     void add(int u, int v, int c) {       g[u].push_back({v, c, (int)g[v].size()});       g[v].push_back({u, 0, (int)g[u].size() - 1});     }     int calc(int s, int t) {       int res = 0;       while (bfs(s, t)) {         fill(it.begin(), it.end(), 0);         while (int f = dfs(s, t, 1e9)) res += f;       }       return res;     }     bool bfs(int s, int t) {       fill(dist.begin(), dist.end(), -1);       queue<int> q;       q.push(s);       dist[s] = 0;       while (!q.empty()) {         int v = q.front();         q.pop();         for (edge e : g[v])           if (e.cap > 0 && dist[e.to] < 0) {             dist[e.to] = dist[v] + 1;             q.push(e.to);           }       }       return dist[t] >= 0;     }     int dfs(int v, int t, int f) {       if (v == t) return f;       for (int &i = it[v]; i < g[v].size(); i++) {         edge &e = g[v][i];         if (e.cap > 0 && dist[v] < dist[e.to]) {           if (int d = dfs(e.to, t, min(f, e.cap))) {             e.cap -= d;             g[e.to][e.rev].cap += d;             return d;           }         }       }       return 0;     }   };   template <class T1, class T2>   void sortPair(vector<T1> &v1, vector<T2> &v2) {     vector<pair<T1, T2>> u(v1.size());     for (int i = 0; i < u.size(); i++) u[i] = make_pair(v1[i], v2[i]);     sort(u.begin(), u.end());     for (int i = 0; i < u.size(); i++) tie(v1[i], v2[i]) = u[i];   }   bool solve() {     int n, b, q;     cin >> n >> b >> q;     vector<int> u(q), v(q);     for (int i = 0; i < (q); i++) scanf( %d %d , &u[i], &v[i]);     u.push_back(b);     v.push_back(n);     q++;     sortPair(u, v);     for (int i = 0; i < (q - 1); i++)       if (v[i] > v[i + 1]) return false;     static int sum[10101][5];     for (int i = 0; i < (10101); i++) sum[i][i % 5]++;     for (int i = (1); i < (10101); i++)       for (int j = 0; j < (5); j++) sum[i][j] += sum[i - 1][j];     int lowSum = 0, highSum = 0;     MaxFlow mf(q + q * 5 + 5 + 2);     int src = q + q * 5 + 5;     int dst = src + 1;     int prevU = 0;     int prevV = 0;     for (int mod = 0; mod < (5); mod++) mf.add(q + q * 5 + mod, dst, n / 5);     for (int i = 0; i < (q); i++) {       int mustUse = v[i] - prevV;       int num = u[i] - prevU;       mf.add(src, i, mustUse);       for (int mod = 0; mod < (5); mod++) {         int mm = sum[u[i]][mod] - sum[prevU][mod];         mf.add(i, q + i * 5 + mod, mm);         mf.add(q + i * 5 + mod, q + q * 5 + mod, mm);       }       prevU = u[i];       prevV = v[i];     }     return mf.calc(src, dst) == n;   }   int main() {     cout << (solve() ?  fair  :  unfair ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[15], b[15];     while (cin >> a >> b) {       int len_a = strlen(a);       sort(a, a + len_a);       int k = 0;       for (int i = 0; i < len_a; i++) {         if (a[i] !=  0 ) {           k = i;           break;         }       }       char tmp;       tmp = a[0];       a[0] = a[k];       a[k] = tmp;       if (strcmp(a, b) == 0)         cout <<  OK  << endl;       else         cout <<  WRONG_ANSWER  << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int oo = 0x3f3f3f3f, mod = 1e9 + 7;   using namespace std;   int dx[]{1, -1, 0, 0, 1, 1, -1, -1};   int dy[]{0, 0, 1, -1, 1, -1, 1, -1};   long long OO = (1LL * oo * oo);   void K_K() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     K_K();     long long n, mx = 0, mxidx = 0;     cin >> n;     map<long long, long long> mp;     vector<long long> v(n + 2);     vector<pair<long long, pair<long long, long long>>> ans;     for (int i = 1; i <= n; i++) {       cin >> v[i], mp[v[i]]++;       if (mp[v[i]] > mx) mxidx = i, mx = mp[v[i]];     }     for (int i = mxidx - 1; i > 0; i--) {       if (v[i] > v[i + 1]) {         v[i] -= abs(v[i] - v[i + 1]);         ans.push_back({2, {i, i + 1}});       } else if (v[i] < v[i + 1]) {         ans.push_back({1, {i, i + 1}});         v[i] += abs(v[i] - v[i + 1]);       }     }     for (int i = mxidx + 1; i <= n; i++) {       if (v[i] > v[i - 1]) {         v[i] -= abs(v[i] - v[i - 1]);         ans.push_back({2, {i, i - 1}});       } else if (v[i] < v[i - 1]) {         ans.push_back({1, {i, i - 1}});         v[i] += abs(v[i] - v[i - 1]);       }     }     cout << (int)(ans.size()) <<   n ;     for (int i = 0; i < (int)(ans.size()); i++)       cout << ans[i].first <<     << ans[i].second.first <<                << ans[i].second.second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c;   unsigned long ans = 0;   unordered_map<int, int> um;   void eval(int x) {     int t = 0;     for (int i = 1; i <= sqrt(x); ++i) {       if (i * i == x)         t += 1;       else if (x % i == 0)         t += 2;     }     ans += t;     um[x] = t;   }   int main() {     cin >> a >> b >> c;     for (int i = 1; i <= a; ++i) {       for (int j = 1; j <= b; ++j) {         for (int k = 1; k <= c; ++k) {           if (um.find(i * j * k) != um.end())             ans = (ans + um[i * j * k]) % 1073741824LL;           else             eval(i * j * k);         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int64_t M = 1000000007;   const int64_t MM = 998244353;   template <typename T, typename U>   static inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T &x, U y) {     if (x < y) x = y;   }   int64_t _runtimeTerror_() {     int64_t n;     cin >> n;     string s;     cin >> s;     vector<long long> d_cnt(n + 1, 0), d_sum(n + 1), u_cnt(n + 1),         u_sum(n + 1, 0);     for (int64_t i = 1; i <= n; ++i) {       u_cnt[i] = u_cnt[i - 1];       u_sum[i] = u_sum[i - 1];       d_cnt[i] = d_cnt[i - 1];       d_sum[i] = d_sum[i - 1];       if (s[i - 1] ==  D ) {         d_cnt[i] += 1;         d_sum[i] += i;       } else {         u_cnt[i] += 1;         u_sum[i] += i;       }     }     for (int64_t i = 1; i <= n; ++i) {       int64_t ans = 0;       if (s[i - 1] ==  U ) {         int64_t r_d = d_cnt[n] - d_cnt[i];         int64_t l_u = u_cnt[i - 1];         if (r_d > l_u) {           auto it = lower_bound(d_cnt.begin(), d_cnt.end(), d_cnt[i] + l_u + 1) -                     d_cnt.begin();           ans += (d_sum[it] - d_sum[i] - (i * (l_u + 1))) * 2;           ans -= (u_sum[i - 1]) * 2;           ans += l_u * i * 2;           ans += i;         } else {           ans += (d_sum[n] - d_sum[i] - (d_cnt[n] - d_cnt[i]) * i) * 2;           ans += (n - i + 1);           auto it =               lower_bound(u_cnt.begin(), u_cnt.end(), u_cnt[i - 1] - r_d + 1) -               u_cnt.begin();           ans -= (u_sum[i - 1] - u_sum[it - 1]) * 2;           ans += (r_d * i) * 2;         }         cout << ans <<    ;       } else {         int64_t r_d = d_cnt[n] - d_cnt[i];         int64_t l_u = u_cnt[i - 1];         if (r_d >= l_u) {           auto it = lower_bound(d_cnt.begin(), d_cnt.end(), d_cnt[i] + l_u) -                     d_cnt.begin();           ans += (d_sum[it] - d_sum[i] - (i * (l_u))) * 2;           ans -= (u_sum[i - 1]) * 2;           ans += l_u * i * 2;           ans += i;         } else {           ans += (d_sum[n] - d_sum[i] - (d_cnt[n] - d_cnt[i]) * i) * 2;           ans += (n - i + 1);           auto it = lower_bound(u_cnt.begin(), u_cnt.end(), u_cnt[i - 1] - r_d) -                     u_cnt.begin();           ans -= (u_sum[i - 1] - u_sum[it - 1]) * 2;           ans += ((r_d + 1) * i) * 2;         }         cout << ans <<    ;       }     }     return 0;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int64_t TESTS = 1;     while (TESTS--) _runtimeTerror_();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     string s;     int x;     cin >> n >> m >> k;     int a[n][m];     int b[n][m];     int c[n][m];     for (int i = 0; i < n; i++) {       cin >> s;       for (int j = 0; j < m; j++) {         cin >> x;         a[i][j] = x;         cin >> x;         b[i][j] = x;         cin >> x;         c[i][j] = x;       }     }     int sum_max = 0;     int sum;     vector<pair<int, int> > abc;     abc.reserve(m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         sum = 0;         abc.clear();         for (int ii = 0; ii < m; ii++) {           abc.push_back(make_pair(b[j][ii] - a[i][ii], c[i][ii]));         }         sort(abc.begin(), abc.end());         int left = k;         for (int ii = m - 1; ii >= 0 && left > 0; ii--) {           int d = min(left, abc[ii].second);           if (abc[ii].first > 0) {             sum += d * abc[ii].first;             left -= d;           }         }         if (sum > sum_max) {           sum_max = sum;         }       }     }     cout << sum_max << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 7;   const int M = N * 3;   const int inf = 1e9 + 7;   const int base = 1e9 + 9;   const double pi = acos(-1);   const double ep = 1e-11;   pair<pair<int, int>, int> p[N];   int n;   int vp, vs;   int sqr(int x) { return x * x; }   double sqr(double x) { return x * x; }   int dist(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {     return sqr(a.first.first - b.first.first) +            sqr(a.first.second - b.first.second) + sqr(a.second - b.second);   }   pair<pair<double, double>, double> curr(double t) {     for (int i = 1; i <= n; i++) {       double d = sqrt(dist(p[i - 1], p[i])) + ep;       if (d >= t * vs) {         pair<pair<double, double>, double> tmp;         tmp.first.first = t * vs * (p[i].first.first - p[i - 1].first.first) / d +                           p[i - 1].first.first;         tmp.first.second =             t * vs * (p[i].first.second - p[i - 1].first.second) / d +             p[i - 1].first.second;         tmp.second =             t * vs * (p[i].second - p[i - 1].second) / d + p[i - 1].second;         return tmp;       } else {         t -= d / vs;       }     }     return make_pair(make_pair(0, 0), 0);   }   int main() {     cin >> n;     double t = 0;     for (int i = (int)0; i < (int)n + 1; i++) {       int u, v, c;       cin >> u >> v >> c;       p[i] = make_pair(make_pair(u, v), c);     }     cin >> vp >> vs;     { cin >> p[n + 1].first.first >> p[n + 1].first.second >> p[n + 1].second; }     for (int i = (int)1; i < (int)n + 1; i++)       t += sqrt(dist(p[i - 1], p[i])) / vs;     if (dist(p[n], p[n + 1]) > t * t * vp * vp + ep) {       cout <<  NO ;       return 0;     }     cout <<  YES n ;     double lo = 0, hi = t + ep, g, res = -1;     pair<pair<double, double>, double> ans = curr(35);     do {       g = (lo + hi) / 2;       pair<pair<double, double>, double> tmp = curr(g);       double di = sqr(p[n + 1].first.first - tmp.first.first) +                   sqr(p[n + 1].first.second - tmp.first.second) +                   sqr(p[n + 1].second - tmp.second);       ans = tmp;       res = g;       if (di <= sqr(g) * sqr(vp) + ep) {         res = g;         hi = g - ep;       } else         lo = g + ep;     } while (lo + ep < hi);     printf( %.9lf n , res);     printf( %.9lf %.9lf %.9lf , ans.first.first, ans.first.second, ans.second);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   int sufp[N], freq[N][2];   int mi = 0, ma = 0, par = 0;   void add(int x) {     if (x >= mi and x <= ma) {       if (x % 2 == par)         mi = 0;       else         mi = 1;     } else if (x > ma) {       mi = x - ma;     } else {       mi = mi - x;     }     if (x % 2) par = 1 - par;     ma += x;   }   void reset() { mi = ma = par = 0; }   int main() {     int n;     scanf( %d , &n);     vector<int> v, p;     for (int i = 0; i < n; i++) {       long long x;       scanf( %lld , &x);       v.push_back(__builtin_popcountll(x));       p.push_back(v.back() % 2);     }     for (int i = n - 1; i >= 0; i--) {       sufp[i] = p[i];       if (i + 1 < n) sufp[i] ^= sufp[i + 1];     }     for (int i = 0; i < n; i++) {       freq[i][0] += sufp[i] == 0;       freq[i][1] += sufp[i] == 1;       if (i) {         freq[i][0] += freq[i - 1][0];         freq[i][1] += freq[i - 1][1];       }     }     long long ans = 0;     for (int i = 0; i < n; i++) {       int pos = i;       reset();       while (pos >= 0 and (mi > 1 or ma < 60)) {         add(v[pos]);         if (mi == 0) ans++;         pos--;       }       if (pos < 0) continue;       int base = sufp[pos + 1];       ans += freq[pos][par ^ base];     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   string s;   int main() {     cin >> n >> k >> s;     --k;     if (k < n - 1 - k) {       while (k) {         cout <<  LEFT  << endl;         --k;       }       for (int i = 0; i < n; ++i) {         if (i) cout <<  RIGHT  << endl;         cout <<  PRINT   << s[i] << endl;       }     } else {       while (k < n - 1) {         cout <<  RIGHT  << endl;         ++k;       }       for (int i = 0; i < n; ++i) {         if (i) cout <<  LEFT  << endl;         cout <<  PRINT   << s[n - 1 - i] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long upper_limit = 1e9;     long long lower_limit = -1e9;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int c, d;       cin >> c >> d;       if (d == 2) {         upper_limit = min(upper_limit, 1899LL);       } else {         lower_limit = max(lower_limit, 1900LL);       }       lower_limit += c;       upper_limit += c;     }     if (upper_limit < lower_limit) {       cout <<  Impossible ;     } else if (upper_limit > 1e8) {       cout <<  Infinity ;     } else {       cout << upper_limit;     }   }


#include <bits/stdc++.h>   using namespace std;   const int pi = 3.14159265;   const int INF = 1 << 30;   const int maxn = 1e5;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, k;     string s;     cin >> n >> k;     cin >> s;     int t = s.find( T );     int g = s.find( G );     if (g > t) swap(t, g);     for (int i = g; i < n && i <= t; i += k) {       if (s[i] ==  # ) {         cout <<  NO  << endl;         return 0;       }       if (i == t) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int n, x[5000 + 5], y[5000 + 5], tot;   int color[5000 + 5];   bool flag;   int ksm(int b, int k) {     int s = 1;     while (k > 0) {       if (k & 1) s = (1ll * s * b) % mod;       k >>= 1;       b = (1ll * b * b) % mod;     }     return s % mod;   }   int dis(int id1, int id2) {     return abs(x[id1] - x[id2]) + abs(y[id1] - y[id2]);   }   void clearall() {     flag = true;     tot = 0;     memset(color, 0, sizeof(color));   }   void dfs(int u, int lim) {     if (flag) {       for (int i = 1; i <= n; i++) {         if (flag) {           if (u == i || dis(u, i) <= lim) continue;           if (!color[i]) {             color[i] = color[u] ^ 1;             dfs(i, lim);           } else {             if (color[i] != color[u]) continue;             flag = false;             return;           }         }       }     }   }   bool check(int lim) {     int i, j;     clearall();     for (i = 1; i <= n; i++)       if (!color[i]) {         tot++;         color[i] = 2;         dfs(i, lim);         if (!flag) break;       }     return flag;   }   int main() {     int i, ans = -1;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d%d , &x[i], &y[i]);     int l = 0, r = 10000;     while (l < r - 5) {       int mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     for (i = l; i <= r; i++)       if (check(i)) {         ans = i;         break;       }     printf( %d n , ans);     printf( %d n , ksm(2, tot));   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, -1, 1};   void arquivo() {     freopen(  ,  r , stdin);     freopen(  ,  w , stdout);   }   const int N = 5000100;   int n;   long long a, b;   int v[N];   bool memo[N][3];   long long pd[N][3];   int atPrime;   long long func(int pos, int op) {     if (pos == n) return 0LL;     if (memo[pos][op]) return pd[pos][op];     long long ret = 1000000000000000001LL;     if (!op) {       ret = func(pos + 1, 1) + a;       if (v[pos] % atPrime == 0) ret = min(ret, func(pos + 1, 0));       if ((v[pos] + 1) % atPrime == 0) ret = min(ret, func(pos + 1, 0) + b);       if ((v[pos] - 1) % atPrime == 0) ret = min(ret, func(pos + 1, 0) + b);     } else if (op == 1) {       ret = func(pos + 1, 1) + a;       if (v[pos] % atPrime == 0) ret = min(ret, func(pos + 1, 2));       if ((v[pos] + 1) % atPrime == 0) ret = min(ret, func(pos + 1, 2) + b);       if ((v[pos] - 1) % atPrime == 0) ret = min(ret, func(pos + 1, 2) + b);     } else {       if (v[pos] % atPrime == 0) ret = min(ret, func(pos + 1, 2));       if ((v[pos] + 1) % atPrime == 0) ret = min(ret, func(pos + 1, 2) + b);       if ((v[pos] - 1) % atPrime == 0) ret = min(ret, func(pos + 1, 2) + b);     }     memo[pos][op] = 1;     return pd[pos][op] = ret;   }   void fatora(long long x, set<int> &all) {     for (long long i = 2; i * i <= x; ++i) {       if (x % i == 0) {         all.insert(i);         while (x % i == 0) x /= i;       }     }     if (x > 1) all.insert(x);   }   int main() {     scanf( %d %lld %lld , &n, &a, &b);     set<int> all;     long long x;     for (int i = 0; i < n; ++i) {       scanf( %d , v + i);     }     for (int i = 0; i < 1; ++i) {       x = v[i];       fatora(x, all);       x = v[i] + 1;       fatora(x, all);       x = v[i] - 1;       fatora(x, all);     }     for (int i = n - 1; i < n; ++i) {       x = v[i];       fatora(x, all);       x = v[i] + 1;       fatora(x, all);       x = v[i] - 1;       fatora(x, all);     }     long long ans = (long long)(n - 1LL) * a;     for (set<int>::iterator it = all.begin(); it != all.end(); it++) {       atPrime = *it;       if (atPrime == 1) continue;       memset(memo, 0, sizeof memo);       for (int j = n - 1; j >= 0; --j) {         func(j, 0);         func(j, 1);         func(j, 2);       }       ans = min(ans, func(0, 0));     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans % m;   }   int main() {     string s;     cin >> s;     int n;     cin >> n;     int from[n];     char s1, s2;     string to[n];     long long a[10], b[10];     for (int i = 0; i < n; i++) {       cin >> from[i] >> to[i];     }     for (int i = 0; i < n; i++) {       to[i] = to[i].substr(2);     }     for (int i = 0; i < 10; i++) {       a[i] = 10;       b[i] = i;     }     for (int i = n - 1; i >= 0; i--) {       long long p = 1, q = 0;       for (int j = 0; j < to[i].length(); j++) {         int c = to[i][j] -  0 ;         long long p2 = (a[c] * p) % 1000000007;         long long q2 = (a[c] * q + b[c]) % 1000000007;         p = p2;         q = q2;       }       a[from[i]] = p;       b[from[i]] = q;     }     long long ans = 0;     for (int i = 0; i < s.length(); i++) {       int c = s[i] -  0 ;       ans = (ans * a[c] + b[c]) % 1000000007;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int32_t M = 1e9 + 7;   int32_t mod_inv(int32_t a, int32_t m) {     int32_t g = m, r = a, x = 0, y = 1;     while (r != 0) {       int32_t q = g / r;       g %= r;       swap(g, r);       x -= q * y;       swap(x, y);     }     return x < 0 ? x + m : x;   }   int gcdi(int a, int b) {     if (b == 0) {       return a;     }     return gcdi(b, a % b);   }   long long gcdl(long long a, long long b) {     if (b == 0) {       return a;     }     return gcdl(b, a % b);   }   long long lcm(long long a, long long b) { return (a / gcdl(a, b)) * b; }   int factorial(int n) {     if (n == 0) return 1;     return n * factorial(n - 1);   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   void FAST() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void swap_ll(long long *a, long long *b) {     long long c;     c = *a;     *a = *b;     *b = c;   }   void swap_int(int *a, int *b) {     int c;     c = *a;     *a = *b;     *b = c;   }   void swap_char(char *a, char *b) {     char c;     c = *a;     *a = *b;     *b = c;   }   bool mycomp(pair<int, int> &a, pair<int, int> &b) {     if (a.first == b.first) return a.second < b.second;     return a.first < b.first;   }   long long fast_pow(long long a, long long p) {     long long res = 1;     while (p) {       if (p % 2 == 0) {         a = a * 1ll * a % 000000007;         p /= 2;       } else {         res = res * 1ll * a % 000000007;         p--;       }     }     return res;   }   long long fact(long long n) {     long long res = 1;     for (long long i = 1; i <= n; i++) {       res = res * 1ll * i % 000000007;     }     return res;   }   long long nCk(long long n, long long k) {     return fact(n) * 1ll * fast_pow(fact(k), 000000007 - 2) % 000000007 * 1ll *            fast_pow(fact(n - k), 000000007 - 2) % 000000007;   }   long long firstDigit(long long n) {     long long digits = (long long)log10(n);     n = (long long)(n / pow(10, digits));     return n;   }   long long find(long long n, long long d) {     while (n > 0) {       if (n % 10 == d) return 1;       n /= 10;     }     return 0;   }   struct node {     int data;     node *next;     node(int d) {       data = d;       next = NULL;     }   };   void ffin() { FAST(); }   long long add(vector<long long> a, long long b, long long e) {     long long sum = 0;     for (long long i = b; i < e; i++) {       sum += a[i];     }     return sum;   }   void decToBinary(int n) {     int binaryNum[32];     int i = 0;     while (n > 0) {       binaryNum[i] = n % 2;       n = n / 2;       i++;     }     for (int j = i - 1; j >= 0; j--) cout << binaryNum[j];   }   bool isInteger(double N) {     int X = N;     double temp2 = N - X;     if (temp2 > 0) {       return false;     }     return true;   }   bool check(vector<int> &v) {     int n = (int)((v).size());     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         for (int k = j + 1; k < n; k++) {           if ((v[i] >= v[j] && v[j] >= v[k]) || (v[i] <= v[j] && v[j] <= v[k])) {             return true;           }         }       }     }     return false;   }   bool digitscheck(long long n) {     while (n != 0) {       long long y = n % 10;       if (y != 0 and y != 1) {         return false;       }       n = n / 10;     }     return true;   }   const long long N = 5e+5;   long long a[N][5];   long long better(long long i, long long j) {     long long cnt = 0;     for (int k = 0; k < 5; k++) {       cnt += (a[i][k] < a[j][k]);     }     return (cnt >= 3);   }   void solve() {     long long n;     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < 5; j++) cin >> a[i][j];     long long best = 0;     for (int i = 1; i < n; i++) {       if (better(i, best)) best = i;     }     bool ok = true;     for (int i = 0; i < n; i++) {       if (i == best) continue;       ok &= better(best, i);     }     if (!ok) best = -2;     cout << best + 1 <<   n ;   }   int main() {     ffin();     long long tests = 1;     cin >> tests;     while (tests--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1E5 + 5;   long long m, n, k, alice[MAXN], bob[MAXN];   bool cmp(int x, int y) { return x > y; }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> alice[i];     for (int i = 0; i < m; i++) cin >> bob[i];     if (n > m) {       cout <<  YES  << endl;       return 0;     }     sort(alice, alice + n, cmp);     sort(bob, bob + m, cmp);     for (int i = 0; i < n; i++) {       if (alice[i] > bob[i]) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     scanf( %d , &n);     long long int a[n];     set<long long int> x;     map<long long int, set<int> > m;     for (i = 0; i < n; i++) {       scanf( %lld , &a[i]);       x.insert(a[i]);       m[a[i]].insert(i);     }     while (!x.empty()) {       long long int j = *x.begin();       if (m[j].size() >= 2) {         m[j].erase(m[j].begin());         int k = *(m[j].begin());         m[j].erase(m[j].begin());         m[2 * j].insert(k);         x.insert(2 * j);       } else {         x.erase(x.begin());       }     }     vector<pair<int, long long int> > ans;     map<long long int, set<int> >::iterator it;     for (it = m.begin(); it != m.end(); it++) {       if ((it->second).size() == 1) {         ans.push_back(make_pair(*(it->second).begin(), it->first));       }     }     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (i = 0; i < ans.size(); i++) {       printf( %lld  , ans[i].second);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   using min_queue = priority_queue<T, vector<T>, greater<T>>;   const long long MOD = 1e9 + 7;   int N;   int cnt[6];   int res[100100];   vector<int> v[6];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     const vector<string> sizes = { S ,  M ,  L ,  XL ,  XXL ,  XXXL };     map<string, int> inv;     {       int k = 0;       for (auto s : sizes) inv[s] = k++;     }     for (int i = 0; i < 6; i++) {       cin >> cnt[i];     }     cin >> N;     for (int i = 0; i < N; i++) {       string s;       cin >> s;       string t;       for (char c : s) {         if (c ==  , ) break;         t += c;       }       int k = inv[t];       if (s == t) {         cnt[k]--;         res[i] = k;       } else {         v[k].push_back(i);       }     }     bool good = 1;     for (int i = 0; i < 5; i++) {       if (cnt[i] < 0) {         good = 0;         break;       }       while (!v[i].empty() && cnt[i] > 0) {         cnt[i]--;         res[v[i].back()] = i;         v[i].pop_back();       }       while (!v[i].empty() && cnt[i + 1] > 0) {         cnt[i + 1]--;         res[v[i].back()] = i + 1;         v[i].pop_back();       }       if (!v[i].empty() || cnt[i + 1] < 0) {         good = 0;         break;       }     }     if (!good) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     for (int i = 0; i < N; i++) cout << sizes[res[i]] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     char a[n + 1][n + 1];     int ans[n + 1][n + 1];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         cin >> a[i][j];         ans[i][j] = 0;       }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n - k + 1; j++) {         bool x = true;         for (int t = j; t < j + k; t++) {           if (a[i][t] ==  # ) {             x = false;             break;           }         }         if (x) {           for (int t = j; t < j + k; t++) ans[i][t]++;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n - k + 1; j++) {         bool x = true;         for (int t = j; t < j + k; t++) {           if (a[t][i] ==  # ) {             x = false;             break;           }         }         if (x) {           for (int t = j; t < j + k; t++) ans[t][i]++;         }       }     }     int mx = ans[1][1];     int p = 1, q = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         if (ans[i][j] > mx) {           mx = ans[i][j];           p = i;           q = j;         }       }     cout << p <<     << q;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   int n, m, a[maxn];   map<int, int> mp, rmp;   int main() {     scanf( %d%d , &n, &m);     int id;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] == m) id = i;     }     int cnt = 0;     for (int i = id; i >= 1; i--) {       if (a[i] < m)         cnt++;       else if (a[i] > m)         cnt--;       mp[cnt]++;     }     long long ans = 0;     cnt = 0;     for (int i = id; i <= n; i++) {       if (a[i] < m)         cnt++;       else if (a[i] > m)         cnt--;       ans += 1LL * mp[-cnt] + 1LL * mp[-cnt - 1];     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long O = 2e9;   const double E = 1e-9;   const double pi = 3.1415926536;   int DX[] = {1, -1, 0, 0};   int DY[] = {0, 0, 1, -1};   int main() {     int n, m;     cin >> n >> m;     int out = n * 2 + 1, in = 1;     if (m > n * 2) {       for (int i = 0; i < m; i++) {         if (i % 2 == 0 && out <= m)           cout << out++ <<    ;         else           cout << in++ <<    ;       }     } else       for (int i = 1; i <= m; i++) cout << i <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   set<int> s;   int x[maxn];   int n, k;   int main() {     while (~scanf( %d , &n)) {       k = 0;       if (!s.empty()) s.clear();       for (int i = 1; i <= n; i++) {         int p;         scanf( %d , &p);         if (s.count(p) == 0)           s.insert(p);         else {           x[k++] = i;           s.clear();         }       }       if (k == 0)         printf( -1 n );       else {         if (x[k - 1] != n) x[k - 1] = n;         printf( %d n , k);         printf( 1 %d n , x[0]);         for (int i = 0; i < k - 1; i++) printf( %d %d n , x[i] + 1, x[i + 1]);       }     }     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 100005;   int n, val[MAXN], ch[MAXN][2], fa[MAXN], maxv[MAXN], size[MAXN], root;   inline int max(int a, int b) { return a > b ? a : b; }   inline int min(int a, int b) { return a > b ? b : a; }   inline void maintain(int x) {     size[x] = size[ch[x][0]] + size[ch[x][1]] + 1;     maxv[x] = max(max(maxv[ch[x][0]], maxv[ch[x][1]]), val[x]);   }   void rotate(int x) {     int y = fa[x], d = ch[y][1] == x;     if (fa[x] = fa[y]) ch[fa[y]][ch[fa[y]][1] == y] = x;     if (ch[y][d] = ch[x][d ^ 1]) fa[ch[y][d]] = y;     fa[ch[x][d ^ 1] = y] = x;     maintain(y), maintain(x);   }   void splay(int &rt, int x) {     int f = fa[rt], y, z;     while ((y = fa[x]) != f && (z = fa[y]) != f) {       rotate((ch[z][1] == y) == (ch[y][1] == x) ? y : x);       rotate(x);     }     if (y != f) rotate(x);     rt = x;   }   void select(int &rt, int k) {     int x = rt;     while (size[ch[x][0]] + 1 != k) {       if (k <= size[ch[x][0]])         x = ch[x][0];       else {         k -= size[ch[x][0]] + 1;         x = ch[x][1];       }     }     splay(rt, x);   }   void getPos(int &rt, int v) {     int x = rt;     while (true) {       if (ch[x][1] && maxv[ch[x][1]] > v)         x = ch[x][1];       else if (ch[x][0] && val[x] <= v)         x = ch[x][0];       else         break;     }     splay(rt, x);   }   void insert(int &rt, int p, int pos) {     if (!pos) {       select(rt, 1);       fa[ch[rt][0] = p] = rt;       rotate(p);       rt = p;       return;     }     select(rt, pos);     int tmp = ch[rt][1];     if (!tmp) {       fa[ch[rt][1] = p] = rt;       rotate(p);       rt = p;       return;     }     fa[ch[rt][1] = p] = rt;     fa[ch[p][1] = tmp] = p;     splay(rt, tmp);   }   void traverse(int x) {     if (!x) return;     traverse(ch[x][0]);     printf( %d  , x);     traverse(ch[x][1]);   }   int main() {     int tmp, i;     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       scanf( %d%d , &val[i], &tmp);       if (i == 1) {         size[root = 1] = 1;         maxv[1] = val[1];         continue;       }       getPos(root, val[i]);       if (val[root] < val[i])         insert(root, i, i - 1 - min(tmp, i - 1));       else         insert(root, i, i - 1 - min(tmp, size[ch[root][1]]));     }     traverse(root);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int main() {     int t;     cin >> t;     while (t--) {       int c, s, v = 0, m, d, k, y;       cin >> c >> s;       m = (s / 2);       d = (c / s);       k = (c % s);       if (m == 0) {         v = c;       } else {         if (k >= m) {           v = (c - k + m);         } else {           v = c;         }       }       cout << v << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   vector<long long> v[105];   map<long long, long long> mp;   int vis[105];   long long cnt, cnt2;   void dfs(int s) {     vis[s] = 1;     cnt += v[s].size();     cnt2++;     for (int i = 0; i < v[s].size(); i++) {       if (!vis[v[s][i]]) dfs(v[s][i]);     }   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m, b, ans = 0, ans2, x, y, z, i, s;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         cnt = 0;         cnt2 = 0;         dfs(i);         if (cnt2 * 2 == cnt) {           if (cnt2 % 2) ans++;         }       }     }     if ((n - ans) % 2 == 0)       cout << ans;     else       cout << ans + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> V;   int solve() {     V.clear();     cin >> n;     for (int i = 0; i < n; ++i) {       int a;       cin >> a;       V.emplace_back(a);     }     sort(V.begin(), V.end());     V.erase(unique(V.begin(), V.end()), V.end());     return V.size();   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) cout << solve() <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v[201];   long long arr[201];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, i, j, c, max1, min1, temp, temp1, n1;     cin >> n;     for (i = 0; i < 2 * n; i++) {       cin >> arr[i];       v[arr[i]].push_back(i);     }     for (i = 1; i <= n; i++) {       if (abs(v[i][0] - v[i][1]) == 1) {         continue;       } else {         break;       }     }     if (i > n) {       cout <<  0 ;       exit(0);     }     c = 0;     while (1) {       for (i = 0; i < 2 * n; i++) {         if (abs(v[arr[i]][0] - v[arr[i]][1]) == 1) {           continue;         } else {           max1 = max(v[arr[i]][0], v[arr[i]][1]);           min1 = min(v[arr[i]][0], v[arr[i]][1]);           c += max1 - min1 - 1;           for (j = max1; j > min1 + 1; j--) {             if (v[arr[j]][0] == j) {               temp = 0;             } else {               temp = 1;             }             if (v[arr[j - 1]][0] == j - 1) {               temp1 = 0;             } else {               temp1 = 1;             }             v[arr[j]][temp] = j - 1;             v[arr[j - 1]][temp1] = j;             swap(arr[j], arr[j - 1]);           }         }       }       for (i = 1; i <= n; i++) {         if (abs(v[i][0] - v[i][1]) == 1) {           continue;         } else {           break;         }       }       if (i > n) {         cout << c;         exit(0);       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long n;   const long long maxn = 2e5 + 100;   const long long mod = 1e9 + 7;   vector<long long> G[maxn];   long long dp[maxn];   long long oth[maxn];   long long fs[maxn], ts[maxn];   long long ans[maxn];   void myinit() {     cin >> n;     for (long long i = 2; i <= n; i++) {       long long u;       cin >> u;       G[u].push_back(i);     }     memset(dp, 0, sizeof(dp));     memset(oth, 0, sizeof(oth));   }   void dfs1(long long x) {     long long s = 1;     for (long long i = 0; i < G[x].size(); i++) {       long long tmp = G[x][i];       dfs1(tmp);       s = s * (dp[tmp] + 1);       s %= mod;     }     dp[x] = s;   }   void dfs2(long long x) {     fs[0] = 1;     for (long long i = 0; i < G[x].size(); i++) {       long long tmp = G[x][i];       fs[i + 1] = fs[i] * (dp[tmp] + 1);       fs[i + 1] %= mod;     }     ts[G[x].size() + 1] = 1;     for (long long i = (long long)G[x].size() - 1; i >= 0; i--) {       long long tmp = G[x][i];       ts[i + 1] = (ts[i + 2] * (dp[tmp] + 1)) % mod;     }     for (long long i = 0; i < G[x].size(); i++) {       oth[G[x][i]] = ((fs[i] * ts[i + 2] % mod) * oth[x] + 1) % mod;     }     for (long long i = 0; i < G[x].size(); i++) {       dfs2(G[x][i]);     }   }   void dfs3(long long x) {     for (long long i = 0; i < G[x].size(); i++) {       long long tmp = G[x][i];       ans[tmp] = (oth[tmp] * dp[tmp]) % mod;       dfs3(tmp);     }   }   void solve() {     myinit();     dfs1(1);     oth[1] = 1;     dfs2(1);     ans[1] = dp[1];     dfs3(1);     for (long long i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void print2dvector(vector<vector<T> > v) {     cout <<  A 2d vector:  << endl;     int a = v.size();     int b = v[0].size();     if (a <= 15 && b <= 15) {       for (int i = 0; i < a; i++) {         for (int j = 0; j < b; j++) {           cout << setw(4) << v[i][j];         }         cout << endl;       }     }     if (a > 15 && b > 15) {       for (int i = 0; i < 9; i++) {         for (int j = 0; j < 9; j++) {           cout << setw(4) << v[i][j];         }         cout <<                    <<  .   .   .  << setw(4) << v[i][b - 3] << setw(4) << v[i][b - 2]              << setw(4) << v[i][b - 1] << endl;       }       for (int i = 0; i < 15; i++) {         cout << setw(4) <<  . ;       }       cout << endl;       for (int i = a - 3; i < a; i++) {         for (int j = 0; j < 9; j++) {           cout << setw(4) << v[i][j];         }         cout <<                    <<  .   .   .  << setw(4) << v[i][b - 3] << setw(4) << v[i][b - 2]              << setw(4) << v[i][b - 1] << endl;       }     }     if (a > 15) {       for (int i = 0; i < 9; i++) {         for (int j = 0; j < b; j++) {           cout << setw(4) << v[i][j];         }         cout << endl;       }       for (int i = 0; i < b; i++) {         cout << setw(4) <<  . ;       }       cout << endl;       for (int i = a - 3; i < a; i++) {         for (int j = 0; j < b; j++) {           cout << setw(4) << v[i][j];         }         cout << endl;       }     }     if (b > 15) {       for (int i = 0; i < a; i++) {         for (int j = 0; j < 9; j++) {           cout << setw(4) << v[i][j];         }         cout <<                    <<  .   .   .  << setw(4) << v[i][b - 3] << setw(4) << v[i][b - 2]              << setw(4) << v[i][b - 1] << endl;       }     }   }   template <typename T>   void printvector(vector<T> v) {     cout <<  A 1d vector:  << endl;     int a = v.size();     if (a <= 15) {       for (int i = 0; i < a; i++) {         cout << setw(4) << v[i];       }     } else {       for (int i = 0; i < 9; i++) {         cout << setw(4) << v[i];       }       cout <<                  <<  .   .   .  << setw(4) << v[a - 3] << setw(4) << v[a - 2] << setw(4)            << v[a - 1];     }     cout << endl;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<int> v(n, 0);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i]);     }     double ans = 0;     int a, b, c;     for (int i = 0; i < m; i++) {       scanf( %d %d %d , &a, &b, &c);       ans = max(ans, 1.0 * (v[a - 1] + v[b - 1]) / c);     }     printf( %.12lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200005], b[200005], vis[200005];   bool cmp(int a, int b) { return a > b; }   int main() {     int n;     scanf( %d , &n);     int numa = 0, numb = 0, flag = 0;     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       if (vis[x])         a[numa++] = x, vis[x]++;       else         b[numb++] = x, vis[x]++;       if (vis[x] > 2) flag = 1;     }     if (flag)       printf( NO n );     else {       printf( YES n );       sort(a, a + numa);       sort(b, b + numb, cmp);       printf( %d n , numa);       int flag1 = 0;       for (int i = 0; i < numa; i++) {         if (flag1) printf(   );         flag1 = 1;         printf( %d , a[i]);       }       printf(  n );       flag1 = 0;       printf( %d n , numb);       for (int i = 0; i < numb; i++) {         if (flag1) printf(   );         flag1 = 1;         printf( %d , b[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const int N = 1005;   int cnt[N];   bitset<N> dp;   int n, m;   int idx[N];   int par[N];   int xx[N];   bool vis[N];   int find(int x) {     if (par[x] == x) return x;     return par[x] = find(par[x]);   }   int main() {     for (int i = 0; i <= 1000; i += 1) cnt[i] = 0;     cin >> n >> m;     int ix = 1;     for (int i = 0; i <= n; i += 1) par[i] = i;     int id = -1, tmp, x;     bool flag = false;     for (int i = 1; i <= n; i += 1) {       cin >> xx[i];       if (xx[i] != 0) par[i] = find(par[xx[i]]);       if (xx[i] == 0) {         idx[i] = ix++;       }     }     for (int i = 1; i <= n; i += 1) {       if (find(par[i]) == find(par[m])) {         continue;       }       cnt[idx[find(par[i])]]++;     }     int now = m;     while (now != 0) {       cnt[idx[par[m]]]++;       now = xx[now];     }     dp[cnt[idx[par[m]]]] = 1;     for (int i = 1; i <= ix - 1; i += 1) {       if (i != idx[par[m]]) {         dp = (dp << cnt[i]) | dp;       }     }     for (int i = 0; i <= n; i += 1) {       if (dp[i] == 1) {         cout << i << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 33;   template <class T>   inline void relax(T &a, const T &b) {     if (b > a) a = b;   }   int main() {     int n;     static int a[MaxN][MaxN];     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) scanf( %d , &a[i][j]);     int l = (n + 1) / 2;     int res = INT_MIN;     for (int lastR = 0; lastR < (1 << l); lastR++) {       int cur = 0;       for (int r = 0; r < l; r++) {         int resR = INT_MIN;         for (int tv = 0; tv <= 1; tv++) {           int curR = 0;           for (int c = 0; c < l; c++) {             int resRC = INT_MIN;             for (int cv = 0; cv <= 1; cv++) {               if (r == l - 1 && cv != (lastR >> c & 1)) continue;               if (c == l - 1 && cv != tv) continue;               int curRC = 0;               curRC += cv == 0 ? a[r][c] : -a[r][c];               if (r + l < n)                 curRC +=                     (cv ^ (lastR >> c & 1)) == 0 ? a[r + l][c] : -a[r + l][c];               if (c + l < n) curRC += (cv ^ tv) == 0 ? a[r][c + l] : -a[r][c + l];               if (r + l < n && c + l < n)                 curRC +=                     (cv ^ (lastR >> c & 1) ^ tv ^ (lastR >> (l - 1) & 1)) == 0                         ? a[r + l][c + l]                         : -a[r + l][c + l];               relax(resRC, curRC);             }             if (resRC == INT_MIN) {               curR = INT_MIN;               break;             }             curR += resRC;           }           relax(resR, curR);         }         cur += resR;       }       relax(res, cur);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); }   inline long long Set(long long n, long long pos) {     return n = n | (1LL << pos);   }   inline long long Reset(long long n, long long pos) {     return n = n & ~(1LL << pos);   }   inline bool Check(long long n, long long pos) {     return (bool)(n & (1LL << pos));   }   inline long long Count(long long n) { return __builtin_popcountll(n); }   long long const N = 3e5 + 5;   long long const MOD = 998244353;   long long color[N];   vector<long long> adj[N];   long long dp[N];   long long res[N];   long long dfs(long long node, long long p) {     long long col = 0;     for (auto c : adj[node]) {       if (p == c) continue;       long long temp = dfs(c, node);       col += max(temp, 0LL);     }     col += color[node];     return dp[node] = col;   }   void adfs(long long node, long long p, long long up) {     up = max(up, 0LL);     res[node] = dp[node] + up;     for (auto c : adj[node]) {       if (p == c) continue;       long long temp = dp[node] - max(dp[c], 0LL) + up;       adfs(c, node, temp);     }   }   void solve() {     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> color[i];       if (color[i] == 0) color[i] = -1;     }     for (long long i = 1; i < n; i++) {       long long u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, -1);     adfs(1, -1, 0);     for (long long i = 1; i <= n; i++) cout << res[i] <<    ;   }   int32_t main() {     fast();     solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1LL << 60;   const long long N = 2e5 + 5;   long long a[N];   void solve() {     long long n;     cin >> n;     vector<long long> vect;     for (long long i = 1; i < n + 1; i++) {       cin >> a[i];       if (a[i] != i) {         vect.push_back(i);       }     }     if ((long long)vect.size() == 0) {       cout << 0;       return;     }     bool fl = true;     for (long long i = 1; i < (long long)vect.size(); i++) {       if (vect[i] - vect[i - 1] > 1) fl = false;     }     if (fl)       cout << 1;     else       cout << 2;   }   signed main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, l, c, d, p, nl, np;     cin >> n >> k >> l >> c >> d >> p >> nl >> np;     int mls = k * l;     int slices = c * d;     int drinks = min(mls / nl, min(p / np, slices)) / n;     cout << drinks << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[500010];   char s[500010], temp[500010];   int n;   long long Max = -1000, sum = 0;   void init() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> s[i];     }   }   void work() {     for (int i = 0; i < n; i++) {       if (s[i] ==  B ) sum += a[i];     }     Max = sum;     long long temp = sum;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  A ) {         sum += a[i];         if (sum > Max) Max = sum;       } else {         sum -= a[i];       }     }     sum = temp;     for (int i = 0; i < n; i++) {       if (s[i] ==  A ) {         sum += a[i];         if (sum > Max) Max = sum;       } else {         sum -= a[i];       }     }   }   int main() {     init();     work();     cout << Max << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     int n, m, q, p;     cin >> n >> m >> q >> p;     queue<pair<pair<int, int>, int>> qu;     vector<vector<int>> g(n, vector<int>(m, 0));     vector<vector<char>> d(n, vector<char>(m));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> d[i][j];         if (d[i][j] ==  * ) g[i][j] = -1;       }     int si[4]{0, 0, -1, 1};     int sj[4]{1, -1, 0, 0};     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (d[i][j] !=  .  && d[i][j] !=  * ) {           int cur = (int(d[i][j]) - int( A ) + 1) * q;           g[i][j] += cur;           qu.push({{i, j}, cur});           vector<vector<bool>> used(n, vector<bool>(m, false));           used[i][j] = true;           while (!qu.empty()) {             int x = qu.front().first.first;             int y = qu.front().first.second;             int qq = qu.front().second;             for (int c = 0; c < 4; c++) {               int tx = x + si[c];               int ty = y + sj[c];               if (tx > -1 && tx < n && ty > -1 && ty < m)                 if (!used[tx][ty] && g[tx][ty] != -1) {                   g[tx][ty] += qq / 2;                   used[tx][ty] = true;                   if (qq > 1) qu.push({{tx, ty}, qq / 2});                 }             }             qu.pop();           }         }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (g[i][j] > p) ans++;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r, g, b;     cin >> r >> g >> b;     if (r % 2 == 0)       r = r / 2;     else       r = r / 2 + 1;     if (g % 2 == 0)       g = g / 2;     else       g = g / 2 + 1;     if (b % 2 == 0)       b = b / 2;     else       b = b / 2 + 1;     int tmp1 = 3 * (r - 1);     int tmp2 = 3 * (g - 1) + 1;     int tmp3 = 3 * (b - 1) + 2;     tmp1 = max(tmp1, tmp2);     tmp1 = max(tmp1, tmp3);     cout << tmp1 + 30;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e6 + 7;   const int inf = INT_MAX;   const long long inff = 1e18;   const long long mod = 1e9 + 7;   int d, s;   pair<int, int> dp[maxn];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> d >> s;     for (int i = 0; i <= (d + 1) * (s + 1); i++) dp[i] = make_pair(-1, 0);     queue<int> q;     q.push(0);     while (!q.empty()) {       int now = q.front();       int sum = now / d, r = now % d;       q.pop();       for (int i = 0; i < 10; i++) {         if (sum + i <= s && (dp[(sum + i) * d + (r * 10 + i) % d].first == -1)) {           dp[(sum + i) * d + (r * 10 + i) % d] = make_pair(now, i);           q.push((sum + i) * d + (r * 10 + i) % d);         }       }     }     int now = s * d;     if (dp[now].first == -1)       return cout << -1 <<   n , 0;     else {       vector<int> v;       while (now) {         v.push_back(dp[now].second);         now = dp[now].first;       }       reverse((v).begin(), (v).end());       for (int i : v) cout << i;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, r, c, i, d, j = 0, a = 0, b = 0;     string s;     cin >> s;     n = s.size();     r = 1;     c = n;     while (c > 20) {       r++;       c = ceil((float)n / (float)r);     }     d = r * c - n;     cout << r <<     << c << endl;     while (j < r && d > 0) {       string s1(s, a, c - 1);       cout <<  *  << s1 << endl;       a = a + c - 1;       j++;       d--;     }     while (j < r) {       string s1(s, a, c);       cout << s1 << endl;       a = a + c;       j++;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, p, m;   vector<vector<int> > g;   vector<char> used;   vector<long long> c, vs, es;   pair<int, int> dfs(int v) {     used[v] = true;     pair<int, int> ans(1, (int)g[v].size());     for (int u : g[v]) {       if (used[u]) {         continue;       }       pair<int, int> a = dfs(u);       ans.first += a.first;       ans.second += a.second;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> p;     g.resize(n);     used.resize(n);     c = vs = es = vector<long long>(p);     for (int k = 0; k < p; k++) {       cin >> c[k];       c[k]--;     }     for (int k = 0; k < m; k++) {       int v, u;       cin >> v >> u;       v--;       u--;       g[v].push_back(u);       g[u].push_back(v);     }     int i = -1;     for (int k = 0; k < p; k++) {       pair<int, int> ans = dfs(c[k]);       vs[k] = ans.first;       es[k] = ans.second / 2;       if (i == -1 || vs[k] > vs[i]) {         i = k;       }     }     int rem = 0;     for (int k = 0; k < n; k++) {       if (!used[k]) {         pair<int, int> ans = dfs(k);         vs[i] += ans.first;         es[i] += ans.second / 2;       }     }     long long ans = 0;     for (int k = 0; k < p; k++) {       ans += vs[k] * (vs[k] - 1) / 2 - es[k];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, max;   vector<int> a[100000];   bool visited[100000] = {0};   char col[100000] = { Z };   void f(int x) {     queue<int> q;     q.push(x);     visited[x] = 1;     char temp =  A ;     col[x] = temp;     while (!q.empty()) {       int p = q.front();       q.pop();       temp = col[p];       if (temp ==  A )         temp =  B ;       else         temp =  A ;       for (int i = 0; i < a[p].size(); i++) {         if (visited[a[p][i]] == false) {           q.push(a[p][i]);           visited[a[p][i]] = true;           col[a[p][i]] = temp;         } else if (col[a[p][i]] != temp) {           puts( -1 );           exit(0);         }       }     }   }   int main() {     cin >> n >> m;     int x, y;     for (int i = 0; i < m; i++) {       cin >> x >> y;       x--;       y--;       a[x].push_back(y);       a[y].push_back(x);     }     f(x);     for (int i = 0; i < 100000; i++) {       if (a[i].size() && visited[i] == 0) f(i);     }     int c1 = 0;     for (int i = 0; i < 100000; i++)       if (col[i] ==  B ) c1++;     cout << c1 <<   n ;     for (int i = 0; i < 100000; i++)       if (col[i] ==  B ) cout << i + 1 <<    ;     cout <<   n ;     c1 = 0;     for (int i = 0; i < 100000; i++)       if (col[i] ==  A ) c1++;     cout << c1 <<   n ;     for (int i = 0; i < 100000; i++)       if (col[i] ==  A ) cout << i + 1 <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 1;   const long long inf = 1e9 + 1;   const long long mod = 1e9 + 7;   const long double eps = 1e-6;   mt19937 rnd(58);   struct point {     long double x, y;     bool operator==(const point &right);   };   bool point::operator==(const point &b) { return (x == b.x && y == b.y); }   long double dist(point a, point b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   long double mindist(point A1, point A2, point B1, point B2) {     long double x0 = A1.x - B1.x, y0 = A1.y - B1.y;     long double k = A2.x - A1.x - (B2.x - B1.x), s = A2.y - A1.y - (B2.y - B1.y);     if (A1 == A2 && B1 == B2) return dist(A1, B1);     long double v = -(x0 * k + y0 * s) / (k * k + s * s);     long double ans = min(dist(A1, B1), dist(A2, B2));     if (v > 0 && v < 1)       ans = min(ans, (k * k + s * s) * v * v + 2 * v * (x0 * k + y0 * s) +                          x0 * x0 + y0 * y0);     return ans;   }   point A[N], B[N];   void solve() {     long long i, j, k, n, d1, d2;     cin >> n >> d1 >> d2;     d1 = d1 * d1;     d2 = d2 * d2;     for (i = 0; i < n; ++i) {       cin >> A[i].x >> A[i].y >> B[i].x >> B[i].y;     }     long long ans = 0;     bool canHello = 1;     for (i = 0; i < n - 1; ++i) {       if (dist(A[i], B[i]) >= d2 + eps) canHello = 1;       if (canHello && mindist(A[i], A[i + 1], B[i], B[i + 1]) <= d1 + eps) {         ++ans;         canHello = 0;       }     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     int l;     vector<int> v;     cin >> s1 >> s2;     for (int i = 0; i < s2.length(); i++) {       if ((s2[i] -  0 ) > 0) v.push_back(s2[i] -  0 );     }     sort(v.begin(), v.end());     int k = v.size() - 1;     for (int i = 0; i < s1.length(); i++) {       for (int j = k; j >= 0; j--) {         if ((s1[i] -  0 ) < v[j]) {           k--;           s1[i] = char(v[j] +  0 );         }         break;       }     }     cout << s1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long int, int> mp;   map<long long int, int> mpp;   long long int a[100007];   long long int b[100007];   long long int bb[100007];   int main() {     int m, p;     scanf( %d %d , &m, &p);     int i, j;     for (i = 0; i < m; i++) scanf( %lld , a + i);     for (i = 0; i < p; i++) scanf( %lld , b + i);     sort(b, b + p);     long long int ans = 0;     long long int anss = 0;     long long int ansss;     bb[0] = 0;     mp[0] = 1;     mpp[0] = 1;     for (i = 1; i < m; i++) anss = anss + a[i], mp[anss]++, bb[i] = anss;     for (i = 0; i < m; i++) {       anss = bb[i];       if (mpp[b[0] - anss - a[0]]) continue;       mpp[b[0] - anss - a[0]] = 1;       ansss = 1;       j = 1;       while (j < p) {         anss = anss + b[j] - b[j - 1];         if (mp[anss]) {           if (!(b[j] - anss - a[0])) ansss = 0;         } else {           ansss = 0;           break;         }         j++;       }       ans = ans + ansss;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int inf = 1e9;   const int NINF = 0xc0c0c0c0;   const int maxn = 1e5 + 7;   const int bas = maxn / 2;   const int Maxn = 1e7 + 7;   const double eps = 1e-6;   const int mod = (1 << 31) - 1;   template <typename T>   void read(T &x) {     x = 0;     char c = getchar();     T flag = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) flag = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     x = x * flag;   }   struct edge {     int v, next;   } e[maxn << 1];   int head[maxn], cnt;   void add(int a, int b) {     e[++cnt] = edge{b, head[a]};     head[a] = cnt;   }   int f[maxn][21], dep[maxn], tot, dp[maxn], treez = 0, root;   void dfs(int u, int fa) {     dep[u] = dep[fa] + 1;     f[u][0] = fa;     for (int i = 1; i <= 20; i++) {       f[u][i] = f[f[u][i - 1]][i - 1];     }     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].v;       if (v == fa) continue;       dfs(v, u);       treez = max(treez, dp[u] + dp[v] + 1);       dp[u] = max(dp[u], dp[v] + 1);     }   }   int getlca(int a, int b) {     if (dep[a] < dep[b]) swap(a, b);     for (int i = 20; ~i; i--) {       int x = f[a][i];       if (dep[x] >= dep[b]) a = x;     }     if (a == b) return a;     for (int i = 20; ~i; i--) {       if (f[a][i] != f[b][i]) {         a = f[a][i];         b = f[b][i];       }     }     return f[a][0];   }   int k;   int work(int a, int lca) {     for (int i = 20; ~i; i--) {       if ((1 << i) <= k && dep[f[a][i]] >= dep[lca]) {         a = f[a][i];         k -= (1 << i);       }     }     return a;   }   void solve() {     int n, a, b, da, db;     cin >> n >> a >> b >> da >> db;     for (int i = 1; i <= n; i++) head[i] = 0, dp[i] = 0, dep[i] = 0;     cnt = 0;     treez = 0;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       add(u, v);       add(v, u);     }     if (da * 2 >= db) {       puts( Alice );       return;     }     dfs(1, 0);     int lca = getlca(a, b);     if (treez <= da * 2) {       puts( Alice );       return;     }     if (dep[a] + dep[b] - dep[lca] * 2 <= da) {       puts( Alice );       return;     }     puts( Bob );   }   signed main() {     int T = 1;     scanf( %d , &T);     while (T--) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long n, l, r;   inline long long query(long long l, long long r) {     for (long long i = 62; i >= 1; i--) {       if ((1ll << i) - 1 >= l && (1ll << i) - 1 <= r) return (1ll << i) - 1;     }     for (long long i = 62; i >= 0; i--)       if (((1ll << i) & l) > 0 && ((1ll << i) & r) > 0)         return (1ll << i) + query(l - (1ll << i), r - (1ll << i));   }   int main() {     scanf( %lld , &n);     while (n--) {       scanf( %lld%lld , &l, &r);       if (l > r) {         long long t = l;         l = r;         r = t;       }       if (l == r) {         printf( %lld n , l);         continue;       }       printf( %lld n , query(l, r));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool nextper(int num[], int n) {     int i;     for (i = n - 1; i > 0; i--) {       if (num[i] > num[i - 1]) {         for (int j = n - 1; j >= i; j--) {           if (num[j] > num[i - 1]) {             int t = num[j];             num[j] = num[i - 1];             num[i - 1] = t;             for (int m = i, k = n - 1; m < k; m++, k--) {               t = num[m];               num[m] = num[k];               num[k] = t;             }             break;           }         }         break;       }     }     if (i > 0) {       return true;     } else       return false;   }   int order[8] = {0, 1, 2, 3, 4, 5, 6, 7};   char s[8][9];   int main() {     int n, k, i, j, min, max, num, ans = 2147483647;     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) scanf( %s , s[i]);     do {       min = 2147483647;       max = 0;       for (i = 0; i < n; i++) {         num = 0;         for (j = 0; j < k; j++) num = num * 10 + (s[i][order[j]] -  0 );         if (min > num) min = num;         if (max < num) max = num;       }       if (max - min < ans) ans = max - min;     } while (nextper(order, k));     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << 6 * n * (n - 1) + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bd(string n) {     string num = n;     long long dec_value = 0;     long long base = 1;     long long len = num.length();     for (long long i = len - 1; i >= 0; i--) {       if (num[i] ==  1 ) dec_value += base;       base = base * 2;     }     return dec_value;   }   long long db(long long n) {     for (long long i = 31; i >= 0; i--) {       long long k = n >> i;       if (k & 1)         cout <<  1 ;       else         cout <<  0 ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long l, r;     cin >> l >> r;     if (l < r) {       long long x = 64 - (__builtin_clzll(l ^ r));       long long y = 1;       long long ans = y << x;       ans--;       cout << ans;     } else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps(1e-8);   long long a[100];   long long f[100];   long long dp[100];   long long l, r;   long long calc(long long i) {     long long ret = 0;     for (long long j = (1); j <= (i - 1); ++j) {       if (i % j == 0) ret += f[j];     }     return ret;   }   long long solve(long long n) {     long long tmp = n;     long long top = 0;     while (tmp) {       a[++top] = tmp % 2;       tmp /= 2;     }     if (top == 1) return 0;     long long ret = 0;     for (long long i = (1); i <= (top - 1); ++i) ret += calc(i);     for (long long i = (1); i <= (top - 1); ++i)       if (top % i == 0) {         long long now = a[top];         dp[i] = 0;         for (long long j = (2); j <= (i); ++j) {           if (a[top - j + 1]) dp[i] += 1 << (i - j);           now = now * 2 + a[top - j + 1];         }         long long tmp = now;         for (long long j = (2); j <= (top / i); ++j) tmp = (tmp << i) + now;         if (tmp <= n) dp[i]++;         for (long long j = (1); j <= (i - 1); ++j)           if (i % j == 0) dp[i] -= dp[j];         ret += dp[i];       }     return ret;   }   void cal(long long n) {     f[1] = 1;     for (long long i = (2); i <= (n); ++i) {       f[i] = 1 << (i - 1);       for (long long j = (1); j <= (i - 1); ++j)         if (i % j == 0) f[i] -= f[j];     }   }   int main() {     cal(70);     scanf( %I64d %I64d , &l, &r);     printf( %I64d n , solve(r) - solve(l - 1));   }