#include <bits/stdc++.h>   const long long llinfinity = 9223372036854775807LL;   const long long llminusinfinity = -9223372036854775808LL;   const int intinfinity = 2147483647;   const int intminusinfinity = -2147483648;   using namespace std;   const int maxn = 1e5 + 5;   int a[maxn], n;   long long ans;   int main(int argc, char *argv[]) {     long long tmp = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     ans = 0;     for (int i = 0; i < n; ++i) {       tmp = 0;       if (i == 0) {         tmp = a[i];         tmp *= (n - a[i] + 1);       } else {         if (a[i] > a[i - 1]) {           tmp = a[i] - a[i - 1];           tmp *= n - a[i] + 1;         } else {           tmp = a[i];           tmp *= a[i - 1] - a[i];         }       }       ans += tmp;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int n, k, ps[N], mx[N], cnt[N], a[N];   long long ans;   int getNeed(int p, int m) {     int x = (((p - m) % k) + k) % k;     return cnt[((k - x) + k) % k];   }   void solve(int l, int r) {     if (r - l <= 1) return;     int mid = (l + r) / 2;     ps[mid - 1] = a[mid - 1] % k, mx[mid - 1] = a[mid - 1];     for (int i = mid - 2; i >= l; i--)       ps[i] = (ps[i + 1] + a[i]) % k, mx[i] = max(mx[i + 1], a[i]);     ps[mid] = a[mid] % k, mx[mid] = a[mid];     for (int i = mid + 1; i < r; i++)       ps[i] = (ps[i - 1] + a[i]) % k, mx[i] = max(mx[i - 1], a[i]);     for (int i = mid - 1; i >= l; i--) cnt[ps[i]]++;     int rn = l;     for (int i = r - 1; i >= mid; i--) {       if (mx[mid - 1] >= mx[i]) break;       while (mx[rn] >= mx[i]) cnt[ps[rn]]--, rn++;       ans += getNeed(ps[i], mx[i]);     }     for (int i = mid - 1; i >= l; i--) cnt[ps[i]] = 0;     rn = r - 1;     for (int i = mid; i < r; i++) cnt[ps[i]]++;     for (int i = l; i < mid; i++) {       if (mx[i] < mx[mid]) break;       while (mx[rn] > mx[i]) cnt[ps[rn]]--, rn--;       ans += getNeed(ps[i], mx[i]);     }     for (int i = mid; i < r; i++) cnt[ps[i]] = 0;     solve(l, mid), solve(mid, r);   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     solve(0, n);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const long long linf = (1ll << 62) - 1;   int n, l, t;   vector<int> a;   long double ans = 0;   inline int getCount(int ll, int rr) {     if (rr < l) {       ll = lower_bound((a).begin(), (a).end(), ll) - a.begin();       rr = upper_bound((a).begin(), (a).end(), rr) - a.begin();       return rr - ll;     }     return getCount(ll, l - 1) + getCount(0, rr - l);   }   int main() {     assert(scanf( %d%d%d , &n, &l, &t));     a.resize(n);     for (int i = 0; i < n; i++) assert(scanf( %d , &a[i]));     t *= 2;     for (int i = 0; i < n; i++) ans += (t / l) * ((n - 1) / 2.0);     t %= l;     for (int i = 0; i < n; i++) ans += (getCount(a[i], a[i] + t) - 1) / 2.0;     cout.precision(20);     cout << fixed << ans / 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ans = 2;     for (int i = 1; i <= n; i++) {       int tmp;       cin >> tmp;       if (tmp % 2 == 0) {         ans = 3 - ans;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[20][20];   int i, j, k = 0;   string s =  WBWBWBWB , s1 =  BWBWBWBW , z[20];   int main() {     for (i = 1; i <= 8; i++) {       cin >> z[i];     }     for (i = 1; i <= 8; i++) {       if (z[i] != s && z[i] != s1) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void gethas(string s, int &has0, int &hasa, int &hasA) {     int n = int(s.size());     has0 = 0;     hasa = 0;     hasA = 0;     for (int i = 0; i < n; i++) {       char c = s[i];       has0 = has0 or ( 0  <= c and c <=  9 );       hasa = hasa or ( a  <= c and c <=  z );       hasA = hasA or ( A  <= c and c <=  Z );     }   }   bool valid(string s) {     int has0, hasa, hasA;     gethas(s, has0, hasa, hasA);     return has0 and hasa and hasA;   }   bool check(string s) {     if (valid(s)) {       cout << s << endl;       return true;     }     return false;   }   int cases;   int main() {     cin >> cases;     for (int cas = 0; cas < cases; cas++) {       string s;       cin >> s;       if (check(s)) continue;       int n = int(s.size());       int has0, hasa, hasA;       gethas(s, has0, hasa, hasA);       if (has0 + hasa + hasA == 2) {         for (int i = 0; i < n; i++) {           if (check(s.substr(0, i) +  0  + s.substr(i + 1, n - i))) break;           if (check(s.substr(0, i) +  a  + s.substr(i + 1, n - i))) break;           if (check(s.substr(0, i) +  A  + s.substr(i + 1, n - i))) break;         }         continue;       }       for (int i = 0; i < n - 1; i++) {         if (check(s.substr(0, i) +  0a  + s.substr(i + 2, n - i - 1))) break;         if (check(s.substr(0, i) +  0A  + s.substr(i + 2, n - i - 1))) break;         if (check(s.substr(0, i) +  aA  + s.substr(i + 2, n - i - 1))) break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000009;   long long pow(long long a, long long b, long long m) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m, k;     cin >> n >> m >> k;     long long start = 0;     long long end = n;     long long ans = 1e12;     while (start <= end) {       long long middle = start + (end - start) / 2;       long long spaceLeft = n - middle * k;       long long questionsLeft = m - middle * k;       long long questionsCanBeFitted = spaceLeft / k * (k - 1) + spaceLeft % k;       if (questionsCanBeFitted >= questionsLeft) {         end = middle - 1;         ans = (k * (pow(2, middle + 1, MOD) - 2 + MOD) % MOD + (m - middle * k)) %               MOD;       } else         start = middle + 1;     }     cout << ans % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1007;   long long lcp[MAXN][MAXN];   string s;   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     long long l = lcp[a.second][b.second];     long long al = a.second - a.first + 1;     long long bl = b.second - b.first + 1;     l = min(l, al);     l = min(l, bl);     if (al == l && bl == l)       return 0;     else if (al == l)       return 1;     else if (bl == l)       return 0;     else       return s[a.second - l] < s[b.second - l];   }   vector<pair<long long, long long>> subs;   long long n, m, k;   long long dp[2][MAXN];   long long add(long long a, long long b) {     return min(a + b, (long long)2e18 + 100);   }   long long f(long long num) {     long long l = subs[num].first;     long long r = subs[num].second;     long long len = r - l + 1;     auto lim = subs[num];     fill(dp[0], dp[0] + n + 1, 0);     dp[0][0] = 1;     for (long long c = 1; c <= m; ++c) {       long long* pdp = dp[c & 1 ^ 1];       long long* cdp = dp[c & 1];       fill(cdp, cdp + n + 1, 0);       for (long long i = 1; i <= n; ++i) pdp[i] = add(pdp[i], pdp[i - 1]);       for (long long i = 1; i <= n; ++i) {         long long first = min(lcp[i][r], len);         if (first == i)           cdp[i] = (c == 1 && first == len);         else if (first == len)           cdp[i] = pdp[i - max(1ll, first)];         else if (s[r - first] < s[i - first])           cdp[i] = pdp[i - first - 1];       }     }     return dp[m & 1][n];   }   void solve() {     cin >> n >> m >> k;     cin >> s;     s +=  # ;     reverse(s.begin(), s.end());     for (long long i = 0; i <= n; ++i)       for (long long j = 0; j <= n; ++j)         if (i && j) lcp[i][j] = (s[i] == s[j] ? lcp[i - 1][j - 1] + 1 : 0);     for (long long i = 1; i <= n; ++i)       for (long long j = i; j <= n; ++j) subs.push_back({i, j});     sort(subs.begin(), subs.end(), cmp);     reverse(subs.begin(), subs.end());     long long l = -1, r = subs.size();     while (r - l > 1) {       long long m = (l + r) / 2;       if (f(m) >= k)         r = m;       else         l = m;     }     auto p = subs[r];     for (long long i = p.second; i >= p.first; --i) cout << s[i];     cout <<   n ;     return;   }   signed main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = std::numeric_limits<int>::max() / 3;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   int dp[6000][6000];   long long sum[1000000];   long long min(long long a, long long b) { return a < b ? a : b; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     vector<long long> a;     for (int i = 0, t; i < n; ++i) {       cin >> t;       a.push_back(t);     }     sort(a.begin(), a.end());     int sz = n / k;     int A = (n % k);     int B = k - A;     sum[0] = 0;     for (int i = 1; i < n; ++i) sum[i] = sum[i - 1] + a[i] - a[i - 1];     for (int i = 0; i <= A; ++i)       for (int j = 0; j <= B; ++j) dp[i][j] = 2e9 + 1;     dp[0][0] = 0;     for (int i = 0; i <= A; ++i) {       for (int j = 0; j <= B; ++j) {         int x = (i + j) * sz + i;         if (i < A) {           long long t = dp[i][j] + sum[x + sz] - sum[x];           dp[i + 1][j] = min(dp[i + 1][j] * 1LL, t);         }         if (j < B) {           long long t = dp[i][j] + sum[x + sz - 1] - sum[x];           dp[i][j + 1] = min(dp[i][j + 1] * 1LL, t);         }       }     }     cout << dp[A][B] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   int a[maxn], n, k;   long long sum;   long long judge1(int m) {     long long ans = 0;     for (int i = 1; a[i] < m && i <= n; i++) {       ans += m - a[i];     }     return ans;   }   long long judge2(int m) {     long long ans = 0;     for (int i = n; a[i] > m && i >= 1; i--) {       ans += a[i] - m;     }     return ans;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     sort(a + 1, a + n + 1);     int l = a[1], r = a[n], poorest = a[1];     while (l <= r) {       int mid = (l + r) >> 1;       long long p = judge1(mid);       if (p <= k) {         poorest = mid;         l = mid + 1;       } else         r = mid - 1;     }     l = a[1];     r = a[n];     int richest = a[n];     while (l <= r) {       int mid = (l + r) >> 1;       long long p = judge2(mid);       if (p <= k) {         richest = mid;         r = mid - 1;       } else         l = mid + 1;     }     if (poorest < richest)       printf( %d n , richest - poorest);     else {       if (sum % n == 0)         printf( 0 n );       else         printf( 1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string& second) { return     + second +    ; }   string to_string(char c) {     string second;     second += c;     return second;   }   string to_string(const char* second) { return to_string((string)second); }   string to_string(bool b) { return (b ?  1  :  0 ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (long long i = 0; i < static_cast<long long>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr <<   n ; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   void Clearing_out() { return; }   template <typename Head, typename... Tail>   void Clearing_out(Head& H, Tail&... T) {     H.clear();     Clearing_out(T...);   }   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);     }   };   void time() {     cerr <<  Time elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s. n ;   }   void hi() {     static long long i = 0;     cerr <<  Check Point :   << ++i <<   n ;     return;   }   long long stoi1(string str) {     bool negative;     if (str[0] ==  - ) {       negative = true;       str = str.substr(1);     } else {       negative = false;     }     long long n = str.length();     long long number = 0;     long long pos = 1;     for (long long i = n - 1; i >= 0; i--) {       number = number + (str[i] -  0 ) * pos;       pos = pos * 10;     }     if (negative) number = -number;     return number;   }   long long power(long long a, long long n) {     long long res = 1;     while (n > 0) {       if (n % 2 != 0) {         res = res * a;         n--;       } else if (n % 2 == 0) {         a = a * a;         n = n / 2;       }     }     return res;   }   pair<long long, long long> min(vector<long long> v, bool first = true) {     bool last = !first;     long long mini = 1000000000000000007;     long long mini_index = -1;     long long n = (long long)v.size();     for (long long i = 0; i < n; i++) {       if ((mini > v[i] && first) || (mini >= v[i] && last)) {         mini = v[i];         mini_index = i;       }     }     return {mini_index, mini};   }   pair<long long, long long> max(vector<long long> v, bool first = true) {     bool last = !first;     long long maxi = -1000000000000000007;     long long maxi_index = -1;     long long n = (long long)v.size();     for (long long i = 0; i < n; i++) {       if ((maxi < v[i] && first) || (maxi <= v[i] && last)) {         maxi = v[i];         maxi_index = i;       }     }     return {maxi_index, maxi};   }   long long sum(vector<long long> v, long long start = 0, long long last = -1) {     if (last == -1) last = (long long)v.size() - 1;     long long ans = 0;     for (long long i = start; i <= last; i++) {       ans = ans + v[i];     }     return ans;   }   long long len(vector<long long> v) { return (long long)v.size(); }   long long rand(long long a, long long b) { return a + rand() % (b - a + 1); }   vector<long long> generate_random_vector() {     vector<long long> v;     long long n = rand(10, 20);     set<long long> used;     for (long long i = 0; i < n; ++i) {       long long x;       do {         x = rand(10, 1000);       } while (used.count(x));       v.push_back(x);       used.insert(x);     }     return v;   }   const long long max_size = 1e6 + 10000;   const double eps = 1e-18;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) {       long long n;       cin >> n;       vector<long long> v(n);       for (long long i = 0; i < n; i++) {         cin >> v[i];       }       vector<vector<long long>> v1(n);       long long new_index = 0;       v1[new_index].push_back(v[0]);       new_index++;       vector<long long> v_back;       v_back.push_back(-v[0]);       for (long long i = 1; i < n; i++) {         long long index =             lower_bound(v_back.begin(), v_back.end(), -v[i]) - v_back.begin();         if (index == (long long)v_back.size()) {           v1[new_index].push_back(v[i]);           v_back.push_back(-v[i]);           new_index++;           continue;         } else {           v1[index].push_back(v[i]);           v_back[index] = -v[i];         }       }       for (auto x : v1) {         if (x.size() == 0) continue;         for (auto y : x) {           cout << y <<    ;         }         cout <<   n ;       }     }     time();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int s[200005];   struct pp {     int lev;     int loc;   } s1[200005], s2[200005];   bool cmp(pp &a, pp &b) { return a.lev < b.lev; }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int s1h = 0, s2h = 0;       string test;       int n;       cin >> n;       for (int j = 0; j < n; j++) {         cin >> s[j];       }       cin >> test;       for (int p = 0; p < test.length(); p++) {         if (test[p] ==  0 )           s1[s1h].lev = s[p], s1[s1h++].loc = p;         else           s2[s2h].lev = s[p], s2[s2h++].loc = p;       }       sort(s1, s1 + s1h, cmp);       sort(s2, s2 + s2h, cmp);       for (int j = 0; j < s1h; j++) {         s[s1[j].loc] = j + 1;       }       for (int j = 0; j < s2h; j++) {         s[s2[j].loc] = j + s1h + 1;       }       for (int j = 0; j < n; j++) cout << s[j] <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int T = clock();     long long int a, ta, b, tb;     cin >> a >> ta >> b >> tb;     string s;     cin >> s;     long long int i = 5 * 60, lim = 23 * 60 + 59;     long long int st = stoi(s.substr(0, 2)) * 60 + stoi(s.substr(3));     long long int ed = st + ta;     long long int ans = 0;     while (i < ed && i <= lim) {       if (i + tb > st) ans++;       i += b;     }     cout << ans;     cerr <<   n nTIME:   << (long double)(clock() - T) / CLOCKS_PER_SEC          <<   sec n ;     T = clock();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200514;   vector<int> a3[N], a4[N], mn, mx;   set<int> s;   int p3[N], p4[N];   int n, m, M, a[N], ct[N], l1 = 1, l2 = 1;   int j, p1, p2, k1, k2;   int main() {     scanf( %d%d , &n, &m);     p3[n + 1] = p4[n + 1] = n + 1;     for (int i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (int i = (n); i >= (1); i--) {       j = i - 1;       p3[i] = p4[i] = n + 1;       while (j >= 1 && a[i] == a[j]) j--;       while (mn.size() && a[i] < a[mn.back()]) {         if (!(--ct[mn.back()])) s.insert(mn.back());         l1 = 0;         mn.pop_back();       }       while (mx.size() && a[i] > a[mx.back()]) {         if (!(--ct[mx.back()])) s.insert(mx.back());         l2 = 0;         mx.pop_back();       }       p1 = lower_bound(mn.begin(), mn.end(), i,                        [&](int x, int y) { return a[x] < a[y]; }) -            mn.begin() - 1;       p2 = lower_bound(mx.begin(), mx.end(), i,                        [&](int x, int y) { return a[x] > a[y]; }) -            mx.begin() - 1;       p3[i] = i + 1 + max(l1, l2);       a3[i] = {i, p3[i] - 1, p3[i]};       if (~p1 && ~p2) {         auto it = s.lower_bound(max(mn[p1], mx[p2]));         if (it != s.end()) {           p4[i] = *it;           k1 = upper_bound(mn.begin(), mn.end(), p4[i], greater<int>()) -                mn.begin();           k2 = upper_bound(mx.begin(), mx.end(), p4[i], greater<int>()) -                mx.begin();           a4[i] = {i, min(mn[k1], mx[k2]), max(mn[k1], mx[k2]), p4[i]};         }       }       if (p3[i] > p3[i + 1]) a3[i] = a3[i + 1], p3[i] = p3[i + 1];       if (p4[i] > p4[i + 1]) a4[i] = a4[i + 1], p4[i] = p4[i + 1];       for (int k = (j + 1); k <= (i); k++) {         l1++, l2++;         mn.push_back(k), mx.push_back(k);         ct[k] = 2;         p3[k] = p3[i], p4[k] = p4[i], a3[k] = a3[i], a4[k] = a4[i];       }       i = j + 1;     }     int x, y;     for (int i = (1); i <= (m); i++) {       scanf( %d%d , &x, &y);       if (p4[x] <= y) {         puts( 4 );         for (int l : a4[x]) printf( %d  , l);         puts(  );       } else if (p3[x] <= y) {         puts( 3 );         for (int l : a3[x]) printf( %d  , l);         puts(  );       } else         puts( 0 );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<vector<int> > g;     vector<int> buf;     g.clear();     buf.clear();     for (int i = 0; i < k; i++) g.push_back(buf);     vector<int> num;     num.clear();     int j;     for (j = 0; j < n * k; j++) num.push_back(0);     for (int i = 0; i < k; i++) {       int c;       cin >> c;       g[i].push_back(c);       num[c - 1] = 1;     }     int l = 0;     for (j = 0; j < n * k; j++)       if (num[j] == 0) {         g[l].push_back(j + 1);         l++;         if (l == k) l = 0;       }     for (int i = 0; i < k; i++) {       for (int j = 0; j < n; j++) cout << g[i][j] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (1ll << 45);   long long bit[1000006];   void update(long long from, long long val) {     for (long long i = from; i < 1000006; i += i & -i) bit[i] += val;   }   long long query(long long from) {     if (from == 0) return 0;     long long cnt = 0;     for (long long i = from; i > 0; i -= i & -i) cnt += bit[i];     return cnt;   }   long long query(long long l, long long r) { return query(r) - query(l - 1); }   struct Node {     Node *lc, *rc;     long long mx, tag;     Node() : lc(NULL), rc(NULL), mx(-INF), tag(0) {}     void pull() { mx = max(lc->mx, rc->mx); }   };   const long long N = 1000002;   Node* Build(long long L, long long R) {     Node* node = new Node();     if (L == R) {       node->mx = -N + L;       return node;     }     long long mid = (L + R) >> 1;     node->lc = Build(L, mid);     node->rc = Build(mid + 1, R);     node->pull();     return node;   }   void push(Node* node, long long L, long long R) {     if (L == R) node->tag = 0;     if (node->tag == 0) return;     node->lc->mx += node->tag;     node->rc->mx += node->tag;     node->lc->tag += node->tag;     node->rc->tag += node->tag;     node->tag = 0;     return;   }   void modify(Node* node, long long L, long long R, long long l, long long r,               long long val) {     if (l > R || L > r)       return;     else if (l <= L && R <= r) {       node->mx += val;       node->tag += val;       return;     }     push(node, L, R);     long long mid = (L + R) >> 1;     modify(node->lc, L, mid, l, r, val);     modify(node->rc, mid + 1, R, l, r, val);     node->pull();     return;   }   long long query(Node* node, long long L, long long R, long long l,                   long long r) {     if (l > R || L > r)       return -INF;     else if (l <= L && R <= r)       return node->mx;     push(node, L, R);     long long mid = (L + R) >> 1;     return max(query(node->lc, L, mid, l, r), query(node->rc, mid + 1, R, l, r));   }   long long n, x[N][2];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     Node* root = Build(1, N);     string in;     long long v1, v2;     for (long long i = 1; i < n + 1; ++i) {       cin >> in;       if (in ==  ? ) {         cin >> v1;         cout << query(root, 1, N, 1, v1) + (N - v1) - query(v1 + 1, 1000006 - 1)              <<   n ;       } else if (in ==  + ) {         cin >> v1 >> v2;         x[i][0] = v1;         x[i][1] = v2;         modify(root, 1, N, 1, x[i][0], x[i][1]);         update(v1, v2);       } else if (in ==  - ) {         cin >> v1;         modify(root, 1, N, 1, x[v1][0], -x[v1][1]);         update(x[v1][0], -x[v1][1]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1 << 28;   const long long LINF = 1ll << 61;   inline long long getnum() {     register long long r = 0;     register bool ng = 0;     register char c;     c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) ng = 1, c = getchar();     while (c !=     && c !=   n ) r = r * 10 + c -  0 , c = getchar();     if (ng) r = -r;     return r;   }   template <class T>   inline void putnum(T x) {     if (x < 0) putchar( - ), x = -x;     register short a[20] = {}, sz = 0;     while (x > 0) a[sz++] = x % 10, x /= 10;     if (sz == 0) putchar( 0 );     for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]);   }   inline void putsp() { putchar(   ); }   inline void putendl() { putchar(  n ); }   int n, a[200111], p[200111], cnt[200111], mx = 1, ans[200111];   bool f[200111];   map<int, vector<int> > mp;   int gf(int x) { return x == p[x] ? x : p[x] = gf(p[x]); }   void un(int x, int y) {     x = gf(x), y = gf(y);     if (x == y) return;     p[y] = x;     cnt[x] += cnt[y];     mx = max(mx, cnt[x]);   }   int main() {     n = getnum();     for (int i = 1; i <= n; i++) {       p[i] = i;       a[i] = getnum();       mp[a[i]].push_back(i);       cnt[i] = 1;     }     for (map<int, vector<int> >::iterator it = --mp.end();; it--) {       vector<int> &v = it->second;       for (int i = 0; i < v.size(); i++) {         f[v[i]] = 1;         if (f[v[i] - 1]) un(v[i] - 1, v[i]);         if (f[v[i] + 1]) un(v[i] + 1, v[i]);         ans[mx] = max(ans[mx], it->first);       }       if (it == mp.begin()) break;     }     int res = ans[n];     for (int i = n; i >= 1; i--) {       if (ans[i] != 0) res = ans[i];       ans[i] = res;     }     for (int i = 1; i <= n; i++) putnum(ans[i]), putsp();     return 0;   }


