#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1000000000 )   #pragma GCC optimize( Ofast,no-stack-protector )   using namespace std;   const int maxn = (int)2e5 + 10;   vector<int> ed[maxn];   int t[maxn], h[maxn];   long long dp[maxn][2];   void go(int v, int p) {     vector<pair<long long, int> > g;     int in = 0;     int out = 0;     long long sc = 0;     for (int u : ed[v]) {       if (u == p) {         continue;       }       go(u, v);       if (h[u] > h[v]) {         out++;         sc += dp[u][0];       } else if (h[u] < h[v]) {         in++;         sc += dp[u][1];       } else {         out++;         g.push_back(make_pair(-dp[u][0] + dp[u][1], u));         sc += dp[u][0];       }     }     sort((g).begin(), (g).end());     for (int it = 0; it < 2; it++) {       if (p != -1)         if (it == 0) {           in++;         } else {           out++;         }       long long ans = (long long)1e18;       long long cur = sc;       for (int i = 0; i <= (int)g.size(); i++) {         ans = min(ans, cur + max(in + i, out - i) * (long long)t[v]);         if (i != (int)g.size()) cur += g[i].first;       }       dp[v][it] = ans;       if (p != -1)         if (it == 0) {           in--;         } else {           out--;         }     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &t[i]);     }     for (int i = 0; i < n; i++) {       scanf( %d , &h[i]);     }     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--;       y--;       ed[x].push_back(y);       ed[y].push_back(x);     }     go(0, -1);     cout << dp[0][0] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   pair<long double, pair<long long, long long> > c[250001];   long double p, q, abcd, ABCD;   long long a, b, n, i, x, y;   bool comp(pair<long double, pair<long long, long long> > a,             pair<long double, pair<long long, long long> > b) {     if (a.first < b.first) return 1;     if (a.first > b.first) return 0;     if (a.second.second < b.second.second) return 1;     if (a.second.second == b.second.second && a.second.first < b.second.first)       return 1;     return 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> x >> y >> n;     abcd = x;     ABCD = y;     for (i = 1; i <= n; i++) {       b = i;       a = x * b / y;       p = a;       q = b;       c[i * 2 - 1] = make_pair(abs(abcd / ABCD - p / q), make_pair(a, b));       b = i;       a = (x * b + y - 1) / y;       p = a;       q = b;       c[i * 2] = make_pair(abs(abcd / ABCD - p / q), make_pair(a, b));     }     sort(c + 1, c + 1 + n * 2, comp);     cout << c[1].second.first <<  /  << c[1].second.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, t, x, y, z, w, ct, ans, f;   string s, l;   long long a[200005];   set<long long> si;   queue<long long> qi;   map<long long, long long> mi;   vector<long long> vi;   priority_queue<long long> pqdi;   priority_queue<long long, vector<long long>, greater<long long>> pqai;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cerr.tie(NULL);     cin >> t;     while (t--) {       si.clear();       vi.clear();       cin >> n;       for (long long i = 1; i <= n; i++) {         cin >> a[i];         si.insert(a[i]);       }       if (si.size() != n) {         cout <<  NO               <<   n ;       } else {         f = 0;         vector<long long> diff;         sort(a + 1, a + n + 1);         for (long long i = 2; i < n + 1; i++) {           for (long long j = 1; j < i; j++) {             diff.push_back(a[i] - a[j]);           }         }         long long valid[1000000];         long long j = 2;         memset(valid, 0, sizeof(valid));         vi.push_back(1);         valid[1] = 1;         for (long long i = 1; i < n; i++) {           for (auto it : diff) {             valid[(vi[i - 1] + it)] = 1;           }           while (valid[j]) j++;           vi.push_back(j);           valid[j] = 1;           if (j > 1000000) {             f = 1;             break;           }         }         if (f)           cout <<  NO                 <<   n ;         else {           cout <<  YES                 <<   n ;           ;           for (long long i = 1; i <= n; i++) cout << vi[i - 1] <<    ;           cout <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   const int MAXN = 1e4 + 10;   const int MOD = 1e9 + 7;   const int inf = 1e9;   const double pi = acos(-1.0);   const double eps = 1e-6;   int dx[] = {0, -1, 0, 1};   int dy[] = {1, 0, -1, 0};   map<int, int> mymap, mymap1;   int n, m;   vector<int> Ve, Vo;   int save[200100];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     int res = 0;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x % 2) {         if (!mymap[x]) {           Vo.push_back(x);           mymap[x] = 1;           mymap1[x] = i;         }       } else {         if (!mymap[x]) {           Ve.push_back(x);           mymap[x] = 1;           mymap1[x] = i;         }       }     }     int o = Vo.size();     int e = Ve.size();     int r = -1;     if (o >= n / 2 && e <= n / 2)       r = min(o - n / 2, n / 2 - e);     else if (o <= n / 2 && e >= n / 2)       r = min(n / 2 - o, e - n / 2);     if (r != -1) {       res += r;       if (o <= n / 2) {         o += r;         e -= r;       } else {         o -= r;         e += r;       }     }     res += max(n / 2 - o, 0);     res += max(n / 2 - e, 0);     for (int i = 1; i <= min(n, m); i++)       if (i % 2) {         if (!mymap[i]) {           mymap[i] = 1;           Vo.push_back(i);         }       } else {         if (!mymap[i]) {           mymap[i] = 1;           Ve.push_back(i);         }       }     o = Vo.size();     e = Ve.size();     if (o >= n / 2 && e >= n / 2) {       cout << res << endl;       vector<int> K;       K.clear();       for (int i = 0; i < n / 2; i++)         if (mymap1[Vo[i]])           save[mymap1[Vo[i]]] = Vo[i];         else           K.push_back(Vo[i]);       for (int i = 0; i < n / 2; i++)         if (mymap1[Ve[i]])           save[mymap1[Ve[i]]] = Ve[i];         else           K.push_back(Ve[i]);       int p = 1;       int q = 0;       while (p <= n && q < K.size())         if (save[p])           p++;         else {           save[p] = K[q];           p++;           q++;         }       for (int i = 1; i <= n; i++) cout << save[i] <<    ;     } else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   template <typename T>   struct modular {     constexpr modular() : val(0) {}     constexpr modular(const modular<T>& _m) : val(_m.val) {}     template <typename U>     constexpr modular(const U& _r = U()) {       val = -MOD <= _r && _r < MOD ? _r : _r % MOD;       if (val < 0) {         val += MOD;       }     }     const T operator()() { return val; }     template <typename U>     explicit operator U() const {       return static_cast<U>(val);     }     modular<T>& operator+=(const modular<T>& _m) {       if ((val += _m.val) >= MOD) {         val -= MOD;       }       return *this;     }     modular<T>& operator-=(const modular<T>& _m) {       if ((val -= _m.val) < 0) {         val += MOD;       }       return *this;     }     modular<T>& operator*=(const modular<T>& _m) {       val = modular<T>(static_cast<int64_t>(val) * static_cast<int64_t>(_m.val))                 .val;       return *this;     }     modular<T>& operator/=(const modular<T>& _m) {       T a = _m.val, b = MOD, u = 0, v = 1;       while (a != 0) {         T q = b / a;         b -= q * a;         swap(a, b);         u -= q * v;         swap(u, v);       }       return *this *= u;     }     modular<T>& operator=(const modular<T>& _m) {       val = _m.val;       return *this;     }     template <typename U>     modular<T>& operator+=(const U& _r) {       return *this += modular<T>(_r);     }     template <typename U>     modular<T>& operator-=(const U& _r) {       return *this -= modular<T>(_r);     }     template <typename U>     modular<T>& operator*=(const U& _r) {       return *this *= modular<T>(_r);     }     template <typename U>     modular<T>& operator/=(const U& _r) {       return *this /= modular<T>(_r);     }     template <typename U>     modular<T>& operator=(const U& _r) {       val = modular<T>(_r).val;       return *this;     }     modular<T> operator-() { return modular<T>(-val); }     template <typename U>     friend bool operator==(const modular<U>&, const modular<U>&);     friend std::istream& operator>>(std::istream& os, modular<T>& _m) {       os >> _m.val;       _m *= 1;       return os;     }     friend std::ostream& operator<<(std::ostream& os, const modular<T>& _m) {       return os << _m.val;     }     template <typename U>     modular<T> exp(U e) {       modular<T> res = 1;       modular<T> b = val;       if (e < 0) {         b = 1 / b;         e *= -1;       }       for (; e; e >>= 1) {         if (e & 1) {           res *= b;         }         b *= b;       }       return res;     }       private:     T val;   };   template <typename T>   inline modular<T> operator+(const modular<T>& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) += _rhs;   }   template <typename T, typename U>   inline modular<T> operator+(const modular<T>& _lhs, const U& _rhs) {     return modular<T>(_lhs) += _rhs;   }   template <typename T, typename U>   inline modular<T> operator+(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) += _rhs;   }   template <typename T>   inline modular<T> operator-(const modular<T>& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) -= _rhs;   }   template <typename T, typename U>   inline modular<T> operator-(const modular<T>& _lhs, const U& _rhs) {     return modular<T>(_lhs) -= _rhs;   }   template <typename T, typename U>   inline modular<T> operator-(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) -= _rhs;   }   template <typename T>   inline modular<T> operator*(const modular<T>& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) *= _rhs;   }   template <typename T, typename U>   inline modular<T> operator*(const modular<T>& _lhs, const U& _rhs) {     return modular<T>(_lhs) *= _rhs;   }   template <typename T, typename U>   inline modular<T> operator*(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) *= _rhs;   }   template <typename T>   inline modular<T> operator/(const modular<T>& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) /= _rhs;   }   template <typename T, typename U>   inline modular<T> operator/(const modular<T>& _lhs, const U& _rhs) {     return modular<T>(_lhs) /= _rhs;   }   template <typename T, typename U>   inline modular<T> operator/(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) /= _rhs;   }   template <typename T>   inline bool operator==(const modular<T>& _lhs, const modular<T>& _rhs) {     return _lhs.val == _rhs.val;   }   template <typename T, typename U>   inline bool operator==(const modular<T>& _lhs, const U& _rhs) {     return _lhs == modular<T>(_rhs);   }   template <typename T, typename U>   inline bool operator==(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) == _rhs;   }   template <typename T>   inline bool operator!=(const modular<T>& _lhs, const modular<T>& _rhs) {     return !(_lhs == _rhs);   }   template <typename T, typename U>   inline bool operator!=(const modular<T>& _lhs, const U& _rhs) {     return !(_lhs == _rhs);   }   template <typename T, typename U>   inline bool operator!=(const U& _lhs, const modular<T>& _rhs) {     return !(_lhs == _rhs);   }   string to_string(string s) { return     + s +    ; }   string to_string(bool x) { return (x ?  T  :  F ); }   string to_string(modular<int> x) { return to_string(int(x)); }   string to_string(const char* s) { return to_string((string)s); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename V>   string to_string(V v) {     bool f = true;     string res =  [ ;     for (const auto& x : v) {       if (!f) res +=  ,  ;       f = false;       res += to_string(x);     }     res +=  ] ;     return res;   }   void debug() { cerr << endl; }   template <typename H, typename... T>   void debug(H h, T... t) {     cerr <<     << to_string(h);     debug(t...);   }   const int N = 5050;   modular<int> a[N], c[N], dn[N][N << 1], res[N << 1];   void solve() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       cin >> a[i];     }     c[1] = 1;     for (int i = 1; i < n; i++) {       c[i + 1] = c[i] * a[i];     }     for (int i = n; i >= 1; i--) {       dn[i][0] = 1;       for (int j = 1; i + j <= n; j++) {         dn[i][j] = a[i] * dn[i + 1][j - 1];         res[j] += dn[i][j] * c[i];       }     }     for (int i = 1; i <= n; i++) {       dn[i][0] = 1;       for (int j = 2 * n - 2; j >= 1; j--) {         dn[i][j] = dn[i - 1][j - 1];         res[j] += dn[i][j] * c[i];         dn[i][j] += (a[i] - 1) * dn[i + 1][j - 1];       }     }     modular<int> half = modular<int>(1) / 2;     for (int j = 1; j <= 2 * n - 2; j++) {       cout << res[j] * half <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     cout << endl;   }


