#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, k, l, x = 1;     cin >> n >> m >> k >> l;     if (k + l > n)       cout <<  -1 ;     else if ((k + l) % m == 0 && (k + l) <= n)       cout << (k + l) / m;     else if ((k + l) % m != 0 && ((k + l) / m + 1) * m <= n)       cout << ((k + l) / m) + 1;     else       cout <<  -1 ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxk = 105, maxn = 2e5 + 5, inf = 1e9;   int n, k, l[maxk], r[maxk], dp[2][maxn];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= k; ++i) scanf( %d %d , l + i, r + i);     if (l[k] != 2 * n) {       ++k;       l[k] = r[k] = 2 * n;     }     for (int t = 0; t < maxn; ++t) dp[1][t] = inf;     dp[1][l[1]] = 0;     for (int j = 2; j <= k; ++j) {       for (int t = 0; t < maxn; ++t) dp[j & 1][t] = inf;       for (int t = l[j] - l[j - 1]; t <= l[j]; ++t) {         dp[j & 1][t] = min(dp[j & 1][t], dp[(j - 1) & 1][t - l[j] + l[j - 1]]);       }       deque<pair<int, int> > minq;       for (int s = 0; s <= l[j]; ++s) {         int val = dp[(j - 1) & 1][s] + 1;         while (!minq.empty() && minq.back().first >= val) minq.pop_back();         minq.push_back({val, s});         while (!minq.empty() && minq.front().second + r[j - 1] - l[j - 1] < s)           minq.pop_front();         int t = l[j] - s;         dp[j & 1][t] = min(dp[j & 1][t], minq.front().first);       }       while (!minq.empty()) minq.pop_back();       for (int s = 0; s <= r[j - 1]; ++s) {         int val = dp[(j - 1) & 1][s] + 2;         while (!minq.empty() && minq.back().first >= val) minq.pop_back();         minq.push_back({val, s});         while (!minq.empty() && minq.front().second + r[j - 1] - l[j - 1] < s)           minq.pop_front();         int t = s + l[j] - r[j - 1];         dp[j & 1][t] = min(dp[j & 1][t], minq.front().first);       }     }     if (dp[k & 1][n] == inf)       printf( Hungry n );     else       printf( Full n%d n , dp[k & 1][n]);   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %i , &n);     printf( %li , (long int)n / 2 * 3);     return 0;   }


#include <bits/stdc++.h>   long long mod = 1e9 + 7;   int main() {     long long n, m;     std::cin >> n >> m;     std::string s;     std::cin >> s;     std::vector<std::vector<long long>> dp(n - m + 1,                                            std::vector<long long>(n - m + 1));     dp[0][0] = 1;     for (long long i = 1; i < n - m + 1; ++i)       for (long long j = 0; j < n - m + 1; ++j) {         dp[i][j] = 0;         if (j > 0) dp[i][j] += dp[i - 1][j - 1];         if (j < n - m) dp[i][j] += dp[i - 1][j + 1];         dp[i][j] %= mod;       }     long long min = 0, balance = 0;     for (long long i = 0; i < m; ++i)       if (s[i] ==  ( )         ++balance;       else if (--balance < min)         min = balance;     long long res = 0;     for (long long left = 0; left <= n - m; ++left)       for (long long here = -min; here <= left; ++here)         if (here + balance <= n - m - left)           res = (res + dp[left][here] * dp[n - m - left][here + balance]) % mod;     std::cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1E9 + 7;   const long long N = 2E5 + 6;   long long n, m, a[N], b[N], ans, zeros[N];   long long dp[N];   long long modexp(long long b, long long e) {     long long res = 1;     while (e) {       if (e & 1) res = (res * b) % MOD;       e >>= 1;       b = (b * b) % MOD;     }     return res;   }   long long recur(long long ind) {     if (dp[ind] != -1) return dp[ind];     if (ind == n + 1) {       dp[ind] = 0;       return 0;     }     long long ans = 0;     if (a[ind] == 0 && b[ind] != 0) {       ans = (m - b[ind] + MOD) % MOD;       ans = (ans * modexp(m, zeros[ind + 1]) % MOD) % MOD;       ans = (ans + recur(ind + 1)) % MOD;     } else if (a[ind] != 0 && b[ind] == 0) {       ans = (a[ind] - 1 + MOD) % MOD;       ans = (ans * modexp(m, zeros[ind + 1]) % MOD) % MOD;       ans = (ans + recur(ind + 1)) % MOD;     } else if (a[ind] == 0 && b[ind] == 0) {       ans = ((m * (m - 1)) % MOD * 500000004LL) % MOD;       ans = (ans * modexp(m, zeros[ind + 1])) % MOD;       ans = (ans + (m * recur(ind + 1)) % MOD) % MOD;     } else {       if (a[ind] > b[ind]) {         ans = modexp(m, zeros[ind + 1]) % MOD;       } else if (a[ind] == b[ind])         ans = recur(ind + 1) % MOD;     }     dp[ind] = ans;     return ans;   }   long long modinv(long long x) { return modexp(x, MOD - 2); }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     if (fopen( inp.txt ,  r )) {       freopen( inp.txt ,  r , stdin);       freopen( outp.txt ,  w , stdout);     }     cin >> n >> m;     long long i;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) cin >> b[i];     memset(dp, -1, sizeof(dp));     zeros[n + 1] = 0;     zeros[n] = (b[n] == 0) + (a[n] == 0);     for (i = n - 1; i >= 1; i--)       zeros[i] = zeros[i + 1] + (a[i] == 0) + (b[i] == 0);     long long total = modexp(m, zeros[1]);     cout << (recur(1) * modinv(total)) % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;   }   inline void write(int x) {     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   const int N = 1000005, P = 1e9 + 7;   inline int power(int x, long long y) {     x %= P;     static int r;     r = 1;     while (y) {       if (y & 1) r = (long long)r * x % P;       x = (long long)x * x % P;       y >>= 1;     }     return r;   }   inline long long powerc(long long x, long long y, long long k) {     static long long r;     r = 1;     while (y) {       if (y & 1) r = r * x;       x = x * x;       y >>= 1;       r = min(r, k), x = min(x, k);     }     r = min(r, k);     return r;   }   int n, p, a[N], b[N], ans;   inline void solve() {     int i;     long long now, lst, dt;     read(n), read(p);     for (i = 1; i <= n; ++i) read(a[i]);     if (p == 1) {       ans = n & 1;       write(ans), putchar(  n );       return;     }     sort(a + 1, a + n + 1);     ans = 0;     for (i = 1; i <= n; ++i) b[i] = power(p, a[i]);     for (now = 0, lst = -1, i = n; i >= 1; --i) {       if (lst == -1) {         lst = a[i], now = 1, ans = (ans + b[i]) % P;         continue;       }       if (now != 0 && lst != a[i]) {         dt = lst - a[i];         now *= powerc(p, dt, n);         now = min(now, n * 1ll);       }       if (now) {         --now, ans = (ans + P - b[i]) % P;         lst = a[i];       } else {         ans = (ans + b[i]) % P;         now = 1, lst = a[i];       }     }     write(ans), putchar(  n );   }   int main() {     int T;     read(T);     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI(acos((long double)-1.0));   struct cpx {     long double r, i;     cpx() : r(0), i(0) {}     cpx(long double a, long double b) : r(a), i(b) {}     cpx conj() { return cpx(r, -i); }   } u[20], iu[20], a[524288], b[524288];   cpx operator+(const cpx &l, const cpx &r) { return cpx(l.r + r.r, l.i + r.i); }   cpx operator-(const cpx &l, const cpx &r) { return cpx(l.r - r.r, l.i - r.i); }   cpx operator*(const cpx &l, const cpx &r) {     return cpx(l.r * r.r - l.i * r.i, l.r * r.i + r.r * l.i);   }   void dif(cpx *a, cpx *unt, int l) {     int lv, i, j;     cpx u, v, w;     for (lv = l; lv; --lv)       for (i = 0; i < 1 << l; i += 1 << lv)         for (j = i, w = {1, 0}; j < i + (1 << lv - 1); ++j, w = w * unt[lv]) {           u = a[j];           v = a[j + (1 << lv - 1)];           a[j] = u + v;           a[j + (1 << lv - 1)] = (u - v) * w;         }   }   void dit(cpx *a, cpx *unt, int l) {     int lv, i, j;     cpx u, v, w;     for (lv = 1; lv <= l; ++lv)       for (i = 0; i < 1 << l; i += 1 << lv)         for (j = i, w = {1, 0}; j < i + (1 << lv - 1); ++j, w = w * unt[lv]) {           u = a[j];           v = a[j + (1 << lv - 1)] * w;           a[j] = u + v;           a[j + (1 << lv - 1)] = u - v;         }   }   int main() {     int tn, n, x, i, j, l;     long long a0;     scanf( %d%d , &n, &x);     for (tn = 0, l = -1, a0 = 0, i = 0; i < n; ++i) {       scanf( %d , &j);       if (j < x) {         a0 += (long long)(i - l) * (i - l - 1);         a[++tn].r = i - l;         l = i;       }     }     a0 += (long long)(n - l) * (n - l - 1);     a[++tn].r = n - l;     for (l = 1; 1 << l < tn; ++l)       ;     ++l;     for (i = 1; i < tn; ++i) b[(1 << l) - i].r = a[i].r;     for (i = 1; i <= l; ++i)       iu[i] =           (u[i] = cpx(cos(2 * PI / (1 << i)), -sin(2 * PI / (1 << i)))).conj();     dif(a, u, l);     dif(b, u, l);     for (i = 0; i < 1 << l; ++i) a[i] = a[i] * b[i];     dit(a, iu, l);     long double t((long double)1.0 / (1 << l));     printf( %lld , a0 / 2);     for (i = 1; i < tn && i <= n; ++i)       printf(  %lld , (long long)(a[i].r * t + 0.1));     for (; i <= n; ++i) printf(  0 );     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 5010;   namespace SuffixArray {   const int MAXN = 1 << 21;   string S;   int N, gap;   int sa[MAXN], pos[MAXN], tmp[MAXN], lcp[MAXN];   bool sufCmp(int i, int j) {     if (pos[i] != pos[j]) return pos[i] < pos[j];     i += gap;     j += gap;     return (i < N && j < N) ? pos[i] < pos[j] : i > j;   }   void buildSA() {     N = S.size();     for (int i = 0; i < (int)(N); ++i) sa[i] = i, pos[i] = S[i];     for (gap = 1;; gap *= 2) {       sort(sa, sa + N, sufCmp);       for (int i = 0; i < (int)(N - 1); ++i)         tmp[i + 1] = tmp[i] + sufCmp(sa[i], sa[i + 1]);       for (int i = 0; i < (int)(N); ++i) pos[sa[i]] = tmp[i];       if (tmp[N - 1] == N - 1) break;     }   }   void buildLCP() {     for (int i = 0, k = 0; i < N; ++i)       if (pos[i] != N - 1) {         for (int j = sa[pos[i] + 1]; S[i + k] == S[j + k];) ++k;         lcp[pos[i]] = k;         if (k) --k;       }   }   }  // namespace SuffixArray   using namespace SuffixArray;   bool dp[M][M];   void pre(string s, int n) {     for (int i = 1; i <= n; i++) dp[i][i] = 1;     for (int i = 1; i < n; i++) {       if (s[i] == s[i + 1]) dp[i][i + 1] = 1;       if (i == (n - 1)) continue;       if (s[i] == s[i + 2]) dp[i][i + 2] = 1;       if (i == (n - 2)) continue;       if (s[i] == s[i + 3]) dp[i][i + 3] = 1;     }     for (int k = 5; k <= n; k++) {       for (int i = 1; i + k - 1 <= n; i++) {         int j = i + k - 1;         if ((s[i] == s[j]) && dp[i + 2][j - 2]) dp[i][j] = 1;       }     }   }   int main() {     string s;     cin >> s;     int n = s.size();     s =  c  + s;     pre(s, n);     int k;     cin >> k;     S = s;     buildSA();     buildLCP();     int match = 0;     for (int i = 0; i < n; i++) {       int j = sa[i];       for (int l = match + 1; l + j - 1 <= n; l++) {         int x = l + j - 1;         if (!dp[j][x]) continue;         int cnter = 1;         for (int f = i; f < n - 1; f++) {           if (lcp[f] < l) break;           cnter++;         }         k -= cnter;         if (k <= 0) {           for (int f = j; f <= x; f++) cout << s[f];           cout << endl;           return 0;         }       }       match = lcp[i];     }     assert(false);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 250005;   int n, k, P, ans, f[30][N], fac[N], ifac[N], inv[N];   inline int ksm(register int x, register int L) {     register int ans = 1;     while (L)       L& 1 ? ans = (0ll + ans) * x % P, 0 : 0, x = (0ll + x) * x % P, L >>= 1;     return ans;   }   inline int dfs(const int x, const int s) {     if (x > k) return 0;     if (~f[x][s]) return f[x][s];     if (!s) return f[x][s] = (0ll + fac[n]) * fac[k] % P * ifac[k - x] % P;     f[x][s] = 0;     const int ss = s - (s & -s);     for (register int i = ss; i; i = (i - 1) & ss)       f[x][s] = (f[x][s] + (0ll + dfs(x + 1, i)) * ifac[s - i]) % P;     f[x][s] = (f[x][s] + (0ll + dfs(x + 1, 0)) * ifac[s]) % P;     return f[x][s];   }   int main() {     scanf( %d%d%d , &n, &k, &P), ans = ksm(k, n);     if (n & 1) return printf( %d , ans), 0;     for (register int i =              (fac[0] = fac[1] = ifac[0] = ifac[1] = inv[0] = inv[1] = 1) + 1;          i <= n; ++i)       fac[i] = (0ll + fac[i - 1]) * i % P,       inv[i] = (0ll + inv[P % i]) * (P - P / i) % P,       ifac[i] = (0ll + ifac[i - 1]) * inv[i] % P;     memset(f, -1, sizeof(f)), ans -= dfs(0, n),         printf( %d , ans < 0 ? ans + P : ans);     return 0;   }


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