#include <bits/stdc++.h>   int vi[60], ho[60];   int main() {     int n, k, i;     int x, y;     scanf( %d , &n);     for (k = 1; k <= n * n; k++) {       scanf( %d%d , &x, &y);       if (vi[x] || ho[y]) continue;       vi[x] = 1;       ho[y] = 1;       printf( %d  , k);     }   }


#include<bits/stdc++.h>      #define y1 dmytxdy   #define pb push_back   #define fi first   #define se second   #define mp make_pair      using namespace std;      typedef long long ll;   typedef unsigned long long ull;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   typedef long double ld;      template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}   template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}      int readint(){    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;   }      struct node{    int x,y,id;    node(int x=0,int y=0,int id=0):x(x),y(y),id(id){}   }p[2005];      int n,m;   int x[2005],y[2005],a[2005];   bool vis[2005];      ll operator*(pii x,pii y){return 1ll*x.fi*y.se-1ll*x.se*y.fi;}      int main(){    n=readint();    for(int i=1;i<=n;i++) x[i]=readint(),y[i]=readint(),a[i]=readint();    int pl=0,mina=1<<30;    for(int i=1;i<=n;i++) if(a[i]!=i&&chkmin(mina,x[i])) pl=i;    if(!pl){     printf( 0 n );     return 0;    }    for(int i=1;i<=n;i++) if(i!=pl&&a[i]!=i) p[++m]=node(x[i],y[i],i);    for(int i=1;i<=m;i++) for(int j=i+1;j<=m;j++) if(mp(p[i].x-x[pl],p[i].y-y[pl])*mp(p[j].x-x[pl],p[j].y-y[pl])<0) swap(p[i],p[j]);    vector<pii> ans(0);    for(int i=1;i<m;i++){     for(int j=p[i].id,k=1;k<=n;j=a[j],k++) vis[j]=1;     bool fl=vis[p[i+1].id];     for(int j=p[i].id,k=1;k<=n;j=a[j],k++) vis[j]=0;     if(!fl) ans.pb(mp(p[i].id,p[i+1].id)),swap(a[p[i].id],a[p[i+1].id]);    }    for(int j=a[pl];j!=pl;j=a[j]) ans.pb(mp(pl,j));    printf( %d n ,ans.size());    for(auto r:ans) printf( %d %d n ,r.fi,r.se);    return 0;   }


