#include <bits/stdc++.h>   using namespace std;   const int N = 710, size = 1 << 20, mod = (int)1e9 + 7, inf = 2e9;   const long long INF = 1e15;   template <class o>   void qr(o& x) {     char c = getchar();     x = 0;     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     x *= f;   }   template <class o, class... O>   void qr(o& x, O&... y) {     qr(x);     qr(y...);   }   template <class o>   void qw(o x) {     if (x / 10) qw(x / 10);     putchar(x % 10 +  0 );   }   template <class o>   void pr1(o x) {     if (x < 0) x = -x, putchar( - );     qw(x);     putchar(   );   }   template <class o, class... O>   void pr1(o x, O... y) {     pr1(x);     pr1(y...);   }   template <class o>   void pr2(o x) {     if (x < 0) x = -x, putchar( - );     qw(x);     putchar(  n );   }   template <class o, class... O>   void pr2(o x, O... y) {     pr2(x);     pr2(y...);   }   long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long power(long long a, long long b = mod - 2, long long p = mod) {     long long c = 1;     while (b) {       if (b & 1) c = c * a % p;       b /= 2;       a = a * a % p;     }     return c;   }   long long exgcd(long long a, long long b, long long& x, long long& y) {     if (!a) {       x = 0;       y = 1;       return b;     }     long long d = exgcd(b % a, a, y, x);     x -= b / a * y;     return d;   }   long long INV(long long n, long long p = mod) {     long long x, y;     exgcd(n, p, x, y);     return (x % p + p) % p;   }   template <class o>   void cmax(o& x, o y) {     if (x < y) x = y;   }   template <class o>   void cmin(o& x, o y) {     if (x > y) x = y;   }   template <typename t1, typename t2>   void ad(t1& x, t2 y) {     x += y;     if (x >= mod) x -= mod;   }   template <typename t1, typename t2>   void dl(t1& x, t2 y) {     x -= y;     if (x < 0) x += mod;   }   char str[N];   int n, a[N], cnt[10], f[N][N][10][2];   void solve() {     scanf( %s , str + 1);     int n = strlen(str + 1);     for (int i = 1; i <= n; i++) a[i] = str[i] -  0 ;     for (int i = 1; i <= 9; i++) f[0][0][i][0] = 1;     for (int i = 0; i <= n - 1; i++)       for (int j = 0; j <= i; j++)         for (int k = 1; k <= 9; k++)           for (int l = 0; l <= 1; l++)             if (f[i][j][k][l])               for (int v = !l ? a[i + 1] : 9; v >= 0; v--)                 ad(f[i + 1][j + (v >= k)][k][l | (v < a[i + 1])], f[i][j][k][l]);     long long p = 1, ans = 0;     for (int i = 1; i <= n; i++) {       long long sum = 0;       for (int j = 1; j <= 9; j++) sum += f[n][i][j][0] + f[n][i][j][1];       sum %= mod;       ans = (ans + sum * p) % mod;       p = (p * 10 + 1) % mod;     }     pr2(ans);   }   int main() {     int T = 1;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], ans[100005], ti[100005], app[100005], t, n;   int cnt(int k) {     int ret = 1, count = 0;     ++t;     for (int i = 1; i <= n; i++) {       if (ti[a[i]] != t) {         ti[a[i]] = t;         app[a[i]] = false;       }       if (!app[a[i]]) {         if (count == k) {           count = 0;           ret++;           ti[a[i]] = ++t;         }         count++;       }       app[a[i]] = true;     }     return ret;   }   void solve(int l, int r, int lo, int hi) {     if (l > r) return;     int mid = (l + r) / 2;     int res = lo == hi ? lo : cnt(mid);     ans[mid] = res;     solve(l, mid - 1, res, hi);     solve(mid + 1, r, lo, res);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     solve(1, n, 1, n);     for (int i = 1; i <= n; i++) {       if (i > 1) printf(   );       printf( %d , ans[i]);     }     cout << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   inline void read(long long &x) {     x = 0;     long long f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 3) + (x << 1) + (s ^ 48);       s = getchar();     }     x *= f;   }   inline long long Max(long long x, long long y) { return x > y ? x : y; }   inline long long Min(long long x, long long y) { return x < y ? x : y; }   long long Gcd(long long a, long long b) {     if (!b) return a;     return Gcd(b, a % b);   }   inline long long Abs(long long x) {     if (x < 0) return -x;     return x;   }   inline double Fabs(double x) {     if (x > 0) return x;     return -x;   }   long long a[100005];   int main() {     long long n;     read(n);     long long XiangMeiHaoGuai = 1;     if (XiangMeiHaoGuai + 1 == 3) printf( SXYYouYiGeQiaoPiGu );     for (register int i = 1; i <= n; ++i) read(a[i]);     if (XiangMeiHaoGuai + 1 == 3) printf( SXYYouYiGeQiaoPiGu );     sort(a + 1, a + 1 + n);     if (XiangMeiHaoGuai + 1 == 3) printf( SXYYouYiGeQiaoPiGu );     long long FuckingAns = a[2] - a[1];     if (XiangMeiHaoGuai + 1 == 3) printf( SXYYouYiGeQiaoPiGu );     for (register int i = 3; i <= n; ++i)       FuckingAns = Gcd(FuckingAns, a[i] - a[i - 1]);     if (XiangMeiHaoGuai + 1 == 3) printf( SXYYouYiGeQiaoPiGu );     long long FuckingDis = a[n] - a[1], Sucky = 1 - n;     printf( %lld , FuckingDis / FuckingAns + Sucky);     if (XiangMeiHaoGuai + 1 == 3) printf( SXYYouYiGeQiaoPiGu );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string s[4];     for (int i = 0; i < 4; i++) cin >> s[i];     int x = 0;     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         x = s[i][j] ==  # ;         x += s[i + 1][j] ==  # ;         x += s[i][j + 1] ==  # ;         x += s[i + 1][j + 1] ==  # ;         if (x != 2) return cout <<  YES , 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, S;     cin >> n >> S;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     long long z = LLONG_MAX;     sort(a.begin(), a.end());     long long fh = 0, sh = 0;     for (int i = 0; i < n / 2; i++) {       if (a[i] > S) fh += a[i] - S;       if (a[n - 1 - i] < S) sh += S - a[n - 1 - i];     }     cout << fh + sh + abs(a[n / 2] - S);     return 0;   }