/**    * Author: Daniel    * Created Time: 2021-05-20 00:17:05   **/      // time-limit: 2000   // problem-url: https://codeforces.com/contest/1525/problem/E   #include <bits/stdc++.h>      using namespace std;      #define F first    #define S second   #define ER erase   #define IS insert   #define PI acos(-1)   #define PB pop_back   #define MP make_pair   #define MT make_tuple   #define LB lower_bound   #define UB upper_bound   #define EB emplace_back   #define lowbit(x) (x & -x)   #define SZ(x) ((int)x.size())   #define ALL(x) x.begin(), x.end()   #define RALL(x) x.rbegin(), x.rend()   #define SOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10)      typedef long long LL;   typedef vector<LL> VL;   typedef vector<int> VI;   typedef vector<bool> VB;   typedef pair<LL, LL> PLL;   typedef vector<string> VS;   typedef vector<double> VD;   typedef pair<int, int> PII;   typedef unsigned long long ULL;   typedef pair<double, double> PDD;   typedef vector<pair<LL, LL> > VPLL;   typedef vector<pair<int, int> > VPII;      template <typename A> using VE = vector<A>;   template <typename A> using USET = unordered_set<A>;   template <typename A> using HEAP = priority_queue<A>;   template <typename A, typename B> using PA = pair<A, B>;   template <typename A, typename B> using UMAP = unordered_map<A, B>;   template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >;      template <typename A> A MAX(const A &a) { return a; }   template <typename A> A MIN(const A &a) { return a; }   template <typename A> A MAX(const A *a, const A *b) { return *max_element(a, b); }   template <typename A> A MIN(const A *a, const A *b) { return *min_element(a, b); }   template <typename A, typename... B> A MAX(const A &a, const B&... b) { return max(a, MAX(b...)); }   template <typename A, typename... B> A MIN(const A &a, const B&... b) { return min(a, MIN(b...)); }   template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MAX(A a, A b) { return *max_element(a, b); }   template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MIN(A a, A b) { return *min_element(a, b); }      mt19937 rng((unsigned int)chrono::steady_clock::now().time_since_epoch().count());      template <typename A, typename B>   string to_string(pair<A, B> p);      template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);      template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);      string to_string(const string& s) { return     + s +    ; }      string to_string(const char* s) { return to_string((string)s); }       string to_string(const char c) { return to_string((string)   + c); }       string to_string(bool b) { return (b ?  true  :  false ); }      string to_string(vector<bool> v)    {       bool first = true;       string res =  { ;       for (int i = 0; i < static_cast<int>(v.size()); i++)        {           if (!first) res +=  ,  ;           first = false;           res += to_string(v[i]);       }       res +=  } ;       return res;   }      template <size_t N>   string to_string(bitset<N> v)   {       string res =   ;       for (size_t i = 0; i < N; i++) res += static_cast<char>( 0  + v[i]);       return res;   }      template <typename A>   string to_string(A v)   {       bool first = true;       string res =  { ;       for (const auto &x : v)       {           if (!first) res +=  ,  ;           first = false;           res += to_string(x);       }       res +=  } ;       return res;   }      template <typename A, typename B>   string to_string(pair<A, B> p) { return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; }      template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) { return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + to_string(get<2>(p)) +  ) ; }      template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) { return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ; }      void debug_out() { cout <<   n ; }      template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) { cout <<     << to_string(H); debug_out(T...); }      #ifdef LOCAL   #define debug(...) cout <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__)   #else   #define debug(...) 42   #endif      ///////////////////////////////////////////////////////////////////////////   //////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////   ///////////////////////////////////////////////////////////////////////////      // check the limitation!!!   const int N = 100010, M = 1010, mod = 998244353;      int qp(int a, int b)   {       int res = 1;       while (b)       {           if (b & 1) res = (LL)res * a % mod;           a = (LL)a * a % mod;           b >>= 1;       }       return res;   }      // read the question carefully!!!   int main()   {       SOS;          int n, m;       cin >> n >> m;       VE<VI> d(n, VI(m));       for (auto &u : d)           for (auto &v : u)               cin >> v;       int fact_inv = 1;       for (int i = 1; i <= n; i ++ ) fact_inv = (LL)fact_inv * i % mod;       fact_inv = qp(fact_inv, mod - 2);       int res = 0;       for (int j = 0; j < m; j ++ )       {           VI cnt(n + 1);           for (int i = 0; i < n; i ++ ) cnt[n - d[i][j] + 1] ++ ;           int ans = 1, tot = 0;           for (int i = 0; i < n; i ++ )           {               tot += cnt[i];               ans = (LL)ans * tot % mod;               tot = max(0, tot - 1);           }           res = (res + 1 - (LL)fact_inv * ans) % mod;       }       res = (res + mod) % mod;       cout << res <<   n ;       return 0;   }      // GOOD LUCK!!!


#include <bits/stdc++.h>   using namespace std;   long long n, s, a, ans, a11, r;   vector<long long> aa, ab, c;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> s >> a;       if (s == 11) {         a11++;         ans += a;       }       if (s == 0) c.push_back(a);       if (s == 10) aa.push_back(a);       if (s == 1) ab.push_back(a);     }     sort(aa.begin(), aa.end());     reverse(aa.begin(), aa.end());     sort(ab.begin(), ab.end());     reverse(ab.begin(), ab.end());     r = min(aa.size(), ab.size());     for (int i = r; i < aa.size(); i++) {       c.push_back(aa[i]);     }     for (int i = r; i < ab.size(); i++) {       c.push_back(ab[i]);     }     sort(c.begin(), c.end());     reverse(c.begin(), c.end());     for (int i = 0; i < min(a11, (long long)c.size()); i++) ans += c[i];     for (int i = 0; i < r; i++) {       ans += aa[i];       ans += ab[i];     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> v(n);     for (int i = (int)(0); i < (int)(n); ++i) cin >> v[i];     sort(v.begin(), v.end());     cout << v[(n - 1) / 2] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int toInt(string s) {     int v;     istringstream sin(s);     sin >> v;     return v;   }   template <class T>   inline string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   const double EPS = 1e-10;   const double PI = acos(-1.0);   vector<int> x, y;   int xo, yo;   int n, d;   int dp[1000][1000];   int sqr(int a) { return a * a; }   int dfs(int x1, int y1) {     if (sqr(x1) + sqr(y1) > sqr(d)) return dp[x1 + 500][y1 + 500] = 1;     if (dp[x1 + 500][y1 + 500] != -1) return dp[x1 + 500][y1 + 500];     for (int i = (0); i < (int((x).size())); ++i)       if (!dfs(x1 + x[i], y1 + y[i])) return dp[x1 + 500][y1 + 500] = 1;     return dp[x1 + 500][y1 + 500] = 0;   }   int main(int argc, char *argv[]) {     ios::sync_with_stdio(false);     memset(dp, -1, sizeof dp);     cin >> xo >> yo >> n >> d;     for (int i = (0); i < (n); ++i) {       int xi, yi;       cin >> xi >> yi;       x.push_back(xi);       y.push_back(yi);     }     if (dfs(xo, yo))       cout <<  Anton  << endl;     else       cout <<  Dasha  << endl;     return 0;   }


#include <bits/stdc++.h>   long long mpow(long long a, long long n, long long mod) {     long long ret = 1;     long long b = a;     while (n) {       if (n & 1) ret = (ret * b) % mod;       b = (b * b) % mod;       n >>= 1;     }     return (long long)ret;   }   using namespace std;   vector<int> v, v1;   pair<int, int> p[100004];   int a[100004], b[100004];   int main() {     int n, i, j;     cin >> n;     for (j = 0; j < n; j++) {       cin >> p[j].first;       p[j].second = j;     }     sort(p, p + n);     long long z = 0;     int need = n - (n + 2) / 3;     for (j = n - need; j < n; j++) {       if (z % 2 == 0) {         a[p[j].second] = p[j].first - z / 2;         b[p[j].second] = z / 2;       } else {         a[p[j].second] = z / 2;         b[p[j].second] = p[j].first - z / 2;       }       z++;     }     for (j = 0; j < n - need; j++) {       a[p[j].second] = 0;       b[p[j].second] = p[j].first;     }     cout <<  YES  << endl;     for (j = 0; j < n; j++) cout << a[j] <<    ;     cout << endl;     for (j = 0; j < n; j++) cout << b[j] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const int SINF = 0x7fffffff;   const long long LINF = 0x3fffffffffffffff;   const long long SLINF = 0x7fffffffffffffff;   const long double DINF = pow(2, 100);   const int MAXN = 1007;   const int MOD = static_cast<int>(1e9 + 7);   const long double EPS = 1e-11;   struct cT {     cT() : x(0), y(0) {}     cT(long double _x, long double _y) : x(_x), y(_y) {}     cT operator+(const cT &a) const { return cT(x + a.x, y + a.y); }     cT operator-(const cT &a) const { return cT(x - a.x, y - a.y); }     cT operator/(const int a) { return cT(x / a, y / a); }     bool operator==(const cT &a) const {       return ((((x - a.x) >= 0) ? (x - a.x) : (-(x - a.x))) < EPS &&               (((y - a.y) >= 0) ? (y - a.y) : (-(y - a.y))) < EPS);     }     bool operator!=(const cT &a) const { return !((*this) == a); }     bool operator<(const cT &a) const {       return ((((x - a.x) >= 0) ? (x - a.x) : (-(x - a.x))) > EPS)                  ? x < a.x                  : y < a.y - EPS;     }     long double getk() {       return (((x) >= 0) ? (x) : (-(x))) < EPS ? DINF : (y / x);     }     long double x, y;   } cr[MAXN];   struct dT {     dT() : k(0) {}     dT(cT _cr, long double _k) : cr(_cr), k(_k) {}     bool operator<(const dT &a) const {       return (cr != a.cr) ? cr < a.cr : k < a.k - EPS;     }     cT cr;     long double k;   } med[MAXN * MAXN];   int n;   int km;   void init();   void input();   void work();   int getans(int l, int r);   int add(int x, int y) {     x += y;     if (x >= MOD) x -= MOD;     return x;   }   void addv(int &x, int y) {     x += y;     if (x >= MOD) x -= MOD;   }   int dec(int x, int y) {     x -= y;     if (x < 0) x += MOD;     return x;   }   void decv(int &x, int y) {     x -= y;     if (x < 0) x += MOD;   }   int main() {     init();     input();     work();   }   void init() { ios::sync_with_stdio(false); }   void input() {     scanf( %d , &n);     int a, b, c, d;     for (int i = 1; i <= n; ++i) {       scanf( %d%d%d%d , &a, &b, &c, &d);       cr[i].x = static_cast<long double>(a * b * d * d) /                 (a * a * d * d + b * b * c * c);       cr[i].y = static_cast<long double>(c * d * b * b) /                 (a * a * d * d + b * b * c * c);     }   }   void work() {     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         med[++km] = dT((cr[i] + cr[j]) / 2, (cr[j] - cr[i]).getk());       }     }     sort(med + 1, med + 1 + km);     med[km + 1] = dT(cT(DINF, DINF), 1);     int pre = 1, ans = 0;     for (int i = 1; i <= km + 1; ++i) {       if (med[i].cr != med[pre].cr) {         addv(ans, getans(pre, i - 1));         pre = i;       }     }     cout << ans << endl;   }   int getans(int l, int r) {     int pre = l;     int ans = 1;     for (int i = l; i <= r; ++i) {       if ((((med[i].k - med[pre].k) >= 0) ? (med[i].k - med[pre].k)                                           : (-(med[i].k - med[pre].k))) > EPS) {         ans = static_cast<long long>(ans) * (i - pre + 1) % MOD;         pre = i;       }     }     ans = static_cast<long long>(ans) * (r - pre + 2) % MOD;     return dec(ans, r - l + 2);   }


