#include <bits/stdc++.h>   #include<cmath>   using namespace std;      int main(){       long long t;       cin>>t;       while(t--){           int a,b,n;           long long ans=0;           cin>>a>>b>>n;           int ar[a+1],br[b+1],arr[2][n];           memset(ar,0,sizeof(ar));           memset(br,0,sizeof(br));           for(int i=0;i<n;i++){               cin>>arr[0][i];               ar[arr[0][i]]++;           }           for(int i=0;i<n;i++){               cin>>arr[1][i];               br[arr[1][i]]++;           }           for(int i=0;i<n-1;i++){               ans+=n-i-1 -ar[arr[0][i]]+1 -br[arr[1][i]]+1;               ar[arr[0][i]]--;               br[arr[1][i]]--;           }           cout<<ans<<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100100 * 3;   const int INF = 1E9;   const int base = 1E9 + 7;   void no() {     cout <<  no n ;     exit(0);   }   int a[maxn];   pair<int, int> b[maxn];   char ans[3030][3030];   int n, m;   void validate() {     vector<int> draws;     n = m;     for (int i = 0; i < n; i++)       if (a[i] & 1) draws.push_back(i);     memset(ans, 0, sizeof(ans));     for (int i = 0; i < draws.size(); i += 2) {       int x, y;       x = draws[i], y = draws[i + 1];       a[x]--, a[y]--;       ans[x][y] = ans[y][x] =  D ;     }     for (int i = 0; i < n; i++) b[i] = make_pair(a[i], i);     for (int i = 0; i < n; i++) ans[i][i] =  X ;     for (int i = 0; i < n; i++) {       sort(b + i, b + n);       reverse(b + i, b + n);       int g = b[i].second;       for (int j = n - 1; j > i; j--)         if (ans[g][b[j].second] == 0) {           char w =  W , l =  L ;           if (b[i].first > 0) {             ans[g][b[j].second] = w, ans[b[j].second][g] = l;             b[i].first -= 2;           } else {             ans[g][b[j].second] = l, ans[b[j].second][g] = w;             b[j].first -= 2;           }         }       if (b[i].first != 0) no();     }     puts( yes );     for (int i = 0; i < n; i++) puts(ans[i]);   }   int solve() {     cin >> m >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int sum = 0;     for (int i = 0; i < n; i++) sum += a[i];     if (sum > m * (m - 1)) no();     if (sum + (m - n) * a[n - 1] < m * (m - 1)) no();     while (sum < m * (m - 1))       for (int i = n; sum < m * (m - 1) && i < m; i++) a[i]++, sum++;     validate();   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   const long long mod = 1e9 + 7;   long long num[N];   long long a[N];   long long b[N];   long long ans[N];   signed main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long T = 1;     cin >> T;     while (T--) {       long long n;       cin >> n;       for (long long i = 1; i <= n; i++) cin >> num[i];       a[1] = num[1] - 1, b[1] = 1;       for (long long i = 2; i <= n; i++) {         a[i] = min(a[i - 1], num[i] - b[i - 1]);         b[i] = num[i] - a[i];       }       bool flag = true;       long long ma = *min_element(a + 1, a + 1 + n);       long long mb = *min_element(b + 1, b + n + 1);       if (ma + mb < 0) flag = false;       cout << (flag ?  YES n  :  NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b, c, d;     scanf( %lld %lld %lld %lld , &a, &b, &c, &d);     printf( %lld %lld %lld n , b, c, c);   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long a[300005], m[300005], t[300005], ans, sum, n, x, qwq;   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld%lld , &a[i], &m[i]);       x = m[i];       while (x) {         x >>= 1ll;         t[i]++;       }       sum += a[i];     }     if (sum < 0)       for (long long i = 1; i <= n; i++) a[i] *= -1ll;     for (long long i = 0; i <= 62; i++) {       qwq = 0ll;       for (long long j = 1; j <= n; j++)         if (m[j] & (1ll << i) && t[j] - 1ll == i) qwq += a[j];       if (qwq > 0) {         for (long long j = 1; j <= n; j++)           if (m[j] & (1ll << i)) a[j] *= -1ll;         ans += (1ll << i);       }     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 10;   const int MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long ans[maxn << 2];   int main() {     long long n, k, m;     scanf( %lld%lld , &n, &k);     m = (n * 6 - 1) * k;     printf( %lld n , m);     for (int i = 1; i <= n; i++) {       long long tmp = 6 * (i - 1);       printf( %lld %lld %lld %lld n , (tmp + 1LL) * k, (tmp + 2LL) * k,              (tmp + 3LL) * k, (tmp + 5LL) * k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(int x) {     if (x == 1) return false;     for (long long i = 2; i <= sqrt(x); i += 1)       if (x % i == 0) return false;     return true;   }   void print(int a[], int n) {     for (long long i = 0; i < n; i += 1) cout << a[i] <<    ;   }   void iarr(int *a, int n) {     for (long long i = 0; i < n; i += 1) cin >> a[i];   }   long long power(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = ((res % 1000000007) * (a % 1000000007)) % 1000000007;       a = ((a % 1000000007) * (a % 1000000007)) % 1000000007;       b >>= 1;     }     return res;   }   long long numFactors(long long x) {     long long cnt = 0;     for (long long i = 1; i <= sqrt(x); i += 1) {       if (x % i == 0) {         if (x / i == i)           cnt += 1;         else           cnt += 2;       }     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout << fixed;     cout.precision(10);     ;     int n;     cin >> n;     int a[n];     iarr(a, n);     long long cnt = 0;     while (true) {       int ind = -1, mx = a[0];       for (long long i = 1; i < n; i += 1) {         if (a[i] >= mx) {           ind = i;           mx = a[i];         }       }       if (ind != -1) {         a[ind]--;         a[0]++;         cnt++;       } else if (ind == -1) {         break;       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long int power(unsigned long long int a, unsigned long long int b,                                unsigned long long int p) {     unsigned long long int res = 1;     a = a % p;     while (b > 0) {       if (b & 1) {         res = (res * a) % p;         b--;       }       a = (a * a) % p;       b >>= 1;     }     return res;   }   unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {     return (b == 0) ? a : gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     unsigned long long int n, p, k;     cin >> n >> p >> k;     vector<unsigned long long int> v(n);     for (auto &i : v) cin >> i;     map<unsigned long long int, unsigned long long int> cnt;     for (unsigned long long int i = 0; i < n; i++) {       unsigned long long int cur = (power(v[i], 4, p) - (k * v[i]) % p + p) % p;       cnt[cur]++;     }     unsigned long long int ans = 0;     for (auto i : cnt) ans += (i.second * (i.second - 1)) / 2;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const unsigned gen_seed =       std::chrono::system_clock::now().time_since_epoch().count();   std::mt19937_64 gen(gen_seed);   const int A = 500;   long long d[A + 1][A + 1];   long long fac[A + 1];   long long ifac[A + 1];   long long cfac[A + 1][A + 1];   long long cfac2[A + 1][A + 1];   long long gcd(long long a, long long b, long long& x, long long& y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = gcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   long long invmod(long long a, long long modulo) {     long long x, y;     gcd(a, modulo, x, y);     return (x % modulo + modulo) % modulo;   }   int main() {     fac[0] = 1;     for (long long i = 1; i <= A; i++) fac[i] = (fac[i - 1] * i) % mod;     for (int i = 0; i < A + 1; i++) ifac[i] = invmod(fac[i], mod);     d[0][0] = 1;     for (int i = 0; i < A + 1; i++)       for (int j = 0; j < i + 1; j++) cfac[i][j] = fac[i] * ifac[i - j] % mod;     for (int i = 0; i < A + 1; i++)       for (int j = 0; j < i + 1; j++) cfac2[i][j] = cfac[i][j] * (j + 1) % mod;     for (int b = 0; b < A + 1; b++)       for (int a = 0; a < A + 1; a++) {         if (a == 0) {           if (b > 0) d[0][b] = (d[0][b - 1] * b) % mod;           continue;         }         for (int tb = 0; tb < b + 1; tb++) {           d[a][b] += d[a - 1][b - tb] * cfac[b][tb] % mod;         }         if (a > 1) {           long long cand = 0;           for (int tb = 0; tb < b + 1; tb++) {             cand += d[a - 2][b - tb] * cfac2[b][tb] % mod;           }           d[a][b] += cand * (a - 1);         }         d[a][b] %= mod;       }     int n;     scanf( %d , &n);     int a = 0;     int b = 0;     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       if (x == 1)         a++;       else         b++;     }     cout << d[a][b];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k, ans = 0, t;     cin >> t;     while (t--) {       cin >> n >> k;       ans = 0;       while (n > 0) {         if (n % k == 0) {           n /= k;           ans++;         } else {           ans += n % k;           n -= n % k;         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   long long p(long long n, long long k) {     long long d = 1;     while (n) {       if (n & 1) d = (d * k) % 1000000007;       k = (k * k) % 1000000007;       n >>= 1;     }     return d;   }   int main() {     long long n, l;     scanf( %I64d , &n);     l = p(n, 2);     printf( %I64d , ((l + l * l) / 2) % 1000000007);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using VV = vector<vector<T>>;   template <class T>   inline bool SMIN(T &l, const T &r) {     return l < r ? l = r, 1 : 0;   }   template <class T>   inline bool SMAX(T &l, const T &r) {     return l > r ? l = r, 1 : 0;   }   const string yes =  YES , no =  NO ;   int X, Y, Z, T1, T2, T3;   string solve() {     long long s = abs(X - Y) * T1;     long long e = abs(Z - X) * T2 + abs(X - Y) * T2 + 3LL * T3;     return !(s < e) ? yes : no;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> X >> Y >> Z >> T1 >> T2 >> T3;     cout << solve() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, i, j, mas[50077], fix[50077], dom, a[50077];   int main() {     cin >> n;     for (k = 1; k <= n; k++) cin >> a[k];     for (k = 1; k <= n; k++) {       dom = a[k];       for (j = 1; j <= n; j++) mas[a[j]] = 0;       for (i = k; i <= n; i++) {         mas[a[i]]++;         if (mas[a[i]] > mas[dom])           dom = a[i];         else if (a[i] < dom && mas[a[i]] == mas[dom])           dom = a[i];         fix[dom]++;       }     }     for (k = 1; k <= n; k++) cout << fix[k] <<    ;   }


#include <bits/stdc++.h>   const double pi = (double)(2.0 * acos(0.0));   const int inf = 1 << 30;   const double eps = 1E-9;   const double e = exp(1.0);   const int sz = 100000 + 5;   const int mod = 1000000000 + 7;   using namespace std;   int main() {     double x, y, z, res, v;     string st =   ;     scanf( %lf %lf %lf , &x, &y, &z);     if (x < 1.0 + eps && y < 1.0 + eps && z < 1.0 + eps) {       res = 1e18;       v = z * log(y) + log(log(1.0 / x));       if (res > v + eps) res = v, st =  x^y^z ;       v = y * log(z) + log(log(1.0 / x));       if (res > v + eps) res = v, st =  x^z^y ;       v = log(y) + log(z) + log(log(1.0 / x));       if (res > v + eps) res = v, st =  (x^y)^z ;       v = z * log(x) + log(log(1.0 / y));       if (res > v + eps) res = v, st =  y^x^z ;       v = x * log(z) + log(log(1.0 / y));       if (res > v + eps) res = v, st =  y^z^x ;       v = log(x) + log(z) + log(log(1.0 / y));       if (res > v + eps) res = v, st =  (y^x)^z ;       v = y * log(x) + log(log(1.0 / z));       if (res > v + eps) res = v, st =  z^x^y ;       v = x * log(y) + log(log(1.0 / z));       if (res > v + eps) res = v, st =  z^y^x ;       v = log(x) + log(y) + log(log(1.0 / z));       if (res > v + eps) res = v, st =  (z^x)^y ;       cout << st << endl;     } else {       res = -1e18;       if (x > 1.0 + eps) {         v = z * log(y) + log(log(x));         if (res + eps < v) res = v, st =  x^y^z ;         v = y * log(z) + log(log(x));         if (res + eps < v) res = v, st =  x^z^y ;         v = log(y) + log(z) + log(log(x));         if (res + eps < v) res = v, st =  (x^y)^z ;       }       if (y > 1.0 + eps) {         v = z * log(x) + log(log(y));         if (res + eps < v) res = v, st =  y^x^z ;         v = x * log(z) + log(log(y));         if (res + eps < v) res = v, st =  y^z^x ;         v = log(x) + log(z) + log(log(y));         if (res + eps < v) res = v, st =  (y^x)^z ;       }       if (z > 1.0 + eps) {         v = y * log(x) + log(log(z));         if (res + eps < v) res = v, st =  z^x^y ;         v = x * log(y) + log(log(z));         if (res + eps < v) res = v, st =  z^y^x ;         v = log(x) + log(y) + log(log(z));         if (res + eps < v) res = v, st =  (z^x)^y ;       }       cout << st << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ans = 0;     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  1 )         ans += 10;       else if (s[i] ==  A )         ans += 1;       else         ans += s[i] -  0 ;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100005], b[100005], difs, f, s;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + n);     for (int i = 0; i < n; i++)       if (a[i] != b[i]) difs++;     if (difs > 2) {       cout <<  NO ;       return 0;     } else {       cout <<  YES ;       return 0;     }     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 )   using namespace std;   const int maxn = 3e5 + 5;   const int maaxn = 1e7 + 2;   const int minn = 22;   const long long mod = 1e9 + 7;   const long double pi = 3.141592653589793238462643383279;   long long binpow(long long a, long long p) {     if (p == 0) return 0;     if (p % 2 == 1) return (a + binpow(a, p - 1)) % mod;     long long b = binpow(a, p / 2);     return (b + b) % mod;   }   int a[maxn];   vector<int> dv[maxn];   vector<int> hop[maaxn];   int cnt[maaxn];   bool sh(int &c, int &b) { return a[c] < a[b]; }   void solve() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       for (int j = 2; j * j <= a[i]; j++) {         if (a[i] % j == 0) {           dv[i].push_back(j);           cnt[j]++;           hop[j].push_back(i);           if (j * j != a[i])             dv[i].push_back(a[i] / j), cnt[a[i] / j]++,                 hop[a[i] / j].push_back(i);         }       }     }     for (int i = 2; i < maaxn; i++) {       if (cnt[i] >= k) {         for (int j = 0; j < k; j++) {           cout << (hop[i][j] + 1) <<    ;         }         cout << endl;         return;       }     }     int ma = 0;     int p = 0;     for (int i = 2; i < maaxn; i++) {       if (hop[i].size() > ma) {         ma = hop[i].size();         p = i;       }     }     vector<int> answ;     unordered_set<int> tv;     for (int i = 0; i < hop[p].size(); i++) tv.insert(hop[p][i]);     for (int i = 0; i < n; i++) {       if (tv.count(i) == 0) answ.push_back(i);     }     sort(answ.begin(), answ.end(), sh);     for (int i = 0; i < k; i++) cout << answ[i] + 1 <<    ;     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     t = 1;     while (t--) {       solve();     }     cin >> t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int p = 1e9 + 7;   struct Matrix {     int n, m;     long long a[105][105];     Matrix(int x, int y) {       n = x, m = y;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) a[i][j] = 0;       }     }     void init() {       for (int i = 1; i <= min(n, m); i++) a[i][i] = 1;     }     void print() {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) cout << a[i][j] <<    ;         cout << endl;       }       cout << endl;     }   };   Matrix operator*(Matrix a, Matrix b) {     Matrix c = Matrix(a.n, b.m);     for (int i = 1; i <= a.n; i++) {       for (int j = 1; j <= b.m; j++) {         for (int k = 1; k <= a.m; k++) {           c.a[i][j] = (c.a[i][j] + a.a[i][k] * b.a[k][j] % p) % p;         }       }     }     return c;   }   Matrix qpow(Matrix a, long long b) {     Matrix res = Matrix(a.n, a.m);     res.init();     while (b) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long n, m, k;   int main() {     cin >> n >> m >> k;     Matrix f = Matrix(m, m);     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= m; j++) f.a[i][j] = 1;     }     string s;     int x, y, z;     while (k--) {       cin >> s;       if (s[0] <=  Z  && s[0] >=  A )         x = s[0] -  A  + 27;       else         x = s[0] -  a  + 1;       if (s[1] <=  Z  && s[1] >=  A )         y = s[1] -  A  + 27;       else         y = s[1] -  a  + 1;       f.a[x][y] &= 0;     }     Matrix ans = Matrix(1, m);     for (int i = 1; i <= m; i++) ans.a[1][i] = 1;     f = qpow(f, n - 1);     ans = ans * f;     long long res = 0;     for (int i = 1; i <= m; i++) res += ans.a[1][i], res %= p;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, a[5001];     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++)       if (a[a[a[i]]] == i) {         printf( YES );         return 0;       }     printf( NO );     return 0;   }


#include <bits/stdc++.h>   #define pb push_back   using namespace std;   typedef long long ll;      void solve()   {       int n;       cin >> n;       int adad[n];       map<int, int> cnt;       for (int i = 0; i < n; i++)       {           cin >> adad[i];           cnt[adad[i]]++;       }       int mini;       mini = *min_element(adad, adad + n);       cout << n - cnt[mini] << endl;   }      int main()   {       ios::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);       int t;       cin >> t;       while (t--)       {           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   inline void writeln2() { cout <<   n ; }   inline void writeln() { cout <<   n ; }   inline void readln() {}   template <typename T>   inline void read(T&);   template <typename T>   inline void priws(T);   template <typename T>   inline void print(T);   void err(vector<string>::iterator it) { ++it; }   template <typename Head, typename... Tail>   inline void readln(Head& head, Tail&... tail) {     read(head);     readln(tail...);   }   template <typename Head, typename... Tail>   inline void writeln2(Head head, Tail... tail) {     print(head);     writeln2(tail...);   }   template <typename Head, typename... Tail>   inline void writeln(Head head, Tail... tail) {     priws(head);     writeln2(tail...);   }   template <typename T>   inline void writeln_range(T f, T s) {     if (f != s)       for (auto i = f; i != s; ++i) writeln(*i);   }   template <typename Head, typename... Tail>   inline void err(vector<string>::iterator it, Head head, Tail... tail) {     writeln((*it).substr((*it)[0] ==    ),  = , head);     err(++it, tail...);   }   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) v.push_back(x);     return move(v);   }   void printAnsAndExit(long long ans) {     writeln(ans);     exit(0);   }   vector<vector<int>> g;   vector<bool> used;   int cc = 0;   int dfs(int u) {     used[u] = true;     int ok = 0;     for (int i = 0; i < (int)(g[u].size()); ++i)       if (!used[g[u][i]]) ok += dfs(g[u][i]);     if (ok >= 3)       cc += 2, ok = 0;     else {       if (ok == 2)         cc += 2, ok = 0;       else {         if (ok == 1) cc++;         ok = 1;       }     }     return ok;   }   void run() {     int n, x, y;     readln(n, x, y);     vector<pair<int, int>> a(n - 1);     readln(a);     vector<int> deg(n + 1, 0);     g.resize(n);     used.resize(n);     for (int i = 0; i < (int)(n - 1); ++i)       deg[a[i].first - 1]++, deg[a[i].second - 1]++,           g[a[i].first - 1].push_back(a[i].second - 1),           g[a[i].second - 1].push_back(a[i].first - 1);     if (x > y) {       for (int i = 0; i < (int)(deg.size()); ++i)         if (deg[i] == n - 1) printAnsAndExit(x + (n - 2) * 1ll * y);       printAnsAndExit((n - 1) * 1ll * y);     }     dfs(0);     writeln(cc * 1ll * x + (n - cc - 1) * 1ll * y);   }   int main() {     ios_base::sync_with_stdio(false);     run();     return 0;   }   template <typename T>   inline ostream& operator<<(ostream& os, vector<T>& _a);   template <typename T1, typename T2>   inline istream& operator>>(istream& is, pair<T1, T2>& _a) {     return is >> _a.first >> _a.second;   }   template <typename T1, typename T2>   inline ostream& operator<<(ostream& os, pair<T1, T2>& _a) {     return os << _a.first <<     << _a.second;   }   template <typename T>   inline ostream& operator<<(ostream& os, vector<T>& _a) {     if (_a.size())       os << _a[0];     else       os <<   n ;     for (int i = 1; i < _a.size(); ++i)       os <<   n  [is_fundamental<T>::value] << _a[i];     return os;   }   template <typename T>   inline istream& operator>>(istream& is, vector<T>& _a) {     if (_a.size() == 0) {       int _n;       is >> _n;       _a.resize(_n);     }     for (int i = 0; i < _a.size(); ++i) is >> _a[i];     return is;   }   template <typename T>   inline void print(T _a) {     cout <<     << _a;   }   template <typename T>   inline void priws(T _a) {     cout << _a;   }   template <typename T>   inline void read(T& _a) {     cin >> _a;   }


#include <bits/stdc++.h>   using namespace std;   set<int> marc[100010];   int input(void) {     int x;     scanf( %d , &x);     return x;   }   int main() {     int n = input();     for (int i = 0; i < (n); i++) {       int x = input(), k = input();       if (x == 0) {         marc[k].insert(0);       } else {         if (marc[k].find(x - 1) != marc[k].end()) {           marc[k].insert(x);         } else {           cout <<  NO n ;           return 0;         }       }     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Time {     long long deno, num;     inline long long gcd(long long a, long long b) {       return !b ? a : gcd(b, a % b);     }     inline void simplify() {       long long g = gcd(abs(deno), abs(num));       deno /= g;       num /= g;       if (deno < 0) {         deno *= -1;         num *= -1;       }     }     Time() {}     Time(long long n, long long d) : num(n), deno(d) { simplify(); }     inline bool operator<(const Time &t) const {       return num * t.deno < t.num * deno;     }     inline bool operator!=(const Time &t) const {       return num * t.deno != t.num * deno;     }   };   pair<Time, Time> s[100010];   pair<Time, int> ds[100010];   int d[100010];   struct BIT {     int f[100010];     BIT() { fill(f, f + 100010, 0); }     inline int lowbit(int x) { return (x & -x); }     inline void add(int p, int v) {       for (++p; p < 100010; p += lowbit(p)) f[p] += v;     }     inline int sum(int p) {       int ret = 0;       for (++p; p; p -= lowbit(p)) ret += f[p];       return ret;     }     inline int sum(int l, int r) { return sum(r) - sum(l - 1); }   } bit;   int n, w;   long long v, x;   int main() {     cin >> n >> w;     for (int i = 0; i < n; i++) {       cin >> x >> v;       s[i] = make_pair(Time(-x, v - w), Time(-x, v + w));     }     for (int i = 0; i < n; i++) s[i].second.num *= -1;     sort(s, s + n);     for (int i = 0; i < n; i++) s[i].second.num *= -1;     for (int i = 0; i < n; i++) ds[i] = make_pair(s[i].second, i);     sort(ds, ds + n);     for (int i = 0, rk = -1; i < n; i++) {       if (!i || ds[i].first != ds[i - 1].first) rk++;       d[ds[i].second] = rk;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       ans += bit.sum(d[i], 100010 - 1);       bit.add(d[i], 1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int par1[10008];   int par2[10008];   vector<pair<int, int>> result;   int find1(int r) {     if (par1[r] == r)       return r;     else       return par1[r] = find1(par1[r]);   }   int find2(int r) {     if (par2[r] == r)       return r;     else       return par2[r] = find2(par2[r]);   }   int main() {     int i, j, t, n, m1, m2, p, q, res = 0, uu, vv, uu2, vv2;     cin >> n >> m1 >> m2;     for (i = 1; i <= n; i++) {       par1[i] = i;       par2[i] = i;     }     for (i = 0; i < m1; i++) {       cin >> p >> q;       uu = find1(p);       vv = find1(q);       par1[uu] = vv;     }     for (i = 0; i < m2; i++) {       cin >> p >> q;       uu2 = find2(p);       vv2 = find2(q);       par2[uu2] = vv2;     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         uu = find1(i);         vv = find1(j);         uu2 = find2(i);         vv2 = find2(j);         if ((uu != vv) && (uu2 != vv2)) {           res++;           par1[uu] = vv;           par2[uu2] = vv2;           result.push_back({i, j});         }       }     }     cout << res << endl;     for (i = 0; i < result.size(); i++) {       cout << result[i].first <<     << result[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e17 + 10;   const int N = 1e4 + 10;   const long long mod = 998244353;   map<string, int> ml;   int c[N], vis[N], a[N], t, n, m, x, y, k, dp[N][105];   char s[N];   int ex, ey, cnt;   long long dist[N];   vector<pair<int, int> > v;   map<int, int> mp;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       mp[a[i]]++;     }     for (auto p : mp) v.push_back(p);     if (v.size() == 2) return cout << n << endl, 0;     dp[0][0] = 1;     for (auto p : v) {       int cost = p.first;       int k = p.second;       for (int i = N; i >= 0; i--)         for (int j = 1; j <= n; j++)           for (int t = 1; t <= k && t <= j && t * cost <= i; t++)             dp[i][j] += dp[i - t * cost][j - t];     }     int ans = 1;     for (auto p : v) {       int cost = p.first;       int k = p.second;       for (int i = 1; i <= k; i++) {         if (dp[i * cost][i] == 1) ans = max(ans, i);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     vector<pair<int, int> > a;     vector<int> b;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int t;       scanf( %d , &t);       if (t & 1) {         int spd = 0;         if (t != 5) scanf( %d , &spd);         a.push_back({t, spd});       } else {         b.push_back(t);       }     }     int res = 0;     int spd = 0;     vector<int> lim;     lim.push_back(1e9);     for (pair<int, int> p : a) {       if (p.first == 1) {         spd = p.second;         while (spd > lim.back()) {           lim.pop_back();           res++;         }       }       if (p.first == 3) {         if (spd <= p.second)           lim.push_back(p.second);         else           res++;       }       if (p.first == 5) lim.push_back(1e9);     }     vector<bool> allowed;     allowed.push_back(1);     for (int p : b) {       if (p == 2) {         while (!allowed.back()) {           allowed.pop_back();           res++;         }       }       if (p == 4) allowed.push_back(1);       if (p == 6) allowed.push_back(0);     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, t, l, r, n, m, p, a, b, c, d, flag;     cin >> t;     while (t--) {       cin >> n;       for (i = 0; i < n; i++) {         cout << (i + 1) <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();     return f ? -x : x;   }   int main() {     int n = read(), ans = 0;     for (int i = 1; i <= n; ++i) ans += read() * i;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, t, i, k, tam;   int main() {     while (scanf( %I64d , &n) > 0) {       t = 0;       tam = 0;       for (i = 0; i < n; i++) {         scanf( %I64d , &k);         if (k % 2 != 0) {           tam = k;         }         t += k;       }       if (t % 2 != 0) {         printf( First n );       } else {         if ((t - tam) % 2 != 0)           printf( First n );         else           printf( Second n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, sum;     while (cin >> n >> k) {       for (int i = k; i >= 1; i--) {         sum = ((n * k) / (i)) + i;         if ((sum / k) * (sum % k) == n) {           break;         }       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:336777216 )   using namespace std;   int IT_MAX = 1 << 17;   int MOD = 1000000007;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1);   const double ERR = 1e-10;   long long dp[1050][10050];   long long C[10050];   long long cost[10050];   int main() {     int N, W, B, X, i, j, k;     scanf( %d %d %d %d , &N, &W, &B, &X);     for (i = 1; i <= N; i++) scanf( %lld , &C[i]);     for (i = 1; i <= N; i++) scanf( %lld , &cost[i]);     for (i = 0; i <= N; i++)       for (j = 0; j <= 10000; j++) dp[i][j] = -LL_INF;     dp[0][0] = W;     for (i = 1; i <= N; i++) {       for (j = 0; j <= 10000; j++) {         long long v = dp[i - 1][j];         if (v < 0) continue;         long long mx = C[i];         if (cost[i]) mx = min(mx, v / cost[i]);         for (k = 0; k <= mx; k++)           dp[i][j + k] = max(dp[i][j + k], dp[i - 1][j] - cost[i] * k);       }       for (j = 0; j <= 10000; j++)         if (dp[i][j] >= 0) dp[i][j] = min(dp[i][j] + X, (long long)B * j + W);     }     int ans = 0;     for (i = 1; i <= 10000; i++)       if (dp[N][i] >= 0) ans = max(ans, i);     return !printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   template <typename flow_t, typename cost_t>   struct min_cost_flow {     const cost_t COST_INF = numeric_limits<cost_t>::max() / 2;     struct edge {       int node, rev;       flow_t capacity;       cost_t cost;       edge() {}       edge(int _node, int _rev, flow_t _capacity, cost_t _cost)           : node(_node), rev(_rev), capacity(_capacity), cost(_cost) {}     };     int V = -1, E = 0;     vector<vector<edge>> adj;     vector<cost_t> dist;     vector<int> prev;     vector<edge *> prev_edge;     bool too_many_bellman_ford_iterations = false;     min_cost_flow(int vertices = -1) {       if (vertices >= 0) init(vertices);     }     void init(int vertices) {       V = vertices;       E = 0;       adj.assign(V, {});       dist.resize(V);       prev.resize(V);       prev_edge.resize(V);       too_many_bellman_ford_iterations = false;     }     void add_directional_edge(int u, int v, flow_t capacity, cost_t cost) {       assert(0 <= u && u < V && 0 <= v && v < V);       edge uv_edge(v, adj[v].size() + (u == v ? 1 : 0), capacity, cost);       edge vu_edge(u, adj[u].size(), 0, -cost);       adj[u].push_back(uv_edge);       adj[v].push_back(vu_edge);       E++;     }     edge &reverse_edge(const edge &e) { return adj[e.node][e.rev]; }     bool bellman_ford(int source, int sink) {       for (int i = 0; i < V; i++) {         dist[i] = COST_INF;         prev[i] = -1;         prev_edge[i] = nullptr;       }       long long work = 0;       vector<int> last_seen(V, -1);       vector<int> nodes = {source}, next_nodes;       dist[source] = 0;       for (int iteration = 0; iteration < V; iteration++) {         next_nodes.clear();         for (int node : nodes) {           for (edge &e : adj[node])             if (e.capacity > 0 && dist[node] + e.cost < dist[e.node]) {               dist[e.node] = dist[node] + e.cost;               prev[e.node] = node;               prev_edge[e.node] = &e;               if (last_seen[e.node] != iteration) {                 last_seen[e.node] = iteration;                 next_nodes.push_back(e.node);               }             }           work += adj[node].size();         }         swap(nodes, next_nodes);       }       if (work > 1.75 * E * (32 - __builtin_clz(V)) + 100)         too_many_bellman_ford_iterations = true;       return prev[sink] != -1;     }     struct dijkstra_state {       cost_t dist;       int node;       dijkstra_state() {}       dijkstra_state(cost_t _dist, int _node) : dist(_dist), node(_node) {}       bool operator<(const dijkstra_state &other) const {         return dist > other.dist;       }     };     void dijkstra_check(int node, cost_t potential_dist, int previous,                         edge *previous_edge, priority_queue<dijkstra_state> &pq) {       if (potential_dist < dist[node]) {         dist[node] = potential_dist;         prev[node] = previous;         prev_edge[node] = previous_edge;         pq.emplace(dist[node], node);       }     }     bool dijkstra(int source, int sink) {       dist.assign(V, COST_INF);       prev.assign(V, -1);       prev_edge.assign(V, nullptr);       priority_queue<dijkstra_state> pq;       dijkstra_check(source, 0, -1, nullptr, pq);       while (!pq.empty()) {         dijkstra_state top = pq.top();         pq.pop();         if (top.dist > dist[top.node]) continue;         for (edge &e : adj[top.node])           if (e.capacity > 0)             dijkstra_check(e.node, top.dist + e.cost, top.node, &e, pq);       }       return prev[sink] != -1;     }     void reduce_cost() {       for (int i = 0; i < V; i++)         for (edge &e : adj[i])           if (dist[i] < COST_INF && dist[e.node] < COST_INF)             e.cost += dist[i] - dist[e.node];     }     vector<pair<flow_t, cost_t>> options;     pair<flow_t, cost_t> solve_min_cost_flow(         int source, int sink, flow_t flow_goal = numeric_limits<flow_t>::max()) {       assert(V >= 0);       flow_t total_flow = 0;       cost_t total_cost = 0;       while (total_flow < flow_goal && bellman_ford(source, sink)) {         if (too_many_bellman_ford_iterations) break;         flow_t path_cap = flow_goal - total_flow;         cost_t cost_sum = 0;         for (int node = sink; prev[node] != -1; node = prev[node])           path_cap = min(path_cap, prev_edge[node]->capacity);         for (int node = sink; prev[node] != -1; node = prev[node]) {           edge *e = prev_edge[node];           e->capacity -= path_cap;           reverse_edge(*e).capacity += path_cap;           cost_sum += e->cost;         }         total_flow += path_cap;         total_cost += cost_sum * path_cap;         options.emplace_back(total_flow, total_cost);       }       if (too_many_bellman_ford_iterations) {         cost_t reduce_sum = 0;         do {           reduce_cost();           reduce_sum += dist[sink];           flow_t path_cap = flow_goal - total_flow;           for (int node = sink; prev[node] != -1; node = prev[node])             path_cap = min(path_cap, prev_edge[node]->capacity);           for (int node = sink; prev[node] != -1; node = prev[node]) {             edge *e = prev_edge[node];             assert(e->cost == 0);             e->capacity -= path_cap;             reverse_edge(*e).capacity += path_cap;           }           total_flow += path_cap;           total_cost += reduce_sum * path_cap;           options.emplace_back(total_flow, total_cost);         } while (total_flow < flow_goal && dijkstra(source, sink));       }       return make_pair(total_flow, total_cost);     }   };   int main() {     int N, M;     scanf( %d %d , &N, &M);     min_cost_flow<int, long long> graph(N);     for (int i = 0; i < M; i++) {       int u, v, weight;       scanf( %d %d %d , &u, &v, &weight);       u--;       v--;       graph.add_directional_edge(u, v, 1, weight);     }     graph.solve_min_cost_flow(0, N - 1);     int Q;     scanf( %d , &Q);     for (int q = 0; q < Q; q++) {       int x;       scanf( %d , &x);       double answer = 1e100;       for (auto &option : graph.options)         answer = min(answer, (double)(option.second + x) / option.first);       printf( %.7lg n , answer);     }   }