#include <bits/stdc++.h>   double eps = 1e-9;   double cal(int x, int n, int m) {     double tmp = 1;     for (int i = 0; i < n; i++) {       tmp *= (double)x / m;       if (tmp < eps) return 0.0;     }     return tmp;   }   int main() {     int m, n;     scanf( %d %d , &m, &n);     double tmp = 0.0;     for (int i = m - 1; i >= 1; i--) tmp += cal(i, n, m);     printf( %.9lf n , m - tmp);   }


#include <bits/stdc++.h>   using namespace std;   long long save[100005];   long long aa[100005];   int hihi[100005];   int main() {     int n;     scanf( %d , &n);     memset(aa, 0, sizeof(aa));     memset(aa, 0, sizeof(aa));     int first = 0, second = 0, sum = 1;     long long a;     scanf( %I64d , &a);     if (a != 1) {       printf( -1 n );       return 0;     }     hihi[second] = 1;     aa[second++] = 1;     for (int i = 1; i < n; i++) {       scanf( %I64d , &a);       if (a == 1)         hihi[second] = 1, aa[second++] = 1, sum = second;       else if (a == aa[second] * 2)         hihi[second]++, aa[second++] = a;       else if (second != 0 && a == aa[second - 1] * 2)         hihi[0]++, aa[0] = a, second = 1;       else {         save[first++] = a;       }     }     if (first > sum) {       printf( -1 n );       return 0;     }     int Min, Max = sum + 1;     int add = first;     for (int i = sum - 1; i >= 0 && add <= i + 1; i--) add += hihi[i], Min = i;     long long v[100005];     while (Min < Max - 1) {       memset(v, 0, sizeof(v));       int xx = 0;       for (xx = 0; xx < first; xx++) v[xx] = save[xx];       int mid = (Max + Min) / 2;       for (int i = mid; i < sum; i++) {         for (long long j = 1; j <= aa[i]; j *= 2)           v[xx++] = j, assert(xx < 100000);         ;       }       sort(v, v + xx);       reverse(v, v + xx);       int ok = 1;       for (int i = 0; i < xx; i++) {         if (v[i] > aa[i] * 2) ok = 0;       }       if (ok) {         Max = mid;       } else {         Min = mid;       }     }     if (Min == sum) {       printf( -1 n );     } else {       printf( %d , Min + 1);       for (int i = Min + 2; i <= sum; i++) printf(  %d , i);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   int lim;   int n;   int p[maxn] = {0};   int res[maxn] = {0};   bool vis[maxn] = {0};   int cnt = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &p[i]);     }     lim = n;     res[cnt++] = 1;     for (int i = 1; i <= n; ++i) {       int temp = i + 1 + lim - n;       vis[p[i]] = 1;       if (p[i] == lim) {         temp--;         lim--;         for (int j = p[i] - 1;; --j) {           if (vis[j]) {             temp--;             lim--;           } else             break;         }       }       res[cnt++] = temp;     }     for (int i = 0; i <= n; ++i) {       cout << res[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) cout << i <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, ans;   char signs[3];   void r1(long long a) { ans = min(ans, a); }   void r2(long long a, long long b) {     if (signs[2] ==  * ) {       r1(a * b);     } else {       r1(a + b);     }   }   void r3(long long a, long long b, long long c) {     if (signs[1] ==  * ) {       r2(a * b, c);       r2(a * c, b);       r2(b * c, a);     } else {       r2(a + b, c);       r2(a + c, b);       r2(b + c, a);     }   }   void r4(long long a, long long b, long long c, long long d) {     if (signs[0] ==  * ) {       r3(a * b, c, d);       r3(a * c, b, d);       r3(a * d, b, c);       r3(b * c, a, d);       r3(b * d, a, c);       r3(c * d, a, b);     } else {       r3(a + b, c, d);       r3(a + c, b, d);       r3(a + d, b, c);       r3(b + c, a, d);       r3(b + d, a, c);       r3(c + d, a, b);     }   }   int main() {     cin >> a >> b >> c >> d >> signs[0] >> signs[1] >> signs[2];     ans = 1000000000001;     r4(a, b, c, d);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, x;     cin >> n >> x;     int sum = 0, infected = 0;     for (int i = 1; i <= n; i++) {       int val;       cin >> val;       sum += val;       infected += (val == x);     }     if (infected == n)       cout << 0 <<   n ;     else if (infected > 0 || n * x == sum)       cout << 1 <<   n ;     else       cout << 2 <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int t = 1, no = 0;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long int a[n + 1];     a[0] = 0ll;     long long int ans = 0ll;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] > a[i - 1]) ans += (1ll * (a[i] - a[i - 1]) * (n - a[i] + 1));       if (a[i] < a[i - 1]) ans += (1ll * a[i] * (a[i - 1] - a[i]));     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, n;     cin >> n;     vector<int> a(n);     int maxNum = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       maxNum = max(a[i], maxNum);     }     vector<vector<bool> > board(maxNum, vector<bool>(n));     for (int i = 0; i < n; i++) {       for (int j = maxNum - 1; j > maxNum - 1 - a[i]; j--) {         board[j][i] = true;       }     }     for (int i = 0; i < maxNum; i++) {       for (int j = n - 1; j >= 0; j--) {         if (board[i][j] == false) {           for (int k = j - 1; k >= 0; k--) {             if (board[i][k] == true) {               swap(board[i][j], board[i][k]);               break;             }           }         }       }     }     for (int i = 0; i < n; i++) {       int count = 0;       for (int j = 0; j < maxNum; j++) {         if (board[j][i]) {           count++;         }       }       cout << count <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long q;     cin >> q;     while (q--) {       long long n, a, b;       cin >> n >> a >> b;       if (a + b >= n)         cout << max(a, b) - (a + b - 1 - n) << endl;       else         cout << min(a, b) + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int A[101];   string s;   long long d[101][101][101];   long long f(int lo, int hi, int p) {     if (lo == hi) return A[p];     if (d[lo][hi][p]) return d[lo][hi][p];     long long ret = f(lo + 1, hi, 1) + A[p];     if (s[lo] == s[lo + 1]) ret = max(ret, f(lo + 1, hi, p + 1));     for (int i = lo + 2; i <= hi; i++)       if (s[i] == s[lo]) ret = max(ret, f(lo + 1, i - 1, 1) + f(i, hi, p + 1));     return d[lo][hi][p] = ret;   }   int main() {     cout << setprecision(10);     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     cin >> s;     s =  #  + s;     for (int i = 1; i <= n; i++) cin >> A[i];     for (int i = 1; i <= n; i++)       for (int k = 1; k < i; k++) A[i] = max(A[i], A[i - k] + A[k]);     cout << f(1, n, 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC diagnostic ignored  -Wmissing-declarations    double triangle_area(const complex<double> p1, const complex<double> p2,                        const complex<double> p3) {     return abs((p2.real() - p1.real()) * (p3.imag() - p1.imag()) -                (p2.imag() - p1.imag()) * (p3.real() - p1.real())) /            2.0;   }   pair<double, complex<double> > getCenter(const complex<double> a,                                            const complex<double> b,                                            const complex<double> c) {     complex<double> res;     res += a;     res += b;     res += c;     return {triangle_area(a, b, c), res / 3.0};   }   complex<double> getCenter(const vector<complex<double> >& v) {     double area = 0;     complex<double> res;     const int n = v.size();     for (int i = 1; i + 1 < n; ++i) {       auto p = getCenter(v[0], v[i], v[i + 1]);       area += p.first;       res += p.second * p.first;     }     return res / area;   }   double getDist(const complex<double> p1, const complex<double> p2) {     return norm(p1 - p2);   }   int main() {     ios_base::sync_with_stdio(false);     int n, q;     cin >> n >> q;     vector<complex<double> > v(n);     for (auto& p : v) {       double x, y;       cin >> x >> y;       p = {x, y};     }     complex<double> center = getCenter(v);     stringstream out;     out << fixed << setprecision(10);     int curP = 1;     for (auto& p : v) p -= center;     complex<double> angle = 1.0;     while (q--) {       int type;       cin >> type;       if (type == 1) {         int f;         cin >> f;         --f;         curP ^= f;         complex<double> p1 = center + angle * v[curP];         complex<double> np{p1.real(), p1.imag() - abs(v[curP])};         angle = complex<double>{0, abs(v[curP])} / v[curP];         center = np;         int t;         cin >> t;         --t;         curP ^= t;       } else {         int t;         cin >> t;         --t;         complex<double> p = center + angle * v[t];         out << p.real() <<     << p.imag() <<   n ;       }     }     cout << out.str();   }


