#include <bits/stdc++.h>      using namespace std;      typedef long long ll;      int get_next_state(bool s1, bool s2, bool b1, bool b2) {     if (s1 && b1) {       return -1;     }     if (s2 && b2) {       return -1;     }     bool a1 = s1 | b1;     bool a2 = s2 | b2;     if ((a1 && a2) || (!a1 && !a2)) {       return 0;     }     if (a1) {       return 1;     }     return 2;   }      bool solve_dp(int n, const vector<pair<int, int>>& cr) {     const bool S1[3] = {false, false, true};     const bool S2[3] = {false, true, false};     vector<vector<bool>> filled(2, vector<bool>(n, false));     int m = cr.size();     for (int i = 0; i < m; ++i) {       filled[cr[i].second][cr[i].first] = true;     }     /*     for (int r = 0; r < 2; ++r) {       for (int i = 0; i < n; ++i) {         if (filled[r][i]) {    cout <<  # ;         }         else {    cout <<  . ;         }       }       cout << endl;       } */     vector<uint8_t> dp(n+1);     dp[n] = 1;     for (int i = n-1; i >= 0; --i) {       dp[i] = 0;       for (int state = 0; state < 3; ++state) {         int next_state = get_next_state(S1[state], S2[state], filled[0][i], filled[1][i]);         //cout <<  next_state[  << i <<  ][  << state <<  ] =   << next_state << endl;         if (next_state >= 0) {    dp[i] |= ((dp[i+1] >> next_state) & 1) << state;         }       }       //cout << dp[i] <<    ;     }     //cout << endl;     return (dp[0] & 1) == 1;   }      bool solve_dp2(int n, const vector<pair<int, int>>& cr) {     int m = cr.size();     int prv_state = 0;     int prv_posish = 0;     int p = 0;     while (p < m) {       int posish = cr[p].first;       int state = 0;       if ((p < (m-1)) && (cr[p+1].first == posish)) {         p += 2;       }       else {         state = cr[p].second+1;         p++;       }       if (state == 0) {         if (prv_state != 0) {    return false;         }       }       else {         if (prv_state == 0) {    prv_state = 3-state;         }         else {    if (((posish - prv_posish) % 2) == 1) {      prv_state = 3-prv_state;    }    if (prv_state != state) {      return false;    }    prv_state = 0;         }       }       prv_posish = posish;     }     return (prv_state == 0);   }      bool solve(int n, const vector<int>& r, const vector<int>& c) {     int m = r.size();     vector<pair<int, int>> cr(m);     for (int i = 0; i < m; ++i) {       cr[i] = make_pair(c[i], r[i]);     }     sort(cr.begin(), cr.end());     return solve_dp2(n, cr);     vector<pair<int, int>> ccr(m);     int prv_c = 0;     int compress = 0;     for (int i = 0; i < m; ++i) {       if ((cr[i].first - prv_c) >= 2) {         compress += ((cr[i].first - prv_c - 2) / 2) * 2;       }       prv_c = cr[i].first;       ccr[i] = make_pair(cr[i].first-compress, cr[i].second);     }     return solve_dp(n-compress, ccr);   }      void test_case() {     int n, m;     cin >> n >> m;     vector<int> r(m), c(m);     for (int i = 0; i < m; ++i) {       cin >> r[i] >> c[i];       --r[i];       --c[i];     }     if (solve(n, r, c)) {       cout <<  YES  << endl;     }     else {       cout <<  NO  << endl;     }   }      int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     for (int i = 0; i < t; ++i) {       test_case();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MODULO = 998244353;   const int N_MAX = 200010;   vector<int> neighbors[N_MAX];   int factorials[N_MAX];   int n;   int calculateBranch(int x, int par) {     int perm = factorials[neighbors[x].size()];     for (int y : neighbors[x]) {       if (y != par) {         perm = ((long long)perm * calculateBranch(y, x)) % MODULO;       }     }     return perm;   }   void outerInit() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     auto fi = new ifstream( test.inp );     if (*fi) {       cin.rdbuf(fi->rdbuf());     }   }   void readData() {     cin >> n;     for (int i = 1; i < n; ++i) {       int x, y;       cin >> x >> y;       neighbors[x].push_back(y);       neighbors[y].push_back(x);     }   }   void initData() {     factorials[0] = 1;     for (int i = 1; i <= n; ++i) {       factorials[i] = ((long long)factorials[i - 1] * i) % MODULO;     }   }   void solveData() { cout << ((long long)n * calculateBranch(1, 0)) % MODULO; }   int main() {     outerInit();     readData();     initData();     solveData();   }


#include<bits/stdc++.h>   #define ll long long   #define ld long double   #define ull unsigned long long   #define izq nod * 2   #define der nod * 2 + 1   #define md (( a + b ) >> 1)   #define oo (1LL<<30LL)   #define len(X) (int)(X).size()   using namespace std;      const ll MOD = 998244353;      const int MX = 2 * 1e5+5;      ll F[MX],iF[MX];      ll pot( ll base, ll e){       ll ans = 1ll;              while( e ){           if( e & 1ll ) ans = (ans * base) % MOD;           base = (base * base) % MOD;           e>>=1ll;           }               return ans;     }      int main(){        ios_base::sync_with_stdio(0);    cin.tie(0);        int t;    cin>>t;        F[0] = iF[0] = 1;        for ( ll i = 1; i <= 2e5; i++ ){         F[i] = ( F[i-1] * i )%MOD;          iF[i] = pot ( F[i], MOD-2LL );    }        while ( t-- ){             int n;             cin>>n;                          string s;             cin>>s;                          int c0 = 0,c1 = 0;                          for ( int i = 0; i < len(s); i++ ){            if ( s[i] ==  1  && i < len(s)-1 && s[i+1] ==  1  ){              c1++; i++;         }         if ( s[i] ==  0  )c0++;        }              cout<<F[c0+c1] * iF[c0] % MOD * iF[c1] % MOD<<  n ;;                    }       return 0;    }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   enum { MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009 };   template <typename T>   class FenwickTree {     vector<T> tree;       public:     FenwickTree<T>() : tree() {}     FenwickTree<T>(vector<T> a) : tree(a.size() + 1, 0) {       for (size_t i = 0; i < a.size(); ++i) {         add(i, a[i]);       }     }     size_t size() const { return tree.size() ? tree.size() - 1 : 0; }     void add(size_t index, T value) {       for (; ++index <= size(); index |= index - 1) {         tree[index] += value;       }     }     T sum(size_t right) {       T ret{};       for (; right; right &= right - 1) {         ret += tree[right];       }       return ret;     }     T sum(size_t left, size_t right) { return sum(right) - sum(left); }   };   int a[200000];   FenwickTree<long long> ft;   int t[800000];   int n;   void build(int x = 0, int L = 0, int R = n - 1) {     if (L == R) {       t[x] = a[L];       return;     }     int M = (L + R) / 2;     build(2 * x + 1, L, M);     build(2 * x + 2, M + 1, R);     t[x] = max(t[2 * x + 1], t[2 * x + 2]);   }   void upd(int index, int val, int x = 0, int L = 0, int R = n - 1) {     if (L == R) {       t[x] = val;       return;     }     int M = (L + R) / 2;     if (index <= M) {       upd(index, val, 2 * x + 1, L, M);     } else {       upd(index, val, 2 * x + 2, M + 1, R);     }     t[x] = max(t[2 * x + 1], t[2 * x + 2]);   }   int get(long long val, int from, int x = 0, int L = 0, int R = n - 1) {     if (t[x] < val || R < from) {       return n;     } else if (L == R) {       return L;     }     int M = (L + R) / 2;     if (M < from) {       return get(val, from, 2 * x + 2, M + 1, R);     } else if (t[2 * x + 1] >= val) {       int s = get(val, from, 2 * x + 1, L, M);       if (s < n) {         return s;       }     }     return get(val, from, 2 * x + 2, M + 1, R);   }   int get_ans() {     long long cur = 0;     int index = 0;     if (a[0] == 0) {       return 1;     }     while (index < n) {       cur += a[index];       index = get(cur, index + 1);       cur = ft.sum(index);       if (a[index] == cur) {         break;       }     }     return index >= n ? -1 : index + 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int q;     cin >> n >> q;     vector<long long> b;     for (int i = 0; i < n; ++i) {       cin >> a[i];       b.push_back(a[i]);     }     ft = FenwickTree<long long>(b);     build();     while (q--) {       int p, x;       cin >> p >> x;       --p;       ft.add(p, x - a[p]);       a[p] = x;       upd(p, x);       cout << get_ans() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const long long mod = 1e9 + 7;   long long qpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   int n;   int vis[N], prime[N], num, mu[N], inv[N];   void makeMobius(int siz) {     mu[1] = 1, num = 0;     for (int i = 2; i <= siz; i++) {       if (!vis[i]) prime[++num] = i, mu[i] = -1;       for (int j = 1; j <= num && i * prime[j] <= siz; j++) {         vis[i * prime[j]] = 1;         if (i % prime[j] == 0) {           mu[i * prime[j]] = 0;           break;         } else           mu[i * prime[j]] = mu[i] * mu[prime[j]];       }     }     inv[1] = 1;     for (int i = 2; i <= siz; i++) inv[i] = qpow(i, mod - 2);   }   long long calc(long long d) {     long long y = n / d;     return y * inv[n - y] % mod;   }   int main() {     scanf( %d , &n);     makeMobius(n);     long long ans = 1;     for (int d = 2; d <= n; d++) ans = (ans - calc(d) * mu[d] % mod + mod) % mod;     printf( %lld n , (ans + mod) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k, b, e;     cin >> n >> k;     if (n == 1) {       cout <<  0  << endl;       return 0;     }     long long p = ((k - 1) * k) / 2 - 1;     if (n >= 2 && n <= (p + 2)) {       b = 2;       e = k - 2;       if (n == p + 2)         cout << k - 1 << endl;       else if (n >= 2 && n <= k)         cout <<  1  << endl;       else {         while (b <= e) {           long long mid = (e + b) / 2;           long long g = k - mid + 1;           long long begin = (k * (k + 1)) / 2 - (g * (g + 1)) / 2;           long long f = mid - 2;           begin = begin - f + 1;           g--;           long long end = (k * (k + 1)) / 2 - (g * (g + 1)) / 2;           long long f2 = mid - 1;           end = end - f2;           if (n >= begin && n <= end) {             cout << mid << endl;             break;           } else if (n > end)             b = mid + 1;           else             e = mid - 1;         }       }     } else       cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tc;     cin >> tc;     while (tc--) {       long long n, m;       cin >> n >> m;       string s;       cin >> s;       long long arr[m];       for (long long i = 0; i < m; i++) cin >> arr[i];       long long MM = 97;       long long dp[n + 1][26];       unordered_map<long long, long long, custom_hash> mp;       for (auto ch : s) mp[ch % MM]++;       for (long long i = 0; i < 26; i++) {         dp[n][i] = mp[i];       }       for (long long i = n - 1; i >= 1; i--) {         long long target = s[i] % MM;         for (long long j = 0; j < 26; j++) {           if (target == j) {             dp[i][j] = dp[i + 1][j] - 1;           } else {             dp[i][j] = dp[i + 1][j];           }         }       }       long long res[26];       for (long long i = 0; i < 26; i++) {         res[i] = dp[n][i];       }       for (long long i = 0; i < m; i++) {         long long l = arr[i];         for (long long j = 0; j < 26; j++) res[j] += dp[l][j];       }       for (long long i = 0; i < 26; i++) cout << res[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 100;   const int mod = 1e9 + 7;   mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());   int q, n = 1000000;   long long seg[maxn * 4], lazy[maxn * 4];   void build(int id = 1, int l = 1, int r = n) {     if (l == r) {       seg[id] = l;       return;     }     int mid = (l + r) / 2;     build(id * 2, l, mid);     build(id * 2 + 1, mid + 1, r);     seg[id] = max(seg[id * 2], seg[id * 2 + 1]);   }   void upd(int id, long long val) {     seg[id] += val;     lazy[id] += val;   }   void shift(int id) {     if (!lazy[id]) return;     upd(id * 2, lazy[id]);     upd(id * 2 + 1, lazy[id]);     lazy[id] = 0;   }   void modify(int first, int second, long long val, int id = 1, int l = 1,               int r = n) {     if (l > second || r < first) return;     if (l >= first && r <= second) {       upd(id, val);       return;     }     shift(id);     int mid = (l + r) / 2;     modify(first, second, val, id * 2, l, mid);     modify(first, second, val, id * 2 + 1, mid + 1, r);     seg[id] = max(seg[id * 2], seg[id * 2 + 1]);   }   long long query(int first, int second, int id = 1, int l = 1, int r = n) {     if (l > second || r < first) return 0;     if (l >= first && r <= second) return seg[id];     shift(id);     int mid = (l + r) / 2;     return max(query(first, second, id * 2, l, mid),                query(first, second, id * 2 + 1, mid + 1, r));   }   long long f[maxn];   void add(int i, long long a) {     for (; i <= n; i += i & -i) f[i] += a;   }   long long get(int i) {     long long ret = 0;     for (; i > 0; i -= i & -i) ret += f[i];     return ret;   }   long long get(int l, int r) { return get(r) - get(l - 1); }   pair<int, int> que[300005];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     build();     cin >> q;     for (int i = 1; i <= q; i++) {       char type;       cin >> type;       if (type ==  + ) {         int pos, d;         cin >> pos >> d;         modify(1, pos, d);         add(pos, d);         que[i] = {pos, d};       } else if (type ==  - ) {         int id, pos, d;         cin >> id;         tie(pos, d) = que[id];         modify(1, pos, -d);         add(pos, -d);       } else {         int pos;         cin >> pos;         long long sum = query(1, pos);         sum -= get(pos + 1, n);         cout << sum - pos <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using INT = long long;   string a[111];   int main() {     int n;     string s;     cin >> s;     cin >> n;     int flag = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == s) flag |= 3;       if (a[i][1] == s[0]) flag |= 1;       if (a[i][0] == s[1]) flag |= 2;     }     if (flag == 3) return puts( YES ), 0;     return puts( NO ), 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long double gimmearea(long double x1, long double y1, long double r1,                         long double x2, long double y2, long double r2,                         long double c) {     long double t1, t2, p1, p2;     t1 = acos((r1 * r1 + c - r2 * r2) / (2 * r1 * sqrt(c)));     t2 = acos((r2 * r2 + c - r1 * r1) / (2 * r2 * sqrt(c)));     p1 = sin(2 * t1);     p2 = sin(2 * t2);     return (r1 * r1 * t1 + r2 * r2 * t2) - 0.5 * (r1 * r1 * p1 + r2 * r2 * p2);   }   int main() {     long double x1, y1, r1, x2, y2, r2, c, ans;     cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2;     c = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);     if (c >= (r1 + r2) * (r1 + r2)) {       ans = 0;     } else if (sqrt(c) <= fabs(r1 - r2)) {       if (r2 < r1) r1 = r2;       ans = 3.14159265358979323846264338 * r1 * r1;     } else {       ans = gimmearea(x1, y1, r1, x2, y2, r2, c);     }     cout << fixed << setprecision(15);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, l, m, n, ok = 0;     char s1[110], s2[110], ans[110];     scanf( %s , s1);     scanf( %s , s2);     l = strlen(s1);     for (i = 0; i < l; i++) {       if (s1[i] > s2[i]) {         ans[i] = s2[i];       } else if (s1[i] < s2[i]) {         ok = 1;         break;       } else         ans[i] = s1[i];     }     ans[l] =   0 ;     if (ok)       printf( -1 n );     else       puts(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mm = 1000000007;   const long long inf = 1e18;   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   vector<int> e[6005];   int a[6005], q[6005], n, ans;   void dfs(int u, int top, int fa) {     int pos, tmp;     if (!top || a[u] > q[top]) {       pos = ++top;       tmp = q[top];       q[top] = a[u];       ans = max(ans, top);     } else {       pos = lower_bound(q + 1, q + 1 + top, a[u]) - q;       tmp = q[pos];       q[pos] = a[u];     }     for (int i = 0; i < (int)e[u].size(); i++) {       int v = e[u][i];       if (v == fa) continue;       dfs(v, top, u);     }     q[pos] = tmp;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n - 1; i++) {       int x = read(), y = read();       e[x].push_back(y);       e[y].push_back(x);     }     for (int i = 1; i <= n; i++) dfs(i, 0, 0);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int N = 1e5 + 7;   const int inf = INT_MAX / 2;   const long long INF = LLONG_MAX / 3;   const int MOD = 998244353;   const long double eps = 1e-6;   const pair<int, int> dir[] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   signed main() {     cout << fixed << setprecision(9);     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int q;     cin >> q;     while (q--) {       long long n;       cin >> n;       cout << (n % 4 == 0 ?  YES n  :  NO n );     }     return 0;   }