#include <bits/stdc++.h>   using namespace std;   int row[1010];   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     memset(row, 0x3f3f3f3f, sizeof row);     long long ans = 0;     for (int i = (0); i < (n); ++i) {       int r, c;       scanf( %d %d , &r, &c);       row[r] = min(c, row[r]);     }     for (int i = 1; i <= m; ++i) ans += ((row[i] == 0x3f3f3f3f) ? 0 : row[i]);     cout << min(ans, (long long)k) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, sol[1000005];   struct ell {     int dr, cnt, poz;     bool operator<(const ell &A) const { return dr < A.dr; }   };   multiset<ell> Q;   struct el {     int x, y, flag, cnt, poz;     bool operator<(const el &A) const {       if (x == A.x) {         if (y == A.y) return flag > A.flag;         return y > A.y;       }       return x < A.x;     }   };   el a[1000005], b[1000005];   int main() {     int i, j, cn;     ell w;     cin.sync_with_stdio(0);     cin >> n;     cn = n;     for (i = 1; i <= n; ++i) {       cin >> a[i].x >> a[i].y;       a[i].poz = i;       b[i] = a[i];     }     cin >> m;     for (i = 1; i <= m; ++i) {       cin >> a[n + i].x >> a[n + i].y >> a[n + i].cnt;       a[n + i].flag = 1;       a[n + i].poz = i;       b[n + i] = a[n + i];     }     n += m;     sort(a + 1, a + n + 1);     for (i = 1; i <= n; ++i) {       if (a[i].flag) {         w.dr = a[i].y;         w.cnt = a[i].cnt;         w.poz = a[i].poz;         Q.insert(w);       } else {         ell w;         w.dr = a[i].y;         multiset<ell>::iterator it = Q.lower_bound(w);         if (it == Q.end()) {           printf( NO n );           return 0;         }         sol[a[i].poz] = it->poz;         --b[it->poz + cn].cnt;         if (!b[it->poz + cn].cnt) Q.erase(it);       }     }     cout <<  YES n ;     for (i = 1; i <= n - m; ++i) cout << sol[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (b > a) swap(a, b);     if (a % b == 0)       return b;     else       return gcd(b, a % b);   }   long long int a, b, k, k1, k2;   int main() {     cin >> a >> b;     k = (a * b) / gcd(a, b);     k1 = k / a;     k2 = k / b;     if (abs(k1 - k2) == 1)       cout <<  Equal ;     else if (k1 > k2)       cout <<  Dasha ;     else       cout <<  Masha ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXH = 1000000;   const int MAXW = 1000000;   const int MAXN = 100000;   const int MOD = 1000000007;   typedef struct R {     int x1, y1, x2, y2;   } R;   int h, w, n;   int shead[MAXH], snxt[MAXN];   int thead[MAXH], tnxt[MAXN];   R r[MAXN];   int cur[MAXN], ncur;   int sval[4 * MAXW];   int slazy[4 * MAXW];   inline void inc(int &a, int b) {     if ((a += b) >= MOD) a -= MOD;   }   void spush(int x) {     if (sval[x] != -1) {       sval[2 * x + 1] = sval[2 * x + 2] = sval[x];       slazy[2 * x + 1] = slazy[2 * x + 2] = 0;       sval[x] = -1;     }     if (slazy[x] != 0) {       inc(slazy[2 * x + 1], slazy[x]), inc(slazy[2 * x + 2], slazy[x]);       slazy[x] = 0;     }   }   void sset(int x, int l, int h, int L, int H, int VAL) {     if (h < L || l > H) return;     if (L <= l && h <= H) {       sval[x] = VAL, slazy[x] = 0;       return;     }     spush(x);     int m = l + (h - l) / 2;     sset(2 * x + 1, l, m, L, H, VAL);     sset(2 * x + 2, m + 1, h, L, H, VAL);   }   void sinc(int x, int l, int h, int L, int H, int BY) {     if (h < L || l > H) return;     if (L <= l && h <= H) {       inc(slazy[x], BY);       return;     }     spush(x);     int m = l + (h - l) / 2;     sinc(2 * x + 1, l, m, L, H, BY);     sinc(2 * x + 2, m + 1, h, L, H, BY);   }   int sget(int x, int l, int h, int IDX) {     if (sval[x] != -1) return sval[x] + slazy[x];     spush(x);     int m = l + (h - l) / 2;     return IDX <= m ? sget(2 * x + 1, l, m, IDX) : sget(2 * x + 2, m + 1, h, IDX);   }   void run() {     scanf( %d%d%d , &h, &w, &n);     for (int x = (0); x < (h); ++x) shead[x] = thead[x] = -1;     for (int i = (0); i < (n); ++i) {       scanf( %d%d%d%d , &r[i].x1, &r[i].y1, &r[i].x2, &r[i].y2);       --r[i].x1, --r[i].y1, --r[i].x2, --r[i].y2;       snxt[i] = shead[r[i].x1], shead[r[i].x1] = i;       tnxt[i] = thead[r[i].x2], thead[r[i].x2] = i;     }     multiset<int> have;     have.insert(w);     sval[0] = slazy[0] = 0;     sset(0, 0, w - 1, 0, 0, 1);     for (int x = (0); x < (h); ++x) {       for (int z = shead[x]; z != -1; z = snxt[z])         sset(0, 0, w - 1, r[z].y1, r[z].y2, 0), have.insert(r[z].y1);       ncur = 0;       if (x == 0)         cur[ncur++] = 0;       else         for (int z = thead[x - 1]; z != -1; z = tnxt[z]) {           if (r[z].y1 != 0) cur[ncur++] = r[z].y1 - 1;           multiset<int>::iterator it = have.lower_bound(r[z].y1);           have.erase(it);         }       sort(cur, cur + ncur);       ncur = unique(cur, cur + ncur) - cur;       for (int i = ncur - 1; i >= 0; --i) {         int y = cur[i];         int val = sget(0, 0, w - 1, y);         if (val == 0) continue;         multiset<int>::iterator it = have.lower_bound(y);         int ny = *it - 1;         if (y + 1 <= ny) sinc(0, 0, w - 1, y + 1, ny, val);       }     }     int ret = sget(0, 0, w - 1, w - 1);     printf( %d n , ret);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <typename T, typename TT>   inline ostream &operator<<(ostream &os, const pair<T, TT> &t) {     return os << t.first <<     << t.second;   }   template <typename T>   inline ostream &operator<<(ostream &os, const vector<T> &t) {     for (auto i : t) os << i <<    ;     return os;   }   template <typename T>   inline istream &operator>>(istream &is, vector<T> &v) {     for (T &t : v) is >> t;     return is;   }   template <typename T1, typename T2>   inline istream &operator>>(istream &is, pair<T1, T2> &t) {     is >> t.first >> t.second;     return is;   }   const long long mod = 1e9 + 7;   void solve() {     int n;     cin >> n;     vector<int> val(3 * n), vis(3 * n + 1);     cin >> val;     vector<int> loc(3 * n + 1);     vector<vector<long long> > v(n, vector<long long>(3));     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         cin >> v[i][j];         loc[v[i][j]] = i;       }     }     int k, j = 0;     cin >> k;     vector<int> ans, up;     for (int i = 0; i < loc[k]; i++) {       for (auto x : v[i]) vis[x] = 1, up.push_back(x);     }     while (vis[val[j]]) j++;     ;     if (k != val[j]) {       for (int i = 1; i <= 3 * n; i++)         if (i != k) cout << i <<    ;       return;     }     for (auto x : v[loc[k]])       if (x != k) ans.push_back(x);     for (int i = loc[k] + 1; i < n; i++) {       for (auto x : v[i]) ans.push_back(x);     }     sort(ans.begin(), ans.begin() + 2);     sort(ans.begin() + 2, ans.end());     sort(up.begin(), up.end());     ;     j = 0;     for (auto x : ans) {       while (j < up.size() and up[j] < x) cout << up[j++] <<    ;       cout << x <<    ;     }     cout << vector<long long>(up.begin() + j, up.end()) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ;     int T = 1;     while (T--) {       solve();     }     return 0;   }


/*      Author: ChinmayKarnik      Time: 21:14:26      Date: 16-04-2021   */      #include<bits/stdc++.h>      using namespace std;      //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());      typedef enum {BLACK,WHITE,GRAY} color;      #define int long long    #define TESTCASES true   #define FASTIO true   const int maxN = 200009;   const int inf  = (int)1e18 + 1;   int N,K;   int a[maxN];      int p[64];         void solve()   {       int i,j,k;       vector<int> ans;          cin >> N >> K;        int one = 1;          if(N<64)       {          if((one<<(N-1))<K)          {              cout <<  -1 n ;              return;          }       }          while(N>=64)       {           ans.push_back(1);           N--;       }          while(N)       {           int curr = 1;           int sub = 0;           while((curr<=N) && p[N-curr]<K)           {               K-=p[N-curr];               curr++;           }          // curr--;           N-=curr;           ans.push_back(curr);           //K-=(curr-1)*(p[])       }          int p = 1;       vector<int> fin;          for(int x:ans)       {           for(i=p+x-1;i>=p;i--)           {               fin.push_back(i);           }           p=p+x;       }              for(int x:fin)       {           cout << x <<    ;       }       cout <<   n ;                 }         signed main()   {       if(FASTIO)       {           ios_base::sync_with_stdio(false);           cin.tie(NULL);       }       int T = 1;          if(TESTCASES)       {           cin >> T;       }       int i,j,k;              p[0]=1;       p[1]=1;       for(i=2;i<64;i++)       {           p[i]=0;           for(j=0;j<i;j++)           {               p[i]+=p[j];           }                     // cout << p[i] <<    ;       }          while(T--)       {           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     int k, n, fl = 0;     cin >> n >> k;     v.resize(n);     for (int i = 0; i < n; ++i) {       cin >> v[i];       if (v[i] == k) fl = 1;     }     int ct = 0;     if (!fl) {       v.push_back(k);       ct++;       ++n;     }     sort(v.begin(), v.end());     int p, d = 1e9;     for (int i = 0; i < v.size(); ++i) {       if (k == v[i] && abs((n + 1) / 2 - (i + 1)) < d) {         p = i + 1;         d = abs((n + 1) / 2 - (i + 1));       }     }     while (p < (n + 1) / 2) {       ++ct;       ++p;       ++n;     }     while (p > (n + 1) / 2) {       ++ct;       ++n;     }     cout << ct;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bananaz(long long x, long long y) {     return (x + 1) * (y + 1) * (x + y) / 2;   }   int main() {     ios_base::sync_with_stdio(false);     long long m, b, x = 0, y, max = -1;     cin >> m >> b;     y = b;     while (y >= 0) {       if (bananaz(x, y) > max) max = bananaz(x, y);       x++;       while (y > -1.0 * x / m + b) y--;     }     cout << max << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int goal, n, stations;     scanf( %i%i%i , &goal, &n, &stations);     vector<pair<int, int> > points;     points.push_back(make_pair(n, -1));     points.push_back(make_pair(goal, 2000000000));     for (auto e = 0; e < stations; e++) {       int a, b;       scanf( %i%i , &a, &b);       points.push_back(make_pair(a, b));       points.push_back(make_pair(a + n, -b - 1));     }     stable_sort(points.begin(), points.end());     multiset<int> sw;     auto prev = make_pair(0, 0);     sw.insert(0);     auto acc = 0LL;     for (auto e : points) {       if (sw.empty()) {         if (e.first != prev.first) {           acc = -1;           break;         }       } else {         acc += ((long long)e.first - prev.first) * (*sw.begin());       }       if (e.first == goal) {         break;       }       if (e.second < 0) {         sw.erase(sw.find(-e.second - 1));       } else {         sw.insert(e.second);       }       prev = e;     }     printf( %I64d n , acc);     return 0;   }


#include <bits/stdc++.h>   int gcd(int a, int b) {     if (a == 0)       return b;     else       return (b % a, a);   }   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int a[n];     long long sum = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     sort(a, a + n);     long long tot = 0;     for (int i = n - 1; i >= 0; i--) {       tot += a[i];       if (tot > sum - tot) {         cout << n - i << endl;         return 0;       }     }     return 0;   }


//#pragma GCC optimize( Ofast )   #include <bits/stdc++.h>   using namespace std;   typedef long long int ll;   typedef unsigned long long ull;       mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   ll myRand(ll B) {    return (ull)rng() % B;   }      int main(){       cin.tie(nullptr);       ios::sync_with_stdio(false);       int n,k; cin >> n >> k;       vector<int> l(n);       for(int i=0;i<n;i++){           cin >> l[i];       }       sort(l.rbegin(), l.rend());       const int N=5e5;       vector<int> a(N);       a[0]=1,a[1]=-1;       int ans=1e9;       int sum=0;       for(int i=0,j=0;i<N-1;i++){           sum+=a[i];           a[i+1]+=a[i];           if(sum+a[i+1]>=k){               ans=i+1; break;           }           while(a[i]>0 and j<n){               int u=(l[j]-1)/2;               int v=l[j]-1-u;               a[i+2]++;               a[i+2+u]--;               a[i+2]++;               a[i+2+v]--;               a[i]--;               sum--;               j++;           }       }       if(ans==1e9){           ans=-1;       }       cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int M = 1e5 + 10;   const int INF = 2147483647;   const int MOD = 1e9 + 7;   int T, n, m;   int sum;   int a[N];   pair<int, int> b[N];   long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }   long long qpow(long long base, long long x) {     long long res = 1;     while (x) {       if (x & 1) res *= base;       base *= base;       base %= MOD;       res %= MOD;       x >>= 1;     }     return res;   }   long long qmul(long long a, long long b, long long mod) {     long long res = 0;     while (b) {       if (b & 1) res = (res + a) % mod;       a = (a + a) % mod;       b >>= 1;     }     return res;   }   void exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return;     }     exgcd(b, a % b, y, x);     y -= (a / b) * x;   }   long long getinv(long long x, long long mod) {     long long x_0, y_0;     exgcd(x, mod, x_0, y_0);     return x_0;   }   bool check(int x) {     if (sum > x) return false;     vector<int> day(n + 1, 0);     for (int i = 1; i <= m; i++) {       int d = b[i].first, item = b[i].second;       if (d <= x) {         day[item] = max(day[item], d);       }     }     vector<vector<int>> tmp(200005);     for (int i = 1; i <= n; i++) {       if (day[i]) {         tmp[day[i]].emplace_back(i);       }     }     vector<int> use(n + 1, 0);     for (int i = 1; i <= n; i++) use[i] = a[i];     int cur = 0;     for (int i = 1; i <= x; i++) {       ++cur;       if (i > 200000) continue;       for (auto &t : tmp[i]) {         if (cur >= a[t]) {           cur -= a[t];           use[t] = 0;         } else {           use[t] -= cur;           cur = 0;           break;         }       }     }     int ss = 0;     for (int i = 1; i <= n; i++) ss += use[i];     return cur >= ss * 2;   }   void solve() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i];     for (int i = 1; i <= m; i++) cin >> b[i].first >> b[i].second;     int l = 1, r = 1e9;     while (l < r) {       int mid = (l + r) >> 1;       if (check(mid))         r = mid;       else         l = mid + 1;     }     cout << l << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     T = 1;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10, P = 998244353;   const double Pi = acos(-1);   inline int read() {     int x = 0, f = 1, ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch - 48, ch = getchar();     return x * f;   }   inline int Add(int a, int b) { return a + b >= P ? a + b - P : a + b; }   inline int Sub(int a, int b) { return a - b < 0 ? a - b + P : a - b; }   inline int Mul(int a, int b) {     long long res = 1ll * a * b;     return res >= P ? res % P : res;   }   inline int qpow(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = Mul(res, a);       a = Mul(a, a);       b >>= 1;     }     return res;   }   int n;   int dp[3][N];   int cnt, head[N];   struct Edge {     int to, nxt;   } edge[N << 1];   inline void AddEdge(int u, int v) {     edge[++cnt] = (Edge){v, head[u]};     head[u] = cnt;     return;   }   void solve(int u, int fa) {     dp[0][u] = dp[2][u] = 1;     for (int i = head[u], v; i; i = edge[i].nxt) {       v = edge[i].to;       if (v == fa) continue;       solve(v, u);       dp[0][u] = Mul(dp[0][u], Add(dp[0][v], dp[1][v]));       dp[1][u] = Add(dp[1][u],                      Mul(dp[2][v], qpow(Add(dp[0][v], Mul(2, dp[1][v])), P - 2)));       dp[2][u] = Mul(dp[2][u], Add(dp[0][v], Mul(2, dp[1][v])));     }     dp[1][u] = Mul(dp[1][u], dp[2][u]);   }   signed main() {     n = read();     for (register int i = 2; i <= n; ++i) {       int a = read(), b = read();       AddEdge(a, b), AddEdge(b, a);     }     solve(1, 0);     printf( %d n , Add(dp[0][1], dp[1][1]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 2000000000LL;   const long double EPS = 1e-9;   vector<pair<int, int> > clear(vector<pair<int, int> > v) {     vector<pair<int, int> > ret;     int tox = v[1].first;     int x = v[0].first, y = v[0].second;     while (x <= tox) {       ret.push_back({x, y});       ++x;     }     int tx = v[1].first, ty = v[1].second;     while (ty != y) {       ret.push_back({tx, ty});       (ty > y) ? --ty : ++ty;     }     tox = v[2].first;     int toy = v[2].second;     int p = v[0].second, q = v[1].second;     if (p > q) swap(p, q);     if (v[2].second >= p and v[2].second <= q) {       while (x <= tox) {         ret.push_back({x, toy});         ++x;       }     } else if (v[2].second < p) {       while (x <= tox) {         ret.push_back({x, p});         ++x;       }       while (toy != p) {         ret.push_back({tox, toy});         (toy > p) ? --toy : ++toy;       }     } else {       while (x <= tox) {         ret.push_back({x, q});         ++x;       }       while (toy != q) {         ret.push_back({tox, toy});         (toy > q) ? --toy : ++toy;       }     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     vector<pair<int, int> > v(3);     for (int i = 0; i < 3; ++i) cin >> v[i].first >> v[i].second;     sort((v).begin(), (v).end());     auto res = clear(v);     sort((res).begin(), (res).end());     res.erase(unique((res).begin(), (res).end()), res.end());     cout << res.size() <<   n ;     for (auto x : res) cout << x.first <<     << x.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   vector<int> ans;   char s1[maxn], s2[maxn];   int n;   void op(int x) {     for (int i = 1; i <= x; ++i) {       s1[i] = s1[i] ==  0  ?  1  :  0 ;     }     reverse(s1 + 1, s1 + 1 + x);     ans.push_back(x);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n;       cin >> s1 + 1 >> s2 + 1;       ans.clear();       for (int i = n; i >= 1; --i) {         if (s1[i] == s2[i]) continue;         if (i == 1)           op(1);         else {           if (s1[1] == s2[i]) op(1);           op(i);         }       }       cout << ((int)ans.size());       for (auto &v : ans) cout <<     << v;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e17 + 10;   const int N = 1e6 + 10;   const long long mod = 998244353;   map<string, int> ml;   long long b[N], vis[N], po[N], num[N], t, n, m, x, y, k, a[N];   long long ex, ey, cnt, ans, sum, flag;   long long dist[N];   long long dp[N];   vector<int> v[N];   map<int, int> mp;   priority_queue<pair<int, int> > q;   priority_queue<pair<int, int> > tq;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     string s;     cin >> s;     for (int i = 0; s[i]; i++) {       a[i] = cnt;       if (s[i] ==  ( )         cnt++;       else         cnt--;       if (a[i - 1] < 0) a[i] = -1;     }     cnt = 0;     for (int i = n - 1; i >= 0; i--) {       b[i] = cnt;       if (s[i] ==  ) )         cnt++;       else         cnt--;       if (b[i + 1] < 0) b[i] = -1;     }     for (int i = 0; s[i]; i++) {       if (a[i] < 0 && b[i] < 0) return cout << 0 << endl, 0;       num[i] = a[i] - b[i];       if (s[i] ==  (  && num[i] == 1 && a[i] >= 0 && b[i] >= 0) ans++;       if (s[i] ==  )  && num[i] == -1 && a[i] >= 0 && b[i] >= 0) ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 2e5 + 7;   long long n, k, a, b, q;   long long arr[MAXN];   void read() { cin >> n >> k >> a >> b >> q; }   long long acnt[MAXN << 2], asum[MAXN << 2], bcnt[MAXN << 2], bsum[MAXN << 2];   long long getacnt(long long v, long long tl, long long tr, long long l,                     long long r) {     if (tr < l || r < tl) return 0;     if (l <= tl && tr <= r) return acnt[v];     long long tm = (tl + tr) >> 1;     return getacnt(v * 2 + 1, tl, tm, l, r) +            getacnt(v * 2 + 2, tm + 1, tr, l, r);   }   long long getbcnt(long long v, long long tl, long long tr, long long l,                     long long r) {     if (tr < l || r < tl) return 0;     if (l <= tl && tr <= r) return bcnt[v];     long long tm = (tl + tr) >> 1;     return getbcnt(v * 2 + 1, tl, tm, l, r) +            getbcnt(v * 2 + 2, tm + 1, tr, l, r);   }   long long getasum(long long v, long long tl, long long tr, long long l,                     long long r) {     if (tr < l || r < tl) return 0;     if (l <= tl && tr <= r) return asum[v];     long long tm = (tl + tr) >> 1;     return getasum(v * 2 + 1, tl, tm, l, r) +            getasum(v * 2 + 2, tm + 1, tr, l, r);   }   long long getbsum(long long v, long long tl, long long tr, long long l,                     long long r) {     if (tr < l || r < tl) return 0;     if (l <= tl && tr <= r) return bsum[v];     long long tm = (tl + tr) >> 1;     return getbsum(v * 2 + 1, tl, tm, l, r) +            getbsum(v * 2 + 2, tm + 1, tr, l, r);   }   void updacnt(long long v, long long tl, long long tr, long long p,                long long x) {     if (tl == tr) {       acnt[v] = (arr[p] + x >= a);       return;     }     long long tm = (tl + tr) >> 1;     if (p <= tm)       updacnt(v * 2 + 1, tl, tm, p, x);     else       updacnt(v * 2 + 2, tm + 1, tr, p, x);     acnt[v] = acnt[v * 2 + 1] + acnt[v * 2 + 2];   }   void updbcnt(long long v, long long tl, long long tr, long long p,                long long x) {     if (tl == tr) {       bcnt[v] = (arr[p] + x >= b);       return;     }     long long tm = (tl + tr) >> 1;     if (p <= tm)       updbcnt(v * 2 + 1, tl, tm, p, x);     else       updbcnt(v * 2 + 2, tm + 1, tr, p, x);     bcnt[v] = bcnt[v * 2 + 1] + bcnt[v * 2 + 2];   }   void updasum(long long v, long long tl, long long tr, long long p,                long long x) {     if (tl == tr) {       asum[v] = (arr[p] + x) * (arr[p] + x < a);       return;     }     long long tm = (tl + tr) >> 1;     if (p <= tm)       updasum(v * 2 + 1, tl, tm, p, x);     else       updasum(v * 2 + 2, tm + 1, tr, p, x);     asum[v] = asum[v * 2 + 1] + asum[v * 2 + 2];   }   void updbsum(long long v, long long tl, long long tr, long long p,                long long x) {     if (tl == tr) {       bsum[v] = (arr[p] + x) * (arr[p] + x < b);       return;     }     long long tm = (tl + tr) >> 1;     if (p <= tm)       updbsum(v * 2 + 1, tl, tm, p, x);     else       updbsum(v * 2 + 2, tm + 1, tr, p, x);     bsum[v] = bsum[v * 2 + 1] + bsum[v * 2 + 2];   }   void print() {     for (long long i = 0; i < q; ++i) {       long long t;       cin >> t;       if (t == 1) {         long long p, x;         cin >> p >> x;         --p;         updacnt(0, 0, MAXN, p, x);         updbcnt(0, 0, MAXN, p, x);         updasum(0, 0, MAXN, p, x);         updbsum(0, 0, MAXN, p, x);         arr[p] += x;       } else {         long long p;         cin >> p;         --p;         long long sum1 =             getbcnt(0, 0, MAXN, 0, p - 1) * b + getbsum(0, 0, MAXN, 0, p - 1);         long long sum2 = getacnt(0, 0, MAXN, p + k, MAXN) * a +                          getasum(0, 0, MAXN, p + k, MAXN);         cout << sum1 + sum2 <<   n ;       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     read();     print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[1111], b[1111];   const int inf = 1e9;   map<int, int> mp, mp1;   int nsd(int x, int y) {     while (x > 0 && y > 0)       if (x > y)         x %= y;       else         y %= x;     return x + y;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     mp[a[1]] = b[1];     for (int i = 2; i <= n; i++) {       for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {         int heh = it->first;         int kok = it->second;         if (!mp1[heh] || mp1[heh] > kok) mp1[heh] = kok;         int kek = nsd(a[i], heh);         if (!mp1[kek] || mp1[kek] > kok + b[i]) mp1[kek] = kok + b[i];       }       mp = mp1;       mp1.clear();       if (!mp[a[i]] || mp[a[i]] > b[i]) mp[a[i]] = b[i];     }     if (mp[1] == 0)       cout << -1;     else       cout << mp[1];   }