#include <bits/stdc++.h>   using namespace std;   template <typename S, typename T>   ostream& operator<<(ostream& out, pair<S, T> const& p) {     out <<  (  << p.first <<  ,   << p.second <<  ) ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> const& v) {     int l = v.size();     for (int i = 0; i < l - 1; i++) out << v[i] <<    ;     if (l > 0) out << v[l - 1];     return out;   }   template <typename T>   void trace(const char* name, T&& arg1) {     cout << name <<   :   << arg1 << endl;   }   template <typename T, typename... Args>   void trace(const char* names, T&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     trace(comma + 1, args...);   }   const int inf = 1e9 + 10;   const long long int INF = 1e18 + 10;   const int MOD = 1e9 + 7;   const int MAXN = 2e5 + 10;   void solve() {     int n;     cin >> n;     int a[MAXN] = {0};     for (int i = 0; i < n; i += 1) cin >> a[i];     sort(a, a + n);     a[n + 1] = inf;     long long int sum = 0;     int ans = 0;     for (int i = 0; i < n; i += 1) {       if (a[i] >= sum)         ans++;       else {         int j = i;         while (j < n && a[j] < sum) j++;         if (a[j] >= sum) {           ans++;         }         i = j;       }       sum += a[i];     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000;   int dist[N * N], memo[N * N];   vector<pair<int, int>> H, T;   vector<int> ladj[N * N];   int vis[N * N];   inline int f(int x, int y) { return x * N + y; }   int bfs(int start) {     int n = N * N;     fill(dist, dist + n, INT_MAX);     fill(memo, memo + n, -1);     dist[start] = 0;     queue<int> Q;     Q.push(start);     while (!Q.empty()) {       int u = Q.front();       Q.pop();       for (int i = 0; i < (int)ladj[u].size(); i++) {         int v = ladj[u][i];         if (dist[v] > dist[u] + 1) {           dist[v] = dist[u] + 1;           Q.push(v);         }       }     }     return dist[0];   }   bool hasCycle(int start) {     if (vis[start] == -1) return true;     if (vis[start]) return false;     vis[start] = -1;     for (int i = 0; i < (int)ladj[start].size(); i++) {       int u = ladj[start][i];       if (hasCycle(u)) return true;     }     vis[start] = 1;     return false;   }   int dp(int u) {     int &ans = memo[u];     if (ans != -1) return ans;     ans = 0;     if (ladj[u].empty()) return 0;     for (int i = 0; i < (int)ladj[u].size(); i++) {       int v = ladj[u][i];       ans = max(ans, dp(v));     }     return ++ans;   }   int main() {     int h, t, r;     cin >> h >> t >> r;     int n;     cin >> n;     H.resize(n);     for (int i = 0; i < n; i++) cin >> H[i].first >> H[i].second;     int m;     cin >> m;     T.resize(m);     for (int i = 0; i < m; i++) cin >> T[i].first >> T[i].second;     for (int i = 0; i <= r; i++)       for (int j = 0; j <= r; j++)         if (i + j <= r) {           for (int k = 1; k <= n && k <= i; k++)             ladj[f(i, j)].push_back(                 f(i - k + H[k - 1].first, j + H[k - 1].second));           for (int k = 1; k <= m && k <= j; k++)             ladj[f(i, j)].push_back(                 f(i + T[k - 1].first, j - k + T[k - 1].second));         }     int start = f(h, t), ans = bfs(start);     if (ans < INT_MAX)       cout <<  Ivan  << endl << ans << endl;     else if (hasCycle(start))       cout <<  Draw  << endl;     else       cout <<  Zmey  << endl << dp(start) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char x = getchar();     int ans = 0, flag = 1;     while (!isdigit(x))       if (x ==  - )         flag = -1, x = getchar();       else         x = getchar();     while (isdigit(x)) ans = ans * 10 + x -  0 , x = getchar();     return ans * flag;   }   int n, m, d, head[100005], nxt[200005], pnt[200005], E, dp[100005][2];   void add_edge(int u, int v) {     pnt[E] = v;     nxt[E] = head[u];     head[u] = E++;   }   void dfs1(int u, int pre) {     for (int i = head[u]; i != -1; i = nxt[i]) {       int v = pnt[i];       if (v == pre) continue;       dfs1(v, u);       if (dp[v][0] == -1) continue;       if (dp[u][0] < dp[v][0] + 1) {         swap(dp[u][0], dp[u][1]);         dp[u][0] = dp[v][0] + 1;       } else if (dp[u][1] < dp[v][0] + 1) {         dp[u][1] = dp[v][0] + 1;       }     }   }   void dfs2(int u, int pre, int val) {     if (dp[u][0] <= val) {       swap(dp[u][0], dp[u][1]);       dp[u][0] = val;     } else if (dp[u][1] <= val) {       dp[u][1] = val;     }     for (int i = head[u]; i != -1; i = nxt[i]) {       int v = pnt[i];       if (v == pre) continue;       int tmp = dp[u][0];       if (tmp == dp[v][0] + 1) tmp = dp[u][1];       dfs2(v, u, tmp + 1);     }   }   signed main() {     memset(head, -1, sizeof(head));     n = read(), m = read(), d = read();     memset(dp, 128, sizeof(dp));     for (int i = 1; i <= m; i++) {       int u = read();       dp[u][0] = dp[u][1] = 0;     }     for (int i = 1; i < n; i++) {       int u = read(), v = read();       add_edge(u, v);       add_edge(v, u);     }     dfs1(1, 0);     dfs2(1, 0, -1e9);     int ans = 0;     for (int i = 1; i <= n; i++) {       if (dp[i][0] <= d) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using std::cerr;   using std::cin;   using std::cos;   using std::cout;   using std::endl;   using std::make_pair;   using std::map;   using std::max;   using std::min;   using std::next_permutation;   using std::pair;   using std::priority_queue;   using std::queue;   using std::random_shuffle;   using std::set;   using std::sin;   using std::sort;   using std::sqrt;   using std::stack;   using std::string;   using std::stringstream;   using std::swap;   using std::vector;   const long double PI = 3.14159265358979323846;   int main() {     string s;     cin >> s;     string s1 =  127 ;     if ((s.size() < s1.size()) || ((s.size() == s1.size()) && (s <= s1))) {       cout <<  byte  << endl;       return 0;     }     s1 =  32767 ;     if ((s.size() < s1.size()) || ((s.size() == s1.size()) && (s <= s1))) {       cout <<  short  << endl;       return 0;     }     s1 =  2147483647 ;     if ((s.size() < s1.size()) || ((s.size() == s1.size()) && (s <= s1))) {       cout <<  int  << endl;       return 0;     }     s1 =  9223372036854775807 ;     if ((s.size() < s1.size()) || ((s.size() == s1.size()) && (s <= s1))) {       cout <<  long  << endl;       return 0;     }     cout <<  BigInteger  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   long long power(long long base, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * base % mod;       base = base * base % mod;       b >>= 1;     }     return ret;   }   int n, m;   long long ans, cur;   int main() {     scanf( %d%d , &n, &m);     ans = 1LL * (n + m + 1) * power(m + 1, mod - 2) % mod;     for (int i = 1; i <= n; ++i) {       cur = (cur + power(i, mod - 2)) % mod;     }     cur = cur * m % mod + 1;     printf( %lld , ans * cur % mod);     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1e5 + 5;   const long long MOD = 998244353;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1);   const double ERR = 1e-10;   const int L = 40;   const int M = 30;   using namespace std;   long long mx = -1e18;   long long mn = 1e18;   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     long long a, b[MAXN], c = 0;     cin >> a;     if (a == 1) {       cout <<  0 ;       return 0;     }     for (int i = 0; i < a; i++) {       cin >> b[i];     }     sort(b, b + a);     for (int i = 0; i < a; i++) {       c += b[a - 1] - b[i];     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T getint() {     T x = 0, p = 1;     char ch;     do {       ch = getchar();     } while (ch <=    );     if (ch ==  - ) p = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * p;   }   mt19937 gen(chrono::system_clock::now().time_since_epoch().count());   template <typename T1, typename T2>   bool umin(T1 &x, const T2 &y) {     if (x > y) return x = y, true;     return false;   }   template <typename T1, typename T2>   bool umax(T1 &x, const T2 &y) {     if (x < y) return x = y, true;     return false;   }   const int maxn = (int)3e5 + 10;   const int inf = (int)1e9 + 5;   const int mod = (int)1e9 + 7;   const long long llinf = (long long)1e18 + 5;   const double pi = acos(-1.0);   int t[4 * maxn];   int pu[4 * maxn];   void push(int v) {     t[v + v] += pu[v];     pu[v + v] += pu[v];     t[v + v + 1] += pu[v];     pu[v + v + 1] += pu[v];     pu[v] = 0;   }   void add(int v, int l, int r, int x, int tl, int tr) {     if (l <= tl && tr <= r) {       t[v] += x;       pu[v] += x;       return;     }     push(v);     int tm = (tl + tr) / 2;     if (l <= tm) add(v + v, l, r, x, tl, tm);     if (r > tm) add(v + v + 1, l, r, x, tm + 1, tr);     t[v] = min(t[v + v], t[v + v + 1]);   }   int a[maxn], b[maxn];   int main() {     ios_base::sync_with_stdio(0);     int n, len, h;     cin >> n >> len >> h;     vector<int> x;     for (int i = (0); i < (len); i++) {       cin >> b[i];       b[i] = h - b[i];       x.push_back(b[i]);     }     for (int i = (0); i < (n); i++) {       cin >> a[i];       x.push_back(a[i]);     }     sort((x).begin(), (x).end());     x.erase(unique((x).begin(), (x).end()), x.end());     for (int i = (0); i < (len); i++)       b[i] = lower_bound((x).begin(), (x).end(), b[i]) - x.begin();     for (int i = (0); i < (n); i++)       a[i] = lower_bound((x).begin(), (x).end(), a[i]) - x.begin();     for (int i = (0); i < (len); i++) add(1, 0, b[i], -1, 0, maxn - 1);     int res = 0;     for (int i = (0); i < (n); i++) {       add(1, 0, a[i], 1, 0, maxn - 1);       if (i - len >= 0) add(1, 0, a[i - len], -1, 0, maxn - 1);       if (i + 1 >= len && t[1] >= 0) res++;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[201][201] = {0};   int n, m;   int main(int argc, char *argv[]) {     int x = 100;     int y = 100;     int ok = 0;     cin >> n >> m;     a[x][y] = n;     do {       ok = 0;       int max = y;       int min = x;       for (int i = x; i <= y; i++)         for (int j = x; j <= y; j++)           if (a[i][j] >= 4) {             ok = 1;             int numofant = a[i][j];             int mods = numofant % 4;             int temp = (numofant - mods) / 4;             a[i][j - 1] += temp;             a[i][j + 1] += temp;             a[i - 1][j] += temp;             a[i + 1][j] += temp;             a[i][j] = mods;           }       if (a[x - 1][100] >= 4) {         x--;         y++;       }     } while (ok == 1);     long long u, v;     int k[50005];     for (int i = 0; i < m; i++) {       cin >> u >> v;       u += 100;       v += 100;       if (u > 200 || u < 0 || v > 200 || v < 0)         k[i] = 0;       else         k[i] = a[u][v];     }     for (int i = 0; i < m; i++) cout << k[i] << endl;     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100005;   bool dp[501][501];   long long a[501], b[501];   signed main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     for (long long i = 1; i < n + 1; i++) {       cin >> a[i] >> b[i];     }     dp[0][0] = true;     long long tot = 0;     for (long long i = 1; i < n + 1; i++) {       tot += (a[i] + b[i]);       for (long long j = 0; j < min(k, a[i] + 1); j++) {         long long x = (a[i] - j) % k;         if (x + b[i] < k) continue;         for (long long l = 0; l < k; l++) {           if (!dp[i - 1][l]) continue;           long long rem = (l + j) % k;           dp[i][rem] = true;         }       }       long long j = a[i] % k;       for (long long l = 0; l < k; l++) {         if (!dp[i - 1][l]) continue;         long long rem = (l + j) % k;         dp[i][rem] = true;       }     }     for (long long i = 0; i < k; i++) {       if (dp[n][i]) {         long long ans = (tot - i) / k;         cout << ans;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, l, m, n;     cin >> n;     if (n & 1)       cout << 1 << endl;     else       cout << 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long i, a = 0, b, j, b1[26] = {}, b2[26] = {};     string s1, s2;     vector<long> v1, v2;     cin >> s1 >> s2;     if (s1.size() != s2.size()) {       cout <<  NO ;       return 0;     }     for (i = 0; i < s1.size(); i++) {       if (s1[i] != s2[i]) {         a++;         v1.push_back(i);       }     }     if (a != 2) {       cout <<  NO ;       return 0;     }     if ((s1[v1[0]] == s2[v1[1]]) && (s2[v1[0]] == s1[v1[1]]))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   using namespace std;   const int N = 7005;   const int M = 200000;   const long long mod = 1e9 + 7;   const long long inf = 0x3f3f3f3f;   namespace FastIO {   template <typename tp>   inline void read(tp& x) {     x = 0;     register char c = getchar();     register bool f = 0;     for (; c <  0  || c >  9 ; f |= (c ==  - ), c = getchar())       ;     for (; c >=  0  && c <=  9 ; x = (x << 3) + (x << 1) + c -  0 , c = getchar())       ;     if (f) x = -x;   }   template <typename tp>   inline void write(tp x) {     if (x == 0) return (void)(putchar( 0 ));     if (x < 0) putchar( - ), x = -x;     long long pr[20];     register long long cnt = 0;     for (; x; x /= 10) pr[++cnt] = x % 10;     while (cnt) putchar(pr[cnt--] +  0 );   }   template <typename tp>   inline void writeln(tp x) {     write(x);     putchar(  n );   }   }  // namespace FastIO   using namespace FastIO;   struct line {     int l, r, val;     line() {}     line(int l, int r, int val) {       this->l = l;       this->r = r;       this->val = val;     }   };   int n, m, lx[M], ly[M];   vector<line> xx[N];   int solve(int d, int x, int y) {     set<int> ans;     for (int i = d; i <= n; i++) {       for (int j = 0; j < xx[i].size(); j++) {         line& c = xx[i][j];         if (c.l <= y && c.r >= x) ans.insert(c.val);       }       x = (lx[x] == -1 ? ly[x] : lx[x]);       y = ly[y];     }     return ans.size();   }   void init() {     int cnt = 1, p = 3;     memset(lx, -1, sizeof(lx));     memset(ly, -1, sizeof(ly));     lx[1] = 1;     ly[1] = 2;     for (int i = 2; i < M; i++) {       if ((1 << cnt) == i) cnt++, lx[i] = p++;       ly[i] = p++;     }   }   int flag, d, x, y, val;   int main() {     init();     read(n), read(m);     for (int i = 0; i < m; i++) {       read(flag);       if (flag == 1)         read(d), read(x), read(y), read(val), xx[d].push_back(line(x, y, val));       else         read(d), read(x), writeln(solve(d, x, x));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int binSearch(int *a, int n, int x) {     int l = 0;     int r = n - 1;     while (l < r) {       int mid = (l + r) / 2;       if (a[mid] == x)         return mid;       else if (a[mid] < x)         l = mid + 1;       else         r = mid - 1;     }     return -1;   }   int main() {     map<long long, long long> mp;     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]] = i + 1;     }     int q;     cin >> q;     long long cntFirst = 0, cntSecond = 0;     for (int i = 0; i < q; i++) {       int x;       cin >> x;       long long res = mp[x];       cntFirst += res;       cntSecond += (n - res + 1);     }     cout << cntFirst <<     << cntSecond;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx )   using namespace std;   const int mod = 1e9 + 7;   const int N = 2e5 + 4;   int a[N], v[N], s[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       v[i] = 1;     }     sort(a, a + n);     int j = 0;     int res = 0;     int cur = 0;     for (int i = 0; i < n; i++) {       while (j < n && a[j] - a[i] < m) {         cur += v[j];         s[j] = cur;         if (cur >= k && v[j] == 1) {           v[j] = 0;           res++;           cur--;         }         j++;       }       if (v[i]) cur--;     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 10000;   struct Big {     vector<int> *data;     int size() const { return data->size(); }     bool operator<(const Big &a) const {       if (size() != a.size()) return size() < a.size();       for (int i = (int)size() - 1; i >= 0; i--)         if ((*data)[i] != (*a.data)[i]) return (*data)[i] < (*a.data)[i];       return false;     }     void Carry() {       for (int i = 0; i < size(); i++)         if ((*data)[i] >= MOD) {           if (i + 1 == size()) data->push_back(0);           (*data)[i + 1] += (*data)[i] / MOD;           (*data)[i] %= MOD;         }     }     Big operator*(const Big &a) const {       Big ans;       ans.data->resize((int)(size() + a.size()) - 1, 0);       for (int i = 0; i < (int)size(); i++)         for (int j = 0; j < (int)a.size(); j++)           (*ans.data)[i + j] += (*data)[i] * (*a.data)[j];       ans.Carry();       return ans;     }     void operator*=(const Big &a) { (*this) = (*this) * a; }     void operator++() {       (*data)[0]++;       Carry();     }     Big() : data(new vector<int>()) {}     Big(const int b) : data(new vector<int>()) {       data->push_back(b);       Carry();     }     Big(const Big &a) : data(new vector<int>()) {       data->resize(a.size());       for (int i = 0; i < a.size(); i++) (*data)[i] = (*a.data)[i];     }   };   void getmax(Big &a, const Big &b) {     if (a < b) a = b;   }   void Print(const Big &a) {     bool printed = false;     for (int i = (int)a.size() - 1; i >= 0; i--) {       const int v = (*a.data)[i];       printf(printed ?  %04d  :  %d , v);       printed = true;     }   }   int N;   Big DP[700][3];   vector<int> ET[700];   struct Type {     Big yes, no, one;     Type() {}     Type(const Big &_yes, const Big &_no, const Big &_one)         : yes(_yes), no(_no), one(_one) {}     bool operator<(const Type &t) const { return no * t.yes < yes * t.no; }   };   Big Dfs(const int u, const int fa, const int dep) {     Big &ans = DP[u][dep];     if (!(ans.data->empty())) return ans;     if (true) {       ans = Big(1);       for (const int nxt : ET[u])         if (nxt != fa) ans *= Dfs(nxt, u, 2);     }     if (dep == 0) return ans;     vector<Type> chinfo;     for (const int nxt : ET[u])       if (nxt != fa)         chinfo.push_back(Type(Dfs(nxt, u, 0), Dfs(nxt, u, 2), Dfs(nxt, u, 1)));     sort(chinfo.begin(), chinfo.end());     const int sz = chinfo.size();     if (true) {       vector<Big> yes, no, part;       yes.resize(sz + 1), no.resize(sz + 1), part.resize(sz + 1);       if (true) {         Big v1 = Big(1), v2 = Big(dep == 1 ? 2 : 1);         yes[0] = Big(v1), part[0] = Big(v2);         for (int i = 1; i <= sz; i++)           v1 *= chinfo[i - 1].yes, ++v2, yes[i] = Big(v1), part[i] = Big(v2);         v1 = Big(1);         no[sz] = Big(v1);         for (int i = sz - 1; i >= 0; i--) v1 *= chinfo[i].no, no[i] = Big(v1);       }       for (int i = 0; i <= sz; i++) getmax(ans, yes[i] * no[i] * part[i]);     }     if (dep == 1) return ans;     if (sz) {       vector<Big> left, right;       left.resize(sz), right.resize(sz);       Big tmp = Big(1);       left[0] = Big(tmp);       for (int i = 1; i < sz; i++) tmp *= chinfo[i - 1].no, left[i] = Big(tmp);       tmp = Big(1);       right[sz - 1] = Big(tmp);       for (int i = sz - 2; i >= 0; i--)         tmp *= chinfo[i + 1].no, right[i] = Big(tmp);       for (int i = 0; i < sz; i++)         getmax(ans, left[i] * right[i] * chinfo[i].one);     }     assert(dep == 2);     return ans;   }   int main() {     while (scanf( %d , &N) == 1) {       for (int i = 0; i < N; i++) ET[i].clear();       for (int i = 0, a, b; i < N - 1; i++) {         scanf( %d%d , &a, &b), a--, b--;         ET[a].push_back(b), ET[b].push_back(a);       }       Big ans = Big(0);       for (int i = 0; i <= 0; i++) {         for (int j = 0; j < N; j++)           for (int k = 0; k < 3; k++) DP[j][k].data->clear();         Big ta = Dfs(i, -1, 2);         getmax(ans, ta);       }       Print(ans);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     string s[105];     set<char> ms;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     long long ans = 1;     for (int i = 0; i < m; i++) {       ms.clear();       for (int j = 0; j < n; j++) ms.insert(s[j][i]);       ans = ans * ms.size() % 1000000007;     }     cout << ans % 1000000007;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void read(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void readc(char &x) {     char c;     while (((c = getchar()) ==    ) || c ==   n )       ;     x = c;   }   inline void writes(string s) { puts(s.c_str()); }   inline void writeln() { writes(  ); }   inline void writei(int x) {     if (x < 0) {       putchar( - );       x = abs(x);     }     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   inline void writell(long long x) {     if (x < 0) {       putchar( - );       x = abs(x);     }     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   int n, m, i, j, lst, t[100005], w[100005], col[100005], dfn[100005],       fa[100005][19], dep[100005], stk[100005], tp, blk, ti, a[100005],       ixt[100005], ans[100005], cur, dup[100005], ixf[100005], cq, duv[100005];   vector<int> e[100005], ee[100005], all, tmp;   vector<pair<int, int> > dur[100005];   int seq[100005];   void add(int x, int y) {     all.push_back(x);     all.push_back(y);     ee[x].push_back(y);     ee[y].push_back(x);   }   int lca(int x, int y) {     if (dep[x] < dep[y]) {       swap(x, y);     }     int t = dep[x] - dep[y], i;     for ((i) = (18); (i) >= (0); (i)--) {       if ((t >> i) & 1) {         x = fa[x][i];       }     }     if (x == y) return x;     for ((i) = (18); (i) >= (0); (i)--) {       if (fa[x][i] != fa[y][i]) {         x = fa[x][i];         y = fa[y][i];       }     }     return fa[x][0];   }   void dfs(int x) {     dfn[x] = ++ti;     for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {       dep[*it] = dep[x] + 1;       dfs(*it);     }   }   void dfs2(int x) {     for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {       dfs2(*it);       w[x] += w[*it];     }   }   bool cmp(int x, int y) { return dfn[x] < dfn[y]; }   void ins(int x) {     if (tp <= 1) {       stk[++tp] = x;       return;     }     int z = lca(stk[tp], x);     if (z == stk[tp]) {       stk[++tp] = x;       return;     }     while (tp > 1 && dfn[stk[tp - 1]] >= dfn[z]) {       add(stk[tp], stk[tp - 1]);       tp--;     }     if (stk[tp] != z) {       add(stk[tp], z);       stk[tp] = z;     }     stk[++tp] = x;   }   void ine(int x, int y) {     int id = y;     duv[id] = 0;     y = fa[y][0];     tmp.clear();     while (y != x) {       ixt[y] = 1;       if (!col[y]) tmp.push_back(t[y] - w[y]);       y = fa[y][0];     }     sort(tmp.begin(), tmp.end());     dur[id].clear();     for (__typeof((tmp).begin()) it = (tmp).begin(); it != (tmp).end(); it++) {       if (dur[id].empty()) {         dur[id].push_back(make_pair(*it, 1));       } else if (dur[id].back().first == *it) {         dur[id].back().second++;       } else {         dur[id].push_back(make_pair(*it, dur[id].back().second + 1));       }     }     for (dup[id] = 0; dup[id] < dur[id].size(); dup[id]++)       if (duv[id] <= dur[id][dup[id]].first) break;     dup[id]--;     cur += (dup[id] == -1 ? 0 : dur[id][dup[id]].second);   }   void dfs3(int x, int fa) {     ixf[x] = fa;     ixt[x] = 1;     if (!col[x]) cur += (w[x] > t[x]);     for (__typeof((ee[x]).begin()) it = (ee[x]).begin(); it != (ee[x]).end();          it++)       if (*it != fa) {         ine(x, *it);         dfs3(*it, x);       }   }   void dfs4(int x) {     if (!ixt[x]) {       if (!col[x]) cur += (w[x] > t[x]);     }     for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {       dfs4(*it);     }   }   void upe(int x, int dlt) {     duv[x] += dlt;     cur -= (dup[x] == -1 ? 0 : dur[x][dup[x]].second);     while (dup[x] + 1 < dur[x].size() && duv[x] > dur[x][dup[x] + 1].first)       dup[x]++;     while (dup[x] > -1 && duv[x] <= dur[x][dup[x]].first) dup[x]--;     cur += (dup[x] == -1 ? 0 : dur[x][dup[x]].second);   }   void work(int x) {     int dlt = x / abs(x), fst = 1;     x = abs(x);     while (x) {       if (!col[x]) cur -= (w[x] > t[x]);       if (fst) col[x] += dlt;       fst = 0;       w[x] += dlt;       if (!col[x]) cur += (w[x] > t[x]);       if (x != 1) upe(x, dlt);       x = ixf[x];     }   }   void solve(int ed) {     int i;     cur = 0;     all.clear();     memset(w, 0, sizeof(w));     memset(ixt, 0, sizeof(ixt));     for (((i)) = (1); ((i)) <= ((lst)); ((i))++) {       if (seq[i] > 0) {         w[seq[i]] = col[seq[i]] = 1;       } else {         w[-seq[i]] = col[-seq[i]] = 0;       }     }     dfs2(1);     for ((i) = (lst + 1); (i) <= (ed); (i)++) {       a[i - lst] = abs(seq[i]);     }     sort(a + 1, a + (ed - lst) + 1, cmp);     stk[tp = 1] = 1;     for (((i)) = (1); ((i)) <= ((ed - lst)); ((i))++) {       if (a[i] != 1 && a[i] != a[i - 1]) {         ins(a[i]);       }     }     while (tp >= 2) {       add(stk[tp], stk[tp - 1]);       tp--;     }     dfs3(1, 0);     dfs4(1);     for ((i) = (lst + 1); (i) <= (ed); (i)++) {       work(seq[i]);       printf( %d  , cur);     }     for (__typeof((all).begin()) it = (all).begin(); it != (all).end(); it++) {       ee[*it].clear();     }   }   int main() {     read(n);     read(m);     blk = sqrt(m) * 2;     for ((i) = (2); (i) <= (n); (i)++) {       scanf( %d , &fa[i][0]);       e[fa[i][0]].push_back(i);     }     for (((j)) = (1); ((j)) <= ((18)); ((j))++)       for (((i)) = (1); ((i)) <= ((n)); ((i))++) {         fa[i][j] = fa[fa[i][j - 1]][j - 1];       }     for (((i)) = (1); ((i)) <= ((n)); ((i))++) {       scanf( %d , &t[i]);     }     dfs(1);     lst = 0;     for (((i)) = (1); ((i)) <= ((m)); ((i))++) {       scanf( %d , &seq[i]);       if (i % blk == 0) {         solve(i);         lst = i;       }     }     if (lst < m) solve(m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int main() {     int t;     int n, m;     long long s = 0;     cin >> n >> m;     vector<long long> a(m);     for (int i = 0; i < m; i++) {       cin >> a[i];     }     s += (a[0] - 1);     for (int i = 1; i < m; i++) {       if (a[i] >= a[i - 1]) {         s += (a[i] - a[i - 1]);       } else {         s += (n - a[i - 1]);         s += (a[i]);       }     }     cout << s << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int id;     bool ok;     int row;     bool operator<(const point &p) const {       return (id == p.id) ? ok < p.ok : id < p.id;     }   };   point a[600100];   vector<int> edge[300100];   int dp[300100];   int truoc[300100];   bool ok[300100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y, z;       cin >> x >> y >> z;       a[i << 1] = {y, 1, x};       a[i << 1 | 1] = {z + 1, 0, x};     }     sort(a, a + 2 * m);     multiset<int, greater<int> > b;     multiset<int> c;     for (int i = 0; i < 2 * m; i++) {       if (a[i].ok) {         if (b.upper_bound(a[i].row) != b.end()) {           edge[*b.upper_bound(a[i].row)].push_back(a[i].row);         }         if (c.upper_bound(a[i].row) != c.end()) {           edge[a[i].row].push_back(*c.upper_bound(a[i].row));         }         b.insert(a[i].row);         c.insert(a[i].row);       } else {         b.erase(b.find(a[i].row));         c.erase(c.find(a[i].row));       }     }     for (int i = 1; i < n; i++) {       dp[i] = max(dp[i], 1);       for (auto x : edge[i]) {         if (dp[x] < dp[i] + 1) {           dp[x] = dp[i] + 1;           truoc[x] = i;         }       }     }     int max1 = -1;     int id;     for (int i = 1; i <= n; i++) {       if (dp[i] > max1) {         max1 = dp[i];         id = i;       }     }     cout << n - max1 <<   n ;     int cur = id;     while (cur != 0) {       ok[cur] = 1;       cur = truoc[cur];     }     for (int i = 1; i <= n; i++) {       if (!ok[i]) {         cout << i <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int w, m;     cin >> w >> m;     vector<int> v;     while (m > 0) {       v.push_back(m % w);       m /= w;     }     int ok = 1;     for (int i = 0; i < v.size(); i++) {       if (v[i] != 0 && v[i] != 1) {         v[i] -= w;         if (v[i] != -1 && v[i] != 0) {           ok = 0;           break;         }         if (i + 1 != v.size()) v[i + 1]++;       }     }     if (ok == 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, sum = 0;     cin >> a >> b;     sum = (a * b) / 2;     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int pow_mod(long long int a, long long int b) {     long long int res = 1;     while (b != 0) {       if (b & 1) {         res = (res * a) % 1000000007;       }       a = (a * a) % 1000000007;       b /= 2;     }     return res;   }   void solve() {     long long int x1, y1, z1;     cin >> x1 >> y1 >> z1;     long long int x2, y2, z2;     cin >> x2 >> y2 >> z2;     long long int ans = 0;     ans = min(z1, y2);     ans *= 2;     z1 -= min(z1, y2);     z2 -= min(z2, z1);     z2 -= min(z2, x1);     ans -= z2 * 2;     cout << ans << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t1, t2, x1, x2, t0, ans1, ans2, z1, z2, y20;   inline void trr(const long long& y1_gdssdfjsdgf, const long long& y2) {     if (y1_gdssdfjsdgf == 0 && y2 == 0) return;     if (ans1 == -1) {       if ((y1_gdssdfjsdgf * t1 + y2 * t2) >= t0 * (y1_gdssdfjsdgf + y2)) {         ans1 = y1_gdssdfjsdgf;         ans2 = y2;       }       return;     }     z1 = (ans1 * t1 + ans2 * t2) * (y1_gdssdfjsdgf + y2) -          t0 * (y1_gdssdfjsdgf + y2) * (ans1 + ans2);     z2 = (y1_gdssdfjsdgf * t1 + y2 * t2) * (ans1 + ans2) -          t0 * (y1_gdssdfjsdgf + y2) * (ans1 + ans2);     if ((z1 >= 0 && z2 >= 0) &&         (z1 > z2 || ((z1 == z2) && (y1_gdssdfjsdgf + y2 > ans1 + ans2)))) {       ans1 = y1_gdssdfjsdgf;       ans2 = y2;     }   }   int main() {     cin >> t1 >> t2 >> x1 >> x2 >> t0;     ans1 = -1;     ans2 = -1;     trr(0, x2);     trr(x1, 0);     trr(x1, x2);     for (long long y1_gdssdfjsdgf = 0; y1_gdssdfjsdgf <= x1; y1_gdssdfjsdgf++)       if (t2 != t0) {         y20 = ((t0 - t1) * y1_gdssdfjsdgf) / (t2 - t0);         for (long long y2 = max(0LL, y20 - 2); y2 <= min(x2, y20 + 2); y2++) {           trr(y1_gdssdfjsdgf, y2);         }       }     cout << ans1 <<     << ans2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 10;   const int mod = 998244353;   int f[N][N], g[N][N];   int mn[N][N], indl[N], indr[N];   bool bz[N][N];   int a[1000001];   int n, m;   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     int x = m;     m = 1;     for (int i = 2; i <= x; i++)       if (a[i] != a[m]) a[++m] = a[i];     for (int i = 1; i <= m; i++) {       if (!indl[a[i]]) indl[a[i]] = i;       indr[a[i]] = i;     }     if (m > 3 * n) {       printf( 0 n );       return 0;     }     for (int i = 1; i <= n; i++)       for (int j = indl[i]; j <= indr[i]; j++)         if (a[j] < i) {           printf( 0 n );           return 0;         }     for (int i = 1; i <= m; i++) {       mn[i][i] = a[i];       for (int j = i + 1; j <= m; j++) mn[i][j] = min(mn[i][j - 1], a[j]);     }     for (int i = 1; i <= m + 1; i++) f[i][i - 1] = g[i][i - 1] = 1;     for (int i = 1; i <= m; i++)       for (int l = 1; l + i - 1 <= m; l++) {         int r = i + l - 1;         int x = mn[l][r], idl = indl[x], idr = indr[x];         if (idl > r || idr < l) continue;         int v = 1;         int lll = idl;         while (lll != idr) {           int rrr = lll + 1;           while (a[rrr] != a[lll]) rrr++;           v = (long long)v * f[lll + 1][rrr - 1] % mod;           lll = rrr;         }         for (int mid = idr; mid <= r; mid++)           g[l][r] = (g[l][r] + (long long)f[l][idl - 1] * f[mid + 1][r] % mod *                                    v % mod * f[idr + 1][mid] % mod) %                     mod;         for (int ll = l; ll <= idl; ll++)           f[l][r] = (f[l][r] + (long long)g[ll][r] * f[l][ll - 1]) % mod;       }     printf( %d n , f[1][m]);     return 0;   }