/*    problem : CF1466I The Riddle of the Sphinx    reference : https://www.luogu.com.cn/blog/CXY07/solution-cf1466i   */   #include <bits/stdc++.h>   #define mp std::make_pair   #define pb push_back   #define fi first   #define se second   #define gc getchar   #define pc putchar   #define ep emplace   #define eb emplace_back   #define ctz __builtin_ctz   typedef unsigned char u8;   typedef unsigned short u16;   typedef unsigned int u32;   typedef long long ll;   typedef long double ld;   typedef unsigned long long ull;   typedef std::pair <int, int> pii;   typedef std::pair <int, ll> pil;   typedef std::pair <ll, int> pli;   typedef std::pair <ll, ll> pll;   const int max_N = 207;   int n, b;   std::string ans;   int read() {    char c = gc(); int ans = 0; bool flag = true;    while (!isdigit(c)) flag &= (c !=  - ), c = gc();    while (isdigit(c)) ans = ans * 10 + c -  0 , c = gc();    return flag ? ans : -ans;   }   void Write(int x) {    if (x < 0) pc( - ), x = -x;    if (x < 10) pc(x +  0 );    else Write(x / 10), pc(x % 10 +  0 );   }   int min(int x, int y) {return x < y ? x : y;}   int max(int x, int y) {return x > y ? x : y;}   void _min(int &x, int y) {if (x > y) x = y;}   void _max(int &x, int y) {if (x < y) x = y;}   namespace Interactive {    bool compare(int x, std::string y) {     std::cout << x <<     << y << std::endl;     return std::cin >> y, y ==  yes ;    }    bool compare_less(int x, std::string y) {     if (!std::count(y.begin(), y.end(),  1 )) return false;     for (int pos = y.size() - 1; y[pos] ==  0  ? (y[pos] =  1 , true) : (y[pos] =  0 , false); pos--);      return y.insert(y.end(), b - y.size(),  1 ), !compare(x, y);    }    bool compare_greater(int x, std::string y) {     if (!std::count(y.begin(), y.end(),  0 )) return false;     return y.insert(y.end(), b - y.size(),  1 ), compare(x, y);    }    void report(std::string x) {     std::cout << 0 <<     << x << std::endl;    }   }   void solve(std::vector <int> vec, int w) {    std::vector <int> stack;    for (auto i : vec) {     while (!stack.empty() && Interactive::compare_greater(i,      (std::string) {ans.begin(), ans.begin() + w + stack.size()})) stack.pop_back();     if (w + stack.size() < b)      ans[w + stack.size()] = !Interactive::compare_less(i,       (std::string) {ans.begin(), ans.begin() + w + stack.size()} +  1 ) +  0 , stack.pb(i);    }    for (int i = stack.size() - 1; i >= 0; i--)     if (Interactive::compare_greater(stack[i],      (std::string) {ans.begin(), ans.begin() + w + stack.size()})) stack.resize(i + 1);    if (w + stack.size() < b) solve(stack, w + stack.size());   }   int main() {    std::cin >> n >> b;    std::vector <int> vec; vec.resize(n);    std::iota(vec.begin(), vec.end(), 1);    ans.resize(b); solve(vec, 0);    return Interactive::report(ans), 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 3e5 + 30;   long long N, M, T, X[maxn], ans[maxn], shift;   char W[maxn];   vector<pair<long long, long long> > v;   vector<long long> last;   int main() {     cin >> N >> M >> T;     for (long long i = 1; i <= N; i++) {       scanf( %lld %c , &X[i], &W[i]);       v.push_back(pair<long long, long long>(X[i], i));       W[i] = W[i] ==  L  ? -1 : 1;     }     for (long long i = 1; i <= N; i++) {       long long a = (X[i] + T * W[i]), plus = 0;       if (W[i] == -1) {         a = a <= 0 ? (-a) / M + 1 : 0;       } else         plus = -(!(a % M)), a /= M;       shift += W[i] * a + plus;     }     T %= M;     for (long long i = 1; i <= N; i++) {       long long a = X[i] + T * W[i] + M;       a = (a - 1) % M + 1;       last.push_back(a);     }     sort(v.begin(), v.end());     sort(last.begin(), last.end());     if (shift) shift = shift / abs(shift) * (abs(shift) % N);     long long beg = ((-shift + N + 1) - 1) % N + 1;     long long j = 0;     for (long long i = beg - 1; i < N; i++) ans[v[i].second] = last[j++];     for (long long i = 0; i < beg - 1; i++) ans[v[i].second] = last[j++];     for (long long i = 1; i <= N; i++) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<double, pair<int, int> > > s;   int n, x;   pair<double, pair<int, int> > tmp;   signed main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (register int i = 1; (1 < n) ? (i <= n) : (i >= n);          i += (1 < n) ? 1 : (-1)) {       cin >> x;       s.push_back(make_pair(x, make_pair(i, i)));       while (s.size() > 1 && s[s.size() - 2] > s.back()) {         tmp = s.back();         s.pop_back();         tmp = make_pair((tmp.first * (tmp.second.second - tmp.second.first + 1) +                          s.back().first * (s.back().second.second -                                            s.back().second.first + 1)) /                             (tmp.second.second - s.back().second.first + 1),                         make_pair(s.back().second.first, tmp.second.second));         s.pop_back();         s.push_back(tmp);       }     }     for (auto i : s) {       for (register int j = 1; (1 < i.second.second - i.second.first + 1)                                    ? (j <= i.second.second - i.second.first + 1)                                    : (j >= i.second.second - i.second.first + 1);            j += (1 < i.second.second - i.second.first + 1) ? 1 : (-1)) {         printf( %.9lf n , i.first);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long X[(int)1e5 + 9];   long long C[(int)1e5 + 9];   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     long long n, k, a, c, cost;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> X[i];     }     cin >> a;     for (int i = 1; i <= n; i++) {       cin >> C[i];     }     c = k;     priority_queue<long long, vector<long long>, greater<long long> > Q;     cost = 0;     bool ans_ase = true;     for (int i = 1; i <= n; i++) {       Q.push(C[i]);       if (c < X[i]) {         if (Q.size() * a + c >= X[i]) {           while (c < X[i]) {             c += a;             cost += Q.top();             Q.pop();           }         } else {           ans_ase = 0;           break;         }       }     }     if (ans_ase)       cout << cost <<   n ;     else       cout << -1 <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000009;   vector<long long> vec;   long long powmod(long long a, long long m) {     long long ret = 1 % MOD;     for (; m; m >>= 1) {       if (m & 1) {         ret *= a;         if (ret >= MOD) ret %= MOD;       }       a *= a;       if (a >= MOD) a %= MOD;     }     return ret;   }   int main() {     long long n, m, k;     vec.clear();     cin >> n >> m >> k;     m = n - m;     if (m >= n) {       cout <<  0  << endl;       return 0;     }     long long p = (long long)(n / k);     if (m >= p) {       cout << n - m << endl;       return 0;     }     long long pos = n - m * k;     long long div = pos / k;     long long mod = pos % k;     long long mul = (powmod(2, div) - 1) * k % MOD * 2 % MOD;     mul = (mul + MOD) % MOD;     mul = (mul + mod) % MOD;     long long ans = (mul + n - pos - m) % MOD;     ans = (ans + MOD) % MOD;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int d[100008] = {0};     int n = 0, f = 0;     cin >> n;     for (f = 0; f < n; f++) cin >> d[f];     sort(d, d + n);     if (d[n - 1] >= d[n - 2] + d[n - 3])       cout <<  NO ;     else {       cout <<  YES n ;       for (f = n - 1; f >= 0; f -= 2) cout << d[f] <<    ;       f = n % 2;       for (; f < n; f += 2) {         cout << d[f];         if (f != n - 2) cout <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   const int inf = INT_MAX;   const long long inff = 1e18;   const long long mod = 1e9 + 7;   int p[30];   int n;   string s;   int used[40];   int Find(int x) { return p[x] == x ? x : p[x] = Find(p[x]); }   void Union(int x, int y) { p[Find(x)] = Find(y); }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     for (int i = 1; i <= 26; i++) p[i] = i;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       int N = s.length();       for (int i = 0; i < N; i++) {         used[s[i] -  a  + 1]++;       }       for (int i = 0; i < N - 1; i++) {         Union(s[i] -  a  + 1, s[i + 1] -  a  + 1);       }     }     set<int> second;     for (int i = 1; i <= 26; i++) {       if (used[i]) {         second.insert(Find(i));       }     }     cout << ((int)(second).size()) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100, M = 52 + 10, LG = 30, base = 2;   const int MOD = 1e9 + 7, mod = 1e9 + 9;   const long long INF = 1e9, inf = 1e18;   long long p, q, m, k;   string w, s, t;   vector<long long> a, b;   vector<long long> ans;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     cin >> w >> s >> t;     while (p = w.find(s, p) + 1) a.push_back(p);     while (q = w.find(t, q) + 1) b.push_back(q);     for (int i = 0; i < a.size(); i++) {       m = 0, k = 0;       for (int j = a[i]; j <= w.size(); j++) {         while (k < b.size() && b[k] < j) k++;         if (k < b.size() && b[k] == j && j + t.size() >= a[i] + s.size())           ans.push_back(m);         m = m * mod + (w[j - 1] -  a  + 1);       }     }     sort(ans.begin(), ans.end());     cout << unique(ans.begin(), ans.end()) - ans.begin();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long cal(long long a, long long b) {     long long sign = 1;     if (a < 0) {       a = -a;       sign = -sign;     }     if (b < 0) {       b = -b;       sign = -sign;     }     unsigned long long n = (unsigned long long)a * b;     long long r = n % 4000000000LL;     return sign < 0 ? -r : r;   }   long long a[200001], BIT[200001], lazy[5 * 200001];   void update(long long i, long long n, long long val) {     while (i <= n) {       BIT[i] += val;       i += i & -i;     }   }   long get(long long i) {     long long ret = 0;     while (i) {       ret += BIT[i];       i -= i & -i;     }     return ret;   }   struct Num {     long long a, b, c;     Num() {}     Num(long long x, long long y, long long z) {       a = x;       b = y;       c = z;     }     Num operator+(const Num &n) {       Num ret = *this;       Num t = n;       long long dif = ret.c - t.c;       if (dif > 0) {         long long k = 1LL << dif;         t.a *= k;         t.b *= k;       } else if (dif < 0) {         dif = -dif;         long long k = 1LL << dif;         ret.a *= k;         ret.b *= k;         ret.c = t.c;       }       ret.a += t.a;       ret.b += t.b;       if (ret.c && !(ret.a & 1) && !(ret.b & 1)) {         ret.c--;         ret.a >>= 1;         ret.b >>= 1;       }       ret.a %= 4000000000LL;       ret.b %= 4000000000LL;       return ret;     }     Num operator-(const Num &n) { return *this + Num(-n.a, -n.b, n.c); }     Num operator*(const Num &n) {       long long x = (cal(a, n.a) + 5 * cal(b, n.b)) % 4000000000LL;       long long y = (cal(a, n.b) + cal(b, n.a)) % 4000000000LL;       long long z = c + n.c;       while (z && !(x & 1) && !(y & 1)) {         z--;         x >>= 1;         y >>= 1;       }       return Num(x, y, z);     }     Num operator*(long long n) {       Num ret = Num(a, b, c);       if (!n) {         return Num(0, 0, 0);       }       if (ret.c && !(n & 1)) {         ret.c--;         n >>= 1;       }       ret.a = cal(ret.a, n);       ret.b = cal(ret.b, n);       return ret;     }     long long get() {       if (c)         return ((b / (1LL << (c - 1))) % 1000000000 + 1000000000) % 1000000000;       return (((b << 1) / (1LL << c)) % 1000000000 + 1000000000) % 1000000000;     }   };   Num x(1, 1, 1);   Num sx[200001], Sx[200001];   struct Segment {     long long i, l, r;     Num val;     Segment() {}     Segment(int k, int a, int b, Num c) {       i = k;       l = a;       r = b;       val = c;     }     long long len() { return r - l + 1; }     void update() {       if (lazy[i] == 0) return;       val = val + (Sx[r - l + 1] * lazy[i]);       if (l < r) {         lazy[i << 1] += lazy[i];         lazy[(i << 1) + 1] += lazy[i];       }       lazy[i] = 0;     }   };   Segment T[5 * 200001];   void go(long long i, long long l, long long r) {     if (l == r) {       T[i] = Segment(i, l, r, x * a[l]);       return;     }     long long m = (l + r) >> 1;     go(i << 1, l, m);     go((i << 1) + 1, m + 1, r);     Num x = T[i << 1].val + (sx[m - l + 1] * T[(i << 1) + 1].val);     T[i] = Segment(i, l, r, x);   }   Num get(long long i, long long l, long long r) {     T[i].update();     if (l == T[i].l && r == T[i].r) {       return T[i].val;     }     long long m = (T[i].l + T[i].r) >> 1;     if (r <= m) return get(i << 1, l, r);     if (l > m) return get((i << 1) + 1, l, r);     Num left = get(i << 1, l, m);     Num right = get((i << 1) + 1, m + 1, r);     return left + (sx[m - l + 1] * right);   }   void update(long long i, long long l, long long r, long long val) {     if (l == T[i].l && r == T[i].r) {       lazy[i] += val;       return;     }     long long m = (T[i].l + T[i].r) >> 1;     if (r <= m) {       update(i << 1, l, r, val);     } else if (l > m) {       update((i << 1) + 1, l, r, val);     } else {       update(i << 1, l, m, val);       update((i << 1) + 1, m + 1, r, val);     }     T[i << 1].update();     T[(i << 1) + 1].update();     T[i].val = T[i << 1].val + (sx[T[i << 1].len()] * T[(i << 1) + 1].val);   }   int main() {     long long n, q, i, k, t, v, l, r, d, add;     scanf( %lld %lld , &n, &q);     sx[1] = Sx[1] = x;     for (i = 2; i <= n; i++) {       sx[i] = sx[i - 1] * x;       Sx[i] = Sx[i - 1] + sx[i];     }     for (i = 1; i <= n; i++) {       scanf( %lld , a + i);       update(i, n, a[i]);       update(i + 1, n, -a[i]);     }     go(1, 1, n);     while (q--) {       scanf( %lld , &t);       if (t == 1) {         scanf( %lld %lld , &k, &v);         add = v - get(k);         update(k, n, add);         update(k + 1, n, -add);         update(1, k, k, add);       } else {         scanf( %lld %lld , &l, &r);         if (t == 2) {           printf( %lld n , get(1, l, r).get());         } else {           scanf( %lld , &d);           update(l, n, d);           update(r + 1, n, -d);           update(1, l, r, d);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NR = 1005;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   int n, m, a, b;   int h[NR][NR];   int num[NR][NR];   int mn[NR][NR];   struct Nd {     int id, x;   };   Nd md(int id, int x) {     Nd tmp;     tmp.id = id, tmp.x = x;     return tmp;   }   int all;   struct Mashiro {     int x, y;     long long ans;     bool operator<(const Mashiro& A) const {       return (ans == A.ans) ? ((x == A.x) ? y < A.y : x < A.x) : ans < A.ans;     }   } p[NR * NR];   bool flag[NR][NR];   Mashiro Md(int x, int y, long long ans) {     Mashiro tmp;     tmp.x = x, tmp.y = y, tmp.ans = ans;     return tmp;   }   long long sum[NR][NR];   long long getsum(int l1, int r1, int l2, int r2) {     return sum[l2][r2] + sum[l1 - 1][r1 - 1] - sum[l2][r1 - 1] - sum[l1 - 1][r2];   }   int tot;   int posx[NR * NR], posy[NR * NR];   long long ans[NR * NR];   void add(int x, int y, long long num) {     tot++;     posx[tot] = x, posy[tot] = y, ans[tot] = num;   }   void print() {     printf( %d n , tot);     for (int i = 1; i <= tot; i++)       printf( %d %d %lld n , posx[i], posy[i], ans[i]);   }   int main() {     n = read(), m = read(), a = read(), b = read();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) h[i][j] = read();     for (int i = 1; i <= n; i++) {       deque<Nd> q;       for (int j = 1; j <= b; j++) {         while (!q.empty() && h[i][j] < q.back().x) q.pop_back();         q.push_back(md(j, h[i][j]));       }       num[i][1] = q.front().x;       for (int j = b + 1; j <= m; j++) {         while (!q.empty() && q.front().id <= j - b) q.pop_front();         while (!q.empty() && h[i][j] < q.back().x) q.pop_back();         q.push_back(md(j, h[i][j]));         num[i][j - b + 1] = q.front().x;       }     }     for (int i = 1; i <= m - b + 1; i++) {       deque<Nd> q;       for (int j = 1; j <= a; j++) {         while (!q.empty() && num[j][i] < q.back().x) q.pop_back();         q.push_back(md(j, num[j][i]));       }       mn[1][i] = q.front().x;       for (int j = a + 1; j <= n; j++) {         while (!q.empty() && q.front().id <= j - a) q.pop_front();         while (!q.empty() && num[j][i] < q.back().x) q.pop_back();         q.push_back(md(j, num[j][i]));         mn[j - a + 1][i] = q.front().x;       }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + h[i][j];     for (int i = 1; i <= n - a + 1; i++)       for (int j = 1; j <= m - b + 1; j++)         p[++all] =             Md(i, j, getsum(i, j, i + a - 1, j + b - 1) - 1ll * mn[i][j] * a * b);     sort(p + 1, p + all + 1);     for (int i = 1; i <= all; i++) {       if (flag[p[i].x][p[i].y]) continue;       add(p[i].x, p[i].y, p[i].ans);       for (int j = max(1, p[i].x - a + 1); j <= min(n, p[i].x + a - 1); j++)         for (int k = max(1, p[i].y - b + 1); k <= min(m, p[i].y + b - 1); k++)           flag[j][k] = 1;     }     print();     return 0;   }