#include <bits/stdc++.h>   using namespace std;   char s[10], a1[] = { vaporeon }, a2[] = { jolteon }, a3[] = { flareon },               a4[] = { espeon }, a5[] = { umbreon }, a6[] = { leafeon },               a7[] = { glaceon }, a8[] = { sylveon };   int n, i;   int main() {     cin >> n;     cin >> s;     if (n == 6) {       cout << a4;       return 0;     }     if (n == 8) {       cout << a1;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] !=  . )         if (s[i] != a2[i]) break;     }     if (i == n) {       cout << a2;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] !=  . )         if (s[i] != a3[i]) break;     }     if (i == n) {       cout << a3;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] !=  . )         if (s[i] != a5[i]) break;     }     if (i == n) {       cout << a5;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] !=  . )         if (s[i] != a6[i]) break;     }     if (i == n) {       cout << a6;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] !=  . )         if (s[i] != a7[i]) break;     }     if (i == n) {       cout << a7;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] !=  . )         if (s[i] != a8[i]) break;     }     if (i == n) {       cout << a8;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[600000];   int main() {     int n = 6 * 1e5;     a[0] = 0;     for (int i = 1; i < n; ++i) {       int cur = i;       int t = 0;       while (cur % 5 == 0) {         cur /= 5;         t++;       }       a[i] = a[i - 1] + t;     }     int m;     cin >> m;     vector<int> res;     for (int i = 1; i < n; ++i) {       if (a[i] == m) {         res.push_back(i);       }     }     cout << res.size() << endl;     for (int i = 0; i < res.size(); ++i) {       cout << res[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int break_point() {     char c;     while ((c = getchar()) !=   n )       ;     return 0;   }   template <typename T>   void read_integer(T &r) {     bool sign = 0;     r = 0;     char c;     while (1) {       c = getchar();       if (c ==  - ) {         sign = 1;         break;       }       if (c !=     && c !=   n ) {         r = c -  0 ;         break;       }     }     while (1) {       c = getchar();       if (c ==     || c ==   n ) break;       r = r * 10 + (c -  0 );     }     if (sign) r = -r;   }   long long binpow(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * a;       a *= a;       b >>= 1;     }     return ret;   }   long long binpow(long long a, long long b, int mod) {     long long ret = 1;     while (b) {       if (b & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ret;   }   inline int getbit(int x, int b) { return (x >> b) & 1; }   inline int setbit(int x, int b) { return x | (1 << b); }   inline void _setbit(int &x, int b) { x = setbit(x, b); }   inline long long setbit(long long x, int b) { return x | (1ll << b); }   inline void _setbit(long long &x, int b) { x = setbit(x, b); }   inline int unsetbit(int x, int b) { return x & (INT_MAX - (1 << b)); }   inline void _unsetbit(int &x, int b) { x = unsetbit(x, b); }   inline int countbit(int x) {     x = x - ((x >> 1) & 0x55555555);     x = (x & 0x33333333) + ((x >> 2) & 0x33333333);     return ((x + (x >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;   }   inline long long countbit(long long x) {     return countbit(int(x & INT_MAX)) + countbit(int(x >> 31) & INT_MAX);   }   inline void printbit(int x, int len) {     for (int i = len - 1; i >= 0; i--) printf( %d , getbit(x, i));   }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   template <typename A, typename B>   ostream &operator<<(ostream &stream, const pair<A, B> &p) {     stream <<  {  << p.first <<  ,  << p.second <<  } ;     return stream;   }   template <typename A>   ostream &operator<<(ostream &stream, const vector<A> &v) {     stream <<  [ ;     for (auto itr = v.begin(); itr != v.end(); itr++) stream << *itr <<    ;     stream <<  ] ;     return stream;   }   template <typename A, typename B>   ostream &operator<<(ostream &stream, const map<A, B> &v) {     stream <<  [ ;     for (auto itr = v.begin(); itr != v.end(); itr++) stream << *itr <<    ;     stream <<  ] ;     return stream;   }   template <typename A>   ostream &operator<<(ostream &stream, const set<A> &v) {     stream <<  [ ;     for (auto itr = v.begin(); itr != v.end(); itr++) stream << *itr <<    ;     stream <<  ] ;     return stream;   }   template <typename A>   ostream &operator<<(ostream &stream, const stack<A> &v) {     stack<A> st = v;     stream <<  [ ;     while (!st.empty()) {       stream << st.top() <<    ;       st.pop();     }     stream <<  ] ;     return stream;   }   template <typename A>   ostream &operator<<(ostream &stream, const priority_queue<A> &v) {     priority_queue<A> q = v;     stream <<  [ ;     while (!q.empty()) {       stream << q.top() <<    ;       q.pop();     }     stream <<  ] ;     return stream;   }   template <typename A>   ostream &operator<<(ostream &stream, const queue<A> &v) {     queue<A> q = v;     stream <<  [ ;     while (!q.empty()) {       stream << q.front() <<    ;       q.pop();     }     stream <<  ] ;     return stream;   }   template <typename A>   ostream &operator<<(ostream &stream, const deque<A> &v) {     deque<A> q = v;     stream <<  [ ;     while (!q.empty()) {       stream << q.front() <<    ;       q.pop_front();     }     stream <<  ] ;     return stream;   }   void run();   int main() {     srand(time(NULL));     run();     return 0;   }   const int mod = 1e9 + 7;   const int N = 1e5 + 7;   struct SegmentTree {     vector<long long> tr;     int n;     SegmentTree(int _n) : n(_n) { tr.resize(n * 4); }     long long get(int v, int l, int r, int L, int R) {       if (R < L) return 0;       if (l == L && r == R) return tr[v];       int mid = (l + r) >> 1;       return max(get(v + v, l, mid, L, min(mid, R)),                  get(v + v + 1, mid + 1, r, max(mid + 1, L), R));     }     long long get(int l, int r) { return get(1, 0, n - 1, l, r); }     void set(int v, int l, int r, int pos, long long val) {       if (l == r)         tr[v] = max((tr[v]), (val));       else {         int mid = (l + r) >> 1;         if (pos <= mid)           set(v + v, l, mid, pos, val);         else           set(v + v + 1, mid + 1, r, pos, val);         tr[v] = max(tr[v + v], tr[v + v + 1]);       }     }     void set(int pos, long long val) { set(1, 0, n - 1, pos, val); }   };   struct tower {     int a, b, h;     bool operator<(const tower &other) const {       if (b == other.b) return a > other.a;       return b > other.b;     }   };   tower tw[N];   void run() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d%d%d , &tw[i].a, &tw[i].b, &tw[i].h);     vector<int> p;     for (int i = 0; i < n; ++i) {       p.push_back(tw[i].a);       p.push_back(tw[i].b);     }     sort(p.begin(), p.end());     int cnt = unique(p.begin(), p.end()) - p.begin();     for (int i = 0; i < n; ++i) {       tw[i].a = upper_bound(p.begin(), p.begin() + cnt, tw[i].a) - p.begin();       tw[i].b = upper_bound(p.begin(), p.begin() + cnt, tw[i].b) - p.begin();     }     sort(tw, tw + n);     SegmentTree tree(cnt + 5);     for (int i = 0; i < n; ++i) {       long long H = tree.get(0, tw[i].b - 1) + tw[i].h;       tree.set(tw[i].a, H);     }     printf( %lld , tree.get(0, cnt + 2));     putchar(  n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k, t;     cin >> n >> m >> k;     if (k > n + m - 2)       cout <<  -1 n ;     else {       if (k < max(n, m))         cout << max(n * (m / (k + 1)), m * (n / (k + 1))) << endl;       else         cout << max(m / (k - n + 2), n / (k - m + 2)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static inline void canhazfast() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   template <typename T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <typename T>   T extgcd(T a, T b, T &x, T &y) {     T x0 = 1, y0 = 0, x1 = 0, y1 = 1;     while (b) {       T q = a / b;       a %= b;       swap(a, b);       x0 -= q * x1;       swap(x0, x1);       y0 -= q * y1;       swap(y0, y1);     }     x = x0;     y = y0;     return a;   }   static inline int ctz(unsigned x) { return __builtin_ctz(x); }   static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); }   static inline int clz(unsigned x) { return __builtin_clz(x); }   static inline int clzll(unsigned long long x) { return __builtin_clzll(x); }   static inline int popcnt(unsigned x) { return __builtin_popcount(x); }   static inline int popcntll(unsigned long long x) {     return __builtin_popcountll(x);   }   static inline int bsr(unsigned x) { return 31 ^ clz(x); }   static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); }   int main() {     canhazfast();     int n, m, k;     int x2, y2, x3, y3;     long long p, r;     cin >> n >> m >> k;     p = 2LL * n * m;     r = p % k;     if (r) return cout <<  NO , 0;     p /= k;     x2 = n;     y3 = (p - 1) / n + 1;     x3 = (long long)x2 * y3 - p;     y2 = 1;     cout <<  YES n0 0 n  << x2 <<     << y2 <<   n  << x3 <<     << y3;     return 0;   }


#include <bits/stdc++.h>   //#include <ext/pb_ds/assoc_container.hpp>   //#include <ext/pb_ds/tree_policy.hpp>    using namespace std;   //using namespace __gnu_pbds;   #define rep(i,a,b) for(i=(a);i<=(b);i++)   #define ll long long   #define pll pair<ll, ll>   #define pii pair<int,int>   #define pb push_back   #define F first   #define S second   #define mod 1000000007   #define maxn 100005   #define inf 1e18   #define boost ios::sync_with_stdio(false);cin.tie(0)   #define fr freopen( source.txt , r ,stdin),freopen( output.txt , w ,stdout)   #define SET(a,b) memset(a,b,sizeof(a))   #define deb(x) cout << #x <<  =  << x << endl   #define deb2(x, y) cout << #x <<  =  << x <<  ,  << #y <<  =  << y << endl   #define all(x) x.begin(), x.end()   #define ps(x,y) fixed<<setprecision(y)<<x   //template<typename T>   //using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;   template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {       return out <<   (  << a.F <<  ,   << a.S <<  ) ;   }       template<class A> ostream& operator << (ostream& out, const vector<A> &a) {       out <<  [ ;       for (auto it = a.begin(); it != a.end(); ++it) {           if (it != a.begin())               out <<  ,  ;           out << *it;       }       return out <<  ] ;   }   void solve(){       ll n,i,j,x,t,y;       cin>>n;       string s[n];       for(i=0;i<n;i++) cin>>s[i];       map<ll,ll>mp;       for(i=0;i<n;i++){           for(j=0;j<n;j++){               if(s[i][j]!= . ) mp[(i+j)%3]++;           }       }       y=min({mp[0],mp[1],mp[2]});       if(mp[0]==y) x=0;       else if(mp[1]==y) x=1;       else x=2;       for(i=0;i<n;i++){           for(j=0;j<n;j++){               if(s[i][j]!= . &&(i+j)%3==x) s[i][j]= O ;           }       }       for(i=0;i<n;i++) cout<<s[i]<<  n ;   }   int main()   {       boost;       ll n,i,j,x,t,y;       cin>>t;       while(t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   int vis[10005];   int main() {     int n;     scanf( %d , &n);     int maxn = -1;     for (int i = 1; i <= n; i++) {       int tmp;       scanf( %d , &tmp);       vis[tmp]++;       maxn = max(maxn, tmp);     }     long long ans1 = -1, ans2 = -1;     for (int i = 1; i <= maxn; i++) {       if (vis[i] != 0) {         if (i > ans1) {           ans1 = i;         }       }     }     for (int i = 1; i <= maxn; i++) {       if (vis[i] == 2 || (ans1 % i != 0 && vis[i] == 1)) {         if (i > ans2) {           ans2 = i;         }       }     }     printf( %lld %lld n , ans1, ans2);   }


#include <bits/stdc++.h>   using namespace std;   int ord[100100];   int inv_ord[100100];   int dep[100100];   int fa[100100][17];   vector<int> g[100100];   set<int> ss;   int ts;   void dfs(int p, int f) {     ord[p] = ++ts;     inv_ord[ord[p]] = p;     dep[p] = dep[f] + 1;     fa[p][0] = f;     for (int i = 0; i < 16; i++) fa[p][i + 1] = fa[fa[p][i]][i];     for (int i = 0; i < g[p].size(); i++)       if (g[p][i] != f) dfs(g[p][i], p);   }   inline int bit(int x, int i) { return (x >> i) & 1; }   int lca(int a, int b) {     if (dep[a] > dep[b]) swap(a, b);     for (int i = 0; i < 17; i++)       if (bit(dep[a] - dep[b], i)) b = fa[b][i];     if (a == b) return a;     for (int i = 16; i >= 0; i--)       if (fa[a][i] != fa[b][i]) a = fa[a][i], b = fa[b][i];     return fa[a][0];   }   int calc(int p) {     if (ss.empty()) return 1;     set<int>::iterator it = ss.lower_bound(ord[p]);     int a = inv_ord[it == ss.end() ? *ss.begin() : *it];     int b = inv_ord[it == ss.begin() ? *ss.rbegin() : *--it];     return dep[p] - dep[lca(a, p)] - dep[lca(b, p)] + dep[lca(a, b)];   }   int main() {     int n, k, a, b;     while (cin >> n >> k) {       for (int i = 1; i < n; i++) {         cin >> a >> b;         g[a].push_back(b);         g[b].push_back(a);       }       ts = 0;       dfs(1, 0);       int v = 0;       int sol = 1;       for (int i = 1, j = 0; i <= n; i++) {         while (v <= k) {           sol = max(sol, j - i + 1);           if (j == n) break;           j++;           v += calc(j);           ss.insert(ord[j]);         }         ss.erase(ord[i]);         v -= calc(i);       }       cout << sol << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool inrange(int y) { return ((y >= 1) && (y <= 9)); }   int main() {     int r1, r2, c1, c2, d1, d2;     bool taken[9] = {false};     cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;     int x = (r1 + r2);     int y = (c1 + c2);     int z = (d1 + d2);     int w;     if (x == y && y == z) {       if ((r1 + c2 - d1) % 2) {         cout <<  -1 n ;         return 0;       }       y = (r1 + c2 - d1) / 2;       if (!inrange(y)) {         cout <<  -1 n ;         return 0;       }       if (taken[y - 1]) {         cout <<  -1 n ;         return 0;       } else         taken[y - 1] = true;       x = r1 - y;       if (!inrange(x)) {         cout <<  -1 n ;         return 0;       }       if (taken[x - 1]) {         cout <<  -1 n ;         return 0;       } else {         taken[x - 1] = true;       }       w = d2 - y;       if (!inrange(w)) {         cout <<  -1 n ;         return 0;       }       if (taken[w - 1]) {         cout <<  -1 n ;         return 0;       } else {         taken[w - 1] = true;       }       z = c2 - y;       if (!inrange(z)) {         cout <<  -1 n ;         return 0;       }       if (taken[z - 1]) {         cout <<  -1 n ;         return 0;       } else {         taken[z - 1] = true;       }       cout << x <<     << y <<   n ;       cout << w <<     << z <<   n ;     } else       cout <<  -1 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   int n;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int _;     cin >> _;     while (_--) {       cin >> n;       for (int i = 1; i <= n; i++) {         cout << i + 1 <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, m;     cin >> n;     vector<string> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     cin >> m;     vector<vector<string>> b(m);     bool new_problem = 1;     for (int i = 0; i < m; i++) {       int k;       cin >> k;       b[i].resize(k);       for (int j = 0; j < k; j++) cin >> b[i][j];       int cnt = 0;       for (int j = 0; j < n; j++) {         for (int p = 0; p < k; p++) {           if (a[j] == b[i][p]) {             cnt++;             break;           }         }       }       new_problem &= cnt != n;     }     if (new_problem) {       cout <<  Brand new problem! n ;       return 0;     }     vector<int> p(n);     iota(p.begin(), p.end(), 0);     const int INF = 1e9;     pair<int, int> best = {INF, INF};     do {       int cost = 0;       for (int i = 1; i < n; i++) {         for (int j = i - 1; j >= 0; j--) cost += p[i] < p[j];       }       int take = -1;       for (int i = 0; i < m; i++) {         int ptr = 0;         for (int j = 0; j < (int)b[i].size(); j++) {           if (a[p[ptr]] == b[i][j]) ptr++;           if (ptr == n) {             break;           }         }         if (ptr == n) {           take = i;           break;         }       }       if (take != -1) {         if (cost < best.first || (cost == best.first && take < best.second))           best = {cost, take};       }     } while (next_permutation(p.begin(), p.end()));     int x = (n * (n - 1) / 2 - best.first + 1);     cout << best.second + 1 <<   n ;     cout <<  [: ;     while (x) {       cout <<  | ;       x--;     }     cout <<  :] n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e3 + 3;   long long n, mod = 1e9 + 7, dp[N][N][2];   long long f(long long idx, long long diff, long long stat) {     long long &ret = dp[idx][diff][stat];     if (ret != -1) return ret;     if (idx == n) {       ret = 0;       return ret;     }     ret = 0;     if (stat == 0) {       if (n - idx - 1 >= diff + 1) {         ret =             (f(idx + 1, diff + 1, 0) + (diff > 0 ? f(idx + 1, diff - 1, 0) : 0)) %             mod;         ret = max(ret, (f(idx + 1, diff + 1, 1) + 1 +                         (diff > 0 ? f(idx + 1, diff - 1, 0) : 0)) %                            mod);         ret = max(ret, (f(idx + 1, diff + 1, 0) +                         (diff > 0 ? 1 + f(idx + 1, diff - 1, 1) : 0)) %                            mod);       } else {         if (diff > 0)           ret = max(f(idx + 1, diff - 1, 0), 1 + f(idx + 1, diff - 1, 1));         else           ret = 0;       }     } else {       if (n - idx - 1 >= diff + 1) {         ret =             (f(idx + 1, diff + 1, 0) + (diff > 0 ? f(idx + 1, diff - 1, 0) : 0)) %             mod;       } else {         if (diff > 0)           ret = f(idx + 1, diff - 1, 0);         else           ret = 0;       }     }     return ret;   }   int main() {     cin >> n;     n *= 2;     for (long long i = 0; i <= n; i++)       for (long long ii = 0; ii <= n; ii++)         for (long long iii = 0; iii < 2; iii++) dp[i][ii][iii] = -1;     cout << f(0, 0, 0) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long inf64 = 1e18;   void solve() {     int n, m;     cin >> n >> m;     vector<vector<int>> a(n, vector<int>(m)), b;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int c = 0;         if (i > 0) c++;         if (j > 0) c++;         if (i + 1 < n) c++;         if (j + 1 < m) c++;         if (a[i][j] > c) {           cout <<  NO n ;           return;         }         a[i][j] = c;       }     }     cout <<  YES n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << a[i][j] <<    ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios_base::sync_with_stdio(false);     int n, x[10], y[10], nx[10], ny[10];     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> nx[i] >> ny[i];     int mnx = 1000000, mny = 1000000, mxx = 0, mxy = 0;     for (int i = 0; i < n; i++) {       mnx = min(mnx, x[i]);       mny = min(mny, y[i]);       mxx = max(mxx, nx[i]);       mxy = max(mxy, ny[i]);     }     long long area = (mxx - mnx) * (mxy - mny);     long long realarea = 0;     for (int i = 0; i < n; i++) {       realarea += (nx[i] - x[i]) * (ny[i] - y[i]);     }     if (mxx - mnx == mxy - mny && area == realarea)       printf( YES );     else       printf( NO );   }