#include<bits/stdc++.h>   using namespace std;   int main()   {       int tst,i,m,n;       cin>>tst;       while(tst--)       {           int ar[4];           cin>>ar[0]>>ar[1]>>ar[2]>>ar[3];           n=max(ar[2],ar[3]);m=max(ar[0],ar[1]);           sort(ar,ar+4);           ((n==ar[3]||n==ar[2])&&(m==ar[3] || m==ar[2]))?cout<< YES n :cout<< NO n ;       }   }


#include <bits/stdc++.h>   using namespace std;   constexpr int maxn = 1010;   int n;   bool e[maxn][maxn];   pair<int, int> flip(int a, int b, bool inv) {     int x = -1, y;     for (int i = 0; i < n; i++)       if (e[a][i] && e[b][i])         if (x == -1)           x = i;         else {           y = i;           break;         }     e[a][b] = e[b][a] = false;     e[x][y] = e[y][x] = true;     return inv ? make_pair(x, y) : make_pair(a, b);   }   vector<pair<int, int> > solve(bool inv) {     memset(e, 0, sizeof(e));     for (int i = 0; i < n; i++) e[i][(i + 1) % n] = e[(i + 1) % n][i] = true;     for (int i = 0, a, b; i < n - 3; i++) {       cin >> a >> b;       a--;       b--;       e[a][b] = e[b][a] = true;     }     vector<pair<int, int> > res;     for (int i = 1; i < n;) {       if (e[0][i]) {         i++;         continue;       }       int j;       for (j = i + 1; e[0][j] == 0; j++)         ;       res.push_back(flip(i - 1, j, inv));     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     vector<pair<int, int> > a = solve(false), b = solve(true);     cout << a.size() + b.size() << endl;     for (int i = 0; i < (int)a.size(); i++)       cout << a[i].first + 1 <<     << a[i].second + 1 << endl;     for (int i = b.size() - 1; i >= 0; i--)       cout << b[i].first + 1 <<     << b[i].second + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   std::ostream& operator<<(std::ostream& os, const std::vector<T>& input) {     for (auto const& i : input) {       os << i <<    ;     }     return os;   }   template <class T1, class T2>   std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& input) {     os <<  (  << input.first <<  ,   << input.second <<  ) ;     return os;   }   const int maxn = 1000;   int d[maxn], f[maxn];   vector<int> E[maxn], node[maxn];   void dfs(int u, int fa) {     node[d[u]].push_back(u + 1);     for (int v : E[u])       if (v != fa) {         d[v] = d[u] + 1;         f[v] = u;         dfs(v, u);       }   }   void solve() {     int n, x, y;     cin >> n;     for (int i = 0; i < int(n); ++i) {       node[i].clear();       E[i].clear();     }     for (int i = 0; i < int(n - 1); ++i) {       cin >> x >> y;       x--, y--;       E[x].push_back(y);       E[y].push_back(x);     }     cout <<  ?   << n;     for (int i = 0; i < int(n); ++i) cout <<     << i + 1;     cout << endl;     int root, dist;     cin >> root >> dist;     root--;     d[root] = 0;     dfs(root, -1);     int l = 0, r = 0;     for (int i = 0; i < int(n); ++i) r = max(r, d[i]);     r++;     int node_u, node_v;     while (r - l > 1) {       int m = (l + r) >> 1;       cout <<  ?   << (node[m]).size() <<     << node[m] << endl;       cin >> x >> y;       x--;       if (y == dist) {         node_u = x + 1;         l = m;       } else {         r = m;       }     }     int lv = dist - l;     if (lv == 0) {       node_v = root + 1;     } else {       int w = node_u - 1;       for (int i = 0; i < int(l - lv); ++i) {         w = f[w];       }       vector<int> tmp(0);       for (int x : node[lv])         if (x != w + 1) tmp.push_back(x);       cout <<  ?   << (tmp).size() <<     << tmp << endl;       cin >> node_v >> y;       assert(y == dist);     }     cout <<  !   << node_u <<     << node_v << endl;     string ret;     cin >> ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int cas = 1;     cin >> cas;     for (int ca = 0; ca < int(cas); ++ca) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;   };   int dist(const point &a, const point &b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   int main(int argc, char *argv[]) {     point p[8];     int a[8] = {0, 1, 2, 3, 4, 5, 6, 7};     for (int i = 0; i < 8; i++) scanf( %d %d , &p[i].x, &p[i].y);     bool found = false;     do {       int d = dist(p[a[0]], p[a[1]]);       if (d != dist(p[a[0]], p[a[2]]) || d != dist(p[a[1]], p[a[3]]) ||           d != dist(p[a[2]], p[a[3]]))         continue;       if (2 * d != dist(p[a[0]], p[a[3]]) || 2 * d != dist(p[a[1]], p[a[2]]))         continue;       int d1 = dist(p[a[4]], p[a[5]]);       int d2 = dist(p[a[4]], p[a[6]]);       if (d1 != dist(p[a[6]], p[a[7]]) || d2 != dist(p[a[5]], p[a[7]])) continue;       if (d1 + d2 != dist(p[a[5]], p[a[6]]) || d1 + d2 != dist(p[a[4]], p[a[7]]))         continue;       found = true;       break;     } while (next_permutation(a, a + 8));     if (found) {       printf( YES n );       for (int i = 0; i < 4; i++) printf( %s%d , i > 0 ?     :   , a[i] + 1);       printf(  n );       for (int i = 4; i < 8; i++) printf( %s%d , i > 4 ?     :   , a[i] + 1);       printf(  n );     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 59;   int t[N];   inline int read() {     int s = 1, a = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) s = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       a = a * 10 + ch -  0 ;       ch = getchar();     }     return s * a;   }   int main() {     int n = read(), k = read(), m = read(), s = 0;     for (int i = 1; i <= k; i++) t[i] = read(), s += t[i];     sort(t + 1, t + k + 1);     long long res = 0;     for (int i = 0; i <= n; i++) {       long long tim = i * s, cur = i * (k + 1);       if (tim > m) break;       for (int j = 1; j <= k; j++) {         if (tim + (n - i) * t[j] <= m)           tim += (n - i) * t[j], cur += (n - i);         else {           while (tim + t[j] <= m) tim += t[j], cur++;           break;         }       }       res = max(res, cur);     }     return 0 * printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const int M = 23;   const int inf = 1e9 + 7;   const long long base = 1e18;   const double pi = acos(-1);   const double ep = 1e-9;   map<int, int> st;   int pre[1 << M];   int cur[1 << M];   int n;   int a[N];   int main() {     cin >> n;     for (int i = 1; i < n + 1; i++) {       cin >> a[i];       st[a[i]] = i - 1;     }     for (int mask = 0; mask < 1 << M; mask++) cur[mask] = inf;     cur[1] = 1;     for (int i = 2; i < n + 1; i++) {       for (int mask = 0; mask < 1 << (i - 1); mask++) {         pre[mask] = cur[mask];         cur[mask] = inf;       }       for (int mask = 0; mask < 1 << (i - 1); mask++) {         if (pre[mask] >= inf) continue;         bool check = false;         for (int j = 0; j + 1 < i; j++) {           if ((mask & (1 << j)) && st.count(a[i] - a[j + 1]) &&               (mask & (1 << st[a[i] - a[j + 1]]))) {             check = true;             break;           }         }         if (!check) continue;         for (int j = 0; j + 1 < i; j++)           if (mask & (1 << (j))) {             int nxt = mask ^ (1 << j) ^ (1 << (i - 1));             cur[nxt] = min(cur[nxt], pre[mask]);           }         int nxt = mask ^ (1 << (i - 1));         cur[nxt] =             min(cur[nxt], pre[mask] + (pre[mask] == __builtin_popcount(mask)));       }     }     int ans = inf;     for (int mask = 0; mask < 1 << n; mask++) ans = min(ans, cur[mask]);     if (ans == inf) ans = -1;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, r;   vector<pair<int, int> > pos, L, R;   vector<int> ans;   map<pair<int, int>, int> vis;   bool cmp(pair<int, int> a, pair<int, int> b) {     return a.first + a.second < b.first + b.second;   }   int main() {     cin >> n >> r;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       vis[{x, y}]++;       if (y >= 0)         pos.push_back({x, y});       else         R.push_back({y, x}), L.push_back({x, y});     }     sort(pos.begin(), pos.end());     sort(L.rbegin(), L.rend(), cmp);     vector<pair<int, int> > aux;     for (pair<int, int> x : pos) {       while (aux.size() && r >= aux.back().first) {         r += aux.back().second;         aux.pop_back();       }       if (r < x.first) {         aux.push_back(x);       } else {         r += x.second;       }     }     if (aux.size()) {       cout <<  NO  << endl;       return 0;     }     for (pair<int, int> x : L) {       if (r < x.first) {         cout <<  NO  << endl;         return 0;       }       r += x.second;     }     if (r < 0)       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     long long int N, M;     cin >> N >> M;     long long int max_n1;     for (max_n1 = 1; (max_n1 * (max_n1 - 1)) / 2 + 1 <= N; max_n1 += 2)       ;     max_n1 -= 2;     long long int max_n2;     for (max_n2 = 0; (max_n2 * (max_n2 - 1)) / 2 + max_n2 / 2 <= N; max_n2 += 2)       ;     max_n2 -= 2;     long long int max_n = max(max_n1, max_n2);     vector<long long int> qs(M, 0);     vector<long long int> ws(M, 0);     for (int m = 0; m < M; ++m) cin >> qs[m] >> ws[m];     sort(ws.begin(), ws.end(), greater<long long int>());     max_n = min(max_n, (long long int)ws.size());     long long int res = 0;     for (int i = 0; i < max_n; ++i) res += ws[i];     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 111111;   int N;   char s[MAX];   int f[MAX];   int sum[MAX];   bool match(int i, int j) {     if (i < 1 || j < 1) return 0;     if (s[i - 1] ==  ) )       return s[j - 1] ==  ( ;     else       return s[j - 1] ==  [ ;   }   int get(int i) { return f[i - 1] < N ? f[i - 1] : i; }   int main() {     int i, j, k;     while (cin >> s) {       N = strlen(s);       sum[0] = 0;       for (i = 1; i <= N; ++i) sum[i] = sum[i - 1] + (s[i - 1] ==  ] );       memset(f, 127, sizeof f);       for (i = 2; i <= N; ++i) {         if (s[i - 1] ==  (  || s[i - 1] ==  [ ) continue;         if (match(i, i - 1)) f[i] = get(i - 1);         if (f[i - 1] < N && match(i, f[i - 1] - 1))           f[i] = min(f[i], get(f[i - 1] - 1));       }       int ans = 0, ansi;       for (i = 1; i <= N; ++i)         if (f[i] < N && sum[i] - sum[f[i] - 1] > ans) {           ans = sum[i] - sum[f[i] - 1];           ansi = i;         }       printf( %d n , ans, ansi);       if (ans > 0) {         for (i = f[ansi] - 1; i < ansi; ++i) putchar(s[i]);       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int num;     double w;   } point[1005];   bool cmp(node a, node b) {     if (fabs(a.w - b.w) < 0.0001) return a.num < b.num;     return a.w > b.w;   }   int main() {     int i, n, t1, t2, k, a, b;     scanf( %d%d%d%d , &n, &t1, &t2, &k);     for (i = 1; i <= n; i++) {       scanf( %d%d , &a, &b);       point[i].num = i;       point[i].w = t1 * a * (1 - k * 0.01) + t2 * b;       if (t1 * b * (1 - k * 0.01) + t2 * a > point[i].w)         point[i].w = t1 * b * (1 - k * 0.01) + t2 * a;     }     sort(point + 1, point + 1 + n, cmp);     for (i = 1; i <= n; i++) printf( %d %.2lf n , point[i].num, point[i].w);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int> > v;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       v.push_back(make_pair(a, b));     }     int k;     cin >> k;     int i;     for (i = 0; i < n; i++) {       if (k >= v[i].first and k <= v[i].second) break;     }     cout << n - i << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[n + 2][m + 2];     int counter = 1;     for (int i = 1; i <= n; i += 2) {       for (int j = 1; j <= m; j++) {         if (n % 2 && i == n && j % 2 == 1) continue;         a[i + (j % 2 == 1)][j] = counter;         counter++;       }     }     for (int i = 1; i <= n; i += 2) {       for (int j = 1; j <= m; j++) {         if (n % 2 && i == n && j % 2 == 0) continue;         a[i + (j % 2 == 0)][j] = counter;         counter++;       }     }     bool res = true;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if ((i < n && abs(a[i][j] - a[i + 1][j]) <= 1) ||             (j < m && abs(a[i][j] - a[i][j + 1]) <= 1))           res = false;       }     }     if (res) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           cout << a[i][j] <<    ;         }         cout <<   n ;       }     } else {       cout << -1;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int minutes[n];     int result = -1;     int lastN = 0;     for (int i = 0; i < n; i++) {       cin >> minutes[i];       if (i == 0 && minutes[0] > 15) {         result = 15;       } else if (result < 0 && minutes[i] - minutes[i - 1] > 15) {         result = minutes[i - 1] + 15;       }     }     if (result < 0) {       result = minutes[n - 1] + 15;     }     if (result > 90) {       result = 90;     }     cout << result;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     if (k % 2 == 1) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < k; i++) {       if (i > 0) cout << endl;       for (int j = 0; j < k; j++) {         for (int l = 0; l < k; l++) {           int layer = min(j, min(l, min(k - j - 1, k - l - 1)));           if (layer % 2 == i % 2)             cout <<  w ;           else             cout <<  b ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>      using namespace std;         void dfs3(int v, vector<vector<int>> &graf, vector<int> &ways) {       ways[v] = -1;       for (auto el : graf[v]) {           if (ways[el] != -1) {               dfs3(el, graf, ways);           }       }   }      void dfs2(int v, vector<vector<int>> &graf,  vector<int> &ways) {       ways[v] = 2;       for (auto el : graf[v]) {           if (ways[el] == 1) {               dfs2(el, graf, ways);           }       }   }      void dfs(int v, vector<int> &vis, vector<int> &cycle, vector<vector<int>> &graf,  vector<int> &ways, vector<int> &progr) {       if (progr[v] == 1) {           cycle.push_back(v);           ways[v] = -1;       } else if (progr[v] == 2) {           vis.push_back(v);           ways[v] = 2;       } else {           progr[v] = 1;           for (auto el : graf[v]) {               dfs(el, vis, cycle, graf, ways, progr);           }           progr[v] = 2;           ways[v] = 1;       }   }      int main()   {       ios::sync_with_stdio(false);       int t;       cin >> t;       while (t--) {           int n, m;           cin >> n >> m;           if (m == 0) {               cout << 1 <<    ;               for (int i = 1; i != n; i++) {                   cout << 0 <<    ;               }           } else {               vector<vector<int>> graf(n);               vector<int> ways(n, 0);               vector<int> progr(n, 0);               // 1 - in progress, 0 - new, 2 - visited               vector<int> cycle;               vector<int> vis;               for (int i = 0; i != m; i++) {                   int s, f;                   cin >> s >> f;                   graf[s - 1].push_back(f - 1);               }               dfs(0, vis, cycle, graf, ways, progr);               for (auto el : vis) {                   dfs2(el, graf, ways);               }               for (auto el : cycle) {                   dfs3(el, graf, ways);               }               for (auto el : ways) {                   cout << el <<    ;               }           }           cout <<   n ;       }       return 0;   }


#include <bits/stdc++.h>   int main() {     long long int l1, r1, l2, r2, k, l, r, t;     scanf( %lld%lld%lld%lld%lld , &l1, &r1, &l2, &r2, &k);     if (l1 > l2)       l = l1;     else       l = l2;     if (r1 > r2)       r = r2;     else       r = r1;     if ((k >= l) && (k <= r))       t = r - l;     else       t = r - l + 1;     if (t < 0)       t = 0;     else       t = t;     printf( %lld , t);     return 0;   }


#include <bits/stdc++.h>   const int md = 1e9 + 7;   int n, k, m, M, c;   struct mat {     int A[256][256];     inline mat() { memset(A, 0, sizeof A); }     inline int* operator[](const int& x) { return A[x]; }     inline mat operator*(const mat& b) const {       mat c;       for (int i = 0; i <= M; ++i)         for (int k = 0; k <= M; ++k)           for (int j = 0; j <= M; ++j)             c[i][j] = (c[i][j] + (long long)A[i][k] * b.A[k][j]) % md;       return c;     }   } A, B;   inline void pow(mat a, int b) {     mat& ret = B;     ret[0][0] = 1;     for (; b; b >>= 1, a = a * a)       if (b & 1) ret = ret * a;   }   int main() {     scanf( %d%d%d , &n, &k, &m), M = (k + 1) << m, c = (1 << m) - 1;     for (int i = 0; i <= k; ++i) {       for (int j = 0; j <= c; ++j) A[i << m | j][i << m | ((j << 1) & c)] = 1;       if (i != k)         for (int j = 0; j <= c; ++j)           A[i << m | j][(i + 1) << m | ((j << 1 | 1) & c)] =               1 + __builtin_popcount(j);     }     pow(A, n);     int ans = 0;     for (int i = 0; i <= c; ++i) ans = (ans + B[0][k << m | i]) % md;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using std::cerr;   using std::endl;   const int N = 2e5 + 233;   int n, m;   std::map<std::pair<int, int>, int> map;   std::vector<std::pair<int, int>> seg[N * 4];   void insert(int p, int l, int r, std::pair<int, int> e, int L, int R) {     if (l <= L && r >= R) return seg[p].push_back(e), void();     if (l <= ((L + R) >> 1)) insert((p << 1), l, r, e, L, ((L + R) >> 1));     if (r > ((L + R) >> 1))       insert(((p << 1) | 1), l, r, e, ((L + R) >> 1) + 1, R);   }   int fa[N], size[N], dis[N];   int find(int x) { return x == fa[x] ? x : find(fa[x]); }   inline int get_dis(int x) {     int ret = 0;     while (x != fa[x]) {       ret ^= dis[x];       x = fa[x];     }     return ret;   }   struct Node {     int x, y, s;   } stk[N];   int top;   void divide(int p, int L, int R, int ok) {     int top_ver = top;     for (auto e : seg[p]) {       int x = e.first, y = e.second;       int u = find(x), v = find(y);       int dis_x = get_dis(x), dis_y = get_dis(y);       if (u != v) {         if (size[u] < size[v]) std::swap(u, v);         stk[++top] = {u, v, size[v]};         fa[u] = v, size[v] += size[u];         dis[u] = dis_x ^ dis_y ^ 1;       } else {         if ((dis_x ^ dis_y) == 0) {           ok = 0;           break;         }       }     }     if (!ok) {       for (int i = L; i <= R; ++i) puts( NO );     } else if (L == R) {       puts( YES );     } else {       divide((p << 1), L, ((L + R) >> 1), ok);       divide(((p << 1) | 1), ((L + R) >> 1) + 1, R, ok);     }     while (top > top_ver) {       int x = stk[top].x, y = stk[top].y, s = stk[top].s;       fa[x] = x, size[y] = s, dis[x] = 0;       --top;     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; ++i) {       int x, y;       scanf( %d %d , &x, &y);       if (x > y) std::swap(x, y);       std::pair<int, int> pair = {x, y};       if (map.find(pair) != map.end()) {         insert(1, map[pair], i - 1, pair, 1, m);         map.erase(pair);       } else {         map[pair] = i;       }     }     for (auto w : map) {       insert(1, w.second, m, w.first, 1, m);     }     for (int i = 1; i <= n; ++i) fa[i] = i, size[i] = 1;     divide(1, 1, m, 1);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   template <typename T1, typename T2>   inline void chkmin(T1 &first, T2 second) {     if (first > second) first = second;   }   template <typename T1, typename T2>   inline void chkmax(T1 &first, T2 second) {     if (first < second) first = second;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {     _out << _p.first <<     << _p.second;     return _out;   }   template <typename T, typename U>   inline istream &operator>>(istream &_in, pair<T, U> &_p) {     _in >> _p.first >> _p.second;     return _in;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const vector<T> &_v) {     if (_v.empty()) {       return _out;     }     _out << _v.front();     for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline istream &operator>>(istream &_in, vector<T> &_v) {     for (auto &_i : _v) {       _in >> _i;     }     return _in;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const set<T> &_s) {     if (_s.empty()) {       return _out;     }     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {     if (_s.empty()) {       return _out;     }     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {     if (_s.empty()) {       return _out;     }     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {     if (_s.empty()) {       return _out;     }     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {     if (_m.empty()) {       return _out;     }     _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ;     for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {       _out <<  , (  << _it->first <<  :   << _it->second <<  ) ;     }     return _out;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {     if (_m.empty()) {       return _out;     }     _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ;     for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {       _out <<  , (  << _it->first <<  :   << _it->second <<  ) ;     }     return _out;   }   const int MAXN = 2e5 + 1;   int n;   long long len;   int a[MAXN];   int b[MAXN];   int pref[MAXN * 3];   int v[MAXN];   long long get(int i) {     int d = i / n;     if (i < 0) --d;     return len * d + a[i - d * n];   }   bool check(int d) {     for (int i = 0; i < n * 3; ++i) {       pref[i] = 0;     }     int L = -n, R = 0;     for (int i = 0; i < n; ++i) {       v[i] = 0;       while (abs(get(L) - b[i]) > d) {         if (L > n * 2) return false;         ++L;       }       chkmax(R, L);       while (abs(get(R) - b[i]) <= d) {         ++R;       }       if (R - L >= n) {         pref[0]++;         pref[n]--;       } else {         pref[L + n * 2 - i]++;         pref[R + n * 2 - i]--;       }     }     int b = 0;     for (int i = 0; i < n * 3; ++i) {       b += pref[i];       v[i % n] += b;     }     for (int i = 0; i < n; ++i) {       if (v[i] == n) return true;     }     return false;   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> len;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < n; ++i) {       cin >> b[i];     }     sort(a, a + n);     sort(b, b + n);     int L = -1, R = len;     while (R - L > 1) {       int M = (L + R) >> 1;       if (check(M)) {         R = M;       } else {         L = M;       }     }     cout << R << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, q, x;     vector<int> v;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     cin >> q;     while (q--) {       cin >> x;       int ans = upper_bound(v.begin(), v.end(), x) - v.begin();       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int p[100001], w[100001];   bool combine(int x, int y) {     while (p[x] != x) x = p[x] = p[p[x]];     while (p[y] != y) y = p[y] = p[p[y]];     if (x == y) return false;     if (w[x] < w[y])       w[p[x] = y] += w[x];     else       w[p[y] = x] += w[y];     return true;   }   int main() {     int n, m, x, y, ans = 1;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) w[p[i] = i] = 1;     while (m--) {       scanf( %d%d , &x, &y);       if (!combine(x, y)) ans = ans * 2 % 1000000009;       printf( %d n , (ans + 1000000008) % 1000000009);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, x, y, z;     cin >> a >> b >> c >> x >> y >> z;     int ans;     if ((a == 0 && b == 0 && c) || (x == 0 && y == 0 && z)) {       ans = 0;     } else if (a * y == b * x) {       if (a * z == c * x && b * z == c * y) {         ans = -1;       } else {         ans = 0;       }     } else {       ans = 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 21;   string s;   long long heavy = 0, sol = 0;   int main() {     cin >> s;     for (int i = 0; i < s.size(); i++) {       string temp = s.substr(i, 5);       if (temp ==  heavy ) {         heavy++;         i += 4;       } else if (temp ==  metal ) {         sol += heavy;         i += 4;       }     }     printf( %I64d , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void chmax(T &x, T &y) {     if (x < y) swap(x, y);   }   template <class T>   inline void chmin(T &x, T &y) {     if (x > y) swap(x, y);   }   const long long INF = 0x3f3f3f3f3f3f;   const long long MOD = 1e9 + 7;   const double EPS = 10e-10;   const long long P2LIM = (long long)2e18;   const long long maxN = 1e9 + 10;   void Solution() {}   long long countSC(long long N) {     long long res =         (long long)sqrt(N) + (long long)cbrt(N) - (long long)(sqrt(cbrt(N)));     return res;   }   int32_t main() {     long long tc;     cin >> tc;     while (tc--) {       long long n;       cin >> n;       cout << countSC(n) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, tmp;   map<long long, int> b;   long long j = 1, c[33];   void make_two_pow() {     long long i = 2;     while (j <= 32) {       c[j++] = i;       i *= 2;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tmp;       b[tmp]++;     }     make_two_pow();     long long ans = 0;     for (auto& v : b) {       bool flag = false;       for (int i = 1; i < 33; i++) {         tmp = b.count(c[i] - v.first);         if (tmp) {           if (b[c[i] - v.first] >= 2) {             flag = true;             break;           }           if (c[i] - v.first != v.first) {             flag = true;             break;           }         }       }       if (!flag) {         ans += b[v.first];       }     }     cout << endl << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Max = 1e5 + 10;   int fw[Max][26];   int bw[Max][26];   int gs[Max][26];   int ge[Max][26];   int n;   int A[Max];   int mex(vector<int> vec);   void CalcGS(int i, int c);   void CalcGE(int i, int c);   int mex(vector<int> vec) {     sort(vec.begin(), vec.end());     if (vec[0] > 0) return 0;     for (int i = 1; i < vec.size(); i++)       if (vec[i] > vec[i - 1] + 1) return vec[i - 1] + 1;     return vec.back() + 1;   }   int G(int l, int r) {     if (l >= r) return 0;     if ((r - l) == 1 || (r - l) == 2 && A[l + 1] == A[r + 1]) return 1;     l++, r--;     for (int ch = 0; ch < 26; ch++) {       if (A[l] == ch && A[r] == ch) {         CalcGS(l + 1, ch);         CalcGS(r + 1, ch);       } else if (A[r] == ch) {         CalcGS(l, ch);         CalcGS(r + 1, ch);       } else if (A[l] == ch) {         int lCh = bw[r][ch];         CalcGS(l + 1, ch);         CalcGS(lCh + 1, ch);         CalcGE(r, ch);       } else {         int lCh = bw[r][ch];         if (lCh < l) continue;         CalcGS(l, ch);         CalcGS(lCh + 1, ch);         CalcGE(r, ch);       }     }     vector<int> vec;     for (int ch = 0; ch < 26; ch++) {       int g = 0;       if (A[l] == ch && A[r] == ch) {         g = gs[l + 1][ch] ^ gs[r + 1][ch];       } else if (A[r] == ch) {         g = gs[l][ch] ^ gs[r + 1][ch];       } else if (A[l] == ch) {         int lCh = bw[r][ch];         g = gs[l + 1][ch] ^ gs[lCh + 1][ch] ^ ge[r][ch];       } else {         int lCh = bw[r][ch];         if (lCh < l) continue;         g = gs[l][ch] ^ gs[lCh + 1][ch] ^ ge[r][ch];       }       vec.push_back(g);     }     return mex(vec);   }   void CalcGE(int i, int c) {     if (ge[i][c] >= 0) return;     if (A[i] == c) {       ge[i][c] = 0;       return;     }     int l = bw[i][c], r = i + 1;     ge[i][c] = G(l, r);   }   void CalcGS(int i, int c) {     if (gs[i][c] >= 0) return;     CalcGS(fw[i - 1][c] + 1, c);     if (A[i] == c) {       gs[i][c] = 0 ^ gs[fw[i - 1][c] + 1][c];       return;     }     int g = G(i - 1, fw[i - 1][c]) ^ gs[fw[i - 1][c] + 1][c];     gs[i][c] = g;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     {       string s;       cin >> s;       n = s.size();       for (int i = 0; i <= n; i++)         for (int ch = 0; ch < 26; ch++) gs[i][ch] = ge[i][ch] = -1;       for (int ch = 0; ch < 26; ch++) gs[0][ch] = gs[n + 1][ch] = 0;       for (int i = 0; i < n; i++) A[i + 1] = s[i] -  a ;       for (int ch = 0; ch < 26; ch++) {         int lastChSeen = n + 1;         for (int i = n; i--;) {           fw[i + 1][ch] = lastChSeen;           if (A[i + 1] == ch) lastChSeen = i + 1;         }         fw[0][ch] = lastChSeen;         lastChSeen = 0;         bw[0][ch] = lastChSeen;         for (int i = 0; i < n; i++) {           bw[i + 1][ch] = lastChSeen;           if (A[i + 1] == ch) lastChSeen = i + 1;         }       }     }     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r;       if (l == r) {         cout <<  Alice n ;         continue;       }       int g = G(l - 1, r + 1);       if (g == 0)         cout <<  Bob n ;       else         cout <<  Alice n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2 * acos(0.0);   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());   const string DIGITS =  0123456789 ;   const string ALPH =  abcdefghijklmnopqrstuvwxyz ;   template <class T0, class T1>   inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {     return out <<  {  << a.first <<  ,   << a.second <<  } ;   }   template <class T0, class T1>   inline istream &operator>>(istream &in, pair<T0, T1> &a) {     return in >> a.first >> a.second;   }   template <class T0, class T1, class T2>   inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {     return out <<  {  << get<0>(a) <<  ,   << get<1>(a) <<  ,   << get<2>(a)                <<  } ;   }   template <class T0, class T1, class T2, class T3>   inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {     return out <<  {  << get<0>(a) <<  ,   << get<1>(a) <<  ,   << get<2>(a)                <<  ,   << get<3>(a) <<  } ;   }   template <class T>   inline ostream &operator<<(ostream &out, vector<T> &a) {     out <<  [ ;     for (int i = 0; i < int(a.size()); ++i)       out << a[i] << vector<string>{ ,  ,  ]   }[i + 1 == a.size()];     return out;   }   void smain();   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << setprecision(12) << fixed;     smain();     return 0;   }   const int L = 20;   vector<int> ts;   int used[L];   int comp[L];   vector<int> verts[L];   set<int> g[L];   vector<int> rg[L];   void top_sort(int v) {     used[v] = 1;     for (int to : g[v]) {       if (used[to] == 0) {         top_sort(to);       }     }     ts.push_back(v);     used[v] = 2;   }   void inv_dfs(int v, int c) {     used[v] = 1;     comp[v] = c;     verts[c].push_back(v);     for (int to : rg[v]) {       if (used[to] == 0) {         inv_dfs(to, c);       }     }     used[v] = 2;   }   const int N = 20;   int mat[N][N];   int dp[1 << N];   int mg[N];   const int oo = 1e9 + 10;   int solve(set<int> &vr) {     int edges = 0;     for (int i = 0; i < int(N); ++i) {       mg[i] = 0;       for (int j = 0; j < int(N); ++j) {         edges += mat[i][j];         if (mat[i][j]) mg[i] += 1 << j;       }     }     for (int mask = 0; mask < int(1 << N); ++mask) {       dp[mask] = oo;     }     dp[0] = 0;     for (int mask = 0; mask < int(1 << N); ++mask) {       for (int i = 0; i < int(N); ++i)         if (!((mask >> i) & 1)) {           int nmask = mask + (1 << i);           int anti = ((1 << N) - 1) ^ nmask;           int ed = __builtin_popcount(mask & mg[i]);           dp[nmask] = min(dp[nmask], (dp[mask] + (ed != 0 && vr.count(i))));         }     }     return dp[(1 << N) - 1];   }   void smain() {     int t;     cin >> t;     while (t--) {       ts.clear();       for (int i = 0; i < int(L); ++i) {         comp[i] = 0;         verts[i].clear();         used[i] = 0;         rg[i].clear();         g[i].clear();       }       int n;       cin >> n;       string a, b;       cin >> a >> b;       for (int i = 0; i < int(n); ++i)         if (a[i] != b[i]) {           g[a[i] -  a ].insert(b[i] -  a );         }       vector<set<int>> t(L);       for (int i = 0; i < int(L); ++i) {         if (used[i]) continue;         top_sort(i);       }       reverse(ts.begin(), ts.end());       for (int v = 0; v < int(L); ++v) {         for (int to : g[v]) {           rg[to].push_back(v);         }         used[v] = 0;       }       int cnt = 0;       int ans = 0;       for (auto v : ts) {         if (used[v]) continue;         inv_dfs(v, cnt++);         if (verts[comp[v]].size() != 1) {           for (int i = 0; i < int(N); ++i) {             for (int j = 0; j < int(N); ++j) {               mat[i][j] = 0;             }           }           set<int> vr(verts[comp[v]].begin(), verts[comp[v]].end());           for (int v = 0; v < int(L); ++v) {             for (int to : g[v]) {               if (vr.count(v) && vr.count(to)) {                 mat[v][to] = 1;               }             }           }           ans += verts[comp[v]].size() - 1;           ans += solve(vr);         }       }       for (int v = 0; v < int(L); ++v) {         for (int to : g[v]) {           if (comp[v] != comp[to]) {             t[comp[v]].insert(comp[to]);           }         }       }       for (int i = 0; i < int(cnt); ++i) {         t[i].erase(i);         if (t[i].empty()) continue;         ans++;         t[*t[i].begin()].insert(t[i].begin(), t[i].end());       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   int nextInt() {     int x;     scanf( %d , &x);     return x;   }   double nextDouble() {     double x;     scanf( %lf , &x);     return x;   }   long long nextLong() {     long long x;     scanf( %I64d , &x);     return x;   }   char nextChar() {     char x;     scanf( %c , &x);     return x;   }   void newLine() { printf(  n ); }   long long powM(long long a, long long b, long long MOD) {     long long x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y);         if (x > MOD) x %= MOD;       }       y = (y * y);       if (y > MOD) y %= MOD;       b /= 2;     }     return x;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   int countSetBits(long long n) {     int ans = 0;     while (n != 0) {       n -= (n & -n);       ++ans;     }     return ans;   }   long long mod = 1000000007;   long long mod2 = 1000000009;   const int N = 1100;   const int M = 111;   const int LOG = 21;   const long long INF = 1e18;   const long double EPS = 1e-6;   const long double PI = 2 * acos(0);   using namespace std;   int a[N], b[N];   int main() {     int n = nextInt();     int m = nextInt();     int d = 0;     bool ok = true;     for (int i = 0; i < m; i++) {       int x = nextInt(), y = nextInt();       a[x] += 1;       a[y + 1] -= 1;     }     for (int i = 1; i <= n; i++) a[i] += a[i - 1];     for (int i = 1; i <= n; i++) {       if (a[i] != 1) {         cout << i <<     << a[i] << endl;         ok = false;         break;       }     }     if (ok) puts( OK );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int qtable[9][9];   int x_min[9];   int x_max[9];   int y_min[9];   int y_max[9];   int solve_problem() {     int n, m, k, s;     if (scanf( %d %d %d %d , &n, &m, &k, &s) != 4) return 1;     fill(x_min, x_min + k, numeric_limits<int>::max());     fill(x_max, x_max + k, numeric_limits<int>::min());     fill(y_min, y_min + k, numeric_limits<int>::max());     fill(y_max, y_max + k, numeric_limits<int>::min());     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int t;         scanf( %d , &t);         --t;         int x = i + j;         int y = i - j;         if (x < x_min[t]) x_min[t] = x;         if (x > x_max[t]) x_max[t] = x;         if (y < y_min[t]) y_min[t] = y;         if (y > y_max[t]) y_max[t] = y;       }     int prev_q = -1;     for (int i = 0; i < s; i++) {       int q;       scanf( %d , &q);       --q;       if (i > 0) qtable[min(prev_q, q)][max(prev_q, q)] = 1;       prev_q = q;     }     int result = 0;     for (int i = 0; i < k; i++)       for (int j = i; j < k; j++)         if (qtable[i][j]) {           int cand = abs(x_min[i] - x_max[j]);           if (cand > result) result = cand;           cand = abs(x_max[i] - x_min[j]);           if (cand > result) result = cand;           cand = abs(y_min[i] - y_max[j]);           if (cand > result) result = cand;           cand = abs(y_max[i] - y_min[j]);           if (cand > result) result = cand;         }     printf( %d n , result);     return 0;   }   int main() {     solve_problem();     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   void sIO();   void iIO();   void fIO(string fn);   const long long INF = 1000000003LL;   const long long BI = (long long)1e18;   int n;   long long c, a[1111], b[1111], lg, l, r, m;   long long check(long long x) {     long long ret = 0, cur;     for (int i = 0; i < n; ++i) {       cur = a[i] * x;       if (cur > INF || cur < 0) return INF;       ret += a[i] * x / b[i] + 1;     }     return min(ret, INF);   }   int main() {     sIO();     scanf( %d %I64d , &n, &c);     for (int i = 0; i < n; ++i) scanf( %I64d %I64d , a + i, b + i);     if (check(BI) == c) {       printf( -1 );       ;       return 0;     }     l = 1;     r = BI;     while (r - l > 1) {       m = (l + r) >> 1;       if (check(m) < c)         l = m;       else         r = m;     }     if (check(l) < c) ++l;     if (check(l) != c) {       printf( 0 );       return 0;     }     lg = l;     l = 1;     r = BI;     while (r - l > 1) {       m = (l + r) >> 1;       if (check(m) > c)         r = m;       else         l = m;     }     printf( %I64d , r - lg);     return 0;   }   inline void sIO() {}   inline void iIO() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   inline void fIO(string fn) {     freopen((fn +  .in ).c_str(),  r , stdin);     freopen((fn +  .out ).c_str(),  w , stdout);   }


