#include <bits/stdc++.h>   using namespace std;   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(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() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   template <typename T>   T inverse(T a, T m) {     T u = 0, v = 1;     while (a != 0) {       T t = m / a;       m -= t * a;       swap(a, m);       u -= t * v;       swap(u, v);     }     assert(m == 1);     return u;   }   template <typename T>   class Modular {    public:     using Type = typename decay<decltype(T::value)>::type;     constexpr Modular() : value() {}     template <typename U>     Modular(const U& x) {       value = normalize(x);     }     template <typename U>     static Type normalize(const U& x) {       Type v;       if (-mod() <= x && x < mod())         v = static_cast<Type>(x);       else         v = static_cast<Type>(x % mod());       if (v < 0) v += mod();       return v;     }     const Type& operator()() const { return value; }     template <typename U>     explicit operator U() const {       return static_cast<U>(value);     }     constexpr static Type mod() { return T::value; }     Modular& operator+=(const Modular& other) {       if ((value += other.value) >= mod()) value -= mod();       return *this;     }     Modular& operator-=(const Modular& other) {       if ((value -= other.value) < 0) value += mod();       return *this;     }     template <typename U>     Modular& operator+=(const U& other) {       return *this += Modular(other);     }     template <typename U>     Modular& operator-=(const U& other) {       return *this -= Modular(other);     }     Modular& operator++() { return *this += 1; }     Modular& operator--() { return *this -= 1; }     Modular operator++(int) {       Modular result(*this);       *this += 1;       return result;     }     Modular operator--(int) {       Modular result(*this);       *this -= 1;       return result;     }     Modular operator-() const { return Modular(-value); }     template <typename U = T>     typename enable_if<is_same<typename Modular<U>::Type, int>::value,                        Modular>::type&     operator*=(const Modular& rhs) {       value = normalize(static_cast<int64_t>(value) *                         static_cast<int64_t>(rhs.value));       return *this;     }     template <typename U = T>     typename enable_if<is_same<typename Modular<U>::Type, long long>::value,                        Modular>::type&     operator*=(const Modular& rhs) {       long long q = static_cast<long long>(static_cast<long double>(value) *                                            rhs.value / mod());       value = normalize(value * rhs.value - q * mod());       return *this;     }     template <typename U = T>     typename enable_if<!is_integral<typename Modular<U>::Type>::value,                        Modular>::type&     operator*=(const Modular& rhs) {       value = normalize(value * rhs.value);       return *this;     }     Modular& operator/=(const Modular& other) {       return *this *= Modular(inverse(other.value, mod()));     }     friend const Type& abs(const Modular& x) { return x.value; }     template <typename U>     friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);     template <typename U>     friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);     template <typename V, typename U>     friend V& operator>>(V& stream, Modular<U>& number);       private:     Type value;   };   template <typename T>   bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) {     return lhs.value == rhs.value;   }   template <typename T, typename U>   bool operator==(const Modular<T>& lhs, U rhs) {     return lhs == Modular<T>(rhs);   }   template <typename T, typename U>   bool operator==(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) == rhs;   }   template <typename T>   bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) {     return !(lhs == rhs);   }   template <typename T, typename U>   bool operator!=(const Modular<T>& lhs, U rhs) {     return !(lhs == rhs);   }   template <typename T, typename U>   bool operator!=(U lhs, const Modular<T>& rhs) {     return !(lhs == rhs);   }   template <typename T>   bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) {     return lhs.value < rhs.value;   }   template <typename T>   Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) += rhs;   }   template <typename T, typename U>   Modular<T> operator+(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) += rhs;   }   template <typename T, typename U>   Modular<T> operator+(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) += rhs;   }   template <typename T>   Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) -= rhs;   }   template <typename T, typename U>   Modular<T> operator-(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) -= rhs;   }   template <typename T, typename U>   Modular<T> operator-(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) -= rhs;   }   template <typename T>   Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) *= rhs;   }   template <typename T, typename U>   Modular<T> operator*(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) *= rhs;   }   template <typename T, typename U>   Modular<T> operator*(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) *= rhs;   }   template <typename T>   Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) /= rhs;   }   template <typename T, typename U>   Modular<T> operator/(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) /= rhs;   }   template <typename T, typename U>   Modular<T> operator/(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) /= rhs;   }   template <typename T, typename U>   Modular<T> power(const Modular<T>& a, const U& b) {     assert(b >= 0);     Modular<T> x = a, res = 1;     U p = b;     while (p > 0) {       if (p & 1) res *= x;       x *= x;       p >>= 1;     }     return res;   }   template <typename T>   bool IsZero(const Modular<T>& number) {     return number() == 0;   }   template <typename T>   string to_string(const Modular<T>& number) {     return to_string(number());   }   template <typename U, typename T>   U& operator<<(U& stream, const Modular<T>& number) {     return stream << number();   }   template <typename U, typename T>   U& operator>>(U& stream, Modular<T>& number) {     typename common_type<typename Modular<T>::Type, long long>::type x;     stream >> x;     number.value = Modular<T>::normalize(x);     return stream;   }   using ModType = int;   struct VarMod {     static ModType value;   };   ModType VarMod::value;   ModType& md = VarMod::value;   using Mint = Modular<VarMod>;   template <typename T>   vector<int> z_function(int n, const T& s) {     vector<int> z(n, n);     int l = 0, r = 0;     for (int i = 1; i < n; i++) {       z[i] = (i > r ? 0 : min(r - i + 1, z[i - l]));       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {         z[i]++;       }       if (i + z[i] - 1 > r) {         l = i;         r = i + z[i] - 1;       }     }     return z;   }   template <typename T>   vector<int> z_function(const T& s) {     return z_function((int)s.size(), s);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s_;     cin >> s_;     string x_;     cin >> x_;     int n = (int)s_.size();     int m = (int)x_.size();     vector<int> s(n);     for (int i = 0; i < n; i++) {       s[i] = (int)(s_[i] -  0 );     }     vector<int> x(m);     for (int i = 0; i < m; i++) {       x[i] = (int)(x_[i] -  0 );     }     vector<int> seq = x;     seq.insert(seq.end(), s.begin(), s.end());     auto z = z_function(seq);     auto Check = [&](int l1, int r1, int l2, int r2) {       int i = r1;       int j = r2;       int c = 0;       for (int q = m - 1; q >= 0; q--) {         if (i >= l1) {           c += s[i];           i -= 1;         }         if (j >= l2) {           c += s[j];           j -= 1;         }         int nc = 0;         if (c >= 10) {           c -= 10;           nc = 1;         }         if (x[q] != c) {           return;         }         c = nc;       }       if (c != 0 || i >= l1 || j >= l2) {         return;       }       cout << l1 + 1 <<     << r1 + 1 <<   n ;       cout << l2 + 1 <<     << r2 + 1 <<   n ;       exit(0);     };     {       mt19937 rng(           (unsigned int)chrono::steady_clock::now().time_since_epoch().count());       while (true) {         md = (int)1e8 + rng() % (int)9e8;         bool pr = true;         for (int i = 2; i * i <= md; i++) {           if (md % i == 0) {             pr = false;             break;           }         }         if (pr) {           break;         }       }     }     vector<Mint> p10(n + 1);     p10[0] = 1;     for (int i = 1; i <= n; i++) {       p10[i] = p10[i - 1] * 10;     }     Mint inv_10 = 1 / Mint(10);     vector<Mint> inv_p10(n + 1);     inv_p10[0] = 1;     for (int i = 1; i <= n; i++) {       inv_p10[i] = inv_p10[i - 1] * inv_10;     }     vector<Mint> suf(n + 1);     for (int i = n - 1; i >= 0; i--) {       suf[i] = suf[i + 1] + p10[n - 1 - i] * s[i];     }     vector<pair<int, int>> all_suf(n + 1);     for (int i = 0; i <= n; i++) {       all_suf[i] = make_pair(suf[i](), i);     }     sort(all_suf.begin(), all_suf.end());     Mint x_val = 0;     for (int i = 0; i < m; i++) {       x_val = x_val * 10 + x[i];     }     for (int k = m; k >= m - 1 && k >= 1; k--) {       for (int i = 0; i <= n - k; i++) {         Mint me = (suf[i] - suf[i + k]) * inv_p10[n - (i + k)];         Mint goal = x_val - me;         {           auto Test = [&](int len) {             if (len >= 1 && len <= m) {               int j = i + k + len;               if (j <= n) {                 if ((suf[i + k] - suf[j]) * inv_p10[n - j] == goal) {                   Check(i, i + k - 1, i + k, j - 1);                 }               }             }           };           if (k == m - 1) {             Test(m - 1);             Test(m);           } else {             int match = min(m, z[m + i]);             Test(m - match);             Test(m - match - 1);           }         }         {           Mint needle = goal * p10[n - i] + suf[i];           auto it = lower_bound(all_suf.begin(), all_suf.end(),                                 make_pair(needle(), -1));           while (it != all_suf.end() && it->first == needle) {             int j = it->second;             if (j < i && i - j <= m) {               Check(j, i - 1, i, i + k - 1);             }             ++it;           }         }       }     }     assert(false);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long N;   vector<int> E[100000];   bool visit[100000] = {0};   long long component[100000] = {0};   int cN = 0;   stack<int> stk;   void DFS(int s) {     if (visit[s]) return;     visit[s] = true;     stk.push(s);     while (!stk.empty()) {       int v = stk.top();       stk.pop();       component[cN]++;       for (int i = (0); i < (E[v].size()); i++) {         if (visit[E[v][i]]) continue;         visit[E[v][i]] = true;         stk.push(E[v][i]);       }     }     cN++;   }   int main() {     cin >> N;     for (int i = (0); i < (N - 1); i++) {       int a, b;       char w[20];       scanf( %d%d%s , &a, &b, w);       bool islucky = 1;       int len = strlen(w);       for (int i = (0); i < (len); i++) {         if (w[i] ==  4  || w[i] ==  7 )           ;         else           islucky = 0;       }       if (islucky) continue;       E[a - 1].push_back(b - 1);       E[b - 1].push_back(a - 1);     }     for (int i = (0); i < (N); i++) DFS(i);     long long ret = 0;     for (int i = (0); i < (cN); i++) {       ret += component[i] * (N - component[i]) * (N - component[i] - 1);     }     cout << ret << endl;   }