#include<bits/stdc++.h>   #define ll long long   #define pll pair<ll,ll>   #define pii pair<int,int>   #define rep(i,a,b) for(int i=a;i<=b;++i)   #define per(i,a,b) for(int i=a;i>=b;--i)   #define mem0(x) memset(x,0,sizeof(x))   #define meminf(x) memset(x,0x3f,sizeof(x))   #define VI vector<int>   #define VL vector<ll>   #define pb push_back   #define YES(n) cout << ((n) ?  YES  :  NO   ) << endl   #define Yes(n) cout << ((n) ?  Yes  :  No   ) << endl   #define endl   n    #define pb push_back   #define fi first    #define se second      #define dump(x)  cerr << #x <<   =   << (x) << endl;   #define debug(x) cerr << #x <<   =   << (x) <<   (L  << __LINE__ <<  )  <<     << __FILE__ << endl;   //#define DEBUG   using namespace  std;         const int N = 150+5, inf = 0x3f3f3f3f;      int n,k;   ll a[N],b[N],tmm[N];      void solve(){       cin>>n;       rep(i,1,n){        cin>>a[i]>>b[i];       }       rep(i,1,n){        cin>>tmm[i];       }              ll tim = 0;          rep(i,1,n){        tim += a[i]-b[i-1]+tmm[i];        if(n == i) break;        ll lim = max(b[i]-tim, (b[i]-a[i]+1)/2);        tim += lim;       }       cout << tim <<endl;          }         int main(){       ios::sync_with_stdio(0);       int tt;cin>>tt;       while(tt--){           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   void ch_max(int &x, int y) {     if (x < y) x = y;   }   void ch_min(int &x, int y) {     if (x > y) x = y;   }   const double pi = acos(-1.0);   const double eps = 1e-9;   bool solve(long long a, long long b) {     if (a == 0 || b == 0) return false;     if (a < b) swap(a, b);     if (a % b == 0) return true;     if (!solve(a % b, b)) return true;     long long t0 = a / b;     long long t1 = t0 % (b + 1);     if (t1 % 2) return false;     return true;   }   int main() {     int i, j, k, t, nc = 0;     scanf( %d , &t);     while (t--) {       long long a, b;       scanf( %I64d%I64d , &a, &b);       if (solve(a, b))         printf( First n );       else         printf( Second n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   void err() { cout << endl; }   template <template <typename...> class T, typename t, typename... Args>   void err(T<t> a, Args... args) {     for (auto x : a) cout << x <<    ;     err(args...);   }   template <typename T, typename... Args>   void err(T a, Args... args) {     cout << a <<    ;     err(args...);   }   struct P {     int a, b, item;   };   const int N = 1E5 + 100;   int n, m, dm[N];   set<int> S[N];   int orders[N];   int main() {     cin >> n >> m;     int tot = 0;     for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i) {       int sz;       scanf( %d , &sz);       for (decay<decltype(sz)>::type j = (0), _j = (sz); j < _j; ++j) {         int x;         scanf( %d , &x);         S[i].insert(x);       }       tot += sz;     }     for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i)       orders[i] = i;     sort(orders + 1, orders + n + 1,          [](const int& x, const int& y) { return S[x].size() > S[y].size(); });     int ll = 1, rr = n;     int at_least = tot / n;     for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i) {       if (i <= tot % n)         dm[orders[i]] = at_least + 1;       else         dm[orders[i]] = at_least;     }     vector<P> gather;     while (ll < rr) {       vector<P> adds;       int rrrrrrrrr = orders[rr], lllllllll = orders[ll];       ;       if (int((S[rrrrrrrrr]).size()) >= dm[rrrrrrrrr] &&           int((S[lllllllll]).size()) <= dm[lllllllll])         break;       vector<set<int>::iterator> vs;       vs.push_back(S[lllllllll].begin());       for (int v : S[rrrrrrrrr]) {         auto it = S[lllllllll].upper_bound(v);         if (it != S[lllllllll].end()) vs.push_back(it);       }       vector<int> dec;       for (auto it : vs)         while (int((S[lllllllll]).size()) - int((dec).size()) > dm[lllllllll] &&                int((S[rrrrrrrrr]).size()) < dm[rrrrrrrrr] &&                S[rrrrrrrrr].find(*it) == S[rrrrrrrrr].end()) {           S[rrrrrrrrr].insert(*it);           dec.push_back(*it++);         }       for (int v : dec) {         S[lllllllll].erase(v);         gather.push_back({lllllllll, rrrrrrrrr, v});       };       if (int((S[lllllllll]).size()) == dm[lllllllll]) ll++;       if (int((S[rrrrrrrrr]).size()) == dm[rrrrrrrrr]) rr--;     }     cout << gather.size() << endl;     for (decay<decltype(gather.size())>::type i = (0), _i = (gather.size());          i < _i; ++i)       printf( %d %d %d n , gather[i].a, gather[i].b, gather[i].item);   }


#include <bits/stdc++.h>   using namespace std;   int n, head[100005], tot, de[100005], le[100005], lf[100005];   struct node {     int to, next;   } edge[100005 * 2];   void add_edge(int u, int v) {     de[u]++;     edge[tot].to = v;     edge[tot].next = head[u];     head[u] = tot++;   }   void dfs(int cnt, int pre) {     lf[cnt] = 1;     for (int i = head[cnt]; i != -1; i = edge[i].next) {       int j = edge[i].to;       if (j == pre) continue;       if (de[j] <= 2) dfs(j, cnt);     }   }   int main() {     while (cin >> n) {       tot = 0;       memset(head, -1, sizeof(head));       memset(de, 0, sizeof(de));       memset(lf, 0, sizeof(lf));       memset(le, 0, sizeof(le));       for (int i = 1; i < n; i++) {         int u, v;         cin >> u >> v;         add_edge(u, v);         add_edge(v, u);       }       for (int i = 1; i <= n; i++) {         if (de[i] == 1) dfs(i, 0);       }       for (int i = 1; i <= n; i++) {         for (int j = head[i]; j != -1; j = edge[j].next) {           int k = edge[j].to;           if (lf[k]) le[i]++;         }       }       int flag = 0;       for (int i = 1; i <= n && !flag; i++) {         if (lf[i]) continue;         int cn = 0;         for (int j = head[i]; j != -1; j = edge[j].next) {           int k = edge[j].to;           if (lf[k] == 0 && de[k] - min(2, le[k]) >= 2) cn++;           if (cn > 2) {             flag = 1;             break;           }         }       }       if (flag)         cout <<  NO n ;       else         cout <<  YES n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 10;   long long n, a, d[MAXN], v[MAXN], P[MAXN];   vector<pair<int, long long> > vc;   long long ans;   int main() {     cin >> n >> a;     vc.push_back({0, 0});     P[0] = -1e18;     for (int i = 0; i < n; i++) {       cin >> d[i] >> v[i];       ans = max(ans, a - v[i]);       v[i] -= a;       if (i == 0) continue;       v[i] += v[i - 1];       long long mn;       if (i >= 2)         mn = v[i - 2];       else         mn = 0;       while (!vc.empty() && vc.back().first <= d[i] - d[i - 1])         mn = max(mn, vc.back().second), vc.pop_back();       vc.push_back({d[i] - d[i - 1], mn});       mn -= (d[i] - d[i - 1]) * (d[i] - d[i - 1]);       P[vc.size()] = max(P[vc.size() - 1], mn);       ans = max(ans, -v[i] + P[vc.size()]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n;     cin >> n;     long long ans = 0;     long long L = -4 * 45, R = 45;     map<long long, long long> vls;     for (long long i = L; i <= R; i++) vls[i] = 1e18;     for (long long i = 0; i < 100; i++) {       for (long long j = 0; j < 100; j++) {         for (long long k = 0; k < 100; k++) {           long long nm = -4 * i + 5 * j + 45 * k;           if (nm >= L && nm <= R) vls[nm] = min(vls[nm], i + j + k);         }       }     }     for (long long i = L; i <= R; i++) {       if (vls[i] <= n) {         ans++;       }     }     for (long long i = L; i < L + 4; i++) {       long long op = vls[i];       if (op < n) ans += n - op;     }     for (long long i = R - 44; i <= R; i++) {       long long op = vls[i];       if (op < n) ans += n - op;     }     cout << ans;     return 0;   }


// #include<bits/stdc++.h>   #include<iostream>   #include<algorithm>   #include<cmath>   /*   #include<vector>   #include<set>   #include<map>   #include<unordered_map>   #define umap unordered_map   #include<unordered_set>   #define uset unordered_set   */   #define pii pair<int,int>   #define F first   #define S second   #define fr(i,n) for(int i=0;i<n;++i)   #define pr cout<<   #define en <<  n    #define sp <<      using namespace std;   typedef long long ll;      int ar[200001];         int main()   {    // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);    int t=1,n,a ;    cin>>t;    while(t--)    {     cin>>n;     int no=0, cnt=0,ans=0;     fr(i,n){      cin>>a;      if(a==no) cnt++;      else{       ans=max(ans,cnt);       cnt=1;       no =a;      }     }     ans=max(ans,cnt);     pr ans en;    }   }


#include <bits/stdc++.h>   using namespace std;   int y;   int main() {     long long int a, b, s;     cin >> a >> b >> s;     a = abs(a);     b = abs(b);     if (s >= a + b && (s - a - b) % 2 == 0) {       cout <<  YES ;     } else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(int a, int b) { return a > b; }   const int maxen = 1e5 + 5, minn = 1e-5;   string a[1005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int res = 0, mn = 13;     for (int i = 0; i < n - 1; i++) {       for (int j = i + 1; j < n; j++) {         string b = a[i];         string c = a[j];         res = 0;         for (int k = 0; k < 6; k++)           if (b[k] != c[k]) res++;         mn = min(mn, res);       }     }     cout << (mn - 1) / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   #define pb push_back   #define mp make_pair   #define ll long long   #define mod 1000000007   using namespace std;   void factorial(ll int *fact)   {    fact[0]=1;       for(ll int i=1;i<=200000;i++)       {        fact[i]=(fact[i-1]*i)%mod;    }   }   int main()    {      int t=1;      cin>>t;      ll int fact[200001];      factorial(fact);      while(t--)      {       ll int n;     cin>>n;     ll int i,j,a[n];     ll int mi=INT_MAX;     for(i=0;i<n;i++)     {      cin>>a[i];      mi=min(mi,a[i]);     }     ll int c=0;     ll int an=mi;     for(i=0;i<n;i++)     {      if(a[i]==mi)      c++;      an=an&a[i];     }     if(an!=mi && c>=2)     {      cout<<0<<endl;     }     else     {      cout<<((((((c*(c-1))/2)%mod)*fact[n-2])%mod)*2)%mod<<endl;     }    }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, i, t, j, p, q, a, b, m;     cin >> t;     while (t--) {       cin >> n >> m;       string s[n];       bool ck = true;       ;       p = (n * m);       if (p % 2 == 0)         a = (p / 2) - 1;       else         a = p / 2;       for (i = 0; i < n; i++) {         for (j = 0; j < m; j++) {           if (!ck && a) {             s[i] +=  W ;             a--;             ck = true;             continue;           } else {             s[i] +=  B ;             ck = false;             continue;           }         }       }       if (p % 2 == 0) {         s[n - 2][m - 2] =  W ;         s[n - 2][m - 1] =  B ;       }       for (i = 0; i < n; i++) cout << s[i] << endl;     }     return;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > arr;   double ans = 0;   void dfs(int x, int h, int p) {     ans += 1.0 / h;     for (int i = 0; i < arr[x].size(); i++) {       if (arr[x][i] != p) dfs(arr[x][i], h + 1, x);     }   }   int main() {     int n;     cin >> n;     int x, y;     arr.resize(n + 1);     for (int i = 0; i < n - 1; i++) {       cin >> x >> y;       arr[x].push_back(y);       arr[y].push_back(x);     }     dfs(1, 1, -1);     printf( %0.7f , ans);   }