#include <bits/stdc++.h>   using namespace std;   int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};   const double PI = acos(-1.0);   const double EPS = 1e-6;   const int MOD = (int)1e9 + 7;   const int maxn = (int)2e5 + 5;   int cnt[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n, m, i, j;     cin >> n >> m;     set<int> s;     for (i = 1; i <= (m); i++) {       int x;       cin >> x;       cnt[x]++;       s.insert(x);       if ((int)s.size() == n) {         cout <<  1 ;         for (j = 1; j <= (n); j++) {           cnt[j]--;           if (cnt[j] == 0) s.erase(j);         }       } else         cout <<  0 ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long two(int x) { return 1LL << x; }   int get(long long p, int i) { return (p >> (i - 1)) & 1; }   long long count(int n, int k, long long pre) {     long long ret = 0;     bool rev = true, inv = true;     for (int i = 1; i + i <= n; i++) {       if (i <= k && n - i + 1 <= k && get(pre, i) != get(pre, n - i + 1))         rev = false;       if (rev)         if (n - 2 * i == 0)           ret += two(max(0, i - k));         else if (n - 2 * i == 1)           ret += two(max(0, i + 1 - k));         else if ((i >= k || !get(pre, i + 1)) &&                  (n - i - 1 >= k || get(pre, n - i)))           ret += two(max(0, n - i - 1 - k - (k <= i)));       if (i <= k && n - i + 1 <= k && get(pre, i) == get(pre, n - i + 1))         inv = false;       if (inv)         if (n - 2 * i == 0)           ret += two(max(0, i - k));         else if (n - 2 * i == 1) {           if (i >= k || !get(pre, i + 1)) ret += two(max(0, i - k));         } else if ((i >= k || !get(pre, i + 1)) &&                    (n - i - 1 >= k || !get(pre, n - i)))           ret += two(max(0, n - i - 1 - k - (k <= i)));     }     return ret;   }   int main() {     int n;     long long m;     cin >> n >> m;     if (m >= count(n, 1, 0LL)) {       cout << -1 << endl;       return 0;     }     long long pre = 0;     for (int i = 2; i <= n; i++) {       long long tmp = count(n, i, pre);       if (m >= tmp) {         m -= tmp;         pre += two(i - 1);       }     }     for (int i = 1; i <= n; i++) cout << get(pre, i);     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 50, LOGN = 17;   const int INF = (int)1e9;   int n, k;   int ord[N], in[N], tim = 0;   char las[N];   int lc[N], rc[N];   int res[N];   string str;   void dfs(int v) {     if (lc[v] != -1) dfs(lc[v]);     ord[tim] = v;     in[v] = tim++;     if (rc[v] != -1) dfs(rc[v]);   }   void solve(int v, int& rem) {     int la = -1;     int cur = v;     for (int i = 0; i < (rem); ++i) {       if (cur == -1) break;       if (las[cur] !=     && las[cur] > str[cur]) {         la = i;       }       cur = lc[cur];     }     cur = v;     vector<int> vs;     for (int i = 0; i < (la + 1); ++i) {       res[cur] = 1;       rem--;       vs.push_back(cur);       cur = lc[cur];     }     while (!vs.empty()) {       if (rc[vs.back()] != -1) solve(rc[vs.back()], rem);       vs.pop_back();     }   }   void print_ans(int v) {     if (lc[v] != -1) print_ans(lc[v]);     cout << str[v];     if (res[v]) cout << str[v];     if (rc[v] != -1) print_ans(rc[v]);   }   int pos[256];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k;     cin >> str;     for (int i = 0; i < (n); ++i) {       cin >> lc[i] >> rc[i];       lc[i]--, rc[i]--;     }     dfs(0);     fill(pos, pos + 256, INF);     for (int i = n - 1; i >= 0; i--) {       pos[str[ord[i]]] = i;       char f =    ;       for (char c =  a ; c <=  z ; c++) {         if (c != str[ord[i]] && pos[f] > pos[c]) f = c;       }       las[ord[i]] = f;     }     solve(0, k);     assert(k >= 0);     print_ans(0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> a(n);     for (size_t i = 0; i < n; i++) {       cin >> a[i];     }     sort(a.begin(), a.end(), greater<int>());     int x = a[0], y = 0;     for (size_t i = 0; i < n - 1; i++) {       if (x % a[i] != 0 || a[i] == a[i + 1]) {         y = a[i];         break;       }     }     cout << x <<     << y;   }


#include <bits/stdc++.h>   using namespace std;   unordered_map<long long, vector<long long>> m3;   vector<long long int> v;   long long a;   int dfs(long long i, long long p) {     long long k, k1, j, t;     k = -1;     k1 = 0;     for (j = 0; j < m3[i].size(); j++) {       long long d = m3[i][j];       if (d != p) {         t = dfs(d, i);         if (t == 1) {           if (v[d] != v[i]) {             k1 = -1;           }         } else {           k1 = -1;         }       }     }     if (k1 == 0) {       return 1;     }     return -1;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long i, j, b, n, x, y, z, t, k, sum, sum1;     vector<long long int> v1, v2, v3, v4;     string s, s1, s2;     unordered_map<long long, long long> m1, m2, m7;     unordered_map<long long, vector<long long>> m;     t = 1;     while (t--) {       cin >> n;       for (i = 0; i < n - 1; i++) {         cin >> a >> b;         m3[a].push_back(b);         m3[b].push_back(a);       }       a = 0;       v.push_back(0);       for (i = 0; i < n; i++) {         cin >> j;         v.push_back(j);       }       j = 1;       x = -1;       for (i = 1; i <= n; i++) {         for (k = 0; k < m3[i].size(); k++) {           if (v[i] != v[m3[i][k]]) {             x = i;             y = m3[i][k];             break;           }         }       }       if (x == -1) {         cout <<  YES  << endl;         cout << 1;         return 0;       }       for (j = 0; j < m3[x].size(); j++) {         i = dfs(m3[x][j], x);         if (i == -1) break;       }       if (i == 1) {         cout <<  YES  << endl;         cout << x;         return 0;       }       x = y;       for (j = 0; j < m3[x].size(); j++) {         i = dfs(m3[x][j], x);         if (i == -1) break;       }       if (i == 1) {         cout <<  YES  << endl;         cout << y;         return 0;       }       cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long t = 1;     while (t--) {       long long n, d;       cin >> n >> d;       vector<long long> temp(n);       vector<long long> temp2(n);       for (long long i = 0; i < n; i++) {         cin >> temp[i];       }       for (long long i = 0; i < n; i++) {         cin >> temp2[i];       }       long long i = 0;       long long j = n - 1;       if (d == 1) {         cout << 1 << endl;         continue;       }       long long score = temp[d - 1] + temp2[0];       long long ans = d;       while (i < d - 1) {         if (temp[i] + temp2[j] <= score) {           ans--;           i++;           j--;         } else {           i++;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int get() {     int x = 0;     char s = getchar();     while (s <  0  || s >  9 ) s = getchar();     while (s >=  0  && s <=  9 )       x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();     return x;   }   int Min(const int x, const int y) {     if (x < y) return x;     return y;   }   const int M = 1e5 + 5, mo = 1e9 + 7;   int n, m, head[M], cntedge, vis[M], dfn[M], low[M], tot, cntscc, scc[M], siz[M],       dep[M], f[M][17], w[M];   vector<int> G[M];   stack<int> st;   struct edge {     int to, nxt;     edge() {}     edge(const int T, const int NX) { to = T, nxt = NX; }   } e[M << 1];   void add(const int u, const int v) {     e[++cntedge] = edge(v, head[u]), head[u] = cntedge;   }   int pow(int x, int k) {     int ans = 1;     while (k) {       if (k & 1) ans = 1ll * ans * x % mo;       x = 1ll * x * x % mo;       k >>= 1;     }     return ans;   }   void tarjan(const int u, const int fa) {     dfn[u] = low[u] = ++tot;     vis[u] = 1;     st.push(u);     int v;     for (int i = head[u]; i; i = e[i].nxt) {       v = e[i].to;       if (v == fa || vis[v] == 2) continue;       if (!vis[v]) tarjan(v, u);       low[u] = Min(low[u], low[v]);     }     if (dfn[u] == low[u]) {       ++cntscc;       do {         v = st.top(), st.pop();         scc[v] = cntscc;         vis[v] = 2;         ++siz[cntscc];       } while (v ^ u);     }   }   void dfs(const int x, const int fa) {     dep[x] = dep[fa] + 1;     f[x][0] = fa;     w[x] = w[fa] + (siz[x] > 1);     for (int i = 1; i < 17; ++i) f[x][i] = f[f[x][i - 1]][i - 1];     for (int i = 0; i < G[x].size(); ++i)       if (G[x][i] ^ fa) dfs(G[x][i], x);   }   void adjust(int &u, const int val) {     for (int i = 16; i >= 0; --i)       if (dep[f[u][i]] >= val) u = f[u][i];   }   int lca(int u, int v) {     if (dep[u] > dep[v])       adjust(u, dep[v]);     else if (dep[u] < dep[v])       adjust(v, dep[u]);     if (u == v) return u;     for (int i = 16; i >= 0; --i)       if (f[u][i] ^ f[v][i]) u = f[u][i], v = f[v][i];     return f[u][0];   }   int main() {     n = get(), m = get();     for (int u, v; m--;) {       u = get(), v = get();       add(u, v), add(v, u);     }     for (int i = 1; i <= n; ++i)       if (!dfn[i]) tarjan(i, 0);     for (int i = 1; i <= n; ++i)       for (int j = head[i]; j; j = e[j].nxt)         if (scc[i] ^ scc[e[j].to]) G[scc[i]].push_back(scc[e[j].to]);     dfs(1, 0);     for (int q = get(), u, v, x, k; q--;) {       u = scc[get()], v = scc[get()], x = lca(u, v);       k = w[u] + w[v] - (w[x] << 1) + (siz[x] > 1);       printf( %d n , pow(2, k));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct st {     int t, x, id;   };   const int INF = 1000 * 1000 * 1000;   bool operator<(const st &a, const st &b) {     return a.x < b.x || a.x == b.x && a.t < b.t;   }   int main() {     st st_inf;     st_inf.x = INF;     st_inf.t = INF;     st_inf.id = INF;     int N, M;     queue<st> ost;     cin >> N >> M;     st r;     for (int i = 0; i < N; ++i) {       scanf( %d%d , &r.t, &r.x);       r.id = i;       ost.push(r);     }     int OST = N;     int BUS = 0;     vector<st> bus;     long long int T = 0;     vector<long long int> R(100005);     while (BUS || OST) {       while (OST && BUS < M) {         st t = ost.front();         T = max(T, (long long int)t.t);         bus.push_back(t);         ost.pop();         OST--;         BUS++;       }       sort(bus.begin(), bus.end());       queue<st> w;       int y = 0;       while (y < bus.size() && bus[y].t != INF) {         w.push(bus[y]);         y++;       }       BUS = 0;       int L = 0;       bus.clear();       while (!w.empty()) {         int X;         X = w.front().x;         int cnt_v = 1;         R[w.front().id] = T + (X - L);         w.pop();         while (!w.empty()) {           if (w.front().x == X) {             R[w.front().id] = T + (X - L);             w.pop();             cnt_v++;           } else {             break;           }         }         T += (X - L) + (int)(cnt_v / 2) + 1;         L = X;         if (w.empty()) {           T += L;         }       }     }     for (int i = 0; i < N; ++i) {       cout << R[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long sq(long long k) { return k * k; }   long long knan(long long k, long long n) {     if (n == 1)       return k;     else if (n == 0)       return 1;     else {       if (n % 2 == 0)         return sq(knan(k, n / 2)) % 1000000007;       else         return (k * knan(k, n - 1)) % 1000000007;     }   }   int main() {     string s;     int p[4], n;     for (int i = 0; i < 4; i++) p[i] = 0;     cin >> n;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  A ) p[0]++;       if (s[i] ==  T ) p[1]++;       if (s[i] ==  C ) p[2]++;       if (s[i] ==  G ) p[3]++;     }     int max(0), brmax(0);     for (int i = 0; i < 4; i++)       if (p[i] > max) max = p[i];     for (int i = 0; i < 4; i++)       if (p[i] == max) brmax++;     cout << knan(brmax, n) % 1000000007 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int a, b, c, d;       cin >> a >> b;       cin >> c >> d;       if (a > c || (a == c && b > d)) {         swap(a, c);         swap(b, d);       }       long long int per = max(0LL, c - b);       long long int capacity = max(b, d) - a;       long long int current = max(0LL, min(b, d) - c);       capacity = capacity - current;       k = max(0LL, k - n * current);       if (k == 0) {         cout << 0 << endl;         continue;       }       long long int ans = 0;       ans += per;       long long int num = min(k, capacity);       ans += num;       k -= num;       n--;       if (k == 0) {         cout << ans << endl;         continue;       }       if (per + capacity >= 2 * capacity) {         ans += 2 * k;       } else {         long long int divi = min(k / capacity, n);         ans += (per + capacity) * (divi);         k -= divi * capacity;         if (divi == n || k >= capacity) {           ans += 2 * k;         } else {           if (k + per < 2 * k)             ans += k + per;           else             ans += 2 * k;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void rd(T &x) {     char ch;     x = 0;     bool fl = false;     while (!isdigit(ch = getchar())) (ch ==  - ) && (fl = true);     for (x = (ch ^  0 ); isdigit(ch = getchar()); x = x * 10 + (ch ^  0 ))       ;     (fl == true) && (x = -x);   }   template <class T>   inline void ot(T x) {     x / 10 ? ot(x / 10) : putchar(x % 10 +  0 );   }   template <class T>   inline void prt(T a[], int st, int nd) {     for (register int i = st; i <= nd; ++i) printf( %lld  , a[i]);     putchar(  n );   }   namespace Miracle {   const int N = 1e5 + 10;   const int mod = 1e9 + 7;   int n;   long long qm(long long x, long long y) {     long long ret = 1;     while (y) {       if (y & 1) ret = ret * x % mod;       x = x * x % mod;       y >>= 1;     }     return ret;   }   long long jie[N], inv[N];   long long m25[N], i26[N];   int iv;   int exi[N];   int ans[450][N];   int cnt;   long long C(int n, int m) {     if (n < 0 || m < 0 || n < m) return 0;     return jie[n] * inv[m] % mod * inv[n - m] % mod;   }   char s[N];   int main() {     jie[0] = 1;     for (register int i = 1; i <= N - 5; ++i) jie[i] = jie[i - 1] * i % mod;     inv[N - 5] = qm(jie[N - 5], mod - 2);     for (register int i = N - 6; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod;     int m, t;     iv = qm(26, mod - 2);     m25[0] = 1, i26[0] = 1;     for (register int i = 1; i <= N - 5; ++i)       m25[i] = m25[i - 1] * 25 % mod, i26[i] = i26[i - 1] * iv % mod;     rd(t);     scanf( %s , s + 1);     m = strlen(s + 1);     int op;     while (t--) {       rd(op);       if (op == 1) {         scanf( %s , s + 1);         m = strlen(s + 1);       } else {         rd(n);         if (!exi[m]) {           exi[m] = ++cnt;           for (register int i = m; i <= N - 5; ++i) {             ans[cnt][i] = ((long long)ans[cnt][i - 1] +                            C(i - 1, m - 1) * m25[i - m] % mod * i26[i] % mod) %                           mod;           }         }         long long now = qm(26, n) * ans[exi[m]][n] % mod;         printf( %lld n , now);       }     }     return 0;   }   }  // namespace Miracle   signed main() {     Miracle::main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, b, m;   int a[100009], sum[100009];   map<int, int> h;   int main() {     cin >> b >> m >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum[i] = (sum[i - 1] + a[i]) % (b - 1);     }     long long zero = 0, t = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == 0)         t++;       else {         zero += 1ll * t * (t + 1) / 2;         t = 0;       }     }     if (t) zero += 1ll * t * (t + 1) / 2;     if (m == 0) {       cout << zero << endl;       return 0;     }     long long ans = 0;     h[0]++;     for (int i = 1; i <= n; i++) {       int t = ((sum[i] - m) % (b - 1) + (b - 1)) % (b - 1);       ans += h[t];       h[sum[i]]++;     }     if (m == b - 1) ans -= zero;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int c(int x) {     int rev = 0;     int tambah = 1;     while (x != 0) {       int temp = x % 10;       if (temp == 4 || temp == 7) {         rev += (tambah * (temp));         tambah *= 10;       }       x /= 10;     }     return rev;   }   int main() {     int a, b;     scanf( %d %d , &a, &b);     a++;     while (c(a) != b) {       a++;     }     printf( %d n , a);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD(1000000007);   const int INF((1 << 30) - 1);   const int MAXN(55);   int a[MAXN];   string b[MAXN];   string gen(int x) {     string ret =   ;     if (x < 26)       ret +=  A ;     else       ret +=  B ;     ret += ( a  + x % 26);     return ret;   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < n - k + 1; i++) {       string s;       cin >> s;       a[i] = (s ==  YES );     }     int now = 0;     for (int i = 0; i < k; i++) b[i] = gen(now++);     if (a[0] == 0) b[k - 1] = b[0];     for (int i = 1; i <= n - k; i++) {       if (a[i] == 1)         b[i + k - 1] = gen(now++);       else         b[i + k - 1] = b[i];     }     for (int i = 0; i < n; i++) cout << b[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 15;   int k, n, m, x, y, ans;   int dz[6] = {0, 0, 0, 0, 1, -1};   int dx[6] = {0, 0, 1, -1, 0, 0};   int dy[6] = {1, -1, 0, 0, 0, 0};   char plt[N][N][N];   bool mark[N][N][N];   bool isval(int a, int b, int c) {     if (a < k && a >= 0 && b < n && b >= 0 && c < m && c >= 0 &&         plt[a][b][c] ==  . ) {       return true;     }     return false;   }   void dfs(int a, int b, int c) {     mark[a][b][c] = true;     ans++;     for (int i = 0; i < 6; i++) {       if (isval(a + dz[i], b + dx[i], c + dy[i]) &&           !mark[a + dz[i]][b + dx[i]][c + dy[i]]) {         dfs(a + dz[i], b + dx[i], c + dy[i]);       }     }     return;   }   int main() {     cin >> k >> n >> m;     for (int i = 0; i < k; i++) {       for (int j = 0; j < n; j++) {         for (int l = 0; l < m; l++) {           cin >> plt[i][j][l];         }       }     }     cin >> x >> y;     x--;     y--;     dfs(0, x, y);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using vvi = vector<vi>;   int main() {     int N;     cin >> N;     vvi tree(N);     for (int i = 0; i < N - 1; ++i) {       int a, b;       cin >> a >> b;       a--;       b--;       tree[a].push_back(b);       tree[b].push_back(a);     }     int min = 0, max = 0;     vi min_v(N), max_v(N);     for (int i = 0; i < N; ++i) min_v[i] = max_v[i] = i;     vi degree(N);     queue<int> q;     for (int u = 0; u < N; ++u)       if ((degree[u] = tree[u].size()) == 1) q.push(u);     while (!q.empty()) {       int u = q.front();       q.pop();       int n = tree[u][0];       for (int v : tree[u])         if (degree[v] > 0) n = v;       if (min_v[u] == u) {         swap(min_v[u], min_v[n]);         min += 2;       }       if (degree[n] > 0) {         degree[u] = 0;         if (--degree[n] == 1) q.push(n);       }     }     cout << min << endl;     for (int u = 0; u < N; ++u) cout << min_v[u] + 1 <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline void file() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     char b[10000];     int a;     cin >> a;     int c = 0;     for (int i = 0; i < a; ++i) {       cin >> b[0] >> b[1] >> b[2];       if (b[0] ==  -  and b[1] ==  -  or b[2] ==  -  and b[1] ==  - )         c--;       else         c++;     }     cout << c;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 500;   char s[N];   int son[N][26];   int fail[N], pos[N];   int n, m;   int cnt;   inline void insert(char s[], int n, int id) {     int i, cur = 0;     for (i = 1; i <= n; i++) {       if (!son[cur][s[i] -  a ]) son[cur][s[i] -  a ] = ++cnt;       cur = son[cur][s[i] -  a ];     }     pos[id] = cur;   }   queue<int> Q;   inline void build() {     int i;     for (i = 0; i <= 25; i++)       if (son[0][i]) Q.push(son[0][i]);     while (!Q.empty()) {       int x = Q.front();       Q.pop();       for (i = 0; i <= 25; i++)         if (!son[x][i])           son[x][i] = son[fail[x]][i];         else           fail[son[x][i]] = son[fail[x]][i], Q.push(son[x][i]);     }   }   struct Edge {     int to, nxt;   };   Edge e[N << 1];   int lst[N];   inline void add(int u, int v) {     static int cnt = 0;     e[++cnt] = (Edge){v, lst[u]}, lst[u] = cnt;   }   int dfn[N], low[N];   inline void dfs(int x) {     static int idx = 0;     int i;     dfn[x] = ++idx;     for (i = lst[x]; ~i; i = e[i].nxt) dfs(e[i].to);     low[x] = idx;   }   int C[N];   inline void update(int x, int delta) {     while (x <= cnt + 1) C[x] += delta, x += ((x) & -(x));   }   inline int query(int x) {     int res = 0;     while (x > 0) res += C[x], x -= ((x) & -(x));     return res;   }   int del[N];   int main() {     int i;     scanf( %d%d , &m, &n);     for (i = 1; i <= n; i++) scanf(  %s  , s + 1), insert(s, strlen(s + 1), i);     build();     for (i = 0; i <= cnt; i++) lst[i] = -1;     for (i = 1; i <= cnt; i++) add(fail[i], i);     dfs(0);     for (i = 1; i <= n; i++) update(dfn[pos[i]], 1), update(low[pos[i]] + 1, -1);     while (m--) {       scanf(  %s  , s), n = strlen(s + 1);       if (s[0] ==  ? ) {         int cur = 0, ans = 0;         for (i = 1; i <= n; i++) {           if (!son[cur][s[i] -  a ])             cur = fail[cur];           else             cur = son[cur][s[i] -  a ];           ans += query(dfn[cur]);         }         printf( %d n , ans);       } else {         int id = 0;         for (i = 1; i <= n; i++) id = (id << 1) + (id << 3) + (s[i] ^ 48);         if (s[0] ==  - ) {           if (!del[id])             update(dfn[pos[id]], -1), update(low[pos[id]] + 1, 1), del[id] = 1;         } else if (del[id])           update(dfn[pos[id]], 1), update(low[pos[id]] + 1, -1), del[id] = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n;     cin >> s;     if (!(n % 2)) {       for (int i = 0; i < n; ++i) {         cout << s[i];         if (i % 2 && i != n - 1) cout <<  - ;       }     } else {       for (int i = 0; i < n - 3; ++i) {         cout << s[i];         if (i % 2) cout <<  - ;       }       for (int i = n - 3; i < n; ++i) cout << s[i];     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, k;     scanf( %d %d , &n, &k);     while (k > 0) {       if (n % 10 == 0)         n /= 10;       else         n--;       k--;     }     printf( %d , n);   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, s, tmp1, tmp2;   vector<long long> ans;   vector<vector<long long>> g(100000);   bool vs[2][100000];   bool vs1[100000] = {0}, rc[100000] = {0};   bool a = false, w = false, d = false, t = false;   long long cnt = 0;   void hasc(long long v) {     vs1[v - 1] = true;     rc[v - 1] = true;     for (auto el : g[v - 1]) {       if (!vs1[el - 1])         hasc(el);       else if (rc[el - 1]) {         d = true;       }     }     rc[v - 1] = false;   }   void dfs(long long v) {     ans.push_back(v);     vs[a][v - 1] = true;     if (a && !(g[v - 1].size())) {       w = 1;       return;     }     a = !a;     for (auto el : g[v - 1])       if (!vs[a][el - 1] && !w) {         dfs(el);       }     a = !a;     if (w) return;     ans.pop_back();   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> tmp1;       for (int j = 0; j < tmp1; j++) {         cin >> tmp2;         g[i].push_back(tmp2);       }     }     cin >> s;     dfs(s);     hasc(s);     if (w) {       cout <<  Win  << endl;       for (auto el : ans) cout << el <<    ;       cout << endl;     } else if (d) {       cout <<  Draw  << endl;     } else       cout <<  Lose  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<pair<int, int> > > Adj;   vector<int> Col;   bool DFS(int u, int f) {     Col[u] = 1 + f;     bool pos = 0;     for (auto i : Adj[u]) {       if (Col[i.first]) {         if ((f ^ i.second) == Col[i.first] - 1)           continue;         else           return 1;       }       pos |= DFS(i.first, f ^ i.second);     }     return pos;   }   template <typename T>   T fast_exp(T base, T power, T M = 0) {     if (M) base %= M;     T result = 1;     while (power) {       if (power & 1) result *= base;       power >>= 1;       base *= base;       if (M) {         base %= M;         result %= M;       }     }     return result;   }   long long Calc(string S, int lA, int lB) {     Adj.clear();     Col.clear();     Adj.resize(lA + lB + 1);     Col.resize(lA + lB + 1);     for (int x = 0; x < lA; x++) {       Adj[x].push_back({lA - x - 1, 0});       Adj[lA - x - 1].push_back({x, 0});     }     for (int x = 0; x < lB; x++) {       Adj[lA + x].push_back({lA + lB - x - 1, 0});       Adj[lA + x].push_back({lA + lB - x - 1, 0});     }     for (int x = 0; x < lA; x++) {       if (S[x] ==  ? ) continue;       if (x < lA - lB) {         Adj[x].push_back({lA + lB, S[x] -  0 });         Adj[lA + lB].push_back({x, S[x] -  0 });       } else {         Adj[x].push_back({lB + x, S[x] -  0 });         Adj[lB + x].push_back({x, S[x] -  0 });       }     }     Adj[lA + lB].push_back({lA, 1});     Adj[lA].push_back({lA + lB, 1});     int cnt = 0;     for (int x = 0; x < lA + lB + 1; x++) {       if (Col[x]) continue;       if (DFS(x, 0)) return 0;       cnt++;     }     return fast_exp<long long>(2, cnt - 1, 998244353);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     string S;     cin >> S;     long long ans = 0;     int lA = S.size();     for (int lB = 1; lB < lA; lB++) {       ans += Calc(S, lA, lB);       ans %= 998244353;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   char s[1005], z[1005];   int solve1() {     int ans = 0;     int lz, rz, ls, rs;     lz = ls = 0;     rz = rs = N - 1;     while (ls <= rs) {       if (z[rz] >= s[rs])         rz--, rs--;       else         ans++, lz++, rs--;     }     return ans;   }   int solve2() {     int ans = 0;     int lz, rz, ls, rs;     lz = ls = 0;     rz = rs = N - 1;     while (ls <= rs) {       if (z[rz] > s[rs])         ans++, rz--, rs--;       else         lz++, rs--;     }     return ans;   }   int main() {     scanf( %d%s%s , &N, s, z);     sort(s, s + N);     sort(z, z + N);     printf( %d n%d , solve1(), solve2());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int rd() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();     return x * f;   }   const int N = 100009;   int n, m, o, a[N], pre[N], suf[N], numq, tr[N];   long long ans[N];   set<int> s[N];   struct node {     int opt, x, y, v, id;     inline bool operator<(const node& rhs) const { return x < rhs.x; }   } p[N * 7], q[N * 7];   int suf_(int v, int x) { return *s[v].upper_bound(x); }   int pre_(int v, int x) {     set<int>::iterator it = s[v].lower_bound(x);     --it;     return *it;   }   void link(int x, int y) {     ++o, p[o].opt = 0, p[o].x = x, p[o].y = pre[x], p[o].v = pre[x] - x,          p[o].id = 0;     pre[x] = y;     ++o, p[o].opt = 0, p[o].x = x, p[o].y = pre[x], p[o].v = x - pre[x],          p[o].id = 0;   }   void add(int x, int d) {     if (!x) return;     for (int i = x; i <= n; i += i & -i) tr[i] += d;   }   int ask(int x) {     int res = 0;     for (int i = x; i > 0; i -= i & -i) res += tr[i];     return res;   }   void clear(int x) {     if (!x) return;     for (int i = x; i <= n; i += i & -i) tr[i] = 0;   }   void cdq(int l, int r) {     if (l == r) return;     int mid = (l + r) >> 1;     cdq(l, mid), cdq(mid + 1, r);     for (int i = mid + 1, j = l; i <= r; ++i) {       if (!p[i].opt) continue;       for (; j <= mid && p[j].x <= p[i].x; ++j)         if (!p[j].opt) add(p[j].y, p[j].v);       ans[p[i].id] += ask(n) - ask(p[i].y - 1);     }     for (int i = l; i <= mid; ++i)       if (!p[i].opt) clear(p[i].y);     merge(p + l, p + mid + 1, p + mid + 1, p + r + 1, q + l);     for (int i = l; i <= r; ++i) p[i] = q[i];   }   signed main() {     n = rd(), m = rd();     for (int i = 1; i <= n; ++i) a[i] = rd(), s[a[i]].insert(i);     for (int i = 1; i <= n; ++i) s[i].insert(0), s[i].insert(n + 1);     for (int i = 1; i <= n; ++i)       pre[i] = pre_(a[i], i), suf[i] = suf_(a[i], i), ++o, p[o].opt = 0,       p[o].x = i, p[o].y = pre[i], p[o].v = i - pre[i], p[o].id = 0;     for (int i = 1; i <= m; ++i) {       int opt = rd(), x = rd(), y = rd();       if (opt == 2)         ++o, ++numq, p[o].opt = 1, p[o].x = y, p[o].y = x, p[o].id = numq;       else {         if (y == a[x]) continue;         int P = pre_(y, x), S = suf_(y, x);         s[y].insert(x), s[a[x]].erase(x), a[x] = y;         if (suf[x] != n + 1) link(suf[x], pre[x]);         if (pre[x]) suf[pre[x]] = suf[x];         if (S != n + 1) link(S, x);         if (P) suf[P] = x;         link(x, P);         suf[x] = S;       }     }     cdq(1, o);     for (int i = 1; i <= numq; ++i) printf( %lld n , ans[i]);     return 0;   }