#include <bits/stdc++.h>   using namespace std;   long long k, l, g = 0, h = 0;   int a, b, p[3][3], q[3][3], t, u, v, c;   vector<pair<int, int> > s;   bool con;   int gg(int a, int b) {     if (a == b + 1 || a == b - 2) return 1;     return 0;   }   void sim(int x, int t, int u) {     while (x > 0) {       g += gg(t, u);       h += gg(u, t);       v = t;       t = p[t][u];       u = q[v][u];       x--;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> k >> a >> b;     a--, b--;     for (int i = 0; i < (3); i++)       for (int j = 0; j < (3); j++) cin >> p[i][j];     for (int i = 0; i < (3); i++)       for (int j = 0; j < (3); j++) cin >> q[i][j];     for (int i = 0; i < (3); i++)       for (int j = 0; j < (3); j++) q[i][j]--, p[i][j]--;     s.push_back({a, b});     t = p[a][b], u = q[a][b];     while (true) {       con = false;       for (int i = 0; i < (s.size()); i++) {         if (s[i].first == t && s[i].second == u) con = true;       }       if (con)         break;       else {         s.push_back({t, u});         v = t;         t = p[t][u];         u = q[v][u];       }       con = false;     }     for (int i = 0; i < (s.size()); i++) {       if (s[i].first == t && s[i].second == u) c = s.size() - i;     }     if (k < 10000) {       sim(k, a, b);     } else {       l = (k - s.size() + c) / c;       sim(c, t, u);       g *= l;       h *= l;       sim(s.size() - c, a, b);       sim((k - s.size() + c) % c, t, u);     }     cout << g <<     << h << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 3;   const int inf = 1e8;   int n, m;   char str[N][N];   int sx, sy;   int tx, ty;   struct data {     int up;     int down;     int rgt;     int lft;     data() {       up = 0;       down = 0;       rgt = 0;       lft = 0;     }     void rotate() {       int _up = lft;       int _rgt = up;       int _down = rgt;       int _lft = down;       up = _up;       rgt = _rgt;       down = _down;       lft = _lft;     }   };   data mat[N][N];   queue<int> qx;   queue<int> qy;   queue<int> qr;   int dist[N][N][4];   inline void relax(int nx, int ny, int nr, int ndist) {     if (dist[nx][ny][nr] > ndist) {       dist[nx][ny][nr] = ndist;       qx.push(nx);       qy.push(ny);       qr.push(nr);     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %s , str[i] + 1);     }     for (int i = 0; i <= m + 1; ++i) {       str[0][i] =  * ;       str[n + 1][i] =  * ;     }     for (int i = 0; i <= n + 1; ++i) {       str[i][0] =  * ;       str[i][m + 1] =  * ;     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (str[i][j] ==  + ) {           mat[i][j].up = 1;           mat[i][j].lft = 1;           mat[i][j].rgt = 1;           mat[i][j].down = 1;         }         if (str[i][j] ==  - ) {           mat[i][j].up = 0;           mat[i][j].lft = 1;           mat[i][j].rgt = 1;           mat[i][j].down = 0;         }         if (str[i][j] ==  | ) {           mat[i][j].up = 1;           mat[i][j].lft = 0;           mat[i][j].rgt = 0;           mat[i][j].down = 1;         }         if (str[i][j] ==  ^ ) {           mat[i][j].up = 1;           mat[i][j].lft = 0;           mat[i][j].rgt = 0;           mat[i][j].down = 0;         }         if (str[i][j] ==  > ) {           mat[i][j].up = 0;           mat[i][j].lft = 0;           mat[i][j].rgt = 1;           mat[i][j].down = 0;         }         if (str[i][j] ==  < ) {           mat[i][j].up = 0;           mat[i][j].lft = 1;           mat[i][j].rgt = 0;           mat[i][j].down = 0;         }         if (str[i][j] ==  v ) {           mat[i][j].up = 0;           mat[i][j].lft = 0;           mat[i][j].rgt = 0;           mat[i][j].down = 1;         }         if (str[i][j] ==  L ) {           mat[i][j].up = 1;           mat[i][j].lft = 0;           mat[i][j].rgt = 1;           mat[i][j].down = 1;         }         if (str[i][j] ==  R ) {           mat[i][j].up = 1;           mat[i][j].lft = 1;           mat[i][j].rgt = 0;           mat[i][j].down = 1;         }         if (str[i][j] ==  U ) {           mat[i][j].up = 0;           mat[i][j].lft = 1;           mat[i][j].rgt = 1;           mat[i][j].down = 1;         }         if (str[i][j] ==  D ) {           mat[i][j].up = 1;           mat[i][j].lft = 1;           mat[i][j].rgt = 1;           mat[i][j].down = 0;         }         if (str[i][j] ==  * ) {           mat[i][j].up = 0;           mat[i][j].lft = 0;           mat[i][j].rgt = 0;           mat[i][j].down = 0;         }       }     }     scanf( %d %d , &sx, &sy);     scanf( %d %d , &tx, &ty);     for (int i = 0; i <= n + 1; ++i) {       for (int j = 0; j <= m + 1; ++j) {         for (int k = 0; k < 4; ++k) {           dist[i][j][k] = inf;         }       }     }     relax(sx, sy, 0, 0);     while (!qx.empty()) {       int x = qx.front();       int y = qy.front();       int r = qr.front();       int d = dist[x][y][r];       qx.pop();       qy.pop();       qr.pop();       relax(x, y, (r + 1) % 4, d + 1);       data tmp = mat[x][y];       data tmprgt = mat[x][y + 1];       data tmpdown = mat[x + 1][y];       data tmplft = mat[x][y - 1];       data tmpup = mat[x - 1][y];       for (int i = 0; i < r; ++i) {         tmp.rotate();         tmprgt.rotate();         tmpdown.rotate();         tmplft.rotate();         tmpup.rotate();       }       if (tmp.rgt && tmprgt.lft) {         relax(x, y + 1, r, d + 1);       }       if (tmp.lft && tmplft.rgt) {         relax(x, y - 1, r, d + 1);       }       if (tmp.up && tmpup.down) {         relax(x - 1, y, r, d + 1);       }       if (tmp.down && tmpdown.up) {         relax(x + 1, y, r, d + 1);       }     }     int ans = inf;     for (int i = 0; i < 4; ++i) {       ans = min(ans, dist[tx][ty][i]);     }     if (ans >= inf) {       ans = -1;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysecdesc(const pair<long long, long long> &a,                      const pair<long long, long long> &b) {     if (a.first == b.first)       return a.second > b.second;     else       return 0;   }   const long long N = 100010;   bool prime[N];   void SieveOfEratosthenes() {     long long n = N - 3;     memset(prime, true, sizeof(prime));     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   long long i, j;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     SieveOfEratosthenes();     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       if (n == 1 || n == 2 || n == 3 || n == 5 || n == 7 || n == 11) {         cout <<  -1  <<   n ;       } else if (n % 4 == 0) {         cout << n / 4 <<   n ;       } else if (n == 6) {         cout << 1 <<   n ;       } else {         long long temp = n / 4;         long long x = n - temp * 4;         if (x == 1) {           cout << 1 + (n - 9) / 4 <<   n ;         } else if (x == 2) {           cout << 1 + (n - 6) / 4 <<   n ;         } else if (x == 3) {           cout << 2 + (n - 15) / 4 <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fastpower(long long power, long long base) {     if (power == 0) return (1 % 1000000007);     long long sum;     sum = fastpower(power / 2, base) % 1000000007;     sum = ((sum % 1000000007) * (sum % 1000000007)) % 1000000007;     if (power & 1) sum = ((sum % 1000000007) * (base % 1000000007)) % 1000000007;     return (sum % 1000000007);   }   int main() {     ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0),         cout.tie(0);     ;     string s;     long long k, sum = 0;     cin >> s >> k;     long long rn =         (fastpower((long long)s.size() * k, 2) - 1 + 1000000007) % 1000000007;     long long r =         (fastpower((long long)s.size(), 2) - 1 + 1000000007) % 1000000007;     long long d = fastpower(1000000007 - 2, r);     for (int i = 0; i < (int)s.size(); ++i) {       if (s[i] ==  0  || s[i] ==  5 ) {         long long a = fastpower(i, 2);         sum = (sum % 1000000007 + a * rn % 1000000007 * d % 1000000007) %               1000000007;       }     }     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   #pragma GCC target( avx,tune=native )   using namespace std;   class CodeHash {    public:     string precise(double number, int prec) {       stringstream ss;       ss << fixed << setprecision(prec) << number;       return ss.str();     }   };   class ScanReader {    private:     FILE *stream;     char buffer[1 << 11];     bool is_digit[1 << 8];     int index, total;     int scan() {       if (index >= total) {         index = 0;         total = fread(buffer, 1, 1 << 11, stream);         if (total <= 0) return -1;       }       return buffer[index++];     }     bool iswhitespace(int n) {       if (n ==     || n ==   n  || n ==   t  || n ==   r  || n == -1) return true;       return false;     }       public:     ScanReader(FILE *stream) {       this->stream = stream;       index = total = 0;       for (int i = 0; i < 1 << 8; i++) is_digit[i] = isdigit(i);     }     int scanInt() {       int integer = 0, temp = scan();       while (iswhitespace(temp)) temp = scan();       int neg = 1;       if (temp ==  - ) neg *= -1, temp = scan();       while (!iswhitespace(temp))         if (is_digit[temp]) integer *= 10, integer += (temp -  0 ), temp = scan();       return neg * integer;     }     long long scanLong() {       long long integer = 0;       int temp = scan();       while (iswhitespace(temp)) temp = scan();       int neg = 1;       if (temp ==  - ) neg *= -1, temp = scan();       while (!iswhitespace(temp))         if (is_digit[temp]) integer *= 10, integer += (temp -  0 ), temp = scan();       return neg * integer;     }     string scanString() {       string ss =   ;       int temp = scan();       while (iswhitespace(temp)) temp = scan();       while (!iswhitespace(temp)) ss += temp, temp = scan();       return ss;     }     double scanDouble() {       int c = scan();       while (iswhitespace(c)) c = scan();       int sgn = 1;       if (c ==  - ) sgn = -1, c = scan();       double res = 0;       while (!iswhitespace(c) && c !=  . ) {         if (c ==  e  || c ==  E ) return res * pow(10, scanInt());         res *= 10;         res += c -  0 ;         c = scan();       }       if (c ==  . ) {         c = scan();         double m = 1;         while (!iswhitespace(c)) {           if (c ==  e  || c ==  E ) {             return res * pow(10, scanInt());           }           m /= 10;           res += (c -  0 ) * m;           c = scan();         }       }       return res * sgn;     }   };   class PrintWriter {    private:     FILE *stream;     static const int BUFFER_SIZE = (1 << 11) - 1;     static const int MAX_OUT_SIZE = 23;     int size;     char buffer[BUFFER_SIZE];     void write(long long v) {       if (v < 0) buffer[size++] =  - , v *= -1;       if (v < 10)         buffer[size++] = v + 48;       else {         write(v / 10);         buffer[size++] = v % 10 + 48;       }     }       public:     PrintWriter(FILE *stream) {       this->size = 0;       this->stream = stream;     }     void close() {       if (size) fwrite(buffer, 1, size, stream);     }     void println(long long s) {       if ((size ^ BUFFER_SIZE) < MAX_OUT_SIZE) {         fwrite(buffer, 1, size, stream);         size = 0;       }       write(s);       buffer[size++] =   n ;     }     void print(long long s) {       if ((size ^ BUFFER_SIZE) < MAX_OUT_SIZE) {         fwrite(buffer, 1, size, stream);         size = 0;       }       write(s);       buffer[size++] =    ;     }     void println(string s) {       if ((size ^ BUFFER_SIZE) < MAX_OUT_SIZE) {         fwrite(buffer, 1, size, stream);         size = 0;       }       for (int i = 0; i < s.length(); i++) {         buffer[size++] = s[i];         if ((size ^ BUFFER_SIZE) < MAX_OUT_SIZE) {           fwrite(buffer, 1, size, stream);           size = 0;         }       }       buffer[size++] =   n ;     }     void print(string s) {       if ((size ^ BUFFER_SIZE) < MAX_OUT_SIZE) {         fwrite(buffer, 1, size, stream);         size = 0;       }       for (int i = 0; i < s.length(); i++) {         buffer[size++] = s[i];         if ((size ^ BUFFER_SIZE) < MAX_OUT_SIZE) {           fwrite(buffer, 1, size, stream);           size = 0;         }       }       buffer[size++] =    ;     }   };   FILE *fi = stdin;   FILE *fo = stdout;   ScanReader *in = new ScanReader(fi);   PrintWriter *out = new PrintWriter(fo);   CodeHash *ch = new CodeHash();   int main() {     multiset<int> mt;     multiset<int> mt1;     multiset<int> mt2;     int n = in->scanInt();     long long ans = 1;     long long mod = 1000000007;     while (n--) {       string s = in->scanString();       int tt = in->scanInt();       if (s.length() == 3) {         if (!mt.empty() && *mt.begin() < tt)           mt.insert(tt);         else if (!mt1.empty() && *mt1.rbegin() > tt)           mt1.insert(tt);         else           mt2.insert(tt);       } else {         if ((!mt.empty() && *mt.begin() < tt) ||             (!mt1.empty() && *mt1.rbegin() > tt)) {           out->println(0);           out->close();           return 0;         }         if ((!mt.empty() && *mt.begin() == tt)) mt.erase(mt.begin());         if ((!mt1.empty() && *mt1.rbegin() == tt)) mt1.erase(--mt1.end());         while (!mt2.empty()) {           int tl = *mt2.begin();           mt2.erase(mt2.begin());           if (tl < tt) {             mt1.insert(tl);           } else if (tl > tt) {             mt.insert(tl);           } else {             ans = (ans * 2) % mod;           }         }       }     }     out->println((ans * (mt2.size() + 1)) % mod);     out->close();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getn() {     int h;     scanf( %d , &h);     return h;   }   template <class T, class U>   ostream& operator<<(ostream& out, const pair<T, U>& par) {     cout <<  [  << par.first <<  ;  << par.second <<  ] ;     return out;   }   vector<vector<int> > mini;   int n;   int nacitaj(int i, int j) {     mini[i][j] = getn();     i = (i != n - 1 ? i + 1 : 0);     j = (i != 0 ? j : j + 1);     return (j != n ? nacitaj(i, j) : 1);   }   int floydwardshal(int i, int j, int l) {     mini[i][j] = min(mini[i][j], mini[i][l] + mini[l][j]);     i = (i != n - 1 ? i + 1 : 0);     j = (i != 0 ? j : j + 1);     j = (j >= n ? 0 : j);     l = (i == 0 && j == 0 ? l + 1 : l);     return (l != n ? floydwardshal(i, j, l) : 0);   }   int maxi(int i, int j) {     int mx = mini[i][j];     i = (i != n - 1 ? i + 1 : 0);     j = (i != 0 ? j : j + 1);     return (j != n ? max(maxi(i, j), mx) : mx);   }   int main() {     n = getn();     mini.resize(n, vector<int>(n, 0));     nacitaj(0, 0);     floydwardshal(0, 0, 0);     cout << maxi(0, 0) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l, r;     cin >> l >> r;     int k = r - l;     if (k >= 1)       cout <<  2  << endl;     else       cout << l << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int sum = 0, a, n, m, i;     scanf( %d %d , &n, &m);     for (i = 1; i <= n; i++) {       sum = sum + i;       if (m > sum && i == n) {         i = 0;       }       a = m - sum;       if (a < i + 1) {         printf( %d , a);         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000000 + 10;   int a[N], b[N];   int n, m;   int main() {     int x, y;     scanf( %d%d , &n, &m);     {       for (int i = 0; i < m; i++) {         scanf( %d%d , &x, &y);         x--;         y--;         a[x]++;         a[y]++;       }       for (int i = 0; i < n; i++) b[i] = n - 1 - a[i];       long long total = 0;       for (int i = 0; i < n; i++) total += (long long)a[i] * b[i];       total /= 2;       cout << (long long)n * (n - 1) / 2 * (n - 2) / 3 - total << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mult(long long a, long long b, long long p = 1000000007) {     return ((a % p) * (b % p)) % p;   }   long long add(long long a, long long b, long long p = 1000000007) {     return (a % p + b % p) % p;   }   long long sub(long long a, long long b, long long p = 1000000007) {     return (a % p - b % p + p) % p;   }   long long fpow(long long n, long long k, long long p = 1000000007) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = mult(r, n, p);       n = mult(n, n, p);     }     return r;   }   long long inv(long long a, long long p = 1000000007) {     return fpow(a, p - 2, p);   }   map<long long, vector<long long> > m;   int main() {     long long n, k;     cin >> n >> k;     long long a[n], c[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       m[a[i]].push_back(i);     }     bool f = 1;     long long mx = 1;     long long it = 1;     for (auto i : m) {       if (i.second.size() > k) f = 0;       for (auto j : i.second) {         c[j] = it;         mx = max(mx, it);         ++it;         if (it > k) {           it = 1;           mx = k;         }       }     }     if (f && mx == k) {       cout <<  YES n ;       for (int i = 0; i < n; i++) cout << c[i] <<    ;     } else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 100 * 1000;   long double l[N];   long double Maks(long double dod, int n) {     int i;     long double as, mi, w;     mi = 0;     w = -10000000000000;     as = 0;     for (i = 1; i <= n; ++i) {       as += (l[i] - dod);       w = max(w, as - mi);       mi = min(mi, as);     }     return w;   }   long double Minim(long double dod, int n) {     int i;     long double as, ma, w;     ma = 0;     w = 10000000000000;     as = 0;     for (i = 1; i <= n; ++i) {       as += (l[i] - dod);       w = min(w, as - ma);       ma = max(ma, as);     }     return w;   }   long double TS(long double p, long double k, int n) {     int i;     long double s1, s2, w1, w2;     for (i = 1; i <= 100; ++i) {       s1 = p + ((k - p) / 3);       s2 = k - ((k - p) / 3);       w1 = max(abs(Maks(s1, n)), abs(Minim(s1, n)));       w2 = max(abs(Maks(s2, n)), abs(Minim(s2, n)));       if (w1 < w2)         k = s2;       else         p = s1;     }     return p;   }   void WczytajLiczby(int &n) {     int i;     cin >> n;     for (i = 1; i <= n; ++i) cin >> l[i];   }   void Weakness() {     int n;     long double w;     WczytajLiczby(n);     w = TS(-10000, 10000, n);     w = max(abs(Minim(w, n)), abs(Maks(w, n)));     cout << fixed << setprecision(10) << w <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     Weakness();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], lg[100005];   int rmq[100005][20];   struct trie {     struct node {       node *edge[2];       vector<int> ps[2];       node() {         for (int i = 0; i < 2; i++) edge[i] = 0;         ps[0].clear();         ps[1].clear();       }     } * root;     trie() { root = new node(); }     void insert(int v, int p) {       node *t = root;       for (int po = 29; po >= 0; po--) {         int x = (bool)(v & (1 << po));         if (!t->edge[x]) t->edge[x] = new node();         t->ps[x].push_back(p);         t = t->edge[x];       }     }     void remove(int v) {       node *t = root;       for (int po = 29; po >= 0; po--) {         int x = (bool)(v & (1 << po));         t->ps[x].pop_back();         t = t->edge[x];       }     }     long long query(int v, int last) {       node *t = root;       int res = 0;       for (int po = 29; po >= 0; po--) {         int x = (bool)(v & (1 << po));         x = !x;         if (!t->ps[x].empty() && t->ps[x].back() > last) {           res += (1 << po);           t = t->edge[x];         } else           t = t->edge[!x];       }       return res;     }   };   int q(int l, int r) {     if (l > r) swap(l, r);     int po = lg[r - l + 1];     return max(rmq[l][po], rmq[r - (1 << po) + 1][po]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     lg[0] = -1;     for (int i = 1; i < 100005; i++) lg[i] = lg[i - 1] + !(i & (i - 1));     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) rmq[i][0] = a[i];     for (int i = 1; i <= lg[n]; i++)       for (int j = 0; j + (1 << i) <= n; j++)         rmq[j][i] = max(rmq[j][i - 1], rmq[j + (1 << (i - 1))][i - 1]);     long long res = 0;     trie t;     t.insert(a[0], 0);     stack<pair<long long, long long> > ms;     ms.push(pair<long long, long long>(a[0], 0));     for (int i = 1; i < n; i++) {       int p1 = -1;       for (int po = (1 << 17); po; po >>= 1)         if (p1 + po < i && q(p1 + po, i) > a[i]) p1 += po;       int p2 = -1;       if (p1 > 0)         for (int po = (1 << 17); po; po >>= 1)           if (p2 + po <= p1 - 1 && q(p2 + po, p1 - 1) > a[i]) p2 += po;       res = max(res, t.query(a[i], p2));       while (!ms.empty() && ms.top().second > p1) {         t.remove(ms.top().first);         ms.pop();       }       t.insert(a[i], i);       ms.push(pair<long long, long long>(a[i], i));     }     cout << (res) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, g[20][20], r, c, k, ans = 0, x, y;   bool chk(int a, int b, int c, int d) {     int cnt = 0;     for (int i = a; i <= a + c; i++) {       for (int j = b; j <= b + d; j++) {         cnt += g[i][j];         if (cnt >= k) return 1;       }     }     return 0;   }   int main() {     scanf( %d%d%d%d , &r, &c, &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       g[x][y] = 1;     }     for (int i = 1; i <= r; i++) {       for (int j = 1; j <= c; j++) {         for (int e = 0; e + i <= r; e++) {           for (int f = 0; f + j <= c; f++) {             ans += chk(i, j, e, f);           }         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void printVec(vector<int> v2, string s =   ) {     cout << s;     for (int i = 0; i < (int)v2.size(); ++i) cout << v2[i] <<    ;     cout <<   n ;   }   bool isOdd(int a) { return (a % 2 == 1); }   void initMem(int n, int mem[]) {     for (int i = 0; i < n; i++) mem[i] = -1;   }   bool lucky(long long n) {     n = abs(n);     while (n) {       if (n % 10 == 8) {         return true;       }       n /= 10;     }     return false;   }   int main() {     int k;     int d;     cin >> k >> d;     string s =   ;     s += ( 0  + d);     for (int i = 1; i < k; i++) s +=  0 ;     if (d == 0) {       if (k == 1)         cout << 0;       else         cout <<  No solution ;       return 0;     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b;     cin >> a >> b;     long long ans = abs(a - b) / 5;     a = abs(a - b) % 5;     if (a == 4) cout << ans + 2;     if (a == 3) cout << ans + 2;     if (a == 2) cout << ans + 1;     if (a == 1) cout << ans + 1;     if (a == 0) cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(20);     long long t = 1;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int gizzly;     cin >> gizzly;     priority_queue<int> scoreList;     for (int i = 1; i < n; i++) {       int x;       cin >> x;       scoreList.push(x);     }     int candy = 0;     while (gizzly <= scoreList.top()) {       int opponent = scoreList.top();       scoreList.pop();       opponent -= 1;       gizzly += 1;       candy += 1;       scoreList.push(opponent);     }     cout << candy << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[((int)1001 * 1000)], maxi, mini;   vector<int> v;   int jaghool;   bitset<((int)1001 * 1000)> dp, mark;   int main() {     scanf( %d%d , &n, &k);     int k2 = k;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++)       if (!mark[i]) {         int x = a[i], p = 1;         while (x != i) p++, mark[x] = 1, x = a[x];         v.push_back(p);         maxi += min(k2, p / 2) * 2, k2 -= min(k2, p / 2);         if (p % 2) jaghool++;       }     maxi += min(k2, jaghool);     dp[0] = 1;     sort(v.begin(), v.end());     v.push_back(-1);     vector<int> v2;     for (int i = 0, cnt = 1; i < v.size(); i++) {       if (v[i] != v[i + 1]) {         int x = v[i];         while (cnt) {           dp |= (dp << v[i]);           for (int j = 0; j < ((int)20); j++) {             if ((1 << j) <= cnt && cnt < (1 << (j + 1))) {               cnt -= (1 << j);               break;             }             dp |= (dp << (v[i] << j));           }         }         cnt = 1;       } else         cnt++;     }     cout << k + 1 - dp[k] <<     << maxi <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Q, cnt = 1;   int par[400010][21], nxt[400010][21], len[400010];   long long w[400010], sum[400010][21];   long long mx[400010][21];   int find_first_bigger(int u, int W) {     if (mx[u][0] >= W) return u;     for (int i = 18; i >= 0; i--)       if (mx[u][i + 1] >= W && mx[u][i] < W) u = par[u][i];     return mx[u][0] >= W ? u : 0;   }   void add(int R, int W) {     int u = ++cnt;     w[u] = W;     int fb = find_first_bigger(R, W);     len[u] = len[fb] + 1;     nxt[u][0] = fb;     sum[u][0] = W;     par[u][0] = R;     mx[u][0] = w[u];     for (int i = 1; i < 21; i++) {       nxt[u][i] = nxt[nxt[u][i - 1]][i - 1];       sum[u][i] = sum[nxt[u][i - 1]][i - 1] + sum[u][i - 1];       par[u][i] = par[par[u][i - 1]][i - 1];       mx[u][i] = max(mx[par[u][i - 1]][i - 1], mx[u][i - 1]);     }   }   long long getsum(long long u, long long k) {     if (!k) return 0;     long long ret = 0;     for (int i = 0; k; i++, k >>= 1)       if (k & 1) {         ret += sum[u][i];         u = nxt[u][i];       }     return ret;   }   long long query(long long u, long long x) {     long long lo = 1, hi = len[u];     while (lo < hi) {       long long mid = (lo + hi) >> 1;       long long s = getsum(u, mid);       if (s > x)         hi = mid;       else         lo = mid + 1;     }     if (getsum(u, lo) <= x)       return lo;     else if (getsum(u, lo - 1) > x)       return 0;     return lo - 1;   }   int main() {     for (int i = 0; i < 400010; i++)       for (int j = 0; j < 21; j++) mx[i][j] = -4e18;     for (int i = 0; i < 21; i++) mx[1][0] = 0;     len[1] = 1;     scanf( %d , &Q);     long long last = 0;     while (Q--) {       long long tt, p, q;       scanf( %lld%lld%lld , &tt, &p, &q);       if (tt == 1) {         long long R = p ^ last, W = q ^ last;         add(R, W);       } else {         long long R = p ^ last, X = q ^ last;         printf( %lld n , last = query(R, X));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> vec;     set<int> st;     for (int i = 0; i < int(n); ++i) {       int a;       cin >> a;       st.insert(i);       vec.push_back(a);     }     queue<int> tok;     int ans = 0;     int killed = 0;     for (int i = n - 1; i > 0; i--) {       if (vec[i] < vec[i - 1]) {         st.erase(i);         ++killed;         tok.push(i - 1);       }     }     if (killed) ans++;     queue<int> qtok;     while (killed) {       killed = 0;       while (!tok.empty()) {         int tp = tok.front();         tok.pop();         auto it = st.find(tp);         if (it == st.end()) continue;         auto itn = st.find(tp);         itn++;         if (itn == st.end()) continue;         if (vec[*it] > vec[*itn]) {           qtok.push(*it);           ++killed;           st.erase(itn);         }       }       while (!qtok.empty()) {         tok.push(qtok.front());         qtok.pop();       }       if (killed) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pie = 3.14159265358979;   const long long mod = 1e9 + 7;   string vow =  aeiou ;   void solve(int test_case) {     string f, m, s;     cin >> f >> m >> s;     map<string, string> beat;     beat[ rock ] =  scissors ;     beat[ scissors ] =  paper ;     beat[ paper ] =  rock ;     if (beat[f] == m && beat[f] == s)       cout <<  F ;     else if (beat[m] == f && beat[m] == s)       cout <<  M ;     else if (beat[s] == f && beat[s] == m)       cout <<  S ;     else       cout <<  ? ;     cout <<   n ;   }   int main() {     int t = 1;     for (int i = 0; i < t; i++) solve(i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, k, d;     cin >> n >> t >> k >> d;     int curr = 0;     while (curr <= d) {       n -= k;       curr += t;     }     if (n > 0) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const int MAXN = 200010;   const int INF = 1e9;   const int Mod = 998244353LL;   int mx;   int N;   int tms = 0;   pair<int, int> sta[MAXN * 10 + 1];   int top;   int Node[MAXN << 1], Next[MAXN << 1], Root[MAXN + 1], cnt;   int deg[MAXN + 1];   inline void insert(int u, int v) {     Node[++cnt] = v;     Next[cnt] = Root[u];     Root[u] = cnt;     return;   }   inline void solve(int k, int Fa, int val) {     if (k != 1) --deg[k];     int last = deg[k];     sta[++top] = make_pair(k, tms);     bool flag = 0;     if (tms == mx && val != -1) {       tms = max(val - last, 0);       if (tms + last != val) flag = 1;       sta[++top] = make_pair(k, tms);     }     for (int x = Root[k]; x; x = Next[x]) {       int v = Node[x];       if (v == Fa) continue;       ++tms;       --last;       solve(v, k, ((tms == val && flag) ? tms : tms - 1));       ++tms;       sta[++top] = make_pair(k, tms);       if (tms == mx && val != -1) {         tms = max(val - last, 0);         if (tms + last != val) flag = 1;         sta[++top] = make_pair(k, tms);       }     }     if (val != -1 && tms > val) {       sta[++top] = make_pair(k, val);       tms = val;     }     return;   }   int main() {     N = read();     for (int i = 1; i < N; i++) {       int u = read(), v = read();       insert(u, v);       insert(v, u);       ++deg[u];       ++deg[v];     }     mx = 0;     for (int i = 1; i <= N; i++) mx = max(mx, deg[i]);     solve(1, 0, -1);     printf( %d n , top);     for (int i = 1; i <= top; i++) printf( %d %d n , sta[i].first, sta[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 600000;   const int MOD = (int)1e9 + 7;   int n, m, k, u, v, g[N];   long long c[N], w[N];   set<long long> s;   vector<pair<long long, pair<int, int> > > e;   int find(int cur) { return cur == g[cur] ? g[cur] : g[cur] = find(g[cur]); }   int main() {     scanf( %d %d %d , &n, &m, &k);     w[0] = 1;     for (int i = 1; i <= n; i++) {       w[i] = 2LL * w[i - 1] % MOD;     }     for (int i = 0; i < n; i++) {       scanf( %lld , &c[i]);     }     for (int i = 0; i < m; i++) {       scanf( %d %d , &u, &v);       u--;       v--;       s.insert(c[u] ^ c[v]);       e.push_back({c[u] ^ c[v], make_pair(u, v)});     }     long long ans = (((1LL << k) - s.size()) % MOD) * w[n] % MOD;     sort(e.begin(), e.end());     for (int i = 0; i < e.size();) {       int j = i;       while (j < e.size() && e[i].first == e[j].first) {         j++;       }       for (int p = i; p < j; p++) {         int u = e[p].second.first;         int v = e[p].second.second;         g[u] = u;         g[v] = v;       }       int c = n;       for (int p = i; p < j; p++) {         int u = e[p].second.first;         int v = e[p].second.second;         u = find(u);         v = find(v);         if (u != v) {           c--;           g[v] = u;         }       }       ans += w[c];       ans %= MOD;       i = j;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, lamps[2002], sol = 0, cs;     memset(lamps, 0, sizeof(lamps));     cin >> n >> m;     string s[2002];     for (int i = 0; i < n; i++) {       cin >> s[i];     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (s[i][j] ==  1 ) lamps[j]++;     for (int i = 0; i < n; i++) {       cs = 1;       for (int j = 0; j < m; j++) {         if (s[i][j] ==  1  && lamps[j] < 2) {           cs = 0;           break;         }       }       if (cs == 1) {         sol = 1;         break;       }     }     if (sol)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200000 + 100;   const int M = 30;   vector<int> G[MAXN];   int deep[MAXN], fa[MAXN][M];   void DFS(int cur, int pre) {     fa[cur][0] = pre;     for (int i = 1; i < 20; ++i) fa[cur][i] = fa[fa[cur][i - 1]][i - 1];     for (int i = 0; i < G[cur].size(); i++) {       int to = G[cur][i];       if (to == pre) continue;       deep[to] = deep[cur] + 1;       DFS(to, cur);     }   }   int LCA(int v, int u) {     if (deep[v] > deep[u]) swap(v, u);     for (int i = 0; i < 20; ++i)       if (deep[u] - deep[v] >> i & 1) u = fa[u][i];     for (int i = 19; i >= 0; --i)       if (fa[v][i] != fa[u][i]) v = fa[v][i], u = fa[u][i];     return v == u ? v : fa[v][0];   }   int cal(int s, int t, int f) {     int ans = 0, sf = LCA(s, f) == f, tf = LCA(t, f) == f;     if (sf != tf)       return 1;     else if (sf)       ans = deep[LCA(s, t)] - deep[f];     else if (LCA(s, f) != LCA(t, f))       ans = deep[f] - max(deep[LCA(f, s)], deep[LCA(f, t)]);     else       ans = deep[LCA(s, t)] + deep[f] - 2 * deep[LCA(s, f)];     return ans + 1;   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 2; i <= n; ++i) {       int x;       scanf( %d , &x);       G[i].push_back(x);       G[x].push_back(i);     }     DFS(1, 0);     while (q--) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       printf( %d n , max(cal(a, b, c), max(cal(b, c, a), cal(c, a, b))));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(int i, int n, set<pair<int, int> >& st) {     for (auto it : st) {       pair<int, int> t(it.first + i, it.second + i);       if (t.first > n) t.first %= n;       if (t.second > n) t.second %= n;       if (t.first > t.second) swap(t.first, t.second);       if (!st.count(t)) return false;     }     return true;   }   int main() {     int n, m, a, b;     while (cin >> n >> m) {       set<pair<int, int> > st;       for (int i = 1; i <= m; i++) {         cin >> a >> b;         st.insert(make_pair(min(a, b), max(a, b)));       }       bool flg = false;       for (int i = 1; i * i <= n; i++) {         if (n % i == 0) {           if (check(i, n, st)) {             flg = true;             break;           } else if (i != 1 && check(n / i, n, st)) {             flg = true;             break;           }         }       }       cout << (flg ?  Yes  :  No ) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, l, n, m, s, an, K, X;   const int N = 5100;   int a[1100000], g[1100000];   long long f[N][N];   int main() {     scanf( %d%d , &n, &K);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(&a[1], &a[n + 1]);     int v1 = n / K + 1;     int v2 = n / K;     if (n % K == 0) v1--;     int ss = n % K;     if (!ss) ss = K;     ss = K - ss;     memset(f, 120, sizeof(f));     f[0][0] = 0;     for (int i = 0; i <= K; i++)       for (int j = 0; j <= ss; j++) {         int now = j * v2 + (i - j) * v1;         f[i + 1][j] = min(f[i + 1][j], f[i][j] + a[now + v1] - a[now + 1]);         f[i + 1][j + 1] =             min(f[i + 1][j + 1], f[i][j] + a[now + v2] - a[now + 1]);       }     printf( %I64d n , f[K][ss]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fun(long long a[], long long remain, long long total, long long n,            long long m) {     vector<long long> ans;     long long i, j;     for (i = 0; i < n && total > 0; i++) {       if (a[i] % m == remain) {         ans.push_back(a[i]);         total--;       }     }     sort(ans.begin(), ans.end());     for (i = 0; i < ans.size(); i++) cout << ans[i] <<    ;   }   int main() {     long long t, n, i, j, k, m;     t = 1;     while (t--) {       cin >> n >> k >> m;       map<long long, long long> x;       long long a[n], flag = 0;       for (i = 0; i < n; i++) {         cin >> a[i];         x[a[i] % m]++;       }       for (auto itr = x.begin(); itr != x.end(); itr++) {         if (itr->second >= k) {           flag = 1;           cout <<  Yes  << endl;           fun(a, itr->first, k, n, m);           break;         }       }       if (flag == 0) cout <<  No  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool isprime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   int main() {     int t;     cin >> t;     string y =  YES n , z =  NO n ;     while (t--) {       long long int a, b, i, j;       cin >> a >> b;       if (a - b != 1)         cout << z;       else {         if (isprime(a + b))           cout << y;         else           cout << z;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = 0;     while (s.at(n) !=  . ) n++;     if (s.at(n - 1) ==  9 )       cout <<  GOTO Vasilisa. ;     else {       if (s.at(n + 1) < 53)         cout << s.substr(0, n);       else {         cout << s.substr(0, n - 1);         cout << (char)(s.at(n - 1) + 1);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 4e5 + 10;   int n, a[M], b[M], ans, cnt;   int f(int x, int i) {     return n - (x >> i) - (lower_bound(b, b + n, (1 << (i + 1)) - x) - b);   }   int32_t main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , a + i);     for (int i = 0; i < 28; i++) {       for (int j = 0; j < n; j++) b[j] = (a[j] & ((1 << (i + 1)) - 1));       sort(b, b + n);       cnt = 0;       for (int j = 0; j < n; j++) cnt += f(b[j], i);       ans += (((cnt >> 1) & 1) << (i + 1));     }     if (n % 2 == 0)       for (int i = 0; i < n; i++) ans ^= a[i];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1);   const long long MOD = 1000000007;   const long long FMOD = 998244353;   long long cnt1, cnt2, x, y;   bool isSafe(long long mid) {     long long div1 = mid / x;     long long div2 = mid / y;     long long div3 = mid / (x * y);     long long no = mid - (div1 + div2 - div3);     long long p = div1 - div3;     long long q = div2 - div3;     long long ans1 = cnt1 - q;     long long ans2 = cnt2 - p;     if (ans1 < 0) ans1 = 0;     if (ans2 < 0) ans2 = 0;     return (ans1 + ans2) <= no;   }   signed main() {     cin >> cnt1 >> cnt2 >> x >> y;     long long beg = 0, end = 1e10;     long long ans = 0;     while (beg <= end) {       long long mid = (beg + end) / 2;       if (isSafe(mid)) {         ans = mid;         end = mid - 1;       } else {         beg = mid + 1;       }     }     cout << ans;   }


/*/ Author: Aniruddh Lawande /*/   #include<bits/stdc++.h>   using namespace std;      /*/---------------------------Defines----------------------/*/       #define ll long long   #define F first   #define S second   #define pb push_back   #define endl   n    #define all(v) (v).begin(),(v).end()      typedef pair<ll,ll> pii;   /*/-----------------------Modular Arithmetic---------------/*/       const long long INF = 1ll << 32;    const int mod=1e9+7;   inline int add(int x,int y){       x+=y;       if (x>=mod) return x-mod;       return x;   }   inline int sub(int x,int y){       x-=y;       if (x<0) return x+mod;       return x;   }   inline int mul(int x,int y){       return (x*1ll*y)%mod;   }   inline int power(int x,int y){       int ans=1;       while(y){           if (y&1) ans=mul(ans,x);           x=mul(x,x);           y>>=1;       }       return ans;   }   inline int inv(int x){       return power(x,mod-2);   }      const ll FACTORIAL_SIZE = 1.1e6;   ll fact[FACTORIAL_SIZE], ifact[FACTORIAL_SIZE];   void gen_factorial(ll n) {    fact[0] = fact[1] = ifact[0] = ifact[1] = 1;         for (ll i = 2; i <= n; i++) {     fact[i] = (i * fact[i - 1]) % mod;    }    ifact[n] = inv(fact[n]);    for (ll i = n - 1; i >= 2; i--) {     ifact[i] = ((i + 1) * ifact[i + 1]) % mod;    }   }         ll nck(ll n, ll k) {    ll den = (ifact[k] * ifact[n - k]) % mod;    return (den * fact[n]) % mod;   }      /*/-----------------------------Code begins----------------------------------/*/   const int N=2e5+5;      void solve()   {       ll d,k;       cin>>d>>k;       ll x=0,y=0;       ll i=0;       while(x*x+y*y<=d*d)       {           if(i%2==0)           {               if((x+k)*(x+k)+y*y<=d*d) x+=k;               else break;           }           else           {               if(x*x+(y+k)*(y+k)<=d*d) y+=k;               else break;           }           i++;       }       if(i%2!=0)       {           cout<< Ashish <<endl;       }       else       {           cout<< Utkarsh <<endl;       }          }            int main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);    int tc=1;    cin>>tc;       int i=1;    while(tc--)    {           //cout<< CASE # <<i<< :  ;     solve();           i++;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 2e5L + 11, M = N * 2;   int a[M], b[M], c[M];   int back[M];   struct SegTree {     ll flag[N * 8];     ll val[N * 4];     void push(int x) {       val[x] += flag[x];       flag[2 * x] += flag[x];       flag[2 * x + 1] += flag[x];       flag[x] = 0;     }     void change(int l, int r, int ql, int qr, int c, int x = 1) {       push(x);       if (ql == l && qr == r) {         flag[x] = c;         push(x);       } else {         if (qr <= (l + r) / 2) {           change(l, (l + r) / 2, ql, qr, c, 2 * x);           push(2 * x + 1);         } else if (ql >= (l + r) / 2) {           push(2 * x);           change((l + r) / 2, r, ql, qr, c, 2 * x + 1);         } else {           change(l, (l + r) / 2, ql, (l + r) / 2, c, 2 * x);           change((l + r) / 2, r, (l + r) / 2, qr, c, 2 * x + 1);         }         val[x] = min(val[2 * x], val[2 * x + 1]);       }     }     ll query(int l, int r, int ql, int qr, int x = 1) {       push(x);       if (ql == l && qr == r) return val[x];       if (qr <= (l + r) / 2)         return query(l, (l + r) / 2, ql, qr, 2 * x);       else if (ql >= (l + r) / 2)         return query((l + r) / 2, r, ql, qr, 2 * x + 1);       else         return min(query(l, (l + r) / 2, ql, (l + r) / 2, 2 * x),                    query((l + r) / 2, r, (l + r) / 2, qr, 2 * x + 1));     }   } st;   vector<int> e[N];   int cnt = 0;   int in[N], out[N], id[N];   void dfs(int x) {     id[x] = ++cnt;     in[x] = cnt;     for (int i : e[x]) dfs(i);     out[x] = cnt;   }   int n;   ll query(int x) { return st.query(1, n + 1, id[x], id[x] + 1) - back[x]; }   int main() {     int q;     cin >> n >> q;     for (int i = 1; i <= 2 * n - 2; i++) {       scanf( %d%d%d , a + i, b + i, c + i);       if (i <= n - 1)         e[a[i]].push_back(b[i]);       else         back[a[i]] = c[i];     }     dfs(1);     for (int i = 1; i <= n - 1; i++)       st.change(1, n + 1, in[b[i]], out[b[i]] + 1, c[i]);     for (int i = 2; i <= n; i++) st.change(1, n + 1, id[i], id[i] + 1, back[i]);     while (q--) {       int t, u, v;       scanf( %d%d%d , &t, &u, &v);       if (t == 1) {         int i = u, w = v;         if (i <= n - 1) {           st.change(1, n + 1, in[b[i]], out[b[i]] + 1, w - c[i]);           c[i] = w;         } else {           st.change(1, n + 1, id[a[i]], id[a[i]] + 1, w - c[i]);           back[a[i]] = w;           c[i] = w;         }       } else {         ll ans = st.query(1, n + 1, in[u], out[u] + 1) - query(u) + query(v);         if (id[v] >= in[u] && id[v] <= out[u])           ans = min(ans, query(v) - query(u));         printf( %lld n , ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e17 + 7;   const long long maxn = 5e5 + 700;   const int mod = 998244353;   const int up = 1e9;   template <typename T>   inline void read(T &a) {     char c = getchar();     T x = 0, f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     a = f * x;   }   long long n, m, p;   int num[maxn], b[maxn];   struct Dinic {     long long cnt = 2;     struct Edge {       int e, next;       long long w;     };     int _S, _T, N;     int head[maxn], d[maxn], cur[maxn];     Edge edge[maxn];     void _inint(int s, int t, int n) {       memset(head, 0, sizeof(head));       cnt = 2;       _S = s, _T = t, N = n;     }     void addedge(int u, int v, long long w) {       edge[cnt] = Edge{v, head[u], w};       head[u] = cnt++;     }     void Add(int u, int v, long long w) {       addedge(u, v, w);       addedge(v, u, 0);     }     bool bfs() {       for (int k = 0; k <= N; k++) d[k] = 0;       queue<int> q;       q.push(_S);       d[_S] = 1;       while (!q.empty()) {         int u = q.front();         q.pop();         for (int i = head[u]; i; i = edge[i].next) {           int e = edge[i].e;           if (edge[i].w <= 0 || d[e]) continue;           d[e] = d[u] + 1;           q.push(e);         }       }       for (int k = 0; k <= N; k++) cur[k] = head[k];       return (d[_T] != 0);     }     long long dfs(int u, long long flow) {       if (u == _T) return flow;       for (int &i = cur[u]; i; i = edge[i].next) {         int e = edge[i].e;         if (d[e] != d[u] + 1 || edge[i].w <= 0) continue;         long long temp = dfs(e, min(flow, edge[i].w));         if (temp <= 0) continue;         edge[i].w -= temp;         edge[i ^ 1].w += temp;         return temp;       }       return 0;     }     long long MaxFlow() {       long long maxflow = 0, delta = 0;       while (bfs()) {         while (delta = dfs(_S, INF)) maxflow += delta;       }       return maxflow;     }     vector<int> v[maxn];     int col[maxn];     vector<vector<int>> res;     void dfs(int u, vector<int> &a) {       col[u] = 1;       a.push_back(u);       for (int e : v[u]) {         if (col[e]) continue;         dfs(e, a);       }     }     void AC() {       long long temp = MaxFlow();       if (temp == N - 1) {         for (int i = 1; i <= n; i++) {           if (!(num[i] & 1)) continue;           for (int k = head[i]; k; k = edge[k].next) {             int e = edge[k].e;             if (edge[k ^ 1].w) {               v[e].push_back(i);               v[i].push_back(e);             }           }         }         for (int i = 1; i <= n; i++) {           if (!col[i]) {             vector<int> temp;             dfs(i, temp);             res.push_back(temp);           }         }         printf( %d n , res.size());         for (auto x : res) {           printf( %d  , x.size());           for (int y : x) printf( %d  , y);           printf(  n );         }       } else         printf( Impossible n );     }   } g;   int judge(int x) {     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return 0;     return 1;   }   int main() {     read(n);     g._inint(0, n + 1, n + 1);     for (int i = 1; i <= n; i++) {       read(num[i]);       if (num[i] & 1)         g.Add(0, i, 2);       else         g.Add(i, n + 1, 2);     }     for (int i = 1; i <= n; i++) {       for (int k = i + 1; k <= n; k++) {         if (judge(num[i] + num[k])) {           if (num[i] & 1)             g.Add(i, k, 1);           else             g.Add(k, i, 1);         }       }     }     g.AC();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 30, Mod = 1e9 + 7;   const long long SQ = 330;   map<long long, vector<long long> > mp;   pair<long long, long long> E[N];   long long p[N], sz[N], M[N], cnt[N];   vector<long long> G[N];   long long r[N], ans[N];   void DFS(long long v, long long R) {     cnt[v] = sz[v];     M[v] = 1;     r[v] = R;     for (auto u : G[v]) {       if (!M[u]) {         DFS(u, R);         cnt[v] += cnt[u];       }     }   }   long long get(long long x) { return (p[x] ? p[x] = get(p[x]) : x); }   void add(long long x, long long y) {     x = get(x);     y = get(y);     if (x == y) return;     if (rand() % 2) swap(x, y);     p[x] = y;     sz[y] += sz[x];   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     long long n;     cin >> n;     fill(sz, sz + N, 1);     for (int i = 1; i < n; i++) {       long long v, u, w;       cin >> v >> u >> w;       mp[w].push_back(i);       E[i] = {v, u};     }     for (auto R : mp) {       vector<long long> V = R.second;       set<long long> second;       for (auto x : V) {         second.insert(get(E[x].first));         second.insert(get(E[x].second));       }       for (auto x : second) G[x].clear(), M[x] = false, cnt[x] = 0;       for (auto x : V) {         G[get(E[x].first)].push_back(get(E[x].second));         G[get(E[x].second)].push_back(get(E[x].first));       }       for (auto u : second)         if (!M[u]) DFS(u, u);       for (auto x : V) {         long long v = E[x].first, u = E[x].second;         v = get(v);         u = get(u);         if (cnt[v] > cnt[u]) swap(v, u);         ans[x] = cnt[v] * (cnt[r[v]] - cnt[v]);       }       for (auto x : V) add(E[x].first, E[x].second);     }     long long mx = 0;     for (int i = 1; i < n; i++) mx = max(mx, ans[i]);     long long C = 0;     for (int i = 1; i < n; i++)       if (ans[i] == mx) C++;     cout << 2 * mx <<     << C <<   n ;     for (int i = 1; i < n; i++)       if (ans[i] == mx) cout << i <<    ;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l = 0, r = 0;     cin >> n;     for (int i = 0; i < n; i++) {       bool a, b;       cin >> a >> b;       l += a;       r += b;     }     int left = 2 * l > n ? (n - l) : l;     int right = 2 * r > n ? (n - r) : r;     int count = left + right;     cout << count;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll MOD = 1e9 + 7;   class SegTree {    private:     const ll NEUT = 0;     vector<ll> seg, tag;     int h = 1;     ll len(int i) { return h >> (31 - __builtin_clz(i)); }     void apply(int i, ll v) {       seg[i] = (seg[i] + v * len(i)) % MOD;       if (i < h) tag[i] = (tag[i] + v) % MOD;     }     void push(int i) {       if (tag[i] == 0) return;       apply(2 * i, tag[i]);       apply(2 * i + 1, tag[i]);       tag[i] = 0;     }     ll combine(ll a, ll b) { return (a + b) % MOD; }     ll recGet(int a, int b, int i, int ia, int ib) {       if (ib <= a || b <= ia) return NEUT;       if (a <= ia && ib <= b) return seg[i];       push(i);       int im = (ia + ib) >> 1;       return combine(recGet(a, b, 2 * i, ia, im),                      recGet(a, b, 2 * i + 1, im, ib));     }     void recApply(int a, int b, ll v, int i, int ia, int ib) {       if (ib <= a || b <= ia) return;       if (a <= ia && ib <= b)         apply(i, v);       else {         push(i);         int im = (ia + ib) >> 1;         recApply(a, b, v, 2 * i, ia, im);         recApply(a, b, v, 2 * i + 1, im, ib);         seg[i] = combine(seg[2 * i], seg[2 * i + 1]);       }     }       public:     SegTree(int n) {       while (h < n) h *= 2;       seg.resize(2 * h, NEUT);       tag.resize(h, 0);     }     ll rangeSum(int a, int b) { return recGet(a, b + 1, 1, 0, h); }     void rangeAdd(int a, int b, ll v) { recApply(a, b + 1, v, 1, 0, h); }   };   class HLD {    private:     vector<int> par, siz, cmp, ind;     void dfs1(int i, vector<vector<int>>& g) {       for (auto& t : g[i]) {         if (t == par[i]) continue;         par[t] = i;         dfs1(t, g);         siz[i] -= siz[t];         if (siz[t] > siz[g[i][0]]) swap(t, g[i][0]);       }       siz[i] *= -1;     }     void dfs2(int i, int& x, const vector<vector<int>>& g) {       ind[i] = x;       ++x;       for (auto t : g[i]) {         if (t == par[i]) continue;         cmp[t] = (x == ind[i] + 1 ? cmp[i] : t);         dfs2(t, x, g);       }     }       public:     HLD(vector<vector<int>> g, int r = 0)         : par(g.size(), -1), siz(g.size(), -1), cmp(g.size(), r), ind(g.size()) {       dfs1(r, g);       int x = 0;       dfs2(r, x, g);     }     const vector<pair<int, int>>& path(int a, int b) const {       static vector<pair<int, int>> res;       res.clear();       for (;; b = par[cmp[b]]) {         if (ind[b] < ind[a]) swap(a, b);         if (ind[cmp[b]] <= ind[a]) {           res.push_back({ind[a], ind[b]});           return res;         }         res.push_back({ind[cmp[b]], ind[b]});       }     }     pair<int, int> subtree(int i) const { return {ind[i], ind[i] + siz[i] - 1}; }     int lca(int a, int b) const {       for (;; b = par[cmp[b]]) {         if (ind[b] < ind[a]) swap(a, b);         if (ind[cmp[b]] <= ind[a]) return a;       }     }     bool deeper(int a, int b) { return siz[a] < siz[b]; }   };   ll modPow(ll a, ll b) {     if (b & 1) return a * modPow(a, b - 1) % MOD;     if (b == 0) return 1;     return modPow(a * a % MOD, b / 2);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     ll colc = 1;     vector<ll> weight(n);     vector<pair<int, int>> evs;     for (int i = 0; i < n; ++i) {       int a, b;       cin >> a >> b;       evs.push_back({a, i + 1});       evs.push_back({b + 1, -(i + 1)});       colc = (colc * (b - a + 1)) % MOD;       weight[i] = modPow(b - a + 1, MOD - 2);     }     sort(evs.begin(), evs.end());     vector<vector<int>> g(n);     for (int i = 0; i < n - 1; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       g[a].push_back(b);       g[b].push_back(a);     }     HLD hld(g);     ll cur = 0;     ll res = 0;     SegTree above(n), below(n);     int c = 0;     for (int j = 0; j < evs.size(); ++j) {       int nc = evs[j].first;       res = (res + cur * (nc - c)) % MOD;       c = nc;       int i = abs(evs[j].second) - 1;       ll v = (evs[j].second < 0 ? MOD - 1 : 1) * weight[i] % MOD;       vector<pair<int, int>> path = hld.path(i, 0);       int pi = n - 1;       for (auto pr : path) {         cur = (cur + v * below.rangeSum(pr.second + 1, pi)) % MOD;         above.rangeAdd(pr.second + 1, pi, v);         cur = (cur + v * above.rangeSum(pr.first, pr.second)) % MOD;         below.rangeAdd(pr.first, pr.second, v);         pi = pr.first - 1;       }     }     res = (res * colc) % MOD;     if (res < 0) res += MOD;     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7, NMAX = 100010;   int N, M;   int color[NMAX];   vector<int> Left[NMAX], Right[NMAX];   void DFS(int node, int current_color) {     if (color[node] && color[node] != current_color) {       cout <<  0 n ;       exit(0);     }     if (color[node] == 0) {       color[node] = current_color;       for (int i = 0; i < int(Left[node].size()); ++i)         DFS(Left[node][i], current_color);       for (int i = 0; i < int(Right[node].size()); ++i)         DFS(Right[node][i], 3 - current_color);     }   }   int FastExponentiation(int exponent) {     int base = 2, ret = 1;     while (exponent) {       if (exponent & 1) ret = (int64_t(ret) * base) % MOD;       base = (int64_t(base) * base) % MOD;       exponent >>= 1;     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     int i, x, y, c;     cin >> N >> M;     while (M--) {       cin >> x >> y >> c;       c == 1 ? (Left[x].push_back(y), Left[y].push_back(x))              : (Right[x].push_back(y), Right[y].push_back(x));     }     int components = 0;     for (i = 1; i <= N; ++i) {       if (color[i]) continue;       DFS(i, 1);       ++components;     }     cout << FastExponentiation(components - 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int current = 0;     int i = 1, i2 = 2;     int ans = 0;     while (current + i <= n) {       current += i;       ans++;       i += i2;       i2++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n = 0, m = 0;   char** values;   bool** values1;   void PrintArray() {     cout <<  Values n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << values[i][j] <<    ;       }       cout << endl;     }     cout <<  Values1 n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << values1[i][j] <<    ;       }       cout << endl;     }   }   void Check(int i, int j) {     char valueToCheck = values[i][j];     if (i == n - 1) goto second;     for (int i1 = i + 1; i1 < n; i1++) {       if (valueToCheck == values[i1][j]) {         values1[i][j] = true;         values1[i1][j] = true;       }     }   second:     if (j == m - 1) return;     for (int j1 = j + 1; j1 < m; j1++) {       if (valueToCheck == values[i][j1]) {         values1[i][j] = true;         values1[i][j1] = true;       }     }   }   void ConstructString() {     string result =   ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (values1[i][j] != true) result += values[i][j];       }     }     cout << result;   }   int main() {     string str, temp;     cin >> n >> m;     values = new char*[n + 1];     values1 = new bool*[n + 1];     for (int i = 0; i < n; i++) {       values[i] = new char[m + 1];       values1[i] = new bool[m + 1];       memset(values1[i], 0, m + 1);       cin >> values[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (values[i][j] ==  * ) continue;         Check(i, j);       }     }     ConstructString();     for (int i = 0; i < n; ++i) {       delete[] values[i];       delete[] values1[i];     }     delete[] values;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Imx = 2147483647;   const long long Lbig = 2e18;   const int mod = 1e9 + 7;   struct fastio {     char s[100000];     int it, len;     fastio() { it = len = 0; }     inline char get() {       if (it < len) return s[it++];       it = 0;       len = fread(s, 1, 100000, stdin);       if (len == 0)         return EOF;       else         return s[it++];     }     bool notend() {       char c = get();       while (c ==     || c ==   n ) c = get();       if (it > 0) it--;       return c != EOF;     }   } _buff;   inline long long getnum() {     long long r = 0;     bool ng = 0;     char c;     c = _buff.get();     while (c !=  -  && (c <  0  || c >  9 )) c = _buff.get();     if (c ==  - ) ng = 1, c = _buff.get();     while (c >=  0  && c <=  9 ) r = r * 10 + c -  0 , c = _buff.get();     return ng ? -r : r;   }   template <class T>   inline void putnum(T x) {     if (x < 0) putchar( - ), x = -x;     register short a[20] = {}, sz = 0;     while (x) a[sz++] = x % 10, x /= 10;     if (sz == 0) putchar( 0 );     for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]);   }   inline char getreal() {     char c = _buff.get();     while (c <= 32) c = _buff.get();     return c;   }   long long qpow(long long x, long long k) {     return k == 0 ? 1                   : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod;   }   char s[100111];   bitset<100005> ch[26], A, all;   char t[100111];   int main() {     scanf( %s , s);     int n = strlen(s);     for (int i = 0; i < n; i++) ch[s[i] -  a ][i] = 1, all[i] = 1;     int q;     scanf( %d , &q);     while (q--) {       int op, x;       scanf( %d%d , &op, &x);       x--;       if (op == 1) {         char c = getchar();         while (c <  a  || c >  z ) c = getchar();         ch[s[x] -  a ][x] = 0;         s[x] = c;         ch[s[x] -  a ][x] = 1;       } else {         int y;         scanf( %d , &y);         y--;         scanf( %s , t);         int l = strlen(t);         A = (all >> (n - (y - x + 1) + l - 1)) << x;         for (int i = 0; i < l; i++) A = (A & ch[t[i] -  a ]) << 1;         printf( %d n , A.count());       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int dig(long long int n) {     long long int r = 0;     while (n) {       ++r;       n = n / 10;     }     return (r - 1);   }   long long int func(long long int n) {     if (n <= 9) return (n + 1);     long long int lt = dig(n);     lt = pow(10, lt);     long long int ret = lt - 1;     long long int mul = ret / 10;     long long int mid = (n % lt) / 10;     lt = n / lt;     long long int rt = n % 10;     if (rt >= lt) {       return (lt * (mul + 1) + func(ret));     } else {       return (lt * (mul + 1) + func(ret));     }   }   long long int fun(long long int n) {     if (n <= 9) return (n + 1);     long long int lt = dig(n);     lt = pow(10, lt);     long long int ret = lt - 1;     long long int mul = ret / 10;     long long int mid = (n % lt) / 10;     lt = n / lt;     long long int rt = n % 10;     if (rt >= lt) {       return ((mid + 1) + (lt - 1) * (mul + 1) + func(ret));     } else {       return (mid + (lt - 1) * (mul + 1) + func(ret));     }   }   int main() {     long long int l, r;     cin >> l >> r;     cout << fun(r) - fun(l - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c;     cin >> a >> b >> c;     cout << a * b + (a + b - 1) * (c - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double inf = 1e14;   const double pi = acos(-1);   const double eps = 1e-10;   const int maxn = 25010;   int n, x[maxn], y[maxn], dx[maxn], dy[maxn], s[maxn];   double ans = inf, ddx[maxn], ddy[maxn], K[maxn], B[maxn];   inline double solve(int a, int b) {     double b1, k1, b2, k2;     k1 = K[a];     b1 = B[a];     k2 = K[b];     b2 = B[b];     if (k1 == k2) {       double kk =           sqrt((x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]));       double X, Y, XX, YY, t;       t = kk / double(s[a] + s[b]);       X = (double)x[a] + (double)ddx[a] * t * s[a];       Y = (double)y[a] + (double)ddy[a] * t * s[a];       XX = (double)x[b] + (double)ddx[b] * t * s[b];       YY = (double)y[b] + (double)ddy[b] * t * s[b];       if (abs(X - XX) <= eps && abs(Y - YY) <= eps) return t;       if (s[a] == s[b]) return inf;       t = kk / double(s[a]);       X = (double)x[a] + (double)ddx[a] * t * s[a];       Y = (double)y[a] + (double)ddy[a] * t * s[a];       if (abs(X - x[b]) <= eps && abs(Y - y[b]) <= eps) return t;       t = kk / double(s[b]);       X = (double)x[b] + (double)ddx[b] * t * s[b];       Y = (double)y[b] + (double)ddy[b] * t * s[b];       if (abs(X - x[a]) <= eps && abs(Y - y[a]) <= eps) return t;       return inf;     }     double X = (b2 - b1) / (k1 - k2), Y;     Y = k1 * X + b1;     if ((Y - y[a]) * dy[a] < 0) return inf;     if ((Y - y[b]) * dy[b] < 0) return inf;     if ((X - x[a]) * dx[a] < 0) return inf;     if ((X - x[b]) * dx[b] < 0) return inf;     double now1 = sqrt((X - x[a]) * (X - x[a]) + (Y - y[a]) * (Y - y[a])) / s[a];     double now2 = sqrt((X - x[b]) * (X - x[b]) + (Y - y[b]) * (Y - y[b])) / s[b];     return max(now1, now2);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d%d%d%d , &x[i], &y[i], &dx[i], &dy[i], &s[i]);       double v = sqrt(dx[i] * dx[i] + dy[i] * dy[i]);       ddx[i] = dx[i] / v;       ddy[i] = dy[i] / v;       K[i] = (double)dy[i] / dx[i];       B[i] = y[i] - (double)dy[i] / dx[i] * x[i];     }     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) {         ans = min(ans, solve(i, j));       }     if (ans > 1e12)       printf( No show :( n );     else       printf( %.15f n , ans);     return 0;   }


#include<iostream>   typedef long long ll;   using namespace std;      const int maxn =1e5+5;   int n,q;   ll sum[maxn];   string s;      int main() {       cin>>n>>q;       cin>>s;       s =  # +s;       for(int i=1;i<=n;i++) sum[i] = sum[i-1]+s[i]- a +1;       while (q--) {           int l,r;           cin>>l>>r;           cout<<sum[r]-sum[l-1]<<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100010];   int la, ra;   void update(int i, int delta) {     for (; i < n; i = i | (i + 1)) {       a[i] += delta;     }   }   int get(int fr, int to) {     int res = 0;     for (int i = to; i >= 0; i = (i & (i + 1)) - 1) {       res += a[i];     }     for (int i = fr - 1; i >= 0; i = (i & (i + 1)) - 1) {       res -= a[i];     }     return res;   }   int main(void) {     int q;     scanf( %d%d , &n, &q);     for (int i = 0; i < n; ++i) {       update(i, 1);     }     int la = 0;     int ra = n;     for (int i = 0; i < q; ++i) {       int t;       scanf( %d , &t);       if (t == 1) {         int p, len, mid;         scanf( %d , &p);         if (la < ra) {           len = ra - la;           mid = la + p;         } else {           len = la - ra;           mid = la - p;         }         if (p > len / 2) {           swap(la, ra);           p = len - p;         }         if (la < ra) {           for (int i = 0; i < p; ++i) {             update(mid + i, get(mid - 1 - i, mid - 1 - i));           }         } else {           for (int i = 0; i < p; ++i) {             update(mid - 1 - i, get(mid + i, mid + i));           }         }         la = mid;       } else {         int l, r;         scanf( %d%d , &l, &r);         if (la < ra) {           l += la;           r += la;         } else {           l = la - l;           r = la - r;           swap(l, r);         }         printf( %d n , get(l, r - 1));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const short maxn = 5000 + 5;   const int mod = 1000000000 + 7;   int n;   short x[maxn], y[maxn];   short d[maxn][maxn];   short md;   char col[maxn];   void dfs(int x) {     for (int i = 0, _n = (int)(n); i < _n; i++)       if (d[x][i] > md) {         if (col[x] == col[i]) throw 0;         if (col[i]) continue;         col[i] = 3 - col[x];         dfs(i);       }   }   int cnt() {     memset(col, 0, sizeof col);     int r = 1;     for (int i = 0, _n = (int)(n); i < _n; i++)       if (col[i] == 0) {         col[i] = 1;         try {           dfs(i);         } catch (...) {           return 0;         }         (r += r) >= mod ? r -= mod : 0;       }     return r;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0, _n = (int)(n); i < _n; i++) cin >> x[i] >> y[i];     for (int i = 0, _n = (int)(n); i < _n; i++)       for (int j = (int)(i + 1), _n = (int)(n); j < _n; j++)         d[i][j] = d[j][i] = abs(x[i] - x[j]) + abs(y[i] - y[j]);     short lo = -1, hi = 10000;     while (lo + 1 < hi) {       md = (lo + hi) / 2;       if (cnt() != 0)         hi = md;       else         lo = md;     }     md = hi;     cout << hi << endl << cnt() << endl;     {       int _;       cin >> _;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, A, B;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     while (n--) {       cin >> A >> B;       cout << A * (long long)log10(B + 1) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int u, v;     long long g, s;     bool operator<(const edge &cmp) const { return s < cmp.s; }   } e[50005], a[50005];   int n, m, cnt, p[205], tam;   long long gt, st;   bool cmpG(edge a, edge b) { return a.g < b.g; }   int find(int x) {     if (p[x] == x) return x;     return p[x] = find(p[x]);   }   bool link(int &a, int &b) {     if (find(a) == find(b)) return false;     p[find(a)] = find(b);     return true;   }   long long kruskal() {     long long res = 0;     cnt = 0;     for (int i = 1; i <= n; ++i) p[i] = i;     sort(a, a + tam);     for (int i = 0; i < tam; ++i) {       if (link(a[i].u, a[i].v)) {         res = a[i].s;         a[cnt++] = a[i];       }     }     tam = cnt;     return res;   }   int main() {     scanf( %d%d , &n, &m);     scanf( %I64d%I64d , &gt, &st);     long long res = 1ll << 62, sil;     cnt = tam = 0;     for (int i = 0; i < m; ++i) {       scanf( %d%d%I64d%I64d , &e[i].u, &e[i].v, &e[i].g, &e[i].s);       e[i].g *= gt;       e[i].s *= st;     }     sort(e, e + m, cmpG);     for (int i = 0; i < m; ++i) {       a[tam++] = e[i];       sil = kruskal();       if (cnt == n - 1) {         sil += e[i].g;         if (sil < res) res = sil;       }     }     if (res < 1ll << 62)       printf( %I64d n , res);     else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 2e5 + 10;   using namespace std;   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f * x;   }   int n, q;   long long a[MAXN];   typedef struct node {     long long maxx;     long long sum;   } node;   node d[MAXN << 2];   void up(int x) {     d[x].sum = d[x << 1].sum + d[x << 1 | 1].sum;     d[x].maxx = max(d[x << 1].maxx, d[x << 1 | 1].maxx);   }   void built(int rt, int l, int r) {     if (l == r) {       d[rt].maxx = d[rt].sum = a[l];       return;     }     int mid = (l + r) >> 1;     built(rt << 1, l, mid);     built(rt << 1 | 1, mid + 1, r);     up(rt);   }   void update(int rt, int l, int r, int t, long long vul) {     if (l == r) {       d[rt].maxx = d[rt].sum = vul;       return;     }     int mid = (l + r) >> 1;     if (t <= mid)       update(rt << 1, l, mid, t, vul);     else       update(rt << 1 | 1, mid + 1, r, t, vul);     up(rt);   }   bool flag;   int pos1;   void querty2(int rt, int l, int r, long long vul) {     if (l == r) {       pos1 = l;       return;     }     int mid = (l + r) >> 1;     if (d[rt << 1].maxx >= vul)       querty2(rt << 1, l, mid, vul);     else       querty2(rt << 1 | 1, mid + 1, r, vul);   }   void querty(int rt, int l, int r, int ql, int qr, long long vul) {     if (flag) return;     if (ql <= l && r <= qr) {       if (d[rt].maxx >= vul) {         flag = 1;         querty2(rt, l, r, vul);       }       return;     }     int mid = (l + r) >> 1;     if (ql <= mid) querty(rt << 1, l, mid, ql, qr, vul);     if (qr > mid) querty(rt << 1 | 1, mid + 1, r, ql, qr, vul);   }   long long ans;   void querty1(int rt, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) {       ans += d[rt].sum;       return;     }     int mid = (l + r) >> 1;     if (ql <= mid) querty1(rt << 1, l, mid, ql, qr);     if (qr > mid) querty1(rt << 1 | 1, mid + 1, r, ql, qr);   }   int main() {     n = read();     q = read();     for (int i = 1; i <= n; i++) a[i] = read();     a[n + 1] = 1e18;     int pos, ans1;     long long vul, key, pre;     n++;     built(1, 1, n);     for (int i = 1; i <= q; i++) {       pos = read();       vul = read();       a[pos] = vul;       update(1, 1, n, pos, vul);       ans1 = -1;       key = 0;       if (!a[1]) {         printf( 1 n );         continue;       }       if (a[1] == a[2]) {         printf( 2 n );         continue;       }       key = a[1] + a[2];       pre = 3;       while (1) {         if (pre > n) break;         flag = 0;         querty(1, 1, n, pre, n, key);         ans = 0;         querty1(1, 1, n, 1, pos1 - 1);         if (ans == a[pos1]) {           ans1 = pos1;           break;         }         key = ans + a[pos1];         pre = pos1 + 1;       }       printf( %d n , ans1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int tree[6000005], a[3000005], minp[3000005], upd[3000005];   long long int cun[3000005];   long long int d[3000005];   long long int n;   void sieve() {     a[0] = 1;     a[1] = 1;     for (long long int i = 1; i < 1e6 + 1; i++) {       for (long long int j = i; j < 1e6 + 1; j += i) {         d[j]++;       }     }   }   long long int lazy[3000005], tree2[3000005];   long long int b[3000005];   void build_tree(long long int node, long long int c, long long int en) {     if (c > en) return;     if (c == en) {       tree[node] = b[c];       tree2[node] = (tree[node] != 2 && tree[node] != 1);       return;     }     build_tree(node * 2, c, (c + en) / 2);     build_tree(node * 2 + 1, 1 + (c + en) / 2, en);     tree[node] = tree[2 * node] + tree[2 * node + 1];     tree2[node] = tree2[node * 2] | tree2[node * 2 + 1];   }   long long int query(long long int node, long long int st, long long int en,                       long long int l, long long int r) {     if (st > r || en < l || st > en) return 0;     if (st >= l && en <= r) {       return tree[node];     }     long long int r1 = query(2 * node, st, (st + en) / 2, l, r);     long long int r2 = query(2 * node + 1, (st + en) / 2 + 1, en, l, r);     return r1 + r2;   }   void update(long long int node, long long int st, long long int en,               long long int l, long long int r) {     if (st > r || en < l || st > en) return;     if (st == en) {       int p = d[tree[node]];       tree[node] = p;       tree2[node] = (tree[node] != 2 && tree[node] != 1);       return;     }     if (tree2[2 * node]) update(2 * node, st, (st + en) / 2, l, r);     if (tree2[2 * node + 1]) update(2 * node + 1, (st + en) / 2 + 1, en, l, r);     tree[node] = tree[2 * node] + tree[2 * node + 1];     tree2[node] = tree2[node * 2] | tree2[node * 2 + 1];   }   int main() {     sieve();     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int q;     cin >> n >> q;     for (long long int i = 0; i < n; i++) cin >> b[i];     build_tree(1, 0, n - 1);     for (long long int i = 0; i < q; i++) {       long long int ty, l, r;       cin >> ty >> l >> r;       l--;       r--;       if (ty == 1)         update(1, 0, n - 1, l, r);       else         cout << query(1, 0, n - 1, l, r) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> g[50005];   vector<int> t[50005];   int T;   int col[1000005];   int team[50005];   mt19937 mt(1235577);   int x[100005], y[100005];   int ans[50005];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (int)(m); ++i) {       int from, to;       scanf( %d%d , &from, &to), --from, --to;       x[i] = from;       y[i] = to;       g[from].push_back(to);       g[to].push_back(from);     }     for (int i = 0; i < (int)(n); ++i) {       int cnt;       scanf( %d , &cnt);       for (int j = 0; j < (int)(cnt); ++j) {         int x;         scanf( %d , &x), --x;         T = max(T, x + 1);         t[i].push_back(x);       }     }     int times = 0;     while (true) {       assert(times++ < 100);       for (int i = 0; i < (int)(T); ++i) {         col[i] = mt() & 1;       }       bool ok = true;       bool was[2];       for (int i = 0; i < (int)(n); ++i) {         was[0] = was[1] = false;         for (int x : t[i]) {           was[col[x]] = true;         }         if (!was[0] || !was[1]) {           ok = false;           break;         }       }       if (ok) {         break;       }     }     while (true) {       for (int i = 0; i < (int)(n); ++i) team[i] = mt() & 1;       int cnt = 0;       for (int i = 0; i < (int)(m); ++i)         if (team[x[i]] != team[y[i]]) {           ++cnt;         }       if (2 * cnt < m) {         continue;       }       for (int i = 0; i < (int)(n); ++i) {         for (int x : t[i])           if (col[x] == team[i]) {             ans[i] = x;             break;           }       }       bool firstTime = true;       for (int i = 0; i < (int)(n); ++i) {         if (!firstTime) {           printf(   );         }         firstTime = false;         printf( %d , ans[i] + 1);       }       printf(  n );       firstTime = true;       for (int i = 0; i < (int)(T); ++i) {         if (!firstTime) {           printf(   );         }         firstTime = false;         printf( %d , col[i] + 1);       }       printf(  n );       break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> num;   void solve() {     int n;     cin >> n;     char arr[2][n];     for (int i = 0; i < 2; i++) {       for (int j = 0; j < n; j++) {         cin >> arr[i][j];       }     }     int row = 0, col = 0;     int visited[2][n];     memset(visited, false, sizeof(visited));     while (col < n - 1) {       visited[row][col] = true;       if (!visited[row][col + 1] && arr[row][col + 1] !=  1 )         col++;       else if (!visited[1 - row][col] && arr[1 - row][col] !=  1 ) {         row = 1 - row;       } else if (!visited[1 - row][col + 1] && arr[1 - row][col + 1] !=  1 ) {         row = 1 - row;         col++;       } else {         break;       }     }     if (col == n - 1)       cout <<  Yes  << endl;     else       cout <<  No  << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[40000005];   void oku() {     int n;     cin >> n;     for (int i = 0; i < n; i++) a[i] = i;     int l, k;     for (k = 2, l = 0; k <= n; k++, l++) {       int r = (n - 1) / k;       a[n + l] = a[r * k + l];       for (; r > 0; r--) {         a[r * k + l] = a[(r - 1) * k + l];       }     }     for (int i = l; i < l + n; i++) printf( %d  , a[i] + 1);     cout << endl;   }   void oku2() {     int n;     cin >> n;     for (int i = 0; i < n; i++) a[i] = i;     for (int i = 2; i <= n; i++) {       for (int k = 0; i * k < n; k++)         for (int j = i * k; j + 1 < min(n, i * (k + 1)); j++)           swap(a[j], a[j + 1]);     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout << endl;   }   int main() {     oku();     return 0;   }


#include <bits/stdc++.h>   const int maxN = 1000000;   char in[maxN + 1];   int occ[10], instanceOfRest[7] = {8169, 8961, 8619, 6891, 8691, 9168, 8196};   int main() {     scanf( %s , in);     int s = std::strlen(in);     for (int i = 0; i < s; i++) occ[in[i] -  0 ]++;     occ[1]--, occ[6]--, occ[8]--, occ[9]--;     int powerOf10 = 1, res = 0, occOfZero = occ[0];     occ[0] = 4;     for (int i = 0; i < 10; i++) {       for (int j = 0; j < occ[i]; j++) {         res = (res + (i % 7) * powerOf10) % 7;         powerOf10 = (powerOf10 * 3) % 7;       }     }     for (int i = 9; i > 0; i--)       for (int j = 0; j < occ[i]; j++) printf( %d , i);     printf( %d , instanceOfRest[(7 - res) % 7]);     while (occOfZero--) printf( 0 );     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;      int b[200100];      int l[200100], r[200100];      int main(){       int T; scanf( %d , &T);       int tot = T;       int num = 0;       while (T--){           num++;           int N, K, M; scanf( %d%d%d , &N, &K, &M);           for (int i = 1; i <= M; i++) scanf( %d , &b[i]);           int ind = 1;           int cnt = 0;           for (int i = 1; i <= N; i++){               l[i] = 0;               if (ind == M+1 || b[ind] != i){                   cnt++;               } else {                   ind++;                   l[i] = cnt;               }           }           if (cnt%(K-1) != 0){               printf( NO n );               continue;           }           bool work = false;           for (int i = 1; i <= N; i++){               if (l[i] >= K/2 && cnt-l[i] >= K/2){                   work = true;                   break;               }           }           if (work) printf( YES n );           else printf( NO n );       }   }


#include <bits/stdc++.h>   using namespace std;   enum faces {     Tetrahedron = 4,     Cube = 6,     Octahedron = 8,     Dodecahedron = 12,     Icosahedron = 20   };   int main() {     int n;     cin >> n;     long long total = 0;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       if (s ==  Tetrahedron )         total += Tetrahedron;       else if (s ==  Cube )         total += Cube;       else if (s ==  Octahedron )         total += Octahedron;       else if (s ==  Dodecahedron )         total += Dodecahedron;       else if (s ==  Icosahedron )         total += Icosahedron;     }     cout << total;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long even[222222] = {0}, a[222222], odd[222222] = {0}, backEven[222222],             cur, best = numeric_limits<int>::min(), besteven = 0;   int main() {     int n;     scanf( %d , &n);     for (int i = 2; i <= n; i++) cin >> a[i];     even[1] = 0;     odd[1] = 0;     for (int i = 2; i <= n; i++) {       even[i] = even[i - 1] + (a[i] / 2) * 2;       if (a[i] < 2) even[i] = 0;       odd[i] = odd[i - 1] + a[i];       if (a[i] % 2 == 0) odd[i]--;     }     backEven[n] = 0;     for (int i = n - 1; i >= 1; i--) {       backEven[i] = backEven[i + 1] + (a[i + 1] / 2) * 2;       if (a[i + 1] < 2) backEven[i] = 0;     }     for (int j = 1; j <= n; j++) {       cur = besteven + backEven[j] + odd[j];       best = max(cur, best);       besteven = max(besteven, even[j + 1] - odd[j + 1]);     }     cout << best;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   const int mod = 998244353;   const int inf = 0x3f3f3f3f;   vector<int> G[maxn];   int id[maxn];   struct SEG {     int ma[maxn << 2];     SEG() { memset(ma, -1, sizeof ma); }     void update(int rt, int pos, int l, int r, int val) {       if (l == r) {         ma[rt] = val;         return;       }       int m = (l + r) >> 1;       if (m >= pos)         update(rt << 1, pos, l, m, val);       else         update(rt << 1 | 1, pos, m + 1, r, val);       ma[rt] = max(ma[rt << 1], ma[rt << 1 | 1]);     }     int query(int rt, int L, int R, int l, int r) {       if (L <= l && r <= R) return ma[rt];       int m = (l + r) >> 1;       int ret = -1;       if (m >= L) ret = max(ret, query(rt << 1, L, R, l, m));       if (m < R) ret = max(ret, query(rt << 1 | 1, L, R, m + 1, r));       return ret;     }   } seg;   struct TREE {     int dfn[maxn], siz[maxn], son[maxn], top[maxn], fa[maxn], o = 0;     void dfs(int rt, int p) {       fa[rt] = p;       siz[rt] = 0;       son[rt] = -1;       for (int x : G[rt]) {         if (x == p) continue;         dfs(x, rt);         siz[rt] += siz[x] + 1;         if (son[rt] == -1 || siz[son[rt]] < siz[x]) son[rt] = x;       }     }     void dfs2(int rt, int p, int tp) {       dfn[rt] = ++o;       top[rt] = tp;       if (son[rt] != -1) dfs2(son[rt], rt, tp);       for (int x : G[rt]) {         if (x == p || x == son[rt]) continue;         dfs2(x, rt, x);       }     }     int query(int rt) {       int ret = -1;       while (rt != -1) {         int tp = top[rt];         ret = max(ret, seg.query(1, dfn[tp], dfn[rt], 1, maxn - 1));         rt = fa[tp];       }       return ret;     }   } tree;   multiset<int> S[maxn];   struct ACAM {     int nxt[maxn][26], fail[maxn], o = 0;     void insert(char* s, int x) {       int rt = 0;       for (int i = 0; s[i]; i++) {         int c = s[i] -  a ;         if (!nxt[rt][c]) nxt[rt][c] = ++o;         rt = nxt[rt][c];       }       id[x] = rt;     }     void build() {       queue<int> Q;       for (int i = 0; i < 26; i++)         if (nxt[0][i]) {           G[0].push_back(nxt[0][i]);           Q.push(nxt[0][i]);         }       while (!Q.empty()) {         int x = Q.front();         Q.pop();         for (int i = 0; i < 26; i++) {           if (nxt[x][i]) {             fail[nxt[x][i]] = nxt[fail[x]][i];             Q.push(nxt[x][i]);             G[nxt[fail[x]][i]].push_back(nxt[x][i]);           } else             nxt[x][i] = nxt[fail[x]][i];         }       }     }     int query(char* s) {       int rt = 0;       int ret = -1;       for (int i = 0; s[i]; i++) {         rt = nxt[rt][s[i] -  a ];         int tmp = tree.query(rt);         ret = max(ret, tmp);       }       return ret;     }   } ac;   char s[maxn];   int raw[maxn];   int main(void) {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %s , s);       ac.insert(s, i);     }     ac.build();     tree.dfs(0, -1);     tree.dfs2(0, -1, 0);     for (int i = 1; i <= n; i++) {       int rt = id[i];       S[rt].insert(0);       seg.update(1, tree.dfn[rt], 1, maxn - 1, 0);     }     while (q--) {       int op;       scanf( %d , &op);       if (op == 1) {         int pos, val;         scanf( %d%d , &pos, &val);         int rt = id[pos];         S[rt].erase(S[rt].find(raw[pos]));         raw[pos] = val;         S[rt].insert(val);         seg.update(1, tree.dfn[rt], 1, maxn - 1, *S[rt].rbegin());       } else {         scanf( %s , s);         int ans = ac.query(s);         printf( %d n , ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   void solve() {     int n, m;     cin >> n >> m;     int mex = INT_MAX, curr = 0;     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       mex = min(mex, r - l + 1);     }     cout << mex <<   n ;     for (int i = 0; i < n; i++) {       cout << curr <<    ;       curr++;       if (curr == mex) curr = 0;     }   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(NULL);     cin.tie(NULL);     ;     long long int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned int dp[100010];   int n, m, maxx;   char str[100010];   int main() {     cin >> n;     if (n & 1) {       cout << 0 << endl;       return 0;     }     scanf( %s , str + 1);     dp[0] = 1;     for (int i = 1; i <= n; i++)       if (str[i] ==  ? ) {         m++;         maxx = min(i / 2, m);         for (int j = maxx; j; j--) dp[j] += dp[j - 1];       }     if (m < n / 2) {       cout << 0 << endl;       return 0;     }     m -= n / 2;     while (m--) dp[n >> 1] *= 25;     cout << dp[n >> 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string a, b;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> a >> b;     int p1 = -1, p2 = -1;     for (int i = 0; i < n; i++) {       if (a[i] != b[i]) {         p1 = i;         break;       }     }     for (int i = n - 1; i >= 0; i--) {       if (a[i] != b[i]) {         p2 = i;         break;       }     }     string x =   , y =   ;     for (int i = p1; i <= p2; i++) {       x += a[i];       y += b[i];     }     int sol = 0;     if (x + y.back() == x[0] + y) sol++;     if (y[0] + x == y + x.back()) sol++;     cout << sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300005;   pair<int, int> pa[maxn];   int main() {     int n, a, b;     scanf( %d%d%d , &n, &a, &b);     for (int i = 0; i < n; ++i) {       scanf( %d , &pa[i].first);       pa[i].second = i + 1;     }     sort(pa, pa + n);     for (int i = 0; i < n; ++i) {       int c = (a + pa[i].first - 1) / pa[i].first + i;       if (c < n && (b + pa[c].first - 1) / pa[c].first <= n - c) {         int d = (b + pa[c].first - 1) / pa[c].first;         puts( Yes );         printf( %d %d n , c - i, d);         printf( %d , pa[i].second);         for (int j = i + 1; j < c; ++j) printf(  %d , pa[j].second);         printf(  n );         printf( %d , pa[c].second);         for (int j = 1; j < d; ++j) printf(  %d , pa[c + j].second);         printf(  n );         return 0;       }     }     swap(a, b);     for (int i = 0; i < n; ++i) {       int c = (a + pa[i].first - 1) / pa[i].first + i;       if (c < n && (b + pa[c].first - 1) / pa[c].first <= n - c) {         int d = (b + pa[c].first - 1) / pa[c].first;         puts( Yes );         printf( %d %d n , d, c - i);         printf( %d , pa[c].second);         for (int j = 1; j < d; ++j) printf(  %d , pa[c + j].second);         printf(  n );         printf( %d , pa[i].second);         for (int j = i + 1; j < c; ++j) printf(  %d , pa[j].second);         printf(  n );         return 0;       }     }     puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 100005;   vector<pair<long long, char>> adj[maxn];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long u, v;       char c;       cin >> u >> v >> c;       adj[u].push_back({v, c});       adj[v].push_back({u, c});     }     vector<long long> res(2e5, 0);     for (long long c : { R ,  B }) {       vector<long long> vec;       bool vis[maxn], color[maxn];       for (long long i = 0; i <= n; i++) vis[i] = color[i] = false;       for (long long i = 1; i <= n; i++) {         if (vis[i]) continue;         vector<long long> s, t;         queue<long long> q;         q.push(i);         vis[i] = true;         while (!q.empty()) {           long long u = q.front();           q.pop();           if (color[u])             s.push_back(u);           else             t.push_back(u);           for (pair<long long, char> e : adj[u]) {             if (vis[e.first]) continue;             if (e.second == c)               color[e.first] = !color[u];             else               color[e.first] = color[u];             vis[e.first] = true;             q.push(e.first);           }         }         if (s.size() < t.size())           for (long long u : s) vec.push_back(u);         else           for (long long u : t) vec.push_back(u);       }       bool ok = true;       for (long long u = 1; u <= n; u++) {         for (pair<long long, char> e : adj[u]) {           if (e.second == c)             ok &= color[e.first] != color[u];           else             ok &= color[e.first] == color[u];         }       }       if (!ok) continue;       if (vec.size() < res.size()) res = vec;     }     if (res.size() == 2e5)       cout <<  -1 n ;     else {       cout << res.size() <<   n ;       for (long long i : res) cout << i <<    ;       cout <<   n ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> ch(26);     for (int i = 0; i < n; i++) {       char c;       cin >> c;       ch[c -  a ]++;     }     if (k >= *max_element(ch.begin(), ch.end()))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


/*   #pragma GCC optimize( O2 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( avx,avx2,sse,sse2,fma )   */   #include <bits/stdc++.h>      using namespace std;      typedef long long ll;   typedef long double ld;   typedef pair<int , int> pii;      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      const int maxn = 3e6;   const ll mod = 1e9+7;   const ld PI = acos((ld)-1);      #define pb push_back   #define endl   n    #define dokme(x) cout << x , exit(0)   #define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)   #define ms(x , y) memset(x , y , sizeof x)   ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}      ll n , q , k;         int32_t main(){    migmig;    cin >> q;    while(q --){     cin >> n >> k;     if(n - (k - 1) <= n/2){      for(int i = 1 ; i < k ; i ++)       cout << 1 <<    ;      cout << n - (k - 1) << endl;      continue;     }     if(n%k == 0){      for(int i = 1 ; i <= k ; i ++)       cout << n / k <<    ;      cout << endl;      continue;     }     for(int i = 1 ; i <= k - 3 ; i ++){      n--;      cout << 1 <<    ;     }     if(n % 3 == 0){      cout << n/3 <<     << n/3 <<     << n/3 << endl;      continue;     }     if(n % 2){      cout << 1 <<     << (n - 1)/2 <<     << (n - 1)/2 << endl;      continue;     }     if((n - 2)%4 == 0){      cout << 2 <<     << (n - 2) / 2 <<     << (n - 2) / 2 << endl;      continue;     }       cout << n / 2 <<     << n/4 <<      << n/4 << endl;    }    return(0);   }