#include <bits/stdc++.h>   using namespace std;   int MOD = 1e9 + 7;   long long int power(long long int a, long long int b) {     long long int res = 1;     a = a % MOD;     while (b > 0) {       if (b & 1) {         res = (res * a) % MOD;         b--;       }       a = (a * a) % MOD;       b >>= 1;     }     return res;   }   long long int fermat_inv(long long int y) { return power(y, MOD - 2); }   long long int gcd(long long int a, long long int b) {     return (b == 0) ? a : gcd(b, a % b);   }   long long int min(long long int a, long long int b) { return (a > b) ? b : a; }   long long int max(long long int a, long long int b) { return (a > b) ? a : b; }   using cd = complex<double>;   const double PI = acos(-1);   void fft(vector<cd> &a, bool invert) {     int n = a.size();     for (int i = 1, j = 0; i < n; i++) {       int bit = n >> 1;       for (; j & bit; bit >>= 1) j ^= bit;       j ^= bit;       if (i < j) swap(a[i], a[j]);     }     for (int len = 2; len <= n; len <<= 1) {       double ang = 2 * PI / len * (invert ? -1 : 1);       cd wlen(cos(ang), sin(ang));       for (int i = 0; i < n; i += len) {         cd w(1);         for (int j = 0; j < len / 2; j++) {           cd u = a[i + j], v = a[i + j + len / 2] * w;           a[i + j] = u + v;           a[i + j + len / 2] = u - v;           w *= wlen;         }       }     }     if (invert) {       for (cd &x : a) x /= n;     }   }   vector<int> mult(vector<int> &a, vector<int> &b) {     int n = 1;     while (n < 2 * max(a.size(), b.size())) n <<= 1;     vector<cd> A((a).begin(), (a).end()), B((b).begin(), (b).end());     A.resize(n);     B.resize(n);     fft(A, false);     fft(B, false);     vector<cd> C(n);     for (int i = 0; i < n; i++) C[i] = A[i] * B[i];     fft(C, true);     vector<int> ans(n);     for (int i = 0; i < n; i++) ans[i] = round(C[i].real());     return ans;   }   int f[1000005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int te = 1;     while (te--) {       int n, x, y;       cin >> n >> x >> y;       vector<int> a(x + 1), b(x + 1);       for (int i = 0; i <= n; i++) {         int z;         cin >> z;         a[z] = 1;         b[x - z] = 1;       }       vector<int> v = mult(a, b);       fill(f, f + 1000005, -1);       for (int i = x + 1; i < v.size(); i++) {         if (v[i]) {           int val = 2 * (i - x) + 2 * y;           for (int j = val; j <= 1000000; j += val) f[j] = val;         }       }       int q;       cin >> q;       for (int i = 0; i < q; i++) {         int l;         cin >> l;         cout << f[l] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> tree[2010];   int cs[2010], ps[2010];   int numDesc(int node) {     int descendants = 0;     for (int x : tree[node]) {       descendants += 1 + numDesc(x);     }     if (descendants < cs[node]) return 10000;     return descendants;   }   void solve(int node, vector<int>& order) {     ps[node] = order[cs[node]];     order.erase(order.begin() + cs[node]);     for (int x : tree[node]) solve(x, order);   }   int main() {     int n;     cin >> n;     int root;     for (int i = 1; i <= n; i++) {       int p, c;       cin >> p >> c;       cs[i] = c;       if (p == 0) {         root = i;         continue;       }       tree[p].push_back(i);     }     if (numDesc(root) > 5000)       cout <<  NO ;     else {       vector<int> order(n);       order[0] = 1;       for (int i = 1; i < n; i++) order[i] = order[i - 1] + 1;       solve(root, order);       cout <<  YES n ;       for (int i = 1; i < n; i++) cout << ps[i] <<    ;       cout << ps[n];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   char s[110];   int main() {     while (~scanf( %s , s) && s[0] !=  e ) {       char op[10];       int x = 0, y = 0, p, ans = 0;       for (int i = 0; i <= 30; i++) {         x = (i == 0 ? 0 : 1 << (i - 1));         y = 1 << i;         cout <<  ?   << x <<     << y << endl;         cin >> op;         if (op[0] ==  x ) {           p = i - 1;           break;         }       }       if (p != -1) {         ans = 1 << p;         for (int i = p - 1; i >= 0; i--) {           y = 1 << i;           cout <<  ?   << ans <<     << ans + y << endl;           cin >> op;           if (op[0] ==  y ) ans += y;         }       }       cout <<  !   << ans + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, m, u, v, cnt = 0;   long long head[400005], depth[200005], visited[200005];   vector<long long> ve[5];   struct edge {     long long next;     long long to;   } e[400005];   queue<long long> q;   inline void add_edge(long long u, long long v) {     cnt++;     e[cnt].to = v;     e[cnt].next = head[u];     head[u] = cnt;   }   inline void bfs() {     q.push(1);     depth[1] = 0;     visited[1] = 1;     while (!q.empty()) {       long long now = q.front();       for (long long i = head[now]; i; i = e[i].next) {         if (visited[e[i].to] == 0) {           depth[e[i].to] = depth[now] + 1;           q.push(e[i].to);           visited[e[i].to] = 1;         }       }       visited[now] = 1;       q.pop();     }   }   signed main() {     cin >> t;     while (t--) {       cin >> n >> m;       cnt = 0;       for (long long i = 0; i <= 1; i++) ve[i].clear();       for (long long i = 1; i <= n; i++) visited[i] = 0;       for (long long i = 1; i <= 2 * n; i++) head[i] = e[i].next = e[i].to = 0;       for (long long i = 1; i <= m; i++) {         cin >> u >> v;         add_edge(u, v);         add_edge(v, u);       }       bfs();       for (long long i = 1; i <= n; i++) ve[depth[i] % 2].push_back(i);       if (ve[0].size() <= ve[1].size()) {         cout << ve[0].size() << endl;         for (long long i = 0; i < ve[0].size(); i++) cout << ve[0][i] <<    ;         cout << endl;       } else {         cout << ve[1].size() << endl;         for (long long i = 0; i < ve[1].size(); i++) cout << ve[1][i] <<    ;         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 2e18;   const long long INFINT = 2e9;   const int N = 1000006;   const int NN = 1006;   const int MOD = 1000000007;   int main() {     ios_base::sync_with_stdio(0);     long double n, h;     cin >> n >> h;     long double s = 1.0 * 1 * h / 2;     long double k = 1.0 * s / n;     long double mda = k;     for (int i = 0; i < n - 1; i++) {       long double l = 0;       long double r = h;       for (int it = 0; it < 10000; it++) {         long double mid = 1.0 * (l + r) / 2;         if ((1.0 * mid / h) * mid / 2 < k) {           l = mid;         } else {           r = mid;         }       }       cout << fixed << setprecision(9) << l <<    ;       k = mda * (i + 2);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 9;   long long power(long long x, long long y) {     if (y == 0) return 1;     long long temp = power(x, y / 2);     if (y % 2 == 1)       return temp * temp * x;     else       return temp * temp;   }   bool check(string a, string b) {     sort(a.begin(), a.end());     sort(b.begin(), b.end());     if (a == b) return true;     return false;   }   string solve(string x) {     int n = x.length();     if (n % 2) return x;     string a = solve(x.substr(0, n / 2));     string b = solve(x.substr(n / 2, n));     return a < b ? (a + b) : (b + a);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string a, b;     cin >> a >> b;     if (solve(a) == solve(b))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, p, q, c, x, y, mod, lo[100000], z[3005][3005];   long long ans;   struct segment_tree {     int a[3005][13];     void update(int x, int y) { a[x][0] = y; }     void build(int n) {       for (int i = 1; i <= lo[n]; i++)         for (int j = 1; j + (1 << i) - 1 <= n; j++)           a[j][i] = min(a[j][i - 1], a[j + (1 << (i - 1))][i - 1]);     }     long long find(int x, int y) {       int len = lo[y - x + 1];       return min(a[x][len], a[y - (1 << len) + 1][len]);     }   } a;   int main() {     scanf( %d%d%d%d , &n, &m, &p, &q);     scanf( %d%d%d%d , &c, &x, &y, &mod);     a.update(1, c);     for (int i = 2; i <= 10000; i++) lo[i] = lo[i >> 1] + 1;     for (int i = 2; i <= m; i++) c = (1ll * c * x + y) % mod, a.update(i, c);     a.build(m);     for (int i = 1; i <= m - q + 1; i++) z[1][i] = a.find(i, i + q - 1);     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= m; j++) c = (1ll * c * x + y) % mod, a.update(j, c);       a.build(m);       for (int j = 1; j <= m - q + 1; j++) z[i][j] = a.find(j, j + q - 1);     }     for (int i = 1; i <= m - q + 1; i++) {       for (int j = 1; j <= n; j++) a.update(j, z[j][i]);       a.build(n);       for (int j = 1; j <= n - p + 1; j++) ans = ans + a.find(j, j + p - 1);     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   int t, k;   int main() {     cin >> t;     while (t--) {       vector<vector<pair<int, int>>> graph;       cin >> k;       graph.resize(2 * k);       for (int i = 0; i < 2 * k - 1; ++i) {         int a, b, c;         cin >> a >> b >> c;         a--;         b--;         graph[a].emplace_back(b, c);         graph[b].emplace_back(a, c);       }       vector<int> parent(2 * k, -1);       vector<long long> cost(2 * k);       vector<int> que(1, 0);       parent[0] = 0;       for (int i = 0; i < que.size(); ++i) {         int t = que[i];         for (auto it : graph[t]) {           if (parent[it.first] == -1) {             parent[it.first] = t;             cost[it.first] = it.second;             que.emplace_back(it.first);           }         }       }       long long mn = 0, mx = 0;       vector<int> size(2 * k, 1);       reverse(que.begin(), que.end());       for (int i : que) {         size[parent[i]] += size[i];         mx += cost[i] * min(2 * k - size[i], size[i]);         mn += cost[i] * (size[i] & 1);       }       cout << mn <<     << mx << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int bit[200050];   int n;   int lowbit(int x) { return x & (-x); }   int sum(int x) {     int sum = 0;     while (x > 0) {       sum += bit[x];       x -= lowbit(x);     }     return sum;   }   void push(int pos, int num) {     while (pos <= n) {       bit[pos] += num;       pos += lowbit(pos);     }   }   int kth(int k) {     int num = 0;     int x = 0;     for (int i = 1 << 18; i > 0; i >>= 1) {       num += i;       if (num >= n || x + bit[num] >= k)         num -= i;       else         x += bit[num];     }     return num + 1;   }   int main() {     scanf( %d , &n);     int a[200050];     int x;     memset((bit), (0), sizeof((bit)));     for (int i = 0; i < n; i++) {       scanf( %d , &x);       push(x + 1, 1);       a[i] = x - sum(x);     }     memset((bit), (0), sizeof((bit)));     for (int i = 0; i < n; i++) {       scanf( %d , &x);       push(x + 1, 1);       a[i] += x - sum(x);     }     for (int i = n - 1; i > 0; i--) {       if (a[i] >= n - i) {         a[i - 1]++;         a[i] -= n - i;       }     }     if (a[0] >= n) a[0] -= n;     for (int i = 0; i < n; i++) {       int num = kth(a[i] + 1);       printf( %d  , num - 1);       push(num, -1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool prime(long long x) {     if (x == 2) return 1;     if (x % 2 == 0) return 0;     for (long long j = 3; j * j <= x; j += 2) {       if (x % j == 0) return 0;     }     return 1;   }   int main() {     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       if (n - m > 1) {         cout <<  NO  << endl;       } else {         if (prime(n + m)) {           cout <<  YES  << endl;         } else {           cout <<  NO  << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(time(0));   const long long inf = 0x3f3f3f3f3f3f3f3fLL;   const long long N = 35;   const long long MOD = 1e9 + 7;   long long n, u, r, ans = -inf;   long long a[N], b[N], k[N], p[N], dp[N][N];   void go(long long pos, long long lst) {     if ((u - pos) % 2 == 0) {       long long cur = 0;       for (long long i = 1; i <= n; i++) cur += dp[pos][i] * k[i];       ans = max(ans, cur);       if (pos == u) return;     }     if (!lst) {       for (long long i = 1; i <= n; i++) dp[pos + 1][i] = dp[pos][i] ^ b[i];       go(pos + 1, 1);     }     for (long long i = 1; i <= n; i++) dp[pos + 1][i] = dp[pos][p[i]] + r;     go(pos + 1, 0);   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> u >> r;     for (long long i = 1; i <= n; i++) cin >> a[i], dp[0][i] = a[i];     for (long long i = 1; i <= n; i++) cin >> b[i];     for (long long i = 1; i <= n; i++) cin >> k[i];     for (long long i = 1; i <= n; i++) cin >> p[i];     go(0, 0);     cout << ans;     return 0;   }