#include <bits/stdc++.h>   int a[300004], pos[300004];   using namespace std;   int main() {     int n, temp;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       pos[a[i]] = i;     }     bool flag = false;     for (int i = 1; i <= n && !flag; i++)       for (int j = i + 1; j <= min(n, i + 5) && !flag; j++) {         temp = 2 * a[j] - a[i];         if (temp <= n && temp > 0 && pos[temp] > j) flag = 1;         temp = 2 * a[i] - a[j];         if (temp <= n && temp > 0 && pos[temp] < i) flag = 1;       }     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


/*   ID: c4ts0up   LANG: C++   TASK:    URL:    */      #include <bits/stdc++.h>   using namespace std;      typedef long long ll;   typedef long double ld;   #define pb push_back   #define ff first   #define ss second   #define endl   n       void fast_io() {       ios_base::sync_with_stdio(false);       cin.tie(NULL);   }      const ll MOD = 1e9+7, NMAX = 1005;   ll t, n, k;      ll dp[NMAX][NMAX][2];   bool vis[NMAX][NMAX][2];      // devuelve la cantidad de particulas generadas por esta   ll Generadas(ll tam, ll pla, bool dir) {       // Caso base       if (tam == 1) return 1LL;       else if (pla < 0 || pla >= n) return 1LL;       // Caso dp       else if (vis[tam][pla][dir]) return dp[tam][pla][dir];       // Caso recursivo       else {           if (dir) dp[tam][pla][dir] = (Generadas(tam-1, pla-1, !dir) + Generadas(tam, pla+1, dir))%MOD;           else dp[tam][pla][dir] = (Generadas(tam-1, pla+1, !dir) + Generadas(tam, pla-1, dir))%MOD;              vis[tam][pla][dir] = true;           return dp[tam][pla][dir];       }   }      int main() {       /*//       freopen( entrada.in ,  r , stdin);       freopen( salida.out ,  w , stdout);       //*/          cin >> t;       while (t--) {           cin >> n >> k;           for (int i=0; i<=n; i++) {               for (int j=0; j<=k; j++) vis[j][i][0] = vis[j][i][1] = false;            }           cout << Generadas(k, 0, 1) << endl;       }       //system( pause );       return 0;   }