#include <bits/stdc++.h>   using namespace std;   char s[1010];   int main() {     int f1 = 0, f2 = 0;     scanf( %s , s);     int len = strlen(s);     for (int i = 0; i < len; i++) {       if (s[i] ==  0 ) {         if (f1 == 0) {           printf( 1 1 n );           f1 = 1;         } else {           printf( 3 1 n );           f1 = 0;         }       }       if (s[i] ==  1 ) {         if (f2 == 0) {           printf( 4 3 n );           f2 = 1;         } else {           printf( 4 1 n );           f2 = 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int oo = 1000000000;   long long n;   long long a[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     if (n == 1) {       cout << 1 <<     << 1 << endl;       cout << -a[1] << endl;       a[1] = 0;       cout << 1 <<     << 1 << endl;       cout << -a[1] << endl;       cout << 1 <<     << 1 << endl;       cout << -a[1] << endl;       return 0;     }     cout << 1 <<     << 1 << endl;     cout << n - (a[1] % n) << endl;     a[1] += n - (a[1] % n);     cout << 2 <<     << n << endl;     for (int i = 2; i <= n; i++) {       cout << (a[i] % n) * (n - 1) <<    ;       a[i] += (a[i] % n) * (n - 1);     }     cout << endl;     cout << 1 <<     << n << endl;     for (int i = 1; i <= n; i++) cout << -a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> me;   long long sum(long long x) { return (x * (x + 1)) / 2; }   int main() {     int k;     string s;     cin >> k >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) {         me.push_back(i);       }     }     long long ans = 0, cnt = 0, idx = -1;     if (k == 0) {       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  1 ) {           ans += sum(cnt);           cnt = 0;         } else {           cnt++;         }       }       ans += sum(cnt);     } else {       long long fst = -1;       for (int i = 0; i < me.size(); i++) {         int idx = me[i];         cnt = 0;         if ((i + k - 1) == me.size() - 1) {           ans += ((idx - fst) * (s.size() - me[i + k - 1]));         } else if (i + k - 1 < me.size() - 1) {           ans += ((idx - fst) * (me[i + k] - me[i + k - 1]));         }         fst = me[i];       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int f[50][50], mn[50], mx[50];   const int INF = 1e9;   int gm, gg, sm, ss;   long long d[51][51] = {}, nd[51][51];   bool cang[50], cans[50], canb[50];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (int)(n); ++i)       for (int j = 0; j < (int)(n); ++j) f[i][j] = INF;     for (int i = 0; i < (int)(n); ++i) f[i][i] = 0;     for (int i = 0; i < (int)(m); ++i) {       int from, to, w;       scanf( %d%d%d , &from, &to, &w), --from, --to;       f[from][to] = min(f[from][to], w);       f[to][from] = min(f[to][from], w);     }     scanf( %d%d%d%d , &gm, &gg, &sm, &ss);     for (int k = 0; k < (int)(n); ++k)       for (int i = 0; i < (int)(n); ++i)         for (int j = 0; j < (int)(n); ++j) {           f[i][j] = min(f[i][j], f[i][k] + f[k][j]);         }     for (int i = 0; i < (int)(n); ++i) {       mn[i] = INF, mx[i] = -INF;       for (int j = 0; j < (int)(n); ++j)         if (i != j) {           mn[i] = min(mn[i], f[i][j]);           mx[i] = max(mx[i], f[i][j]);         }     }     long long ans = 0;     for (int gco = 0; gco < (int)(n); ++gco)       for (int bco = 0; bco < (int)(n); ++bco)         if (mn[gco] < mx[bco] || (mn[gco] == mx[bco] && gco < bco)) {           if (gco == bco) continue;           bool ok = true;           for (int i = 0; i < (int)(n); ++i) {             if (i == gco) {               cang[i] = true;               cans[i] = canb[i] = false;             } else if (i == bco) {               canb[i] = true;               cang[i] = cans[i] = false;             } else {               cang[i] = mn[i] < mn[gco] || (mn[i] == mn[gco] && i < gco);               canb[i] = mx[i] > mx[bco] || (mx[i] == mx[bco] && i > bco);               cans[i] = false;               for (int j = 0; j < (int)(n); ++j)                 if (j != i &&                     (f[i][j] > mn[gco] || (f[i][j] == mn[gco] && i > gco)) &&                     (f[i][j] < mx[bco] || (f[i][j] == mx[bco] && i < bco))) {                   cans[i] = true;                   break;                 }               if (!cang[i] && !cans[i] && !canb[i]) {                 ok = false;                 break;               }             }           }           if (!ok) continue;           memset(d, 0, sizeof d);           d[0][0] = 1;           for (int i = 0; i < (int)(n); ++i) {             memset(nd, 0, sizeof nd);             for (int g = 0; g < (int)(gg + 1); ++g)               for (int s = 0; s < (int)(ss + 1); ++s)                 if (d[g][s] != 0) {                   if (cang[i]) {                     nd[g + 1][s] += d[g][s];                   }                   if (cans[i]) {                     nd[g][s + 1] += d[g][s];                   }                   if (canb[i]) {                     nd[g][s] += d[g][s];                   }                 }             memcpy(d, nd, sizeof nd);           }           for (int g = gm; g <= gg; ++g)             for (int s = sm; s <= ss; ++s) {               ans += d[g][s];             }           d[gg][ss] -= ans;         }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   struct P {     long long x, y;     P() {}     P(long long _x, long long _y) : x(_x), y(_y) {}     P operator+(const P &o) { return P(x + o.x, y + o.y); }     P operator-(const P &o) { return P(x - o.x, y - o.y); }     long long operator*(const P &o) {       if (!x && !o.x) return 0;       if (!x) return -y;       if (!o.x) return o.y;       if (fabs(1.0 * o.y / o.x - 1.0 * y / x) < 1e-10) {         return 0;       }       if (1.0 * y / x < 1.0 * o.y / o.x) {         return 1;       } else {         return -1;       }     }     bool operator<(const P &o) const { return x == o.x ? y < o.y : x < o.x; }   };   struct E {     int tot;     int lnk[N], nxt[N << 1], son[N << 1];     P w[N << 1];     E() { tot = 1; }     void add(int x, int y, P pt) {       nxt[++tot] = lnk[x], son[tot] = y, w[tot] = pt, lnk[x] = tot;     }     void adde(int x, int y, P pt) { add(x, y, pt), add(y, x, pt); }   } S, T;   int n, m, k, all, mx, gid, gu, gv;   int cnt, na, nb, s1, s2, qaq;   int las[N], sz[N], dl[N];   P pa[N << 3], qa[N << 3], qb[N << 3], ans[N << 3];   void build(int x, int p) {     for (int j = S.lnk[x]; j; j = S.nxt[j]) {       if (S.son[j] != p) {         T.adde(las[x], ++k, P(0, 0));         T.adde(k, S.son[j], S.w[j]);         las[x] = k;         build(S.son[j], x);       }     }   }   void dfs_sz(int x, int p) {     sz[x] = 1;     for (int j = T.lnk[x], v; j; j = T.nxt[j]) {       if (!dl[j >> 1] && T.son[j] != p) {         dfs_sz(T.son[j], x);         sz[x] = sz[x] + sz[T.son[j]];         v = min(sz[T.son[j]], all - sz[T.son[j]]);         if (mx < v) {           mx = v;           gid = j;           gu = x, gv = T.son[j];         }       }     }   }   void dfs_calc(int x, int p, P pt) {     pa[++cnt] = pt;     for (int j = T.lnk[x]; j; j = T.nxt[j]) {       if (!dl[j >> 1] && T.son[j] != p) {         dfs_calc(T.son[j], x, pt + T.w[j]);       }     }   }   void making(int &num, P *pt) {     sort(pa + 1, pa + cnt + 1);     pt[num = 1] = pa[1];     for (int i = 2; i <= cnt; ++i) {       for (; num >= 2; --num) {         if ((pa[i] - pt[num - 1]) * (pt[num] - pt[num - 1]) > 0) {           break;         }       }       pt[++num] = pa[i];     }   }   void merge() {     if (!na || !nb) {       for (int i = 1, t = max(na, nb); i <= t; ++i) {         ans[++qaq] = na ? qa[i] : qb[i];       }       return;     }     ans[++qaq] = qa[1] + qb[1];     for (int u = 2, v = 2; u <= na || v <= nb;) {       if (u > na) {         ans[++qaq] = qa[u - 1] + qb[v++];       } else if (v > nb) {         ans[++qaq] = qa[u++] + qb[v - 1];       } else {         P du = qa[u] - qa[u - 1], dv = qb[v] - qb[v - 1];         if (du * dv < 0) {           ans[++qaq] = qa[u++] + qb[v - 1];         } else {           ans[++qaq] = qa[u - 1] + qb[v++];         }       }     }   }   void divide(int x, int t) {     if (t == 1) {       return;     }     all = t, mx = gu = gv = 0;     dfs_sz(x, 0);     int x1 = gv, s1 = sz[gv], x2 = gu, s2 = all - s1;     dl[gid >> 1] = 1;     cnt = 0, dfs_calc(x1, x2, P(0, 0)), making(na, qa);     cnt = 0, dfs_calc(x2, x1, T.w[gid]), making(nb, qb);     merge();     divide(x1, s1);     divide(x2, s2);   }   long long val(P pt, int sl) { return pt.x * sl + pt.y; }   int main() {     scanf( %d%d , &n, &m), k = n;     for (int i = 1, x, y, z1, z2; i < n; ++i) {       scanf( %d%d%d%d , &x, &y, &z1, &z2);       S.adde(x, y, P(z1, z2));     }     for (int i = 1; i <= n; ++i) {       las[i] = i;     }     build(1, 0);     divide(1, k);     cnt = qaq;     memcpy(pa, ans, sizeof pa);     making(qaq, ans);     for (int i = 0, cur = 1; i < m; ++i) {       for (; cur < qaq; ++cur) {         if (val(ans[cur], i) > val(ans[cur + 1], i)) {           break;         }       }       printf( %lld , val(ans[cur], i));       putchar(i < m - 1 ?     :   n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool Check(long long A, long long B, long long T1, long long T2) {     if (!A && !B) return !T1 && !T2;     return !((T1 * A + T2 * B) % (A * A + B * B)) &&            !((T2 * A - T1 * B) % (A * A + B * B));   }   int main() {     long long X0, Y0, X1, Y1, X2, Y2;     cin >> X0 >> Y0 >> X1 >> Y1 >> X2 >> Y2;     cout << ((Check(X2, Y2, X1 - X0, Y1 - Y0) ||               Check(X2, Y2, Y1 - X0, -X1 - Y0) ||               Check(X2, Y2, -X1 - X0, -Y1 - Y0) ||               Check(X2, Y2, -Y1 - X0, X1 - Y0))                  ?  YES                   :  NO )          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     ;     cin.tie(NULL);     ;     int n, b;     double total = 0, maxx = 0;     cin >> n >> b;     double ar[n];     for (int i = 0; i < n; i++) {       cin >> ar[i];       total += ar[i];       maxx = max(maxx, ar[i]);     }     if (b + total < maxx * n) {       cout << -1 << endl;     } else {       double e = (b + total) / n;       for (int i = 0; i < n; i++) {         cout << fixed << setprecision(6) << e - ar[i] << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int l, r;     cin >> l >> r;     cout <<  YES  << endl;     for (long long int i = l; i <= r; i += 2) {       cout << i <<     << i + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long n, m;   char s[111111], t[111111];   bool ar[111111];   long long fail[111111], f[111111], ff[111111], dp[111111];   void kmp() {     int i = 0, j = -1;     fail[0] = -1;     while (i < m) {       while (j > -1 && t[i] != t[j]) j = fail[j];       i++, j++;       fail[i] = j;     }     i = 1, j = 0;     while (i <= n) {       while (j > -1 && s[i] != t[j]) j = fail[j];       j++;       if (j == m) ar[i] = 1, j = fail[j];       i++;     }   }   int main() {     scanf( %s , s + 1);     scanf( %s , t);     n = strlen(s + 1);     m = strlen(t);     kmp();     for (int i = 1; i <= n; i++) dp[i] = (ar[i] ? i - m + 1 : dp[i - 1]);     for (int i = 1; i <= n; i++) {       int l = dp[i];       if (l) {         f[i] = (f[i - 1] + l) % mod;         f[i] = (f[i] + ff[l - 1]) % mod;         ff[i] = (ff[i - 1] + f[i]) % mod;       }     }     cout << f[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int dx4[] = {-1, 0, 1, 0};   const int dy4[] = {0, 1, 0, -1};   const int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};   const int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};   const int dxk[] = {-2, -2, -1, -1, 1, 1, 2, 2};   const int dyk[] = {-1, 1, -2, 2, -2, 2, -1, 1};   inline long long Int() {     long long inputNumber = 0;     char c = getchar_unlocked();     bool sign = true;     while (!((c >=  0  && c <=  9 ) || c ==  - )) c = getchar_unlocked();     if (c ==  - ) sign = false, c = getchar_unlocked();     while (c >=  0  && c <=  9 )       inputNumber = (inputNumber << 1) + (inputNumber << 3) + c -  0 ,       c = getchar_unlocked();     return sign ? inputNumber : -inputNumber;   }   template <class S, class T>   ostream& operator<<(ostream& out, const pair<S, T>& Pair) {     out <<  {  << Pair.first <<  ,   << Pair.second <<  } ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, const vector<T>& Vector) {     out <<  [ ;     for (int i = 0; i < (int)Vector.size(); ++i) {       out << Vector[i];       if (i + 1 < (int)Vector.size()) out <<  ,  ;     }     out <<  ] ;     return out;   }   template <class S, class T>   ostream& operator<<(ostream& out, const map<S, T>& Map) {     out <<  [ n ;     for (const auto& x : Map) {       out <<  { Key:   << x.first <<   , Value:   << x.second <<   } n ;     }     out <<  ] n ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, const multiset<T>& Set) {     out <<  { ;     for (auto it = Set.begin(); it != Set.end();) {       out << *it;       it++;       if (it != Set.end()) out <<  ,  ;     }     out <<  } ;     return out;   }   void solve();   int main() { solve(); }   const double eps = 1e-10;   const int mod = 1e9 + 7;   const int N = 2e5 + 5;   void solve() {     string s;     cin >> s;     int len = ((int)(s).size());     string sd =   ;     string org =   ;     int br = -1;     for (int i = len - 1; i >= 0; --i) {       if (s[i] !=  a ) {         sd += s[i];       } else {         br = i;         break;       }     }     if (sd ==   ) {       bool ok = true;       for (int i = 0; i < (((int)(s).size())); ++i) {         if (s[i] !=  a ) {           ok = false;           break;         }       }       if (ok) {         cout << s;       } else {         puts( :( );       }       return;     }     reverse((sd).begin(), (sd).end());     for (int i = 0; i <= br; ++i) {       org += s[i];     }     string strip =   ;     for (int i = 0; i < (((int)(org).size())); ++i)       if (org[i] !=  a ) strip += org[i];     if (strip == sd) {       cout << org;       return;     }     string tot = strip + sd;     if (((int)(tot).size()) % 2) {       puts( :( );       return;     }     int mid = ((int)(tot).size()) / 2;     string a = tot.substr(0, mid);     string b = tot.substr(mid);     if (a != b) {       puts( :( );       return;     }     reverse((s).begin(), (s).end());     reverse((a).begin(), (a).end());     if (s.substr(0, mid) == a) {       reverse((s).begin(), (s).end());       int len = ((int)(s).size()) - mid;       for (int i = 0; i < (len); ++i) putchar(s[i]);       return;     }     puts( :( );   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9;   const long long inf64 = 1e18;   const long long MOD = inf + 7;   long long a[100005], p[100005];   long long n, m;   bool check(long long mid) {     long long last = 0;     for (long long i = 0; i < (long long)n; i++) {       if (last == m) return true;       if (p[last] > a[i]) {         while (last < m && p[last] - a[i] <= mid) last++;         continue;       }       long long mn = a[i] - mid;       if (mn > p[last]) return false;       long long id1 =           upper_bound(p, p + m, a[i] + mid - 2 * (a[i] - p[last])) - p;       long long id2 =           upper_bound(p, p + m, a[i] + (mid - (a[i] - p[last])) / 2) - p;       last = max(last, id1);       last = max(last, id2);     }     return (last == m);   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     ;     cin >> n >> m;     for (long long i = 0; i < (long long)n; i++) cin >> a[i];     for (long long i = 0; i < (long long)m; i++) cin >> p[i];     long long ans, low = 0, high = 1e18, mid;     while (low <= high) {       mid = (low + high) / 2;       if (check(mid)) {         ans = mid;         high = mid - 1;       } else {         low = mid + 1;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1007, K = 1007, INF = LONG_MAX;   int i, j, n, x, y;   int gcd(int x, int y) {     while (x && y) {       if (x > y)         x %= y;       else         y %= x;     }     return x | y;   }   multiset<int> m;   vector<int> ans;   int main() {     cin >> n;     for (i = 0; i < n * n; i++) {       cin >> x;       m.insert(x);     }     ans.push_back(*--m.end());     m.erase(--m.end());     while (!m.empty()) {       x = *--m.end();       m.erase(--m.end());       for (j = 0; j < ans.size(); j++) {         int v = gcd(x, ans[j]);         m.erase(m.find(v));         m.erase(m.find(v));       }       ans.push_back(x);     }     for (i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e7 + 5;   const int M = 25;   int A[M], B[M], n, m, x, y, cnt;   int dp[M * 4][M * 4];   void Min(int &x, int y) { x = min(x, y); }   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> A[i];     for (int i = 0; i < n; ++i) cin >> B[i];     memset(dp, 0x3f, sizeof(dp));     dp[0][0] = 0;     for (int i = 0; i < n * 4; ++i) {       for (int j = 0; j <= n + n; ++j)         if (dp[i][j] <= 1e9) {           Min(dp[i + 1][j + 1], dp[i][j] + A[i % n]);           if (j) Min(dp[i + 1][j - 1], dp[i][j] + B[i % n]);         }     }     if (m <= 3)       cout << dp[n * m][0] << endl;     else       cout << dp[n * 4][0] + (m - 4) / 2 * (dp[n * 4][0] - dp[n * 2][0]) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 2 * acos(0.0);   const int INF = 0x3f3f3f3f;   const double inf = 1.0 / 0.0;   void solve();   void Adi() {     ios::sync_with_stdio(false);     cin.tie(0);   }   int main() {     Adi();     solve();     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs           <<   n ;     return 0;   }   void solve() {     long long n, x, tt = 0, dis = 0, rem = 0;     char s;     cin >> n >> x;     vector<long long> v;     for (int i = 0; i < n; i++) {       long long q;       cin >> s >> q;       if (s ==  - ) q = -q;       v.push_back(q);     }     for (int i = 0; i < n; i++) {       if (v[i] >= 0)         x += v[i];       else if (v[i] < 0) {         if (x >= abs(v[i]))           x += v[i];         else           dis++;       }     }     cout << x <<     << dis;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z, t1, t2, t3;     cin >> x >> y >> z >> t1 >> t2 >> t3;     unsigned long long xy, xz;     if (x > y) {       xy = x - y;     } else {       xy = y - x;     }     if (x > z) {       xz = x - z;     } else {       xz = z - x;     }     unsigned long long stair = xy * t1;     unsigned long long lift = (xz + xy) * t2 + t3 * 3;     if (lift > stair) {       cout <<  NO ;     } else {       cout <<  YES ;     }     return 0;   }