#include <bits/stdc++.h>   using namespace std;   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   int ddx[8] = {-1, -1, 0, 1, 1, 1, 0, -1};   int ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};   bool debug = false;   int main() {     int n, L, a;     cin >> n >> L >> a;     int ans = 0, now = 0;     for (int i = 0; i < n; i++) {       int t, l;       cin >> t >> l;       ans += (t - now) / a;       now = t + l;     }     ans += (L - now) / a;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 7;   bool pri(int a) {     if (a == 1) return 0;     for (int i = 2; i * i <= a; i++) {       if (a % i == 0) {         return 0;       }     }     return 1;   }   long long n, m, t, a[200000];   string s;   int main() {     cin >> t;     while (t--) {       long long x, y;       cin >> x >> y;       if (x > y) {         cout << x + y <<   n ;         continue;       }       if (x == y) {         cout << x <<   n ;         continue;       }       if (2 * x >= y) {         cout << (x + y) / 2 <<   n ;         continue;       }       x = x * int(y / x);       cout << (x + y) / 2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned short log2(unsigned short x) {     unsigned short log = 0;     while (x > 1) {       log++;       x /= 2;     }     return log;   }   int main() {     unsigned short a, b, n, r;     cin >> n >> a >> b;     a -= 1;     b -= 1;     n /= 2;     if (a / n != b / n)       cout <<  Final!  << endl;     else {       r = log2(n);       n /= 2;       while (a / n == b / n) {         n /= 2;         r -= 1;       }       cout << r << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class flow_t, const flow_t inf>   struct Dinic {     struct edge_t {       long long to;       flow_t cap, flow;       edge_t(long long to = 0, flow_t cap = 0, flow_t flow = 0)           : to(to), cap(cap), flow(flow) {}     };     long long n, s, t;     vector<vector<long long>> g;     vector<long long> d, ptr;     vector<edge_t> ed;     Dinic(long long n = 0, long long s = 0, long long t = 0) : n(n), s(s), t(t) {       g.assign(n + 5, vector<long long>());       ed.clear();     }     void add(long long u, long long v, long long cap) {       g[u].push_back(ed.size());       ed.push_back(edge_t(v, cap, 0));       g[v].push_back(ed.size());       ed.push_back(edge_t(u, 0, 0));     }     bool bfs() {       d.assign(n + 5, -1);       ptr.assign(n + 5, 0);       queue<long long> q;       d[s] = 0;       q.push(s);       while (!q.empty()) {         long long u = q.front();         q.pop();         for (long long id : g[u]) {           long long v = ed[id].to;           if (d[v] == -1 && ed[id].cap > ed[id].flow) {             d[v] = d[u] + 1;             q.push(v);           }         }       }       return d[t] != -1;     }     flow_t dfs(long long u, flow_t flow) {       if (u == t || !flow) return flow;       for (long long& i = ptr[u]; i < (long long)g[u].size(); ++i) {         long long id = g[u][i];         long long v = ed[id].to;         if (d[v] != d[u] + 1 || ed[id].cap <= ed[id].flow) continue;         flow_t nxt = dfs(v, min(flow, ed[id].cap - ed[id].flow));         if (nxt) {           ed[id].flow += nxt;           ed[id ^ 1].flow -= nxt;           return nxt;         }       }       return 0;     }     flow_t max_flow() {       while (bfs())         while (dfs(s, inf))           ;       flow_t ret = 0;       for (long long id : g[s]) ret += ed[id].flow;       return ret;     }     vector<long long> path;     flow_t trace(long long u) {       path.push_back(u);       if (u == t) return 1;       for (long long id : g[u]) {         long long v = ed[id].to;         if (ed[id].flow > 0) {           ed[id].flow--;           trace(v);           return 1;         }       }       return 0;     }     vector<vector<long long>> solve() {       vector<vector<long long>> ret;       while (true) {         path.clear();         if (trace(s))           ret.push_back(path);         else           break;       }       return ret;     }   };   signed main() {     ios_base::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     long long s = 0, t = n + m + 1;     Dinic<long long, (long long)1e18> dn(n + m, s, t);     for (long long i = 1; i <= n; ++i) {       long long x;       cin >> x;       dn.add(i, t, x);     }     long long sum = 0;     for (long long i = 1; i <= m; ++i) {       long long u, v;       long long w;       cin >> u >> v >> w;       dn.add(n + i, u, 1e18);       dn.add(n + i, v, 1e18);       dn.add(s, n + i, w);       sum += w;     }     cout << sum - dn.max_flow() <<   n ;   }