#include <bits/stdc++.h>   long double eps = 1e-8;   int main() {     int n, k;     std::cin >> n >> k;     std::vector<long double> probabilities(n);     for (long double& probability : probabilities) {       std::cin >> probability;     }     long long max_size = (1 << n);     std::vector<std::vector<long double>> dp(n,                                              std::vector<long double>(max_size));     std::vector<long double> result(n, 0.0);     for (int i = 0; i < n; ++i) {       dp[i][0] = probabilities[i];       result[i] += dp[i][0];     }     for (int mask = 1; mask < max_size; ++mask) {       long double mask_probability = 0;       if (__builtin_popcount(mask) >= k) {         continue;       }       for (int i = 0; i < n; ++i) {         if (mask & (1 << i)) {           mask_probability += probabilities[i];         }       }       for (int k = 0; k < n; ++k) {         if (mask & (1 << k)) {           continue;         }         long double sum = 0;         for (int j = 0; j < n; ++j) {           if (!(mask & (1 << j))) {             continue;           }           sum += dp[j][mask - (1 << j)];         }         if (mask_probability > 1.0 - eps) {           sum = 0;         } else {           sum *= probabilities[k] / (1 - mask_probability);         }         dp[k][mask] = sum;         result[k] += dp[k][mask];       }     }     std::cout.precision(20);     std::cout << std::fixed;     for (int i = 0; i < n; ++i) {       std::cout << result[i] <<    ;     }     std::cout << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int kkk = 0, x = 1;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) c = getchar(), x = -1;     while (c >=  0  && c <=  9 )       kkk = (kkk << 3) + (kkk << 1) + (c -  0 ), c = getchar();     return kkk * x;   }   int n, can[200001], maxn, ans, sum[200001], a[200001], minn[400001];   int c1[200001], c2[200001];   void check(int v) {     memset(c1, 0, sizeof(c1));     memset(c2, 0, sizeof(c2));     int L = 1;     c2[0] = n;     for (int i = 1; i <= n; ++i) {       if (a[i] == maxn && c1[a[i]] == v) {         while (a[L] != maxn) {           --c2[c1[a[L]]];           --c1[a[L]];           ++c2[c1[a[L]]];           ++L;         }         ++L;       } else {         --c2[c1[a[i]]];         ++c1[a[i]];         ++c2[c1[a[i]]];       }       if (c1[maxn] == v && c2[c1[maxn]] >= 2) ans = max(ans, i - L + 1);     }   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) {       a[i] = read();       ++can[a[i]];       if (can[a[i]] > can[maxn]) maxn = a[i];     }     for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + (a[i] == maxn);     int lim = sqrt(n);     for (int col = 1; col <= n; ++col) {       if (col == maxn) continue;       if (can[col] >= lim) {         for (int i = 1; i <= 2 * n; ++i) minn[i] = n + 1;         minn[n] = 0;         int sumv = 0;         for (int i = 1; i <= n; ++i) {           sumv += (a[i] == col);           int v = sumv - sum[i] + n;           ans = max(ans, i - minn[v]);           minn[v] = min(minn[v], i);         }       }     }     for (int i = 1; i <= lim; ++i) check(i);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using str = string;   using pi = pair<int, int>;   using pl = pair<ll, ll>;   using pd = pair<ld, ld>;   using vi = vector<int>;   using vb = vector<bool>;   using vl = vector<ll>;   using vd = vector<ld>;   using vs = vector<str>;   using vpi = vector<pi>;   using vpl = vector<pl>;   using vpd = vector<pd>;   str Tout[2] = { NO ,  YES };   str tout[2] = { No ,  Yes };   int main() {     ll n, k;     cin >> n >> k;     ll a[n + 17];     for (int i = (0); i < (n); i++) cin >> a[i];     if (k == 2) {       cout << max(a[0], a[n - 1]);       return 0;     }     sort(a, a + n);     if (k == 1)       cout << a[0];     else       cout << a[n - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x[100005], y[100005], q[100005], N = ((long long)1 << 40) - 1;   struct node {     long long r, l, v, sum;   } tree[400005];   void buildtree(int i, int l, int r) {     tree[i].l = l;     tree[i].r = r;     tree[i].v = 0;     if (tree[i].r == tree[i].l) {       tree[i].sum = 0;       return;     }     buildtree(i * 2, l, (r + l) / 2);     buildtree(i * 2 + 1, (l + r) / 2 + 1, r);     tree[i].sum = tree[i * 2].sum & tree[i * 2 + 1].sum;   }   void downadd(long long v) {     tree[v * 2].v |= tree[v].v;     tree[v * 2 + 1].v |= tree[v].v;     tree[v * 2].sum |= tree[v].v;     tree[v * 2 + 1].sum |= tree[v].v;     tree[v].v = 0;   }   void update(long long i, long long l, long long r, long long k) {     if (tree[i].l >= l && tree[i].r <= r) {       tree[i].sum |= k;       tree[i].v |= k;       return;     }     downadd(i);     long long m = (tree[i].l + tree[i].r) / 2;     if (l <= m) update(i * 2, l, r, k);     if (r > m) update(i * 2 + 1, l, r, k);     tree[i].sum = tree[i * 2].sum & tree[i * 2 + 1].sum;   }   long long query(long long i, long long l, long long r) {     if (tree[i].l >= l && tree[i].r <= r) {       return tree[i].sum;     }     downadd(i);     long long ans = N, m = (tree[i].r + tree[i].l) / 2;     if (l <= m) ans &= query(i * 2, l, r);     if (r > m) ans &= query(i * 2 + 1, l, r);     return ans;   }   int main() {     int n, m;     cin >> n >> m;     buildtree(1, 1, n);     for (int i = 1; i <= m; i++) {       cin >> x[i] >> y[i] >> q[i];       update(1, x[i], y[i], q[i]);     }     for (int i = 1; i <= m; i++) {       long long v = query(1, x[i], y[i]);       if (v != q[i]) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) {       cout << query(1, i, i) <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   char op[600001];   long long id[600001], ans[600001], s[600001];   long long n, m, t;   bool cmp(long long x, long long y) {     long long pa, pb;     if (op[x] ==  L ) {       pa = ((s[x] - t) % m + m) % m;     } else       pa = (s[x] + t) % m;     if (op[y] ==  L ) {       pb = ((s[y] - t) % m + m) % m;     } else       pb = (s[y] + t) % m;     if (pa != pb) return pa < pb;     return op[x] ==  L ;   }   long long id2[300001];   bool cmp2(long long x, long long y) {     if (s[x] != s[y]) {       return s[x] < s[y];     }     return op[x] ==  L ;   }   signed main() {     cin >> n >> m >> t;     for (long long i = 0; i < n; i++) {       cin >> s[i] >> op[i];       s[i]--;       id[i] = id2[i] = i;     }     sort(id, id + n, cmp);     sort(id2, id2 + n, cmp2);     long long pos = 0;     if (op[0] ==  L ) {       long long x = s[0] - t;       for (long long i = 0; i < n; i++)         if (op[i] ==  R ) {           long long y = s[i] + t;           if (s[i] > s[0]) y -= m;           if (y < x) continue;           pos = (pos + (y - x) / m + 1) % n;         }       pos = (n - pos) % n;     } else {       long long x = s[0] + t;       for (long long i = 0; i < n; i++) {         if (op[i] ==  L ) {           long long y = s[i] - t;           if (s[i] < s[0]) y += m;           if (y > x) continue;           pos = (pos + (x - y) / m + 1) % n;         }       }     }     long long p = 0;     for (long long i = 0; i < n; i++) {       if (id2[i] == 0) p = i;     }     p = (p + pos) % n;     long long q = 0;     for (long long i = 0; i < n; i++) {       if (id[i] == 0) q = i;     }     for (long long i = 0; i < n; i++) {       long long j = id[(q + i) % n];       long long x = (q + i) % n, y;       if (op[j] ==  L )         y = ((s[j] - t) % m + m) % m;       else         y = (s[j] + t) % m;       long long z = id2[(p + i) % n];       ans[z] = y + 1;     }     for (long long i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 5;   long long add[N << 2], sum[N << 2], color[N << 1];   int n, m;   void down(int rt, int len) {     if (add[rt]) {       add[(rt << 1)] += add[rt];       add[(rt << 1 | 1)] += add[rt];       sum[(rt << 1)] += add[rt] * (len - (len >> 1));       sum[(rt << 1 | 1)] += add[rt] * (len >> 1);       add[rt] = 0;       color[(rt << 1)] = color[(rt << 1 | 1)] = color[rt];       color[rt] = 0;     }   }   void build(int rt, int l, int r) {     if (l == r) {       color[rt] = l;       return;     }     int mid = (l + r) >> 1;     build((rt << 1), l, mid);     build((rt << 1 | 1), mid + 1, r);     color[rt] = (color[(rt << 1)] == color[(rt << 1 | 1)]) ? color[(rt << 1)] : 0;     sum[rt] = sum[(rt << 1)] + sum[(rt << 1 | 1)];   }   void modify(int rt, int l, int r, int L, int R, int x) {     if (L <= l && r <= R && color[rt]) {       add[rt] += abs(color[rt] - x);       sum[rt] += (r - l + 1) * abs(color[rt] - x);       color[rt] = x;       return;     }     down(rt, r - l + 1);     int mid = (l + r) >> 1;     if (L <= mid) modify((rt << 1), l, mid, L, R, x);     if (mid < R) modify((rt << 1 | 1), mid + 1, r, L, R, x);     color[rt] = (color[(rt << 1)] == color[(rt << 1 | 1)]) ? color[(rt << 1)] : 0;     sum[rt] = sum[(rt << 1)] + sum[(rt << 1 | 1)];   }   long long query(int rt, int l, int r, int L, int R) {     if (L <= l && r <= R) {       return sum[rt];     }     down(rt, r - l + 1);     long long t = 0ll;     int mid = (l + r) >> 1;     if (L <= mid) t += query((rt << 1), l, mid, L, R);     if (mid < R) t += query((rt << 1 | 1), mid + 1, r, L, R);     return t;   }   int main() {     scanf( %d%d , &n, &m);     build(1, 1, n);     while (m--) {       int op, l, r, x;       scanf( %d , &op);       if (op == 1) {         scanf( %d%d%d , &l, &r, &x);         modify(1, 1, n, l, r, x);       } else {         scanf( %d%d , &l, &r);         printf( %I64d n , query(1, 1, n, l, r));       }     }     return 0;   }


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


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i, x = 0, m, num;     cin >> n >> k;     map<int, int> mp;     int arr[1000000];     for (i = 0; (i < n) && (x < k); i++) {       cin >> num;       if (mp[num] == 0) {         arr[x] = num;         mp[num] = 1;         x++;       }     }     int j = 0;     for (m = i; m <= (n - 1); m++) {       cin >> num;       if (mp[num] == 1) {         continue;       } else if ((mp[num] == 0) && ((x - j) != k)) {         arr[x] = num;         mp[num] = 1;         x++;       } else {         mp[arr[j]] = 0;         j++;         arr[x] = num;         x++;         mp[num] = 1;       }     }     cout << x - j <<   n ;     for (m = x - 1; m >= j; m--) {       cout << arr[m] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k, q;   vector<int> style;   vector<vector<int> > place;   vector<int> base;   vector<vector<int> > t;   void read() {     cin >> n >> k;     style.resize(n + 1);     place.resize(100001);     base.resize(n + 1);     t.resize(n * 4 + 4);     for (int i = 1; i < n + 1; i++) cin >> style[i];     cin >> q;   }   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v] = vector<int>(1, base[tl]);     } else {       int tm = (tl + tr) / 2;       build(v * 2, tl, tm);       build(v * 2 + 1, tm + 1, tr);       merge(t[v * 2].begin(), t[v * 2].end(), t[v * 2 + 1].begin(),             t[v * 2 + 1].end(), back_inserter(t[v]));     }   }   int query(int v, int tl, int tr, int l, int r, int x) {     if (l > r) return 0;     if (tl == l && tr == r) {       vector<int>::iterator pos = lower_bound(t[v].begin(), t[v].end(), x);       return pos - t[v].begin();     } else {       int tm = (tl + tr) / 2;       return (query(v * 2, tl, tm, l, min(tm, r), x) +               query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, x));     }   }   int main() {     int x, y, last = 0;     int l, r;     read();     for (int i = 1; i < n + 1; i++) place[style[i]].push_back(i);     for (int i = 1; i < 100001; i++) {       for (int j = 0; j < place[i].size(); j++) {         if (j >= k)           base[place[i][j]] = place[i][j - k];         else           base[place[i][j]] = -1;       }     }     place.clear();     style.clear();     build(1, 1, n);     while (q--) {       cin >> x >> y;       l = ((x + last) % n) + 1;       r = ((y + last) % n) + 1;       if (l > r) swap(l, r);       last = query(1, 1, n, l, r, l);       cout << last << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     char a;     int k = 0;     vector<int> s;     while (1) {       cin >> a >> a;       k++;       if (a ==  + )         s.push_back(1);       else if (a ==  - )         s.push_back(-1);       else         break;     }     int n;     cin >> n;     int plus = 0, minus = 0;     for (int i = 0; i < k - 1; i++) {       if (s[i] == 1)         plus++;       else         minus++;     }     if (minus > n * plus || plus + 1 > n * (minus + 1)) {       cout <<  Impossible  << endl;       return 0;     }     if (plus + 1 > n + minus) {       cout <<  Possible  << endl;       int x = n + n * minus - plus - 1;       if (x > n - 1) {         cout << n;         x -= (n - 1);       } else {         cout << x + 1;         x = 0;       }       for (int i = 0; i < k - 1; i++) {         if (s[i] == 1) {           cout <<   +  ;           if (x > n - 1) {             cout << n;             x -= (n - 1);           } else {             cout << x + 1;             x = 0;           }         } else {           cout <<   -   << n;         }       }       cout <<   =   << n << endl;       return 0;     }     cout <<  Possible  << endl;     int x = n + minus - plus - 1;     if (x > n - 1) {       cout << n;       x -= (n - 1);     } else {       cout << x + 1;       x = 0;     }     for (int i = 0; i < k - 1; i++) {       if (s[i] == 1) {         cout <<   +  ;         if (x > n - 1) {           cout << n;           x -= (n - 1);         } else {           cout << x + 1;           x = 0;         }       } else {         cout <<   - 1 ;       }     }     cout <<   =   << n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 545;   int a[MAX_N];   int main() {     int n, minus = 0;     cin >> n;     int sum = 0;     for (int i = (0); i < (int)(2 * n - 1); ++i) {       cin >> a[i];       if (a[i] < 0) {         a[i] = abs(a[i]);         minus++;       }       sum += a[i];     }     sort(a, a + (2 * n) - 1);     if (n % 2 == 0 && minus % 2) sum -= (a[0] * 2);     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   const int MM = 998244353;   template <typename T, typename U>   static inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T &x, U y) {     if (x < y) x = y;   }   map<int, map<int, pair<int, int>>> mask;   int _runtimeTerror_() {     int n;     cin >> n;     vector<long long> b(n);     vector<int> even, odd;     set<int> s;     for (int i = 0; i < n; ++i) {       cin >> b[i];       if (!s.count(b[i])) {         if (b[i] & 1) {           odd.push_back(b[i]);         } else {           even.push_back(b[i]);         }       }       s.insert(b[i]);     }     if ((long long)s.size() < n) {       vector<int> ans(n, 1e8);       ans[0] = 0;       s.clear();       int cur = 1;       for (int i = 0; i < n; ++i) {         if (s.count(b[i])) {           continue;         }         ans[cur] = b[i];         ++cur;         s.insert(b[i]);       }       cout <<  YES n ;       for (int i = 0; i < n; ++i) {         cout << ans[i] <<    ;       }       cout <<   n ;       return 0;     }     if (n == 2) {       cout <<  NO n ;       return 0;     }     if (n == 3) {       int sum = b[0] + b[1] + b[2];       if (sum % 2) {         cout <<  NO n ;         return 0;       }       sum /= 2;       cout <<  YES n ;       cout << sum - b[0] <<     << sum - b[1] <<     << sum - b[2] <<   n ;       return 0;     }     assert(n >= 4);     if (even.empty()) {       int nn = min(n, 24);       vector<int> left, right;       for (int i = 0; i < (nn + 1) / 2; ++i) {         left.push_back(b[i]);       }       for (int i = 0; i < nn / 2; ++i) {         right.push_back(b[nn - 1 - i]);       }       reverse(right.begin(), right.end());       int tmp = (long long)right.size();       assert((long long)left.size() + (long long)right.size() == nn);       mask[0][0] = {0, 0};       for (int i = 0; i < (1 << tmp); ++i) {         for (int j = i; j; j = (j - 1) & i) {           int val = 0, f = 0;           for (int k = 0; k < tmp; ++k) {             if ((i & (1 << k)) && ((j & (1 << k)) == 0)) {               val += right[k];               ++f;             } else if (i & (1 << k)) {               val -= right[k];               --f;             }           }           mask[f][val] = {i, j};         }       }       tmp = (long long)left.size();       pair<int, int> ans = {-1, -1};       if (mask[0][0].first != 0) {         ans = mask[0][0];         ans.first <<= tmp;         ans.second <<= tmp;       }       for (int i = 0; i < (1 << tmp); ++i) {         if (ans.first != -1) {           break;         }         for (int j = i; j; j = (j - 1) & i) {           int val = 0, f = 0;           for (int k = 0; k < tmp; ++k) {             if ((i & (1 << k)) && ((j & (1 << k)) == 0)) {               val += left[k];               ++f;             } else if (i & (1 << k)) {               val -= left[k];               --f;             }           }           if (mask.count(-f) && mask[-f].count(-val)) {             ans = mask[-f][-val];             ans.first <<= tmp;             ans.second <<= tmp;             ans.first |= i;             ans.second |= j;             break;           }         }         if (ans.first != -1) {           break;         }       }       if (ans.first == -1) {         cout <<  NO n ;         return 0;       }       assert(__builtin_popcountll(ans.first) ==              2 * __builtin_popcountll(ans.second));       vector<int> lx, rx, tt;       for (int i = 0; i < nn; ++i) {         if ((ans.first & (1 << i)) && (ans.second & (1 << i))) {           rx.push_back(b[i]);         } else if (ans.first & (1 << i)) {           lx.push_back(b[i]);         } else {           tt.push_back(b[i]);         }       }       assert((long long)lx.size() == (long long)rx.size());       cout <<  YES n ;       int cur = 0;       for (int i = 0; i < (long long)lx.size(); ++i) {         cout << lx[i] - cur <<    ;         cur = lx[i] - cur;         cout << rx[i] - cur <<    ;         cur = rx[i] - cur;       }       for (auto &j : tt) {         cout << j - cur <<    ;       }       for (int i = nn; i < n; ++i) {         cout << b[i] - cur <<    ;       }       cout <<   n ;       return 0;     }     vector<int> t;     int cnt = min(3ll, (long long)even.size());     for (int i = 0; i < cnt; ++i) {       t.push_back(even.back());       even.pop_back();     }     if ((long long)t.size() % 2 == 0) {       even.push_back(t.back());       t.pop_back();     }     while ((long long)t.size() < 3) {       t.push_back(odd.back());       odd.pop_back();     }     int sum = accumulate(t.begin(), t.end(), 0);     assert(sum % 2 == 0);     cout <<  YES n ;     sum /= 2;     cout << sum - t[0] <<     << sum - t[1] <<     << sum - t[2] <<    ;     for (int i : even) {       cout << i - (sum - t[0]) <<    ;     }     for (int i : odd) {       cout << i - (sum - t[0]) <<    ;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) _runtimeTerror_();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long N_MAX = 1123;   const long long MOD = 998244353;   long long w;   long long h;   long long result = 1;   int main() {     ios_base::sync_with_stdio(0);     cin >> w;     cin >> h;     for (long long i = 1; i <= w; i++) {       for (long long j = 1; j <= h; j++) {         if (i == 1 && j == 1) {           result *= 4;         } else if (i == 1) {           result *= 2;         } else if (j == 1) {           result *= 2;         }         result %= MOD;       }     }     cout << result <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100005];   bool vis[100005];   long long min_val;   void dfs(int v, long long* arr) {     min_val = min(arr[v], min_val);     vis[v] = true;     for (int i = 0; i < g[v].size(); i++) {       int neig = g[v][i];       if (!vis[neig]) {         dfs(neig, arr);       }     }   }   int main() {     std::ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n, m, x, y;     cin >> n >> m;     long long* v = new long long[n + 1]();     for (int i = 1; i <= n; i++) {       cin >> v[i];     }     for (int i = 0; i < m; i++) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     long long ans = 0;     memset(vis, false, sizeof(vis));     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         min_val = LONG_MAX;         dfs(i, v);         ans += min_val;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int ans, n, m, k, a[12];   struct Edge {     int to, t;     Edge() { to = t = 0; }     Edge(int _to, int _t) {       to = _to;       t = _t;     }     bool operator<(const Edge &z) const { return t < z.t; }   };   vector<Edge> vec[N];   int d[N][12][12];   bool vis[12][12][12][12];   inline void dfs(int x) {     if (k + 1 == x) {       for (int i = 1; i <= k; i++)         for (int j = 1; j <= k; j++)           if (vis[i][a[i]][j][a[j]]) return;       ans++;       return;     }     for (int i = 1; i <= x; i++) a[x] = i, dfs(x + 1);   }   int main() {     scanf( %d%d%d , &n, &m, &k);     int s, e, t;     for (int i = 1; i <= m; i++)       scanf( %d%d%d , &s, &e, &t), vec[s].push_back(Edge(e, t));     for (int i = 1; i <= n; i++) {       sort(vec[i].begin(), vec[i].end());       for (int j = 0; j < vec[i].size(); j++)         d[vec[i][j].to][vec[i].size()][j + 1]++;     }     for (int i = 1; i <= n; i++)       for (int j = 0; j < vec[i].size(); j++)         for (int t = 1; t <= k; t++)           for (int l = 1; l <= k; l++)             if (d[vec[i][j].to][t][l]) {               if (t ^ vec[i].size())                 vis[vec[i].size()][j + 1][t][l] = 1;               else if (d[vec[i][j].to][t][l] > 1)                 vis[vec[i].size()][j + 1][t][l] = 1;             }     dfs(1);     return printf( %d n , ans), 0;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<int, int> > a;   priority_queue<pair<int, int> > b;   vector<pair<int, int> > A;   vector<pair<int, int> > B;   int main() {     int n, x;     scanf( %d%d , &n, &x);     int x0 = x;     for (int i = 0; i < n; i++) {       int t;       int h, m;       scanf( %d%d%d , &t, &h, &m);       if (t == 0)         A.push_back(pair<int, int>(h, m));       else         B.push_back(pair<int, int>(h, m));     }     int pa = 0, push_back = 0;     sort(A.begin(), A.end());     sort(B.begin(), B.end());     int ans = 0;     while (pa < A.size() && A[pa].first <= x)       a.push(pair<int, int>(A[pa].second, A[pa].first)), pa++;     while (push_back < B.size() && B[push_back].first <= x)       b.push(pair<int, int>(B[push_back].second, B[push_back].first)),           push_back++;     int nn = 0;     int cur = 0;     while (nn < 2) {       pair<int, int> k;       if (cur == 0) {         if (a.size() == 0) {           nn++;           continue;         }         k = a.top();         a.pop();       }       if (cur == 1) {         if (b.size() == 0) {           nn++;           continue;         }         k = b.top();         b.pop();       }       x += k.first;       ans++;       while (pa < A.size() && A[pa].first <= x)         a.push(pair<int, int>(A[pa].second, A[pa].first)), pa++;       while (push_back < B.size() && B[push_back].first <= x)         b.push(pair<int, int>(B[push_back].second, B[push_back].first)),             push_back++;       cur ^= 1;       nn = 0;     }     int ans2 = 0;     cur = 1;     nn = 0;     while (a.size()) a.pop();     while (b.size()) b.pop();     pa = push_back = 0;     x = x0;     while (pa < A.size() && A[pa].first <= x)       a.push(pair<int, int>(A[pa].second, A[pa].first)), pa++;     while (push_back < B.size() && B[push_back].first <= x)       b.push(pair<int, int>(B[push_back].second, B[push_back].first)),           push_back++;     while (nn < 2) {       pair<int, int> k;       if (cur == 0) {         if (a.size() == 0) {           nn++;           continue;         }         k = a.top();         a.pop();       }       if (cur == 1) {         if (b.size() == 0) {           nn++;           continue;         }         k = b.top();         b.pop();       }       x += k.first;       ans2++;       while (pa < A.size() && A[pa].first <= x)         a.push(pair<int, int>(A[pa].second, A[pa].first)), pa++;       while (push_back < B.size() && B[push_back].first <= x)         b.push(pair<int, int>(B[push_back].second, B[push_back].first)),             push_back++;       cur ^= 1;       nn = 0;     }     printf( %d n , max(ans, ans2));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, q, num;     cin >> n >> q;     vector<int> a(n), b(n), c(n);     for (int i = 0; i < n; ++i) cin >> a[i];     b[0] = a[0];     for (int i = 1; i < n; ++i) {       b[i] = max(a[i], b[i - 1]);       if (b[i] == a[i])         c[i - 1] = b[i - 1];       else         c[i - 1] = a[i];     }     while (q--) {       cin >> num;       if (num < n)         cout << b[num - 1] <<     << a[num] << endl;       else         cout << b[n - 1] <<     << c[(num - 1) % (n - 1)] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ull = unsigned long long;   template <class T = ll>   constexpr T TEN(int n) {     return (n == 0) ? 1 : 10 * TEN<T>(n - 1);   }   ll calc(string s) {     int n = int(s.size());     if (n == 1) {       if (s[0] ==  9 ) {         return 1989;       } else {         return 1990 + s[0] -  0 ;       }     }     ll u = calc(s.substr(1));     u += TEN(n - 1);     while (true) {       if (u / TEN(n - 1) % 10 == s[0] -  0 ) break;       u += TEN(n - 1);     }     return u;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       s = s.substr(4);       cout << calc(s) << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   bool myfunction(int i, int j) { return (i < j); }   int main() {     int n, a, b, h;     cin >> n >> a >> b;     vector<int> myvector(n);     for (int i = 0; i < n; ++i) {       cin >> h;       myvector.at(i) = h;     }     sort(myvector.begin(), myvector.end(), myfunction);     cout << myvector.at(b) - myvector.at(b - 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxN = 5005;   deque<deque<int> > Painter(mxN);   vector<bool> Painted(mxN);   vector<vector<int> > cnt(mxN, vector<int>(mxN, 0));   int main() {     int n, q;     cin >> n >> q;     for (int i = 0; i < q; i++) {       int l, r;       cin >> l >> r;       for (int j = l; j <= r; j++) {         if ((int)Painter[j].size() < 3) {           Painter[j].push_back(i);         }         Painted[j] = true;       }     }     int total_sections = 0;     for (int i = 1; i <= n; i++) {       total_sections += (Painted[i] == true);     }     for (int i = 1; i <= n; i++) {       if ((int)Painter[i].size() == 3 || (int)Painter[i].size() == 0) {         continue;       }       assert((int)Painter[i].size() < 3);       if ((int)Painter[i].size() == 1) {         for (int j = 0; j < q; j++) {           if (j == Painter[i].back()) {             continue;           }           cnt[Painter[i].back()][j]++;           cnt[j][Painter[i].back()]++;         }       } else {         cnt[Painter[i].back()][Painter[i].front()]++;         cnt[Painter[i].front()][Painter[i].back()]++;       }     }     int Min = 1e9;     for (int i = 0; i < q; i++) {       for (int j = i + 1; j < q; j++) {         Min = min(Min, cnt[i][j]);       }     }     assert(Min != 1e9);     cout << total_sections - Min <<   n ;     return 0;   }


#include <bits/stdc++.h>   const long long int INF = (1e9 + 12312), MOD = 1e9 + 7;   const long double EPS = 0.0000000001;   using namespace std;   vector<pair<long long int, long long int> > a;   pair<long long int, pair<long long int, long long int> > l(long long int x,                                                              long long int y) {     long long int x1, x2, y1, y2;     x1 = a[x].first;     x2 = a[y].first;     y1 = a[x].second;     y2 = a[y].second;     long long int a = y2 - y1;     long long int b = x1 - x2;     long long int c = x2 * y1 - x1 * y2;     return make_pair(a, make_pair(b, c));   }   bool can(long long int x, long long int y) {     auto ff = l(x, y);     long long int a1, b1, c1;     a1 = ff.first;     b1 = ff.second.first;     c1 = ff.second.second;     vector<long long int> rer;     for (long long int i = 0; i < (long long int)a.size(); i++) {       if (a1 * a[i].first + b1 * a[i].second + c1 != 0) {         rer.push_back(i);       }     }     if ((long long int)rer.size() < 3) {       return 1;     }     auto f2 = l(rer[0], rer[1]);     long long int a2, b2, c2;     a2 = f2.first;     b2 = f2.second.first;     c2 = f2.second.second;     for (long long int i = 0; i < (long long int)a.size(); i++) {       if (a1 * a[i].first + b1 * a[i].second + c1 != 0) {         if (a2 * a[i].first + b2 * a[i].second + c2 != 0) {           return 0;         }       }     }     return 1;   }   int main() {     long long int n;     cin >> n;     if (n < 3) {       cout <<  YES n ;       return 0;     }     for (long long int i = 0; i < n; i++) {       long long int x, y;       cin >> x >> y;       a.push_back(make_pair(x, y));     }     if (can(0, 1)) {       cout <<  YES n ;       return 0;     }     if (can(1, 2)) {       cout <<  YES n ;       return 0;     }     if (can(0, 2)) {       cout <<  YES n ;       return 0;     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const double PI = 3.14159265359;   int oneCt = 0, n;   class File {    public:     string name;     int type;     bool isNum;     int numVal;     File(string _name, int _type) : name(_name), type(_type), isNum(true) {       int sz = name.size();       string s = name;       numVal = 0;       if (s[0] ==  0 ) {         isNum = false;       } else {         for (int i = sz - 1, mult = 1; i >= 0; i--, mult *= 10) {           if (s[i] >=  0  && s[i] <=  9 ) {             numVal += mult * (s[i] -  0 );           } else {             isNum = false;           }         }       }     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     vector<bool> avail(n + 1, true);     vector<File> files;     for (int i = 0; i < n; i++) {       int x;       string s;       cin >> s >> x;       oneCt += x;       File f(s, x);       files.push_back(f);     }     vector<File> ob, zb;     for (auto f : files) {       if (f.isNum) {         int nv = f.numVal;         if (nv <= n) avail[nv] = false;         if (nv > oneCt && f.type)           ob.push_back(f);         else if (!f.type && (nv <= oneCt || nv > n)) {           zb.push_back(f);         }       } else if (f.type)         ob.push_back(f);       else         zb.push_back(f);     }     vector<string> operations;     queue<File> qob, qob2, qzb, qzb2;     for (auto f : ob) {       if (f.isNum && f.numVal > oneCt && f.numVal <= n) {         qob.push(f);       } else {         qob2.push(f);       }     }     while (qob2.size()) {       qob.push(qob2.front());       qob2.pop();     }     for (auto f : zb) {       if (f.isNum && f.numVal <= oneCt) {         qzb.push(f);       } else {         qzb2.push(f);       }     }     while (qzb2.size()) {       qzb.push(qzb2.front());       qzb2.pop();     }     stack<int> oneAvail, zeroAvail;     for (int i = 1; i <= n; i++) {       if (i <= oneCt && avail[i])         oneAvail.push(i);       else if (i > oneCt && avail[i])         zeroAvail.push(i);     }     while (qob.size() || qzb.size()) {       if (qob.size() && oneAvail.size()) {         auto f = qob.front();         if (f.isNum && f.numVal <= n) {           zeroAvail.push(f.numVal);         }         string s =  move  ;         s += f.name;         s +=    ;         s += to_string(oneAvail.top());         operations.push_back(s);         qob.pop();         oneAvail.pop();       } else if (qzb.size() && zeroAvail.size()) {         auto f = qzb.front();         if (f.isNum && f.numVal <= oneCt) {           oneAvail.push(f.numVal);         }         string s =  move  ;         s += f.name;         s +=    ;         s += to_string(zeroAvail.top());         operations.push_back(s);         qzb.pop();         zeroAvail.pop();       } else {         auto f = qob.front();         if (f.isNum && f.numVal <= n) {           zeroAvail.push(f.numVal);         }         string s =  move  ;         s += f.name;         s +=   aaaaaa ;         operations.push_back(s);         f.name =  aaaaaa ;         f.isNum = false;         qob.pop();         qob.push(f);       }     }     cout << operations.size() << endl;     for (string s : operations) {       cout << s << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans = 1e18;   vector<char> ops;   void solve(vector<long long> a, int pos) {     if (pos == 3) {       ans = min(ans, a[0]);       return;     }     for (int i = 0; i < (int)(a).size(); ++i) {       for (int j = i + 1; j < (int)(a).size(); ++j) {         long long val = a[i];         if (ops[pos] ==  * ) {           val *= a[j];         } else {           val += a[j];         }         vector<long long> b;         for (int k = 0; k < (int)(a).size(); ++k) {           if (i == k || j == k) {             continue;           }           b.push_back(a[k]);         }         b.push_back(val);         solve(b, pos + 1);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     vector<long long> a(4);     for (int i = 0; i < 4; ++i) {       cin >> a[i];     }     for (int i = 0; i < 3; ++i) {       char c;       cin >> c;       ops.push_back(c);     }     solve(a, 0);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long INF = 9999999999;   double EPSILON = 0.00000001;   int sint(string s) {     int num = 0;     istringstream myStream(s);     (myStream >> num);     return num;   }   string str(int num) {     ostringstream oss;     oss << num;     return oss.str();   }   vector<string> split(string s) {     vector<string> tokens;     stringstream os(s);     string temp;     while (os >> temp) {       tokens.push_back(temp);     }     return tokens;   }   int maxv(vector<int> v) {     int m = -9999999;     for (int i = 0; i < v.size(); i++) m = max(m, v[i]);     return m;   }   int minv(vector<int> v) {     int m = 9999999;     for (int i = 0; i < v.size(); i++) m = min(m, v[i]);     return m;   }   int main() {     long long n;     cin >> n;     long long s = 0;     while (n != 1) {       s += n;       long long root = sqrt(n);       bool found = false;       for (long long r = 2; r <= root; r++) {         if (n % r == 0) {           n /= r;           found = true;           break;         }       }       if (not found) n = 1;     }     cout << s + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[100005];   char notValid[15] = { B ,  C ,  D ,  E ,  F ,  G ,  J ,  K ,                         L ,  N ,  P ,  Q ,  R ,  S ,  Z };   bool valid(char c) {     static int i;     for (i = 0; i < 15; ++i)       if (c == notValid[i]) return false;     return true;   }   bool check(char *s) {     int i;     int len = strlen(s);     int lend2 = len / 2;     for (i = 0; i < lend2; ++i) {       if (!valid(s[i]) || !valid(s[len - i - 1]) || (s[i] != s[len - i - 1]))         return false;     }     if (len & 1) return valid(s[lend2]);     return true;   }   int main(void) {     int i;     while (scanf( %s , str) == 1) {       printf( %s n , check(str) ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(int a) {     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(int a) {     if (a < 0) {       a = -a;       putchar( - );     }     write(a);     puts(  );   }   const int N = 200005, oo = 1e9;   int ans[N], fa[N];   pair<pair<int, int>, int> a[N];   int nedge, wson[N], ed[N], nextt[N], son[N], tree[N << 2], lazy[N << 2], peo[N],       deep[N], ti, n, m, pos[N], father[N], in[N], top[N];   inline void aedge(int a, int b) {     nextt[++nedge] = son[a];     son[a] = nedge;     ed[nedge] = b;   }   inline void cao(int nod, int r, int x) {     tree[nod] = x + deep[pos[r]] * 2;     lazy[nod] = x;   }   inline void pushdown(int nod, int l, int r) {     if (lazy[nod] == -oo) return;     int mid = (l + r) >> 1;     cao(nod << 1, mid, lazy[nod]);     cao(nod << 1 | 1, r, lazy[nod]);     lazy[nod] = -oo;   }   inline int ask(int l, int r, int i, int j, int s, int nod) {     if (l > 1 && tree[nod] <= s) return 0;     if (l == r) return pos[l];     pushdown(nod, l, r);     int mid = (l + r) >> 1;     if (j <= mid)       return ask(l, mid, i, j, s, nod << 1);     else if (i > mid)       return ask(mid + 1, r, i, j, s, nod << 1 | 1);     int t = ask(mid + 1, r, mid + 1, j, s, nod << 1 | 1);     if (t) return t;     return ask(l, mid, i, mid, s, nod << 1);   }   inline void insert(int l, int r, int i, int j, int s, int nod) {     if (l == i && r == j) {       lazy[nod] = s;       cao(nod, r, s);       return;     }     pushdown(nod, l, r);     int mid = (l + r) >> 1;     if (j <= mid)       insert(l, mid, i, j, s, nod << 1);     else if (i > mid)       insert(mid + 1, r, i, j, s, nod << 1 | 1);     else {       insert(l, mid, i, mid, s, nod << 1);       insert(mid + 1, r, mid + 1, j, s, nod << 1 | 1);     }     tree[nod] = max(tree[nod << 1], tree[nod << 1 | 1]);   }   void dfs1(int p) {     peo[p] = 1;     wson[p] = -1;     for (int i = son[p]; i; i = nextt[i]) {       deep[ed[i]] = deep[p] + 1;       dfs1(ed[i]);       peo[p] += peo[ed[i]];       if (wson[p] == -1 || peo[ed[i]] > peo[wson[p]]) wson[p] = ed[i];     }   }   void dfs2(int p) {     pos[in[p] = ++ti] = p;     if (p == wson[father[p]])       top[p] = top[father[p]];     else       top[p] = p;     if (wson[p] != -1) dfs2(wson[p]);     for (int i = son[p]; i; i = nextt[i])       if (ed[i] != wson[p]) dfs2(ed[i]);   }   inline bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {     return a.first.second + deep[a.first.first] ==                    b.first.second + deep[b.first.first]                ? a.first.first < b.first.first                : a.first.second + deep[a.first.first] <                      b.first.second + deep[b.first.first];   }   void update(int u, int v, int x) {     while (top[u] != top[v]) {       insert(1, n, in[top[u]], in[u], x, 1);       u = father[top[u]];     }     if (u != v) insert(1, n, in[v] + 1, in[u], x, 1);   }   int query(int u, int t) {     int ans = deep[u] + t;     while (1) {       int t = ask(1, n, in[top[u]], in[u], ans, 1);       if (t) return t;       u = father[top[u]];     }   }   int main() {     n = read() + 1;     m = read();     for (int i = 1; i < (N << 2); i++) lazy[i] = -oo;     for (int i = 2; i <= n; i++) {       deep[i] = deep[father[i] = read() + 1] + 1;       aedge(father[i], i);     }     dfs1(1);     dfs2(1);     for (int i = 1; i <= m; i++) {       a[i].first.first = read() + 1;       a[i].first.second = read();       a[i].second = i;     }     sort(&a[1], &a[m + 1], cmp);     for (int i = 1; i <= m; i++) {       int t = query(a[i].first.first, a[i].first.second);       ans[a[i].second] =           a[i].first.second + (deep[a[i].first.first] - deep[t]) * 2;       update(a[i].first.first, t, ans[a[i].second] - deep[a[i].first.first]);     }     for (int i = 1; i <= m; i++) write(ans[i]), putchar(   );   }


#include <bits/stdc++.h>   using namespace std;   const int mv4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   const int mv8[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},                          {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   const int inf = (int)1e9;   const char *boo[2] = { NO ,  YES };   const char *inv =  Impossible ;   inline void term(string msg = inv) {     cout << msg << endl;     exit(0);   }   const char *in =  in.txt ;   const char *out =  out.txt ;   struct Point {     long long y, x;     Point(long long y = 0, long long x = 0) : y(y), x(x) {}     Point operator-(const Point &a) { return Point(y - a.y, x - a.x); }   };   inline unsigned long long sq(long long d) { return d * d; }   inline unsigned long long sqdist(const Point &a, const Point &b) {     return sq(a.x - b.x) + sq(a.y - b.y);   }   inline long long dot(const Point &a, const Point &b) {     return a.x * b.x + a.y * b.y;   }   const int MAX = 1000;   int main() {     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     int n;     unsigned long long r = 0;     cin >> n;     vector<Point> v(n);     unordered_map<int, int> dup, ddown;     for (int i = 0; i < n; i++) {       cin >> v[i].x >> v[i].y;       dup[v[i].y - v[i].x]++;       ddown[v[i].y + v[i].x]++;     }     for (auto e : dup) {       unsigned long long t = (e.second * (e.second - 1)) / 2;       r += t;     }     for (auto e : ddown) {       unsigned long long t = (e.second * (e.second - 1)) / 2;       r += t;     }     cout << r <<   n ;     exit(0);   }


#include <bits/stdc++.h>   bool commonDigits(long a, long b) {     bool digits[10] = {0};     bool output(0);     while (a > 0) {       digits[a % 10] = 1;       a /= 10;     }     while (b > 0) {       if (digits[b % 10]) {         output = 1;         break;       };       b /= 10;     }     return output;   }   int main() {     long n(0);     scanf( %ld , &n);     long total(0);     std::vector<long> divisors;     for (long k = 1; k <= sqrt(n); k++) {       if (n % k == 0) {         divisors.push_back(k);         if (n / k > k) {           divisors.push_back(n / k);         }       }     }     for (long k = 0; k < divisors.size(); k++) {       if (commonDigits(n, divisors[k])) {         ++total;       }     }     printf( %ld n , total);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000002;   long long memo[MAXN];   long long cost[MAXN];   int tin[MAXN];   int low[MAXN];   bool in_stack[MAXN];   int Stack[MAXN];   int comp[MAXN];   vector<pair<int, int> > g[MAXN];   vector<pair<int, int> > t[MAXN];   int n, m, s;   int u, v, w;   int SCC, T, top;   void fast_io() {     ios::sync_with_stdio(false);     cin.tie(NULL);   }   long long contrib(int o) {     int lo = 0, hi = o;     int n = -1;     while (lo <= hi) {       int mid = (lo + hi) >> 1;       if (1LL * mid * (mid + 1) <= (o << 1))         n = mid, lo = mid + 1;       else         hi = mid - 1;     }     return 1LL * o * (n + 1) - 1LL * n * (n + 1) * (n + 2) / 6;   }   void tarjan(int u) {     low[u] = tin[u] = ++T;     Stack[top++] = u, in_stack[u] = 1;     for (auto v : g[u]) {       if (!tin[v.first]) tarjan(v.first);       if (in_stack[v.first]) low[u] = min(low[u], low[v.first]);     }     if (tin[u] == low[u]) {       ++SCC;       while (top) {         int v = Stack[--top];         in_stack[v] = 0, comp[v] = SCC;         if (u == v) break;       }     }   }   long long solve(int u) {     if (memo[u] != -1) return memo[u];     long long res = cost[u];     for (auto v : t[u]) {       res = max(res, cost[u] + v.second + solve(v.first));     }     return memo[u] = res;   }   int main() {     fast_io();     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> u >> v >> w;       g[u].push_back(make_pair(v, w));     }     cin >> s;     tarjan(s);     for (int i = 1; i <= n; i++) {       if (!tin[i]) continue;       int u = comp[i];       for (auto v : g[i]) {         int to = comp[v.first];         if (u != to)           t[u].push_back(make_pair(to, v.second));         else           cost[u] += contrib(v.second);       }     }     memset(memo, -1, sizeof(memo));     printf( %lld n , solve(comp[s]));     return 0;   }


#include <bits/stdc++.h>   char buf[1 << 21], *p1 = buf, *p2 = buf;   inline long long read() {     long long ret = 0, ff = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) ff = -ff;       ch = getchar();     }     while (isdigit(ch)) {       ret = (ret << 3) + (ret << 1) + ch -  0 ;       ch = getchar();     }     return ret * ff;   }   long long p, q, b;   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   inline long long ksm(long long a, long long b) {     long long res = 1, base = a;     while (b) {       if (b & 1) {         res = (res * base) % q;         if (res == 0) return 0;       }       base = (base * base) % q;       b >>= 1;     }     return res;   }   int main() {     int T = read();     while (T--) {       p = read(), q = read(), b = read();       long long g = gcd(p, q);       p /= g;       q /= g;       if (q == 1ll) {         printf( Finite n );       } else {         while (1) {           g = gcd(q, b);           if (g == 1) break;           while (q % g == 0) q /= g;           if (q == 1) break;         }         if (q == 1) {           printf( Finite n );         } else {           printf( Infinite n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0)->sync_with_stdio(0);     int n;     cin >> n;     vector<vector<int>> adj(n);     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v, --u, --v;       adj[u].push_back(v), adj[v].push_back(u);     }     array<int, 2> cnt{};     function<void(int, int, int)> dfs = [&](int u, int p, int c) {       ++cnt[c];       for (auto v : adj[u]) {         if (v != p) {           dfs(v, u, !c);         }       }     };     dfs(0, 0, 0);     cout << min(cnt[0], cnt[1]) - 1 <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename G>   struct triple {     G first, second, T;   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long d, n, m;     cin >> d >> n >> m;     vector<pair<long long, long long> > x(m + 2);     x[m + 1].first = d;     for (int i = 1; i <= m; i++) cin >> x[i].first >> x[i].second;     sort(x.begin(), x.end());     vector<int> mn(m + 2);     stack<int> s;     for (int i = m + 1; i >= 0; i--) {       while (!s.empty() && x[s.top()].second > x[i].second) s.pop();       if (!s.empty())         mn[i] = s.top();       else         mn[i] = m + 2;       s.push(i);     }     long long comb = n, ans = 0;     for (int i = 0; i < m + 1; i++) {       int p = mn[i];       long long t = min(n - comb, max(x[p].first - x[i].first - comb, 0LL));       ans += x[i].second * t;       comb += t;       comb -= x[i + 1].first - x[i].first;       if (comb < 0) {         cout <<  -1 n ;         return 0;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void run() {     vector<string> v;     for (int i = 0; i < 8; i++) {       string s;       cin >> s;       v.push_back(s);     }     int a = INT_MAX, b = INT_MAX;     for (int i = 0; i < 8; i++) {       int c = 0;       for (int j = 7; j >= 0; j--) {         if (v[j][i] ==  B ) {           b = min(b, c);           break;         } else if (v[j][i] ==  W )           break;         c++;       }     }     for (int i = 0; i < 8; i++) {       int c = 0;       for (int j = 0; j < 8; j++) {         if (v[j][i] ==  W ) {           a = min(a, c);           break;         } else if (v[j][i] ==  B )           break;         c++;       }     }     if (a <= b)       cout <<  A ;     else       cout <<  B ;     return;   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   struct Lesson {     long long a, b;     int c, id;     bool operator<(const Lesson &t) const { return c < t.c; }   } ls[55];   int fstc[110];   long long dp[55][55][110];   pair<int, int> trans[55][55][110];   inline void upd(int x1, int y1, int z1, int y2, int z2, long long val) {     if (dp[x1][y1][z1] < val) {       dp[x1][y1][z1] = val;       trans[x1][y1][z1] = make_pair(y2, z2);     }   }   void Print(int lvl, int od, int ad) {     if (lvl == 0) {       printf( %d %I64d n , ls[od].id, ls[od].a + ad);       return;     }     Print(lvl - 1, trans[lvl][od][ad].first, trans[lvl][od][ad].second);     printf( %d %lld n , ls[od].id, ls[od].a + ad);   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < m; i++) {       scanf( %I64d%I64d%d , &ls[i].a, &ls[i].b, &ls[i].c);       ls[i].id = i + 1;     }     sort(ls, ls + m);     memset(fstc, -1, sizeof(fstc));     for (int i = 0; i < m; i++)       if (fstc[ls[i].c] == -1) fstc[ls[i].c] = i;     for (int i = 0; i < m; i++) {       for (int j = 0; j <= (int)(ls[i].b - ls[i].a); j++) {         dp[0][i][j] = (ls[i].a + j);       }     }     for (int i = 1; i < n; i++) {       for (int j = 0; j < m; j++) {         int c = ls[j].c;         for (int task = 0; task <= 100; task++)           if (dp[i - 1][j][task]) {             long long val = ls[j].a + task;             if (val > ls[j].b) continue;             long long knval = val * 1ll * k;             long long nvalk = val + 1ll * k;             for (int nc = c + 1; nc <= 100; nc++) {               if (fstc[nc] == -1) continue;               for (int nj = fstc[nc]; nj < m && ls[nj].c == nc; nj++) {                 if (ls[nj].a <= knval && knval <= ls[nj].b) {                   int ntask = (int)(knval - ls[nj].a);                   upd(i, nj, ntask, j, task, dp[i - 1][j][task] + knval);                 }                 if (ls[nj].a <= nvalk && nvalk <= ls[nj].b) {                   int ntask = (int)(nvalk - ls[nj].a);                   upd(i, nj, ntask, j, task, dp[i - 1][j][task] + nvalk);                 }               }             }           }       }     }     long long ans = 0;     int y = -1, z = -1;     for (int i = 0; i < m; i++)       for (int j = 0; j <= (int)(ls[i].b - ls[i].a); j++) {         if (dp[n - 1][i][j] > ans) {           ans = dp[n - 1][i][j];           y = i;           z = j;         }       }     if (ans == 0 || y == -1 || z == -1) {       printf( NO n );       return 0;     }     printf( YES n );     Print(n - 1, y, z);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Rand(int x) { return rand() * rand() % x + 1; }   const int INF = 0x3f3f3f3f, N = 5000005, M = 2000005, MOD = 1e9 + 7;   long long qpow(long long a, long long b) {     long long ret = 1;     for (; b; b >>= 1, a = a * a % MOD)       if (b & 1) ret = ret * a % MOD;     return ret;   }   long long val[N];   map<int, int> g[N];   map<long long, int> has;   int find(int id, int x) {     if (x == g[id][x]) return x;     return g[id][x] = find(id, g[id][x]);   }   void Union(int id, int x, int y) {     int fx = find(id, x), fy = find(id, y);     if (fx == fy) return;     g[id][fy] = fx;   }   int cnt[N], ss;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int n, m, c;     cin >> n >> m >> c;     for (int i = 1; i <= n; i++) cin >> val[i];     long long ans = qpow(2, c) * qpow(2, n) % MOD;     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       long long x = val[u] ^ val[v];       if (!has.count(x)) has[x] = ++ss, cnt[ss] = n;       x = has[x];       if (!g[x][u]) g[x][u] = u;       if (!g[x][v]) g[x][v] = v;       if (find(x, u) == find(x, v)) continue;       Union(x, u, v);       ans = (ans - qpow(2, cnt[x]) + MOD) % MOD;       cnt[x]--;       ans = (ans + qpow(2, cnt[x]) + MOD) % MOD;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, minx, h, m, ans;     int a[105];     cin >> n >> minx;     for (int i = 1; i <= n; i++) {       cin >> h >> m;       a[i] = h * 60 + m;     }     if (a[1] >= minx + 1) {       cout << 0 <<     << 0 << endl;       return 0;     }     for (int i = 2; i <= n; i++) {       if (a[i] - a[i - 1] >= minx * 2 + 2) {         ans = a[i - 1] + minx + 1;         cout << ans / 60 <<     << ans % 60 << endl;         return 0;       }     }     ans = a[n] + minx + 1;     cout << ans / 60 <<     << ans % 60 << endl;     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-10, pi = acos(-1.0);   const int maxS = 1e2 + 10;   const int maxS2 = 5e4 + 10;   const unsigned long long MOD = 1e9 + 7;   using namespace std;   struct point {     int x, y, z;   };   int n, m, i, j, k, x, y, z, T, ii, t, l, r, pos;   int tot = 0, cnt = 0, ans = 0, sum = 0;   bool chk, chk2[maxS], flag;   string s, s1, s2;   char c[maxS][maxS];   vector<point> res;   void print(int x, int y, int l) {     int i;     for (i = x - l; i <= x + l; i++) c[i][y] =  # ;     for (i = y - l; i <= y + l; i++) c[x][i] =  # ;   }   bool deal(int x, int y, int l) {     int i;     if (x - l < 0 || x + l >= n || y - l < 0 || y + l >= m) return false;     for (i = x - l; i <= x + l; i++)       if (c[i][y] ==  . ) return false;     for (i = y - l; i <= y + l; i++)       if (c[x][i] ==  . ) return false;     print(x, y, l);     res.push_back({x, y, l});     chk = true;     return true;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) cin >> c[i][j];     for (i = 0; i < n; i++)       for (j = 0; j < m; j++)         if (c[i][j] ==  * ) {           chk = false;           for (k = 1; k < min(n, m); k++)             if (deal(i, j, k)) break;           if (!chk)             for (k = 1; k < min(n, m); k++)               if (deal(i + k, j, k)) break;           if (!chk)             for (k = 1; k < min(n, m); k++)               if (deal(i - k, j, k)) break;           if (!chk)             for (k = 1; k < min(n, m); k++)               if (deal(i, j + k, k)) break;           if (!chk)             for (k = 1; k < min(n, m); k++)               if (deal(i, j - k, k)) break;         }     chk = true;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++)         if (c[i][j] ==  * ) chk = false;     if (!chk)       cout << -1 << endl;     else {       cout << res.size() << endl;       for (i = 0; i < res.size(); i++)         cout << res[i].x + 1 <<     << res[i].y + 1 <<     << res[i].z << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long l, r;     cin >> l >> r;     int t = 0;     while (l != r) {       r >>= 1;       l >>= 1;       ++t;     }     cout << ((1ll << t) - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9;   const int maxc = 77;   struct thang {     int X, B;   };   thang A[1010];   double f[1010];   int trace[1010], st[1010];   int N, L;   void nhap() {     scanf( %d%d , &N, &L);     for (int i = 1; i <= N; i++) scanf( %d%d , &A[i].X, &A[i].B);     A[0].X = 0;   }   void solve(double mid) {     for (int i = 1; i <= N; i++) f[i] = oo;     f[0] = 0;     for (int i = 1; i <= N; i++) {       int vt = 0;       double t = oo;       for (int j = i - 1; j >= 0; j--)         if (f[j] + sqrt(abs((A[i].X - A[j].X) - L * 1.0)) - mid * 1.0 * A[i].B <             t) {           vt = j;           t = f[j] + sqrt(abs((A[i].X - A[j].X) - L * 1.0)) - mid * 1.0 * A[i].B;         }       f[i] = t;       trace[i] = vt;     }   }   void chat() {     double l = 0, r = oo;     for (int i = 1; i <= maxc; i++) {       double mid = (l + r) / 2;       solve(mid);       if (f[N] <= 0)         r = mid;       else         l = mid;     }     int top = 0, i = N;     while (i != 0) {       st[++top] = i;       i = trace[i];     }     while (top > 0) printf( %d  , st[top--]);   }   int main() {     nhap();     chat();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[300005], op, l, r;   long long fib[300005 + 100];   struct wyh {     long long tagl, tagr, sum;   } tree[300005 * 4];   inline long long getint() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   inline void update(int x) {     tree[x].sum = tree[x * 2].sum + tree[x * 2 + 1].sum;     if (tree[x].sum >= 1000000009) tree[x].sum %= 1000000009;   }   inline void build(int x, int l, int r) {     if (l == r) {       tree[x].sum = a[l];       return;     }     int mid = (l + r) >> 1;     build(x * 2, l, mid), build(x * 2 + 1, mid + 1, r);     update(x);   }   inline void modify(int x, int l, int r, int s, int t, int c, int d);   inline void push(int x, int l, int r) {     if (tree[x].tagl || tree[x].tagr) {       int mid = (l + r) >> 1;       modify(x * 2, l, mid, l, r, tree[x].tagl, tree[x].tagr);       modify(x * 2 + 1, mid + 1, r, l, r, tree[x].tagl, tree[x].tagr);       tree[x].tagl = tree[x].tagr = 0;     }   }   inline long long get(int a, int b, int x) {     if (x == 0) return a;     if (x == 1) return b;     return (a * fib[x - 1] % 1000000009 + b * fib[x] % 1000000009) % 1000000009;   }   inline void modify(int x, int l, int r, int s, int t, int c, int d) {     if (s <= l && t >= r) {       int first, second;       first = get(c, d, l - s), second = get(c, d, l - s + 1);       c = first, d = second;       tree[x].tagl += c, tree[x].tagr += d;       tree[x].tagl %= 1000000009, tree[x].tagr %= 1000000009;       tree[x].sum = (tree[x].sum + get(c, d, r - l + 2) - d) % 1000000009;       return;     }     push(x, l, r);     int mid = (l + r) >> 1;     if (s <= mid) modify(x * 2, l, mid, s, t, c, d);     if (t > mid) modify(x * 2 + 1, mid + 1, r, s, t, c, d);     update(x);   }   inline long long query(int x, int l, int r, int s, int t) {     if (s <= l && t >= r) return tree[x].sum;     int mid = (l + r) >> 1;     push(x, l, r);     long long tmp = 0;     if (s <= mid) tmp += query(x * 2, l, mid, s, t);     if (t > mid) tmp += query(x * 2 + 1, mid + 1, r, s, t);     return tmp;   }   void work() {     n = getint(), m = getint();     for (int i = 1; i <= n; ++i) a[i] = getint();     fib[1] = 1;     for (int i = 2; i <= n + 5; ++i)       fib[i] = (fib[i - 1] + fib[i - 2]) % 1000000009;     build(1, 1, n);     for (int i = 1; i <= m; ++i) {       op = getint(), l = getint(), r = getint();       if (op == 1)         modify(1, 1, n, l, r, 1, 1);       else         printf( %I64d n ,                (query(1, 1, n, l, r) % 1000000009 + 1000000009) % 1000000009);     }   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   long long size(const T& x) {     return x.size();   }   #pragma GCC optimize( Ofast )   template <class T>   T smod(T a, T b) {     return (a % b + b) % b;   }   long long pw(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b % 2) res = (res * a) % 1000000007;       b /= 2;       a = a * a % 1000000007;     }     return res;   }   void solve() {     long long n;     cin >> n;     string S;     cin >> S;     long long cntk = 0;     for (long long i = (0); i < (n); ++i) cntk += (S[i] ==  ? );     vector<long long> A(n);     A[0] = (S[0] ==  a );     for (long long i = (1); i < (n); ++i) A[i] = A[i - 1] + (S[i] ==  a );     vector<long long> C(n);     C[n - 1] = (S[n - 1] ==  c );     for (long long i = (n - 2); i > -1; --i) C[i] = C[i + 1] + (S[i] ==  c );     vector<long long> KL(n);     KL[0] = (S[0] ==  ? );     for (long long i = (1); i < (n); ++i) KL[i] = KL[i - 1] + (S[i] ==  ? );     vector<long long> KR(n);     KR[n - 1] = (S[n - 1] ==  ? );     for (long long i = (n - 2); i > -1; --i) KR[i] = KR[i + 1] + (S[i] ==  ? );     long long ans = 0;     for (long long i = (1); i < (n - 1); ++i) {       if (S[i] ==  a  || S[i] ==  c ) continue;       long long cnta = A[i - 1];       long long cntc = C[i + 1];       long long cntkl = KL[i - 1];       long long cntkr = KR[i + 1];       long long isk = (S[i] ==  ? );       ans = (ans + cnta * cntc * pw(3, cntk - isk)) % 1000000007;       ans = (ans + cnta * cntkr * pw(3, cntk - 1 - isk)) % 1000000007;       ans = (ans + cntkl * cntc * pw(3, cntk - 1 - isk)) % 1000000007;       ans = (ans + cntkl * cntkr * pw(3, cntk - 2 - isk)) % 1000000007;     }     cout << ans << endl;   }   int main() {     cin.sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     solve();     return 0;   }


#include <bits/stdc++.h>   int main() {     char s[101];     int cnt[2] = {};     scanf( %s , s);     for (int i = 0; s[i]; i++) cnt[s[i] ==  - ]++;     printf( %s n , cnt[0] && cnt[1] % cnt[0] ?  NO  :  YES );   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int p[maxn], w[maxn];   vector<pair<pair<int, int>, int>> a;   int find(int x) {     if (p[x] == x)       return x;     else {       int ret = find(p[x]);       w[x] ^= w[p[x]];       return p[x] = ret;     }   }   int main() {     int l, r, n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> l >> r;       a.push_back(make_pair(make_pair(l, 0), i));       a.push_back(make_pair(make_pair(r, 1), i));     }     sort(a.begin(), a.end());     for (int i = 0; i < n; i++) p[i] = i;     for (int i = 0; i < a.size(); i += 2)       if (a[i].second != a[i + 1].second) {         int ret = a[i].first.second == a[i + 1].first.second;         int u = a[i].second, v = a[i + 1].second;         if (find(u) == find(v)) {           if (w[u] ^ w[v] ^ ret) {             cout << -1 << endl;             return 0;           }         } else {           w[p[v]] = ret ^ w[v];           p[p[v]] = u;         }       }     for (int i = 0; i < n; i++) {       find(i);       cout << w[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace IO {   const unsigned int Buffsize = 1 << 15, Output = 1 << 23;   static char Ch_[Buffsize], *S_ = Ch_, *T_ = Ch_;   static char Out[Output], *nowps = Out;   inline void flush() {     fwrite(Out, 1, nowps - Out, stdout);     nowps = Out;   }   template <class T>   inline bool chkmax(T &_, T __) {     return _ < __ ? _ = __, 1 : 0;   }   template <class T>   inline bool chkmin(T &_, T __) {     return _ > __ ? _ = __, 1 : 0;   }   template <class T>   inline T read(T &_) {     _ = 0;     static char __;     T ___ = 1;     for (__ = ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin),                              S_ == T_)                    ? 0                    : *S_++);          !isdigit(__);          __ = ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin),                              S_ == T_)                    ? 0                    : *S_++))       if (__ ==  - ) ___ = -1;     for (; isdigit(__);          __ = ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin),                              S_ == T_)                    ? 0                    : *S_++))       _ = (_ << 3) + (_ << 1) + (__ ^ 48);     return _ *= ___;   }   template <class T>   inline void write(T _, char __ =   n ) {     if (!_) *nowps++ = ( 0 );     if (_ < 0) *nowps++ = ( - ), _ = -_;     static unsigned int sta[111], tp;     for (tp = 0; _; _ /= 10) sta[++tp] = _ % 10;     for (; tp; *nowps++ = (sta[tp--] ^ 48))       ;     *nowps++ = (__);   }   }  // namespace IO   inline void proStatus() {     ifstream t( /proc/self/status );     cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>());   }   using namespace IO;   const int N = 1e5 + 10;   const int M = 3e5 + 10;   vector<pair<int, int> > Q[N];   int n, q, root[N], a[N], ans[M];   struct Fenwick_Tree {     int S[N], res;     Fenwick_Tree() { memset(S, (0x3f3f3f3f), sizeof(S)); }     void update(int first, int second) {       first = n - first + 1;       for (; first < N; first += first & -first) chkmin(S[first], second);     }     int query(int first) {       first = n - first + 1;       for (res = (0x3f3f3f3f); first; first -= first & -first)         chkmin(res, S[first]);       return res;     }   } T1;   struct Chairman_Tree {     int cnt;     struct node {       int ch[2], pos;     } T[N * 200];     void update(int &first, int pre, int l, int r, int pos, int val) {       T[first = ++cnt] = T[pre], chkmax(T[first].pos, pos);       if (l ^ r) {         if (val <= ((l + r) >> 1))           update((T[first].ch[0]), (T[pre].ch[0]), l, ((l + r) >> 1), pos, val);         else           update((T[first].ch[1]), (T[pre].ch[1]), ((l + r) >> 1) + 1, r, pos,                  val);       }     }     int query(int first, int l, int r, int mn, int mx) {       if (mn > mx || !first) return 0;       if (mn <= l && r <= mx) return T[first].pos;       if (mx <= ((l + r) >> 1))         return query((T[first].ch[0]), l, ((l + r) >> 1), mn, mx);       if (mn > ((l + r) >> 1))         return query((T[first].ch[1]), ((l + r) >> 1) + 1, r, mn, mx);       return max(           query((T[first].ch[0]), l, ((l + r) >> 1), mn, ((l + r) >> 1)),           query((T[first].ch[1]), ((l + r) >> 1) + 1, r, ((l + r) >> 1), mx));     }   } T2;   int main() {     int first, second;     read(n);     for (int i = 1; i <= n; ++i)       T2.update(root[i], root[i - 1], 0, 1e9, i, read(a[i]));     read(q);     for (int i = 1; i <= q; ++i)       read(first), Q[read(second)].push_back(make_pair(first, i));     for (int r = 1, pos, lim; r <= n; ++r) {       pos = r, lim = (0x3f3f3f3f);       while (pos = T2.query(root[pos - 1], 0, 1e9, a[r], lim))         T1.update(pos, a[pos] - a[r]),             lim = (a[pos] + a[r]) / 2 - (((a[r] + a[pos] + 1) & 1));       pos = r, lim = -(0x3f3f3f3f);       while (pos = T2.query(root[pos - 1], 0, 1e9, lim, a[r]))         T1.update(pos, a[r] - a[pos]),             lim = (a[pos] + a[r]) / 2 + (((a[r] + a[pos] + 1) & 1));       for (auto v : Q[r]) ans[v.second] = T1.query(v.first);     }     for (int i = 1; i <= q; ++i) write(ans[i]);     return flush(), 0;   }


#include <bits/stdc++.h>   using namespace std;   double dis(double ax, double ay, double bx, double by) {     return sqrt(pow(ax - bx, 2) + pow(ay - by, 2));   }   bool f(double a, double b, double c) {     if (a == sqrt(pow(b, 2) + pow(c, 2)))       return true;     else       return false;   }   int main() {     cout << fixed << setprecision(15);     double ax, ay, bx, by, cx, cy;     cin >> ax >> ay >> bx >> by >> cx >> cy;     double ab = dis(ax, ay, bx, by), bc = dis(bx, by, cx, cy),            ac = dis(ax, ay, cx, cy);     bool res = true;     if (ab == bc) {       if (ay - by == 0) {         if (ay == by && ay == cy) res = false;       } else if (ax - bx == 0) {         if (ax == bx && ax == cx) res = false;       } else {         double m = (ay - by) / (ax - bx);         if (cy == (m * cx + ay - m * ax)) res = false;       }     } else       res = false;     if (res)       cout <<  Yes  << endl;     else       cout <<  No  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int w = 26;     int count = 0;     char a[] = { a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i ,  j ,  k ,  l ,  m ,                  n ,  o ,  p ,  q ,  r ,  s ,  t ,  u ,  v ,  w ,  x ,  y ,  z };     string b;     cin >> b;     for (char c : b) {       for (int m = 0; m < w; m++) {         if (c == a[m]) {           a[m] =  1 ;           count++;         }       }     }     if (count % 2 == 0) {       cout <<  CHAT WITH HER! ;     } else {       cout <<  IGNORE HIM! ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, x;     cin >> s;     int count = 0, sz = s.size();     for (int i = 0; i < sz; ++i)       if (s[i] ==  1 ) ++count;     for (int i = 0; i < sz; ++i) {       if (s[i] ==  0 )         x +=  0 ;       else if (s[i] ==  2 ) {         while (count-- > 0) x +=  1 ;         x +=  2 ;       }     }     while (count-- > 0) x +=  1 ;     cout << x;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100009;   int first[maxn], du[maxn], pre[maxn][2];   struct edg {     int next, to;   } e[maxn << 1];   struct node {     int x, opt;   };   bool vis[maxn][2], ins[maxn], ok[maxn];   queue<node> q;   int n, m, s, e_sum;   bool flag;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   void add_edg(int x, int y) {     e_sum++;     e[e_sum].next = first[x];     first[x] = e_sum;     e[e_sum].to = y;   }   void print(int x, int opt) {     if (x == s && opt == 0) {       printf( %d  , x);       return;     }     print(pre[x][opt], opt ^ 1);     printf( %d  , x);   }   void dfs(int x) {     ok[x] = ins[x] = 1;     for (int i = first[x]; i; i = e[i].next) {       int w = e[i].to;       if (ins[w]) flag = 1;       if (!ok[w]) dfs(w);     }     ins[x] = 0;   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) {       du[i] = read();       for (int j = 1; j <= du[i]; j++) {         int x = read();         add_edg(i, x);       }     }     s = read();     q.push((node){s, 0});     vis[s][0] = 1;     while (!q.empty()) {       int x = q.front().x, opt = q.front().opt;       q.pop();       for (int i = first[x]; i; i = e[i].next) {         int w = e[i].to;         if (!vis[w][opt ^ 1]) {           vis[w][opt ^ 1] = 1;           pre[w][opt ^ 1] = x;           q.push((node){w, opt ^ 1});         }       }     }     for (int i = 1; i <= n; i++)       if (du[i] == 0 && vis[i][1]) {         puts( Win );         print(i, 1);         return 0;       }     dfs(s);     if (flag)       puts( Draw );     else       puts( Lose );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, l, r, x, mid;     cin >> n >> m;     int a[n][2];     for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];     int b[m];     for (int i = 0; i < m; i++) cin >> b[i];     int music[n];     for (int i = 0; i < n; i++) music[i] = 0;     music[0] = a[0][0] * a[0][1];     for (int i = 1; i < n; i++) music[i] = music[i - 1] + a[i][0] * a[i][1];     for (int i = 0; i < m; i++) {       x = b[i];       l = -1;       r = n - 1;       while (r - l > 1) {         mid = (l + r) / 2;         if (x <= music[mid])           r = mid;         else           l = mid;       }       cout << r + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,unroll-loops,no-stack-protector,fast-math,inline )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2 )   using namespace std;   using ll = long long;   using vvi = vector<vector<int>>;   using vi = vector<int>;   using vvll = vector<vector<long long>>;   using vll = vector<long long>;   using vd = vector<double>;   using vvd = vector<vector<double>>;   using pii = pair<int, int>;   using vpii = vector<pair<int, int>>;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   ll MOD = 1e9 + 7;   vvll multiply(vvll a, vvll b) {     int x = a.size();     int y = b.size();     int z = b[0].size();     assert(y == a[0].size());     vvll ans(x, vll(z));     for (int i = 0; i < x; i++) {       for (int j = 0; j < z; j++) {         for (int k = 0; k < y; k++) {           ans[i][j] += a[i][k] * b[k][j];           ans[i][j] %= MOD;         }       }     }     return ans;   }   vvll binexp(vvll m, ll b) {     int n = m.size();     vvll ans(n, vll(n));     for (int i = 0; i < n; i++) {       ans[i][i] = 1;     }     while (b) {       if (b & 1) {         ans = multiply(ans, m);       }       m = multiply(m, m);       b >>= 1;     }     return ans;   }   void solve() {     int n, k, m;     cin >> n >> k >> m;     int d = (k + 1) * (1 << m);     vvll mat(d + 1, vll(d + 1));     mat[d][d] = 1;     mat[0][d] = 1;     for (int j = 1; j <= k; j++) {       for (int mask = 0; mask < (1 << m); mask++) {         int row = j * (1 << m) + mask;         if (mask & 1) {           for (int b = 0; b < 2; b++) {             mat[row][(j - 1) * (1 << m) + ((b << (m - 1)) | (mask >> 1))] =                 (__builtin_popcount((b << (m - 1)) | (mask >> 1)) + 1);           }         } else {           for (int b = 0; b < 2; b++) {             mat[row][j * (1 << m) + ((b << (m - 1)) | (mask >> 1))] = 1;           }         }       }     };     vvll v(d + 1, vll(1));     v[0][0] = 1;     v[d][0] = 1;     ;     vvll e = binexp(mat, n);     ;     vvll res = multiply(e, v);     ;     ll ans = 0;     for (int mask = 0; mask < (1 << m); mask++) {       ans += res[k * (1 << m) + mask][0];     }     cout << ans % MOD << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }