#include <bits/stdc++.h>   using namespace std;   int ans1 = 0, ans2 = 0;   int main(void) {     int t, i, j;     cin >> t;     while (t--) {       int n, mx = INT_MIN, ans = 0, sz;       cin >> n;       int a[n];       set<int> s;       for (i = 0; i < n; i++) {         cin >> a[i];         mx = max(mx, a[i]);         s.insert(a[i]);       }       for (i = 12; i >= 0; i--) {         if (((1 << i) & mx) != 0) break;       }       mx = (1 << (i + 1));       for (i = 1; i <= mx; i++) {         map<int, int> mp;         sz = 0;         for (j = 0; j < n; j++) {           if ((s.count(a[j] ^ i) > 0) && (mp[a[j] ^ i] == 0)) {             sz++;             mp[a[j] ^ i]++;           }         }         if (sz == s.size()) ans = 1;         if (ans == 1) break;       }       if (ans == 0)         cout << -1 << endl;       else         cout << i << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, a, b;     scanf( %d%d , &n, &k);     printf( %d , n);     for (int i = n - 1; i > k; --i) printf(  %d , i);     a = 1, b = k;     while (a < b) printf(  %d %d , a++, b--);     if (a == b) printf(  %d , a);     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, c;     cin >> n >> m >> c;     int a[n], b[m];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     for (int i = 0; i < n - m + 1; i++) {       int k = i;       for (int j = 0; j < m; j++) {         a[k] += b[j];         a[k] = a[k] % c;         k++;       }     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, l, tl, ans, ca, cb, cc;   long long min(long long a, long long b) { return a < b ? a : b; }   void cpy() {     a = ca, b = cb;     c = cc;   }   int main() {     scanf( %lld%lld%lld%lld , &a, &b, &c, &l);     ca = a;     cb = b;     cc = c;     for (int i = l + 2; i >= 2; --i) ans += 1ll * i * (1ll * i - 1) / 2;     if (b + c - a <= l) {       if (a > b + c)         tl = l;       else         tl = l - (b + c - a), a = b + c;       for (int i = 0; i <= tl; ++i) {         long long tb = min(a - b - c + 1ll * i, tl - 1ll * i);         ans -= (tb + 1) * (tb + 2) / 2;       }     }     cpy();     if (a + b - c <= l) {       if (c > a + b)         tl = l;       else         tl = l - (a + b - c), c = a + b;       for (int i = 0; i <= tl; ++i) {         long long tb = min(c - a - b + i * 1ll, tl - i * 1ll);         ans -= (tb + 1) * (tb + 2) / 2;       }     }     cpy();     if (a + c - b <= l) {       if (b > a + c)         tl = l;       else         tl = l - (a + c - b), b = a + c;       for (int i = 0; i <= tl; ++i) {         long long tb = min(b - a - c + i * 1ll, tl - i * 1ll);         ans -= (tb + 1) * (tb + 2) / 2;       }     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   bool func(string s, long n) {     if (s.size() % n) return false;     for (long i = 0; i < s.size(); i++)       if (s[i] != a[i % n]) return 0;     return 1;   }   int main() {     cin >> a >> b;     long ans = 0, i = 1;     string p = a, q = b;     long minx = min(a.size(), b.size());     while (i <= minx) {       ans += (func(p, i) && func(q, i));       i++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   const double PI = acos(-1);   const long long N = 500005, md = 1e9 + 7, inf = 1e18, iinf = 1e9 + 5, MX = 3e5;   long long g, w, h, x, y, z, i, j, k, q, n, cnt, res, sum, r[N], a[N], b[N];   char c[N];   string s, t;   pair<int, int> p[N];   vector<int> e[N];   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n >> k;     if (k == 2 && (n < 3 || n == 4))       cout <<  NO ;     else if (k == 3 && (n < 6 || n == 8))       cout <<  NO ;     else {       if (n < k * (k + 1) / 2) cout <<  NO , exit(0);       cout <<  YES n ;       x = (n - k * (k + 1) / 2) / k;       for (long long i = 0; i < k; i++) a[i] = i + 1 + x, sum += a[i];       while (sum < n) {         for (long long i = k - 1; i >= 0; i--) {           if (a[i] + 1 > a[i - 1] * 2) i = k - 1;           if (sum == n) break;           if (sum < n) sum++, a[i]++;         }       }       for (long long i = 0; i < k; i++) cout << a[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   bool ask(int val) {     cout <<  ?   << val + 1 << endl;     string resp;     cin >> resp;     return resp[0] ==  Y  ? true : false;   }   void fix() { cout <<  R  << endl; }   int main() {     int n, k;     cin >> n >> k;     vector<bool> check(n + 1, 0);     int block = k % 2 ? 1 : k / 2;     for (int blockno = 1; blockno < n / block; blockno += 1) {       for (int j = 0; j < blockno && (blockno + j < n / block); j += 1) {         for (int k = j; k < n / block; k += blockno) {           for (int a = 0; a < block; a += 1) {             if (ask(k * block + a)) {               check[k * block + a + 1] = true;             }           }         }         fix();       }     }     int res = 0;     for (int i = 1; i <= n; i += 1) {       if (check[i] == 0) {         res += 1;       }     }     cout <<  !   << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int _ = 1, tc = 1;   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   const int MAXN = 1e7 + 1;   int spf[MAXN];   int d, x, y;   void sieve() {     for (int i = 1; i < MAXN; i++) spf[i] = i;     for (int i = 4; i < MAXN; i += 2) spf[i] = 2;     for (int i = 3; i * i < MAXN; i += 2) {       if (spf[i] == i) {         for (int j = i * i; j < MAXN; j += i) {           if (spf[j] == j) spf[j] = i;         }       }     }   }   void extended_gcd(int a, int b) {     if (b == 0) {       d = a;       x = 1;       y = 0;     } else {       extended_gcd(b, a % b);       int temp = y;       y = x - y * (a / b);       x = temp;     }   }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return a * (b / gcd(a, b)); }   int getmod(int x, int y, int mod) { return (((x - y) % mod) + mod) % mod; }   vector<string> split(string line, char dil) {     vector<string> tokens;     stringstream check1(line);     string intermediate;     while (getline(check1, intermediate, dil)) {       tokens.push_back(intermediate);     }     return tokens;   }   void read(vector<long long>& v) {     for (int i = 0; i < v.size(); i++) cin >> v[i];   }   long long calc(long long curr, long long cuts) {     int p2 = curr % cuts;     int p1 = cuts - p2;     long long w = curr / cuts;     long long val = p1 * w * w + p2 * (w + 1) * (w + 1);     return val;   }   void solve() {     int n, k;     cin >> n >> k;     vector<long long> v(n);     read(v);     priority_queue<pair<long long, pair<long long, long long> > > q;     long long time = 0;     for (int i = 0; i < n; i++) {       long long curr = v[i];       time += curr * curr;       q.push(make_pair(calc(curr, 1) - calc(curr, 2), make_pair(curr, 2)));     }     while (n < k) {       pair<long long, pair<long long, long long> > curr = q.top();       q.pop();       long long dec = curr.first;       long long past = curr.second.second;       long long org = curr.second.first;       q.push(make_pair(calc(org, past) - calc(org, past + 1),                        make_pair(org, past + 1)));       n++;       time -= dec;     }     cout << time << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     while (_--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 1000;   int n;   char s[MAXN + 1];   int solve() {     int ret = n;     for (int i = (0); i < (n); ++i)       if (s[i] ==  1  || s[n - i - 1] ==  1 ) ret = max(ret, 2 * (n - i));     return ret;   }   void run() {     scanf( %d , &n);     scanf( %s , s);     assert(strlen(s) == n);     printf( %d n , solve());   }   int main() {     int ncase;     scanf( %d , &ncase);     for (int i = (1); i <= (ncase); ++i) run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const mod = 1000000007;   long long const md = 998244353;   long long mypow(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   ifstream in( txt.in );   ofstream out( txt.out );   int f[105];   int main() {     cout << fixed << setprecision(12);     cin.tie(0);     ios_base::sync_with_stdio(0);     cout.tie(0);     long long n, x, y;     cin >> n >> x >> y;     for (int i = 1; i <= n; ++i) {       cin >> f[i];     }     sort(f + 1, f + n + 1);     if (x > y) return cout << n, 0;     int u = 0;     for (int i = 1; i <= n; ++i) {       if (x >= f[i]) u = i;     }     cout << (u + 1) / 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long resp, n, m, tt;   int main() {     cin >> n >> m;     if (m % 2 == 0) {       tt = m / 2;       tt = tt * (tt + 1) - tt;     } else {       tt = m / 2;       tt = tt * (tt + 1);     }     for (long long i = 2; i <= n; i += 2) {       resp += tt * (n - i + 1);     }     cout << resp;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   int INF = 1e6;   long long int n, m;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int i, j, t, k, x, y, z, N;     cin >> n;     long long int a[n], b[n], c[n];     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     for (i = 0; i < n; i++) cin >> c[i];     long long int dp[n][2];     memset(dp, 0, sizeof(dp));     ;     dp[n - 1][0] = a[n - 1];     dp[n - 1][1] = b[n - 1];     for (i = n - 2; i >= 0; i--) {       dp[i][0] = max(dp[i + 1][0] + b[i], dp[i + 1][1] + a[i]);       dp[i][1] = max(dp[i + 1][0] + c[i], dp[i + 1][1] + b[i]);     }     cout << dp[0][0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[1000010];   char ch[1000010];   map<int, int> mp, mp1;   vector<int> vec(1000010);   int main() {     int i, j, k, n, m, t, p, cas = 1;     memset(arr, 0, sizeof arr);     vec.clear();     mp.clear();     mp1.clear();     int cnt = 0, l = 0, r = 0;     stack<int> st;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &arr[i]);       mp[arr[i]] = i + 1;     }     getchar();     scanf( %s , &ch);     sort(arr, arr + n);     int len = strlen(ch);     for (i = 0; i < len; i++) {       if (ch[i] ==  0 ) {         cnt++;         st.push(cnt - 1);         vec.push_back(mp[arr[cnt - 1]]);       } else {         int n1 = st.top();         st.pop();         vec.push_back(mp[arr[n1]]);       }     }     for (i = 0; i < vec.size(); i++) {       if (i == 0)         printf( %d , vec[i]);       else         printf(  %d , vec[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, flag = 0;       cin >> n;       vector<int> v(n);       for (int i = 0; i < n; i++) {         cin >> v[i];       }       sort(v.begin(), v.end());       if (v[0] == 0) {         vector<int> v1(n);         for (int k = 1; k < 2000; k++) {           for (int i = 0; i < n; i++) {             v1[i] = (v[i] ^ k);           }           sort(v1.begin(), v1.end());           if (v1 == v) {             cout << k << endl;             flag++;             break;           }         }       } else {         vector<int> v1(n);         for (int k = 1; k < 2000; k++) {           for (int i = 0; i < n; i++) {             v1[i] = (v[i] ^ k);           }           sort(v1.begin(), v1.end());           if (v1 == v) {             cout << k << endl;             flag++;             break;           }         }       }       if (flag == 0) {         cout <<  -1  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m, a, b, count = 0;     ;     cin >> n >> m;     while (cin >> a >> b) {       if (a == 1 || b == 1) {         count++;       }     }     cout << count;   }   signed main() {     long long test = 1;     while (test--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, c = 0;     cin >> n;     bool* V = new bool[n];     bool Back = false;     for (int i = 0; i < n; ++i) {       cin >> V[i];       if (V[i]) {         if (Back && c) c++;         c++;         Back = false;       } else {         Back = true;       }     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pt {     long long x, y;     pt operator-(pt b) const { return {x - b.x, y - b.y}; }     bool operator==(pt b) const { return x == b.x && y == b.y; }     bool operator<(pt b) const {       if (x != b.x) return x < b.x;       return y < b.y;     }   };   long long det(pt a, pt b, pt c) {     return a.x * b.y + b.x * c.y + c.x * a.y - a.y * b.x - b.y * c.x - c.y * a.x;   }   long long sq(long long x) { return x * x; }   long long d2(pt a, pt b) { return sq(a.x - b.x) + sq(a.y - b.y); }   long long sp(pt a, pt b) { return a.x * b.x + a.y * b.y; }   bool kolin(pt a, pt b, pt c) {     if (det(a, b, c) != 0) return false;     return b == a || b == c || sp(a - b, b - c) > 0;   }   long long sgn(long long x) {     if (x < 0)       return -1;     else if (x == 0)       return 0;     else       return 1;   }   bool sek(pt a, pt b, pt c, pt d) {     return sgn(det(a, b, c)) * sgn(det(a, b, d)) == -1 &&            sgn(det(c, d, a)) * sgn(det(c, d, b)) == -1;   }   bool pip(pt b, pt* a, int n) {     long double w = 0;     for (int i = 0; i < n; i++) {       int j = (i + 1) % n;       long double arg = sp(b - a[i], b - a[j]);       arg /= sqrt(d2(b, a[i]));       arg /= sqrt(d2(b, a[j]));       arg = max(arg, (long double)-1);       arg = min(arg, (long double)1);       if (det(b, a[i], a[j]) < 0)         w += acos(arg);       else         w -= acos(arg);     }     return abs(w) > 1.5;   }   long long area(pt* a, int n) {     long long s = 0;     for (int i = 1; i < n - 1; i++) s += det(a[0], a[i], a[i + 1]);     return s;   }   basic_string<pt> hull_half(basic_string<pt> a) {     basic_string<pt> b;     for (pt p : a) {       while (b.size() >= 2 && det(b[b.size() - 2], b[b.size() - 1], p) <= 0)         b.pop_back();       b += p;     }     return b;   }   basic_string<pt> hull(basic_string<pt> a) {     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());     auto p = hull_half(a);     p.pop_back();     reverse(a.begin(), a.end());     auto q = hull_half(a);     q.pop_back();     return p + q;   }   const long long H = 100000;   basic_string<pt> find_pts(long long x, long long y, long long r) {     basic_string<pt> z;     if (x - r >= 0) {       z += {x - r, y};     } else {       long long u = y - abs(x - r);       long long v = y + abs(x - r);       u = max(u, 0ll);       v = min(v, H);       z += pt{0, u};       z += pt{0, v};     }     if (x + r <= H) {       z += {x + r, y};     } else {       long long u = y - abs(x + r - H);       long long v = y + abs(x + r - H);       u = max(u, 0ll);       v = min(v, H);       z += pt{H, u};       z += pt{H, v};     }     if (y - r >= 0) {       z += {x, y - r};     } else {       long long u = x - abs(y - r);       long long v = x + abs(y - r);       u = max(u, 0ll);       v = min(v, H);       z += pt{u, 0};       z += pt{v, 0};     }     if (y + r <= H) {       z += {x, y + r};     } else {       long long u = x - abs(y + r - H);       long long v = x + abs(y + r - H);       u = max(u, 0ll);       v = min(v, H);       z += pt{u, H};       z += pt{v, H};     }     return z;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     long long n;     cin >> n;     basic_string<pt> b;     while (n--) {       long long x, y, v;       cin >> x >> y >> v;       b += find_pts(x, y, v);     }     b = hull(b);     b += b.substr(0, 2);     long double sol = 0;     basic_string<pt> zz;     for (int i = 0; i + 2 < (int)b.size(); i++) {       long double A = sqrt((long double)d2(b[i + 0], b[i + 1]));       long double B = sqrt((long double)d2(b[i + 1], b[i + 2]));       long double C = sqrt((long double)d2(b[i + 2], b[i + 0]));       long double H = abs(det(b[i], b[i + 1], b[i + 2]));       long double R = A * B * C / H;       if (R > sol) {         sol = R;         zz = b.substr(i, 3);       }     }     for (int i = 0; i < 3; i++) cout << zz[i].x <<     << zz[i].y <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o,       p = 0, q = 0, r, s, t, u, v, w, x, y, z, temp = 0, ans = 0, t1, t2, sum = 0;   vector<long long int> v1, v2, v3, v4, v5, v6;   vector<string> vs1, vs2, vs3, vs4;   double f1, f2 = 0, f3, f4;   vector<double> v10;   vector<pair<long long int, long long int>> v11, v12, v13, v14;   string s1, s2, s3, s4, s5, s6;   long long int a10[100][3];   long long int a1[1000000], a2[1000000];   char c1, c2, c3;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (i = 0; i < n; i++) {       p = 0;       cin >> g >> h;       while (g != 0) {         if (g % h == 0) {           g = g / h;           p++;         } else {           p = p + g % h;           g = g - g % h;         }       }       cout << p << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool vis[1000][1000];   bool lab[1000][1000];   vector<int> ans;   int comp[1000][1000];   int cur_ans;   int cur_comp = 0;   int dfs(int x, int y) {     if (!lab[x][y]) {       ++cur_ans;       return 0;     }     if (!vis[x][y]) {       comp[x][y] = cur_comp;       vis[x][y] = true;       dfs(x + 1, y);       dfs(x, y + 1);       dfs(x - 1, y);       dfs(x, y - 1);     }     return 0;   }   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         char c;         cin >> c;         if (c ==  * ) {           lab[i][j] = false;         } else {           lab[i][j] = true;         }       }     }     for (int i = 0; i < k; ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       if (!vis[x][y]) {         cur_ans = 0;         dfs(x, y);         cur_comp++;         ans.push_back(cur_ans);         cout << cur_ans << endl;       } else {         cout << ans[comp[x][y]] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long readLL() {     long long n = 0;     int ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) n = n * 10 + ch -  0 , ch = getchar();     return n;   }   const int MAX_N = 500000 + 3, MAX_LOG_V = 61;   int n;   long long a[MAX_N], b[MAX_LOG_V];   int main() {     n = readLL();     long long v = 0;     for (int i = 0; i < n; ++i) {       a[i] = readLL(), v ^= a[i];       a[i] ^= readLL();     }     int cnt = 0;     for (int i = 0; i < n; ++i)       for (int j = MAX_LOG_V - 1; j >= 0; --j)         if (a[i] >> j & 1) {           if (b[j])             a[i] ^= b[j];           else {             b[j] = a[i];             ++cnt;             break;           }         }     long long nowV = 0;     for (int i = MAX_LOG_V - 1; i >= 0; --i)       if ((v >> i & 1) != (nowV >> i & 1)) nowV ^= b[i];     if (nowV != v)       puts( 1/1 );     else       printf( %lld/%lld , (1LL << cnt) - 1, 1LL << cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, n, k;   string Yes_No,       names[] = { a ,   b ,   c ,   d ,   e ,   f ,   g ,   h ,   i ,   j ,   k ,                   l ,   m ,   n ,   o ,   p ,   q ,   r ,   s ,   t ,   u ,   v ,                   w ,   x ,   y ,   z ,   aa ,  bb ,  cc ,  dd ,  ee ,  ff ,  gg ,                   hh ,  ii ,  jj ,  kk ,  ll ,  mm ,  nn ,  oo ,  pp ,  qq ,  rr ,                   ss ,  tt ,  uu ,  vv ,  ww ,  xx ,  yy ,  zz };   int main() {     for (i = 0; i < 52; i++) names[i] =  A  + names[i];     cin >> n >> k;     for (i = 1; i <= n - k + 1; i++) {       cin >> Yes_No;       if (Yes_No ==  NO ) names[i + k - 1] = names[i];     }     for (i = 1; i <= n; i++) cout << names[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   string gd, str, ask;   int q, n, t, ans, tmp, cnt, ara[1000];   int main() {     cin >> gd >> str >> n;     for (int i = 0; i < gd.size(); i++) ara[gd[i] -  a ] = 1;     while (n--) {       cin >> ask;       int in = -1, fin = -1;       ans = 0;       for (int i = 0; i < max(str.size(), ask.size()); i++) {         if (str[i] ==  ? ) {           if (ara[ask[i] -  a ] != 1) {             ans = 2;             break;           }         } else if (str[i] ==  * ) {           in = i;           break;         } else {           if (str[i] != ask[i]) {             ans = 2;             break;           }         }       }       if (ans == 2) {         printf( NO n );         continue;       } else if (in == -1) {         printf( YES n );         continue;       } else {         for (int i = str.size() - 1, j = ask.size() - 1; i >= 0; i--, j--) {           if (str[i] ==  ? ) {             if (ara[ask[j] -  a ] != 1) {               ans = 2;               break;             }           } else if (str[i] ==  * ) {             fin = j + 1;             break;           } else {             if (str[i] != ask[j]) {               ans = 2;               break;             }           }         }       }       if (ans == 2 || fin == -1 || in > fin) {         printf( NO n );         continue;       } else {         for (int i = in; i < fin; i++) {           if (ara[ask[i] -  a ] == 1) {             ans = 2;             break;           }         }       }       if (ans == 2) {         printf( NO n );       } else         printf( YES n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t1, t2, x1, x2, t0, ans1 = 1000000000, ans2 = 1000000000;   double best = 1e16;   int main() {     cin >> t1 >> t2 >> x1 >> x2 >> t0;     if (t1 == t2 && t1 == t0) {       cout << x1 <<     << x2 <<   n ;       return 0;     }     if (t2 == t0) {       cout <<  0   << x2 <<   n ;       return 0;     }     for (int y1 = 0; y1 <= x1; y1++) {       int temp = y1 * double(t0 - t1) / double(t2 - t0);       for (int y2 = temp - 3; y2 <= temp + 2; y2++) {         if (y1 == 0 && y2 == temp - 3) {           y2 = x2;         }         if (y2 < 0 || y2 > x2) {           continue;         }         double cur =             ((long long)y1 * t1 + (long long)y2 * t2) / (double)(y1 + y2);         if (cur < t0) {           continue;         }         if (cur < best) {           best = cur;           ans1 = y1;           ans2 = y2;         } else if (cur == best) {           if (y1 + y2 > ans1 + ans2) {             ans1 = y1;             ans2 = y2;           }         }       }     }     cout << ans1 <<     << ans2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXR = 1e6 + 1e3;   int n;   vector<int> b, dp, s;   vector<pair<int, int> > v;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     while (cin >> n) {       b = vector<int>(MAXR, 0);       s = vector<int>(MAXR, 0);       dp = vector<int>(MAXR, 0);       for (int i = 0; i < n; ++i) {         int x, y;         cin >> x >> y;         b[x] = y;         s[x] = 1;       }       int ans = 0;       dp[0] = s[0];       for (int i = 1; i <= MAXR; ++i) {         if (b[i])           dp[i] = i - b[i] <= 0 ? 1 : dp[i - b[i] - 1] + 1;         else           dp[i] = dp[i - 1];         ans = max(ans, dp[i]);       }       cout << n - ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, i;     cin >> n;     int la, ra;     int cnt00 = 0, cnt01 = 0, cnt10 = 0, cnt11 = 0;     for (i = 0; i < n; i++) {       cin >> la >> ra;       if (la == 1) {         if (ra == 0)           cnt10++;         else           cnt11++;       } else {         if (ra == 0)           cnt00++;         else           cnt01++;       }     }     int a00 = cnt01 + cnt10 + 2 * cnt11;     int a01 = cnt11 + cnt00 + 2 * cnt10;     int a10 = cnt11 + cnt00 + 2 * cnt01;     int a11 = cnt01 + cnt10 + 2 * cnt00;     cout << min(a00, min(a01, min(a10, a11)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1e9;   const long long LINF = INF * (long long)INF;   const double EPS = 1e-7;   const int MAX = 20 * 1000 + 47;   const int MAS = 2 * 1e5 + 10;   const int MOD = 998244353;   long long haves, haveb, havec;   long long priceb, prices, pricec;   long long money;   long long cntS, cntB, cntC;   bool check(long long cnt) {     long long a1 = max(0LL, (cntS * cnt - haves) * prices);     long long a2 = max(0LL, (cntB * cnt - haveb) * priceb);     long long a3 = max(0LL, (cntC * cnt - havec) * pricec);     return a1 + a2 + a3 <= money;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     cntC = cntB = cntC = 0;     for (int i = (0); i < ((int)s.size()); i++) {       if (s[i] ==  S ) cntS++;       if (s[i] ==  B ) {         cntB++;       }       if (s[i] ==  C ) cntC++;     }     cin >> haveb >> haves >> havec;     cin >> priceb >> prices >> pricec;     cin >> money;     long long l = 0;     long long r = 1e14 + 10;     for (int i = (0); i < (200); i++) {       long long m = (l + r) / 2;       if (check(m)) {         l = m;       } else {         r = m;       }     }     cout << l << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct pii {     char C;     int fi;     int se;   };   char A[1000][1000];   void p(int L) {     cout << L << endl;     for (int i = 1; i <= L; ++i) {       for (int j = 1; j <= L; ++j) {         cout << A[i][j];       }       cout << endl;     }   }   void prin1(pii a, pii b, pii c) {     int L = a.se;     for (int i = 1; i <= L; ++i) {       for (int j = 1; j <= a.fi; ++j) {         A[i][j] = a.C;       }     }     for (int i = 1; i <= L; ++i) {       for (int j = a.fi + 1; j <= a.fi + b.fi; ++j) {         A[i][j] = b.C;       }     }     for (int i = 1; i <= L; ++i) {       for (int j = a.fi + b.fi + 1; j <= L; ++j) {         A[i][j] = c.C;       }     }     p(L);   }   void prin2(pii a, pii b, pii c) {     int L = a.fi;     for (int i = 1; i <= L; ++i) {       for (int j = 1; j <= a.se; ++j) {         A[j][i] = a.C;       }     }     for (int i = 1; i <= L; ++i) {       for (int j = a.se + 1; j <= a.se + b.se; ++j) {         A[j][i] = b.C;       }     }     for (int i = 1; i <= L; ++i) {       for (int j = a.se + b.se + 1; j <= L; ++j) {         A[j][i] = c.C;       }     }     p(L);   }   void prin3(pii a, pii b, pii c) {     int L = c.se;     for (int i = 1; i <= a.fi; ++i) {       for (int j = 1; j <= a.se; ++j) {         A[i][j] = a.C;       }     }     for (int i = 1; i <= b.fi; ++i) {       for (int j = a.se + 1; j <= L; ++j) {         A[i][j] = b.C;       }     }     for (int i = a.fi + 1; i <= L; ++i) {       for (int j = 1; j <= L; ++j) {         A[i][j] = c.C;       }     }     p(L);   }   void prin4(pii a, pii b, pii c) {     int L = a.fi;     for (int i = 1; i <= b.fi; ++i) {       for (int j = a.se + 1; j <= L; ++j) {         A[i][j] = b.C;       }     }     for (int i = b.fi + 1; i <= L; ++i) {       for (int j = a.se + 1; j <= L; ++j) {         A[i][j] = c.C;       }     }     for (int i = 1; i <= L; ++i) {       for (int j = 1; j <= a.se; ++j) {         A[i][j] = a.C;       }     }     p(L);   }   bool check(pii a, pii b, pii c) {     if (a.fi + b.fi + c.fi == a.se and a.se == b.se and b.se == c.se) {       prin1(a, b, c);       return 1;     }     if (a.fi == b.fi and b.fi == c.fi and a.fi == a.se + b.se + c.se) {       prin2(a, b, c);       return 1;     }     if (a.fi == b.fi + c.fi and a.fi == a.se + b.se and b.se == c.se) {       prin4(a, b, c);       return 1;     }     if (a.se + b.se == c.se and c.se == a.fi + c.fi and a.fi == b.fi) {       prin3(a, b, c);       return 1;     }     return 0;   }   int main() {     vector<pii> temp;     pii a, b, c;     cin >> a.fi >> a.se;     cin >> b.fi >> b.se;     cin >> c.fi >> c.se;     a.C =  A ;     b.C =  B ;     c.C =  C ;     vector<int> g;     g.push_back(0);     g.push_back(1);     g.push_back(2);     for (int mask = 0; mask < 8; ++mask) {       if (mask & (1 << 0)) swap(a.fi, a.se);       if (mask & (1 << 1)) swap(b.fi, b.se);       if (mask & (1 << 2)) swap(c.fi, c.se);       temp.clear();       sort(g.begin(), g.end());       temp.push_back(a);       temp.push_back(b);       temp.push_back(c);       do {         if (check(temp[g[0]], temp[g[1]], temp[g[2]])) return 0;       } while (next_permutation(g.begin(), g.end()));       if (mask & (1 << 0)) swap(a.fi, a.se);       if (mask & (1 << 1)) swap(b.fi, b.se);       if (mask & (1 << 2)) swap(c.fi, c.se);     }     cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   int hc(int a, int b) {     if (b == 0) return a;     return hc(b, a % b);   }   int main() {     int n, a[10010], i, sum = 0;     cin >> n;     int k = n;     for (i = 2; i < n; i++) {       a[i] = i;     }     for (i = 2; i < n; i++) {       while (n != 0) {         sum = sum + n % a[i];         n = n / a[i];       }       n = k;     }     int q = k - 2;     int h = hc(sum, k - 2), b;     sum = sum / h;     b = q / h;     cout << sum <<  /  << b << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( -O3 )   using namespace std;   void _main();   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     _main();   }   template <typename T>   int gaussianElimination(vector<vector<T>> &A, int var = -1) {     int N = A.size(), M = A[0].size();     if (var < 0) var = min(N, M);     int k = 0, rank = var;     for (int i = 0; i < var; i++) {       int v = -1;       for (int j = k; j < N && v == -1; j++)         if (A[j][i] != 0) v = j;       if (v == -1) {         rank--;         continue;       }       swap(A[k], A[v]);       T x = A[k][i];       for (int j = 0; j < M; j++) A[k][j] = A[k][j] / x;       for (int j = 0; j < N; j++)         if (j != k) {           T y = A[j][i];           for (int h = M - 1; h >= i; h--) A[j][h] = A[j][h] - A[k][h] * y;         }       k++;     }     return rank;   }   template <typename T>   void print(vector<vector<T>> &A) {     int N = A.size(), M = A[0].size();     for (int y = 0; y < N; y++) {       for (int x = 0; x < M; x++) cout << A[y][x] <<   t ;       cout << endl;     }     cout << endl;   }   template <int MOD>   struct ModInt {     static const int Mod = MOD;     unsigned x;     ModInt() : x(0) {}     ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }     ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }     int get() const { return (int)x; }     ModInt &operator+=(ModInt that) {       if ((x += that.x) >= MOD) x -= MOD;       return *this;     }     ModInt &operator-=(ModInt that) {       if ((x += MOD - that.x) >= MOD) x -= MOD;       return *this;     }     ModInt &operator*=(ModInt that) {       x = (unsigned long long)x * that.x % MOD;       return *this;     }     ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }     ModInt operator+(ModInt that) const { return ModInt(*this) += that; }     ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }     ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }     ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }     ModInt inverse() const {       long long a = x, b = MOD, u = 1, v = 0;       while (b) {         long long t = a / b;         a -= t * b;         std::swap(a, b);         u -= t * v;         std::swap(u, v);       }       return ModInt(u);     }     bool operator==(ModInt that) const { return x == that.x; }     bool operator!=(ModInt that) const { return x != that.x; }     ModInt operator-() const {       ModInt t;       t.x = x == 0 ? 0 : Mod - x;       return t;     }   };   template <int MOD>   ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {     ModInt<MOD> r = 1;     while (k) {       if (k & 1) r *= a;       a *= a;       k >>= 1;     }     return r;   }   template <int MOD>   std::ostream &operator<<(std::ostream &stream, const ModInt<MOD> a) {     stream << a.get();     return stream;   };   int N, M, Q;   string S[505], B[303];   void _main() {     cin >> N >> M;     for (int i = 0; i < N; i++) cin >> S[i];     cin >> Q;     for (int i = 0; i < Q; i++) cin >> B[i];     vector<vector<ModInt<5>>> A(M, vector<ModInt<5>>(N + Q));     for (int i = 0; i < N; i++)       for (int j = 0; j < M; j++) A[j][i] = S[i][j] -  a ;     for (int i = 0; i < Q; i++)       for (int j = 0; j < M; j++) A[j][i + N] = B[i][j] -  a ;     int rank = gaussianElimination(A, N);     ModInt<1000000007> ans = 1;     for (int i = 0; i < N - rank; i++) ans *= 5;     vector<int> zero;     for (int i = 0; i < M; i++) {       int ok = 1;       for (int j = 0; j < N; j++)         if (A[i][j] == 1) ok = 0;       if (ok) zero.push_back(i);     }     for (int i = 0; i < Q; i++) {       int ok = 1;       for (auto &j : zero)         if (A[j][N + i] != 0) ok = 0;       if (ok)         printf( %d n , ans.get());       else         printf( 0 n );     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   template <typename T>   void debug(vector<T> x) {     for (auto e : x) {       cout << e <<    ;     }     cout <<   n ;   }   void solve() {     long long n;     cin >> n;     long long x = n / 4;     long long y = n % 4;     if (y % 4 == 0) {       for (long long i = 0; i < n - x; i++) {         cout <<  9 ;       }       for (long long i = 0; i < x; i++) {         cout <<  8 ;       }       cout <<   n ;       return;       ;     } else {       for (long long i = 0; i < n - (x + 1); i++) {         cout <<  9 ;       }       for (long long i = 0; i < x + 1; i++) {         cout <<  8 ;       }       cout <<   n ;       return;       ;     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, cur;   int fa[1005];   set<int> s1, s2;   struct edge {     int from, to;     char color[2];   } e[100005];   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   void init() {     for (int i = 1; i <= n; i++) {       fa[i] = i;     }     cur = n;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> e[i].from >> e[i].to >> e[i].color;     }     if (n % 2 == 0) {       cout << -1 << endl;       return 0;     }     init();     for (int i = 1; i <= m; i++) {       if (e[i].color[0] ==  S ) {         int fx = find(e[i].from);         int fy = find(e[i].to);         if (fx != fy) {           fa[fx] = fy;           cur--;         }       }     }     if (cur - 1 > (n - 1) / 2) {       cout << -1 << endl;       return 0;     }     for (int i = 1; i <= m; i++) {       if (e[i].color[0] ==  M ) {         int fx = find(e[i].from);         int fy = find(e[i].to);         if (fx != fy) {           fa[fx] = fy;           cur--;           s2.insert(i);         }       }     }     if (cur != 1) {       cout << -1 << endl;       return 0;     }     init();     for (auto i : s2) {       int fx = find(e[i].from);       int fy = find(e[i].to);       if (fx != fy) {         fa[fx] = fy;         cur--;       }     }     for (int i = 1; i <= m; i++) {       if (s2.size() == (n - 1) / 2) break;       if (e[i].color[0] ==  M ) {         int fx = find(e[i].from);         int fy = find(e[i].to);         if (fx != fy) {           fa[fx] = fy;           cur--;           s2.insert(i);         }       }     }     if (s2.size() != (n - 1) / 2) {       cout << -1 << endl;       return 0;     }     for (int i = 1; i <= m; i++) {       if (e[i].color[0] ==  S ) {         int fx = find(e[i].from);         int fy = find(e[i].to);         if (fx != fy) {           fa[fx] = fy;           cur--;           s1.insert(i);         }       }     }     cout << n - 1 << endl;     for (auto i : s1) cout << i <<    ;     for (auto i : s2) cout << i <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   namespace FastIO {   const int SIZE = (1 << 21) + 1;   char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,                                          qu[55];   int qr;   inline void flush() {     fwrite(obuf, 1, oS - obuf, stdout);     oS = obuf;   }   inline void putc(char x) {     *oS++ = x;     if (oS == oT) flush();   }   inline void wrap() {     *oS++ =   n ;     if (oS == oT) flush();   }   template <class I>   inline void gi(I &x) {     I sign = 1;     for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++);          c <  0  || c >  9 ;          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       if (c ==  - ) sign = -1;     for (x = 0; c <=  9  && c >=  0 ;          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       x = x * 10 + (c & 15);     x *= sign;   }   inline int gi() {     int x, sign = 1;     for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++);          c <  0  || c >  9 ;          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       if (c ==  - ) sign = -1;     for (x = 0; c <=  9  && c >=  0 ;          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       x = x * 10 + (c & 15);     return x * sign;   }   inline long long gl() {     long long x, sign = 1;     for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++);          c <  0  || c >  9 ;          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       if (c ==  - ) sign = -1;     for (x = 0; c <=  9  && c >=  0 ;          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       x = x * 10 + (c & 15);     return x * sign;   }   template <class I>   inline void print(I &x) {     if (!x) putc( 0 );     while (x) qu[++qr] = x % 10 +  0 , x /= 10;     while (qr) putc(qu[qr--]);   }   template <class I>   inline void println(I &x) {     if (!x) putc( 0 );     while (x) qu[++qr] = x % 10 +  0 , x /= 10;     while (qr) putc(qu[qr--]);     wrap();   }   }  // namespace FastIO   using namespace std;   int n;   struct Rectangle {     int l, r, d, u;   } rec[1000 + 5];   bool solve(vector<Rectangle> v) {     if (v.size() <= 1) return 1;     int maxr = 0, maxu = 0;     bool flag = 0;     vector<Rectangle> pre, suf;     sort(v.begin(), v.end(),          [](const Rectangle &a, const Rectangle &b) { return a.l < b.l; });     for (int i = v.size() - 1; ~i; --i) suf.push_back(v[i]);     for (int i = 0; i < v.size() - 1; ++i) {       pre.push_back(v[i]), suf.pop_back();       maxr = max(maxr, v[i].r);       if (maxr <= v[i + 1].l && solve(pre) && solve(suf)) {         flag = 1;         break;       }     }     if (flag) return true;     sort(v.begin(), v.end(),          [](const Rectangle &a, const Rectangle &b) { return a.d < b.d; });     pre.clear();     suf.clear();     for (int i = v.size() - 1; ~i; --i) suf.push_back(v[i]);     for (int i = 0; i < v.size() - 1; ++i) {       pre.push_back(v[i]), suf.pop_back();       maxu = max(maxu, v[i].u);       if (maxu <= v[i + 1].d && solve(pre) && solve(suf)) {         flag = 1;         break;       }     }     if (flag) return true;     return false;   }   int main() {     scanf( %d , &n);     vector<Rectangle> v;     for (int i = 1, a, b, c, d; i <= n; ++i) {       scanf( %d%d%d%d , &a, &b, &c, &d);       rec[i] = {a, c, b, d};       v.push_back(rec[i]);     }     if (solve(v))       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const long long MOD = 998244353ll;   enum RESULT { OK, WIN };   int n, v[N], nxt[N], prv[N];   long long dp[N][2], acc[N], inv[N];   long long expr(long long e, long long n) {     if (n == 0) return 1ll;     long long tp = expr(e, n / 2ll);     tp = (tp * tp) % MOD;     if (n % 2ll) tp = (tp * e) % MOD;     return tp;   }   void ok(int t, int p) {     int h = prv[p - 1];     dp[p][OK] = (acc[h] * inv[n - t + 1]) % MOD;   }   void win(int t, int p) {     int r = nxt[p - 1];     int l = prv[p - 1];     dp[p][WIN] =         (((acc[r] - acc[l] - dp[p][OK] + 2ll * MOD) % MOD) * inv[n - t + 1]) %         MOD;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &v[i - 1]);       dp[i][OK] = expr(n, MOD - 2) % MOD;       acc[i] = (acc[i - 1] + dp[i][OK]) % MOD;     }     sort(v, v + n);     long long resp = 0ll;     for (int t = 1; t <= n; t++) inv[t] = expr(t, MOD - 2);     for (int i = 0; i < n; i++) {       prv[i] = lower_bound(v, v + n, v[i]) - v;       nxt[i] = upper_bound(v, v + n, v[i]) - v;     }     for (int t = 2; t <= n; t++) {       for (int p = 1; p <= n; p++) {         win(t, p);         ok(t, p);         resp = (resp + dp[p][WIN]) % MOD;       }       for (int p = 1; p <= n; p++) acc[p] = (acc[p - 1] + dp[p][OK]) % MOD;     }     printf( %lld n , resp);   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m, i, j;     cin >> n >> m;     int x, y;     vector<vector<int> > adj(n);     vector<int> ncon(n, 0);     for (i = (0); i < (m); i++) {       cin >> x >> y;       adj[x - 1].push_back(y - 1);       adj[y - 1].push_back(x - 1);       ncon[x - 1]++;       ncon[y - 1]++;     }     vector<int> onecon;     for (i = (0); i < (n); i++)       if (ncon[i] == 1) onecon.push_back(i);     int maxd = 0;     queue<int> q;     vector<int> dist(n, 0), rem(n, 0);     for (auto i : onecon) {       q.push(i);       dist[i] = 1;     }     if ((int)((onecon).size()) != 0) maxd = 1;     while (!q.empty()) {       int cur = q.front();       q.pop();       rem[cur] = 1;       if (ncon[cur] == 1) maxd = max(maxd, dist[cur]);       for (auto next : adj[cur]) {         if (rem[next] == 1) continue;         ncon[next]--;         if (ncon[next] == 1) {           dist[next] = dist[cur] + 1;           q.push(next);         }       }     }     cout << maxd <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   const int M = 1e4 + 5;   int n, m, w, vis[N], l[N], r[N];   long long a[N], ans[N], s;   int main() {     cin >> n >> s;     long long sum = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     if (sum < s) {       cout << -1 << endl;       return 0;     } else if (sum == s) {       cout << 0 << endl;       return 0;     }     sort(a + 1, a + 1 + n);     int now = 1;     sum = s;     while (a[now] == a[1]) {       now++;     }     for (int i = n; i >= now; i--) {       sum -= (a[i] - a[1]);     }     if (sum) {       int cnt = 0;       while (sum > 0) {         sum -= n;         cnt++;       }       cout << a[1] - cnt << endl;     } else {       cout << a[1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int S, C, Ha, Hb, Wa, Wb;   long long Ans;   int main() {     scanf( %d%d%d%d%d , &C, &Ha, &Hb, &Wa, &Wb);     S = sqrt(C);     if (Wa > Wb) swap(Ha, Hb), swap(Wa, Wb);     if (Wb > S)       for (int i = 0; 1LL * i * Wb <= C; i++)         Ans = max(Ans, 1LL * i * Hb + 1LL * (C - i * Wb) / Wa * Ha);     else {       if (1LL * Ha * Wb > 1LL * Hb * Wa) swap(Ha, Hb), swap(Wa, Wb);       for (int i = 0; i < Wb; i++)         Ans = max(Ans, 1LL * i * Ha + 1LL * (C - i * Wa) / Wb * Hb);     }     printf( %I64d n , Ans);   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char a[109][109], b[109][109];   void add(int x, int y) {     if (a[x][y] ==  * ) return;     if (b[x][y] ==   0 )       b[x][y] =  1 ;     else       ++b[x][y];   }   void fill(int x, int y) {     if (x > 0 && y > 0) add(x - 1, y - 1);     if (x > 0) {       add(x - 1, y);       add(x - 1, y + 1);     }     if (y > 0) {       add(x, y - 1);       add(x + 1, y - 1);     }     add(x, y + 1);     add(x + 1, y);     add(x + 1, y + 1);   }   bool check() {     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if ((a[i][j] >=  1  && a[i][j] <=  8 ) ||             (b[i][j] >=  1  && b[i][j] <=  8 )) {           if (a[i][j] != b[i][j]) {             return false;           }         }       }     }     return true;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       scanf( %s , a[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  * ) {           fill(i, j);         }       }     }     if (check())       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ui32 = unsigned int;   using i64 = long long;   using f64 = long double;   using ui64 = unsigned long long;   void read(int& x) { scanf( %d , &x); }   void read(int n, vector<int>& a) {     for (int i = 0; i < n; i++) read(a[i]);   }   void read(int n, int* a) {     for (int i = 0; i < n; i++) read(a[i]);   }   void write(int x) { printf( %d n , x); }   void print(int x) { printf( %d  , x); }   void write(int n, vector<int> a) {     for (int i = 0; i < n; i++) printf( %d n , a[i]);   }   void print(int n, int* a) {     for (int i = 0; i < n; i++) printf( %d  , a[i]);   }   void print(string s) { printf( %s n , s.c_str()); }   i64 z[3 * 100007], lcp[3 * 100007], cnt[3 * 100007];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s, t;     cin >> s >> t;     string concate = t +  #  + s;     i64 n = (i64)(concate.size()), m = (i64)(t.size());     i64 l = 0;     i64 r = 0;     for (i64 i = 0; i < n; i++) {       if (i > r) {         l = i;         r = i;         while (r < n && concate[r - l] == concate[r]) {           r++;         }         z[i] = r - l;         r--;       } else {         i64 k = i - l;         if (z[k] < r - i + 1)           z[i] = z[k];         else {           l = i;           while (r < n && concate[r - l] == concate[r]) {             r++;           }           z[i] = r - l;           r--;         }       }     }     n = (i64)(s.size());     for (i64 i = m + 2; i < n + m + 1; i++) {       cnt[z[i]]++;     }     for (i64 i = m; i > 0; i--) {       cnt[i - 1] += cnt[i];     }     l = 0;     r = 1;     while (r != m) {       if (t[l] == t[r]) {         l++;         lcp[r] = l;         r++;       } else {         if (l == 0) {           lcp[r] = 0;           r++;         } else {           l = lcp[l - 1];         }       }     }     i64 ans = n * m;     for (i64 i = 0; i < m; i++) {       if (lcp[i] != 0) {         ans -= cnt[i + 1 - lcp[i]];       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int isprime(int n) {     int i;     for (i = 2; i * i <= n; i++) {       if (n % i == 0) return 0;     }     return 1;   }   int main() {     long long int n, k = 0, i = 0, m, x = 0, y, q, r, s, l, t, a, v0, v1, c, b,                      j = 0, d = 0, ct = 0, sum = 0, h[1000009] = {0},                      temp = 10000, fl = 0;     cin >> c >> v0 >> v1 >> a >> l;     for (i = 0;; i++) {       if ((v0 + a * i) <= v1)         c = c - (v0 + a * i);       else         c -= v1;       if (c <= 0) break;       c += l;     }     cout << i + 1;   }


#include <bits/stdc++.h>   using namespace std;   void GO() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   const long long INF = 1e9;   const long long mod = (1e9) + 7;   const int maxn = (int)100;   const long double PI = acos(-1.0);   const long double eps = 0.000000001;   mt19937 rnd(time(0));   long long step[19];   long long lower(long long a_0, long long d, long long k) {     long long l = 0, r = INF;     while (r - l > 1) {       long long m = r + l >> 1;       long long a_m = a_0 + d * (m - 1);       long long sum = (a_0 + a_m) * m / 2;       (sum >= k ? r : l) = m;     }     return l;   }   void solve1(long long k) {     for (long long i = 1; i < 19; ++i) {       long long plus = i * (step[i] - step[i - 1]);       if (plus == k) {         cout <<  9 n ;         return;       }       if (k > plus) {         k -= plus;         continue;       }       long long x = (k + i - 1) / i;       k %= i;       long long num = step[i - 1] + x - 1;       string ans = to_string(num);       if (!k) k = i;       cout << ans[k - 1] <<   n ;       return;     }   }   void solve() {     long long k;     cin >> k;     long long a_0 = 1;     for (long long i = 1; i < 19; ++i) {       long long n = step[i] - step[i - 1];       long long a_n = a_0 + i * (n - 1);       long long sum = (a_0 + a_n) * n / 2ll;       if (k == sum) {         cout <<  9 n ;         return;       }       if (k > sum) {         k -= sum;         a_0 = a_n + i + 1;         continue;       }       long long x = lower(a_0, i, k);       long long a_x = a_0 + i * (x - 1);       k -= (a_0 + a_x) * x / 2;       solve1(k);       return;     }   }   signed main() {     GO();     step[0] = 1;     for (int i = 1; i < 19; ++i) step[i] = step[i - 1] * 10ll;     int Q = 1;     cin >> Q;     while (Q--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   int n, nn, m;   int a[N], b[N], c[N];   int f[N];   inline void add(int i, int v) {     for (; i <= n; i += i & -i) f[i] += v;   }   inline int find(int v) {     int i = 0;     for (int k = 20; k >= 0; k--) {       if (i + (1 << k) <= n && f[i + (1 << k)] < v) {         i += 1 << k;         v -= f[i];       }     }     return i + 1;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++) {       scanf( %d , c + i);       if (c[i] != -1) b[++nn] = c[i];     }     for (int i = 1; i <= nn; i++) add(i, 1);     nn = 0;     for (int i = 1; i <= n; i++) {       if (c[i] != -1)         nn++;       else {         int k;         for (k = 1; k <= m && a[k] <= nn; k++) add(find(a[k] - k + 1), -1);         nn -= k - 1;       }     }     if (nn == 0) {       printf( Poor stack! n );       return 0;     }     for (int i = 1; i <= nn; i++) printf( %d , b[find(i)]);   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int m;     cin >> m;     int C[m];     for (int i = 0; i < m; ++i) cin >> C[i];     int x, y;     cin >> x >> y;     int sum_1, sum_2;     sum_1 = sum_2 = 0;     int now = 0;     for (int i = 0; i < m; ++i) sum_2 += C[i];     while (sum_1 < x || sum_1 > y || sum_2 < x || sum_2 > y) {       if (now == m) break;       sum_1 += C[now];       sum_2 -= C[now];       ++now;     }     if (now == m)       cout << 0;     else       cout << now + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mxN = 52;   vector<long long> adj[mxN];   signed main() {     long long n;     cin >> n;     long long x = (n * (n - 1)) / 2;     long long a[x - 1][2];     for (long long i = 0; i < x - 1; i++) {       cin >> a[i][0] >> a[i][1];       adj[a[i][0]].push_back(a[i][1]);       adj[a[i][1]].push_back(a[i][0]);     }     long long ans1 = -1, ans2 = -1;     for (long long i = 1; i <= n; i++) {       if (ans1 == -1 && adj[i].size() < n - 1) {         ans1 = i;       } else if (ans2 == -1 && adj[i].size() < n - 1) {         ans2 = i;       }     }     for (long long i = 1; i <= n; i++) {       if (i == ans1 || i == ans2) {         continue;       } else {         long long w1 = -1, w2 = -1;         for (long long j = 0; j < x - 1; j++) {           if (a[j][0] == ans1 && a[j][1] == i) {             w1 = ans1;           } else if (a[j][0] == i && a[j][1] == ans1) {             w1 = i;           } else if (a[j][0] == ans2 && a[j][1] == i) {             w2 = ans2;           } else if (a[j][0] == i && a[j][1] == ans2) {             w2 = i;           }         }         if (w1 == ans1 && w2 != ans2) {           cout << ans1 <<     << ans2 << endl;           return 0;         } else if (w2 == ans2 && w1 != ans1) {           cout << ans2 <<     << ans1 << endl;           return 0;         }       }     }     cout << ans1 <<     << ans2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   int n;   int dp[maxn][256], a[maxn], cur[8];   vector<int> pos[maxn];   int ok(int len) {     int ans = -1;     memset(dp, -1, sizeof(dp));     memset(cur, 0, sizeof(cur));     dp[0][0] = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 256; j++) {         if (dp[i][j] == -1) continue;         for (int k = 0; k < 8; k++) {           if (j & (1 << k)) continue;           int p = cur[k] + len - 1;           if (pos[k].size() <= p) continue;           dp[pos[k][p] + 1][j | 1 << k] =               max(dp[pos[k][p]][j | 1 << k], dp[i][j]);           if (pos[k].size() <= p + 1) continue;           dp[pos[k][p + 1] + 1][j | 1 << k] =               max(dp[pos[k][p + 1] + 1][j | 1 << k], dp[i][j] + 1);         }       }       cur[a[i]]++;     }     for (int i = 0; i < n + 1; i++) ans = max(ans, dp[i][255]);     if (ans == -1) return ans;     return ans * (len + 1) + (8 - ans) * len;   }   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return f * x;   }   int main() {     n = read();     for (int i = 0; i < n; i++) a[i] = read() - 1;     for (int i = 0; i < n; i++) pos[a[i]].push_back(i);     int l = 1, r = n / 8;     while (r - l > 1) {       int mid = (l + r) >> 1;       if (ok(mid) != -1)         l = mid;       else         r = mid;     }     int ans = max(ok(l), ok(r));     if (ans == -1) {       ans = 0;       for (int i = 0; i < 8; i++)         if (pos[i].size()) ans++;     }     printf( %d n , ans);     return 0;   }


#pragma GCC optimize( O3 , Ofast , unroll-loops , omit-frame-pointer , inline ) //Optimization flags   #pragma GCC option( arch=native , tune=native , no-zero-upper ) //Enable AVX   // #pragma GCC target( avx2 ) //Enable AVX      #include <bits/stdc++.h>      #define int long long      using namespace std;      #ifdef LOCAL    #include  /media/brayand/BrayanD/debugger.h    #else   #define db(...) false   #define dbl(...) false   #define dbg(...) false   #define dbm(...) false   #define dbs(...) false   #define dbas(...) false   #endif      const int oo = 1e18;      const int MAXN = 4e4+100;      int ST[MAXN*4];   int lazy[MAXN*4];      int dp[MAXN][120];      void prop(int nodo)   {    if(lazy[nodo] != 0)    {     ST[nodo] += lazy[nodo];     if(nodo*2 < MAXN*4)     {      lazy[nodo*2] += lazy[nodo];     }     if(nodo*2+1 < MAXN*4)     {      lazy[nodo*2+1] += lazy[nodo];     }     lazy[nodo] = 0;    }   }      void build(int nodo, int l, int r, int k)   {    lazy[nodo] = 0;    if(l == r)    {     ST[nodo] = dp[l][k];     return;    }    int mid = (l+r)/2;    build(nodo*2,l,mid,k);    build(nodo*2+1,mid+1,r,k);    ST[nodo] = max(ST[nodo*2], ST[nodo*2+1]);   }      void update(int nodo, int l, int r, int a, int b, int x)   {    prop(nodo);    if(r < a || l > b)return;    if(a <= l && r <= b)    {     lazy[nodo] += x;     prop(nodo);     return;    }    int mid = (l+r)/2;    update(nodo*2,l,mid,a,b,x);    update(nodo*2+1,mid+1,r,a,b,x);    ST[nodo] = max(ST[nodo*2], ST[nodo*2+1]);   }      int query(int nodo, int l, int r, int a, int b)   {    prop(nodo);    if(r < a || l > b)return -oo;    if(a <= l && r <= b)    {     return ST[nodo];    }    int mid = (l+r)/2;    return max(query(nodo*2,l,mid,a,b), query(nodo*2+1,mid+1,r,a,b));   }      int A[MAXN];      vector<int> arr[MAXN];      int T[MAXN];      vector<int> ins[MAXN];   vector<int> del[MAXN];      int32_t main()   {       ios_base::sync_with_stdio(0);       cin.tie(0);          int N, K;       cin >> N >> K;       K--;          for(int i = 1 ; i <= N ; i++)       {        cin >> A[i];        arr[A[i]].push_back(i);       }          if(N == 1)       {        cout << 0 <<   n ;        return 0;       }          vector<pair<int,int>> vect;          int sum = 0;          for(int i = 1 ; i <= N ; i++)       {        for(int j = 1 ; j < arr[i].size() ; j++)        {         vect.push_back({arr[i][j-1],arr[i][j]-1});        }        if(arr[i].size())        {         sum += arr[i].back()-arr[i][0];        }       }          for(auto x : vect)       {        int d = x.second-x.first+1;        T[x.first] += d;        T[x.second+1] -= d;       }          for(int i = 1 ; i <= N ; i++)       {        T[i] += T[i-1];       }          for(int i = 0 ; i < MAXN ; i++)       {        for(int j = 0 ; j < 120 ; j++)        {         dp[i][j] = -oo;        }       }          for(int i = 1 ; i < N ; i++)       {        dp[i][0] = 0;        dp[i][1] = T[i];       }          for(int i = 0 ; i < vect.size() ; i++)       {        ins[vect[i].first].push_back(i);        del[vect[i].second+1].push_back(i);       }          for(int j = 2 ; j <= K ; j++)       {         build(1,1,N-1,j-1);           for(int i = 1 ; i < N ; i++)        {         for(auto x : ins[i])         {          int v = vect[x].second-vect[x].first+1;          update(1,1,N-1,vect[x].first, vect[x].second, -v);         }         for(auto x : del[i])         {          int v = vect[x].second-vect[x].first+1;          update(1,1,N-1,vect[x].first, vect[x].second, v);         }         if(i >= j)dp[i][j] = query(1,1,N-1,1,i-1) + T[i];        }       }          int res = 0;          for(int i = 1 ; i < N ; i++)       {        res = max(res, dp[i][K]);       }          cout << sum - res <<   n ;          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int a[n];     vector<int> c;     for (int i = 0; i < n; i++) a[i] = 0;     for (int i = 0; i < n; i++) {       int k;       cin >> k;       c.push_back(k);       a[k - 1] += 1;     }     queue<int> q;     int ans = 0;     for (int i = 0; i < n; i++) {       if (a[i] == 0) {         q.push(i + 1);         ans++;       }     }     bool done[n];     for (int i = 0; i < n; i++) done[i] = 0;     for (int i = 0; i < n; i++) {       if (q.empty()) break;       if (done[c[i] - 1] == 1) {         a[c[i] - 1]--;         c[i] = q.front();         q.pop();       } else {         if (a[c[i] - 1] == 1) {           done[c[i] - 1] = 1;           a[c[i] - 1]--;         } else if (q.front() > c[i]) {           done[c[i] - 1] = 1;           a[c[i] - 1]--;         } else {           a[c[i] - 1]--;           c[i] = q.front();           q.pop();         }       }     }     cout << ans << endl;     for (int i = 0; i < n; i++) cout << c[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, a, b, c, d;   long long divide(long long x, long long y) { return (x + y - 1) / y; }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> a >> b >> c >> d;       if (b >= a)         cout << b <<   n ;       else if (d >= c)         cout <<  -1 n ;       else         cout << divide(a - b, c - d) * c + b <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = ~0ULL >> 1;   const int maxV = 3e5 + 10;   const int maxE = 6e5 + 10;   struct EDGE {     int v, nxt;     long long w;     EDGE() {}     EDGE(int vv, int xx, long long ww) { v = vv, nxt = xx, w = ww; }   };   EDGE edg[maxE];   int EH[maxV], etot;   void initG() {     memset(EH, -1, sizeof(EH));     etot = 0;   }   void addEdge(int u, int v, long long w) {     edg[etot] = EDGE(v, EH[u], w);     EH[u] = etot++;   }   int n, m;   short an[maxE];   long long dist[maxV];   short vs[maxV];   struct Node {     int src, id;     long long dst;     Node() {}     Node(int ss, long long dd, int ii) { src = ss, dst = dd, id = ii; }     bool operator<(const Node &rhs) const {       return (rhs.dst < dst) || (dst == rhs.dst && edg[rhs.id].w < edg[id].w);     }   };   void spfa(int s) {     for (int i = 1; i <= n; i++) dist[i] = inf;     memset(vs, 0, sizeof(vs));     memset(an, 0, sizeof(an));     priority_queue<Node> que;     dist[s] = 0;     que.push(Node(s, dist[s], -1));     long long rs = 0;     while (!que.empty()) {       Node now = que.top();       que.pop();       int u = now.src;       int id = now.id;       if (vs[u]) continue;       vs[u] = 1;       if (id != -1) {         rs += edg[id].w;         an[id] = 1;       }       for (int p = EH[u]; ~p; p = edg[p].nxt) {         int v = edg[p].v;         long long w = edg[p].w;         if (dist[v] >= dist[u] + w) {           dist[v] = dist[u] + w;           que.push(Node(v, dist[v], p));         }       }     }     cout << rs << endl;     m <<= 1;     for (int i = 0; i < m; i++)       if (an[i]) cout << (i / 2 + 1) <<    ;     cout << endl;   }   int main() {     int u, v, p;     long long w;     while (~scanf( %d%d , &n, &m)) {       initG();       for (int i = 1; i <= m; i++) {         scanf( %d%d%I64d , &u, &v, &w);         addEdge(u, v, w);         addEdge(v, u, w);       }       scanf( %d , &p);       spfa(p);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 58, SQ = 500;   int LE[maxn], LO[maxn], par[maxn], a[maxn], root[maxn], lazy[maxn], m;   inline void make(int j) {     int lase = -1, laso = -1;     int l = j * SQ;     for (int i = l; i - l < SQ; i++) {       a[i] ^= lazy[j];       if (a[i])         laso = i;       else         lase = i;       LE[i] = lase;       LO[i] = laso;       if (i - l >= m + 1) {         if (a[i])           par[i] = LO[i - (m + 1)];         else           par[i] = LE[i - (m + 1)];       } else         par[i] = -1;       if (par[i] == -1)         root[i] = i;       else         root[i] = root[par[i]];     }     lazy[j] = 0;   }   inline int getlast(int r) {     while ((lazy[r / SQ] && (LE[r] == -1 || LE[r] / SQ != r / SQ)) ||            (!lazy[r / SQ] && (LO[r] == -1 || LO[r] / SQ != r / SQ))) {       r = r / SQ * SQ - 1;     }     if (lazy[r / SQ]) return LE[r];     return LO[r];   }   inline bool P(int r, int l) {     while (r / SQ > l / SQ) {       r = root[r];       r = getlast(r - m - 1);     }     while (r > l) {       r = par[r];     }     return r == l;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, q;     cin >> n >> m >> q;     int lase = -1, laso = -1;     for (int i = 0; i < n; i++) {       long long b;       cin >> b;       b &= 1;       a[i] = b;       if (b)         laso = i;       else         lase = i;       LE[i] = lase;       LO[i] = laso;       if (i % SQ >= m + 1) {         if (b)           par[i] = LO[i - (m + 1)];         else           par[i] = LE[i - (m + 1)];         if (par[i] == -1 || par[i] / SQ < i / SQ) par[i] = -1;       } else         par[i] = -1;       if (par[i] == -1)         root[i] = i;       else         root[i] = root[par[i]];     }     while (q--) {       int t;       cin >> t;       if (t == 1) {         int l, r;         long long d;         cin >> l >> r >> d;         d &= 1;         l--;         r--;         if (!d) continue;         for (int i = l / SQ + 1; i < r / SQ; i++) {           lazy[i] ^= 1;         }         if (l / SQ != r / SQ) {           for (int i = l; i / SQ == l / SQ; i++) {             a[i] ^= 1;           }           for (int i = r / SQ * SQ; i <= r; i++) {             a[i] ^= 1;           }           make(l / SQ);           make(r / SQ);         } else {           for (int i = l; i <= r; i++) {             a[i] ^= 1;           }           make(l / SQ);         }       } else {         int l, r;         cin >> l >> r;         l--;         r--;         if (a[l] == lazy[l / SQ]) {           cout <<  1 n ;           continue;         }         int x = getlast(r);         if (P(x, l))           cout <<  2 n ;         else           cout <<  1 n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     cout << n << endl;     while (n--) {       cout <<  1  ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, s, p, k, m, t, x, y, ans, res;     cin >> t;     while (t--) {       cin >> n;       long long a[n + 1];       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       ans = 0;       m = INT_MAX;       for (int i = n; i >= 1; i--) {         if (a[i] > m) ans++;         m = min(a[i], m);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long x, long long y) { return x > y ? x : y; }   long long min(long long x, long long y) { return x < y ? x : y; }   long long gcd(long long p, long long q) {     if (q == 0) return p;     return gcd(q, p % q);   }   bool check(long long b, long long p) {     long long m;     while (gcd(p, b) != 1) {       m = gcd(p, b);       while (p % m == 0) p = p / m;       b = m;     }     if (p == 1)       return true;     else       return false;   }   int main() {     long long p, q, b;     int n;     scanf( %d , &n);     while (n--) {       scanf( %I64d%I64d%I64d , &p, &q, &b);       if (p == 0) {         printf( Finite n );         continue;       }       long long mmax = max(p, q);       long long mmin = min(p, q);       long long GCD = gcd(mmax, mmin);       p = q / GCD;       if (check(b, p))         printf( Finite n );       else         printf( Infinite n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long fexp(long long b, long long e) {     long long x = 1;     for (; e; e >>= 1, b = (b * b) % (1000000007))       if (e & 1) x = (x * b) % (1000000007);     return x;   }   long long n, k, ok, i, j, x;   set<long long> S;   signed main() {     ios_base::sync_with_stdio(0);     cin >> n >> k;     ok = 1;     for (x = 1; x <= k && ok; x++) {       S.clear();       for (i = 1; i <= x; i++) {         if (S.count(n % i))           ok = 0;         else           S.insert(n % i);       }     }     cout << (ok ?  Yes  :  No ) << endl;     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i = 0;     string s;     cin >> s;     if (s[0] >=  a  && s[0] <=  z ) s[0] = char(s[0] - 32);     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const static int INF = 1000000000;   int t;   string input;   map<string, string> apa;   int main() {     scanf( %d , &t);     string a, b;     string v =  void ;     apa[v] =  void ;     while (t--) {       cin >> input;       if (input ==  typedef ) {         cin >> a >> b;         string tipe =   ;         int bintang = 0, dan = 0;         for (int i = 0; a[i] !=   0 ; i++) {           if (a[i] ==  * )             bintang++;           else if (a[i] ==  & )             dan++;           else             tipe += a[i];         }         string bener = apa[tipe];         if (bener ==  errtype  || tipe ==  errtype ) {           apa[b] =  errtype ;           continue;         }         if (bintang >= dan) {           for (int i = 0; i < bintang - dan; i++) {             bener +=  * ;           }           apa[b] = bener;         } else if (dan > bintang) {           string ganti =   ;           dan = dan - bintang;           for (int i = 0; bener[i] !=   0 ; i++) {             if (bener[i] ==  * ) {               if (dan > 0)                 dan--;               else {                 ganti +=  * ;               }             } else               ganti += bener[i];           }           if (dan == 0)             apa[b] = ganti;           else             apa[b] =  errtype ;         }       } else {         cin >> a;         string tipe =   ;         int bintang = 0, dan = 0;         for (int i = 0; a[i] !=   0 ; i++) {           if (a[i] ==  * )             bintang++;           else if (a[i] ==  & )             dan++;           else             tipe += a[i];         }         string bener = apa[tipe];         if (bener ==  errtype  || bener ==   ) {           printf( errtype n );           continue;         }         if (bintang >= dan) {           for (int i = 0; i < bintang - dan; i++) {             bener +=  * ;           }           printf( %s n , bener.c_str());         } else if (dan > bintang) {           string ganti =   ;           dan = dan - bintang;           for (int i = 0; bener[i] !=   0 ; i++) {             if (bener[i] ==  * ) {               if (dan > 0)                 dan--;               else {                 ganti +=  * ;               }             } else               ganti += bener[i];           }           if (dan == 0)             printf( %s n , ganti.c_str());           else             printf( errtype n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long pos = 0;     long long distance;     int n, flag = 1;     char dir[20];     cin >> n;     for (int j = 0; j < n; j++) {       cin >> distance >> dir;       if (pos == 0 && strcmp(dir,  South ) != 0) {         flag = 0;       } else if (pos == 20000 && strcmp(dir,  North ) != 0) {         flag = 0;       } else {         if (strcmp(dir,  South ) == 0) {           pos = pos + distance;           if (pos > 20000) flag = 0;         } else if (strcmp(dir,  North ) == 0) {           pos = pos - distance;           if (pos < 0) {             flag = 0;           }         }       }     }     if (pos) flag = 0;     if (flag)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize  Ofast    #pragma GCC optimize  unroll-loops    #pragma GCC target  sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native    using namespace std;   class Debugger {    public:     Debugger(const std::string& _separator =   -  )         : first(true), separator(_separator) {}     template <typename ObjectType>     Debugger& operator,(const ObjectType& v) {       if (!first)       std:         cerr << separator;       std::cerr << v;       first = false;       return *this;     }     ~Debugger() {     std:       cerr << endl;     }       private:     bool first;     std::string separator;   };   long long int n, k, d;   set<pair<long long int, long long int> > ans;   long long int s;   void dfs(long long int u, long long int dad, long long int d,            long long int rem) {     ans.insert({dad, u});     if (d) {       for (long long int i = 0; i < rem && s < n; i++) dfs(++s, u, d - 1, k - 1);     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> d >> k;     if (n <= d || d > 1 && k < 2) {       cout <<  NO ;       return 0;     }     for (s = 1; s <= d; s++) ans.insert({s, s + 1});     for (long long int i = 2; i <= d && s < n; i++) {       dfs(i, i - 1, min(i - 1, d + 1 - i), k - 2);     }     if (s < n) {       cout <<  NO ;       return 0;     }     cout <<  YES n ;     for (auto it : ans) cout << it.first <<     << it.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long(n), (k);     scanf( %lld%lld , &(n), &(k));     ;     long long n2 = n;     vector<long long> vec;     while (n) {       vec.push_back(n);       if (n - 1 > 0) vec.push_back(n - 1);       if (n - 2 > 0) vec.push_back(n - 2);       if (n - 3 > 0) vec.push_back(n - 3);       n /= 2;     }     long long maxi = 1;     auto allok = [&](long long v) {       long long mi = v, ma = (v % 2) ? v : v + 1;       long long c = ma - mi + 1;       while (ma <= n2) {         mi *= 2;         ma = 2 * ma + 1;         if (mi < n2) c += min(ma, n2) - mi + 1;       }       return c >= k;     };     for (auto i : vec) {       if (allok(i)) maxi = max(maxi, i);     }     printf( %lld n , maxi);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int inf = 0x3f3f3f3f3f3f3f3fLL;   const double eps = 1e-9;   const double PI = acos(-1);   long long int i, j, k;   void solve(void);   inline bool equal(double a, double b) { return fabs(a - b) < eps; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout << fixed << setprecision(10);     int t = 1;     while (t--) solve();     return 0;   }   long long int m;   unordered_map<long long int, long long int> f;   long long int fib(long long int n) {     if (n == 0) return 0;     if (n == 1 || n == 2) return (f[n] = 1) % m;     if (f[n]) return f[n];     long long int k = (n & 1) ? (n + 1) / 2 : n / 2;     f[n] = (n & 1) ? ((fib(k) * fib(k)) % m + (fib(k - 1) * fib(k - 1)) % m) % m                    : (((2 * fib(k - 1)) % m + fib(k)) % m * fib(k)) % m;     return f[n];   }   void solve() {     long long int l, r, k;     cin >> m >> l >> r >> k;     long long int d = (r - l) / (k - 1);     while (d > 1) {       if (1 + r / d - (l + d - 1) / d >= k) break;       long long int N = 1 + r / d;       d -= ((N * d - r) + (N - 1)) / N;     }     cout << fib(d) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   char str[100010];   long long n, l[100010], r[100010], ofs, stk[100010], sa[100010], rk[100010],       tmp[100010], hei[100010];   vector<long long> ll[100010], rr[100010];   void build_sa(char *str, long long sa[]);   void build_hei(char *str, long long sa[], long long hei[]);   int main() {     scanf( %s , str);     n = strlen(str);     build_sa(str, sa);     build_hei(str, sa, hei);     long long i, k;     for (k = 0, i = 1; i <= n - 1; i++) {       while (k && hei[stk[k]] >= hei[i]) k--;       l[i] = (k ? stk[k] + 1 : 1);       stk[++k] = i;     }     for (k = 0, i = n - 1; i >= 1; i--) {       while (k && hei[stk[k]] >= hei[i]) k--;       r[i] = (k ? stk[k] - 1 : n - 1);       stk[++k] = i;     }     for (i = 1; i <= n - 1; i++)       if (hei[i] && (ll[hei[i]].empty() || l[i] != ll[hei[i]].back())) {         ll[hei[i]].push_back(l[i]);         rr[hei[i]].push_back(r[i]);       }     long long ans = 0, p, q;     for (hei[0] = hei[n] = 0, i = 1; i <= n - 1; i++)       while (!ll[i].empty()) {         p = ll[i].back();         q = rr[i].back();         ans += (q - p + 2) * (q - p + 3) / 2 * (i - max(hei[p - 1], hei[q + 1]));         ll[i].pop_back();         rr[i].pop_back();       }     for (i = 1; i <= n; i++) ans += n - sa[i] + 1 - max(hei[i], hei[i - 1]);     printf( %I64d n , ans);     return 0;   }   bool cmp(long long i, long long j) {     if (rk[i] != rk[j]) return rk[i] < rk[j];     long long ri = (i + ofs <= n ? rk[i + ofs] : -1),               rj = (j + ofs <= n ? rk[j + ofs] : -1);     return ri < rj;   }   void build_sa(char *str, long long sa[]) {     long long i;     for (i = 1; i <= n; i++) {       sa[i] = i;       rk[i] = str[i - 1];     }     for (ofs = 1; ofs <= n; ofs *= 2) {       sort(sa + 1, sa + n + 1, cmp);       for (tmp[sa[1]] = 1, i = 2; i <= n; i++)         tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) ? 1 : 0);       for (i = 1; i <= n; i++) rk[i] = tmp[i];     }   }   void build_hei(char *str, long long sa[], long long hei[]) {     long long h = 0, i, j;     for (i = 1; i <= n; i++) {       if (rk[i] == n) continue;       j = sa[rk[i] + 1];       if (h) h--;       for (; j + h <= n && i + h <= n; h++)         if (str[j + h - 1] != str[i + h - 1]) break;       hei[rk[i]] = h;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, A = 5e5 + 5;   vector<vector<long long>> v;   long long n, m, val;   long long ans[A];   bool vis[A], vis2[A];   void DFS(long long node) {     if (vis[node]) return;     vis[node] = 1;     for (auto child : v[node]) {       if (vis[child]) continue;       val++;       DFS(child);     }   }   void DFSmemo(long long node) {     if (vis2[node]) return;     vis2[node] = 1;     for (auto child : v[node]) {       if (vis2[child]) continue;       ans[child] = val;       DFSmemo(child);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     v.resize(n + 2);     for (int i = 0; i < m; i++) {       long long g, x, y;       cin >> g;       if (g != 0) cin >> x;       for (int j = 1; j < g; j++) {         cin >> y;         v[x].push_back(y), v[y].push_back(x);       }     }     for (int i = 1; i <= n; i++) {       if (ans[i] == 0) {         val = 1;         DFS(i);         DFSmemo(i);       } else         val = ans[i];       cout << val <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<set<int> > v(n);     vector<set<int> > w(n);     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       if (a > b)         v[a].insert(b);       else         v[b].insert(a);       if (a > b)         w[b].insert(a);       else         w[a].insert(b);     }     vector<int> pairs(n), pairs2(n);     pairs[0] = v[0].size();     for (int i = 1; i < n; i++) pairs[i] = pairs[i - 1] + v[i].size();     pairs2[n - 1] = 0;     for (int i = n - 2; i >= 0; i--) pairs2[i] = pairs2[i + 1] + w[i].size();     long long ans = 0;     for (int i = 0; i < n - 1; i++)       if (pairs[i] == 0 && pairs2[i + 1] == 0) ans++;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long cnt(long long a, long long b, long long c) {     if (a > b || b > c) return 0LL;     if (a == b && b == c) return 1LL;     if (a == b && b < c) return 3LL;     if (a < b && b == c) return 3LL;     if (a < b && b < c) return 6LL;   }   int main() {     long long n;     scanf( %lld , &n);     if (n % 3LL)       printf( 0 n );     else {       long long ans = 0LL;       n /= 3LL;       for (long long sab = 1LL; sab * sab * sab <= n; sab++)         if (n % sab == 0LL) {           for (long long a = 1LL; a <= sab - a; a++) {             long long b = sab - a;             long long det = sab * sab - 4LL * a * b + 4LL * n / sab;             if (det < 0LL) continue;             long long sqdet = 0LL, dd = 1LL << 30LL;             while (dd) {               long long nsqdet = sqdet + dd;               if (nsqdet * nsqdet <= det) sqdet = nsqdet;               dd >>= 1LL;             }             if (sqdet * sqdet == det) {               long long c = sqdet - sab;               if (c % 2LL == 0) {                 c /= 2LL;                 ans += cnt(a, b, c);               }             }           }         }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6;   const int md = 1000000009;   int n;   long long two[maxn + 5], f[maxn + 5], ans;   int main() {     two[0] = 1;     for (int i = 1; i <= maxn; ++i) two[i] = two[i - 1] * 2 % md;     scanf( %d , &n);     f[n] = 2;     for (int i = n - 1; i >= 2; --i) {       if (i & 1)         f[i] = (f[i + 1] + 2) % md;       else {         int k = i >> 1;         f[i] = (2 + ((two[k - 1] - 1 + md) % md * 4 + 1) * f[i + 1]) % md;       }     }     f[1] = (1 + f[2] * f[2]) % md;     ans = f[1] * 2 % md;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd1(long long a, long long b) {     if (a == 0) return b;     return gcd1(b % a, a);   }   long long modx(long long base, long long ex) {     long long ans = 1LL, val = base;     while (ex > 0LL) {       if (ex & 1LL) ans = (ans * val) % 998244353LL;       val = (val * val) % 998244353LL;       ex = ex >> 1LL;     }     return ans;   }   const int maxn = 5e5 + 10;   int a[maxn], n, c;   int pre[maxn], suff[maxn];   int cnt[maxn], ans;   vector<int> v[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> c;     for (int i = 1; i <= n; i++) {       cin >> a[i];       v[a[i]].push_back(i);       if (a[i] == c)         cnt[i] = cnt[i - 1] + 1;       else         cnt[i] = cnt[i - 1];     }     ans = cnt[n];     for (int i = 1; i < maxn; i++) {       if (i == c) continue;       if (v[i].size() == 0) continue;       for (int j = 0; j < v[i].size(); j++) {         pre[j] = cnt[v[i][j]];         pre[j]++;         if (j > 0) pre[j] = max(pre[j], pre[j - 1] + 1);       }       for (int j = v[i].size() - 1; j >= 0; j--) {         suff[j] = cnt[n] - cnt[v[i][j]];         suff[j]++;         if (j + 1 < v[i].size()) suff[j] = max(suff[j], suff[j + 1] + 1);       }       for (int j = 0; j < v[i].size(); j++) {         ans = max(ans, pre[j] + suff[j] - 1);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     int base = sqrt(n);     if (base * base == n) {       cout << base <<     << 1 << endl;       return;     }     n = n - base * base;     if (n <= base + 1) {       cout << n <<     << base + 1 << endl;     } else       cout << base + 1 <<     << (2 * (base + 1) - n) << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, s;     cin >> a >> s;     sort(s.begin(), s.end());     reverse(s.begin(), s.end());     int k = 0;     for (int i = 0; i < a.size() && i < s.size(); i++) {       bool found = false;       for (int j = k; j < a.size(); j++) {         if (s[i] > a[j]) {           a[j] = s[i];           found = true;           k = j;           break;         }       }       if (!found) break;     }     cout << a << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool sort_d(long long x, long long y) { return x > y; }   int gcd(long long x, long long y) {     if (!y)       return x;     else       return gcd(y, x % y);   }   int lcm(long long x, long long y) { return (x * y) / gcd(x, y); }   int main() {     int n, m, a, b;     std::vector<int> Cs, Ce, Ps, Pe;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b;       Cs.push_back(a);       Ce.push_back(b);     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b;       Ps.push_back(a);       Pe.push_back(b);     }     sort(Cs.begin(), Cs.end());     sort(Ce.begin(), Ce.end());     sort(Ps.begin(), Ps.end());     sort(Pe.begin(), Pe.end());     a = max(Ps[Ps.size() - 1] - Ce[0], 0);     b = max(Cs[Cs.size() - 1] - Pe[0], 0);     cout << max(a, b) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int ni() {     int a;     scanf( %d , &a);     return a;   }   inline double nf() {     double a;     scanf( %lf , &a);     return a;   }   template <class T>   void out(T a, T b) {     bool first = true;     for (T i = a; i != b; i++) {       if (!first) printf(   );       first = false;       cout << *i;     }     puts(  );   }   template <class T>   void outl(T a, T b) {     for (T i = a; i != b; i++) cout << *i <<   n ;   }   int n, m;   vector<pair<int, int> > v;   map<int, vector<int> > p;   set<pair<int, int> > s;   vector<pair<int, int> > cur;   vector<pair<int, int> > w;   int mx;   int main() {     n = ni();     m = ni();     v.resize(m);     for (int i = 0; i < (int)(m); i++) {       v[i].first = ni();       v[i].second = ni();       p[v[i].first].push_back(v[i].second);       mx = max(mx, v[i].first);     }     for (map<int, vector<int> >::iterator it = p.begin(); it != p.end(); it++)       sort((it->second).begin(), (it->second).end());     s.insert(make_pair(1, 1));     int last = 0;     for (map<int, vector<int> >::iterator it = p.begin(); it != p.end();) {       if (s.empty()) break;       cur.clear();       if (last + 1 < it->first) {         cur.push_back(make_pair(1, n));         last = it->first - 1;       } else {         int f = 1, lst = n;         for (int i = 0; i < (int)(((int)(it->second).size())); i++) {           if (f < it->second[i]) {             cur.push_back(make_pair(f, it->second[i] - 1));           }           f = it->second[i] + 1;         }         if (f <= lst) cur.push_back(make_pair(f, lst));         last = it->first;         it++;       }       int d = 0;       w.clear();       for (set<pair<int, int> >::iterator sit = s.begin();            sit != s.end() && d < ((int)(cur).size());) {         while (d < ((int)(cur).size()) && cur[d].second < sit->first) d++;         if (d < ((int)(cur).size()) && cur[d].first <= sit->second) {           w.push_back(make_pair(max(cur[d].first, sit->first), cur[d].second));           d++;         } else {           sit++;         }       }       s.clear();       for (int i = 0; i < (int)(((int)(w).size())); i++) s.insert(w[i]);     }     if (!s.empty()) {       if (last == n) {         if (s.rbegin()->second == n)           cout << 2 * (n - 1) << endl;         else           puts( -1 );       } else {         cout << 2 * (n - 1) << endl;       }     } else {       cout << -1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   int solve();   void precomp();   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t = 1;     if (0) cin >> t;     precomp();     for (int tc = 1; tc <= t; tc++) {       if (0 && 0) cout <<  Case #  << tc <<  :  ;       solve();     }   }   void precomp() { return; }   int cnt[26][26], ans[26], tmp[26];   string s;   int solve() {     cin >> s;     for (int i = 1; i <= s.size(); i++) {       memset(cnt, 0, sizeof(cnt));       memset(tmp, 0, sizeof(tmp));       for (int j = 0; j < s.size(); j++)         cnt[s[j] -  a ][s[(j + i) % s.size()] -  a ]++;       for (int j = 0; j < s.size(); j++)         if (cnt[s[j] -  a ][s[(i + j) % s.size()] -  a ] == 1) tmp[s[j] -  a ]++;       for (int j = 0; j < 26; j++) ans[j] = max(ans[j], tmp[j]);     }     int tot = 0;     for (int i = 0; i < 26; i++) tot += ans[i];     long double ans = (long double)tot / (long double)s.size();     cout << fixed << setprecision(10);     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int MOD = 1e9 + 7;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long l, r;     long long ans = -1;     cin >> l >> r;     for (int i = 0; l > 0 || r > 0; ++i) {       if ((l & 1) != (r & 1)) ans = i;       l >>= 1;       r >>= 1;     }     cout << (1LL << (ans + 1)) - 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double __begin;   template <typename T1, typename T2, typename T3>   struct triple {     T1 a;     T2 b;     T3 c;     triple(){};     triple(T1 _a, T2 _b, T3 _c) : a(_a), b(_b), c(_c) {}   };   template <typename T1, typename T2, typename T3>   bool operator<(const triple<T1, T2, T3>& t1, const triple<T1, T2, T3>& t2) {     if (t1.a != t2.a)       return t1.a < t2.a;     else if (t1.b != t2.b)       return t1.b < t2.b;     else       return t1.c < t2.c;   }   template <typename T1, typename T2, typename T3>   inline std::ostream& operator<<(std::ostream& os, const triple<T1, T2, T3>& t) {     return os <<  (  << t.a <<  ,   << t.b <<  ,   << t.c <<  ) ;   }   inline int bits_count(int v) {     v = v - ((v >> 1) & 0x55555555);     v = (v & 0x33333333) + ((v >> 2) & 0x33333333);     return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;   }   inline int bits_count(long long v) {     int t = v >> 32;     int p = (v & ((1LL << 32) - 1));     return bits_count(t) + bits_count(p);   }   unsigned int reverse_bits(register unsigned int x) {     x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));     x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));     x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));     x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));     return ((x >> 16) | (x << 16));   }   inline int sign(int x) { return x > 0; }   inline bool isPowerOfTwo(int x) { return (x != 0 && (x & (x - 1)) == 0); }   template <typename T1, typename T2>   inline std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {     bool first = true;     os <<  [ ;     for (unsigned int i = 0; i < v.size(); i++) {       if (!first) os <<  ,  ;       os << v[i];       first = false;     }     return os <<  ] ;   }   template <typename T>   inline std::ostream& operator<<(std::ostream& os, const std::set<T>& v) {     bool first = true;     os <<  [ ;     for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end();          ++ii) {       if (!first) os <<  ,  ;       os << *ii;       first = false;     }     return os <<  ] ;   }   template <typename T1, typename T2>   inline std::ostream& operator<<(std::ostream& os, const std::map<T1, T2>& v) {     bool first = true;     os <<  [ ;     for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end();          ++ii) {       if (!first) os <<  ,  ;       os << *ii;       first = false;     }     return os <<  ] ;   }   template <typename T, typename T2>   void printarray(T a[], T2 sz, T2 beg = 0) {     for (T2 i = beg; i < sz; i++) cout << a[i] <<    ;     cout << endl;   }   inline long long mulmod(long long x, long long n, long long _mod) {     long long res = 0;     while (n) {       if (n & 1) res = (res + x) % _mod;       x = (x + x) % _mod;       n >>= 1;     }     return res;   }   inline long long powmod(long long x, long long n, long long _mod) {     long long res = 1;     while (n) {       if (n & 1) res = (res * x) % _mod;       x = (x * x) % _mod;       n >>= 1;     }     return res;   }   inline long long gcd(long long a, long long b) {     long long t;     while (b) {       a = a % b;       t = a;       a = b;       b = t;     }     return a;   }   inline int gcd(int a, int b) {     int t;     while (b) {       a = a % b;       t = a;       a = b;       b = t;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long gcd(long long a, long long b, long long c) {     return gcd(gcd(a, b), c);   }   inline int gcd(int a, int b, int c) { return gcd(gcd(a, b), c); }   template <class T>   inline void cinarr(T& a, int n) {     for (int i = 0; i < n; ++i) cin >> a[i];   }   int main() {     int n, c_mx = -1, c_mn = 1e9, ans = 0;     scanf( %d , &n);     vector<int> a(n), p(n), s(n);     for (int i = 0; i < (n); ++i) scanf( %d , &a[i]);     for (int i = 0; i < (n); ++i) {       if (a[i] > c_mx) c_mx = a[i];       p[i] = c_mx;     }     for (int i = (n)-1; i >= (0); --i) {       if (a[i] < c_mn) c_mn = a[i];       s[i] = c_mn;     }     for (int i = 0; i < (n - 1); ++i) ans += (p[i] <= s[i + 1]);     printf( %d , ans + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, n, d, t, v;   double ans[100001];   double gets_ans() {     double t1 = v * 1.0 / a;     if (0.5 * a * t1 * t1 <= d) return t + t1 + (d - 0.5 * a * t1 * t1) / v;     return sqrt(2.0 * d / a) + t;   }   int main() {     cin >> n >> a >> d;     for (int i = 0; i < n; i++) {       cin >> t >> v;       ans[i] = gets_ans();       if (i != 0 && ans[i] < ans[i - 1]) ans[i] = ans[i - 1];       printf( %.10lf n , ans[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   struct dsu {     vector<int> p;     vector<int> q;     vector<int> pre;     vector<int> nxt;     vector<int> sz;     int n;     dsu(int _n) : n(_n) {       p.resize(n);       iota(p.begin(), p.end(), 0);       q = p;       sz.assign(n, 1);       pre.assign(n, -1);       nxt.assign(n, -1);     }     inline int get(int x) {       if (p[x] == x) {         return x;       } else {         return p[x] = get(p[x]);       }     }     inline bool unite(int x, int y) {       x = get(x);       y = get(y);       if (x == y) {         return false;       }       if (sz[x] > sz[y]) {         swap(x, y);       }       pre[x] = q[y];       nxt[q[y]] = x;       p[x] = y;       q[y] = q[x];       sz[y] += sz[x];       return true;     }     inline bool same(int x, int y) { return (get(x) == get(y)); }   };   template <class T>   struct segtree {     int n;     T ie = -1;     vector<T> node;     function<T(T, T)> f = [&](T a, T b) { return max(a, b); };     segtree() : segtree(0) {}     segtree(int _n) : segtree(vector<T>(_n, ie)) {}     segtree(vector<T> v) {       n = 1 << (32 - __builtin_clz((int)v.size() - 1));       node.resize(2 * n - 1, ie);       for (int i = 0; i < (int)v.size(); i++) {         node[i + n - 1] = v[i];       }       for (int i = n - 2; i >= 0; i--) {         node[i] = f(node[2 * i + 1], node[2 * i + 2]);       }     }     void update(int x, T v) {       x += n - 1;       node[x] = v;       while (x > 0) {         x = (x - 1) / 2;         node[x] = f(node[2 * x + 1], node[2 * x + 2]);       }     }     T get(int a, int b, int x, int l, int r) {       if (r <= a || b <= l) {         return ie;       }       if (a <= l && r <= b) {         return node[x];       }       T vl = get(a, b, 2 * x + 1, l, (l + r) / 2);       T vr = get(a, b, 2 * x + 2, (l + r) / 2, r);       return f(vl, vr);     }     T get(int a, int b) { return get(a, b, 0, 0, n); }     T get(int a) { return node[a + n - 1]; }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m, q;     cin >> n >> m >> q;     vector<int> p(n);     for (int i = 0; i < n; i++) {       cin >> p[i];     }     vector<pair<int, int>> e(m);     for (int i = 0; i < m; i++) {       cin >> e[i].first >> e[i].second;       e[i].first--, e[i].second--;     }     vector<int> del(m);     vector<pair<int, int>> t(q);     for (int i = 0; i < q; i++) {       cin >> t[i].first >> t[i].second;       t[i].first--, t[i].second--;       if (t[i].first == 1) {         del[t[i].second] = 1;       }     }     dsu uf(n);     for (int i = 0; i < m; i++) {       if (!del[i]) {         uf.unite(e[i].first, e[i].second);       }     }     for (int i = q - 1; i >= 0; i--) {       if (t[i].first == 1) {         if (del[t[i].second]) {           uf.unite(e[t[i].second].first, e[t[i].second].second);         }         t[i].first = -1;       } else {         int v = uf.get(t[i].second);         t[i] = make_pair(v, uf.q[v]);       }     }     vector<int> a;     for (int i = 0; i < n; i++) {       if (uf.get(i) == i) {         int v = i;         while (v != -1) {           a.emplace_back(v);           v = uf.nxt[v];         }       }     };     vector<int> b(n);     vector<int> c(n);     vector<int> d(n + 1, -1);     for (int i = 0; i < n; i++) {       b[a[i]] = i;       c[i] = p[a[i]];       d[c[i]] = i;     }     segtree<int> st(c);     for (int i = 0; i < q; i++) {       if (t[i].first == -1) {         continue;       }       int l = b[t[i].first], r = b[t[i].second];       int res = st.get(l, r + 1);       cout << res <<   n ;       if (res) {         st.update(d[res], 0);       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   long long n, cnt[5], fct[1000001];   pair<long long, long long> dp[1000001];   string st;   map<char, int> mp;   long long pw(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     long long ret = pw(a, b / 2);     (ret *= ret) %= 1000000007;     if (b & 1) (ret *= a) % 1000000007;     return ret;   }   pair<long long, long long> rec(int lef) {     if (lef == 0) return make_pair(0, 1);     if (~dp[lef].first) return dp[lef];     pair<long long, long long> ret = make_pair(0, 0);     for (int i = 0; i < 4; i++) {       pair<long long, long long> tmp = rec(lef - 1);       tmp.first += cnt[i];       if (tmp.first == ret.first)         (ret.second += tmp.second) %= 1000000007;       else if (tmp.first > ret.first)         ret = tmp;     }     return dp[lef] = ret;   }   int main() {     cin >> n >> st;     mp[ A ] = 0;     mp[ C ] = 1;     mp[ G ] = 2;     mp[ T ] = 3;     fct[0] = fct[1] = 1;     for (int i = 0; i < st.size(); i++) cnt[mp[st[i]]]++;     for (int i = 2; i < 1000001; i++) fct[i] = (fct[i - 1] * i) % 1000000007;     memset((dp), (-1), sizeof(dp));     pair<long long, long long> x = rec(n);     cout << x.second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Nmax = 2005;   int n, k;   pair<double, double> mij[Nmax * Nmax];   pair<int, int> a[Nmax];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         mij[++k] = {(double)(a[i].first + a[j].first) / 2,                     (double)(a[i].second + a[j].second) / 2};     sort(mij + 1, mij + k + 1);     int cnt;     long long sol = 0;     cnt = 1;     for (int i = 2; i <= k;) {       while (i <= k && mij[i].first == mij[i - 1].first &&              mij[i].second == mij[i - 1].second) {         i++;         cnt++;       }       sol += (cnt * (cnt - 1)) / 2;       cnt = 1;       i++;     }     cout << sol <<   n ;     return 0;   }