#include <bits/stdc++.h>   int mat[1010][1010];   int counts = 0;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) scanf( %d , &mat[i][j]);     }     counts = 0;     for (int i = 1; i <= n; i++) counts += mat[i][i];     counts %= 2;     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int a;       scanf( %d , &a);       if (a == 1 || a == 2) {         int b;         scanf( %d , &b);         mat[b][b] = 1 - mat[b][b];         counts = 1 - counts;       } else         printf( %d , counts);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 20;   int x[maxn], y[maxn];   int main() {     int n, m;     while (cin >> n >> m) {       for (int i = 1; i <= n; i++) scanf( %d , &x[i]);       for (int j = 1; j <= m; j++) scanf( %d , &y[j]);       int ans = 0;       int p1 = 1, p2 = 1;       long long sum1 = 0, sum2 = 0;       while (p1 <= n || p2 <= m) {         if (sum1 <= sum2) {           if (p1 > n) break;           sum1 += x[p1++];         } else {           if (p2 > m) break;           sum2 += y[p2++];         }         if (sum1 == sum2) ans++;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int w, h, k;     cin >> w >> h >> k;     int s = 0;     w -= 2;     for (int i = 0; i < k; i++) {       s += (w + h) * 2;       w -= 4;       h -= 4;     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   long long w[100005], mon[305], droz[305], wlazi[305], t;   long long dfs(long long co) {     long long x;     if (!droz[co]) return mon[co];     x = dfs(droz[co]);     t -= x;     mon[co] += x;     return mon[co];   }   int main() {     long long n, q, a, b, c, mod = 1000000007;     scanf( %I64d%I64d%I64d , &n, &q, &t);     for (a = 1; a <= n; a++) scanf( %I64d , &mon[a]);     while (q--) {       scanf( %I64d%I64d , &a, &b);       droz[b] = a;       wlazi[a] = 1;     }     for (a = 1; a <= n; a++) {       for (b = droz[a]; b && b != a; b = droz[b])         ;       if (b == a) {         printf( 0 n );         return 0;       }     }     for (a = 1; a <= n; a++)       if (!wlazi[a]) dfs(a);     if (t < 0) {       printf( 0 n );       return 0;     }     w[0] = 1;     for (a = 1; a <= n; a++) {       for (b = mon[a]; b <= t; b++) {         w[b] += w[b - mon[a]];         w[b] %= mod;       }     }     printf( %I64d n , w[t]);     getchar();     getchar();     return 0;   }