#include <iostream>   #include <algorithm>   #define int long long   using namespace std;   void solve () {    int a, b, c, d;    cin >> a >> b >> c >> d;    int arr[4] = {a,b,c,d};    sort (arr, arr+4);    int max1 = arr[4-1];    int max2 = arr[4-2];    int win1 = max (a, b);    int win2 = max (c, d);    if (win1 == max1 && win2 == max2){     cout <<  YES  <<   n ;     return;    }    if (win1 == max2 && win2 == max1){     cout <<  YES  <<   n ;     return;    }    cout <<  NO  <<   n ;   }   signed main () {    ios_base::sync_with_stdio (0);cin.tie (0);    int t; cin >> t;    while (t--) {     solve ();    }    }


#include <bits/stdc++.h>   using namespace std;   long long int MOD = 1e9 + 7;   long long int prime[10000000];   long long int fac[200100], ifac[200100];   long long int inv[200100];   vector<long long int> primes;   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool IsPrime(long long int x) {     if (x == 1) return false;     for (long long int i = 2; i * i <= x; i++) {       if (x % i == 0) return false;     }     return true;   }   void seive(long long int n) {     prime[0] = prime[1] = 1;     for (long long int i = 2; i * i <= n; i++)       if (!prime[i]) {         primes.push_back(i);         for (long long int j = i * i; j <= 1e6; j += i) prime[j] = 1;       }   }   bool sortMa7boub(const pair<long double, int>& a,                    const pair<long double, int>& b) {     if (a.first == b.first) return (a.second < b.second);     return (a.first > b.first);   }   bool IsVowel(char c) {     return (c ==  a  || c ==  e  || c ==  i  || c ==  u  || c ==  o  ||             c ==  y  || c ==  A  || c ==  E  || c ==  I  || c ==  U  ||             c ==  O  || c ==  Y );   }   bool IsEqual(string s1, string s2) {     if (s1.length() != s2.length()) return 0;     for (int i = 0; i < s1.length(); i++)       if (s1[i] != s2[i]) return 0;     return 1;   }   long long int powMod(long long int base, long long int pw) {     long long int ret = 1;     while (pw) {       if (pw & 1) ret = (ret * base) % MOD;       base = (base * base) % MOD;       pw >>= 1;     }     return ret;   }   void makeFact() {     fac[0] = ifac[0] = 1;     for (long long int i = 1; i < 200100; i++) {       fac[i] = (fac[i - 1] * i) % MOD;       ifac[i] = powMod(fac[i], MOD - 2);     }   }   inline void Init() {     inv[1] = 1;     for (int i = 2; i < 200100; ++i)       inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;   }   long long int C(long long int a, long long int b) {     if (a < b) return 0;     return (((fac[a] * ifac[b]) % MOD) * ifac[a - b]) % MOD;   }   long long int P(long long int a, long long int b) {     if (a < b) return 0;     return (fac[a] * ifac[a - b]) % MOD;   }   long long int sum(long long int k) { return (k % MOD) * ((k + 1) % MOD) / 2; }   long long int pascalDivisibility(long long int n, long long int p) {     long long int ans = 1;     long long int i = 0;     while (n) {       ans = (sum(n % p) % MOD) * (powMod(sum(p), i) % MOD) +             ((n % p + 1) % MOD) * (ans % MOD);       ans %= MOD;       n /= p;       i++;     }     return ans % MOD;   }   bool PointInRectangle(long double x1, long double y1, long double x2,                         long double y2, long double x, long double y) {     return (x >= x1 && x <= x2 && y >= y1 && y <= y2);   }   bool InRange(long long int a, long long int b, long long int c) {     return a >= b && a <= c;   }   string AL =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ;   long long int arr[200100];   long long int level[200100];   vector<long long int> rang;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, k, x, mx(0), mn(2 * 1e18);     cin >> n >> k;     set<long long int> ss;     for (int i = 0; i < n; i++)       cin >> x, arr[x]++, mx = max(mx, x), mn = min(mn, x);     long long int sum = 0;     for (int i = 200100 - 1; i > 0; i--) {       sum += arr[i];     }     long long int cnt(0);     long long int sumi = 0;     for (long long int i = mx; i > mn; i--) {       sumi += arr[i];       level[i] = sumi;     }     for (long long int i = mx; i > mn;) {       long long int sumo = 0;       while (sumo < k) {         sumo += level[i];         i--;       }       if (sumo > k) i++;       cnt++;     }     cout << cnt << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int c[25];   bool vis[25];   int n, m;   bool dfs(int p, int s, int k) {     if (p > n) return m == n - 1;     if (!k) return dfs(p + 1, p, c[p + 1]);     for (; s; s--)       if (!vis[s] && c[s] + 1 < c[p] && c[s] + 1 <= k) {         vis[s] = true;         k -= c[s] + 1;         m++;         if (dfs(p, s - 1, k)) return true;         vis[s] = false;         k += c[s] + 1;         m--;       }     return false;   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; ++i) {         scanf( %d , &c[i]);         c[i]--;       }       sort(c + 1, c + 1 + n);       memset(vis, false, sizeof(vis));       m = 0;       puts(dfs(1, 0, c[1]) ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   class SegmentTree {     struct data {       int ans;       int opened;       int closed;     };       public:     data merge(data A, data B) {       int extra = min(A.opened, B.closed);       return data{A.ans + B.ans + extra, A.opened + B.opened - extra,                   A.closed + B.closed - extra};     }     data leafNodeValue(int index) {       if (s[index] ==  ( )         return data{0, 1, 0};       else         return data{0, 0, 1};     }     void updateNode(data& node, int& value, int& start, int& end) {}     void updateLazy(int& child, int& parent) {}     data outOfRange;     int defaultLazyValue;     void setDefaultAndOutOfRange() { outOfRange = {0, 0, 0}; }     SegmentTree(int n) {       setDefaultAndOutOfRange();       size = n;       tree = new data[n << 3];       lazy = new int[n << 3];       build(1, 0, size - 1);     }     void update(int start, int end, int value) {       update(1, 0, size - 1, start, end, value);     }     data query(int start, int end) { return query(1, 0, size - 1, start, end); }       private:     void build(int node, int start, int end) {       int into2 = node << 1, mid = (start + end) / 2;       if (start == end) {         tree[node] = leafNodeValue(start);         lazy[node] = defaultLazyValue;       } else {         build(into2, start, mid), build(into2 + 1, mid + 1, end);         lazy[node] = defaultLazyValue;         tree[node] = merge(tree[into2], tree[into2 + 1]);       }     }     void push(int node, int start, int end) {       return;       if (lazy[node] != defaultLazyValue) {         updateNode(tree[node], lazy[node], start, end);         if (start != end) {           updateLazy(lazy[node + node], lazy[node]);           updateLazy(lazy[node + node + 1], lazy[node]);         }         lazy[node] = defaultLazyValue;       }     }     void update(int node, int start, int end, int rangestart, int rangeend,                 int value) {       return;       int into2 = node << 1, mid = (start + end) / 2;       push(node, start, end);       if (start > end || start > rangeend || end < rangestart) return;       if (rangestart <= start && end <= rangeend) {         updateNode(tree[node], value, start, end);         if (start != end) {           updateLazy(lazy[into2 + 1], value);           updateLazy(lazy[into2], value);         }         return;       }       update(into2, start, mid, rangestart, rangeend, value),           update(into2 + 1, mid + 1, end, rangestart, rangeend, value);       tree[node] = merge(tree[into2], tree[into2 + 1]);     }     data query(int node, int start, int end, int rangestart, int rangeend) {       int into2 = node << 1, mid = (start + end) / 2;       if (start > end || start > rangeend || end < rangestart) return outOfRange;       push(node, start, end);       if (rangestart <= start && end <= rangeend) return tree[node];       return merge(query(into2, start, mid, rangestart, rangeend),                    query(into2 + 1, mid + 1, end, rangestart, rangeend));     }     long long int size;     data* tree;     int* lazy;   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     ;     cin >> s;     SegmentTree S(s.size());     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       cout << 2 * S.query(l - 1, r - 1).ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     if (a > 36) {       cout <<  -1 ;     } else {       while (a >= 2) {         a -= 2;         cout <<  8 ;       }       if (a == 1) {         cout <<  4 ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     getline(cin, s);     for (int i = 0; i < n; i++) {       getline(cin, s);       if (s.length() >= 5) {         if ((s.substr(0, 5) ==  miao. ) &&             (s.substr(s.length() - 5, 5) !=  lala. ))           cout <<  Rainbow s  << endl;         else if ((s.substr(0, 5) !=  miao. ) &&                  (s.substr(s.length() - 5, 5) ==  lala. ))           cout <<  Freda s  << endl;         else           cout <<  OMG>.< I don t know!  << endl;       } else         cout <<  OMG>.< I don t know!  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   char mtr[MAXN][MAXN];   int main() {     int n, m;     cin >> n >> m;     set<int> s;     bool ok = true;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> mtr[i][j];       }     }     for (int i = 1; i <= n; i++) {       int gnomo, doce;       for (int j = 1; j <= m; j++) {         if (mtr[i][j] ==  G ) gnomo = j;         if (mtr[i][j] ==  S ) doce = j;       }       int r = doce - gnomo;       if (r > 0)         s.insert(r);       else         ok = false;     }     if (ok == false) {       cout <<  -1  << endl;       return 0;     }     cout << s.size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chmin(T &x, const T &y) {     if (x > y) x = y;   }   template <typename T>   void chmax(T &x, const T &y) {     if (x < y) x = y;   }   char readc() {     char c;     while ((c = getchar()) <  - )       ;     return c;   }   int read() {     char c;     while ((c = getchar()) <  - )       ;     if (c ==  - ) {       int x = (c = getchar()) -  0 ;       while ((c = getchar()) >=  0 ) x = x * 10 + c -  0 ;       return -x;     }     int x = c -  0 ;     while ((c = getchar()) >=  0 ) x = x * 10 + c -  0 ;     return x;   }   const int N = 2e5 + 5;   pair<int, int> p[N];   long long s[N];   int main() {     int n, a, b;     cin >> n >> a >> b;     for (int i = 1; i <= n; ++i) {       p[i].first = read();       p[i].second = read();       p[i].first -= p[i].second;     }     sort(p + 1, p + n + 1, greater<pair<int, int> >());     for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + max(0, p[i].first);     for (int i = n + 1; i <= b; ++i) s[i] = s[i - 1];     long long ans = s[b];     if (b)       for (int i = 1; i <= n; ++i)         chmax(ans, ((i < b) ? s[b] - max(0, p[i].first) : s[b - 1]) +                        ((long long)(p[i].first + p[i].second) << a) -                        p[i].second);     for (int i = 1; i <= n; ++i) ans += p[i].second;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 150000 + 10;   int len, n, h;   int a[MAXN], b[MAXN];   int dp[1 << 20], all[1 << 20];   inline void go(int root, int lo, int hi, int s, int e, int key) {     if (hi < s || e < lo) return;     if (s <= lo && hi <= e) {       all[root] += key;       dp[root] += key;       return;     }     int mid = (lo + hi) / 2;     go(root * 2, lo, mid, s, e, key);     go(root * 2 + 1, mid + 1, hi, s, e, key);     dp[root] = min(dp[root * 2], dp[root * 2 + 1]) + all[root];   }   inline void build(int root, int lo, int hi) {     if (lo == hi) {       dp[root] = -lo;       return;     }     int mid = (lo + hi) / 2;     build(root * 2, lo, mid);     build(root * 2 + 1, mid + 1, hi);     dp[root] = -hi;   }   int main() {     cin >> n >> len >> h;     for (int i = 0; i < len; i++) cin >> b[i];     for (int i = 0; i < n; i++) cin >> a[i];     sort(b, b + len);     int ret = 0;     build(1, 0, len - 1);     for (int i = 0; i < n; i++) {       int poi = lower_bound(b, b + len, h - a[i]) - b;       go(1, 0, len - 1, poi, len - 1, 1);       if (len <= i + 1) {         ret += (dp[1] > 0);         poi = lower_bound(b, b + len, h - a[i - len + 1]) - b;         go(1, 0, len - 1, poi, len - 1, -1);       }     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q, ans, top[200005 << 1];   int find(int u) {     if (top[u] == u) return u;     return top[u] = find(top[u]);   }   inline void work() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= n + m; i++) top[i] = i;     for (int i = 1, u, v; i <= q; i++) {       scanf( %d %d , &u, &v);       v = v + n;       int fu = find(u), fv = find(v);       if (fu == fv) continue;       top[fu] = fv;     }     for (int i = 1; i <= n + m; i++)       if (top[i] == i) ans++;     printf( %d , ans - 1);   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getMin(int l, int r, char a[], char ch) {     int count = 0;     for (int i = l; i <= r; i++) {       if (a[i] != ch) {         count++;       }     }     return count;   }   int findans(int l, int r, char a[], char ch) {     if (l == r) {       if (a[l] == ch) {         return 0;       } else {         return 1;       }     }     int mid = (l + r) / 2;     return min(getMin(l, mid, a, ch) + findans(mid + 1, r, a, ch + 1),                getMin(mid + 1, r, a, ch) + findans(l, mid, a, ch + 1));   }   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       char a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       int ans = findans(0, n - 1, a,  a );       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void MAIN();   int main() {     MAIN();     return 0;   }   const long long N = 5e3 + 1, mod = 1e9 + 7;   int n, m, best[N][N], len[N][N];   char s[N][N];   void MAIN() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %s , s[i] + 1);       for (int j = 1; j <= m; ++j) {         if (s[i][j] ==  1 ) {           len[i][j] = len[i][j - 1] + 1;         }         ++best[j][len[i][j]];       }     }     for (int i = m - 1; i >= 1; --i) {       for (int j = 1; j <= m; ++j) {         best[j][i] += best[j][i + 1];       }     }     int ans = 0;     for (int i = 1; i <= m; ++i) {       for (int len = 1; len <= m; ++len) {         ans = max(ans, len * best[i][len]);       }     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> parent;   vector<string> names;   void parse(int par) {     string str;     char c;     while (isalpha(cin.peek())) {       cin >> c;       str += c;     }     names.push_back(str);     parent.push_back(par);     int id = names.size() - 1;     while (cin.peek() ==  ,  || cin.peek() ==  : ) {       cin >> c;       parse(id);     }     cin >> c;   }   int main() {     int ans = 0;     parse(-1);     for (int i = 0; i < names.size(); i++) {       int j = parent[i];       while (j != -1) {         ans += (names[j] == names[i]);         j = parent[j];       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long sz = 1e5 + 10;   long long ara[sz], n, p;   ;   bool isValid(long long now) {     long long ptr = 1;     for (long long i = 1; i <= n; ++i) {       while (ptr <= n && ara[ptr] <= now) ptr++;       if (ptr - i >= p) return 0;       now++;     }     return 1;   }   int main() {     cin >> n >> p;     for (long long i = 1; i <= n; ++i) scanf( %lld , &ara[i]);     sort(ara + 1, ara + n + 1);     long long start = 1, now = start;     for (long long i = 1; i <= n; ++i) {       if (now < ara[i]) {         long long diff = ara[i] - now;         now += diff, start += diff;       }       now++;     }     long long lo = start, hi = 1e9, stop = -1;     while (lo <= hi) {       long long mid = lo + hi >> 1;       if (isValid(mid)) {         stop = mid;         lo = mid + 1;       } else         hi = mid - 1;     }     cout << max(0LL, stop - start + 1) <<   n ;     for (long long i = start; i <= stop; i += 1) {       if (i != start) printf(   );       printf( %lld , i);     }     if (stop != -1) printf(  n );     return 0;   }