#include <bits/stdc++.h>   std::string colors( RGBYW );   struct Card {     int color;     int number;     bool operator<(const Card& rhs) const {       if (color == rhs.color)         return (number < rhs.number);       else         return color < rhs.color;     }   };   int mapColor(char color) {     size_t pos = colors.find_first_of(color);     if (pos != std::string::npos) {       return pos;     }     return -1;   }   bool isNumberHinted(int number, long long hint) {     long long mask = (1 << number) << 5;     return hint & mask;   }   bool isColorHinted(int color, long long hint) {     long long mask = (1 << color);     return hint & mask;   }   int bitCount(long long n) {     int count = 0;     while (n > 0) {       count++;       n = n & (n - 1);     }     return count;   }   void codeforces442a() {     int n = 0;     int minAns = 10;     std::cin >> n;     std::set<Card> cards;     for (int i = 0; i < n; ++i) {       Card card;       char color;       char number;       std::cin >> color;       std::cin >> number;       card.color = mapColor(color);       card.number = number -  1 ;       cards.insert(card);     }     if (cards.size() == 1) {       std::cout <<  0 ;       return;     }     for (long long hint = 0; hint < (1 << 10); ++hint) {       if (bitCount(hint) >= minAns) continue;       bool isValid = true;       for (std::set<Card>::iterator i = cards.begin();            i != cards.end() && isValid; ++i)         for (std::set<Card>::iterator j = cards.begin();              j != cards.end() && isValid; ++j) {           if (i != j) {             bool areHintedAsDifferent = false;             Card firstCard = *i;             Card secondCard = *j;             if (firstCard.color == secondCard.color) {               areHintedAsDifferent = isNumberHinted(firstCard.number, hint) ||                                      isNumberHinted(secondCard.number, hint);             } else if (firstCard.number == secondCard.number) {               areHintedAsDifferent = isColorHinted(firstCard.color, hint) ||                                      isColorHinted(secondCard.color, hint);             } else {               areHintedAsDifferent = isNumberHinted(firstCard.number, hint) ||                                      isNumberHinted(secondCard.number, hint) ||                                      isColorHinted(firstCard.color, hint) ||                                      isColorHinted(secondCard.color, hint);             }             if (!areHintedAsDifferent) {               isValid = false;             }           }         }       if (isValid) {         int numHints = bitCount(hint);         if (minAns > numHints) {           minAns = numHints;         }       }     }     std::cout << minAns;   }   int main() {     codeforces442a();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, m[1001][1001];   void solve() {     cin >> n >> a >> b;     if (a > 1 and b > 1) {       cout <<  NO  <<   n ;       return;     }     if (a == 1 and b == 1) {       if (n == 1) {         cout <<  YES  <<   n ;         cout << 0;         return;       }       if (n <= 3) {         cout <<  NO  <<   n ;         return;       }       for (int i = 1; i < n; i++) {         m[i][i + 1] = 1;         m[i + 1][i] = 1;       }       cout <<  YES  <<   n ;       for (int i = 1; i < n + 1; i++) {         for (int j = 1; j < n + 1; j++) {           cout << m[i][j];         }         cout <<   n ;       }       return;     }     if (a == 1) {       for (int i = 1; i < b; i++) {         for (int j = 1; j < n + 1; j++) {           if (i == j) continue;           m[i][j] = 1;           m[j][i] = 1;         }       }       cout <<  YES  <<   n ;       for (int i = 1; i < n + 1; i++) {         for (int j = 1; j < n + 1; j++) {           cout << m[i][j];         }         cout <<   n ;       }       return;     }     if (b == 1) {       for (int i = a; i < n + 1; i++) {         for (int j = a; j < n + 1; j++) {           if (i == j) continue;           m[i][j] = 1;           m[j][i] = 1;         }       }       cout <<  YES  <<   n ;       for (int i = 1; i < n + 1; i++) {         for (int j = 1; j < n + 1; j++) {           cout << m[i][j];         }         cout <<   n ;       }       return;     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};   long long k;   int n, m, h[N][N];   bool mark[N][N];   int pre[N * N], sz[N * N];   int find(int x) { return pre[x] = (pre[x] == x ? x : find(pre[x])); }   bool merge(int x, int y) {     int a = find(x), b = find(y);     if (a == b) return false;     if (rand() % 2) swap(a, b);     sz[b] += sz[a];     pre[a] = b;     return true;   }   inline int id(int i, int j) { return i * m + j; }   int res[N][N];   void dfs(int i, int j, int v) {     if (i < 0 || i >= n || j < 0 || j >= m || h[i][j] < v) return;     if (res[i][j] || !k) return;     res[i][j] = v;     k -= v;     for (int d = 0; d < 4; d++) {       int ni = i + di[d], nj = j + dj[d];       dfs(ni, nj, v);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> k;     vector<tuple<int, int, int>> pos;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         pre[id(i, j)] = id(i, j);         sz[id(i, j)] = 1;         cin >> h[i][j];         pos.emplace_back(h[i][j], i, j);       }     sort(pos.rbegin(), pos.rend());     bool good = false;     for (auto p : pos) {       int v, i, j;       tie(v, i, j) = p;       for (int d = 0; d < 4; d++) {         int ni = i + di[d], nj = j + dj[d];         if (ni < 0 || ni >= n || nj < 0 || nj >= m || !mark[ni][nj]) continue;         merge(id(i, j), id(ni, nj));       }       mark[i][j] = true;       if (k % v == 0 && k / v <= sz[find(id(i, j))]) {         dfs(i, j, h[i][j]);         good = true;         break;       }     }     if (good) {       cout <<  YES n ;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) cout << res[i][j] <<    ;         cout <<   n ;       }     } else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ans, n, m, x, y;     cin >> n >> m;     int lo = (n + 1) / 2;     ans = (lo + m - 1) / m;     ans *= m;     if (ans > n)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, dp[1 << 19][21], a[22][22], ans;   long long lowbit(long long x) { return (x & (-x)); }   int main() {     memset(a, 0, sizeof(a));     memset(dp, 0, sizeof(dp));     scanf( %lld%lld , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       a[x - 1][y - 1] = a[y - 1][x - 1] = 1;     }     for (int i = 0; i <= n; i++) dp[1 << i][i] = 1;     for (int mask = 1; mask < (1 << n); mask++) {       for (int ed = 0; ed < n; ed++) {         if (!dp[mask][ed]) continue;         for (int nxt = 0; nxt < n; nxt++) {           if (!a[ed][nxt]) continue;           if (lowbit(mask) > (1 << nxt)) continue;           if (mask & (1 << nxt)) {             if ((lowbit(mask)) == (1 << nxt)) ans += dp[mask][ed];           } else             dp[(mask | (1 << nxt))][nxt] += dp[mask][ed];         }       }     }     printf( %lld , (ans - m) / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename P, typename Q>   ostream& operator<<(ostream& os, pair<P, Q> p) {     os <<  (  << p.first <<  ,  << p.second <<  ) ;     return os;   }   int main(int argc, char* argv[]) {     int n, k;     while (scanf( %d%d , &n, &k) == 2) {       vector<int> v;       for (int i = 0; i < n; ++i) {         int m;         scanf( %d , &m);         v.push_back(m);       }       long long int sum = 0;       for (int i = 0; i < n; ++i) {         long long int s = sum + i + 1;         if (k <= s) {           printf( %d n , v[k - sum - 1]);           break;         }         sum = s;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buf[256];   signed main() {     long long n;     scanf( %lld , &n);     stack<long long> cur;     set<long long> si;     long long tmp = 1, ans = 0;     for (long long i = 0; i < n * 2; i++) {       scanf( %s , buf);       string s(buf);       if (s ==  add ) {         long long x;         scanf( %lld , &x);         cur.push(x);       }       if (s ==  remove ) {         if (cur.empty() || cur.top() == tmp) {           if (!cur.empty()) cur.pop();           tmp++;         } else {           while (!cur.empty()) {             si.insert(cur.top());             cur.pop();           }           si.erase(tmp);           tmp++;           ans++;         }       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300100, mod = 998244353;   inline void Add(int &a, int b) { a = a + b >= mod ? a + b - mod : a + b; }   int head[maxn], nxt[maxn << 1], ver[maxn << 1], tot;   inline void addedge(int a, int b) {     nxt[++tot] = head[a];     ver[tot] = b;     head[a] = tot;     nxt[++tot] = head[b];     ver[tot] = a;     head[b] = tot;   }   int n, f[maxn][2], g[maxn][2], h[maxn];   inline void treedp(int x, int fat) {     f[x][0] = f[x][1] = g[x][0] = g[x][1] = h[x] = 1;     for (int i = head[x]; i; i = nxt[i]) {       int y = ver[i];       if (y == fat) continue;       treedp(y, x);       f[x][0] = (0ll + f[y][0] + f[y][1] + g[y][0] + g[y][1] + h[y]) % mod *                 f[x][0] % mod;       f[x][1] = (0ll + f[y][0] + g[y][0] + g[y][1] + h[y]) % mod * f[x][1] % mod;       h[x] = (0ll + g[y][0] + g[y][1] + h[y]) % mod * h[x] % mod;     }     g[x][0] = (f[x][0] + mod - h[x]) % mod;     g[x][1] = (f[x][1] + mod - h[x]) % mod;   }   int main() {     scanf( %d , &n);     for (int i = 1, a, b; i < n; i++) scanf( %d%d , &a, &b), addedge(a, b);     treedp(1, 0);     int ans = (0ll + g[1][0] + g[1][1] + h[1] - 1 + mod) % mod;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int newMask[1000000][4];   bool canMove[1000000][4];   int mv[][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   int len;   int getMove(int x, int y) {     if (x == 1 && y == 0) return 0;     if (x == 0 && y == 1) return 1;     if (x == -1 && y == 0) return 2;     return 3;   }   vector<pair<int, int> > getLoc(int mask) {     vector<pair<int, int> > ret;     ret.push_back(make_pair(0, 0));     for (int i = 0; i + 1 < len; i++) {       int j = mask % 4;       mask /= 4;       int x = ret[ret.size() - 1].first + mv[j][0];       int y = ret[ret.size() - 1].second + mv[j][1];       ret.push_back(make_pair(x, y));     }     reverse(ret.begin(), ret.end());     return ret;   }   int getMask(vector<pair<int, int> > loc) {     int ret = 0;     for (int i = 0; i + 1 < loc.size(); i++) {       int x = loc[i].first - loc[i + 1].first;       int y = loc[i].second - loc[i + 1].second;       ret = ret * 4 + getMove(x, y);     }     return ret;   }   void precalc() {     int num = len - 1;     for (int i = 0; i < (1 << (2 * num)); i++) {       vector<pair<int, int> > loc = getLoc(i);       for (int x = 0; x < 4; x++) {         bool ok = 1;         for (int j = 1; j < loc.size(); j++) {           if (mv[x][0] == loc[j].first && mv[x][1] == loc[j].second) ok = 0;         }         if (ok) {           canMove[i][x] = true;           vector<pair<int, int> > newLoc = loc;           newLoc.erase(newLoc.begin());           newLoc.push_back(make_pair(mv[x][0], mv[x][1]));           newMask[i][x] = getMask(newLoc);         }       }     }   }   pair<int, int> l[10];   int n, m;   char a[100][100];   int dist[16][16][70000];   bool vis[16][16][70000];   int X, Y;   int ans;   int bfs(pair<int, int> v, int mask) {     ans = 1000000000;     queue<pair<int, int> > q1;     queue<int> q2;     q1.push(v);     q2.push(mask);     vis[v.first][v.second][mask] = 1;     while (!q1.empty()) {       v = q1.front();       q1.pop();       mask = q2.front();       q2.pop();       if (v == make_pair(X, Y)) ans = min(ans, dist[v.first][v.second][mask]);       for (int x = 0; x < 4; x++) {         if (!canMove[mask][x]) continue;         pair<int, int> u = v;         u.first += mv[x][0];         u.second += mv[x][1];         if (u.first < 0 || u.first >= n || u.second < 0 || u.second >= m ||             a[u.first][u.second] ==  # )           continue;         int uMask = newMask[mask][x];         if (vis[u.first][u.second][uMask]) continue;         dist[u.first][u.second][uMask] = 1 + dist[v.first][v.second][mask];         vis[u.first][u.second][uMask] = 1;         q1.push(u);         q2.push(uMask);       }     }     if (ans == 1000000000) return -1;     return ans;   }   void getInput() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] >=  1  && a[i][j] <=  9 )           len++, l[a[i][j] -  0 ] = make_pair(i, j);         if (a[i][j] ==  @ ) X = i, Y = j;       }     }     vector<pair<int, int> > fLoc;     for (int i = len; i >= 1; i--) fLoc.push_back(l[i]);     precalc();     int mask = getMask(fLoc);     cout << bfs(fLoc[fLoc.size() - 1], mask) << endl;   }   int main() { getInput(); }


#include <bits/stdc++.h>   using namespace std;   int a[120], n, t;   bool check();   int main() {     cin >> t;     while (t--) {       cin >> n;       for (int i = 1; i <= n; i++) cin >> a[i];       sort(a + 1, a + n + 1);       if (check())         cout <<  YES n ;       else         cout <<  NO n ;     }   }   bool check() {     for (int i = 1; i < n; i++) {       if (a[i + 1] == a[i] || a[i + 1] == a[i] + 1)         continue;       else         return false;     }     return true;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110000;   string s;   int n, cnt1, cnt0, cntq, m, p;   char last0, last1;   int may01, may10;   int main() {     cin >> s;     n = s.size();     for (int i = 0; i < n; i++)       if (s[i] ==  1 )         cnt1++;       else if (s[i] ==  0 )         cnt0++;       else         cntq++;     m = n / 2 + n % 2 - 1;     p = n - m - 2;     if (cnt1 <= m) puts( 00 );     if (m + 1 - cnt1 <= cntq && m + 1 >= cnt1) {       int q1 = (m + 1 - cnt1);       int q0 = cntq - q1;       if (q0 + cnt0 == p + 1) {         if (s[n - 1] ==  1  || (s[n - 1] ==  ?  && q1 > 0)) {           may01 = 1;         }         if (s[n - 1] ==  0  || (s[n - 1] ==  ?  && q0 > 0)) {           may10 = 1;         }         if (may01) puts( 01 );         if (may10) puts( 10 );       }     }     if (cnt0 <= p) puts( 11 );   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433832795l;   template <typename T>   inline auto sqr(T x) -> decltype(x * x) {     return x * x;   }   template <typename T1, typename T2>   inline bool umx(T1& a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool umn(T1& a, T2 b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   const int N = 2000;   struct Input {     int n;     string s[N];     bool read() {       if (!(cin >> n)) {         return 0;       }       getline(cin, s[0]);       for (int i = int(0); i < int(n); ++i) {         getline(cin, s[i]);       }       return 1;     }     void init(const Input& input) { *this = input; }   };   struct Data : Input {     vector<int> ans[N];     void write() {       for (int i = int(0); i < int(n); ++i) {         printf( %d , ((int)(ans[i]).size()));         for (int j = int(0); j < int(((int)(ans[i]).size())); ++j) {           printf(  %d , ans[i][j]);         }         puts(  );       }     }     virtual void solve() {}     virtual void clear() { *this = Data(); }   };   struct Solution : Data {     static const int L = (N + 63) >> 6;     unsigned long long m[N][L];     unsigned long long u[N][L];     bool need[N];     int pos[N];     void solve() {       memset(m, 0, sizeof m);       for (int i = int(0); i < int(n); ++i) {         vector<unsigned long long> q((((int)(s[i]).size()) + 8) / 9, 0);         for (int j = int(((int)(s[i]).size())) - 1; j >= int(0); --j) {           (q[((int)(q).size()) - 1 - j / 9] *= 10) +=               s[i][((int)(s[i]).size()) - 1 - j] -  0 ;         }         for (int k = int(0); k < int(L * 2); ++k) {           unsigned long long r = 0;           for (int j = int(0); j < int(((int)(q).size())); ++j) {             q[j] += r * 1000000000;             r = q[j] & ((1ull << 32) - 1);             q[j] >>= 32;           }           m[i][k >> 1] |= r << (32 * (k & 1));         }       }       memset(u, 0, sizeof u);       for (int i = int(0); i < int(n); ++i) {         u[i][i >> 6] |= 1ull << (i & 63);         for (int j = int(0); j < int(i); ++j)           if (need[j]) {             if (m[i][pos[j] >> 6] & (1ull << (pos[j] & 63))) {               for (int k = int(0); k < int(L); ++k) {                 m[i][k] ^= m[j][k];               }               for (int k = int(0); k < int((i + 63) >> 6); ++k) {                 u[i][k] ^= u[j][k];               }             }           }         need[i] = 0;         for (int j = int(0); j < int(N); ++j) {           if (m[i][j >> 6] & (1ull << (j & 63))) {             need[i] = 1;             pos[i] = j;             break;           }         }         if (!need[i]) {           for (int j = int(0); j < int(i); ++j) {             if (u[i][j >> 6] & (1ull << (j & 63))) {               ans[i].push_back(j);             }           }         }       }     }     void clear() { *this = Solution(); }   };   Solution sol;   int main() {     cout.setf(ios::showpoint | ios::fixed);     cout.precision(20);     sol.read();     sol.solve();     sol.write();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char spots[9][9];     for (int i = 0; i < 9; i++) {       for (int j = 0; j < 3; j++) {         string input;         cin >> input;         for (int k = 0; k < input.size(); k++) {           spots[i][j * 3 + k] = input[k];         }       }     }     int first, second;     cin >> first >> second;     first--;     second--;     int targetedFirst = first % 3;     int targetedSecond = second % 3;     bool changed = false;     for (int i = targetedFirst * 3; i < targetedFirst * 3 + 3; i++) {       for (int j = targetedSecond * 3; j < targetedSecond * 3 + 3; j++) {         if (spots[i][j] ==  . ) {           changed = true;           spots[i][j] =  ! ;         }       }     }     if (changed == false) {       for (int i = 0; i < 9; i++) {         for (int j = 0; j < 9; j++) {           if (spots[i][j] ==  . ) {             spots[i][j] =  ! ;           }         }       }     }     for (int i = 0; i < 9; i++) {       for (int j = 0; j < 9; j++) {         cout << spots[i][j];         if (j % 3 == 2) {           cout <<    ;         }       }       if (i % 3 == 2 && i != 8) {         cout << endl;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[1000005];   int n, m, k;   int main() {     scanf( %d%d%d , &n, &m, &k);     memset(arr, 0, sizeof arr);     for (int i = 0; i < m; ++i) {       int number;       scanf( %d , &number);       arr[number] = 1;     }     bool flg = 0;     int where = 1;     if (arr[where] == 1) flg = 1;     while (k--) {       int num1, num2;       scanf( %d%d , &num1, &num2);       if (num1 == where && !flg) {         where = num2;         if (arr[where] == 1) flg = 1;       } else if (num2 == where && !flg) {         where = num1;         if (arr[where] == 1) flg = 1;       }     }     printf( %d , where);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct debugger {     static void call(const char* it) {}     template <typename T, typename... aT>     static void call(const char* it, T a, aT... rest) {       string b;       for (; *it && *it !=  , ; ++it)         if (*it !=    ) b += *it;       cerr << b <<  =  << a <<    ;       call(++it, rest...);     }   };   int dr[] = {0, 1, 1, -1, 0, -1, -1, 1};   int dc[] = {1, 0, 1, 1, -1, 0, -1, -1};   char field[4][4];   int dt = 0;   int tour(int r, int c, char c1, char c2, int d) {     if (r < 0 || r > 3 || c < 0 || c > 3) return 0;     if (field[r][c] == c2) {       dt++;       if (dt > 1) return 0;     } else if (field[r][c] != c1)       return 0;     int ans = 1;     ans += tour(r + dr[d], c + dc[d], c1, c2, d);     return ans;   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);     };     for (int i = 0; i < 4; i++)       for (int j = 0; j < 4; j++) cin >> field[i][j];     int y = 0;     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 4; j++) {         for (int k = 0; k < 4; k++) {           if (tour(i, j,  x ,  . , k) == 3) {             y = 1;             break;           }           dt = 0;         }         if (y) break;       }       if (y) break;     }     if (y)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[105];   int main() {     int ans = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 2; i <= n - 1; i++) {       if (a[i] == 0 && a[i - 1] == 1 && a[i + 1] == 1) {         ans++;         a[i + 1] = 0;       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   long long a[10010];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     sort(a + 1, a + 1 + n);     long long sum = 0;     for (int i = 1; i <= k; i++) sum += a[i];     printf( %lld n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err() { cout << endl; }   template <class T, class... Ts>   void err(const T &arg, const Ts &...args) {     cout << arg <<    ;     err(args...);   }   using ll = long long;   using db = double;   const int N = 1e5 + 10;   int n, m, q;   int deg[N];   vector<vector<int>> G;   ll f(ll x) { return 1ll * (deg[x] - G[x].size()) * G[x].size(); }   void RUN() {     while (cin >> n >> m) {       G.clear();       G.resize(n + 1);       memset(deg, 0, sizeof deg);       for (int i = 1, u, v; i <= m; ++i) {         cin >> u >> v;         if (u > v) {           swap(u, v);         }         deg[u]++, deg[v]++;         G[u].push_back(v);       }       ll res = 0;       for (int i = 1; i <= n; ++i) {         res += f(i);       }       cout << res <<   n ;       cin >> q;       while (q--) {         int u;         cin >> u;         res -= f(u);         for (auto &v : G[u]) {           res -= f(v);           G[v].push_back(u);           res += f(v);         }         G[u].clear();         res += f(u);         cout << res <<   n ;       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     RUN();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   int t, n, h, m, a[maxn], x;   int sum;   int main() {     ios::sync_with_stdio(0);     cin >> n >> h >> m;     for (int i = 1; i <= n; ++i) a[i] = h;     for (int i = 0; i < m; ++i) {       int l, r, w;       cin >> l >> r >> w;       for (int i = l; i <= r; ++i) {         a[i] = min(a[i], w);       }     }     long long ac = 0;     for (int i = 1; i <= n; ++i) {       ac += a[i] * a[i];     }     cout << ac << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(long long int n, long long int k) {     long long int sum = k;     long long int A[k];     fill(A, A + k, 1);     for (long long int i = k - 1; i >= 0; --i) {       while (sum + A[i] <= n) {         sum += A[i];         A[i] *= 2;       }     }     if (sum != n) {       return 0;     }     return 1;   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(NULL);     long long int a, b;     cin >> a >> b;     for (long long int i = 0; i < 33; i++) {       long long int x = a - i * (b);       if (check(x, i)) return cout << i <<   n , 0;     }     cout << -1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   char arr[2 * 1000 + 5];   int cum[2 * 1000 + 5];   void read_input() {     cin >> n;     cum[0] = 0, k = 0;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       arr[i + n] = arr[i];       cum[i] = cum[i - 1];       if (arr[i] ==  T )         cum[i] += 1;       else         k++;     }     for (int i = n + 1; i < n + k; i++) {       cum[i] = cum[i - 1];       if (arr[i] ==  T ) cum[i] += 1;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cerr.tie(0);     read_input();     int min_swaps = INT_MAX;     for (int i = k; i < n + k; i++) {       min_swaps = min(min_swaps, cum[i] - cum[i - k]);     }     cout << min_swaps <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<pair<long long, long long> > s1;   long long a[212345], ans[212345];   long long b[212345];   signed main() {     std::ios::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= m; i++) {       long long b2;       cin >> b[i] >> b2;       pair<long long, long long> now = make_pair(b2, i);       s1.insert(now);       while (*s1.begin() != now) s1.erase(s1.begin());     }     s1.insert(make_pair(0, 0));     set<pair<long long, long long> >::iterator t = s1.end();     t--;     for (long long i = (*t).first + 1; i <= n; i++) ans[i] = a[i];     sort(a + 1, a + (*t).first + 1);     long long l = 0, r = (*t).first + 1;     while (t != s1.begin()) {       set<pair<long long, long long> >::iterator tl = t;       tl--;       for (long long i = (*t).first; i > (*tl).first; i--) {         if (b[(*t).second] == 1)           ans[i] = a[--r];         else           ans[i] = a[++l];       }       t--;     }     for (long long i = 1; i <= n; i++) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:256000000 )   template <typename T>   int size(T& a) {     return (int)a.size();   }   template <typename T>   T sqr(T a) {     return a * a;   }   int main() {     int a, b, mod;     cin >> a >> b >> mod;     int ta = a, tb = b;     a %= mod;     b %= mod;     a += mod;     b += mod;     a = min(a, ta);     b = min(b, tb);     int r = 1;     for (int i = (0); i < (9); ++i) r = (r * 10) % mod;     for (int i = 0; i <= a; ++i) {       int c = (long long)r * i % mod;       int z = (mod - c);       if (z >= mod) z -= mod;       if (z <= b) {         continue;       }       printf( 1  );       printf( %0*d , 9, i);       return 0;     }     printf( 2 );   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using PII = pair<int, int>;   const int mod = 998244353;   const int inf = 1 << 30;   const int maxn = 100000 + 5;   int n, k, alive[maxn];   int query(int x) {     cout <<  ?   << x << endl;     string s;     cin >> s;     if (s ==  Y ) {       alive[x] = false;       return true;     } else {       return false;     }   }   void reset() { cout <<  R  << endl; }   int main() {     cin >> n >> k;     fill(alive + 1, alive + 1 + n, true);     int B = max(k / 2, 1), Bcnt = n / B;     for (int i = 1; i <= Bcnt; i++) {       for (int j = 0; j < i && i + j < Bcnt; j++) {         for (int k = j; k < Bcnt; k += i) {           for (int p = 1; p <= B; p++) {             query(k * B + p);           }         }         reset();       }     }     cout <<  !   << count(alive + 1, alive + 1 + n, true) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5, INF = 1e9;   const double PI = 3.141592653589793238462643383279502884197, eps = 1e-9;   int sum;   void getstring(int st, int ed, int n, bool val) {     string s;     sum = 0;     cout <<  ?  ;     for (int i = 0; i < st; i++) cout << 0;     for (int i = st; i < ed; i++)       cout << (i % 2 ? !val : val),           sum += ((val && i % 2 == 0) || (!val && i % 2));     for (int i = ed; i < n; i++) cout << 0;     cout << endl;   }   bool check(int cnt, int total, bool x) {     return (cnt != total + sum && x) || (cnt != total - sum && !x);   }   int main() {     int n, total, cnt, st, ed, md;     bool val, x;     string s1, s2;     cin >> n;     cout <<  ?  ;     for (int i = 0; i < n; i++) cout << 0;     cout << endl;     cin >> total;     cout <<  ?  ;     for (int i = 1; i < n; i++) cout << 0;     cout << 1 << endl;     cin >> cnt;     x = (cnt == total - 1);     getstring(0, n, n, 0);     cin >> cnt;     val = !check(cnt, total, !x);     st = 0, ed = n - 1;     while (st < ed) {       md = (st + ed) / 2;       getstring(st, md + 1, n, val);       cin >> cnt;       if (check(cnt, total, !x))         ed = md;       else         st = md + 1;     }     if (x)       cout <<  !   << st + 1 <<     << n;     else       cout <<  !   << n <<     << st + 1;     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;     if (n & 1) {       cout << 0;     } else {       int res = n / 4;       if (n % 4 == 0) {         res--;       }       cout << res;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 5, M = 205, INF = 1e9, MOD2 = 1e9 + 7;   int n, k, y, x[N], mem[N][3], freq[N];   int cur = 0, last = -1;   vector<int> vec;   int solve(int idx, int rem) {     if (!rem) return 0;     if (idx > cur) return 0;     int& ret = mem[idx][rem];     if (~ret) return ret;     ret = 0;     ret = solve(idx + 1, rem);     int last =         upper_bound(vec.begin(), vec.end(), vec[idx] + k) - vec.begin() - 1;     int c2 = freq[last];     if (idx) c2 -= freq[idx - 1];     ret = max(ret, solve(last + 1, rem - 1) + c2);     return ret;   }   void runtestcase() {     cin >> n >> k;     vec.clear();     for (int i = 0; i < n; ++i) {       cin >> x[i];       vec.push_back(x[i]);       mem[i][2] = mem[i][1] = -1;       freq[i] = 0;     }     freq[n] = 0;     sort(vec.begin(), vec.end());     cur = -1, last = -1;     for (int i = 0; i < n; ++i) {       if (last != vec[i]) last = vec[i], ++cur;       freq[cur]++;     }     for (int i = 1; i <= cur; ++i) freq[i] += freq[i - 1];     for (int i = 0; i < n; ++i) cin >> y;     vec.erase(unique(vec.begin(), vec.end()), vec.end());     cout << solve(0, 2);   }   int main() {     cout << fixed << setprecision(12), ios::sync_with_stdio(false),         cin.tie(nullptr), cout.tie(nullptr);     int t = 1, tt = 1;     cin >> t;     while (t) {       runtestcase();       cout <<   n ;       --t, ++tt;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   int getbit(T s, int i) {     return (s >> i) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   const double PI = 2 * acos(0.0);   const double eps = 1e-9;   const int infi = 1e9;   const long long Linfi = (long long)1e18;   const long long MOD = 1000000007;   const int c1 = 11;   const int c2 = 13;   int n, m, dx, dy;   int a[100005], b[100005];   map<int, int> M;   long long power(int a, int p, int M) {     if (p == 0) return 1;     if (p == 1) return a % M;     long long ans = power(a, p / 2, M);     ans = (ans * ans) % M;     if (p % 2 == 1) ans = (ans * a) % M;     return ans;   }   int phiEuler(int n) {     int res = n;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) res -= res / i;       while (n % i == 0) n /= i;     }     if (n > 1) res -= res / n;     return res;   }   void solve() {     int phi = phiEuler(n);     for (int i = 1; i <= m; i++) {       long long inver = power(dx, phi - 1, n);       long long k = inver * (n - a[i]);       k %= n;       long long tmp = (b[i] + k * dy) % n;       M[tmp]++;     }     int maxx = 0, val = -1;     for (typeof(M.begin()) i = M.begin(); i != M.end(); i++) {       if (i->second > maxx) {         maxx = i->second;         val = i->first;       }     }     cout << 0 <<     << val << endl;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> dx >> dy;     for (int i = 1; i <= m; i++) {       cin >> a[i] >> b[i];     }     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long a, b;     cin >> a >> b;     long long count = 0;     while (b >= a) {       ostringstream str1;       str1 << a;       string str2 = str1.str();       for (long long i = 0; i < str2.length(); i++) {         if (str2[i] ==  2  || str2[i] ==  3  || str2[i] ==  5 ) {           count += 5;         } else if (str2[i] ==  0  || str2[i] ==  6  || str2[i] ==  9 ) {           count += 6;         } else if (str2[i] ==  1 ) {           count += 2;         } else if (str2[i] ==  4 ) {           count += 4;         } else if (str2[i] ==  7 ) {           count += 3;         } else if (str2[i] ==  8 ) {           count += 7;         }       }       a++;     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     set<long long int> s;     long long int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > 0) {         s.insert(a[i]);       }     }     long long int len1 = s.size();     cout << len1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Q {     int r1, r2, c1, c2, idx;   };   int n, m, k, q;   Q qs[200001];   vector<int> qAtRow[100001];   vector<int> qAtCol[100001];   vector<int> atCol[100001];   vector<int> atRow[100001];   bool must[200000];   bool res[200000];   int v[100001];   int Z = 400001;   int seg[400001];   int at, val;   void update(int n, int s, int e) {     if (at < s || at > e) return;     if (s == e) {       if (seg[n] == (1 << 29))         seg[n] = val;       else         seg[n] = val;       return;     }     update(n * 2, s, (s + e) / 2);     update(n * 2 + 1, (s + e) / 2 + 1, e);     seg[n] = max(seg[n * 2], seg[n * 2 + 1]);   }   int l, r;   int get(int n, int s, int e) {     if (l > e || r < s) return -1;     if (s >= l && e <= r) return seg[n];     return max(get(n * 2, s, (s + e) / 2), get(n * 2 + 1, (s + e) / 2 + 1, e));   }   int main() {     scanf( %d%d%d%d , &n, &m, &k, &q);     for (int i = 0; i < k; ++i) {       int r, c;       scanf( %d%d , &r, &c);       atCol[c].push_back(r);       atRow[r].push_back(c);     }     for (int i = 0; i < q; ++i) {       Q &t = qs[i];       scanf( %d%d%d%d , &t.r1, &t.c1, &t.r2, &t.c2);       t.idx = i;       qAtCol[t.c1].push_back(i);       qAtRow[t.r1].push_back(i);     }     for (int i = 0; i < Z; ++i) seg[i] = 1 << 29;     for (int i = n; i > 0; --i) {       for (int j = 0; j < atRow[i].size(); ++j) {         at = atRow[i][j];         val = i;         update(1, 1, m);       }       for (int j = 0; j < qAtRow[i].size(); ++j) {         Q &t = qs[qAtRow[i][j]];         l = t.c1;         r = t.c2;         int a = get(1, 1, m);         if (a <= 0 || a > t.r2) must[t.idx] = true;       }     }     for (int i = 0; i < Z; ++i) seg[i] = 1 << 29;     for (int i = m; i > 0; --i) {       for (int j = 0; j < atCol[i].size(); ++j) {         at = atCol[i][j];         val = i;         update(1, 1, n);       }       for (int j = 0; j < qAtCol[i].size(); ++j) {         Q &t = qs[qAtCol[i][j]];         l = t.r1;         r = t.r2;         int a = get(1, 1, n);         if (must[t.idx] && (a <= 0 || a > t.c2)) res[t.idx] = true;       }     }     for (int i = 0; i < q; ++i)       if (res[i])         puts( NO );       else         puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> glen(100001);   long long int M = 1000000007;   long long int n1, n2 = 0, sum = 0;   long long int gcd(long long int a, long long int b) {     return (b == 0) ? a : gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     long long int g = gcd(a, b);     long long int l = (a * b) / g;     return l;   }   long long int po(long long int a, long long int b) {     if (b == 0) return 1;     long long int temp = po(a, b / 2);     long long int z = ((temp % M) * (temp % M)) % M;     if (b % 2)       return ((z % M) * (a % M)) % M;     else       return z;   }   bool fun1(char c) {     if (c ==  1  || c ==  2 ) return true;     return false;   }   bool fun3(char c) {     if (c ==  1  || c ==  2 ) return false;     return true;   }   long long int fun(long long int dp[], long long int n, long long int left) {     if (dp[n] != 0) return dp[n];     if (n == left) return 1;     long long int ans = 0;     long long int limit = n - left;     for (long long int i = 1; i < limit + 1; i++) {       ans += fun(dp, n - i, left - 1);     }     return ans;   }   bool compare(pair<double, long long int> p1, pair<double, long long int> p2) {     if (p1.first != p2.first) {       return p1.first > p2.first;     }     return p1.second < p2.second;   }   struct HASH {     size_t operator()(const pair<double, long long int>& x) const {       return hash<long long>()(((long long)x.first) ^                                (((long long)x.second) << 32));     }   };   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     long long int cs = 1;     while (t--) {       long long int n, k, m;       cin >> n >> k >> m;       long long int ans = 0;       long long int a[n];       for (long long int i = 0; i < n; i++) cin >> a[i];       long long int b;       map<long long int, vector<long long int>> mp;       for (long long int i = 0; i < n; i++) {         b = a[i] % m;         mp[b].push_back(a[i]);       }       long long int f = 0;       for (auto i : mp) {         if (mp[i.first].size() >= k) {           f = 1;           cout <<  Yes n ;           long long int s = 0;           for (auto j : mp[i.first]) {             cout << j <<    ;             s++;             if (s == k) break;           }           break;         }       }       if (f == 0) cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   const int maxn = 2e5 + 100;   const int mod = 998244353;   mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());   ll fact[maxn], inv[maxn];   ll pwr(ll a, ll pw) {     ll ret = 1;     while (pw > 0) {       if (pw & 1) ret = ret * a % mod;       a = a * a % mod;       pw >>= 1;     }     return ret;   }   ll modinv(ll a) { return pwr(a, mod - 2); }   ll choose(ll N, ll K) { return fact[N] * inv[K] % mod * inv[N - K] % mod; }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     fact[0] = inv[0] = 1;     for (ll i = 1; i < maxn; i++) {       fact[i] = fact[i - 1] * i % mod;       inv[i] = modinv(fact[i]);     }     int n, k;     cin >> n >> k;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     int cnt = 0;     for (int i = 0; i < n; i++)       if (v[i] != v[(i + 1) % n]) ++cnt;     ll same = 0;     for (int c = 0; c * 2 <= cnt; c++)       same = (same + choose(cnt, c) * choose(cnt - c, c) % mod *                          pwr(k - 2, cnt - 2 * c)) %              mod;     same = same * pwr(k, n - cnt) % mod;     ll ans = ((pwr(k, n) - same + mod) % mod) * modinv(2) % mod;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     while (n--) {       int tenth = 10;       int F = 0;       char input[15];       char A[15] = {           0,       };       scanf( %s , input);       for (int i = 4; i < strlen(input); i++) A[i - 4] = input[i];       for (int i = 1; i < strlen(A); i++) {         F += tenth;         tenth *= 10;       }       int year = atoi(A);       while (year < 1989 + F) year += tenth;       printf( %d n , year);     }   }