#include <bits/stdc++.h>   const bool DEBUG = false;   using namespace std;   const long long maxn = 2e5 + 5;   const long long INF = 1e18 + 1;   const long long M = 1e9 + 7;   const int lg = 21;   int n, m, x[maxn], b[maxn], a[maxn], y[maxn];   vector<pair<int, int> > v;   set<int> s;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> x[i] >> y[i];     for (int i = 0; i < m; i++) cin >> a[i] >> b[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[j] == b[j] or x[i] == y[i]) continue;         if (a[j] == x[i] and b[j] == y[i]) continue;         if (a[j] == y[i] and b[j] == x[i]) continue;         if (a[j] != x[i] and a[j] != y[i] and b[j] != x[i] and b[j] != y[i])           continue;         if (a[j] == x[i] or a[j] == y[i])           s.insert(a[j]);         else           s.insert(b[j]);       }     }     if (s.size() == 1) return cout << (*s.begin()) << endl, 0;     for (int i = 0; i < n; i++) {       vector<int> v;       set<int> s;       for (int j = 0; j < m; j++) {         if (a[j] == b[j] or x[i] == y[i]) continue;         if (a[j] == x[i] and b[j] == y[i]) continue;         if (a[j] == y[i] and b[j] == x[i]) continue;         if (a[j] != x[i] and a[j] != y[i] and b[j] != x[i] and b[j] != y[i])           continue;         if (x[i] == a[j] or x[i] == b[j])           s.insert(x[i]);         else           s.insert(y[i]);       }       if (s.size() > 1) return cout << -1 << endl, 0;     }     for (int i = 0; i < m; i++) {       vector<int> v;       set<int> s;       for (int j = 0; j < n; j++) {         if (a[i] == b[i] or x[j] == y[j]) continue;         if (a[i] == x[j] and b[i] == y[j]) continue;         if (a[i] == y[j] and b[i] == x[j]) continue;         if (a[i] != x[j] and a[i] != y[j] and b[i] != x[j] and b[i] != y[j])           continue;         if (x[j] == a[i] or a[i] == y[j])           s.insert(a[i]);         else           s.insert(b[i]);       }       if (s.size() > 1) return cout << -1 << endl, 0;     }     cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int list[100000];     for (int i = 0; i < n; i++) {       cin >> list[i];     }     int max = 1;     int temp = 1;     for (int i = 0; i < n - 1; i++) {       if (list[i] < list[i + 1]) {         temp++;       } else {         if (max < temp) {           max = temp;         }         temp = 1;       }     }     if (max < temp) {       max = temp;     }     cout << max <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long T, A, B, res;   vector<long long> P;   int main() {     cin >> T >> A >> B;     if (T == 1) {       if (A == 1) {         if (B == 1) {           res = -1;         }       } else {         if (B % A == 0) {           ++res;         }         while (B > 0) {           P.push_back(B % A);           B /= A;         }         long long cp = 1;         for (int i = 0; i < ((int)P.size()); i++) {           A -= P[i] * cp;           cp *= T;         }         if (A == 0) {           ++res;         }       }     } else {       if (A < T) {         if (B == A) {           res = 1;         }       } else if (A == T) {         if (B == A) {           res = 2;         }       } else {         if (A == B) {           ++res;         }         while (B > 0) {           P.push_back(B % A);           B /= A;         }         long long cp = 1;         for (int i = 0; i < ((int)P.size()); i++) {           A -= P[i] * cp;           cp *= T;         }         if (A == 0) {           ++res;         }       }     }     if (res == -1) {       cout <<  inf n ;     } else {       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000 * 1000 * 1000 + 7;   const int N = 1000 * 1000 + 7;   long long a[N];   multiset<long long> st;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) scanf( %I64d , a + i);     long long ans = 0;     for (int i = 0; i < n; ++i) {       if (st.size() > 0) {         if (*st.begin() < a[i]) {           ans += a[i] - *st.begin();           st.erase(st.begin());           st.insert(a[i]);         }       }       st.insert(a[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[200010], cnt, id, k[200010];   double ans = -1, pre[200010];   double f(long long x, long long mid) {     return ((pre[n] - pre[n - x]) + (pre[mid] - pre[mid - x - 1])) / (x * 2 + 1);   }   signed main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     sort(a + 1, a + 1 + n);     for (long long i = 1; i <= n; i++) {       pre[i] = pre[i - 1] + a[i];     }     for (long long i = 1; i <= n; i++) {       long long l = 1, r = min(i - 1, n - i);       long long num = 0;       while (l <= r) {         long long mid = (l + r) / 2;         if (f(mid, i) >= f(mid - 1, i))           l = mid + 1, num = mid;         else           r = mid - 1;       }       if (f(num, i) - (pre[i] - pre[i - 1]) > ans) {         ans = f(num, i) - (pre[i] - pre[i - 1]);         cnt = num, id = i;       }     }     printf( %lld n , 2 * cnt + 1);     for (long long i = id - cnt; i <= id; i++) printf( %lld  , a[i]);     for (long long i = n - cnt + 1; i <= n; i++) printf( %lld  , a[i]);     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; }   const int MAX = 1e5;   const long long MOD = 1e9 + 7;   const long long inf = 1e18;   int a[MAX + 5];   int main() {     ios_base::sync_with_stdio(false);     int n, m, r, i, j;     long long ans = 0;     cin >> n >> m;     a[0] = 1;     for ((i) = (1); (i) <= (m); ++i) cin >> a[i];     i = 0;     while (i < m) {       if (a[i + 1] > a[i])         ans += (a[i + 1] - a[i]);       else if (a[i + 1] < a[i])         ans += (n - a[i] + a[i + 1]);       i++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 10;   class Edge {    public:     long long dest, weight, cost;     Edge() {       dest = 0;       weight = 0;       cost = 0;     }   };   class Compare {    public:     bool operator()(pair<long long, long long>& a,                     pair<long long, long long>& b) {       long long cura = a.first * a.second;       long long curb = b.first * b.second;       long long futa = (a.first / 2) * a.second;       long long futb = (b.first / 2) * b.second;       return (cura - futa) < (curb - futb);     }   };   vector<Edge> adj[MAXN];   long long numLeaves[MAXN], par[MAXN];   bool visited[MAXN];   void dfs(long long cur) {     visited[cur] = true;     if (adj[cur].size() == 1 && visited[adj[cur][0].dest]) {       numLeaves[cur] = 1;       return;     }     numLeaves[cur] = 0;     for (auto i : adj[cur]) {       if (!visited[i.dest]) {         par[i.dest] = cur;         dfs(i.dest);         numLeaves[cur] += numLeaves[i.dest];       }     }   }   void solve() {     long long n, s;     cin >> n >> s;     for (long long i = 0; i < n + 1; i++) {       adj[i].clear();       numLeaves[i] = 0;       par[i] = -1;       visited[i] = false;     }     for (long long i = 1; i < n; i++) {       long long x, y, w, c;       cin >> x >> y >> w >> c;       x--, y--;       Edge cur;       cur.dest = y;       cur.weight = w;       cur.cost = c;       adj[x].push_back(cur);       cur.dest = x;       adj[y].push_back(cur);     }     dfs(0);     priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                    Compare>         oneCost, twoCost;     long long sum = 0;     for (long long i = 0; i < n; i++) {       for (auto j : adj[i]) {         if (par[j.dest] == i) {           sum += (numLeaves[j.dest]) * (j.weight);           if (j.cost == 1)             oneCost.push(make_pair(j.weight, numLeaves[j.dest]));           else             twoCost.push(make_pair(j.weight, numLeaves[j.dest]));         }       }     }     vector<long long> oneDif, twoDif;     while (!oneCost.empty()) {       pair<long long, long long> cur = oneCost.top();       oneCost.pop();       long long fut = (cur.first / 2) * (cur.second);       long long dif = (cur.first) * (cur.second) - fut;       oneDif.push_back(dif);       cur.first /= 2;       if (cur.first != 0) oneCost.push(cur);     }     while (!twoCost.empty()) {       pair<long long, long long> cur = twoCost.top();       twoCost.pop();       long long fut = (cur.first / 2) * (cur.second);       long long dif = (cur.first) * (cur.second) - fut;       twoDif.push_back(dif);       cur.first /= 2;       if (cur.first != 0) twoCost.push(cur);     }     long long cost = LLONG_MAX;     for (long long i = 1; i < oneDif.size(); i++) oneDif[i] += oneDif[i - 1];     for (long long i = 1; i < twoDif.size(); i++) twoDif[i] += twoDif[i - 1];     if (sum <= s) cost = 0;     long long l = 0, h = twoDif.size() - 1;     long long ans = -1;     while (l <= h) {       long long mid = (l + h) / 2;       if (sum - twoDif[mid] <= s) {         ans = mid;         h = mid - 1;       } else         l = mid + 1;     }     if (ans != -1) {       cost = min(cost, 2 * (ans + 1));     }     for (long long i = 0; i < oneDif.size(); i++) {       long long l = 0, h = twoDif.size() - 1;       long long cur = sum - oneDif[i];       if (cur <= s) {         cost = min(cost, i + 1);         break;       }       long long ans = -1;       while (l <= h) {         long long mid = (l + h) / 2;         if (cur - twoDif[mid] <= s) {           ans = mid;           h = mid - 1;         } else           l = mid + 1;       }       if (ans != -1) {         long long temp = (i + 1) + (ans + 1) * 2;         cost = min(temp, cost);       }     }     cout << cost <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, mx, now, ans;   int main() {     scanf( %lld , &n);     mx = 2 * n - 1;     while (now * 10 + 9 <= mx) now = now * 10 + 9;     for (long long k = now; k <= mx; k += now + 1) {       long long d = max(k - n, 1ll), u = max(k - d, d);       ans += (u - d + 1) / 2;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const long long mo = 1e9 + 7;   int n, m, k, nn;   template <typename T>   inline void read(T &X) {     X = 0;     int w = 0;     char ch = 0;     while (!isdigit(ch)) {       w |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();     if (w) X = -X;   }   vector<pair<int, int>> vc[3], vv[3], ys[maxn * 5];   int sum[(maxn * 5) << 2], fg[(maxn * 5) << 2];   void build(int rt, int l, int r, int v) {     sum[rt] = fg[rt] = v;     if (l == r) {       return;     }     int mid = (l + r) >> 1;     build((rt << 1), l, mid, v);     build((rt << 1 | 1), mid + 1, r, v);   }   void pu(int rt) { sum[rt] = sum[(rt << 1)] + sum[(rt << 1 | 1)]; }   void pd(int rt) {     if (fg[rt]) {       sum[(rt << 1)] += fg[rt];       sum[(rt << 1 | 1)] += fg[rt];       fg[(rt << 1)] += fg[rt];       fg[(rt << 1 | 1)] += fg[rt];       fg[rt] = 0;     }   }   void pdd(int rt) {     if (fg[rt]) {       sum[(rt << 1)] = sum[rt];       sum[(rt << 1 | 1)] = sum[rt];       fg[(rt << 1)] = fg[(rt << 1 | 1)] = 1;       fg[rt] = 0;     }   }   void update(int rt, int l, int r, int ql, int qr, int v) {     if (ql <= l && r <= qr) {       sum[rt] = v;       fg[rt] = 1;       return;     }     pdd(rt);     int mid = (l + r) >> 1;     if (ql <= mid) update((rt << 1), l, mid, ql, qr, v);     if (qr > mid) update((rt << 1 | 1), mid + 1, r, ql, qr, v);   }   void add(int rt, int l, int r, int p, int v) {     if (p <= l && r <= p) {       sum[rt] += v;       fg[rt] += v;       return;     }     pd(rt);     int mid = (l + r) >> 1;     if (p <= mid) add((rt << 1), l, mid, p, v);     if (p > mid) add((rt << 1 | 1), mid + 1, r, p, v);     pu(rt);   }   int query1(int rt, int l, int r, int q) {     if (q <= l && r <= q) {       return sum[rt];     }     pdd(rt);     int mid = (l + r) >> 1;     if (q <= mid) return query1((rt << 1), l, mid, q);     if (q > mid) return query1((rt << 1 | 1), mid + 1, r, q);   }   long long query2(int rt, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) {       return sum[rt];     }     pd(rt);     int mid = (l + r) >> 1;     long long ans = 0;     if (ql <= mid) ans = query2((rt << 1), l, mid, ql, qr);     if (qr > mid) ans += query2((rt << 1 | 1), mid + 1, r, ql, qr);     return ans;   }   void solve() {     nn = 1000000;     read(n);     read(m);     for (int i = (1); i <= (n); i++) {       int y, lx, rx;       read(y);       read(lx);       read(rx);       if (lx == 0)         vc[0].push_back({rx, y});       else         vc[1].push_back({lx, y});     }     for (int i = (1); i <= (m); i++) {       int x, ly, ry;       read(x);       read(ly);       read(ry);       if (ly == 0)         vv[0].push_back({x, ry});       else         vv[1].push_back({x, ly});     }     for (int i = (0); i <= (1); i++) {       if (!vc[i].empty()) sort(vc[i].begin(), vc[i].end());       if (!vv[i].empty()) sort(vv[i].begin(), vv[i].end());     }     reverse(vc[1].begin(), vc[1].end());     int sz0 = vv[0].size() - 1;     int sz1 = vv[1].size() - 1;     build(1, 0, nn, 0);     for (auto i : vc[1]) {       int fg = 1;       while (fg) {         fg = 0;         if (sz1 >= 0 && sz0 >= 0 && vv[0][sz0].first < vv[1][sz1].first &&             vv[1][sz1].first >= i.first) {           update(1, 0, nn, vv[1][sz1].second, nn, vv[1][sz1].first);           sz1--;           fg = 1;         } else if (sz0 < 0 && sz1 >= 0 && vv[1][sz1].first >= i.first) {           update(1, 0, nn, vv[1][sz1].second, nn, vv[1][sz1].first);           sz1--;           fg = 1;         } else if (sz1 >= 0 && sz0 >= 0 && vv[0][sz0].first > vv[1][sz1].first &&                    vv[0][sz0].first >= i.first) {           update(1, 0, nn, 0, vv[0][sz0].second, vv[0][sz0].first);           sz0--;           fg = 1;         } else if (sz1 < 0 && sz0 >= 0 && vv[0][sz0].first >= i.first) {           update(1, 0, nn, 0, vv[0][sz0].second, vv[0][sz0].first);           sz0--;           fg = 1;         }       }       int pos = query1(1, 0, nn, i.second);       ys[pos].push_back(i);     }     build(1, 0, nn, 0);     int j = 0, k = 0;     vv[0].push_back({nn, nn});     int nj = vv[0].size(), nk = vv[1].size();     for (auto i : vc[0]) {       add(1, 0, nn, i.second, 1);     }     int i = 0, ni = vc[0].size();     long long ans = 0;     while (j < nj || k < nk) {       pair<int, int> p;       if (j == nj)         p = vv[1][k++];       else if (k == nk)         p = vv[0][j++];       else if (vv[0][j].first < vv[1][k].first)         p = vv[0][j++];       else         p = vv[1][k++];       while (i < ni && vc[0][i].first < p.first) {         add(1, 0, nn, vc[0][i].second, -1);         i++;       }       if (k && p == vv[1][k - 1])         ans += query2(1, 0, nn, p.second, nn);       else         ans += query2(1, 0, nn, 0, p.second);       if (p.second == nn) ans++;       for (auto s : ys[p.first]) add(1, 0, nn, s.second, 1);     }     printf( %lld n , ans);   }   int main() {     int T = 1, cas = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream &operator<<(ostream &os, pair<T1, T2> &p);   template <class T>   ostream &operator<<(ostream &os, vector<T> &v);   template <class T>   ostream &operator<<(ostream &os, set<T> &v);   template <class T1, class T2>   ostream &operator<<(ostream &os, map<T1, T2> &v);   const long long mod = 100000007;   const int N = 15;   int n, k;   bool check(vector<int> &a, int x) {     bool flag = true;     vector<int> v;     for (int i = 0; i < n; i++) {       if (v.size() == k) break;       if ((int)v.size() % 2) {         v.push_back(a[i]);       } else if (a[i] <= x) {         v.push_back(a[i]);       }     }     if (v.size() == k) {       return true;     }     v.clear();     for (int i = 0; i < n; i++) {       if (v.size() == k) break;       if ((int)v.size() % 2 == 0) {         v.push_back(a[i]);       } else if (a[i] <= x) {         v.push_back(a[i]);       }     }     if (v.size() == k) {       return true;     }     return false;   }   void TEST_CASES(int cas) {     scanf( %d %d , &n, &k);     vector<int> a(n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int low = *min_element(a.begin(), a.end()),         high = *max_element(a.begin(), a.end());     int ans = -1;     while (low <= high) {       int mid = (low + high) / 2;       ;       ;       if (check(a, mid)) {         high = mid - 1;         ans = mid;       } else {         low = mid + 1;       }     }     printf( %d n , ans);   }   int main() {     int t = 1, cas = 0;     while (t--) {       TEST_CASES(++cas);     }     return 0;   }   template <class T1, class T2>   ostream &operator<<(ostream &os, pair<T1, T2> &p) {     os <<  {  << p.first <<  ,   << p.second <<  }  ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, vector<T> &v) {     os <<  [  ;     for (int i = 0; i < v.size(); i++) {       os << v[i] <<    ;     }     os <<   ] ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, set<T> &v) {     os <<  [  ;     for (T i : v) {       os << i <<    ;     }     os <<   ] ;     return os;   }   template <class T1, class T2>   ostream &operator<<(ostream &os, map<T1, T2> &v) {     for (auto i : v) {       os <<  Key :   << i.first <<   , Value :   << i.second << endl;     }     return os;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int num[maxn];   long long ret;   int n;   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &num[i]);   }   void print() {     for (int i = 1; i < n; i++) {       int j = 0;       for (; j < 30; j++)         if (i + (1 << j) > n) break;       j--;       ret += num[i];       num[i + (1 << j)] += num[i];       printf( %I64d n , ret);     }   }   int main() {     init();     print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T = 1;     cin >> T;     while (T--) {       int64_t w, h;       cin >> w >> h;       vector<int64_t> hor1, hor2, ver1, ver2;       int64_t k;       int64_t q;       cin >> k;       for (int i = 0; i < k; ++i) cin >> q, hor1.push_back(q);       cin >> k;       for (int i = 0; i < k; ++i) cin >> q, hor2.push_back(q);       cin >> k;       for (int i = 0; i < k; ++i) cin >> q, ver1.push_back(q);       cin >> k;       for (int i = 0; i < k; ++i) cin >> q, ver2.push_back(q);       cout << max({(hor1.back() - hor1[0]) * h, (hor2.back() - hor2[0]) * h,                    (ver1.back() - ver1[0]) * w, (ver2.back() - ver2[0]) * w})            <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     long long i;     cin >> n >> m;     long long cnt = 0;     for (i = 1; i <= n; i++) {       cnt += (m + i) / 5 - i / 5;     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, size_t N>   long long SIZE(const T (&t)[N]) {     return N;   }   template <typename T>   long long SIZE(const T &t) {     return t.size();   }   string to_string(const string s, long long x1 = 0, long long x2 = 1e9) {     return     + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) +    ;   }   string to_string(const char *s) { return to_string((string)s); }   string to_string(const bool b) { return (b ?  true  :  false ); }   string to_string(const char c) { return string({c}); }   template <size_t N>   string to_string(const bitset<N> &b, long long x1 = 0, long long x2 = 1e9) {     string t =   ;     for (long long __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);          __iii__ <= __jjj__; ++__iii__) {       t += b[__iii__] +  0 ;     }     return     + t +    ;   }   template <typename A, typename... C>   string to_string(const A(&v), long long x1 = 0, long long x2 = 1e9,                    C... coords);   long long l_v_l_v_l = 0, t_a_b_s = 0;   template <typename A, typename B>   string to_string(const pair<A, B> &p) {     l_v_l_v_l++;     string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;     l_v_l_v_l--;     return res;   }   template <typename A, typename... C>   string to_string(const A(&v), long long x1, long long x2, C... coords) {     long long rnk = rank<A>::value;     string tab(t_a_b_s,    );     string res =   ;     bool first = true;     if (l_v_l_v_l == 0) res +=   n ;     res += tab +  [ ;     x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));     auto l = begin(v);     advance(l, x1);     auto r = l;     advance(r, (x2 - x1) + (x2 < SIZE(v)));     for (auto e = l; e != r; e = next(e)) {       if (!first) {         res +=  ,  ;       }       first = false;       l_v_l_v_l++;       if (e != l) {         if (rnk > 1) {           res +=   n ;           t_a_b_s = l_v_l_v_l;         };       } else {         t_a_b_s = 0;       }       res += to_string(*e, coords...);       l_v_l_v_l--;     }     res +=  ] ;     if (l_v_l_v_l == 0) res +=   n ;     return res;   }   void dbgm() { ; }   template <typename Heads, typename... Tails>   void dbgm(Heads H, Tails... T) {     cerr << to_string(H) <<   |  ;     dbgm(T...);   }   void FIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const long long N = 2e5 + 6;   int32_t main() {     FIO();     long long tc;     cin >> tc;     while (tc--) {       long long x, y;       cin >> x >> y;       long long n = x;       if (x == y)         n = x;       else if (x > y) {         n = x * y + y;       } else {         long long r = y % x;         n = y - r / 2;       }       assert(n <= (long long)2e18 and (n % x == y % n));       cout << n <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int k[1000010];   long long qpow(long long x, int n) {     long long ans = 1;     for (; n; n >>= 1, x = x * x % mod)       if (n & 1) ans = ans * x % mod;     return ans;   }   long long lpow(long long x, int n) {     long long ans = 1;     for (; n; n >>= 1, x *= x) {       if (n && x > mod) return mod;       if (n & 1) ans *= x;       if (ans > mod) return mod;     }     return ans;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, p;       scanf( %d%d , &n, &p);       for (int i = 0; i < n; i++) scanf( %d , &k[i]);       sort(k, k + n);       long long d = 0;       long long sl = 0, sr = 0, q = k[n - 1];       for (int i = n - 1; i >= 0; i--) {         if (q > k[i]) {           sl = sl * qpow(p, q - k[i]) % mod;           sr = sr * qpow(p, q - k[i]) % mod;           d = min(d * lpow(p, q - k[i]), mod);           q = k[i];         }         if (d)           d--, sr++;         else           d++, sl++;       }       sl = sl * qpow(p, q) % mod;       sr = sr * qpow(p, q) % mod;       printf( %lld n , (sl - sr + mod) % mod);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int UNDEF = -1;   const long long INF = 1e18;   template <typename T>   inline bool chkmax(T &aa, T bb) {     return aa < bb ? aa = bb, true : false;   }   template <typename T>   inline bool chkmin(T &aa, T bb) {     return aa > bb ? aa = bb, true : false;   }   int rint();   char rch();   long long rlong();   const int mv = 160;   const int mc = ((mv * (mv - 1)) / 2) + 1;   const int ma = 31;   bitset<mc> f[mv][ma];   void reset() {     for (int v = 0; v < mv; v++)       for (int ai = 0; ai < ma; ai++) f[v][ai].reset();   }   vector<int> solve(vector<int> &a) {     vector<int> fail;     sort(a.begin(), a.end());     int alim = a.size();     f[0][0][a[0]] = true;     {       int v = 0;       int klim = (v * (v + 1)) / 2;       if (f[(v)][alim - 1][klim]) {         return vector<int>({a[0]});       }     }     for (int v = 1; v < mv; v++) {       for (int sai = 0; sai < alim; sai++) {         for (int dai = sai; dai <= min(alim - 1, sai + 1); dai++) {           int shift = a[dai];           f[(v)][dai] |= (f[(v)-1][sai] << shift);         }       }       int klim = (v * (v + 1)) / 2;       if (f[(v)][alim - 1][klim]) {         vector<int> final;         int ai = alim - 1;         int k = klim;         for (int x = v; x >= 1; x--) {           final.push_back(a[ai]);           k -= a[ai];           if (f[x - 1][ai][k]) {             ai = ai;           } else {             ai--;           }         }         final.push_back(a[0]);         sort(final.begin(), final.end());         return final;       }       bitset<mc> filt;       filt.set();       filt >>= klim;       filt <<= klim;       for (int ai = 0; ai < alim; ai++) {         f[(v)][ai] &= filt;       }     }     return fail;   }   bool vans[mv + 2][mv + 2];   void recurse(vector<int> &r) {     int n = r.size() - 1;     if (n == 0) return;     vector<int> R;     R.push_back(-1);     int sum = 0;     for (int i = 1; i <= n; i++) {       sum += r[i];       R.push_back(sum);     }     int s = n - 1 - r[n];     vector<int> F;     F.resize(n + 1);     for (int v = 1; v <= n; v++) F[v] = R[v] - (v * (v - 1)) / 2;     int j = 1;     vector<int> rp = r;     for (int x = 1; x <= n; x++) vans[n][x] = 1;     vans[n][n] = 0;     vector<int> vj;     vj.resize(s + 1);     for (int d = 1; d <= s; d++) {       int vmin = max(1, vj[d - 1] + 1);       int ans = vmin;       for (int v = n - 1; v >= vmin; v--) {         if (F[v] < d) {           ans = v + 1;           break;         }       }       vj[d] = ans;     }     for (int d = 1; d <= s; d++) {       int j = vj[d];       assert(j <= n - 1);       vans[n][j] = 0;       vans[j][n] = 1;       rp[j]--;     }     rp.resize(rp.size() - 1);     recurse(rp);   }   vector<int> fgot;   int comb(vector<int> &va) {     auto got = solve(va);     fgot = got;     if (got.size() == 0) {       printf( =( n );       return 0;     } else {       vector<int> r;       r.push_back(-1);       for (auto &w : got) r.push_back(w);       recurse(r);       int sz = got.size();       printf( %d n , sz);       for (int x = 1; x <= sz; x++) {         for (int y = 1; y <= sz; y++) {           printf( %d , (int)vans[x][y]);         }         printf(  n );       }       return sz;     }   }   void test() {     reset();     memset(vans, 0, sizeof vans);     vector<int> va;     int p = (rand() % 100);     for (int x = 0; x <= 30; x++) {       if (rand() % 100 <= p) va.push_back(x);     }     if (va.size() == 0) va.push_back(rand() % 31);     int got = comb(va);     if (got != 0) {       set<int> s;       for (int x = 1; x <= got; x++) {         assert(vans[x][x] == 0);         int degout = 0;         for (int y = 1; y <= got; y++) {           degout += vans[x][y];         }         s.insert(degout);       }       for (int x = 1; x <= got; x++) {         for (int y = 1; y <= got; y++) {           if (x == y) continue;           assert(vans[x][y] + vans[y][x] == 1);         }       }       set<int> sa;       for (auto &w : va) sa.insert(w);       if (s != sa) {         for (auto &w : sa) printf( %d  , w);         printf(  sa n );         for (auto &w : s) printf( %d  , w);         printf(  s n );         for (auto &w : fgot) printf( %d  , w);         printf(  fgot n );         exit(1);       }     }   }   void go() {     for (int k = 0; k < 100000; k++) {       srand(clock());       test();     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n = rint();     vector<int> va;     va.reserve(n);     for (int i = 0; i < n; i++) {       int x = rint();       va.push_back(x);     }     comb(va);   }   static char stdinBuffer[1024];   static char *stdinDataEnd = stdinBuffer + sizeof(stdinBuffer);   static const char *stdinPos = stdinDataEnd;   void readAhead(size_t amount) {     size_t remaining = stdinDataEnd - stdinPos;     if (remaining < amount) {       memmove(stdinBuffer, stdinPos, remaining);       size_t sz = fread(stdinBuffer + remaining, 1,                         sizeof(stdinBuffer) - remaining, stdin);       stdinPos = stdinBuffer;       stdinDataEnd = stdinBuffer + remaining + sz;       if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0;     }   }   int rint() {     readAhead(16);     int x = 0;     bool neg = false;     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     if (*stdinPos ==  - ) {       ++stdinPos;       neg = true;     }     while (*stdinPos >=  0  && *stdinPos <=  9 ) {       x *= 10;       x += *stdinPos -  0 ;       ++stdinPos;     }     return neg ? -x : x;   }   char rch() {     readAhead(16);     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     char ans = *stdinPos;     ++stdinPos;     return ans;   }   long long rlong() {     readAhead(32);     long long x = 0;     bool neg = false;     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     if (*stdinPos ==  - ) {       ++stdinPos;       neg = true;     }     while (*stdinPos >=  0  && *stdinPos <=  9 ) {       x *= 10;       x += *stdinPos -  0 ;       ++stdinPos;     }     return neg ? -x : x;   }


#include <bits/stdc++.h>   using namespace std;   bool ps[1111111];   const int mod = 1e9 + 7;   int main() {     int p, k, c = 0;     long long ans = 1;     scanf( %d%d , &p, &k);     for (int i = 0; i < p; ++i) {       if (ps[i]) continue;       c++;       long long b = i;       while (!ps[b]) ps[b] = 1, b = (b * k) % p;     }     if (k != 1) c--;     while (c--) ans = (ans * p) % mod;     printf( %d n , int(ans));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     if (m == 3 && (n == 5 || n == 6)) {       printf( -1 n );       return 0;     }     for (int i = 0; i < m; ++i) printf( %d %d n , i, i * i + 10000000);     for (int i = 0; i < n - m; ++i) printf( %d %d n , i, -i * i - 10000000);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > vec[2102100];   pair<int, int> tr[2102100];   int lz[2102100];   int id[2102100];   int l[2102100];   int r[2102200];   int b[2102100];   int path[2102100];   int st[2102100];   void build(int p, int l, int r) {     tr[p] = {0, -1};     lz[p] = 0;     if (l == r) {       return;     }     int mid = l + r >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);   }   void pushup(int p) { tr[p] = max(tr[p << 1], tr[p << 1 | 1]); }   void pushdown(int p) {     if (lz[p]) {       lz[p << 1] = lz[p << 1 | 1] = lz[p];       lz[p] = 0;       tr[p << 1] = tr[p << 1 | 1] = tr[p];     }   }   pair<int, int> query(int p, int l, int r, int ll, int rr) {     if (ll <= l && rr >= r) {       return tr[p];     }     pushdown(p);     int mid = l + r >> 1;     pair<int, int> res = {0, -1};     if (ll <= mid) res = max(query(p << 1, l, mid, ll, rr), res);     if (rr > mid) res = max(query(p << 1 | 1, mid + 1, r, ll, rr), res);     return res;   }   void update(int p, int l, int r, int ll, int rr, pair<int, int> res) {     if (ll <= l && rr >= r) {       tr[p] = res;       lz[p] = 1;       return;     }     pushdown(p);     int mid = l + r >> 1;     if (ll <= mid) update(p << 1, l, mid, ll, rr, res);     if (rr > mid) update(p << 1 | 1, mid + 1, r, ll, rr, res);     pushup(p);   }   int main() {     int n, t;     cin >> n >> t;     for (int i = 1; i <= t; i++) {       cin >> id[i] >> l[i] >> r[i];       b[i * 2 - 1] = l[i];       b[i * 2] = r[i];     }     sort(b + 1, b + 1 + t * 2);     int len = unique(b + 1, b + 1 + t * 2) - b - 1;     build(1, 1, len);     for (int i = 1; i <= t; i++) {       l[i] = lower_bound(b + 1, b + 1 + len, l[i]) - b;       r[i] = lower_bound(b + 1, b + 1 + len, r[i]) - b;       vec[id[i]].push_back({l[i], r[i]});     }     for (int i = 1; i <= n; i++) {       pair<int, int> mx = {0, -1};       for (auto tt : vec[i]) {         mx = max(mx, query(1, 1, len, tt.first, tt.second));       }       mx.first++;       path[i] = mx.second;       mx.second = i;       for (auto tt : vec[i]) {         update(1, 1, len, tt.first, tt.second, mx);       }     }     pair<int, int> ans = query(1, 1, len, 1, len);     int u = ans.second;     int aa = n;     while (u != -1) {       st[u] = 1;       aa--;       u = path[u];     }     cout << aa << endl;     for (int i = 1; i <= n; i++) {       if (!st[i]) cout << i <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int MOD = 1000000007;   long long int MOD1 = 998244353;   mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());   unsigned long long power(unsigned long long x, int y, int p) {     unsigned 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;   }   void solve() {     long long int n;     cin >> n;     long long int res = 1;     for (int i = 1; i <= n; i++) {       res = (res * i) % MOD;     }     long long int p = power(2, n - 1, MOD);     res = (res - p + MOD) % MOD;     cout << res <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   long long qu(long long a, long long b) {     cout <<  ?   << a <<     << b << endl;     fflush(stdout);     string s;     cin >> s;     if (s[0] ==  x ) return 1;     return 2;   }   int main() {     string s;     while (1) {       cin >> s;       if (s !=  start ) return 0;       long long l = 1;       if (qu(0, 1) == 1) {         cout <<  ! 1 n ;         fflush(stdout);         continue;       }       while (qu(2 * l, l) == 1) l = l * 2LL;       long long r = min((l * 2LL), 1000000000LL);       l++;       long long x = l;       while (l < r) {         long long mid = (l + r) / 2;         if (qu(l - 1, mid) == 2)           l = mid + 1;         else           r = mid;       }       cout <<  !   << l <<   n ;       fflush(stdout);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MD = 1000000007;   inline void add(int &a, const int b) {     a += b;     if (a >= MD) a %= MD;   }   inline int mul(const int &a, const int &b) {     long long r = 1ll * a * b;     if (r >= MD) r %= MD;     return r;   }   int a[9], n, k;   bool vis[9];   bool ok(int x) {     if (x == 1) return 1;     vis[x] = 1;     if (!vis[a[x]] && ok(a[x])) return 1;     return 0;   }   bool check() {     for (int i = 1; i <= k; ++i) {       memset(vis, 0, sizeof vis);       if (!ok(a[i])) return 0;     }     return 1;   }   int dfs(int x) {     if (x == k + 1) {       if (check()) return 1;       return 0;     }     int ret = 0;     for (int i = 1; i <= k; ++i) a[x] = i, ret += dfs(x + 1);     return ret;   }   int main() {     scanf( %d%d , &n, &k);     int ans = 1;     for (int i = k + 1; i <= n; ++i) ans = mul(ans, n - k);     printf( %d n , mul(ans, dfs(1)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 10;   const int INF = 0x3f3f3f3f;   const int mod = 998244353;   vector<long long> v;   long long dfs(vector<long long> &v, int bit) {     vector<long long> v0, v1;     if (bit < 0 || v.size() == 0) return 0;     for (long long &j : v) {       if ((j >> bit) & 1)         v1.push_back(j);       else         v0.push_back(j);     }     if (v1.size() == 0) return dfs(v0, bit - 1);     if (v0.size() == 0) return dfs(v1, bit - 1);     return min(dfs(v0, bit - 1), dfs(v1, bit - 1)) + (1 << bit);   }   int main() {     int n;     v.clear();     scanf( %d , &n);     for (int i = 0; i < n; i++) {       long long x;       scanf( %lld , &x);       v.push_back(x);     }     long long ans = dfs(v, 30);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   inline int add(int a, int b) {     a += b;     return a >= 1000000007 ? a - 1000000007 : a;   }   inline int sub(int a, int b) {     a -= b;     return a < 0 ? a + 1000000007 : a;   }   inline int mul(int a, int b) { return (long long int)a * b % 1000000007; }   int Set(int N, int pos) { return N = N | (1 << pos); }   int Reset(int N, int pos) { return N = N & ~(1 << pos); }   bool Cheek(int N, int pos) { return (bool)(N & (1 << pos)); }   int a[1000005], b[1000005], lft[1000005], rgt[1000005], addina[1000005];   void Solve(int t) {     int i, j, k, n, ans = 0;     scanf( %d , &(n));     for (__typeof(i) i = 1; i <= n; i++) {       scanf( %d , &(a[i]));       addina[a[i]] = i;     }     for (__typeof(i) i = 1; i <= n; i++) scanf( %d , &(b[i]));     for (i = 1; i <= n; i++) {       int address = addina[b[i]];       int needlft = (n - address + i) % n;       lft[needlft]++;       int needrgt = (address - i + n) % n;       rgt[needrgt]++;     }     for (i = 0; i <= n; i++) {       ans = max(ans, lft[i]);       ans = max(ans, rgt[i]);     }     cout << ans << endl;   }   int main() {     int t, T;     T = 1;     for (__typeof(t) t = 1; t <= T; t++) {       Solve(t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-9;   struct Point {     long long x, y;     Point() {}     Point(long long x, long long y) : x(x), y(y) {}     Point operator-(const Point& a) { return Point(x - a.x, y - a.y); }     long long operator*(Point a) { return x * a.x + y * a.y; }     long long operator%(const Point& a) { return x * a.y - y * a.x; }     long double norm() { return x * x + y * y; }     long double len() { return sqrt(norm()); }     void read() { scanf( %lld%lld , &x, &y); }   } A[5], B[5];   bool operator==(const Point& a, const Point& b) {     return a.x == b.x && a.y == b.y;   }   long long ccw(Point A, Point B, Point C) {     long long t = (B - A) % (C - A);     if (t == 0) return 0;     if (t < 0) return -1;     return 1;   }   const long double PI = acos((long double)-1.0);   long double angle(Point a, Point o, Point b) {     a = a - o;     b = b - o;     long double res = acos((a * b) / sqrt(a.norm()) / sqrt(b.norm()));     while (res < -EPS) res += 2 * PI;     while (res >= 2 * PI) res -= 2 * PI;     return res;   }   bool order(Point A, Point B, Point C) {     return min(A.x, C.x) <= B.x && B.x <= max(A.x, C.x) && min(A.y, C.y) <= B.y &&            B.y <= max(A.y, C.y);   }   bool good(Point A, Point B, Point C) {     if (ccw(A, B, C)) return false;     if (!order(A, B, C)) return false;     long double x = (B - A).len();     long double y = (C - B).len();     if (x * 4 < y - EPS) return false;     if (y * 4 < x - EPS) return false;     return true;   }   bool check() {     long long t[5];     for (long long i = (1), _b = (3); i <= _b; ++i) t[i] = i;     do {       for (long long r1 = 0, _a = (2); r1 < _a; ++r1) {         for (long long r2 = 0, _a = (2); r2 < _a; ++r2) {           for (long long r3 = 0, _a = (2); r3 < _a; ++r3) {             if (A[t[1]] == A[t[2]] && ccw(A[t[1]], B[t[1]], B[t[2]]) &&                 angle(B[t[1]], A[t[1]], B[t[2]]) < PI / 2.0 + EPS &&                 good(A[t[1]], A[t[3]], B[t[1]]) &&                 good(A[t[2]], B[t[3]], B[t[2]])) {               return true;             }             swap(A[3], B[3]);           }           swap(A[2], B[2]);         }         swap(A[1], B[1]);       }     } while (next_permutation(t + 1, t + 4));     return false;   }   int main() {     long long ntest;     scanf( %lld , &ntest);     while (ntest--) {       for (long long i = (1), _b = (3); i <= _b; ++i) {         A[i].read();         B[i].read();       }       puts(check() ?  YES  :  NO );     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000007;   const double eps = 1e-6;   const long long Inf = 1LL << 62;   const long long mod = 1000000007;   const long long pnum = 5761460;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cout << *it <<   =   << a <<   n ;     ;     err(++it, args...);   }   void solve_with_case(int cas) {}   long long maxCalories(vector<vector<long long>> arr, int n, int m) {     vector<vector<long long>> dp1(1005, vector<long long>(1005, 0));     vector<vector<long long>> dp2(1005, vector<long long>(1005, 0));     vector<vector<long long>> dp3(1005, vector<long long>(1005, 0));     vector<vector<long long>> dp4(1005, vector<long long>(1005, 0));     for (int i = (1); i <= (n); i++) {       for (int j = (1); j <= (m); j++) {         dp1[i][j] = arr[i][j] + max(dp1[i - 1][j], dp1[i][j - 1]);       }     }     for (int i = (n); i >= (1); i--) {       for (int j = (m); j >= (1); j--) {         dp2[i][j] = arr[i][j] + max(dp2[i + 1][j], dp2[i][j + 1]);       }     }     for (int i = (n); i >= (1); i--) {       for (int j = (1); j <= (m); j++) {         dp3[i][j] = arr[i][j] + max(dp3[i + 1][j], dp3[i][j - 1]);       }     }     for (int i = (1); i <= (n); i++) {       for (int j = (m); j >= (1); j--) {         dp4[i][j] = arr[i][j] + max(dp4[i - 1][j], dp4[i][j + 1]);       }     }     long long ans = 0;     for (int i = (2); i <= (n - 1); i++) {       for (int j = (2); j <= (m - 1); j++) {         long long ans1 =             dp1[i - 1][j] + dp2[i + 1][j] + dp3[i][j - 1] + dp4[i][j + 1];         long long ans2 =             dp1[i][j - 1] + dp2[i][j + 1] + dp3[i + 1][j] + dp4[i - 1][j];         ans = max({ans, ans1, ans2});       }     }     return ans;   }   void solve_without_case() {     int n, m;     cin >> n >> m;     vector<vector<long long>> arr(1005, vector<long long>(1005, 0));     for (int i = (1); i <= (n); i++) {       for (int j = (1); j <= (m); j++) {         cin >> arr[i][j];       }     }     cout << maxCalories(arr, n, m) <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     solve_without_case();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M = 1e9 + 7;   double pi = acos(-1.0);   long long powerm(long long x, long long y) {     long long res = 1;     while (y) {       if (y & 1) res = (res * x) % M;       y = y >> 1;       x = (x * x) % M;     }     return res % M;   }   long long power(long long x, long long y) {     long long res = 1;     while (y) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long gcd(long long a, long long b) {     if (b > a) return gcd(b, a);     if (b == 0) return a;     return gcd(b, a % b);   }   const int N = 2e5 + 5;   vector<int> adj[N];   long long a[N];   bool b[N], c[N];   vector<pair<int, int> > pp(N);   long long ans;   void dfs(int u, int par, long long mn) {     if (b[u] == 1 && c[u] == 0)       pp[u].first++;     else if (b[u] == 0 && c[u] == 1)       pp[u].second++;     a[u] = min(a[u], mn);     for (auto it : adj[u]) {       if (it == par) continue;       dfs(it, u, a[u]);       pp[u].first += pp[it].first;       pp[u].second += pp[it].second;     }     long long jj = min(pp[u].first, pp[u].second);     ans += jj * 2 * a[u];     pp[u].first -= jj;     pp[u].second -= jj;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i] >> b[i] >> c[i];     }     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, -1, M);     if (pp[1].first > 0 || pp[1].second > 0)       cout << -1;     else       cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 7e5 + 10;   const int inf = 0x3f3f3f3f;   int n, m, p, q, nx, ny;   long long sum[300][300];   int dis[300][300];   int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};   char maze[300][300];   void bfs(int sx, int sy, long long k) {     dis[sx][sy] = 0, sum[sx][sy] += k;     queue<pair<pair<int, int>, int> > q;     q.push(make_pair(make_pair(sx, sy), k));     while (q.empty() == 0) {       pair<pair<int, int>, int> tmp = q.front();       q.pop();       for (int i = 0; i < 4; i++) {         nx = tmp.first.first + dx[i], ny = tmp.first.second + dy[i];         if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && maze[nx][ny] !=  *  &&             dis[nx][ny] == inf) {           dis[nx][ny] = dis[tmp.first.first][tmp.first.second] + 1;           int res = tmp.second / 2;           if (res <= 0) {             break;           }           sum[nx][ny] += res;           q.push(make_pair(make_pair(nx, ny), res));         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> q >> p;     memset(sum, 0, sizeof(sum));     int cnt = 0;     for (int i = 1; i <= n; i++) {       cin >> maze[i] + 1;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (maze[i][j] >=  A  && maze[i][j] <=  Z ) {           memset(dis, inf, sizeof(dis));           bfs(i, j, (maze[i][j] -  A  + 1) * q);         }       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (sum[i][j] > p && maze[i][j] !=  * ) {           ans++;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool uin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       vector<vector<int> > occs(n);       for (int i = 0; i < (int)(n); ++i) {         int x;         cin >> x;         --x;         occs[x].push_back(i);       }       int dif = 0;       for (int i = 0; i < (int)(n); ++i)         if (!occs[i].empty()) ++dif;       int ch = 0, maxch = 0, R = -1;       for (int i = 0; i < (int)(n); ++i) {         if (occs[i].empty()) continue;         if (occs[i][0] > R)           ++ch, uax(maxch, ch);         else           ch = 1;         R = occs[i].back();       }       cout << dif - maxch <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 * 100 + 50;   vector<long long> nb[MAXN];   long long n, m, k, cmp, sz[MAXN];   bool mrk[MAXN];   long long pw(long long x, long long y) {     if (!y) return 1;     if (y == 1) return x % k;     long long tmp = pw(x, y / 2);     if (y % 2)       return ((tmp * tmp) % k * x) % k;     else       return (tmp * tmp) % k;   }   void dfs(int x) {     if (mrk[x]) return;     mrk[x] = 1;     sz[cmp]++;     for (int i = 0; i < nb[x].size(); i++) dfs(nb[x][i]);   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       int tmp1, tmp2;       cin >> tmp1 >> tmp2;       nb[tmp1 - 1].push_back(tmp2 - 1);       nb[tmp2 - 1].push_back(tmp1 - 1);     }     for (int i = 0; i < n; i++) {       if (!mrk[i]) {         dfs(i);         cmp++;       }     }     if (cmp == 1) {       cout << 1 % k << endl;       return 0;     }     long long ans = pw(n, cmp - 2) % k;     for (int i = 0; i < cmp; i++) {       ans *= sz[i];       ans %= k;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   template <class T>   inline void read(T &x) {     x = 0;     int f = 0;     char ch = getchar();     while (!isdigit(ch)) {       f |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     x = f ? -x : x;     return;   }   int p[100010], siz[100010], find[100010];   int t, n;   bool flag;   int main() {     read(t);     while (t--) {       read(n);       flag = true;       for (int i = 1; i <= n; ++i) read(p[i]);       for (int i = 2; i <= n; ++i) {         if (p[i] - p[i - 1] > 1) {           flag = false;           break;         }       }       puts(flag ?  Yes  :  No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, INF = 1e9;   const int mx = 1e5 + 5;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, s, k;     cin >> n >> s;     if (2 * n > s)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       for (int i = 1; i < n; i++) cout << s / n <<    ;       cout << (s - (s / n) * (n - 1)) << endl;       cout << 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   int days[200][12];   int v[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   void swap(int &a, int &b) {     int t = a;     a = b;     b = t;   }   struct year {     int y;     int m;     int d;     bool operator>(year &next) {       if (this->y > next.y)         return true;       else if (this->y < next.y)         return false;       if (this->m > next.m)         return true;       else if (this->m < next.m)         return false;       return this->d > next.d;     }     void inc() {       if (++this->d >= days[this->y][this->m]) {         this->d = 0;         if (++this->m >= 12) {           this->m = 0;           ++this->y;         }       }     }   };   int main() {     for (int i = 0; i < 139; i++)       for (int j = 0; j < 12; j++) {         days[i][j] = v[j];         if (j == 1 && i % 4 == 0) days[i][1] = 29;       }     days[0][1] = 28;     year y[2];     for (int i = 0; i < 2; i++) {       scanf( %d:%d:%d , &y[i].y, &y[i].m, &y[i].d);       y[i].y -= 1900;       y[i].m--;       y[i].d--;     }     year *a, *b;     if (y[0] > y[1]) {       a = &y[1];       b = &y[0];     } else {       a = &y[0];       b = &y[1];     }     int cnt = 0;     while (a->y != b->y || a->m != b->m || a->d != b->d) {       a->inc();       cnt++;     }     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[100005], diff[100005], prv[100005];   bool flag[100005];   vector<int> a, d;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , arr + i);       flag[arr[i]] = 1;     }     for (int i = 1; i <= n; ++i) {       if (!flag[arr[i]]) continue;       if (prv[arr[i]] && !diff[arr[i]])         diff[arr[i]] = i - prv[arr[i]];       else if (prv[arr[i]] && diff[arr[i]] != i - prv[arr[i]])         flag[arr[i]] = 0;       prv[arr[i]] = i;     }     for (int i = 0; i < 100005; ++i)       if (flag[i]) a.push_back(i), d.push_back(diff[i]);     printf( %d n , a.size());     for (int i = 0; i < a.size(); ++i) printf( %d %d n , a[i], d[i]);     return 0;   }