#include<bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   int vis[MAXN*2][MAXN*2],T,n,m,ans;   /*   void dfs(int x,int y,int step,int now){    if(step==n){          if(!vis[x+MAXN][y+MAXN]) ans++,vis[x+MAXN][y+MAXN] = 1;     return;    }    if(now==1){     dfs(x+1,y,step+1,2);     dfs(x-1,y,step+1,2);    }    else if(now==2){     dfs(x,y+1,step+1,1);     dfs(x,y-1,step+1,1);    }    else{     dfs(x+1,y,step+1,2);     dfs(x-1,y,step+1,2);     dfs(x,y+1,step+1,1);     dfs(x,y-1,step+1,1);    }   }   */   int main(){    int aa = -1;     cin>>n;     long long a1 = 3*n*(n+4)+2,a2 = n%2==0?aa*(n*(n + 4)+2):-aa*(n*(n + 4)+2);     cout<<1 + (a1+a2)/8<<endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> q, s;   int n, k;   vector<int> apply(vector<int> &a, vector<int> q) {     vector<int> res(n);     for (int i = 0; i < n; i++) {       res[i] = a[q[i]];     }     return res;   }   vector<int> rev_apply(const vector<int> &a, vector<int> &q) {     vector<int> res(n);     for (int i = 0; i < n; i++) {       res[q[i]] = a[i];     }     return res;   }   int main() {     cin >> n >> k;     q = vector<int>(n);     s = vector<int>(n);     for (int i = 0; i < n; i++) {       cin >> q[i];       q[i]--;     }     for (int i = 0; i < n; i++) {       cin >> s[i];       s[i]--;     }     vector<int> a(n), b, c;     for (int i = 0; i < n; i++) {       a[i] = i;     }     if (a == s) {       cout <<  NO  << endl;       return 0;     }     b = apply(a, q);     c = rev_apply(a, q);     if (b == s && c == s) {       if (k == 1) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }       return 0;     }     b = a;     c = a;     int min_b = -1, min_c = -1;     for (int i = 0; i < k; i++) {       b = apply(b, q);       c = rev_apply(c, q);       if (b == s && min_b == -1) {         min_b = i + 1;       }       if (c == s && min_c == -1) {         min_c = i + 1;       }     }     if (min_b >= 0 && min_b % 2 == k % 2) {       cout <<  YES  << endl;       return 0;     }     if (min_c >= 0 && min_c % 2 == k % 2) {       cout <<  YES  << endl;       return 0;     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long sz = 3e5 + 10;   long long ara[sz], pos[sz], other[sz], mn[sz];   int main() {     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; ++i) {       scanf( %lld , &ara[i]);       pos[ara[i]] = i;     }     for (long long i = 1; i <= n; ++i) other[i] = mn[i] = n + 1;     for (long long i = 1; i <= m; ++i) {       long long p1, p2;       scanf( %lld , &p1), scanf( %lld , &p2);       if (pos[p1] > pos[p2]) swap(p1, p2);       other[pos[p1]] = min(other[pos[p1]], pos[p2]);     }     mn[n + 1] = n + 1;     for (long long i = n; i >= 1; --i) mn[i] = min(mn[i + 1], other[i]);     long long ans = 0;     for (long long i = 1; i <= n; ++i) ans += (mn[i] - i);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int q;     cin >> q;     while (q--) {       string s;       cin >> s;       vector<char> v[2];       for (int i = 0; i < s.size(); i++) v[s[i] % 2].push_back(s[i]);       int p1, p2;       for (p1 = 0, p2 = 0; p1 < v[0].size() && p2 < v[1].size();) {         if (v[0][p1] < v[1][p2])           cout << v[0][p1++];         else           cout << v[1][p2++];       }       while (p1 < v[0].size()) cout << v[0][p1++];       while (p2 < v[1].size()) cout << v[1][p2++];       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, temp;     cin >> n >> k;     int arr[n], sum[n];     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < n; i++) {       if (arr[i] == 0)         sum[i] = 0;       else         sum[i] = sum[arr[i] - 1];       temp = i > k ? k : i;       temp += i + k < n ? k : (n - i - 1);       temp++;       if (arr[i] + k > i - k && arr[i] != 0) {         if (arr[i] + k > n)           temp = 0;         else if (i - k < 0)           temp -= arr[i] + k;         else           temp -= arr[i] + k - i + k;       }       sum[i] += temp;       cout << sum[i] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   pair<long long, char> s[MAXN], t[MAXN];   int nxt[MAXN];   void kmp(pair<long long, char> str[], int len) {     memset(nxt, -1, sizeof(nxt));     for (int i = 0; i < len - 1; i++) {       int p = nxt[i];       while (p != -1 && str[i + 1] != str[p + 1]) p = nxt[p];       nxt[i + 1] = p + (str[i + 1] == str[p + 1]);     }   }   long long solve(pair<long long, char> s[], int lens, pair<long long, char> t[],                   int lent) {     long long res = 0;     kmp(t, lent);     int p = -1;     if (lent == 0 && s[0].second == t[0].second && s[0].first >= t[0].first &&         s[-1].second == t[-1].second && s[-1].first >= t[-1].first)       res++;     for (int i = 0; i < lens; i++) {       while (p != -1 && s[i] != t[p + 1]) p = nxt[p];       if (p + 1 < lent && s[i] == t[p + 1]) p++;       if (p == lent - 1) {         if (s[i + 1].second == t[p + 1].second &&             s[i + 1].first >= t[p + 1].first &&             s[i - p - 1].second == t[-1].second &&             s[i - p - 1].first >= t[-1].first)           res++;         p = nxt[p];       }     }     return res;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     long long l;     char c[5];     for (int i = 0; i < n; i++) {       scanf( %I64d-%s , &l, c);       s[i] = make_pair(l, *c);     }     for (int i = 0; i < m; i++) {       scanf( %I64d-%s , &l, c);       t[i] = make_pair(l, *c);     }     int now = 0;     for (int i = 0; i + 1 < n; i++) {       if (s[i + 1].second == s[now].second)         s[now].first += s[i + 1].first;       else         s[++now] = s[i + 1];     }     n = now + 1;     now = 0;     for (int i = 0; i + 1 < m; i++) {       if (t[i + 1].second == t[now].second)         t[now].first += t[i + 1].first;       else         t[++now] = t[i + 1];     }     m = now + 1;     if (m == 1) {       long long res = 0;       for (int i = 0; i < n; i++)         if (s[i].second == t[0].second)           res += max(0LL, s[i].first - t[0].first + 1);       return 0 * printf( %I64d , res);     }     printf( %I64d , solve(s + 1, n - 2, t + 1, m - 2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long p = 31;   const unsigned long long m = 1e9 + 7;   bool compare(string a, string b) {     sort(a.begin(), a.end());     sort(b.begin(), b.end());     int n = a.length();     unsigned long long hash_a = 0, hash_b = 0;     unsigned long long p_pow = 1;     for (int i = 0; i < n; i++) {       hash_a = (hash_a + (a[i] -  a  + 1) * p_pow) % m;       hash_b = (hash_b + (b[i] -  a  + 1) * p_pow) % m;       p_pow = (p_pow * p) % m;     }     if (hash_a == hash_b) return true;     return false;   }   bool check(string a, string b) {     int blen = b.length();     int alen = a.length();     for (int i = 0; i + blen - 1 < alen; i++) {       string aux = a.substr(i, blen);       if (compare(b, aux)) return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       string a, b;       cin >> a >> b;       if (a.length() > b.length())         cout <<  NO  <<   n ;       else if (check(b, a))         cout <<  YES  <<   n ;       else         cout <<  NO  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10101;   const int BIT = 30;   int N;   int arr[MAXN], brr[MAXN];   bool isb[MAXN];   vector<pair<int, int> > vans;   void action(int a, int b) {     arr[b] ^= arr[a];     vans.push_back(make_pair(b + 1, a + 1));   }   void aswap(int a, int b) {     if (a == b) return;     action(a, b);     action(b, a);     action(a, b);   }   void fail() {     cout << -1 << endl;     exit(0);   }   void calc() {     int basis[BIT];     memset((basis), -1, sizeof(basis));     memset((isb), 0, sizeof(isb));     for (int i = 0; i < BIT; i++) {       for (int j = 0; j < N; j++) {         if (isb[j]) continue;         if (arr[j] & (1 << i)) {           basis[i] = j;           isb[j] = true;           break;         }       }       if (basis[i] == -1) continue;       for (int j = 0; j < N; j++) {         if (j == basis[i]) continue;         if (arr[j] & (1 << i)) {           action(basis[i], j);         }       }     }     bool bused[BIT];     memset((bused), 0, sizeof(bused));     for (int i = 0; i < N; i++) {       int x = brr[i];       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (x & (1 << j)) {           x ^= arr[basis[j]];           if (!bused[j]) {             bused[j] = true;           }         }       }       if (x) fail();     }     for (int i = 0; i < N; i++) {       if (arr[i]) continue;       int x = brr[i];       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (x & (1 << j)) {           x ^= arr[basis[j]];           action(basis[j], i);         }       }     }     int mat[BIT], mat2[BIT];     memset((mat), 0, sizeof(mat));     memset((mat2), 0, sizeof(mat2));     memset((bused), 0, sizeof(bused));     for (int i = 0; i < BIT; i++) {       if (basis[i] == -1) continue;       mat2[i] = 1 << i;       int x = brr[basis[i]];       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (x & (1 << j)) {           x ^= arr[basis[j]];           mat[i] ^= 1 << j;         }       }     }     for (int i = 0; i < BIT; i++) {       if (basis[i] == -1) continue;       int pv = -1;       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (bused[j]) continue;         if (mat[j] & 1 << i) {           pv = j;           bused[j] = true;           break;         }       }       if (pv == -1) continue;       swap(bused[i], bused[pv]);       swap(mat[i], mat[pv]);       swap(mat2[i], mat2[pv]);       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (j == i) continue;         if (mat[j] & 1 << i) {           mat[j] ^= mat[i];           mat2[j] ^= mat2[i];         }       }     }     for (int i = 0; i < BIT; i++) {       if (basis[i] == -1) continue;       if (!(mat[i] & 1 << i)) {         for (int j = 0; j < BIT; j++) {           if (basis[j] == -1) continue;           if (j == i) continue;           if (mat[j] & 1 << i) action(basis[i], basis[j]);         }         action(basis[i], basis[i]);       }     }     for (int i = 0; i < BIT; i++) {       if (basis[i] == -1) continue;       int pv = -1;       for (int j = i; j < BIT; j++) {         if (basis[j] == -1) continue;         if (mat2[j] & 1 << i) {           pv = j;           break;         }       }       swap(mat2[i], mat2[pv]);       aswap(basis[i], basis[pv]);       for (int j = 0; j < BIT; j++) {         if (basis[j] == -1) continue;         if (j == i) continue;         if (mat2[j] & 1 << i) {           mat2[j] ^= mat2[i];           action(basis[i], basis[j]);         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> N;     for (int i = 0; i < N; i++) cin >> arr[i];     for (int i = 0; i < N; i++) cin >> brr[i];     calc();     int A = vans.size();     cout << A <<   n ;     for (__typeof(vans.begin()) it = vans.begin(); it != vans.end(); it++) {       cout << it->first <<     << it->second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100001, BAR = 500, MOD = 1000000007;   int fac[N], inv[N];   int powMod(int a, int n) {     int ret = 1;     while (n) {       if (n & 1) {         ret = (long long)ret * a % MOD;       }       a = (long long)a * a % MOD;       n >>= 1;     }     return ret;   }   int binom(int n, int m) {     return (long long)fac[n] * inv[m] % MOD * inv[n - m] % MOD;   }   int m;   char s[N];   int ans[N];   void prepare(int l) {     int base = 1;     for (int i = 0; i < N; ++i) {       ans[i] = i < l ? 0 : (long long)binom(i - 1, l - 1) * base % MOD;       if (i >= l) {         base = (long long)base * 25 % MOD;       }     }     for (int i = 0; i < N; ++i) {       if (ans[i] >= MOD) {         ans[i] -= MOD;       }       if (i + 1 < N) {         ans[i + 1] += (long long)ans[i] * 26 % MOD;       }     }   }   int main() {     fac[0] = 1;     for (int i = 1; i < N; ++i) {       fac[i] = (long long)fac[i - 1] * i % MOD;     }     inv[N - 1] = powMod(fac[N - 1], MOD - 2);     assert((long long)inv[N - 1] * fac[N - 1] % MOD == 1);     for (int i = N - 2; i >= 0; --i) {       inv[i] = (long long)inv[i + 1] * (i + 1) % MOD;     }     scanf( %d , &m);     scanf( %s , s);     int len = strlen(s);     if (len > BAR) {       prepare(len);     }     while (m--) {       int op;       scanf( %d , &op);       if (op == 1) {         scanf( %s , s);         len = strlen(s);         if (len > BAR) {           prepare(len);         }       } else {         int n;         scanf( %d , &n);         if (len > BAR) {           printf( %d n , ans[n]);         } else {           if (n < len) {             printf( 0 n );           } else {             int ans = powMod(26, n);             int base = powMod(25, n - len + 1);             for (int i = len - 1; i >= 0; --i) {               ans -= (long long)binom(n, i) * base % MOD;               if (ans < 0) {                 ans += MOD;               }               base = (long long)base * 25 % MOD;             }             printf( %d n , ans);           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, t, i;     scanf( %d , &t);     for (i = 0; i < t; i++) {       scanf( %d , &n);       printf( %d n , n / 2);     }   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265359;   const long long MOD = (long long)998244353ll;   const long long MAXN = (long long)3e5 + 10;   const long long INF = (long long)2242545357980376863;   const long double EPS = (long double)1e-8;   long long source[MAXN], d0[MAXN], dis[MAXN], done[MAXN], par[MAXN];   vector<long long> C[MAXN];   vector<pair<long long, long long> > G[MAXN];   vector<pair<long long, pair<long long, long long> > > E;   set<pair<long long, long long> > dj;   void change_key(long long node, long long last, long long now) {     dj.erase({last, node});     dis[node] = now;     dj.insert({now, node});     return;   }   long long A[MAXN], B[MAXN], ans[MAXN];   long long W;   long long get_par(long long u) {     if (par[u] == u) return u;     return par[u] = get_par(par[u]);   }   bool merge(long long u, long long v) {     long long U = u, V = v;     u = get_par(u);     v = get_par(v);     if (u == v) return false;     if (C[u].size() < C[v].size()) swap(u, v);     par[v] = u;     for (auto x : C[v]) {       C[u].push_back(x);       if (get_par(A[x]) == get_par(B[x])) ans[x] = min(ans[x], W);     }     C[v].clear();     return true;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(ans, 31, sizeof ans);     for (int i = 0; i < MAXN; i++) par[i] = i;     memset(dis, 31, sizeof dis);     memset(d0, 31, sizeof d0);     long long n, m, k, q;     scanf( %lld%lld%lld%lld , &n, &m, &k, &q);     long long u, v, w;     for (int i = 0; i < m; i++) {       scanf( %lld%lld%lld , &u, &v, &w);       G[u].push_back({v, w});       G[v].push_back({u, w});     }     long long p, f;     for (int i = 1; i <= k; i++) {       p = i;       source[p] = p;       dj.insert({0, p});       dis[p] = 0;     }     long long fr, d, adj;     while (dj.size()) {       d = (*dj.begin()).first;       fr = (*dj.begin()).second;       dj.erase(dj.begin());       for (auto edge : G[fr]) {         adj = edge.first;         w = edge.second;         if (done[adj] == 1) {           E.push_back({dis[adj] + dis[fr] + w, {source[fr], source[adj]}});         }         if (dis[adj] > d + w) {           change_key(adj, dis[adj], d + w);           source[adj] = source[fr];         }       }       done[fr] = 1;     }     for (int i = 0; i < q; i++) {       scanf( %lld%lld , A + i, B + i);       C[A[i]].push_back(i);       C[B[i]].push_back(i);     }     sort(E.begin(), E.end());     for (auto edge : E) {       W = edge.first;       if (merge(edge.second.first, edge.second.second)) {       }     }     for (int i = 0; i < q; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > adj[200001];   int totalIn, totalOut;   int inEdges[200001];   int outEdges[200001];   void dfs(int u, int par, int in, int out) {     inEdges[u] = in;     outEdges[u] = out;     for (pair<int, int> &p : adj[u]) {       int v = p.first;       int type = p.second;       if (v != par) {         if (type == 1) {           dfs(v, u, in, out + 1);           totalOut++;         } else {           dfs(v, u, in + 1, out);           totalIn++;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int s, t;     for (int i = 0; i < n - 1; i++) {       cin >> s >> t;       adj[s].push_back({t, 1});       adj[t].push_back({s, -1});     }     dfs(1, -1, 0, 0);     int in;     vector<int> cities;     int minIn = totalIn;     cities.push_back(1);     for (int i = 2; i <= n; i++) {       in = totalIn - inEdges[i] + outEdges[i];       if (in < minIn) {         minIn = in;         cities.clear();         cities.push_back(i);       } else if (in == minIn) {         cities.push_back(i);       }     }     cout << minIn <<   n ;     for (int &i : cities) cout << i <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, arr[26], s, k, fuck[19], ans;   vector<pair<long long, long long> > v1;   map<pair<long long, long long>, long long> maph;   void rek(long long x, long long r, long long z, long long o, bool p) {     if (x >= r) {       if (!p)         v1.push_back({z, o});       else         maph[{z, o}]++;       return;     }     if (arr[x] + z <= s) rek(x + 1, r, z + arr[x], o, p);     if (o < k and arr[x] <= 18 and z + fuck[arr[x]] <= s)       rek(x + 1, r, z + fuck[arr[x]], o + 1, p);     rek(x + 1, r, z, o, p);   }   int main() {     cin >> n >> k >> s;     fuck[0] = 1;     for (int i = 1; i <= 18; i++) fuck[i] = fuck[i - 1] * i;     for (int i = 0; i < n; i++) cin >> arr[i];     rek(0, n / 2, 0, 0, 0), rek(n / 2, n, 0, 0, 1);     for (int i = 0; i < v1.size(); i++) {       for (int j = 0; j <= k - v1[i].second; j++) {         if (maph.find({s - v1[i].first, j}) != maph.end())           ans += maph[{s - v1[i].first, j}];       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt, pos, sz, mx, last, start;   char s[2000005], ans[2000005];   int main() {     scanf( %d , &n);     memset(ans,   000 , sizeof(ans));     for (register int i = 1; i <= n; i++) {       scanf( %s , s);       scanf( %d , &cnt);       sz = strlen(s);       for (register int j = 1; j <= cnt; j++) {         scanf( %d , &pos);         if (j == 1) {           start = 0;         } else {           start = last + sz - pos;           if (start < 0) {             start = 0;           }         }         for (register int k = start; k < sz; k++) {           ans[k + pos] = s[k];         }         last = pos;         mx = max(mx, pos + sz - 1);       }     }     while (ans[mx] ==   000 ) {       mx--;     }     for (register int i = 1; i <= mx; i++) {       if (ans[i] ==   000 ) {         ans[i] =  a ;       }       printf( %c , ans[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       double n;       cin >> n;       double r = 1 / (2 * tan((360 / (4 * n)) * (3.1415926535 / 180)));       cout << setprecision(15) << 2 * r << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int c = 0, m = 0, y = 0, w = 0, g = 0, b = 0, d, e;     cin >> d >> e;     char arr[d][e];     for (int i = 0; i < d; i++) {       for (int j = 0; j < e; j++) {         cin >> arr[i][j];         if (arr[i][j] ==  M ) {           m++;         } else if (arr[i][j] ==  C ) {           c++;         } else if (arr[i][j] ==  Y ) {           y++;         } else if (arr[i][j] ==  W ) {           w++;         } else if (arr[i][j] ==  G ) {           g++;         } else if (arr[i][j] ==  B ) {           b++;         }       }     }     if (y == 0 && c == 0 && m == 0) {       cout <<  #Black&White ;     } else {       cout <<  #Color ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long t;     cin >> t;     for (int ti = (int)(0); ti < (int)(t); ti++) {       unsigned long long n;       cin >> n;       if (n % 2) {         unsigned long long tmp = (n + 1u) * n;         unsigned long long res;         if (tmp % (4u * n) == 0) {           res = n;         } else if (tmp % (4u * n) == 2u * n) {           res = n * 2u;         } else {           res = n * 4u;         }         cout << res + 1u << endl;       } else {         cout << n * 4u + 1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 2e6 + 10;   int a[M], b[M], c[M], d[M], e[M], f[M];   vector<int> T[M];   struct NTT {     static const int G = 3, P = 998244353;     int N, na, nb, w[2][M], rev[M];     long long kpow(long long a, int b) {       long long c = 1;       for (; b; b >>= 1, a = a * a % P)         if (b & 1) c = c * a % P;       return c;     }     void FFT(int *a, int f) {       for (int i = (0); i < (N); i++)         if (i < rev[i]) swap(a[i], a[rev[i]]);       for (int i = 1; i < N; i <<= 1)         for (int j = 0, t = N / (i << 1); j < N; j += i << 1)           for (int k = 0, l = 0, x, y; k < i; k++, l += t)             x = (long long)w[f][l] * a[j + k + i] % P, y = a[j + k],             a[j + k] = (y + x) % P, a[j + k + i] = (y - x + P) % P;       if (f)         for (int i = 0, x = kpow(N, P - 2); i < N; i++)           a[i] = (long long)a[i] * x % P;     }     void work() {       int d = __builtin_ctz(N);       w[0][0] = w[1][0] = 1;       for (int i = 1, x = kpow(G, (P - 1) / N), y = kpow(x, P - 2); i < N; i++) {         rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (d - 1));         w[0][i] = (long long)x * w[0][i - 1] % P,         w[1][i] = (long long)y * w[1][i - 1] % P;       }     }     void doit(int *a, int *b, int na, int nb) {       for (N = 1; N < na + nb - 1; N <<= 1)         ;       for (int i = (na); i < (N); i++) a[i] = 0;       for (int i = (nb); i < (N); i++) b[i] = 0;       work(), FFT(a, 0), FFT(b, 0);       for (int i = (0); i < (N); i++) a[i] = (long long)a[i] * b[i] % P;       FFT(a, 1);     }     void get_inv(int *a, int *b, int na) {       if (na == 1) {         b[0] = kpow(a[0], P - 2);         return;       }       get_inv(a, b, (na + 1) >> 1);       for (N = 1; N < (na << 1); N <<= 1)         ;       work();       for (int i = (0); i < (na); i++) c[i] = a[i];       for (int i = (na); i < (N); i++) c[i] = 0;       FFT(c, 0), FFT(b, 0);       for (int i = (0); i < (N); i++)         b[i] = 1ll * (2 - 1ll * c[i] * b[i] % P + P) % P * b[i] % P;       FFT(b, 1);       for (int i = (na); i < (N); i++) b[i] = 0;     }     void get_ln(int *a, int *b, int na) {       for (int i = (0); i < (na - 1); i++)         d[i] = (long long)(a[i + 1]) * (i + 1) % P;       for (int i = (na); i < (N); i++) d[i] = 0;       d[na - 1] = 0;       get_inv(a, b, na);       doit(b, d, na, na);       for (int i = (na)-1; i >= (1); i--)         b[i] = (long long)b[i - 1] * kpow(i, P - 2) % P;       b[0] = 0;     }     void get_exp(int *a, int *b, int na) {       if (na == 1) {         b[0] = 1;         return;       }       get_exp(a, b, (na + 1) >> 1);       for (int i = 0; i < (na << 1); i++) f[i] = 0;       get_ln(b, f, na);       for (N = 1; N < (na << 1); N <<= 1)         ;       work();       f[0] = ((long long)a[0] + 1 - f[0] + P) % P;       for (int i = (1); i < (na); i++) f[i] = ((long long)a[i] - f[i] + P) % P;       FFT(f, 0);       FFT(b, 0);       for (int i = (0); i < (N); i++) b[i] = (long long)b[i] * f[i] % P;       FFT(b, 1);       for (int i = (na); i < (N); i++) b[i] = f[i] = 0;     }     void get_pow(int *a, int *b, int na, int k) {       get_ln(a, e, na);       for (int i = (0); i < (na); i++) e[i] = (long long)e[i] * k % P;       get_exp(e, b, na);     }     void fast_pow(int *a, int *b, int na, int k, int maxn) {       for (N = 1; N < max(((maxn + 1) << 1), (na << 1)); N <<= 1)         ;       for (int i = (na); i < (N); i++) a[i] = 0;       for (int i = (0); i < (N); i++) b[i] = 0;       b[0] = 1;       work();       while (k) {         FFT(a, 0);         if (k & 1) {           FFT(b, 0);           for (int i = (0); i < (N); i++) b[i] = (long long)a[i] * b[i] % P;           FFT(b, 1);           for (int i = (max(na, maxn + 1)); i < (N); i++) b[i] = 0;         }         for (int i = (0); i < (N); i++) a[i] = (long long)a[i] * a[i] % P;         FFT(a, 1);         for (int i = (max(na, maxn + 1)); i < (N); i++) a[i] = 0;         k >>= 1;       }     }     priority_queue<pair<int, int> > H;     void Merge(int m) {       while (!H.empty()) H.pop();       for (int i = (1); i < (m + 1); i++) H.emplace(make_pair(-T[i].size(), i));       while (H.size() >= 2) {         int x = H.top().second;         H.pop();         int y = H.top().second;         H.pop();         for (int i = (0); i < (T[x].size()); i++) a[i] = T[x][i];         for (int i = (0); i < (T[y].size()); i++) b[i] = T[y][i];         doit(a, b, T[x].size(), T[y].size());         int na = T[x].size() + T[y].size();         T[x].clear();         T[y].clear();         for (int i = (0); i < (na); i++) T[x].push_back(a[i]);         H.emplace(-T[x].size(), x);       }     }   } ntt;   int F[10];   int dis[300000 + 10][7][7];   int find(int i) {     if (F[i] == i) return i;     return F[i] = find(F[i]);   }   int main() {     string s, t;     cin >> s >> t;     int n = s.size(), m = t.size();     reverse(t.begin(), t.end());     for (int i = (0); i < (6); i++) {       for (int j = (0); j < (6); j++) {         if (i == j) continue;         for (int k = (0); k < (n); k++) {           if (s[k] == i +  a )             a[k] = 1;           else             a[k] = 0;         }         for (int k = (0); k < (m); k++) {           if (t[k] == j +  a )             b[k] = 1;           else             b[k] = 0;         }         ntt.doit(a, b, n, m);         for (int k = (m - 1); k < (n); k++) {           dis[k][i][j] = a[k];         }       }     }     for (int i = (m - 1); i < (n); i++) {       for (int j = (0); j < (6); j++) F[j] = j;       for (int j = (0); j < (6); j++) {         for (int k = (0); k < (6); k++) {           if (j == k) continue;           if (dis[i][j][k]) F[find(j)] = find(k);         }       }       int ans = 0;       for (int j = (0); j < (6); j++) {         if (F[j] == j) ans++;       }       cout << 6 - ans <<    ;     }     return 0;   }


#define _USE_MATH_DEFINES   #include <bits/stdc++.h>   using namespace std;      //template   #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)   #define ALL(v) (v).begin(),(v).end()   using ll=long long int;   const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;   template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}   template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}   //end      void solve(int _rot){      // printf( Case #%d:  ,_rot);      int n;      cin>>n;      string s[3];      rep(i,0,3)cin>>s[i];      rep(_,0,3){         string S=s[_],T=s[(_+1)%3];         string res;            int S0=0,T0=0;         rep(i,0,n*2)if(S[i]== 0 )S0++;         rep(i,0,n*2)if(T[i]== 0 )T0++;         if((S0>n) and (T0<n))continue;         if((S0<n) and (T0>n))continue;         char mx;         if(S0>=n and T0>=n)mx= 0 ;         if(S0<=n and T0<=n)mx= 1 ;            int i1=0,i2=0;         for(;;){            int c1=0,c2=0;            while(i1<n*2 and S[i1]!=mx){               i1++; c1++;            }            while(i2<n*2 and T[i2]!=mx){               i2++; c2++;            }            res+=string(max(c1,c2),mx^ 0 ^ 1 );            res+=mx;            i1=min(i1+1,n*2);            i2=min(i2+1,n*2);            if(i1==n*2 and i2==n*2)break;         }         while(res.size()>n*3)res.pop_back();         while(res.size()<n*3)res+= 0 ;         cout<<res<<  n ;         return;      }   }      int main(){      int t; scanf( %d ,&t);      rep(rot,0,t)solve(rot+1);      return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 0x3f3f3f3f;   const double eps = 1e-8;   const long long mod = 10007;   const int N = 110;   int val[110];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         for (int k = i; k <= j; k++) {           val[k]++;         }       }     }     int ans = -1;     for (int i = 1; i <= n; i++) {       ans = max(ans, val[i]);     }     printf( %d n , ans);     return 0;   }


#include<bits/stdc++.h>   #define ll long long   #define ii pair<ll,ll>   #define x first   #define y second   using namespace std;   const long o=200005;   ll n,it[2][4*o];   ii a[o];   vector<ii>p[2];   void build(long db,long x,long l,long r)   {       if(l==r)       {           it[db][x]=p[db][l].y;           return;       }       long mid=(l+r)>>1;       build(db,2*x,l,mid);       build(db,2*x+1,mid+1,r);       it[db][x]=min(it[db][2*x],it[db][2*x+1]);   }   ll get(long db,long x,long l,long r,long u,long v)   {       if(u>v || v<l || u>r)           return 1e9;       if(u<=l && r<=v)           return it[db][x];       long mid=(l+r)>>1;       return min(get(db,2*x,l,mid,u,v),get(db,2*x+1,mid+1,r,u,v));   }   int main()   {    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);       cin>>n;    for(long i=1;i<=n;i++)           cin>>a[i].x;          ll kq=0;       for(long i=1;i<=n;i++)       {           cin>>a[i].y;           if(a[i].x<a[i].y)p[0].push_back({a[i].y,a[i].x});           if(a[i].x>a[i].y)p[1].push_back(a[i]);           kq+=abs(a[i].x-a[i].y);       }             sort(p[0].begin(),p[0].end());       sort(p[1].begin(),p[1].end());       if(p[0].size()==0 || p[1].size()==0)       {           cout<<kq;           return 0;       }          build(0,1,0,p[0].size()-1);       build(1,1,0,p[1].size()-1);       ll l=0,r=1e9;       while(l<r)       {           ll mid=(l+r+1)>>1;           bool ok=0;           for(long i=0;i<p[0].size();i++)           if(p[0][i].x-p[0][i].y>=mid)           {               long vt=lower_bound(p[1].begin(),p[1].end(),ii(p[0][i].y+mid,0))-p[1].begin();               if(get(1,1,0,p[1].size()-1,vt,p[1].size()-1)<=p[0][i].y)               {                   ok=1;                   break;               }           }           for(long i=0;i<p[1].size();i++)           if(p[1][i].x-p[1][i].y>=mid)           {               long vt=lower_bound(p[0].begin(),p[0].end(),ii(p[1][i].y+mid,0))-p[0].begin();               if(get(0,1,0,p[0].size()-1,vt,p[0].size()-1)<=p[1][i].y)               {                   ok=1;                   break;               }           }           if(ok)l=mid;           else r=mid-1;       }       cout<<kq-l*2;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int v[200005];   void read();   int main() {     read();     int k = n - 1;     while (v[k] == v[k + 1]) --k;     cout << k <<   n ;     return 0;   }   void read() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> v[i];   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 2e9;   const long long infll = 1e18;   double eps = 0.0000001;   ifstream in( input.txt );   ofstream out( output.txt );   ;   long long n;   vector<long long> c;   vector<long long> t;   void init() {     cin >> n;     c.resize(n);     t.resize(n);     for (long long i = 0; i < n; i++) cin >> c[i];     for (long long i = 0; i < n; i++) cin >> t[i];   }   void solve() {     multiset<long long> razn1, razn2;     for (long long i = 0; i < n - 1; i++) {       razn1.insert(c[i + 1] - c[i]);       razn2.insert(t[i + 1] - t[i]);     }     if (razn1 == razn2 && c[0] == t[0] && c[n - 1] == t[n - 1])       cout <<  Yes ;     else       cout <<  No ;   }   signed main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, y, z, arr[100 * 100005], rearr[100 * 100005];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     cin >> x >> y;     for (int i = 0; i < x; i++) {       cin >> z;       arr[z]++;     }     z = 0;     for (int i = 1e7; i >= 1; i--) {       z += arr[i];       arr[i / 2] += arr[i] + rearr[i];       rearr[i / 2 + i % 2] += arr[i] + rearr[i];       if (z >= y) {         cout << i << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, k, l, c, d, p, nl, np, x, y, z, a, i;     scanf( %d%d%d%d%d%d%d%d , &n, &k, &l, &c, &d, &p, &nl, &np);     x = (k * l) / nl;     y = c * d;     z = p / np;     if (x < y && x < z) {       a = x;     } else if (y < x && y < z) {       a = y;     } else {       a = z;     }     i = a / n;     printf( %d , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (1 << 30) - 1;   const long long mod = 1e9 + 9;   map<pair<int, int>, int> mp;   int m;   int v[100010][2];   int vis[100010];   int ans[100010], anscnt;   int up[100010][3];   int down[100010][3];   priority_queue<int> qmax;   priority_queue<int, vector<int>, greater<int> > qmin;   bool check(int a) {     for (int i = 0; i < 3; ++i)       if (up[a][i]) {         int id = up[a][i], cnt = 0;         for (int j = 0; j < 3; ++j) cnt += !down[id][j];         if (cnt == 2) return false;       }     return true;   }   bool Check(int a, int x) {     for (int i = 0; i < 3; ++i)       if (up[a][i]) {         int id = up[a][i], cnt = 0;         if (id == x) continue;         for (int j = 0; j < 3; ++j) cnt += !down[id][j];         if (cnt == 2) return false;       }     return true;   }   void Remove(int a) {     int now;     for (int i = 0; i < 3; ++i)       if (up[a][i]) {         int id = up[a][i];         for (int j = 2; j >= 0; --j)           if (down[id][j]) {             now = down[id][j];             if (now == a) down[id][j] = 0;           }       }     for (int i = 0; i < 3; ++i)       if (down[a][i]) {         int id = down[a][i];         for (int j = 2; j >= 0; --j)           if (up[id][j]) {             now = up[id][j];             if (now == a) up[id][j] = 0;           }       }   }   void Topo() {     anscnt = 0;     for (int i = 1; i <= m; ++i)       if (check(i)) {         qmax.push(i);         qmin.push(i);       }     int cur = 1;     while (1) {       int x;       if (cur % 2) {         if (qmax.empty()) break;         x = qmax.top();         qmax.pop();         if (vis[x]) continue;       } else {         if (qmin.empty()) break;         x = qmin.top();         qmin.pop();         if (vis[x]) continue;       }       if (check(x) == false) continue;       cur++;       vis[x] = 1;       ans[++anscnt] = x;       for (int i = 0; i < 3; ++i)         if (down[x][i]) {           int id = down[x][i];           if (Check(id, x)) {             qmax.push(id);             qmin.push(id);           }         }       Remove(x);     }   }   int main() {     scanf( %d , &m);     for (int i = 1; i <= (m); ++i) {       scanf( %d%d , &v[i][0], &v[i][1]);       mp[make_pair(v[i][0], v[i][1])] = i;     }     for (int i = 1; i <= (m); ++i) {       int id, a = v[i][0], b = v[i][1];       if (mp.find(make_pair(a - 1, b - 1)) != mp.end())         down[i][0] = mp[make_pair(a - 1, b - 1)];       if (mp.find(make_pair(a, b - 1)) != mp.end())         down[i][1] = mp[make_pair(a, b - 1)];       if (mp.find(make_pair(a + 1, b - 1)) != mp.end())         down[i][2] = mp[make_pair(a + 1, b - 1)];       if (mp.find(make_pair(a - 1, b + 1)) != mp.end())         up[i][0] = mp[make_pair(a - 1, b + 1)];       if (mp.find(make_pair(a, b + 1)) != mp.end())         up[i][1] = mp[make_pair(a, b + 1)];       if (mp.find(make_pair(a + 1, b + 1)) != mp.end())         up[i][2] = mp[make_pair(a + 1, b + 1)];     }     Topo();     long long rlt = 0;     for (int i = 1; i <= anscnt; ++i) rlt = (rlt * m % mod + ans[i] - 1) % mod;     printf( %I64d n , rlt);     return 0;   }


#include <bits/stdc++.h>   #pragma optimization_level 3   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   const long long N = 1e6 + 5;   const long long mod = 1e+9 + 7;   const long long INF = 0x7f7f7f7f7f7f7f7f;   const int INFi = 0x7f7f7f7f;   long long n, k;   long long ch(long long first) {     long long ans = first;     while (first) {       first /= k;       ans += first;     }     return (ans >= n);   }   void bs() {     long long l = 1;     long long r = 1e9;     while (l <= r) {       long long mid = (l + r) / 2;       if (ch(mid))         r = mid - 1;       else         l = mid + 1;     }     cout << (r + 1) << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout << setprecision(10);     ;     cin >> n >> k;     bs();   }


#include <bits/stdc++.h>   using namespace std;   const long long llInf = 1e18 + 1e17;   const int Inf = 1e9 + 1e8, N = 1e5 + 10, Mod = 1e9 + 7;   int dp[N], t[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     dp[0] = 0;     for (int i = 1; i <= n; i++) {       cin >> t[i];       int ind2 = upper_bound(t + 1, t + i, t[i] - 90) - t - 1,           ind3 = upper_bound(t + 1, t + i, t[i] - 1440) - t - 1;       int val1 = dp[i - 1] + 20;       dp[i] = val1;       int val2 = dp[ind2] + 50, val3 = dp[ind3] + 120;       dp[i] = min({dp[i], val2, val3});     }     for (int i = 1; i <= n; i++) cout << dp[i] - dp[i - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   void __print(long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     long long f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   inline long long GCD(long long x, long long y) {     long long r = x % y;     while (r) {       x = y;       y = r;       r = x % y;     }     return y;   }   const long long N = 1e6 + 69;   long long timer;   vector<long long> adj[N];   bool vis[N];   long long low[N];   long long arr[N];   vector<pair<long long, pair<long long, long long>>> v;   vector<pair<long long, long long>> ord;   map<pair<long long, long long>, long long> mm;   map<pair<long long, long long>, long long> edgecount;   void dfs(long long v, long long p = -1) {     vis[v] = true;     arr[v] = low[v] = timer++;     for (long long x : adj[v]) {       long long to = x;       if (to == p) continue;       if (vis[to]) {         low[v] = min(low[v], arr[to]);       } else {         dfs(to, v);         low[v] = min(low[v], low[to]);         if (low[to] > arr[v] && edgecount[{to, v}] == 1) {           ;           mm[{to, v}]++;           mm[{v, to}]++;         }       }     }   }   void find_bridges(long long n) {     timer = 0;     for (long long i = 0; i < n; i++) {       vis[i] = 0;       arr[i] = -1;       low[i] = -1;     }     for (long long i = 0; i < n; ++i) {       if (!vis[i]) dfs(i);     }   }   long long sze[N], parent[N];   void make_set(long long v) {     parent[v] = v;     sze[v] = 1;   }   long long find_set(long long v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_set(long long a, long long b) {     a = find_set(a);     b = find_set(b);     if (a != b) {       if (sze[a] < sze[b]) swap(a, b);       parent[b] = a;       sze[a] += sze[b];     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long x, y, z;       cin >> x >> y >> z;       ord.push_back({x, y});       v.push_back({z, {x, y}});     }     dfs(1, 0);     ;     map<pair<long long, long long>, string> ans;     for (long long i = 1; i <= n; i++) make_set(i);     sort(v.begin(), v.end());     ;     for (long long i = 0; i < (long long)v.size(); i++) {       long long p = v[i].second.first;       long long q = v[i].second.second;       long long w = v[i].first;       vector<pair<long long, long long>> temp;       temp.push_back({p, q});       long long x = w;       while (i + 1 < (long long)v.size() && v[i + 1].first == x) {         temp.push_back({v[i + 1].second.first, v[i + 1].second.second});         i++;       };       mm.clear();       long long cnt = 0;       map<long long, long long> buddy;       vector<pair<long long, long long>> poki;       for (pair<long long, long long> erin : temp) {         p = erin.first;         q = erin.second;         if (find_set(p) == find_set(q)) {           ans[{p, q}] =  none ;           ans[{q, p}] =  none ;         } else {           poki.push_back({erin});           if (buddy.find(find_set(p)) == buddy.end()) buddy[find_set(p)] = cnt++;           if (buddy.find(find_set(q)) == buddy.end()) buddy[find_set(q)] = cnt++;         }       };       edgecount.clear();       for (long long i = 0; i <= cnt; i++) adj[i].clear();       for (pair<long long, long long> erin : poki) {         long long var1 = find_set(erin.first);         long long var2 = find_set(erin.second);         long long point1 = buddy[var1];         long long point2 = buddy[var2];         ;         edgecount[{point1, point2}]++;         edgecount[{point2, point1}]++;         adj[point1].push_back(point2);         adj[point2].push_back(point1);       }       find_bridges(cnt);       for (pair<long long, long long> erin : poki) {         p = erin.first;         q = erin.second;         long long var1 = buddy[find_set(erin.first)];         long long var2 = buddy[find_set(erin.second)];         if (mm[{var1, var2}]) {           ans[{p, q}] =  any ;           ans[{q, p}] =  any ;         } else {           ans[{p, q}] =  at least one ;           ans[{q, p}] =  at least one ;         }       }       for (pair<long long, long long> erin : poki) {         p = erin.first;         q = erin.second;         union_set(p, q);       }     }     for (pair<long long, long long> x : ord) cout << ans[x] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   vector<long long> edges[N];   long long vdiv[N];   int alreadyPrinted = 0;   void rec(int d, int k, int v, int m) {     if (v == m || alreadyPrinted == N) {       return;     }     if (v == 0) {       cout << 1 <<    ;       alreadyPrinted++;       return;     }     if (d == k) {       for (int i = 0; i < edges[v].size() && alreadyPrinted != N; i++) {         cout << vdiv[edges[v][i]] <<    ;         alreadyPrinted++;       }       return;     }     for (auto u : edges[v]) {       rec(d + 1, k, u, m);     }   }   void solve() {     long long n;     int k;     cin >> n >> k;     vector<long long> div;     for (long long i = 1; i * i <= n; i++) {       if (n % i == 0) {         div.push_back(i);         if (i * i != n) div.push_back(n / i);       }     }     sort(div.begin(), div.end());     int m = div.size();     for (int i = 0; i < m; i++) {       vdiv[i] = div[i];       for (int j = i; j < m; j++) {         if (div[j] % div[i] == 0) edges[j].push_back(i);       }     }     if (k > 0)       rec(1, k, m - 1, m);     else       cout << n <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   int a[102][102];   int main() {     int n, m;     cin >> n >> m;     int sum = 0;     for (int i = 0; i < m; i++) {       int x, y, c;       cin >> x >> y >> c;       a[x - 1][y - 1] = c;       sum += c;     }     for (int i = 0; i < n; i++) {       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           int k = 0;           while (k < n && a[i][j] > 0) {             if (a[j][k] > 0) {               int t = min(a[i][j], a[j][k]);               a[j][k] -= t;               a[i][j] -= t;               a[i][k] += t;               sum -= t;             }             k++;           }         }       for (int i = 0; i < n; i++) {         sum -= a[i][i];         a[i][i] = 0;       }     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long arr[200011];   long long sum[200011];   bool check(int k) {     int i;     for (i = 1; i <= n; i++) sum[i] = 0;     for (i = n; i >= 3; i--) {       if (sum[i] + arr[i] < k) return 0;       long long d = (sum[i] + arr[i] - k) / 3;       long long d3 = d * 3;       d3 = min(d3, arr[i]);       sum[i - 2] += d3 / 3 * 2;       sum[i - 1] += d3 / 3;     }     return sum[2] + arr[2] >= k && sum[1] + arr[1] >= k;   }   int main() {     cin.tie(nullptr);     cout.tie(nullptr);     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       cin >> n;       int i;       for (i = 1; i <= n; i++) cin >> arr[i];       int l = 0, r = 1e9 + 5, mid;       while (l + 1 < r) {         mid = l + r >> 1;         if (check(mid))           l = mid;         else           r = mid;       }       cout << l <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2 * acos(0.0);   void fastInOut();   int power(int z, int i) {     int zz = 1;     for (int k = 0; k < i; k++) {       zz *= z;     }     return zz;   }   long long power(long long x, long long y) {     long long z = 1;     for (long long i = 0; i < y; i++) z *= x;     return z;   }   unsigned long long power(unsigned long long b, unsigned long long pow) {     if (b == 0)       return 0;     else if (pow == 1)       return b;     else if (pow % 2 == 0)       return power(b * b, pow / 2);     else       return b * power(b * b, pow / 2);   }   int main() {     fastInOut();     int n, x, y, res1 = 0, res2 = 0, sum = 0;     cin >> n;     vector<pair<int, int>> v;     while (n--) {       cin >> x >> y;       v.push_back({x, y});     }     int arr[100000] = {0};     arr[2] = 1;     for (int i = 3; i < 100000; i++) arr[i] = arr[i - 1] + (i - 1);     for (int i = 1; i <= 1000; i++) {       res1 = res2 = 0;       for (int k = 0; k < v.size(); k++) {         if (1 + i == v[k].first + v[k].second) res1++;         if (1 - i == v[k].first - v[k].second) res2++;       }       sum += (arr[res1] + arr[res2]);       res1 = res2 = 0;       if (i > 1 && i < 1000) {         for (int k = 0; k < v.size(); k++) {           if (1000 + i == v[k].first + v[k].second) res1++;           if (1000 - i == v[k].first - v[k].second) res2++;         }       }       sum += (arr[res1] + arr[res2]);     }     cout << sum;   }   void fastInOut() {     ios_base::sync_with_stdio(0);     cin.tie(NULL), cout.tie(NULL);   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long dp[1010][1010], sum[1010];   int main() {     memset(dp, 0, sizeof(dp));     int n, m, r;     cin >> n >> m >> r;     for (int i = 0; i <= 1000; i++) dp[0][i] = 1;     for (int i = 1; i <= r; i++) {       memset(sum, 0, sizeof(sum));       for (int j = 3; j <= 1000; j++) {         sum[j] = (sum[j - 1] + dp[i - 1][j - 2]) % mod;         dp[i][j] = (dp[i][j - 1] + sum[j]) % mod;       }     }     cout << dp[r][n] * dp[r][m] % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   char s[60];   int main() {     cin >> s;     set<string> A;     int n = strlen(s);     for (int i = 0; i < n; ++i) {       string cur;       for (int j = 0; j < n; ++j) {         cur += s[(i + j) % n];       }       A.insert(cur);     }     cout << A.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     string st;     int l;   };   int n, k, cnt = 0, m;   node a[1000];   bool cmp(const node &x, const node &y) { return (x.l < y.l); }   bool substring(string s1, string s2) {     for (int i = 0; i <= s2.length() - s1.length(); i++) {       bool flag = 1;       for (int j = 0; j < s1.length(); j++) {         if (s2[i + j] != s1[j]) {           flag = 0;           break;         }       }       if (flag) return 1;     }     return 0;   }   bool judge(void) {     for (int i = 1; i < n; i++) {       if (!substring(a[i].st, a[i + 1].st)) {         return 0;       }     }     return 1;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].st;       a[i].l = a[i].st.length();     }     sort(a + 1, a + n + 1, cmp);     if (judge()) {       cout <<  YES  << endl;       for (int i = 1; i <= n; i++) {         cout << a[i].st << endl;       }     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void show(const vector<T> &a) {     for (T x : a) cout << x <<    ;     cout << endl;   }   signed main() {     long long tc;     cin >> tc;     while (tc--) {       long long x, y, z;       cin >> x >> y >> z;       vector<long long> a(3);       a[2] = z;       a[1] = y;       a[0] = x;       sort(a.begin(), a.end());       if (a[2] == a[1]) {         cout <<  YES  << endl;         cout << a[0] <<     << a[0] <<     << a[2] << endl;       } else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f;     int g = 1000;     cin >> a >> b >> c >> d >> e >> f;     if ((b * d * f) > (a * c * e) || (c == 0 && d != 0) ||         (a == 0 && b != 0 && d != 0))       cout <<  Ron  << endl;     else       cout <<  Hermione  << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   const int maxn = 2e5 + 5;   const int minn = 65;   const long long mod = 1e9 + 7;   const long long mod1 = 998244353;   const long double pi = acos(-1.);   class Matrix {    public:     int n, m;     std::vector<std::vector<long long>> mat;     Matrix(int n, int m)         : n(n),           m(m),           mat(std::vector<std::vector<long long>>(               n, std::vector<long long>(m, 0ll))) {}     Matrix(std::vector<std::vector<long long>> mat)         : mat(mat), n(mat.size()), m(mat[0].size()) {}     Matrix operator*(Matrix& other) {       if (this->m != other.n) {         printf( Wrong size: %d*%d X %d*%d n , this->n, this->m, other.n, other.m);         throw  Wrong size ;       }       Matrix answ = Matrix(this->n, other.m);       for (int i = 0; i < answ.n; i++) {         for (int j = 0; j < answ.m; j++) {           for (int k = 0; k < this->m; k++) {             answ.mat[i][j] += this->mat[i][k] * other.mat[k][j];             answ.mat[i][j] %= (mod - 1ll);           }         }       }       return answ;     }     Matrix& operator*=(Matrix& other) {       if (this->m != other.n) {         printf( Wrong size: %d*%d X %d*%d n , this->n, this->m, other.n, other.m);         throw  Wrong size ;       }       Matrix answ = Matrix(this->n, other.m);       for (int i = 0; i < answ.n; i++) {         for (int j = 0; j < answ.m; j++) {           for (int k = 0; k < this->m; k++) {             answ.mat[i][j] += this->mat[i][k] * other.mat[k][j];             answ.mat[i][j] %= (mod - 1ll);           }         }       }       (*this) = answ;       return (*this);     }     Matrix operator^(long long x) {       if (x == 0) {         printf( Not implemented yet. n );         throw  Not implemented ;       } else if (x == 1)         return *this;       else {         Matrix y = (*this) ^ (x / 2ll);         if (x % 2ll == 0) {           return y * y;         } else {           return y * y * (*this);         }       }     }     Matrix& operator^=(long long x) {       if (x == 0) {         printf( Not implemented yet. n );         throw  Not implemented ;       } else if (x == 1)         return *this;       else {         Matrix y = (*this) ^ (x / 2ll);         if (x % 2ll == 0) {           *this = y * y;           return *this;         } else {           *this = y * y * (*this);           return (*this);         }       }     }     Matrix operator%(long long xmod) {       if (xmod == 0) {         printf( Can t divide by 0 );         throw  Can t divide by 0 ;       }       Matrix answ(this->n, this->m);       for (int i = 0; i < answ.n; i++) {         for (int j = 0; j < answ.m; j++) {           answ.mat[i][j] = this->mat[i][j] % xmod;         }       }       return answ;     }     Matrix& operator%=(long long xmod) {       if (xmod == 0) {         printf( Can t divide by 0 );         throw  Can t divide by 0 ;       }       for (int i = 0; i < this->n; i++) {         for (int j = 0; j < this->m; j++) {           this->mat[i][j] %= xmod;         }       }     }   };   std::vector<long long> prime;   int pr[maxn];   void precalc() {     for (int i = 2; i < maxn; i++) {       if (!pr[i]) {         prime.push_back((long long)i);         for (int j = i * i; j < maxn; j += i) {           pr[i] = 1;         }       }     }   }   std::map<long long, int> PrimeDecomposition(long long x) {     std::map<long long, int> answ;     for (long long y : prime) {       if (x <= 1) break;       int cnt = 0;       while (x % y == 0) {         x /= y;         cnt++;       }       if (cnt)         answ[y] += cnt;       else if (y * y > x) {         answ[x]++;         break;       }     }     return answ;   }   long long binpow(long long a, long long x) {     long long res = 1ll;     while (x) {       if (x & 1ll) res *= a, res %= mod;       a *= a;       a %= mod;       x >>= 1ll;     }     return (res % mod + 2ll * mod) % mod;   }   void solve() {     precalc();     long long f[4], n, c;     scanf( %lld%lld%lld%lld%lld , &n, &f[0], &f[1], &f[2], &c);     Matrix matrix = Matrix({{1ll, 1ll, 1ll}, {1ll, 0ll, 0ll}, {0ll, 1ll, 0ll}});     matrix ^= (n - 3ll);     std::set<long long> primes;     std::map<long long, int> FG[5];     for (int i = 0; i < 3; i++) {       FG[i] = PrimeDecomposition(f[i]);       for (std::pair<long long, long long> x : FG[i]) {         primes.insert(x.first);       }     }     FG[3] = PrimeDecomposition(c);     for (std::pair<long long, long long> x : FG[3]) {       primes.insert(x.first);     }     std::vector<std::pair<long long, long long>> FnCn;     for (long long x : primes) {       Matrix PrimeCount = Matrix(3, 1);       for (int i = 0; i < 3; i++) {         PrimeCount.mat[2 - i][0] += FG[i][x];         PrimeCount.mat[2 - i][0] += FG[3][x] * 1ll * (i + 1);       }       Matrix Lprimes = matrix * PrimeCount;       FnCn.push_back({x, Lprimes.mat[0][0]});     }     long long answ = 1ll;     for (std::pair<long long, long long> x : FnCn) {       answ *= binpow(x.first, x.second);       answ %= mod;     }     answ *= binpow(binpow(c, mod - 2ll), n);     answ %= mod;     printf( %lld n , answ);     return;   }   int main() {     int t;     t = 1;     while (t--) {       solve();     }     std::cin >> t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long f[2000007];   void pre() {     f[0] = 1;     for (int i = 1; i <= 2000001; i++) {       f[i] = i * f[i - 1] % mod;     }   }   long long powmod(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = res * x % mod;       x = x * x % mod;       n >>= 1;     }     return res;   }   long long C(int n, int k) {     if (k > n) {       return 0;     }     return f[n] * powmod(f[k], mod - 2) % mod * powmod(f[n - k], mod - 2) % mod;   }   int main() {     pre();     int n;     cin >> n;     n++;     long long ans = (2 * C(2 * n - 1, n) + mod - 1) % mod;     cout << ans % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int f = 1, x = 0;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -f;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     return x * f;   }   const int N = 3e2 + 5;   int n, m, p, q;   pair<int, int> a[N * N];   int id(int i, int j) { return (i - 1) * m + j; }   void work() {     n = read(), m = read();     for (int i = 1; i <= n * m; i++) {       a[i] = (pair<int, int>){read(), i};     }     sort(a + 1, a + 1 + n * m);     for (int i = 1; i <= n * m; i++) {       a[i].second *= -1;     }     int res = 0;     for (int i = 1; i <= n; i++) {       sort(a + id(i, 1), a + id(i, m) + 1);       for (int j = 1; j <= m; j++) {         for (int k = 1; k < j; k++) {           if (a[id(i, j)].second < a[id(i, k)].second) res++;         }       }     }     cout << res <<   n ;   }   int main() {     q = read();     while (q--) work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long gcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long x1, y1;     long long g = gcd(b, a % b, x1, y1);     x = y1;     y1 = x1 - y1 * (a / b);     return g;   }   long long qpow(long long a, long long n) {     long long res = 1;     while (n) {       if (n % 2) {         res = (res * a) % MOD;         n--;       } else {         n = n / 2;         a = (a * a) % MOD;       }     }     return res;   }   long long inv(long long a) { return qpow(a, MOD - 2); }   bool cmp(pair<long long, long long> &p1, pair<long long, long long> &p2) {     if (p1.first != p2.first) return p1.first < p2.first;     return p1.second < p2.second;   }   bool prime(long long n) {     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   long long sum(long long n) {     long long second = 0;     while (n) {       second += n % 10;       n /= 10;     }     return second;   }   void solve() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long second, x;     cin >> second >> x;     long long c = 0;     vector<long long> a;     for (int i = 0; i < 42; i++) {       if (x & (1LL << i)) {         c++;         second -= (1LL << i);       } else         a.push_back(1LL << (i + 1));     }     if (second < 0) {       cout << 0 <<   n ;       return;     }     sort(a.begin(), a.end(), greater<long long>());     bool ok = false;     for (int i = 0; i < a.size(); i++) {       if (a[i] <= second) {         ok = true;         second -= a[i];       }     }     if (second == 0) {       if (ok)         cout << (1LL << c) <<   n ;       else {         cout << max(0LL, (1LL << c) - 2) <<   n ;       }     } else       cout << 0 <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long mod = 1000000007;   template <class T1>   void deb(T1 e1) {     cout << e1 <<   n ;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 <<   n ;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 <<   n ;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<   n ;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<   n ;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          <<   n ;   }   int main() {     int nob, nog, dancing_jodis = 0;     cin >> nob >> nog;     vector<pair<int, int> > store;     int max_gender = max(nob, nog);     int min_gender = min(nob, nog);     for (int gender = 1; gender <= min_gender; gender++, dancing_jodis++)       (nob >= nog) ? store.push_back(make_pair(1, gender))                    : store.push_back(make_pair(gender, 1));     for (int gender = 2; gender <= max_gender; gender++, dancing_jodis++)       (nob >= nog) ? store.push_back(make_pair(gender, 1))                    : store.push_back(make_pair(1, gender));     cout << dancing_jodis <<   n ;     for (int jodi = 0; jodi < int((store).size()); jodi++)       cout << store[jodi].first <<     << store[jodi].second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (1 << 17);   int a[maxn], pos[maxn], n, b[maxn];   struct num {     int idx, val;     bool operator<(const num &mtp) const { return val > mtp.val; }   };   priority_queue<num> q1, q2;   int out[maxn];   void read() {     int i;     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       pos[a[i]] = i;     }     for (i = 1; i <= n; ++i) {       scanf( %d , &b[i]);     }   }   void solve() {     int i;     num tmp;     tmp.idx = maxn + 1;     tmp.val = maxn + 1;     q1.push(tmp);     q2.push(tmp);     for (i = 1; i <= n; ++i) {       if (i > pos[b[i]]) {         tmp.idx = i;         tmp.val = i - pos[b[i]];         q1.push(tmp);       } else {         tmp.idx = i;         tmp.val = pos[b[i]] - i;         q2.push(tmp);       }     }     printf( %d n , min(q1.top().val, q2.top().val));     int k = 0;     for (i = 1; i < n; ++i) {       k++;       tmp.idx = i;       tmp.val = n - pos[b[i]] + k;       q1.push(tmp);       out[i] = 1;       while ((q1.top().val - k) == 0) {         tmp.idx = q1.top().idx;         tmp.val = (-1) * k;         q2.push(tmp);         out[q1.top().idx] = 0;         q1.pop();       }       while (out[q2.top().idx]) q2.pop();       printf( %d n , min(q1.top().val - k, q2.top().val + k));     }   }   int main() {     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long q[1000001], a[100001];   int main() {     long long n, x, cnt = 0;     cin >> n >> x;     for (int i = 1; i <= n; i++) {       cin >> a[i];       q[a[i]]++;     }     int e = 0;     if (!x) {       e = 1;     }     for (int i = 1; i <= n; i++) {       int w = x;       w ^= a[i];       cnt += q[w] - e;       q[a[i]]--;     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double INF = 1e12, epsilon = 1e-8;   long double Y_AXIS, res = INF;   vector<pair<long double, bool> > forbid;   inline long double sqr(long double x) { return x * x; }   inline long double dist(long double x1, long double y1, long double x2 = 0,                           long double y2 = 0) {     return sqr(x1 - x2) + sqr(y1 - y2);   }   inline long double area(long double x1, long double y1, long double x2,                           long double y2, long double x3, long double y3) {     return (x1 - x2) * (y1 - y3) - (x1 - x3) * (y1 - y2);   }   inline void mini(long double &a, long double b) {     if (a > b) a = b;   }   long double binsearch(long double x, long double y, int r) {     long double L = -INF, R = INF, mid;     while (L + epsilon < R) {       mid = (L + R) / 2;       (sqrt(dist(x, y, mid)) + r < sqrt(dist(mid, Y_AXIS)) ^ x < 0 ? R : L) = mid;     }     return mid;   }   bool check_zero() {     int cnt = 0;     for (pair<long double, bool> info : forbid)       if (abs(++cnt -= (info.first > 0 ^ info.second) << 1) > 1) return false;     return true;   }   int main() {     int x1, y1, x2, y2, n;     scanf( %d%d%d%d%d , &x1, &y1, &x2, &y2, &n);     Y_AXIS = sqrt(dist(x1, y1, x2, y2)) / 2;     for (int i = 0; i < n; ++i) {       int x, y, r;       scanf( %d%d%d , &x, &y, &r);       long double xx = area(x, y, x1, y1, x2, y2) / Y_AXIS / 2;       long double yy =           sqrt(dist(x, y, (x1 + x2) / 2.0, (y1 + y2) / 2.0) - sqr(xx));       forbid.push_back(make_pair(binsearch(xx, yy, r), xx > 0));       forbid.push_back(make_pair(binsearch(xx, yy, -r), xx < 0));     }     if (check_zero()) {       printf( %.9Lf , Y_AXIS);       return 0;     }     sort(forbid.begin(), forbid.end());     int cnt = 0;     for (pair<long double, bool> info : forbid)       if (info.second && !--cnt || !info.second && !cnt++)         mini(res, sqrt(dist(info.first, Y_AXIS)));     printf( %.9Lf , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void MACRO_VAR_Scan(T& t) {     cin >> t;   }   template <typename First, typename... Rest>   void MACRO_VAR_Scan(First& first, Rest&... rest) {     cin >> first;     MACRO_VAR_Scan(rest...);   }   template <typename T>   void MACRO_VEC_ROW_Init(int n, T& t) {     t.resize(n);   }   template <typename First, typename... Rest>   void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) {     first.resize(n);     MACRO_VEC_ROW_Init(n, rest...);   }   template <typename T>   void MACRO_VEC_ROW_Scan(int p, T& t) {     cin >> t[p];   }   template <typename First, typename... Rest>   void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) {     cin >> first[p];     MACRO_VEC_ROW_Scan(p, rest...);   }   void _main();   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     _main();   }   inline long long toInt(std::string s) {     long long v;     std::istringstream sin(s);     sin >> v;     return v;   }   template <class T>   inline string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <typename A, typename B>   inline void chmin(A& a, B b) {     if (a > b) a = b;   }   template <typename A, typename B>   inline void chmax(A& a, B b) {     if (a < b) a = b;   }   long long qp(long long a, long long b) {     long long ans = 1ll;     do {       if (b & 1) ans = 1ll * ans * a;       a = 1ll * a * a;     } while (b >>= 1);     return ans;   }   long long qpmod(long long a, long long b, long long mo) {     long long ans = 1ll;     do {       if (b & 1) ans = 1ll * ans * a % mo;       a = 1ll * a * a % mo;     } while (b >>= 1);     return ans;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline bool valid(int x, int h) { return 0 <= x && x < h; }   const double EPS = 1e-10;   const double PI = acos(-1.0);   const int INF = (int)(1e9) + 7;   const long long MOD = (long long)(1e9) + 7;   const long long MOD2 = (long long)(1e18) + 9;   const long long INF2 = (long long)(1e18);   const long long INTMAX = (0x7FFFFFFFL);   const long long LLMAX = (0x7FFFFFFFFFFFFFFFL);   const int N4 = (int)1e4 + 10;   const int N5 = (int)1e5 + 10;   int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};   int dy[8] = {0, 1, 0, -1, -1, -1, 1, 1};   long long ans, cnt, ret, cur, f;   void _main() {     map<int, int> ma;     int n;     MACRO_VAR_Scan(n);     ;     vector<int> v(n);     for (auto& i : v) cin >> i;     ;     for (auto& x : v) ma[x]++;     for (auto& x : ma) chmax(ret, x.second);     cout << ret << endl;     ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   int read_int() {     bool minus = false;     int result = 0;     char ch;     ch = getchar();     while (1) {       if (ch ==  - ) break;       if (ch >=  0  && ch <=  9 ) break;       ch = getchar();     }     if (ch ==  - )       minus = true;     else       result = ch -  0 ;     while (1) {       ch = getchar();       if (ch <  0  || ch >  9 ) break;       result = result * 10 + (ch -  0 );     }     if (minus)       return -result;     else       return result;   }   const int MAX = 2e5 + 10;   unsigned char v[MAX];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n = read_int();     for (int i = 0; i < n; i++) v[i] = read_int();     int q = read_int();     while (q--) {       int l = read_int(), r = read_int();       unsigned char x = read_int(), y = read_int();       l--, r--;       for (int i = l; i <= r; i++) v[i] = v[i] == x ? y : v[i];     }     for (int i = 0; i < n; i++) cout << int(v[i]) <<    ;     cout <<   n ;     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   long long k, b, n, t;   int main() {     cin >> k >> b >> n >> t;     int temp = 0;     long long acc = 1;     while (acc <= t) {       acc *= k;       acc += b;       temp++;     }     int ans = n - temp + 1;     if (ans < 0)       cout << 0 << endl;     else       cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   int func(int a, int b) {     if (a == 1 and b >= 1) return (b - a);     if (a == b or b % a == 0 or a <= 0 or b <= 0) return INT_MAX;     int ret = func(b % a, a);     if (ret != INT_MAX) ret += b / a;     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     if (n == 1) {       cout << 0 << endl;       return 0;     }     int ans = INT_MAX;     for (int i = n >> 1; i > 0; i--) {       ans = min(ans, func(i, n - i));     }     cout << ans + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool vis[12][12][12];   int ans2(int x, int y, int z, char a[12][12][12], int k, int n, int m) {     int cnt = 0;     if (a[x][y][z] ==  #  || vis[x][y][z]) return 0;     cnt++;     vis[x][y][z] = true;     if (x > 1) cnt += ans2(x - 1, y, z, a, k, n, m);     if (x < k) cnt += ans2(x + 1, y, z, a, k, n, m);     if (y > 1) cnt += ans2(x, y - 1, z, a, k, n, m);     if (y < n) cnt += ans2(x, y + 1, z, a, k, n, m);     if (z > 1) cnt += ans2(x, y, z - 1, a, k, n, m);     if (z < m) cnt += ans2(x, y, z + 1, a, k, n, m);     return cnt;   }   int ans(int x, int y, int z, char a[12][12][12], int k, int n, int m) {     int cnt = 0;     vis[x][y][z] = true;     if (a[x][y][z] ==  . ) cnt++;     if (a[x][y][z] ==  . ) {       if (x < k) cnt += ans2(x + 1, y, z, a, k, n, m);     }     if (y > 1) cnt += ans2(x, y - 1, z, a, k, n, m);     if (y < n) cnt += ans2(x, y + 1, z, a, k, n, m);     if (z > 1) cnt += ans2(x, y, z - 1, a, k, n, m);     if (z < m) cnt += ans2(x, y, z + 1, a, k, n, m);     return cnt;   }   int main() {     int n, k, m;     char a[12][12][12];     cin >> k >> n >> m;     for (int i = 1; i <= k; i++) {       for (int j = 1; j <= n; j++) {         for (int t = 1; t <= m; t++) {           cin >> a[i][j][t];         }       }     }     int x, y;     cin >> x >> y;     cout << ans(1, x, y, a, k, n, m) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     long long A[50001];     long long total = 0;     for (int i = 0; i < N; ++i) {       cin >> A[i];       total += A[i];     }     long long x = total / N;     long long res = 0;     long long bal = 0;     for (int i = 0; i < N; ++i) {       res += abs(bal);       bal += x - A[i];     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string S;   const int MAX_N = 5000;   bool wyn[MAX_N + 3][MAX_N + 3];   int main() {     ios::sync_with_stdio(0);     cin >> S;     int wynik = 0;     int val = 0;     int zap = 0;     for (int l = 0; l < S.size(); l++) {       val = 0;       zap = 0;       for (int r = l; r < S.size(); r++) {         if (S[r] ==  ( )           val++;         else if (S[r] ==  ) )           val--;         else if (S[r] ==  ? )           zap++;         if (val + zap >= 0)           wyn[l][r] = true;         else           break;       }     }     for (int r = 0; r < S.size(); r++) {       val = 0;       zap = 0;       for (int l = r; l >= 0; l--) {         if (S[l] ==  ( )           val--;         else if (S[l] ==  ) )           val++;         else if (S[l] ==  ? )           zap++;         int len = r - l + 1;         if (val + zap >= 0) {           if (wyn[l][r] && len % 2 == 0) wynik++;         } else           break;       }     }     cout << wynik;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, k, a[N];   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int g = a[0];     for (int i = 1; i < n; i++) {       g = gcd(g, a[i]);     }     int gk = gcd(g, k);     if (gk == k) {       printf( 1 n );       printf( 0 n );     } else {       vector<int> vc;       for (int x = 0; x < k; x += gk) {         vc.push_back(x);       }       printf( %d n , vc.size());       for (int i = 0; i < vc.size(); i++) {         printf( %d  , vc[i]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int num[200000];   long long cnt[200000] = {0};   long long dp[200000] = {0};   long long sum[200000] = {0};   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> num[i];       cnt[num[i]]++;     }     long long ans = 0;     for (int i = 1; i < 200000; ++i) {       if (i > 1) {         dp[i] = max(dp[i - 2] + cnt[i] * i, dp[i - 1]);       } else {         dp[i] = cnt[i] * i;       }       ans = max(ans, dp[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   long long ln, lk, lm;   char s[100005];   void fmain() {     scanf( %d%d%d , &n, &m, &k);     scanf( %s , s + 1);     for (int ty, l, r, x, i = 0; i < m + k; i++) {       scanf( %d%d%d%d , &ty, &l, &r, &x);       if (ty == 1) {         memset(s + l,  0  + x, r - l + 1);       } else {         bool fg = memcmp(s + l, s + l + x, r - x - l + 1) == 0;         puts(fg ?  YES  :  NO );       }     }   }   int main() {     fmain();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Arco {     int v, next;     Arco() {}     Arco(int v, int next) : v(v), next(next) {}   } edges[1];   int last[1], E;   void add_edge(int v, int u) {     edges[E] = Arco(u, last[v]);     last[v] = E++;   }   int xf[8] = {-1, -1, -1, 0, 0, +1, +1, +1};   int xc[8] = {-1, 0, +1, -1, +1, -1, 0, +1};   bool esta[30];   bool M[256][256];   int METODO(char *cad) {     int sol = 0;     return sol;   }   int main() {     char texto[100004];     char cad[10];     int q;     scanf( %s , texto);     scanf( %d , &q);     int sol = 0, len = strlen(texto);     while (q--) {       scanf( %s , cad);       for (int i = 0; i < len; i++)         if (texto[i] == cad[0] || texto[i] == cad[1]) {           int a = 0, b = 0, j = i;           while (j < len && (texto[j] == cad[0] || texto[j] == cad[1]))             if (texto[j++] == cad[0])               a++;             else               b++;           sol += min(a, b);           i = j;         }     }     printf( %d n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       long long l_occ_1 = -1, l_occ_2 = -1, l_occ_3 = -1;       long long maxi = s.length() + 1, mini;       for (long long i = 0; i < s.length(); i++) {         if (s[i] ==  1 ) l_occ_1 = i;         if (s[i] ==  2 ) l_occ_2 = i;         if (s[i] ==  3 ) l_occ_3 = i;         if (!(l_occ_1 == -1 || l_occ_2 == -1 || l_occ_3 == -1)) {           long long x = max(abs(l_occ_1 - l_occ_3), abs(l_occ_2 - l_occ_3));           mini = max(x, abs(l_occ_1 - l_occ_2));           maxi = min(maxi, mini);         }       }       if (l_occ_1 == -1 || l_occ_2 == -1 || l_occ_3 == -1) maxi = -1;       cout << maxi + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 5;   const long long INF = 100000000000000;   long long h[maxn], p[maxn];   long long l[maxn], r[maxn];   int n, m;   bool ok(long long t) {     for (int i = 0; i < n; i++) {       l[i] = h[i];       r[i] = h[i];     }     int k = 0;     for (int i = 0; i < m; i++) {       if (p[i] >= l[k] && p[i] <= r[k]) continue;       if (p[i] < l[k]) {         if (r[k] - p[i] > t) {           return false;         } else {           l[k] = p[i];         }       }       if (p[i] > r[k]) {         if (p[i] - l[k] + min(p[i] - h[k], h[k] - l[k]) > t) {           k++;           if (k >= n) return false;           i--;         } else {           r[k] = p[i];         }       }     }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %I64d , &h[i]);     for (int i = 0; i < m; i++) scanf( %I64d , &p[i]);     long long l = -1, r = INF;     while (l < r - 1) {       long long mid = (l + r) / 2;       if (ok(mid)) {         r = mid;       } else {         l = mid;       }     }     cout << r << endl;   }


#include <bits/stdc++.h>   char s1[1000100], s2[1000100];   char s[1000100 * 2];   int i, j, n, m;   inline char rev(char& a) {     if (a ==  N ) return  S ;     if (a ==  W ) return  E ;     if (a ==  S ) return  N ;     if (a ==  E ) return  W ;     return 0;   }   int z[1000100 * 2];   inline void Z() {     int L = 0, R = 0;     for (int i = 1; i < n; i++) {       if (i > R) {         L = R = i;         while (R < n && s[R - L] == s[R]) R++;         z[i] = R - L;         R--;       } else {         int k = i - L;         if (z[k] < R - i + 1)           z[i] = z[k];         else {           L = i;           while (R < n && s[R - L] == s[R]) R++;           z[i] = R - L;           R--;         }       }     }   }   int main() {     scanf( %d , &n);     n--;     scanf(  %s %s , s1, s2);     for (i = 0; i < n; i++) {       s2[i] = rev(s2[i]);       s[n - i - 1] = s2[i];       s[i + n] = s1[i];     }     n *= 2;     Z();     n /= 2;     for (i = 0; i < n; i++) {       if (z[i + n] >= n - i) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 1e5 + 10;   char s[N];   int f[N][3];   bool _ok(int x, int y, int z) {     if (x == z && z == y) return true;     if (x == z && y == z - 1) return true;     if (y == z && y == x - 1) return true;     return false;   }   bool ok(int x, int y, int z) {     if (x + y + z < 3) return true;     return _ok(x, y, z) || _ok(z, x, y) || _ok(y, z, x);   }   int main() {     scanf( %s , s);     int n = (int)strlen(s);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < 3; ++j) f[i + 1][j] = f[i][j];       ++f[i + 1][s[i] -  x ];     }     int m, l, r;     for (scanf( %d , &m); m--;) {       scanf( %d%d , &l, &r);       int x = f[r][0] - f[l - 1][0], y = f[r][1] - f[l - 1][1],           z = f[r][2] - f[l - 1][2];       if (ok(x, y, z))         puts( YES );       else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, y, ans;   struct Edge {     long long to, next;   } edge[2 * 300001];   long long head[300001], sze;   long long fa[300001], Tsze[300001], deep[300001];   inline char gc() {     static char now[1 << 20], *S, *T;     if (T == S) {       T = (S = now) + fread(now, 1, 1 << 20, stdin);       if (T == S) return EOF;     }     return *S++;   }   inline long long read() {     long long res = 0;     char c;     while ((c = getchar()) <  0  || c >  9 )       ;     res = (c ^ 48);     while ((c = getchar()) >=  0  && c <=  9 )       res = (res << 3) + (res << 1) + (c ^ 48);     return res;   }   inline void add(long long u, long long v) {     edge[++sze] = (Edge){v, head[u]}, head[u] = sze;     edge[++sze] = (Edge){u, head[v]}, head[v] = sze;   }   inline void dfs(long long u, long long f) {     fa[u] = f, deep[u] = deep[f] + 1, Tsze[u] = 1;     long long i;     for (i = head[u]; i; i = edge[i].next) {       long long v = edge[i].to;       if (v == f) continue;       dfs(v, u), Tsze[u] += Tsze[v];     }   }   inline long long ask() {     if (deep[x] > deep[y]) swap(x, y);     long long ok = 0, i;     for (i = y; i; i = fa[i])       if (i == x) {         ok = 1;         break;       }     if (ok) return (n - Tsze[x] + 1) * Tsze[y];     return Tsze[x] * Tsze[y];   }   signed main() {     n = read(), x = read(), y = read(), ans = n * (n - 1);     long long i;     for (i = 1; i < n; i++) add(read(), read());     dfs(1, 0);     long long a = x, b = y, ok = 0;     for (; a; a = fa[a])       if (fa[a] == y) ans -= Tsze[x] * (n - Tsze[a]), ok = 1;     for (; b; b = fa[b])       if (fa[b] == x) ans -= Tsze[y] * (n - Tsze[b]), ok = 1;     if (!ok) ans -= Tsze[x] * Tsze[y];     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, n, r, a, q;   void solve() {     cin >> n;     if (n == 4 || n == 1 || n == 2) {       cout <<  -1 n ;       return;     }     a = n / 3;     r = n % 3;     if (r == 1) {       cout << n / 3 - 2 <<   0              <<  1 n ;       return;     }     if (r == 2) {       cout << n / 3 - 1 <<   1 0             <<   n ;       return;     }     cout << n / 3 <<   0           <<   0           <<   n ;   }   int main() {     for (cin >> q; q--;) {       solve();     }   }


#include<bits/stdc++.h>   #define ll long long   #define all(v) v.begin(),v.end()   #define rall(v) v.rbegin(),v.rend()   #define sz(x) (int)(x).size()   #define PB push_back   #define PI 3.1415926535897932384626433832795   #define what(x) cout<<#x<<  is  <<x<<endl;   using namespace std;      #ifdef LOCAL//ONLINE_JUDGE   #include  D: c_c++ template.h    #else   #define debug(...) 42   #endif      ll powmod(ll a,ll b,ll mod) {       ll res=1;a%=mod;       for(;b;b>>=1){           if(b&1)res=res*a%mod;      a=a*a%mod;       }       return res;   }      void solve(){    ll n,k;    cin>>n>>k;    if(k>=n){     cout<<k/n+((k%n)?1:0)<<  n ;    }else{     ll f = (n/k)*k;     if(f<n)f+=k;     cout<<f/n+((f%n)?1:0)<<  n ;         }   }         int main(){       ios::sync_with_stdio(false);       cin.tie(0);   //    #ifdef LOCAL   //    freopen( input.txt ,  r , stdin);   //    freopen( output.txt ,  w , stdout);   //    #endif       int tc=1;        cin>>tc;       while(tc--)solve();   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long double PI = 4 * atan((long double)1);   long long power(long long a, long long n) {     long long res = 1;     while (n) {       if (n % 2) res *= a;       a *= a;       n /= 2;     }     return res;   }   string bits(long long int n) {     long long int m = n;     string s;     while (m != 0) {       char x = (m % 2) +  0 ;       s = s + x;       m = m / 2;     }     reverse(s.begin(), s.end());     return s;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     string s;     cin >> s;     int e = 0;     long long int ans = 0;     for (int i = s.size() - 1; i > 0; i--) {       if (s[i] ==  1 ) {         if (e == 0) {           ans += 2;           e = 1;         } else           ans += 1;       } else {         if (e == 0)           ans += 1;         else           ans += 2;       }     }     if (e == 1) ans += 1;     cout << ans;     return 0;   }