#include <bits/stdc++.h>   struct state {     int n : 24;     int c : 8;     state const *prev;   };   state b[128][128][128] = {};   void print(state const &s) {     if (s.n) {       state const &p = *s.prev;       print(p);       if (p.n < s.n) printf( %c , s.c);     }   }   int main() {     char s1[128];     char s2[128];     char sv[128];     scanf( %s%s%s , s1, s2, sv);     unsigned int n1 = strlen(s1);     unsigned int n2 = strlen(s2);     unsigned int nv = strlen(sv);     unsigned int fail[128] = {};     for (unsigned int i = 1, j = 0; i < nv;)       if (sv[i] == sv[j])         fail[i++] = 1 + j++;       else if (0 < j)         j = fail[j - 1];       else         fail[i++] = 0;     b[0][0][0].n = 0;     for (unsigned int i = 1; i <= nv; ++i) b[0][0][i].n = -4200;     for (unsigned int i = 1; i <= n1; ++i) {       for (unsigned int j = 1; j <= n2; ++j) {         for (unsigned int k = 0; k < nv; ++k) {           b[i][j][k] = b[i - 1][j][k];           if (b[i][j][k].n < b[i][j - 1][k].n) b[i][j][k] = b[i][j - 1][k];         }         if (s1[i - 1] == s2[j - 1]) {           for (unsigned int k = 0; k < nv; ++k) {             unsigned int v = k;             while (1) {               if (s1[i - 1] == sv[v]) {                 ++v;                 break;               }               if (0 < v)                 v = fail[v - 1];               else                 break;             }             if (b[i][j][v].n < b[i - 1][j - 1][k].n + 1) {               b[i][j][v].n = b[i - 1][j - 1][k].n + 1;               b[i][j][v].c = s1[i - 1];               b[i][j][v].prev = &b[i - 1][j - 1][k];             }           }         }       }     }     unsigned int v = 0;     for (unsigned int i = 1; i < nv; ++i)       if (b[n1][n2][v].n < b[n1][n2][i].n) v = i;     if (0 < b[n1][n2][v].n) {       print(b[n1][n2][v]);       printf(  n );     } else       printf( 0 n );   }


#include <bits/stdc++.h>   using namespace std;   set<pair<string, string> > m;   int n, z[2000], d, k, ans;   string a[2000], b[2000], zx[2000][5];   int main() {     cin >> n >> d;     for (int i = 0; i < n; i++) {       cin >> a[i];       cin >> b[i];       cin >> z[i];     }     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++)         if (z[j] - z[i] <= d) {           if (a[i] == b[j] && a[j] == b[i] && z[i] != z[j])             m.insert(make_pair(min(a[i], b[i]), max(a[i], b[i])));         } else           break;     cout << m.size() << endl;     for (set<pair<string, string> >::iterator i = m.begin(); i != m.end(); i++)       cout << i->first <<     << i->second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int x[100111];   int num[100111], numl;   int ans[100111];   map<int, int> HASH;   int main() {     int i, temp;     scanf( %d , &n);     memset(num, 0, sizeof(num));     numl = 0;     for (i = 0; i < n; i++) {       scanf( %d , &temp);       if (HASH.count(temp) == 0) {         HASH[temp] = numl;         x[numl] = temp;         numl++;       }       num[HASH[temp]]++;     }     sort(x, x + numl);     ans[0] = num[HASH[x[0]]];     for (i = 1; i < numl; i++) {       ans[i] = ans[i - 1] + num[HASH[x[i]]];     }     int m, q;     int left, right, mid;     scanf( %d , &q);     for (i = 0; i < q; i++) {       scanf( %d , &m);       left = 0;       right = numl - 1;       while (left <= right) {         mid = (left + right) / 2;         if (x[mid] == m ||             (x[mid - 1] < m && x[mid + 1] > m && mid + 1 < numl && mid - 1 >= 0))           break;         if (x[mid] > m)           right = mid - 1;         else           left = mid + 1;       }       while (x[mid] > m && mid >= 0) mid--;       while (x[mid + 1] <= m && mid + 1 < numl) mid++;       if (mid >= 0 && mid < numl) printf( %d n , ans[mid]);       if (mid < 0) printf( 0 n );       if (mid >= numl) printf( %d n , n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void debug(int n) { printf( %d n ); }   bool cmp(pair<int, pair<int, int> > &a, pair<int, pair<int, int> > &b) {     if (a.second.first == b.second.first) {       return a.first < b.first;     }     return a.second.first < b.second.first;   }   int main() {     int n, u, v, kase;     scanf( %d , &kase);     while (kase--) {       scanf( %d , &n);       vector<pair<int, pair<int, int> > > q;       for (int i = 0; i < n; i++) {         scanf( %d%d , &u, &v);         q.push_back(make_pair(i, make_pair(u, v)));       }       sort(q.begin(), q.end(), cmp);       vector<int> idx;       int time = 0;       for (int i = 0; i < n; i++) {         time = max(time, q[i].second.first);         if (time > q[i].second.second) {           idx.push_back(0);         } else {           idx.push_back(time);           time++;         }       }       for (auto i : idx) printf( %d  , i);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int INF = 2e9;   const long long INFLL = 1e18;   const int MAX_N = 100000;   vector<int> gp[MAX_N + 1];   int N;   int p[MAX_N + 1];   int cnt[MAX_N + 1];   int lv[MAX_N + 1];   void dfs(int x) {     cnt[lv[x]]++;     for (int i : gp[x]) {       lv[i] = lv[x] + 1;       dfs(i);     }   }   int main() {     scanf( %d , &N);     for (int i = 2; i <= N; i++) {       scanf( %d , &p[i]);       gp[p[i]].push_back(i);     }     lv[1] = 1;     dfs(1);     int ans = 0;     for (int i = 1; i <= N; i++) {       ans += (cnt[i] % 2);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100002;   const int logN = 22;   vector<int> c;   map<int, int> m;   void solve() {     int n;     cin >> n;     while (n--) {       int x;       cin >> x;       m[x]++;     }     int ans = 0;     for (const pair<int, int> &x : m) {       bool f = false;       for (const int &y : c) {         if (y == x.first) {           if (x.second >= 2) {             f = true;             break;           }           continue;         }         if (y != 2 * x.first && m.find(y - x.first) != m.end()) {           f = true;           break;         }       }       if (!f) {         ans += x.second;       }     }     cout << ans << endl;   }   int main() {     int t = 1;     for (int i = 0; i <= 31; i++) {       c.push_back(1 << i);     }     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, p;   long long A[5001];   long long a[5001];   long long l[1000005];   long long dp[2][5001];   long long s[5001][5001];   void work(long long *prev, long long *nxt) {     long long total = 0, prev_total = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= min(l[i], m); j++) {         nxt[j] = (s[l[i]][j] * A[j] % p) * prev_total % p;         if (j <= l[i - 1])           nxt[j] = (nxt[j] - ((prev[j] * a[j] % p) * s[l[i]][j]) % p + p) % p;         total = (total + nxt[j]) % p;       }       swap(nxt, prev);       memset(nxt, 0, sizeof(long long) * 5000);       prev_total = total;       total = 0;     }     printf( %I64d n , prev_total);   }   int main() {     scanf( %I64d %I64d %I64d , &n, &m, &p);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &l[i]);     }     a[0] = 1;     A[0] = 1;     for (int i = 1; i <= 5000; i++) {       A[i] = A[i - 1] * (m - i + 1) % p;       a[i] = a[i - 1] * i % p;     }     s[0][0] = 1;     for (int i = 1; i <= 5000; i++)       for (int j = 1; j <= i; j++) {         s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * (j - 1) % p) % p;       }     work(dp[0], dp[1]);   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100005, LOG = 25;   long long n, f[N][LOG + 5], cnt = 0, head[N], dep[N];   long long size[N];   struct CLANNAD {     long long to, nxt;   } a[N << 1];   inline void add(long long u, long long v) {     a[++cnt].to = v;     a[cnt].nxt = head[u];     head[u] = cnt;   }   inline long long getnode(long long x, long long deep) {     for (long long i = LOG; i >= 0; i--)       if (dep[f[x][i]] >= deep) x = f[x][i];     return x;   }   inline long long LCA(long long x, long long y) {     if (dep[x] < dep[y]) swap(x, y);     long long ox = x, oy = y;     for (long long i = LOG; i >= 0; i--)       if (dep[f[x][i]] >= dep[y]) x = f[x][i];     long long lca;     if (x == y)       lca = x;     else {       for (long long i = LOG; i >= 0; i--)         if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];       lca = f[x][0];     }     long long dis = dep[ox] + dep[oy] - dep[lca] * 2;     if (dis & 1)       return 0;     else if (oy == lca) {       long long mid = (dep[ox] + dep[oy]) >> 1;       return size[getnode(ox, mid)] - size[getnode(ox, mid + 1)];     } else if (dep[ox] != dep[oy]) {       long long mid = dep[ox] - dis / 2;       return size[getnode(ox, mid)] - size[getnode(ox, mid + 1)];     } else       return n - size[getnode(ox, dep[lca] + 1)] -              size[getnode(oy, dep[lca] + 1)];   }   void dfs(long long x, long long fx) {     size[x] = 1;     dep[x] = dep[fx] + 1;     f[x][0] = fx;     for (long long i = 1; i <= LOG; i++) f[x][i] = f[f[x][i - 1]][i - 1];     for (long long i = head[x]; i; i = a[i].nxt)       if (a[i].to != fx) dfs(a[i].to, x), size[x] += size[a[i].to];   }   signed main() {     cin >> n;     long long u, v;     for (long long i = 1; i <= n - 1; i++)       scanf( %lld%lld , &u, &v), add(u, v), add(v, u);     dfs(1, 0);     long long T, x, y;     cin >> T;     while (T--) {       scanf( %lld%lld , &x, &y);       if (x == y)         printf( %lld n , n);       else         printf( %lld n , LCA(x, y));     }     return 0;   }


#include <bits/stdc++.h>   const int N = 50005;   char s[N];   int main() {     scanf( %s , s);     int i, j, n = strlen(s);     for (j = 1; j <= n / 2; j++) {       int t = 0, cnt = 0;       for (i = 0; i + j < n; i++) {         s[t++] = s[i];         if (s[i] == s[i + j])           cnt++;         else           cnt = 0;         if (cnt == j) {           t -= j;           cnt = 0;         }       }       for (; i < n; i++) s[t++] = s[i];       n = t;     }     s[n] = 0;     puts(s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int r;   int done = 1;   pair<int, int> tempo(int x, int y) {     if (x >= y) {       if (x % y == 0) {         if (y == 1)           return make_pair(x, x - 1);         else           return make_pair(1000000100, 1000000100);       }       pair<int, int> next = tempo(x % y, y);       int num = x / y;       next.first += num;       next.second += num - 1;       return next;     }     if (y % x == 0) {       if (x == 1) {         return make_pair(y, y - 2);       } else         return make_pair(1000000100, 1000000100);     }     pair<int, int> next = tempo(x, y % x);     int num = y / x;     next.first += num;     next.second += num - 1;     return next;   }   int main() {     cin >> n >> r;     if (r == 1) {       if (n == 1)         cout <<  0 nT ;       else         cout <<  IMPOSSIBLE ;       return 0;     }     int minimo = 1000000100;     int chos = 0;     for (int i = 1; i < r; i++) {       pair<int, int> ris = tempo(i, r - i);       if (ris.first == n - 1 and ris.second < minimo) {         minimo = ris.second;         chos = i;       }     }     if (chos == 0) {       cout <<  IMPOSSIBLE ;       return 0;     }     cout << minimo;     cout << endl;     vector<char> roba;     int x = chos;     int y = r - chos;     while (x > 0) {       if (x == 1 and y == 1) {         x = 0;         roba.push_back( T );       } else if (x > y) {         roba.push_back( T );         x -= y;       } else if (x < y) {         roba.push_back( B );         y -= x;       }     }     for (int i = int(roba.size()) - 1; i >= 0; i--) cout << roba[i];     if (roba[0] ==  T )       cout <<  B ;     else       cout <<  T ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool chmax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   const int INF = 1e9;   struct UnionFind {     vector<int> par;     vector<int> rank;     vector<long long> Size;     UnionFind(int n = 1) { init(n); }     void init(int n = 1) {       par.resize(n + 1);       rank.resize(n + 1);       Size.resize(n + 1);       for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;     }     int root(int x) {       if (par[x] == x) {         return x;       } else {         int r = root(par[x]);         return par[x] = r;       }     }     bool issame(int x, int y) { return root(x) == root(y); }     bool merge(int x, int y) {       x = root(x);       y = root(y);       if (x == y) return false;       if (rank[x] == rank[y]) ++rank[x];       par[y] = x;       Size[x] += Size[y];       return true;     }     long long size(int x) { return Size[root(x)]; }   };   long long N, Q;   long long node[150000][27];   long long subtree[150000][27];   int p[150000];   int tmpp[150000];   vector<int> children[150000];   int val[150000];   int tmpval[150000];   void f(int now) {     if (children[now].size() == 0) {       for (int i = 0; i < 27; i++) {         subtree[now][i] = node[now][i];       }     }     if (children[now].size() == 1) {       for (int i = 0; i < 27; i++) {         subtree[now][i] = node[now][i] + subtree[children[now][0]][i];       }     }     if (children[now].size() == 2) {       int num[2] = {0, 0};       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 27; j++) {           num[i] += subtree[children[now][i]][j];         }       }       if (num[0] != num[1]) {         for (int i = 0; i < 27; i++) subtree[now][i] = -INF;       } else {         int tmpnum = num[0];         for (int i = 0; i < 26; i++) {           subtree[now][i] =               max(subtree[children[now][0]][i], subtree[children[now][1]][i]);           tmpnum -= subtree[now][i];         }         if (tmpnum < 0) {           for (int i = 0; i < 27; i++) subtree[now][i] = -INF;         } else {           subtree[now][26] = tmpnum;           for (int i = 0; i < 27; i++) {             subtree[now][i] += node[now][i];           }         }       }     }   }   void dfs(int now) {     cerr <<  ---dfs:   << now << endl;     cerr <<  children:  ;     for (auto tmp : children[now]) {       cerr << tmp <<    ;     }     cerr << endl;     for (auto tmp : children[now]) dfs(tmp);   }   UnionFind uni;   void print() {     for (int i = 0; i < N; i++) {       if (uni.root(i) != i) continue;       cerr <<  -------------  << i <<  -------------  << endl;       for (int j = 0; j < 27; j++) {         cerr << subtree[i][j] <<    ;       }       cerr << endl;     }   }   int main() {     cin >> N >> Q;     p[0] = -1;     for (int i = 1; i < N; i++) {       cin >> p[i];       p[i]--;       char tmp;       cin >> tmp;       if (tmp ==  ? )         tmpval[i] = 26;       else         tmpval[i] = (int)(tmp -  a );       val[i] = 26;       children[p[i]].push_back(i);     }     uni.init(N);     for (int i = 0; i < N; i++) {       if (children[i].size() == 1) {         uni.merge(i, children[i][0]);       }     }     for (int i = 1; i < N; i++) {       node[uni.root(i)][val[i]]++;     }     for (int i = 0; i < N; i++) {       tmpp[i] = p[i];       p[i] = -1;     }     for (int i = 0; i < N; i++) {       if (children[i].size() == 2) {         p[children[i][0]] = uni.root(i);         p[children[i][1]] = uni.root(i);       }     }     for (int i = 0; i < N; i++) children[i].clear();     for (int i = 0; i < N; i++) {       if (p[i] != -1) {         children[p[i]].push_back(i);       }     }     for (int i = N - 1; i >= 0; i--) {       if (uni.root(i) == i) f(i);     }     if (subtree[0][0] < 0) {       for (int q = 0; q < Q; q++) {         cout <<  Fou  << endl;       }       return 0;     }     for (int i = 1; i < N; i++) {       val[i] = tmpval[i];     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < 27; j++) {         subtree[i][j] = 0;         node[i][j] = 0;       }     }     for (int i = 1; i < N; i++) {       node[uni.root(i)][val[i]]++;     }     for (int i = N - 1; i >= 0; i--) {       if (uni.root(i) == i) f(i);     }     for (int q = 0; q < Q; q++) {       int v;       char tmp;       cin >> v >> tmp;       v--;       int c;       if (tmp ==  ? )         c = 26;       else         c = (int)(tmp -  a );       int now = uni.root(v);       node[now][val[v]]--;       val[v] = c;       node[now][val[v]]++;       int nownode = now;       while (true) {         f(nownode);         if (p[nownode] == -1) break;         nownode = p[nownode];       }       if (subtree[0][0] < 0) {         cout <<  Fou  << endl;       } else {         cout <<  Shi  ;         long long ans = 0;         for (long long i = 0; i < 26; i++) {           ans += (i + 1) * (subtree[0][i] + subtree[0][26]);         }         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   template <class _, class __>   bool checkmax(_ &a, __ b) {     return a < b ? a = b, true : false;   }   template <class _, class __>   bool checkmin(_ &a, __ b) {     return a > b ? a = b, true : false;   }   using namespace std;   const int INF = 1e9;   struct node {     int x, p;     bool operator<(const node &a) const { return x < a.x; }   } A[200086];   int n, c, m;   stack<int> stk;   int nxt[200086];   int main() {     cin >> n >> c >> m;     for (register int i = (1), i_end_ = (m); i <= i_end_; ++i) {       scanf( %d%d , &A[i].x, &A[i].p);     }     A[0] = (node){0, 0};     A[++m] = (node){n, INF};     sort(A, A + m + 1);     for (register int i = (m), i_end_ = (0); i >= i_end_; --i) {       while (!stk.empty() && A[stk.top()].p >= A[i].p) stk.pop();       nxt[i] = stk.empty() ? -1 : stk.top();       stk.push(i);     }     int rest = c;     long long ans = 0;     for (register int i = (1), i_end_ = (m); i <= i_end_; ++i) {       if (rest < A[i].x - A[i - 1].x) {         puts( -1 );         return EXIT_SUCCESS;       }       if (i == m) break;       rest -= A[i].x - A[i - 1].x;       if (nxt[i] != -1) {         int dis = A[nxt[i]].x - A[i].x;         if (rest >= dis) continue;         ans += 1ll * (min(dis, c) - rest) * A[i].p;         rest = min(dis, c);       } else {         if (rest >= A[m].x - A[i].x) continue;         ans += 1ll * (min(A[m].x - A[i].x, c) - rest) * A[i].p;         rest = min(A[m].x - A[i].x, c);       }     }     printf( %I64d n , ans);     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int len, star = 0, question = 0, k = 0, n = 0;     cin >> s;     cin >> k;     len = s.length();     for (int i = 0; i < len; i++) {       if (s[i] ==  ? ) {         question++;       }       if (s[i] ==  * ) {         star++;       }     }     n = len - (star + question);     if (n == k) {       for (int i = 0; i < len; i++) {         if (s[i] !=  ?  && s[i] !=  * ) {           cout << s[i];         }       }     } else if (n < k && star < 1) {       cout <<  Impossible ;     } else if (n > k && n - star - question > k) {       cout <<  Impossible ;     } else {       if (n > k) {         for (int i = 0; i < len; i++) {           if (s[i] !=  ?  && s[i] !=  * ) {             if (i + 1 < len && (s[i + 1] ==  ?  || s[i + 1] ==  * ) && n > k) {               n--;             } else {               cout << s[i];             }           }         }       } else {         for (int i = 0; i < len; i++) {           if (s[i] !=  ?  && s[i] !=  * ) {             if (i + 1 < len && s[i + 1] ==  * ) {               cout << s[i];               while (n < k) {                 cout << s[i];                 n++;               }             } else {               cout << s[i];             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const long double PI2 = atan2(1.L, 0.L);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     long double r;     cin >> n >> r;     long double res =         r * r * n * sin(PI2 / n) * sin(2 * PI2 / n) / sin(3 * PI2 / n);     cout << fixed << setprecision(10) << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, A[100], B[100];     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> A[i];     for (int i = 0; i < k; i++) cin >> B[i];     if (k > 1) {       cout <<  Yes n ;       return 0;     }     for (int i = 0; i < n; i++)       if (!A[i]) A[i] = B[0];     for (int i = 1; i < n; i++)       if (A[i] < A[i - 1]) {         cout <<  Yes n ;         return 0;       }     cout <<  No n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     cin >> n >> x >> y;     string num;     cin >> num;     num = num.substr(num.length() - x, x);     cout << count(num.begin(), num.end() - y - 1,  1 ) +                 count(num.end() - y, num.end(),  1 ) +                 (*(num.end() - y - 1) ==  1  ? 0 : 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6 + 7;   int n;   long long dp[2][maxn];   int main() {     cin >> n;     int now = 1;     dp[0][1] = 1;     dp[0][2] = 1;     long long ans = 0;     ans += dp[0][n];     for (int i = 1; i <= 19; i++) {       memset(dp[now], 0, sizeof(dp[now]));       for (int j = (1 << (i)) - 1; j < (1 << (i + 1)) - 1; j++) {         if (dp[now ^ 1][j] == 0) continue;         for (int l = (1 << (i)) - 1; l < (1 << (i + 1)) - 1; l++) {           if (j + l + 1 < maxn && l % 2 == 0)             dp[now][j + l + 1] += dp[now ^ 1][j] * dp[now ^ 1][l];         }       }       ans += dp[now][n];       now ^= 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse2 )   using namespace std;   const int N = 2020;   namespace Gause {   static const int N = ::N;   int equ, var;   bitset<N> a[N];   int x[N];   int free_x[N];   int free_num;   int l[N];   void ini(int n) {     for (int i = (0); i < (n); ++i) x[i] = 0;     for (int i = (0); i < (n); ++i) a[i].reset();   }   int Gauss() {     int max_r, col, k;     free_num = 0;     for (k = 0, col = 0; k < equ && col < var; k++, col++) {       max_r = k;       for (int i = k + 1; i < equ; i++) {         if (abs(a[i][col]) > abs(a[max_r][col])) max_r = i;       }       if (a[max_r][col] == 0) {         k--;         free_x[free_num++] = col;         continue;       }       l[k] = col;       if (max_r != k) {         swap(a[k], a[max_r]);       }       for (int i = k + 1; i < equ; i++) {         if (a[i][col] != 0) a[i] ^= a[k];       }     }     for (int i = k; i < equ; i++) {       if (a[i][col] != 0) return -1;     }     for (int i = k - 1; i >= 0; i--) {       int t = l[i];       x[t] = a[i][var];       for (int j = t + 1; j < var; j++) x[t] ^= (a[i][j] & x[j]);     }     return 0;   }   }  // namespace Gause   int T, n, m, u, v;   bool du[N], vis[N][N];   int main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     cin >> T;     for (int cas = (0); cas < (T); ++cas) {       cin >> n >> m;       Gause ::ini(n);       for (int i = (1); i < (n + 1); ++i)         for (int j = (1); j < (n + 1); ++j) vis[i][j] = 0;       for (int i = (1); i < (n + 1); ++i) du[i] = 0;       for (int i = (1); i < (m + 1); ++i) {         cin >> u >> v;         du[u] ^= 1;         du[v] ^= 1;         vis[u][v] = vis[v][u] = 1;       }       Gause ::equ = Gause ::var = n;       for (int i = (1); i < (n + 1); ++i) {         vis[i][i] = du[i];         for (int j = (1); j < (n + 1); ++j) Gause ::a[i - 1][j - 1] = vis[i][j];         Gause ::a[i - 1][n] = du[i];       }       Gause::Gauss();       bool Vis[2] = {0};       for (int i = (1); i < (n + 1); ++i) Vis[Gause::x[i - 1]] = 1;       if (Vis[0] && Vis[1]) {         cout << 2 <<   n ;       } else {         cout << 1 <<   n ;         if (Vis[1])           for (int i = (1); i < (n + 1); ++i) Gause::x[i - 1] = 0;       }       for (int i = (1); i < (n + 1); ++i) cout << Gause::x[i - 1] + 1 <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const long double EPS = 0.000000001;   const long long INF64 = 1000000000000000000;   const long long INF32 = 2000000000;   bool iss_pt_in_triangle(pair<long long, long long> a,                           pair<long long, long long> b,                           pair<long long, long long> c,                           pair<long long, long long> point) {     long long x1 = a.first, x2 = b.first, x3 = c.first, x0 = point.first;     long long y1 = a.second, y2 = b.second, y3 = c.second, y0 = point.second;     long long aa = (x1 - x0) * (y2 - y1) - (x2 - x1) * (y1 - y0);     long long bb = (x2 - x0) * (y3 - y2) - (x3 - x2) * (y2 - y0);     long long cc = (x3 - x0) * (y1 - y3) - (x1 - x3) * (y3 - y0);     if (aa == 0 || bb == 0 || cc == 0) return 1;     if (aa >= 0 && bb >= 0 && cc >= 0) return 1;     if (aa <= 0 && bb <= 0 && cc <= 0) return 1;     return 0;   }   bool iss_ll(long long &__1, long long &__2) { return INF64 / __1 >= __2; }   bool equal(long double _1, long double _2) { return (abs(_1 - _2) < EPS); }   bool iss_sqr(long long &__1) {     long long __2 = sqrt((long double)__1);     return __2 * __2 == __1;   };   bool iss_prime(long long __1) {     for (long long i = 2; i * i <= __1; ++i)       if (!(__1 % i)) return 0;     return 1;   }   long long gcd(long long __1, long long __2) {     while (__1 && __2)       if (__1 > __2)         __1 = __1 % __2;       else         __2 = __2 % __1;     return __1 + __2;   }   long long lcm(long long &__1, long long &__2) {     return __1 * __2 / (gcd(__1, __2));   }   long long sq_cube(long long x) {     if (x == 0) return 1;     long long l = 0, r = 2e6;     while (l + 1 < r) {       long long m = (l + r) / 2;       if (m * m * m > x)         r = m;       else         l = m;     }     return l;   }   set<long long> G[100100];   vector<long long> GR[100100];   bool used[100100];   void dfs(long long v) {     if (used[v]) return;     used[v] = 1;     for (long long i : G[v]) dfs(i);   }   long long n, k;   long long step(long long k) {     long long res = 1;     for (long long i = 0; i < k; ++i) res *= 3;     return res;   }   long long dfss(long long v, long long deep) {     long long ans = deep;     used[v] = 1;     if (deep != k) {       if ((GR[v].size() < 4 && deep > 0 && deep != k) ||           (deep == 0 && GR[v].size() < 3)) {         cout <<  No               <<   n ;         exit(0);       }     }     for (long long i : GR[v]) {       if (used[i]) continue;       ans = max(dfss(i, deep + 1), ans);     }     if (ans != k) {       cout <<  No             <<   n ;       exit(0);     }     return ans;   }   signed main(signed argc, const char *argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     if (k > 20) {       cout <<  No             <<   n ;       return 0;     }     for (long long i = 1; i < n; ++i) {       long long x, y;       cin >> x >> y;       G[x].insert(y);       G[y].insert(x);       GR[x].push_back(y);       GR[y].push_back(x);     }     dfs(1);     for (long long i = 1; i <= n; ++i) {       if (!used[i]) {         cout <<  No               <<   n ;         return 0;       }     }     vector<long long> VEC;     long long k1 = k;     long long pos = 0;     for (long long i = 1; i <= n; ++i)       if (G[i].size() == 1) VEC.push_back(i);     while (k--) {       if (VEC.size() == 0) {         cout <<  No               <<   n ;         return 0;       }       if (k == 0) {         pos = *G[VEC.front()].begin();       }       for (long long i : VEC) {         G[*G[i].begin()].erase(i);         G[i].clear();       }       VEC.clear();       for (long long i = 1; i <= n; ++i) {         if (G[i].size() == 1) VEC.push_back(i);         if (G[i].size() == 2) {           cout <<  No                 <<   n ;           return 0;         }       }     }     memset(used, 0, sizeof(used));     k = k1;     dfss(pos, 0);     cout <<  Yes           <<   n ;   }


#include <bits/stdc++.h>   const int maxn = 2e5 + 5;   using namespace std;   int rd() {     int x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = (x << 3) + (x << 1) + c -  0 , c = getchar();     return x * f;   }   int n, q, cnt, id, now;   map<long long, int> mp;   map<pair<int, int>, int> ans;   vector<pair<int, int> > a[maxn];   vector<pair<int, int> >::iterator it;   int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }   int get(long long x) {     if (!mp.count(x)) mp[x] = ++id;     return mp[x];   }   pair<int, int> fac(int x, int y) {     int z = gcd(x, y);     return make_pair(x / z, y / z);   }   int main() {     n = rd();     for (int i = 1, op, x, y; i <= n; i++) {       op = rd();       x = rd();       y = rd();       long long r = 1ll * x * x + 1ll * y * y;       if (op == 1) {         ++cnt;         now = get(r);         for (int i = 0; i < ((int)a[now].size()); i++)           ans[fac(a[now][i].first + x, a[now][i].second + y)] += 2;         ans[fac(x, y)]++;         a[now].push_back(make_pair(x, y));       } else if (op == 2) {         --cnt;         now = get(r);         for (int i = 0; i < ((int)a[now].size()); i++)           if (a[now][i] != make_pair(x, y))             ans[fac(a[now][i].first + x, a[now][i].second + y)] -= 2;         ans[fac(x, y)]--;         it = a[now].begin();         while (*it != make_pair(x, y)) ++it;         a[now].erase(it);       } else         printf( %d n , cnt - ans[fac(x, y)]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     long long q;     cin >> q;     for (int i = 0; i < (int)(q); ++i) {       long long n, ans = 0;       cin >> n;       vector<int> a(n);       for (int j = 0; j < (int)(n); ++j) {         cin >> a[j];       }       sort((a).rbegin(), (a).rend());       for (int j = 0; j < (int)(n); ++j) {         if (a[j] > j) {           ans++;         } else {           break;         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long int, long long int> > arr;   bool fun(pair<long long int, long long int> fi,            pair<long long int, long long int> se) {     if (fi.first < se.first) {       return true;     } else       return false;   }   void solve() {     long long int i, j, k, l, m, n, x;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       arr.push_back(make_pair(x, i + 1));     }     sort(arr.begin(), arr.end(), fun);     if (n <= 3) {       cout << 1 << endl;       return;     }     long long int d = arr[1].first - arr[0].first;     long long int count = 0;     long long int index = arr[0].second;     for (i = 0; i < n; i++) {       if (arr[i].first != arr[0].first + (i - count) * d) {         count++;         index = arr[i].second;         if (count > 1) {           break;         }       }     }     if (count <= 1) {       cout << index << endl;       return;     }     d = arr[2].first - arr[0].first;     count = 1;     index = arr[1].second;     for (i = 3; i < n; i++) {       if (arr[i].first != arr[0].first + (i - count) * d) {         count++;         index = arr[i].second;         if (count > 1) {           break;         }       }     }     if (count <= 1) {       cout << index << endl;       return;     }     d = arr[2].first - arr[1].first;     count = 1;     index = arr[0].second;     for (i = 3; i < n; i++) {       if (arr[i].first != arr[1].first + (i - count) * d) {         count++;         index = arr[i].second;         if (count > 1) {           break;         }       }     }     if (count <= 1) {       cout << index << endl;       return;     }     cout << -1 << endl;     return;   }   int main() {     long long int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n, i, b, a[105];   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       b += a[i];     }     if (b != 0) {       cout <<  YES n1 n1   << n;       return 0;     }     for (i = 1; i <= n; i++) {       if (a[i] != 0) {         break;       }     }     if (i <= n) {       cout <<  YES n2 n1   << i << endl;       cout << i + 1 <<     << n;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, CountDog[400];   char x[100005];   int main() {     scanf( %d , &n);     if (n == 1) {       printf( Yes );       return 0;     }     for (int i = 1; i <= n; i++) {       cin >> x[i];       CountDog[x[i]]++;     }     for (int i = 1; i <= n; i++)       if (CountDog[x[i]] >= 2) {         printf( Yes );         return 0;       }     printf( No );   }