#include <bits/stdc++.h>   int n, q[20];   long long A, B, C, a, b, c, m, m1, ans, v, p[20];   void dfs1(register int s, long long now) {     if (now > m) return;     if (s > n) {       if (now < a) return;       b = now;       c = v / a / b;       if (a * b + a * c + b * c < ans)         ans = a * b + a * c + b * c, A = a, B = b, C = c;       return;     }     if (q[s]) q[s]--, dfs1(s, now * p[s]), q[s]++;     dfs1(s + 1, now);   }   void dfs2(register int s, long long now) {     if (now > m1) return;     if (s > n) {       if (a = now, v / a + 2 * a * sqrt(v / a) < ans)         m = sqrt(v / a) + 1e-8, dfs1(1, 1);       return;     }     if (q[s]) q[s]--, dfs2(s, now * p[s]), q[s]++;     dfs2(s + 1, now);   }   int main() {     for (register int T, x = scanf( %d , &T); T--;) {       scanf( %d , &n);       for (register int i = v = 1; i <= n; i++) {         scanf( %lld%d , &p[i], &q[i]);         for (register int j = 1; j <= q[i]; j++) v *= p[i];       }       ans = 5e18;       A = 0;       m1 = pow(v, 1. / 3) + 1e-8;       dfs2(1, 1);       printf( %lld %lld %lld %lld n , ans * 2, A, B, C);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   long long power(long long x, long long p) {     if (p == 0) return 1;     if (p == 1) return x;     if (p % 2) return x * power(x, p - 1);     long long y = power(x, p / 2);     return y * y;   }   void solve() {     long long n;     cin >> n;     long long arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     pair<long long, long long> modd, meven;     long long odd = 0, even = 0, l = -1, r = -1, res = 0;     for (int i = 0; i < n; i++) {       if (i % 2)         odd += arr[i];       else         even += arr[i];       long long cur = odd - even;       pair<long long, long long> p;       if (i % 2)         p = meven;       else         p = modd;       long long val = cur - p.first;       if (val > res) {         l = p.second;         r = i;         res = val;       }       long long x = odd - even + arr[i] * (i % 2 ? -1 : 1);       if (i % 2 == 0) {         if (x < meven.first) meven = make_pair(x, i);       } else {         if (x < modd.first) modd = make_pair(x, i);       }     }     if (l != -1) {       for (int i = 0; i < (r - l + 1) / 2; i++) {         swap(arr[l + i], arr[r - i]);       }     }     odd = 0;     even = 0;     for (int i = 0; i < n; i++) {       if (i % 2)         odd += arr[i];       else         even += arr[i];     }     cout << max(odd, even) << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5001, M = 1e9 + 7;   int n, F, vis[maxn], T = 1, mid, a[maxn], b[maxn], w[maxn][maxn], ans = 1;   vector<int> g[maxn];   bool C[maxn];   bool dfs(int v) {     vis[v] = T;     for (int i = 0; i < g[v].size(); i++)       if (vis[g[v][i]] != T) {         C[g[v][i]] = !C[v];         if (!dfs(g[v][i])) return false;       } else if (C[g[v][i]] == C[v])         return false;     return true;   }   inline bool check(int x) {     for (int i = 1; i <= n; i++) g[i].resize(0);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (w[i][j] > x) g[i].push_back(j), g[j].push_back(i);     T++;     for (int i = 1; i <= n; i++)       if (vis[i] != T)         if (!dfs(i)) return false;     return true;   }   inline void bs(int f, int l) {     while (f != l) {       mid = (f + l) / 2;       if (check(mid))         l = mid;       else         f = mid + 1;     }     check(f);     F = f;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d%d , a + i, b + i);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         w[i][j] = abs(a[i] - a[j]) + abs(b[i] - b[j]);     bs(0, 7500);     T++;     ans = 1;     for (int i = 1; i <= n; i++)       if (vis[i] != T) dfs(i), ans = (ans << 1) % M;     printf( %d n%d n , F, ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[200005];   long long eff[200005];   long long dp[200005][2];   long long dfs(int src, int polarity) {     long long &ret = dp[src][polarity];     if (ret != -1) return ret;     if (adj[src].size() == 0) return ret = eff[src] * polarity;     long long sumE = 0;     vector<long long> even(adj[src].size()), diff(adj[src].size());     for (int i = 0; i < adj[src].size(); i++) {       even[i] = dfs(adj[src][i], 0);       sumE += even[i];       diff[i] = dfs(adj[src][i], 1) - even[i];     }     sort(diff.begin(), diff.end());     vector<long long> temp = diff;     long long bestEvenFromChildren = sumE, bestOddFromChildren = sumE;     while (temp.size() >= 2 && temp.back() + temp[temp.size() - 2] > 0) {       bestEvenFromChildren += temp.back();       temp.pop_back();       bestEvenFromChildren += temp.back();       temp.pop_back();     }     temp = diff;     bestOddFromChildren += temp.back();     temp.pop_back();     while (temp.size() >= 2 && temp.back() + temp[temp.size() - 2] > 0) {       bestOddFromChildren += temp.back();       temp.pop_back();       bestOddFromChildren += temp.back();       temp.pop_back();     }     if (polarity == 0)       return ret = bestEvenFromChildren;     else       return ret = max(bestEvenFromChildren + eff[src], bestOddFromChildren);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, -1, sizeof dp);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int p, e;       cin >> p >> eff[i];       if (p != -1) adj[p].push_back(i);     }     cout << max(dfs(1, 0), dfs(1, 1)) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, d[100005], x, y, a, b, c, r;   int main() {     cin >> n >> m;     for (i = 1; i <= m; i++) {       cin >> x >> y;       d[x]++;       d[y]++;     }     for (i = 1; i <= n; i++) {       if (d[i] == 1) a++;       if (d[i] == 2) b++;       if (d[i] == n - 1)         c++;       else         r++;     }     if (a == 2 && b == n - 2) {       cout <<  bus topology ;       return 0;     }     if (a == n - 1 && c == 1) {       cout <<  star topology ;       return 0;     }     if (b == n) {       cout <<  ring topology ;       return 0;     }     cout <<  unknown topology ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mult(int a, int b) { return ((long long)a * b) % 1000000007; }   int binaryPow(int n, int p) {     int acc = 1;     while (p) {       if (p & 1) acc = mult(acc, n);       n = mult(n, n);       p >>= 1;     }     return acc;   }   int modularInv(int n) { return binaryPow(n, 1000000007 - 2); }   int main() {     int k, a, b;     cin >> k >> a >> b;     int pa = mult(a, modularInv(a + b));     int pb = mult(b, modularInv(a + b));     int modPB = modularInv(pb);     int dp[k + 1][k + 1];     for (int i = k; i >= 1; i--) {       for (int j = k; j >= 0; j--) {         if (i + j < k) {           dp[i][j] =               (mult(pa, dp[i + 1][j]) + mult(pb, dp[i][i + j])) % 1000000007;         } else {           dp[i][j] = (i + j + mult(pa, modPB)) % 1000000007;         }       }     }     cout << dp[1][0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int MOD;   struct Modint {     int val;     Modint(int nval = 0) { val = nval % MOD; }     Modint& operator+=(Modint r) {       val = (val + r.val) % MOD;       return *this;     }     Modint operator+(Modint r) { return Modint(*this) += r; }     Modint& operator-=(Modint r) {       val = (val + MOD - r.val) % MOD;       return *this;     }     Modint operator-(Modint r) { return Modint(*this) -= r; }     Modint& operator*=(Modint r) {       val = 1LL * val * r.val % MOD;       return *this;     }     Modint operator*(Modint r) { return Modint(*this) *= r; }   };   int main() {     int n, k;     cin >> n >> k >> MOD;     static Modint dp[1001][100];     static Modint from_end[1001];     from_end[0] = 1;     from_end[1] = 9;     for (int i = 2; i <= n; i++) {       from_end[i] = from_end[i - 1] * 10;     }     Modint result = 0;     for (int i = 1; i < 10; i++) {       dp[1][i % k] += 1;     }     int tpow = 10 % k;     for (int i = 1; i < n; i++) {       for (int s = 1; s < k; s++) {         for (int m = 0; m < 10; m++) {           dp[i + 1][(s + tpow * m) % k] += dp[i][s];         }       }       for (int m = 1; m < 10; m++) {         dp[i + 1][tpow * m % k] += 1;       }       tpow = (tpow * 10) % k;     }     for (int i = 1; i <= n; i++) {       result += dp[i][0] * from_end[n - i];     }     cout << result.val <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long powmod(long long a, long long b, long long p) {     long long res = 1;     a %= p;     while (b) {       if (b & 1) res = res * a % p;       a = a * a % p;       b >>= 1;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   void solve() {     int n, m;     cin >> n >> m;     vector<string> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     string ans = v[0];     for (int j = 0; j < m; j++) {       char save = ans[j];       for (char d =  a ; d <=  z ; d++) {         ans[j] = d;         bool flag = true;         for (int z = 0; z < n; z++) {           int cntErrors = 0;           for (int c = 0; c < m; c++) {             if (v[z][c] != ans[c]) {               cntErrors++;             }           }           if (cntErrors > 1) {             flag = false;             break;           }         }         if (flag) {           cout << ans << endl;           return;         }       }       ans[j] = save;     }     cout <<  -1  << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200020, P = 1000000000;   int add(int a, int b) { return a + b >= P ? a + b - P : a + b; }   struct mat {     int r, c, a[2][2];     void construct(int r_, int c_) {       r = r_, c = c_;       for (int i = 0; i < r; ++i)         for (int j = 0; j < c; ++j) a[i][j] = 0;     }     mat operator*(const mat& rhs) const {       mat res;       res.construct(r, rhs.c);       for (int i = 0; i < res.r; ++i)         for (int j = 0; j < res.c; ++j)           for (int k = 0; k < c; ++k)             res.a[i][j] = add(res.a[i][j], (long long)a[i][k] * rhs.a[k][j] % P);       return res;     }   } trans_sum[N];   mat qpow(mat t, int k) {     mat res = t;     --k;     for (; k; k >>= 1) {       if (k & 1) res = res * t;       t = t * t;     }     return res;   }   mat trans;   struct node {     mat v;     int sz;     int tag;   } t[N << 2];   int n, m, a[N], fibo[N], sfibo[N];   node merge(node x, node y) {     node res;     res.sz = x.sz + y.sz;     mat nxt = y.v * trans_sum[x.sz];     res.v.construct(1, 2);     res.v.a[0][0] = add(x.v.a[0][0], nxt.a[0][0]);     res.v.a[0][1] = add(x.v.a[0][1], nxt.a[0][1]);     res.tag = 0;     return res;   }   void build(int p, int l, int r) {     t[p].tag = 0;     if (l == r) {       t[p].v.construct(1, 2);       t[p].v.a[0][0] = t[p].v.a[0][1] = a[l];       t[p].sz = 1;       return;     }     int mid = (l + r) >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     t[p] = merge(t[p << 1], t[p << 1 | 1]);   }   void ontag(int p, int l, int r, int v) {     t[p].tag = add(t[p].tag, v);     t[p].v.a[0][0] = add(t[p].v.a[0][0], (long long)v * sfibo[r - l] % P);     t[p].v.a[0][1] =         add(t[p].v.a[0][1], (long long)v * (sfibo[r - l + 1] - 1 + P) % P);   }   void pushdown(int p, int l, int r) {     if (t[p].tag) {       int mid = (l + r) >> 1;       ontag(p << 1, l, mid, t[p].tag);       ontag(p << 1 | 1, mid + 1, r, t[p].tag);       t[p].tag = 0;     }   }   void add(int p, int l, int r, int L, int R, int v) {     if (L <= l && r <= R) {       ontag(p, l, r, v);       return;     }     pushdown(p, l, r);     int mid = (l + r) >> 1;     if (L <= mid) add(p << 1, l, mid, L, R, v);     if (R > mid) add(p << 1 | 1, mid + 1, r, L, R, v);     t[p] = merge(t[p << 1], t[p << 1 | 1]);   }   void change(int p, int l, int r, int v, int x) {     if (l == r) {       a[l] = x;       t[p].v.construct(1, 2);       t[p].v.a[0][0] = t[p].v.a[0][1] = a[l];       t[p].sz = 1;       return;     }     pushdown(p, l, r);     int mid = (l + r) >> 1;     if (v <= mid)       change(p << 1, l, mid, v, x);     else       change(p << 1 | 1, mid + 1, r, v, x);     t[p] = merge(t[p << 1], t[p << 1 | 1]);   }   node qry(int p, int l, int r, int L, int R) {     if (L <= l && r <= R) return t[p];     pushdown(p, l, r);     int mid = (l + r) >> 1;     if (R <= mid)       return qry(p << 1, l, mid, L, R);     else if (L > mid)       return qry(p << 1 | 1, mid + 1, r, L, R);     else       return merge(qry(p << 1, l, mid, L, R), qry(p << 1 | 1, mid + 1, r, L, R));   }   int main() {     cout << fixed;     trans.construct(2, 2);     trans.a[0][1] = trans.a[1][0] = trans.a[1][1] = 1;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     fibo[0] = fibo[1] = sfibo[0] = 1;     sfibo[1] = 2;     for (int i = 2; i <= n; ++i) {       fibo[i] = add(fibo[i - 1], fibo[i - 2]);       sfibo[i] = add(sfibo[i - 1], fibo[i]);     }     trans_sum[1] = trans;     for (int i = 2; i <= n; ++i) trans_sum[i] = trans_sum[i - 1] * trans;     build(1, 1, n);     while (m--) {       int op, x, v, l, r, d;       scanf( %d , &op);       if (op == 1) {         scanf( %d%d , &x, &v);         change(1, 1, n, x, v);       } else if (op == 2) {         scanf( %d%d , &l, &r);         node ans = qry(1, 1, n, l, r);         printf( %d n , ans.v.a[0][0]);       } else if (op == 3) {         scanf( %d%d%d , &l, &r, &d);         add(1, 1, n, l, r, d);       }     }     return 0;   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::vector;   int main() {     long long n;     cin >> n;     int t = 0;     while (n > 0) {       if (n % 2 != 0) t++;       n = n / 2;     }     cout << t;     int h;     cin >> h;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dist[65][65][65];   int dp[65][65][65][2];   int n, m, r, td[65][65];   vector<long long> li[1024];   int ans[222222];   void prep() {     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < m; k++) dp[i][j][k][0] = dist[k][i][j];     for (int i = 0; i < int(li[0].size()); i++) {       int u = li[0][i], v = li[0][i + 1], ii = li[0][i + 2];       i++;       i++;       ans[ii] = 2000000000;       for (int car = 0; car < m; car++) ans[ii] = min(ans[ii], dp[u][v][car][0]);     }     int flag = 1;     for (int k = 1; k <= n; k++) {       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           td[i][j] = dp[i][j][0][1 - flag];           for (int cc = 0; cc < m; cc++) {             td[i][j] = min(dp[i][j][cc][1 - flag], td[i][j]);           }         }       for (int car = 0; car < m; car++) {         for (int i = 0; i < n; i++)           for (int j = 0; j < n; j++) {             dp[i][j][car][flag] = td[i][j];             for (int p = 0; p < n; p++)               dp[i][j][car][flag] =                   min(dp[i][j][car][flag], td[i][p] + dist[car][p][j]);           }       }       for (int i = 0; i < int(li[k].size()); i++) {         int u = li[k][i], v = li[k][i + 1], ii = li[k][i + 2];         i++;         i++;         ans[ii] = 2000000000;         for (int car = 0; car < m; car++)           ans[ii] = min(ans[ii], dp[u][v][car][flag]);       }       flag = 1 - flag;     }   }   int main() {     scanf( %d , &n);     scanf( %d , &m);     scanf( %d , &r);     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++)         for (int k = 0; k < n; k++) scanf( %d , &dist[i][j][k]);       for (int k = 0; k < n; k++)         for (int ii = 0; ii < n; ii++)           for (int j = 0; j < n; j++)             dist[i][ii][j] = min(dist[i][ii][j], dist[i][ii][k] + dist[i][k][j]);     }     for (int i = 0; i < r; i++) {       int u, v, k;       scanf( %d , &u);       scanf( %d , &v);       scanf( %d , &k);       u--;       v--;       k = min(k, n);       li[k].push_back(u);       li[k].push_back(v);       li[k].push_back(i);     }     prep();     for (int i = 0; i < r; i++) {       printf( %d , ans[i]);       ;       printf(  n );     }   }