#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1001;   int dp2[MAX_N][MAX_N], dp5[MAX_N][MAX_N];   int n;   string findPath(int (*p)[MAX_N]) {     int i = n - 1, j = n - 1;     string path =   ;     while (i != 0 && j != 0) {       if (p[i - 1][j] > p[i][j - 1]) {         path.insert(0,  R );         j--;       } else {         path.insert(0,  D );         i--;       }     }     if (i == 0) {       while (j != 0) {         path.insert(0,  R );         j--;       }     } else {       while (i != 0) {         path.insert(0,  D );         i--;       }     }     return path;   }   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     int temp1, temp2, zeroI = -1;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         cin >> temp1;         if (!temp1) {           zeroI = i;           continue;         }         temp2 = temp1;         while (!(temp1 & 1)) {           dp2[i][j]++;           temp1 >>= 1;         }         while (!(temp2 % 5)) {           dp5[i][j]++;           temp2 /= 5;         }       }     for (int i = 1; i < n; i++) {       dp2[i][0] += dp2[i - 1][0];       dp5[i][0] += dp5[i - 1][0];       dp2[0][i] += dp2[0][i - 1];       dp5[0][i] += dp5[0][i - 1];     }     for (int i = 1; i < n; i++) {       for (int j = 1; j < n; j++) {         dp2[i][j] += min(dp2[i - 1][j], dp2[i][j - 1]);         dp5[i][j] += min(dp5[i - 1][j], dp5[i][j - 1]);       }     }     int(*p)[MAX_N] = (dp2[n - 1][n - 1] < dp5[n - 1][n - 1]) ? dp2 : dp5;     if ((~zeroI) && p[n - 1][n - 1] > 1) {       cout <<  1  << endl;       for (int i = 0; i < zeroI; i++) cout <<  D  << flush;       for (int j = 1; j < n; j++) cout <<  R  << flush;       for (int i = zeroI + 1; i < n; i++) cout <<  D  << flush;       return 0;     } else {       cout << p[n - 1][n - 1] << endl;       cout << findPath(p) << flush;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int B, n, m;   int li[500008], ri[500008], mx[500008], tag[500008];   short g[480][100008];   int bel[500008], de[500008], ai[500008], pa[500008];   short size[500008];   int find(int x) {     if (pa[x] == x) return x;     return pa[x] = find(pa[x]);   }   void link(int x, int y) {     if (x == y) return;     if (size[x] > size[y]) swap(x, y);     pa[x] = y;     size[y] += size[x];   }   int tot;   int lst[500008], stamp[500008];   void makeup(int id) {     ++tot;     mx[id] = 0;     for (int i = li[id]; i <= ri[id]; i++) pa[i] = i, size[i] = 1;     for (int i = li[id]; i <= ri[id]; i++) {       int x = ai[i];       mx[id] = max(mx[id], x);       if (stamp[x] != tot)         stamp[x] = tot, g[id][x] = lst[x] = i - li[id];       else         link(i, g[id][x] + li[id]), g[id][x] = find(g[id][x] + li[id]) - li[id];     }   }   void pushdown(int id) {     for (int i = li[id]; i <= ri[id]; i++) g[id][ai[i]] = -1;     for (int i = li[id]; i <= ri[id]; i++) {       g[id][ai[i] + de[i]] = -1;       if (find(i) == i) ai[i] = ai[i] + de[i] - tag[id];       de[i] = 0;     }     for (int i = li[id]; i <= ri[id]; i++) ai[i] = ai[find(i)];     tag[id] = 0;   }   void refresh(int id) {     while (-1 == g[id][mx[id]]) mx[id]--;   }   int cnt = 0;   void subtract(int id, int x) {     if (mx[id] - tag[id] <= x) return;     if (mx[id] - tag[id] > x * 2 + 1 and 1) {       for (int i = tag[id] + 1; i <= x + tag[id]; i++)         if (g[id][i] != -1) {           int j = i + x;           de[g[id][i] + li[id]] += x;           if (g[id][j] != -1)             link(g[id][i] + li[id], g[id][j] + li[id]),                 g[id][j] = find(g[id][j] + li[id]) - li[id];           else             g[id][j] = g[id][i];           g[id][i] = -1;         }       tag[id] += x;     } else {       for (int i = x + 1 + tag[id]; i <= mx[id]; i++)         if (g[id][i] != -1) {           int j = i - x;           de[g[id][i] + li[id]] -= x;           if (g[id][j] != -1)             link(g[id][j] + li[id], g[id][i] + li[id]),                 g[id][j] = find(g[id][j] + li[id]) - li[id];           else             g[id][j] = g[id][i];           g[id][i] = -1;         }       refresh(id);     }   }   int ask(int id, int x) {     if (x + tag[id] > 100001) return 0;     if (g[id][x + tag[id]] == -1) return 0;     g[id][x + tag[id]] = find(g[id][x + tag[id]] + li[id]) - li[id];     return size[g[id][x + tag[id]] + li[id]];   }   signed main() {     memset(g, -1, sizeof g);     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &ai[i]);     B = sqrt(n);     B = max(B, n / 475);     memset(li, 0x3f, sizeof li);     for (int i = 1; i <= n; i++) {       bel[i] = i / B;       li[bel[i]] = min(li[bel[i]], i);       ri[bel[i]] = i;     }     for (int i = 0; i <= n / B; i++) makeup(i);     while (m--) {       int op, l, r, x;       scanf( %d%d%d%d , &op, &l, &r, &x);       if (op == 1) {         if (bel[l] == bel[r]) {           pushdown(bel[l]);           for (int i = l; i <= r; i++)             if (ai[i] > x) ai[i] -= x;           makeup(bel[l]);         } else {           pushdown(bel[l]);           for (int i = l; i <= ri[bel[l]]; i++)             if (ai[i] > x) ai[i] -= x;           pushdown(bel[r]);           for (int i = li[bel[r]]; i <= r; i++)             if (ai[i] > x) ai[i] -= x;           makeup(bel[l]);           makeup(bel[r]);           for (int i = bel[l] + 1; i < bel[r]; i++) subtract(i, x);         }       } else {         int ans = 0;         if (bel[l] == bel[r]) {           pushdown(bel[l]);           for (int i = l; i <= r; i++)             if (ai[i] == x) ans++;           makeup(bel[l]);           printf( %d n , ans);         } else {           pushdown(bel[l]);           for (int i = l; i <= ri[bel[l]]; i++) ans += (ai[i] == x);           pushdown(bel[r]);           for (int i = li[bel[r]]; i <= r; i++) ans += (ai[i] == x);           makeup(bel[l]);           makeup(bel[r]);           for (int i = bel[l] + 1; i < bel[r]; i++) ans += ask(i, x);           printf( %d n , ans);         }       }       ++cnt;       if (cnt < -7) {         for (int i = 0; i <= n / B; i++) pushdown(i);         for (int i = 1; i <= n; i++) cout << ai[i] <<    ;         cout << g[2][30] <<  : n n ;         for (int i = 0; i <= n / B; i++) makeup(i);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   long long a[N];   int n;   bool check(long long x) {     long long sum = 0;     for (int i = 2; i <= n; ++i) {       if (x - a[i] < 0) return false;       sum += x - a[i];     }     return (sum >= a[1]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %I64d , &a[i]);     sort(a + 1, a + n + 1);     long long l = 0, r = (long long)1e14 + 1;     while (l + 1 < r) {       long long mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     if (check(l))       printf( %I64d , l);     else       printf( %I64d , r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isPowerOfTwo(int n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   void asquare() {     long long n, c = 0, ans = LONG_LONG_MAX;     cin >> n;     string sn;     if (isPowerOfTwo(n) == true)       cout <<  0 n ;     else {       long long j = 0, k = 0, nn = 1;       string s = to_string(n);       for (int i = 0; i <= 60; i++) {         nn = (long long)pow(2, i);         sn = to_string(nn);         c = 0, j = 0, k = 0;         bool bb;         while (j != s.length() && k != sn.length()) {           if (s[j] == sn[k]) {             j++;             k++;             bb = true;           } else {             j++;             c++;             bb = false;           }         }         if (bb = true) {           if (j == s.length()) {             k--;             c += sn.length() - k - 1;           } else if (k == sn.length()) {             j--;             c += s.length() - j - 1;           }         } else {           k--;           c += sn.length() - k - 1;         }         if (c == 1) {           ans = 1;           break;         } else           ans = min(ans, c);       }       cout << ans <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       asquare();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int x, y;     cin >> x >> y;     int ans = 0;     int d = max(abs(x), abs(y));     if (d == 0) {       cout << 0 <<   n ;       return 0;     } else       ans = (d - 1) * 4;     if (x == d && y != -1 * (d - 1) && y != -1 * (d)) ans++;     if (y == d && x != d) ans += 2;     if (x == -1 * d && y != d) ans += 3;     if (y == -1 * d && x != -1 * d) ans += 4;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct Aho {     Aho *son[26];     Aho *fail;     int cntstr, faildp;     Aho() {       for (int i = 0; i < 26; ++i) son[i] = NULL;       fail = NULL;       cntstr = 0;       faildp = -1;     }   };   void insert(Aho *x, int i, const string &str) {     if (i < str.size()) {       if (x->son[str[i] -  a ] == NULL) {         x->son[str[i] -  a ] = new Aho();       }       insert(x->son[str[i] -  a ], i + 1, str);     } else {       x->cntstr++;     }   }   void calcFailEdges(Aho *root) {     deque<Aho *> q;     root->fail = root;     q.push_back(root);     while (!q.empty()) {       Aho *x = q.front();       q.pop_front();       for (int i = 0; i < 26; ++i) {         if (x->son[i] != NULL) {           q.push_back(x->son[i]);           Aho *pnt = x->fail;           if (x == root)             x->son[i]->fail = root;           else {             while (pnt != root && pnt->son[i] == NULL) {               pnt = pnt->fail;             }             if (pnt->son[i] != NULL)               x->son[i]->fail = pnt->son[i];             else               x->son[i]->fail = root;           }         }       }     }   }   int getDp(Aho *t) {     if (t->faildp == -1) {       t->faildp = t->cntstr;       t->faildp += getDp(t->fail);     }     return t->faildp;   }   const int MAX_N = 200000;   Aho *state[1 + MAX_N];   Aho *advance(Aho *t, char ch) {     while (t->fail != t && t->son[ch -  a ] == NULL) t = t->fail;     if (t->son[ch -  a ] == NULL) return t;     return t->son[ch -  a ];   }   Aho *state1[MAX_N], *state2[MAX_N];   void doStuff(int n, Aho **state, const string &str, const vector<string> &vec) {     Aho *T = new Aho();     for (int i = 0; i < n; ++i) insert(T, 0, vec[i]);     T->faildp = T->cntstr;     calcFailEdges(T);     Aho *pnt = T;     for (int i = 1; i <= str.size(); ++i) {       pnt = advance(pnt, str[i - 1]);       state[i] = pnt;     }   }   int main() {     int n;     string str;     cin >> str >> n;     vector<string> vec;     for (int i = 0; i < n; ++i) {       string p;       cin >> p;       vec.push_back(p);     }     doStuff(n, state1, str, vec);     for (int i = 0; i < n; ++i) reverse(vec[i].begin(), vec[i].end());     reverse(str.begin(), str.end());     doStuff(n, state2, str, vec);     long long rez = 0LL;     for (int i = 1; i < str.size(); ++i)       rez = (long long)getDp(state1[i]) * getDp(state2[str.size() - i]) + rez;     printf( %lld , rez);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const int base = 101;   inline void chmax(int& x, int y) {     if (x < y) x = y;   }   inline void chmin(int& x, int y) {     if (x > y) x = y;   }   inline int LSB(int i) { return (i & -i); }   int n, m, dp[10005];   char s[10005], str[10005];   map<long long, string> mp;   vector<string> v;   inline long long Hash(int a, int b) { return (1LL * a * base + b) % MOD; }   int main() {     scanf( %d%s%d , &n, &s, &m);     for (int i = 0; i < m; i++) {       scanf( %s , &str);       long long h = 1;       for (int j = 0; j < strlen(str); j++) {         h = Hash(h, tolower(str[j]));       }       mp[h] = str;     }     fill(dp, dp + n, -1);     dp[0] = 0;     for (int i = 0; i < n; i++) {       long long h = 1;       for (int j = i; j >= 0; j--) {         h = Hash(h, s[j]);         if (dp[j] != -1 && mp.find(h) != mp.end()) {           dp[i + 1] = h;           break;         }       }     }     int p = n;     while (p > 0) {       v.push_back(mp[dp[p]]);       p -= mp[dp[p]].length();     }     reverse(v.begin(), v.end());     for (string& i : v) printf( %s  , &i[0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long p = 1e9 + 7;   int mk[705][705][3][3];   char s[705];   long long ck(int l, int r, int lc, int rc) {     if (l > r) return !lc || !rc || lc != rc;     if (mk[l][r][lc][rc]) return mk[l][r][lc][rc];     for (int i = l, cnt = 0;; i++) {       if (s[i] ==  ) )         cnt++;       else         cnt--;       if (!cnt) {         long long m = ck(l + 1, i - 1, 0, 1) * ck(i + 1, r, 1, rc) % p +                       ck(l + 1, i - 1, 0, 2) * ck(i + 1, r, 2, rc);         if (lc != 1) m += ck(l + 1, i - 1, 1, 0) * ck(i + 1, r, 0, rc);         if (lc != 2) m += ck(l + 1, i - 1, 2, 0) * ck(i + 1, r, 0, rc);         return mk[l][r][lc][rc] = m % p;       }     }   }   int main() {     scanf( %s , s + 1);     printf( %lld , ck(1, strlen(s + 1), 0, 0));   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   using ll = long long;   using ull = unsigned long long;   template <typename T>   void print(vector<T> v) {     for (T i : v) cout << i <<    ;     cout <<   n ;   }   template <typename T>   void print(vector<vector<T>>& v) {     for (vector<T>& vv : v) {       for (T& i : vv) cout << i <<    ;       cout <<   n ;     }   }   template <typename T>   void print(T&& t) {     cout << t <<   n ;   }   template <typename T, typename... Args>   void print(T&& t, Args&&... args) {     cout << t <<    ;     print(forward<Args>(args)...);   }   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& i : v) is >> i;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T>& v) {     for (auto& i : v) os << i <<    ;     return os;   }   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char* x) { cerr <<     << x <<    ; }   void __print(const string& x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V>& x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T& x) {     int f = 0;     cerr <<  { ;     for (auto& i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void loop() {     ll n;     cin >> n;     vector<ll> a(n);     cin >> a;     if (n == 1) {       print( Alice );       return;     }     vector<ll> inc, dec;     inc.push_back(a[0]);     for (ll i = 0; i < n - 1; i++) {       if (a[i] < a[i + 1]) {         inc.push_back(a[i + 1]);       } else         break;     }     dec.push_back(a[n - 1]);     for (ll i = n - 1; i > 0; i--) {       if (a[i] < a[i - 1]) {         dec.push_back(a[i - 1]);       } else         break;     }     if (dec.size() % 2) {       print( Alice );       return;     } else if ((inc.size() - 1 + dec.size()) % 2 == 0) {       print( Alice );       return;     }     print( Bob );   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ll t;     t = 1;     while (t--) {       loop();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int INF = 0x3f3f3f3f;   int n, m, a[maxn], b[maxn], f[maxn], g[maxn], l[maxn], p[maxn], ans[maxn];   bool vis[maxn];   int main() {     scanf( %d , &n);     for (int i = (1), _end_ = (n); i <= _end_; ++i) scanf( %d , &a[i]);     a[++n] = INF;     scanf( %d , &m);     for (int i = (1), _end_ = (m); i <= _end_; ++i) scanf( %d , &b[i]);     sort(b + 1, b + m + 1);     for (int i = (1), _end_ = (n + 1); i <= _end_; ++i) f[i] = INF;     for (int i = (1), _end_ = (n); i <= _end_; ++i)       if (a[i] != -1) {         int L = 1, R = n, pos = 0;         while (L <= R) {           int Mid = L + R >> 1;           if (f[Mid] < a[i]) {             pos = Mid;             L = Mid + 1;           } else             R = Mid - 1;         }         f[pos + 1] = a[i];         g[pos + 1] = i;         l[i] = pos + 1;         p[i] = g[pos];       } else {         int pos = n;         for (int j = m; j >= 1; --j) {           while (f[pos] >= b[j]) --pos;           f[pos + 1] = b[j];           g[pos + 1] = i;         }       }     for (int len = l[n], pos = n, val = a[n]; len >= 1; --len)       if (a[pos] != -1) {         if (a[p[pos]] != -1) {           pos = p[pos];           val = a[pos];         } else {           int t = lower_bound(b + 1, b + m + 1, val) - b - 1;           vis[t] = true;           pos = p[pos];           val = ans[pos] = b[t];         }       } else {         for (int i = pos - 1; i >= 1; --i)           if (a[i] != -1 && l[i] == len - 1 && a[i] < val) {             pos = i;             val = a[i];             goto Next;           }         for (int i = pos - 1; i >= 1; --i)           if (a[i] == -1) {             int t = lower_bound(b + 1, b + m + 1, val) - b - 1;             vis[t] = true;             pos = i;             val = ans[pos] = b[t];             goto Next;           }       Next:;       }     int pos = 1;     for (int i = (1), _end_ = (n - 1); i <= _end_; ++i)       if (a[i] != -1)         ans[i] = a[i];       else if (!ans[i]) {         while (vis[pos]) ++pos;         ans[i] = b[pos];         ++pos;       }     for (int i = (1), _end_ = (n - 1); i <= _end_; ++i) printf( %d  , ans[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getChar(char c) {     if (c ==  + ) return 1;     return 0;   }   string s;   stack<int> mystack;   int main() {     cin >> s;     int n = s.size();     int temp;     for (int i = 0; i < n; i++) {       temp = getChar(s[i]);       if (mystack.empty())         mystack.push(temp);       else {         if (mystack.top() == temp)           mystack.pop();         else           mystack.push(temp);       }     }     if (mystack.empty()) {       cout <<  Yes  << endl;       return 0;     }     cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2000000000;   const double eps = 1e-9, Pi = 2 * acos(0);   int main() {     ifstream fin( input.txt );     ofstream fout( output.txt );     string s;     cin >> s;     map<string, int> make_pair;     for (int i = 0; i <= 9; i++) {       string x;       cin >> x;       make_pair[x] = i;     }     for (int i = 0; i < 8; i++) {       string x =   ;       for (int j = i * 10; j < (i + 1) * 10; j++) x += s[j];       cout << make_pair[x];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, memo[1 << 25];   pair<int, int> arr[30];   int dist(int a, int n) {     int k1 = arr[n].first - arr[a].first;     int k2 = arr[n].second - arr[a].second;     return k1 * k1 + k2 * k2;   }   int dp(int mask) {     if (__builtin_popcount(mask) == N) {       return 0;     }     if (memo[mask] != 0) return memo[mask];     int res = 1e9;     for (int i = 1; i <= N; i++) {       if (!((mask >> (i - 1) & 1))) {         res = min(res, dp(mask | (1 << (i - 1))) + 2 * dist(i, 0));         for (int j = i + 1; j <= N; j++) {           if (!(mask >> (j - 1) & 1) and i != j) {             res = min(res, dp(mask | (1 << (i - 1)) | (1 << (j - 1))) +                                dist(i, 0) + dist(i, j) + dist(j, 0));           }         }         break;       }     }     memo[mask] = res;     return res;   }   void backtrack(int mask) {     if (__builtin_popcount(mask) == N) {       return;     }     for (int i = 1; i <= N; i++) {       if (!((mask >> (i - 1) & 1))) {         if (dp(mask | (1 << (i - 1))) + 2 * dist(i, 0) == dp(mask)) {           cout << 0 <<     << i <<    ;           backtrack(mask | (1 << (i - 1)));           return;         }         for (int j = i + 1; j <= N; j++) {           if (!(mask >> (j - 1) & 1) and i != j) {             if (dp(mask | (1 << (i - 1)) | (1 << (j - 1))) + dist(i, 0) +                     dist(i, j) + dist(j, 0) ==                 dp(mask)) {               cout << 0 <<     << i <<     << j <<    ;               backtrack(mask | (1 << (i - 1)) | (1 << (j - 1)));               return;             }           }         }         break;       }     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cin >> arr[0].first >> arr[0].second;     cin >> N;     for (int i = 1; i <= N; i++) cin >> arr[i].first >> arr[i].second;     cout << dp(0) << endl;     backtrack(0);     cout << 0 << endl;   }


#include <bits/stdc++.h>   using namespace std;   char str[2][400000 + 10];   int n;   void sortstr(int t, int l, int r) {     if ((r - l + 1) & 1) return;     int md = (l + r) / 2;     sortstr(t, l, (l + r) / 2), sortstr(t, (l + r) / 2 + 1, r);     bool needswap = false;     for (int i = l, j = md + 1; i <= md; i++, j++) {       if (str[t][i] < str[t][j]) break;       if (str[t][i] > str[t][j]) {         needswap = true;         break;       }     }     if (needswap) {       for (int i = l, j = md + 1; i <= md; i++, j++) swap(str[t][i], str[t][j]);     }   }   int main() {     for (int i = 0; i < 2; i++)       scanf( %s , str[i]), n = strlen(str[i]), sortstr(i, 0, n - 1);     bool equ = true;     for (int i = 0; i < n; i++)       if (str[0][i] != str[1][i]) equ = false;     printf( %s n , equ ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, gxx;   pair<int, int> a[411111];   int p[411111];   int Gxx[411111], bb[411111];   int degree[411111];   int h, t;   void make_ans(int x, int y, int tot) {     int now_x = degree[x] - 1 - tot;     int need_x = max(h - now_x, 0);     int now_y = degree[y] - 1 - tot;     int need_y = max(t - now_y, 0);     for (int i = p[x]; i < p[x + 1]; i++) Gxx[a[i].second] = 1;     for (int i = p[y]; i < p[y + 1]; i++)       if (Gxx[a[i].second] == 1) bb[a[i].second] = 1;     printf( YES n );     printf( %d %d n , x, y);     bool bo = false;     for (int i = p[x]; i < p[x + 1]; i++)       if ((bb[a[i].second] == 0 || need_x) && a[i].second != y && h) {         h--;         if (bb[a[i].second]) {           bb[a[i].second] = -1;           need_x--;         }         if (bo) printf(   );         bo = true;         printf( %d , a[i].second);       }     printf(  n );     bo = false;     for (int i = p[y]; i < p[y + 1]; i++)       if ((bb[a[i].second] == 0 || need_y) && a[i].second != x && t &&           bb[a[i].second] != -1) {         t--;         if (bb[a[i].second]) need_y--;         if (bo) printf(   );         bo = true;         printf( %d , a[i].second);       }     printf(  n );   }   int find(int x, int y) {     int ans = 0;     for (int i = p[x]; i < p[x + 1]; i++)       if (a[i].second != y) {         int t =             lower_bound(a + p[y], a + p[y + 1], make_pair(y, a[i].second)) - a;         if (a[t].second == a[i].second) ans++;       }     return ans;   }   int main() {     scanf( %d%d%d%d , &n, &m, &h, &t);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &a[i].first, &a[i].second);       degree[a[i].first]++;       degree[a[i].second]++;       a[i + m].second = a[i].first;       a[i + m].first = a[i].second;     }     int M = m * 2;     sort(a + 1, a + M + 1);     a[0].first = 0;     a[M + 1].first = n + 1;     int now = 0;     for (int i = 1; i <= M + 1; i++)       while (now != a[i].first) {         now++;         p[now] = i;       }     p[0] = 0;     for (int i = 1; i <= M; i++)       if (degree[a[i].first] > h && degree[a[i].second] > t) {         int t1 = a[i].first;         int t2 = a[i].second;         int tot = 0;         if (t1 < t2)           tot = find(t1, t2);         else           tot = find(t2, t1);         if (degree[t1] + degree[t2] - 2 - tot >= h + t) {           make_ans(t1, t2, tot);           return 0;         }       }     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int v[100000 + 1];   int mx, rez;   pair<int, int> rz[100000 + 1];   int stkLen;   int stkLen2;   int stk[100000 + 1];   int stk2[100000 + 1];   int s, s2;   void readFile() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie();     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> v[i];   }   int cautBin(int nr, int stk[], int stkLen) {     int i = 0;     int pas = 1 << 16;     while (pas != 0) {       if (i + pas <= stkLen && abs(v[stk[i + pas]] - nr) > k) i += pas;       pas >>= 1;     }     return stk[i] + 1;   }   bool verif(int st, int dr) {     while (s < stkLen && stk[s] < st) s++;     while (s2 < stkLen2 && stk2[s2] < st) s2++;     return (abs(v[stk[s]] - v[stk2[s2]]) <= k);   }   void solve() {     stkLen = 0;     int st = 1;     s = s2 = 1;     for (int i = 1; i <= n; i++) {       while (stkLen >= s && v[i] >= v[stk[stkLen]]) stkLen--;       stk[++stkLen] = i;       while (stkLen2 >= s2 && v[i] <= v[stk2[stkLen2]]) stkLen2--;       stk2[++stkLen2] = i;       while (st < i && verif(st, i) == 0) st++;       int len = i - st + 1;       if (len > mx) {         mx = len;         rez = 0;       }       if (len == mx) rz[++rez] = {st, i};     }   }   void printFile() {     cout << mx <<     << rez <<   n ;     for (int i = 1; i <= rez; i++)       cout << rz[i].first <<     << rz[i].second <<   n ;   }   int main() {     readFile();     solve();     printFile();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ar[200010];   void solve() {     long long a, b, c = 0, i, j, t, k, lie, m, n, o, x, y, z;     long long p = 0, sm = 0, cnt = 0;     scanf( %lld , &n);     string s;     cin >> s;     if (n == 1) {       printf( Yes n );       return;     }     for (i = 0; i < n; i++) ar[s[i] -  a ]++;     for (i = 0; i < 26; i++) {       if (ar[i] > 1) {         printf( Yes n );         return;       }     }     printf( No n );   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const int inf = 1e9;   int t, n, k;   char s[N];   int cnt[N];   int a[N], b[N];   int main() {     ios::sync_with_stdio(false);     cin >> t;     while (t--) {       cin >> n >> k;       cin >> s + 1;       for (int i = 1; i <= n; i++) {         cnt[i] = cnt[i - 1];         if (s[i] ==  1 ) cnt[i]++;       }       int ans = inf;       for (int i = 1; i <= k; i++) {         int ret = 0, mn = inf, tp = inf, l = 0;         vector<int> q;         q.push_back(0);         for (int j = i; j <= n; j += k) {           int tmp = cnt[j - 1] - cnt[l];           ret += tmp;           q.push_back(cnt[j] - cnt[j - 1]);           l = j;         }         ret += cnt[n] - cnt[l];         int sz = q.size() - 1;         for (int i = 1; i <= sz; i++) {           a[i] = a[i - 1];           b[i] = b[i - 1];           if (q[i] == 1)             a[i]++;           else             b[i]++;         }         tp = a[sz];         for (int i = sz; i >= 1; i--) {           mn = min(mn, b[i] - a[i] + a[sz]);           tp = min(tp, a[i - 1] - b[i - 1] + mn);         }         ans = min(ans, ret + tp);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using std::string;   using std::vector;   namespace Template {   struct IN {     template <class T>     void fr(T& a) {       T s = 0;       int w = 1;       char ch = getchar();       while (ch <  0  || ch >  9 ) {         if (ch ==  - ) w = -1;         ch = getchar();       }       while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();       a = w * s;     }     template <class T>     T fr() {       T a;       fr(a);       return a;     }     IN& operator>>(long long& x) { return fr(x), *this; }     IN& operator>>(signed& x) { return fr(x), *this; }     IN& operator>>(unsigned& x) { return fr(x), *this; }     IN& operator>>(char& c) {       while (isspace(c = getchar()))         ;       return *this;     }     IN& operator>>(string& str) {       char ch;       while (isspace(ch = getchar()))         ;       str = ch;       while (!isspace(ch = getchar())) str += ch;       return *this;     }   } cin;   struct OUT {     char D[1 << 27], *A = D - 1;     ~OUT() { fwrite(D, 1, A - D + 1, stdout); }     template <class T>     void fw(T x) {       static char C[20];       static int f;       x < 0 ? * ++A =  - , x = -x : 0;       while (C[++f] = 48 + x % 10, x /= 10)         ;       while (*++A = C[f], --f)         ;     }     OUT& operator<<(char c) { return *++A = c, *this; }     OUT& operator<<(string str) {       int len = str.length();       for (int i = 0; i < len; i++) *++A = str[i];       return *this;     }     OUT& operator<<(long long x) { return fw(x), *this; }     OUT& operator<<(signed x) { return fw(x), *this; }     OUT& operator<<(unsigned x) { return fw(x), *this; }   } cout;   char endl =   n ;   int DEBUG = 0;   template <class T>   T sqr(T a) {     return a * a;   }   template <class T>   T abs(T a) {     return a < 0 ? -a : a;   }   template <class T>   T cmin(T a, T b) {     return a < b ? a : b;   }   template <class T>   T cmax(T a, T b) {     return a > b ? a : b;   }   template <class T>   void cswp(T& a, T& b) {     T t = a;     a = b;     b = t;   }   }  // namespace Template   using namespace Template;   const int N = 1e5;   int n, blo, tot = 0, fa[N + 10], len[N + 10], arr[N + 10];   vector<int> E[N + 10];   void adde(int u, int v) { E[u].push_back(v); }   void dfs(int u, int f) {     fa[u] = f, arr[++tot] = u;     for (int v : E[u])       if (v != f) dfs(v, u);   }   int calc(int k) {     int ret = 0;     for (int i = 1; i <= n; i++) len[i] = 1;     for (int i = n; i > 1; i--) {       int u = arr[i], f = fa[u];       if (len[f] != -1 && len[u] != -1) {         if (len[f] + len[u] >= k)           ret++, len[f] = -1;         else           len[f] = cmax(len[f], len[u] + 1);       }     }     return ret;   }   int main() {     cin >> n;     blo = sqrt(n * log2(n));     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       adde(u, v), adde(v, u);     }     dfs(1, 0), cout << n << endl;     for (int i = 2; i <= blo; i++) cout << calc(i) << endl;     for (int i = blo + 1; i <= n;) {       int f = calc(i), l = i, r = n, pos = 0;       while (l <= r) {         int mid = (l + r) >> 1;         if (calc(mid) == f)           l = mid + 1, pos = mid;         else           r = mid - 1;       }       for (; i <= pos; i++) cout << f << endl;     }     return 0;   }


#include <bits/stdc++.h>   template <typename T>   void MACRO_VAR_Scan(T& t) {     std::cin >> t;   }   template <typename First, typename... Rest>   void MACRO_VAR_Scan(First& first, Rest&... rest) {     std::cin >> first;     MACRO_VAR_Scan(rest...);   }   template <typename T>   void MACRO_VEC_ROW_Init(int n, T& t) {     t.resize(n);   }   template <typename First, typename... Rest>   void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) {     first.resize(n);     MACRO_VEC_ROW_Init(n, rest...);   }   template <typename T>   void MACRO_VEC_ROW_Scan(int p, T& t) {     std::cin >> t[p];   }   template <typename First, typename... Rest>   void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) {     std::cin >> first[p];     MACRO_VEC_ROW_Scan(p, rest...);   }   template <class T>   inline T CHMAX(T& a, const T b) {     return a = (a < b) ? b : a;   }   template <class T>   inline T CHMIN(T& a, const T b) {     return a = (a > b) ? b : a;   }   template <class T>   using V = std::vector<T>;   template <class T>   using VV = V<V<T>>;   template <typename S, typename T>   std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {     os <<  (  << p.first <<  ,   << p.second <<  ) ;     return os;   }   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using PAIR = std::pair<ll, ll>;   using PAIRLL = std::pair<ll, ll>;   constexpr ll INFINT = 1 << 30;   constexpr ll INFINT_LIM = (1LL << 31) - 1;   constexpr ll INFLL = 1LL << 60;   constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);   constexpr double EPS = 1e-6;   constexpr ll MOD = 1000000007;   constexpr double PI = 3.141592653589793238462643383279;   template <class T, size_t N>   void FILL(T (&a)[N], const T& val) {     for (auto& x : a) x = val;   }   template <class ARY, size_t N, size_t M, class T>   void FILL(ARY (&a)[N][M], const T& val) {     for (auto& b : a) FILL(b, val);   }   template <class T>   void FILL(std::vector<T>& a, const T& val) {     for (auto& x : a) x = val;   }   template <class ARY, class T>   void FILL(std::vector<std::vector<ARY>>& a, const T& val) {     for (auto& b : a) FILL(b, val);   }   struct Trie {     std::vector<std::vector<ll>> g;     ll p;     Trie() : p(0) {       g.emplace_back(std::vector<ll>(2, -1));       ++p;     }     void add(const std::string& s) {       size_t par = 0;       for (size_t i = 0; i < s.size(); ++i) {         ll t = s[i] -  0 ;         if (g[par][t] == -1) {           g.emplace_back(std::vector<ll>(2, -1));           g[par][t] = p++;         }         par = g[par][t];       }     }     ll next(size_t par, char c) {       ll t = c -  0 ;       return g[par][t];     }   };   bool ng(std::string s) {     return s ==  1100  || s ==  1010  || s ==  0111  || s ==  1111 ;   }   signed main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     ;     ll n;     MACRO_VAR_Scan(n);     ;     std::string s;     for (ll i = 0; i < ll(n); ++i) {       char c;       MACRO_VAR_Scan(c);       ;       s += c;     }     Trie tr;     std::vector<ll> c(n, 0);     for (ll i = 0; i < ll(n); ++i) {       auto S = s.substr(0, i + 1);       std::reverse((S).begin(), (S).end());       std::vector<ll> dp(S.size() + 1, 0);       dp[0] = 1;       for (ll j = 0; j < ll(S.size()); ++j) {         for (ll k = 0; k < ll(4); ++k) {           if (j < k) break;           if (k == 3) {             if (ng(S.substr(j - 3, 4))) continue;           }           (dp[j + 1] += dp[j - k]) %= MOD;         }       }       ll p = 0;       ll len = 0;       for (ll j = 0; j < ll(S.size()); ++j) {         ll ne = tr.next(p, S[j]);         if (ne == -1) break;         p = ne;         dp[++len] = 0;       }       tr.add(S);       for (ll j = (1); j < (S.size() + 1); ++j) {         (c[i] += dp[j]) %= MOD;       }     }     for (ll i = 0; i < ll(n - 1); ++i) (c[i + 1] += c[i]) %= MOD;     for (ll i = 0; i < ll(n); ++i) {       std::cout << (c[i]);       std::cout <<   n ;       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B, typename C>   struct triple {     A X;     B Y;     C Z;     triple(A a = 0, B b = 0, C c = 0) : X(a), Y(b), Z(c) {}   };   template <typename A, typename B, typename C>   triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) {     return triple<A, B, C>(a, b, c);   }   template <typename A, typename B, typename C>   bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b) {     if (a.X != b.X) return a.X < b.X;     if (a.Y != b.Y) return a.Y < b.Y;     return a.Z < b.Z;   }   template <typename T, typename SS>   ostream& operator<<(ostream& ofs, const pair<T, SS>& p) {     ofs <<  (   << p.first <<   ,   << p.second <<   ) ;     return ofs;   }   template <typename T>   void print(T a) {     for (auto i : a) cout << i <<    ;     cout <<   n ;   }   template <typename T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   template <typename T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <typename T, typename D>   D min(T a) {     return *min_element(a.begin(), a.end());   }   template <typename T, typename D>   D max(T a) {     return *max_element(a.begin(), a.end());   }   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 solve() {     string s;     cin >> s;     if ((long long)(s.size()) & 1) s =  0  + s;     long long n = (long long)(s.size());     for (long long i = 0; i < (n); i++) s[i] -=  0 ;     reverse(s.begin(), s.end());     vector<vector<long long> > dp(n / 2 + 1, vector<long long>(4));     dp[0][0] = 1;     for (long long i = 0; i < (n / 2); i++)       for (long long j = 0; j < (4); j++) {         long long x = 2 * i, y = x + 1;         long long dx = j & 1, dy = j >> 1;         for (long long d11 = 0; d11 < (10); d11++)           for (long long d12 = 0; d12 < (10); d12++) {             long long sx = d11 + d12 + dx;             if (sx % 10 != s[x]) continue;             long long nmask = (sx >= 10);             for (long long d21 = 0; d21 < (10); d21++)               for (long long d22 = 0; d22 < (10); d22++) {                 long long sy = d21 + d22 + dy;                 if (sy % 10 != s[y]) continue;                 if (sy >= 10) nmask |= 2;                 dp[i + 1][nmask] += dp[i][j];               }           }       }     cout << dp[n / 2][0] - 2 <<   n ;   };   signed main() {     if (0) {       freopen(            a             .in ,            r , stdin);       freopen(            a             .out ,            w , stdout);     }     srand(time(NULL));     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     long long t = 1;     cin >> t;     for (long long _ = 0; _ < (t); _++) solve();   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int MAXN = 200005;   int n, x[MAXN];   long long a[MAXN], t;   long long b[MAXN];   void solve() {     for (int i = 0; i + 1 < n; i++) {       if (x[i] > x[i + 1]) {         cout <<  No  << endl;         return;       }     }     for (int i = 0; i < n; i++) {       if (i > x[i]) {         cout <<  No  << endl;         return;       }     }     for (int i = 0; i < n;) {       int pos = x[i];       int j = i;       while (j < n && x[j] == pos) {         j++;       }       if (j < x[i] + 1) {         cout <<  No  << endl;         return;       }       long long num = a[j - 1];       for (int k = i; k + 1 < j; k++) {         b[k] = a[k + 1] + t;       }       b[j - 1] = a[j - 1] + t + (j - i > 1);       if (j < n && b[j - 1] >= a[j] + t) {         cout <<  No  << endl;         return;       }       i = j;     }     cout <<  Yes  << endl;     for (int i = 0; i < n; i++) {       cout << b[i] <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     while (cin >> n >> t) {       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < n; i++) {         cin >> x[i];         x[i]--;       }       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int N, Q, C, Rt, L[200005], R[200005], G[200005], F[200005], ch[200005][2];   struct Nod {     int Now, Max, Min, Laz;     Nod() {       Min = 1 << 30;       Max = -Min;     }   } T[200005];   vector<int> son[200005];   void Upd(int x, int k) {     if (x) T[x].Now += k, T[x].Max += k, T[x].Min += k, T[x].Laz += k;   }   void Up(int x) {     int l = ch[x][0], r = ch[x][1];     T[x].Max = max(T[x].Now, max(T[l].Max, T[r].Max));     T[x].Min = min(T[x].Now, min(T[l].Min, T[r].Min));   }   void Dn(int x) {     int k = T[x].Laz;     if (k) Upd(ch[x][0], k), Upd(ch[x][1], k), T[x].Laz = 0;   }   void Rot(int x) {     int y = F[x], z = F[y], k = ch[y][0] == x, t;     if (t = ch[y][!k] = ch[x][k]) F[t] = y;     if (F[x] = z) ch[z][ch[z][1] == y] = x;     ch[F[y] = x][k] = y;     Up(y);   }   void Splay(int x, int Aim) {     for (Dn(x); F[x] ^ Aim; Rot(x)) {       int y = F[x], z = F[y];       Dn(z);       Dn(y);       Dn(x);       if (F[y] ^ Aim) (ch[z][0] == y ^ ch[y][0] == x) ? Rot(x) : Rot(y);     }     Up(x);     if (!Aim) Rt = x;   }   void DFS(int u, int d) {     L[u] = ++C;     G[C] = u;     T[C].Now = d;     for (int i = 1, lim = son[u].size(); i <= lim; i++) DFS(son[u][i - 1], d + 1);     R[u] = ++C;     G[C] = u;     T[C].Now = d;   }   void Build(int& u, int l, int r, int fa) {     F[u = l + r >> 1] = fa;     if (l < u) Build(ch[u][0], l, u - 1, u);     if (u < r) Build(ch[u][1], u + 1, r, u);     Up(u);   }   int Find(int x, int k) {     int l = ch[x][0], r = ch[x][1];     Dn(x);     if (T[r].Min <= k && k <= T[r].Max) return Find(r, k);     return T[x].Now == k ? x : Find(l, k);   }   int Pre(int x) {     Splay(x, 0);     x = ch[x][0];     for (; ch[x][1]; x = ch[x][1]) Dn(x);     return x;   }   int Suf(int x) {     Splay(x, 0);     x = ch[x][1];     for (; ch[x][0]; x = ch[x][0]) Dn(x);     return x;   }   void Get(int x, int y) {     Splay(x, 0);     Splay(y, x);   }   int main() {     scanf( %d%d , &N, &Q);     for (int i = 1, lim = N; i <= lim; i++) {       int x, t;       scanf( %d , &x);       for (; x--;) scanf( %d , &t), son[i].push_back(t);     }     C++;     DFS(1, 1);     C++;     Build(Rt, 1, C, 0);     for (int k, x, y, z, l, r, w, t; Q--;) {       scanf( %d , &k);       if (k == 1) {         scanf( %d%d , &x, &y);         if (x == y)           puts( 0 );         else {           x = L[x];           y = L[y];           Get(x, y);           z = (ch[x][0] == y ? T[ch[y][1]] : T[ch[y][0]]).Min;           printf( %d n ,                  T[x].Now + T[y].Now - 2 * min(z - 1, min(T[x].Now, T[y].Now)));         }       } else if (k == 2) {         scanf( %d%d , &x, &y);         Get(1, L[x]);         w = G[Find(ch[L[x]][0], T[L[x]].Now - y)];         l = Pre(L[x]);         r = Suf(R[x]);         Get(l, r);         t = ch[r][0];         ch[r][0] = 0;         Up(r);         Up(l);         r = R[w];         l = Pre(r);         Get(l, r);         ch[r][0] = t;         F[t] = r;         Upd(t, -y + 1);         Splay(t, 0);       } else         scanf( %d , &x), printf( %d n , G[Find(Rt, x + 1)]);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 112, INF = 1e18;   long long t, n, m, a[N];   long long B10(string s) {     reverse(s.begin(), s.end());     long long ret = 0;     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) ret += (1ll << i);     }     return ret;   }   string B2(long long a) {     string ret;     for (long long i = 0; i < m; i++) {       if (a & (1ll << i))         ret +=  1 ;       else         ret +=  0 ;     }     reverse(ret.begin(), ret.end());     return ret;   }   long long BS() {     long long low = 0, high = (1ll << m);     while (high - low > 1) {       long long mid = (low + high) >> 1;       long long v1 = mid - (lower_bound(a, a + n, mid) - a);       long long v2 = ((1ll << m) - n - 1) / 2;       if (v1 <= v2)         low = mid;       else         high = mid;     }     return low;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n >> m;       for (long long i = 0; i < n; i++) {         string s;         cin >> s;         a[i] = B10(s);       }       sort(a, a + n);       cout << B2(BS()) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[100100];   int main() {     int n, a, b, t, cn = 1;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       p[i] = a;     }     sort(p, p + n);     int ans = 0;     vector<int> v;     for (int i = 0; i < n; i++) {       int j = 0;       for (j = 0; j < v.size(); j++) {         if (p[i] >= v[j]) {           v[j]++;           break;         }       }       if (j == v.size()) {         v.push_back(1);       }     }     cout << v.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buf[25];   struct node {     long long x, y;     bool operator<(node tp) const {       if (x != tp.x) return x < tp.x;       return y < tp.y;     }   };   map<long long, long long> h1, h2;   map<node, long long> t, q;   const long long inf = 1e17;   const long long maxn = 200010;   long long L1[maxn], R1[maxn], l1[maxn], r1[maxn], s1[maxn], a[maxn];   long long L2[maxn], R2[maxn], l2[maxn], r2[maxn], s2[maxn];   long long n, m, sum1, sum2;   long long ans;   long long read() {     long long x = 0, f = 0;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = 1;     } while (ch <  0  || ch >  9 );     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return f ? -x : x;   }   void write(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (!x) {       putchar( 0 );       return;     }     long long cnt = 0;     while (x) {       buf[++cnt] =  0  + x % 10;       x /= 10;     }     for (long long i = cnt; i >= 1; --i) putchar(buf[i]);   }   signed main() {     srand(19267180);     n = read();     m = read();     for (long long i = 1; i <= n; ++i) {       h1[i] = (1ll * rand() * rand() * rand() * rand() % inf + inf) % inf;       h2[i] = (1ll * rand() * rand() * rand() * rand() % inf + inf) % inf;       sum1 = h1[i] ^ sum1;       sum2 = h2[i] ^ sum2;     }     for (long long i = 1; i <= n; ++i) {       long long l = read(), r = read();       ++a[l];       --a[r + 1];       s1[l] ^= h1[i];       s1[r + 1] ^= h1[i];       L1[l - 1] ^= h1[i];       R1[r + 1] ^= h1[i];       s2[l] ^= h2[i];       s2[r + 1] ^= h2[i];       L2[l - 1] ^= h2[i];       R2[r + 1] ^= h2[i];     }     for (long long i = m - 1; i >= 1; --i) L1[i] ^= L1[i + 1], L2[i] ^= L2[i + 1];     for (long long i = 2; i <= m; ++i) {       R1[i] ^= R1[i - 1], s1[i] ^= s1[i - 1];       R2[i] ^= R2[i - 1], s2[i] ^= s2[i - 1];     }     for (long long i = 2; i <= m; ++i) s1[i] ^= s1[i - 1], s2[i] ^= s2[i - 1];     for (long long i = 1; i <= m; ++i) {       l1[i] = s1[i - 1] ^ R1[i], r1[i] = s1[i] ^ L1[i];       l2[i] = s2[i - 1] ^ R2[i], r2[i] = s2[i] ^ L2[i];     }     for (long long i = m; i >= 1; --i) {       t[(node){r1[i], r2[i]}] += 1;       q[(node){r1[i], r2[i]}] += i;       long long x_1 = sum1 ^ l1[i], x_2 = sum2 ^ l2[i];       ans += q[(node){x_1, x_2}] - 1ll * t[(node){x_1, x_2}] * (i - 1);     }     for (long long i = 1; i <= m; ++i) a[i] += a[i - 1];     long long x = 0;     for (long long i = 1; i <= m; ++i) {       if (a[i] == 0)         ++x;       else         x = 0;       if (x)         if (i == m || a[i + 1] != 0)           for (long long j = 1; j <= x; ++j) ans -= 1ll * j * (x - j + 1);     }     write(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void RI() {}   template <typename... T>   void RI(int& head, T&... tail) {     scanf( %d , &head);     RI(tail...);   }   template <typename T>   void _dump(const char* s, T&& head) {     cerr << s <<  =  << head << endl;   }   template <typename T, typename... Args>   void _dump(const char* s, T&& head, Args&&... tail) {     int c = 0;     while (*s !=  ,  || c != 0) {       if (*s ==  (  || *s ==  [  || *s ==  { ) c++;       if (*s ==  )  || *s ==  ]  || *s ==  } ) c--;       cerr << *s++;     }     cerr <<  =  << head <<  ,  ;     _dump(s + 1, tail...);   }   template <typename Iter>   ostream& _out(ostream& s, Iter b, Iter e) {     s <<  [ ;     for (auto it = b; it != e; it++) s << (it == b ?    :    ) << *it;     s <<  ] ;     return s;   }   template <typename A, typename B>   ostream& operator<<(ostream& s, const pair<A, B>& p) {     return s <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& s, const vector<T>& c) {     return _out(s, begin(c), end(c));   }   template <typename T>   ostream& operator<<(ostream& s, const set<T>& c) {     return _out(s, begin(c), end(c));   }   template <typename A, typename B>   ostream& operator<<(ostream& s, const map<A, B>& c) {     return _out(s, begin(c), end(c));   }   vector<int> app[1000010];   int ask(int l, int r, int v) {     auto it = lower_bound(begin(app[v]), end(app[v]), l);     auto jt = upper_bound(begin(app[v]), end(app[v]), r);     return jt - it;   }   int n, m, a[300010], sa[300010], ord[300010], l[300010], r[300010];   bool vis[300010];   bool cmp(int x, int y) { return a[x] < a[y]; }   long long calc(int l1, int r1, int l2, int r2, int mx) {     long long ans = 0;     mx %= m;     if (r1 - l1 <= r2 - l2) {       for (int i = (l1 - 1); i <= int(r1 - 1); i++) {         int x = sa[i] + mx;         if (x >= m) x -= m;         int now = ask(l2, r2, x);         ans += now;       }     } else {       for (int i = (l2); i <= int(r2); i++) {         int x = sa[i] - mx;         if (x < 0) x += m;         int now = ask(l1 - 1, r1 - 1, x);         ans += now;       }     }     return ans;   }   int main() {     RI(n, m);     for (int i = (1); i <= int(n); i++) RI(a[i]);     for (int i = (1); i <= int(n); i++) l[i] = r[i] = i;     for (int i = (1); i <= int(n); i++) ord[i] = i;     for (int i = (1); i <= int(n); i++) sa[i] = (sa[i - 1] + a[i]) % m;     for (int i = (0); i <= int(n); i++) app[sa[i]].push_back(i);     sort(ord + 1, ord + n + 1, cmp);     long long ans = 0;     for (int ii = (1); ii <= int(n); ii++) {       int i = ord[ii];       vis[i] = 1;       if (i > 1 && vis[i - 1]) {         ans += calc(l[i - 1], i - 1, i, i, a[i]);         l[i] = l[i - 1];         r[l[i - 1]] = i;       }       if (i < n && vis[i + 1]) {         ans += calc(l[i], i, i + 1, r[i + 1], a[i]);         r[l[i]] = r[i + 1];         l[r[i + 1]] = l[i];       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long a, b[100100], p[100100];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m >> a;     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= m; i++) cin >> p[i];     sort(b + 1, b + n + 1);     sort(p + 1, p + m + 1);     int le = -1, ri = min(n, m) + 1;     while (le + 1 < ri) {       int mi = (le + ri) / 2;       long long cnt = 0;       for (int i = 1; i <= mi; i++) {         cnt += max(0LL, p[mi + 1 - i] - b[n + 1 - i]);       }       if (cnt > a) {         ri = mi;       } else {         le = mi;       }     }     long long tot = 0;     for (int i = 1; i <= le; i++) tot += p[i];     cout << le <<     << max(tot - a, 0LL) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100000], outpalsz, inn, b[100000];   long long result;   int inicount[100001], iniodd;   int ccount[100001], codd;   int main() {     cin.sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n - 1 - i && a[i] == a[n - 1 - i]; i++) outpalsz++;     for (int i = outpalsz; i < n - outpalsz; i++) {       inicount[a[i]]++;       if (inicount[a[i]] % 2)         iniodd++;       else         iniodd--;       b[inn++] = a[i];     }     if (inn <= 1) {       cout << 1LL * n * (n + 1) / 2 <<   n ;       return 0;     }     if (iniodd <= 1) result = 1LL * (outpalsz + 1) * (outpalsz + 1);     for (int i = 0; i <= 100000; i++) ccount[i] = inicount[i];     codd = iniodd;     for (int i = 0; i < inn; i++) {       ccount[b[i]] -= 2;       if (i * 2 + 1 == inn) ccount[b[i]]++;       if (i > inn - 1 - i && b[i] == b[inn - 1 - i]) ccount[b[i]] += 2;       if (ccount[b[i]] < 0) break;       if (codd <= 1) result += outpalsz + 1;     }     for (int i = 0; i <= 100000; i++) ccount[i] = inicount[i];     codd = iniodd;     for (int i = inn - 1; i >= 0; i--) {       ccount[b[i]] -= 2;       if (i * 2 + 1 == inn) ccount[b[i]]++;       if (i < inn - 1 - i && b[i] == b[inn - 1 - i]) ccount[b[i]] += 2;       if (ccount[b[i]] < 0) break;       if (codd <= 1) result += outpalsz + 1;     }     cout << result <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long get(string a) {     long long len = a.length();     long long b = 0;     long long cnt = 1;     for (int i = len - 1; i >= 0; i--) {       b += ((a[i] -  0 ) % 2) * cnt;       cnt *= 2;     }     return b;   }   int p[262150];   int main() {     int t;     cin >> t;     while (t--) {       char c;       cin >> c;       string a;       cin >> a;       long long b = get(a);       switch (c) {         case  + : {           p[b]++;           break;         }         case  - : {           p[b]--;           break;         }         case  ? : {           cout << p[b] << endl;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return val < a ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   template <class T>   inline T isqrt(T k) {     T r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   template <class T>   inline T icbrt(T k) {     T r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   const int maxn = 2000 + 10;   const int maxm = 500000 + 10;   int n, m;   int a[maxm];   int b[maxm];   bitset<maxn << 1> mat[maxn];   void solve() {     cin >> n >> m;     for (int i = (0); i < (m); i++) {       cin >> a[i] >> b[i], a[i]--, b[i]--;       mat[b[i]][a[i]] = 1;     }     for (int i = (0); i < (n); i++)       for (int j = (0); j < (n); j++) mat[i][j + n] = i == j;     for (int i = (0); i < (n); i++) {       if (!mat[i][i]) {         for (int j = (i + 1); j < (n); j++)           if (mat[j][i]) {             mat[i] ^= mat[j];             break;           }       }       for (int j = (0); j < (n); j++) {         if (j == i) continue;         if (mat[j][i]) {           mat[j] ^= mat[i];         }       }     }     for (int i = (0); i < (m); i++) {       if (!mat[a[i]][b[i] + n]) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     int ans(0);     for (int i = 0; i < str.size(); ++i)       if (str[i] != str[str.size() - 1 - i]) ++ans;     if (ans == 2 || (ans == 0 && str.size() % 2 == 1))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int main() {     srand(1373737);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, t, k, d, q;     cin >> n >> q;     vector<int> arr(n);     for (int i = 0; i < (int)q; i++) {       cin >> t >> k >> d;       int free = 0;       for (int j = 0; j < (int)n; j++) {         if (arr[j] <= t) free++;       }       if (free < k) {         cout << -1 <<   n ;         continue;       }       int res = 0;       for (int j = 0; j < n && k; j++) {         if (arr[j] <= t) {           arr[j] = t + d;           k--;           res += j + 1;         }       }       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool uin(T& a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   inline bool uax(T& a, T b) {     return a < b ? (a = b, true) : false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long N, K;     cin >> N >> K;     if (K == 1) {       cout << N <<   n ;       return 0;     }     string be, en;     cin >> be >> en;     long long ans = 0, cur = 1;     for (int i = 0; i < N; ++i) {       cur *= 2LL;       if (be[i] ==  b ) --cur;       if (en[i] ==  a ) --cur;       uin(cur, K);       ans += cur;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   struct POINT {     int x, y;     POINT() : x(0), y(0) {}     POINT(int x, int y) : x(x), y(y) {}     POINT operator+(const POINT &t) const { return POINT(x + t.x, y + t.y); }     POINT operator-(const POINT &t) const { return POINT(x - t.x, y - t.y); }     POINT operator!() const { return POINT(-y, x); }   };   inline long long dot(const POINT &a, const POINT &b) {     return (long long)a.x * b.x + (long long)a.y * b.y;   }   inline long long cross(const POINT &a, const POINT &b) {     return (long long)a.x * b.y - (long long)a.y * b.x;   }   inline long long cross(const POINT &a, const POINT &b, const POINT &c) {     return cross(a - c, b - c);   }   inline bool halfPlane(const POINT &p) {     if (p.y == 0) return p.x < 0;     return p.y < 0;   }   inline bool angSortCmp(const POINT &a, const POINT &b) {     bool ha = halfPlane(a);     bool hb = halfPlane(b);     if (ha != hb) return ha < hb;     return cross(a, b) > 0;   }   const int N = 2000;   int n;   long long S;   POINT tab[N + 7];   int poz[N + 7];   POINT stab[N + 7];   struct kierunek {     POINT wek;     int p, q;   };   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> S;     S *= 2;     for (int i = 1; i <= n; ++i) cin >> tab[i].x >> tab[i].y;     sort(tab + 1, tab + n + 1, [](const POINT &a, const POINT &b) -> bool {       if (a.x == b.x) return a.y > b.y;       return a.x < b.x;     });     for (int i = 1; i <= n; ++i) {       poz[i] = i;       stab[i] = tab[i];     }     vector<kierunek> kol((n * (n - 1)) / 2);     int it = 0;     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         kol[it].wek = !(tab[j] - tab[i]);         kol[it].p = i;         kol[it].q = j;         it++;       }     }     sort(kol.begin(), kol.end(),          [](const kierunek &a, const kierunek &b) -> bool {            return angSortCmp(a.wek, b.wek);          });     for (kierunek u : kol) {       int p = u.p;       int q = u.q;       swap(stab[poz[p]], stab[poz[q]]);       swap(poz[p], poz[q]);       int l = 1;       int r = n;       while (l <= r) {         int s = (l + r) / 2;         long long ww = cross(tab[q], stab[s], tab[p]);         if (ww == S) {           cout <<  Yes  << endl;           cout << tab[p].x <<     << tab[p].y << endl;           cout << tab[q].x <<     << tab[q].y << endl;           cout << stab[s].x <<     << stab[s].y << endl;           exit(0);         }         if (ww > S)           r = s - 1;         else           l = s + 1;       }       l = 1;       r = n;       while (l <= r) {         int s = (l + r) / 2;         long long ww = cross(tab[q], stab[s], tab[p]);         if (ww == -S) {           cout <<  Yes  << endl;           cout << tab[p].x <<     << tab[p].y << endl;           cout << tab[q].x <<     << tab[q].y << endl;           cout << stab[s].x <<     << stab[s].y << endl;           exit(0);         }         if (ww > -S)           r = s - 1;         else           l = s + 1;       }     }     cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     int i, j, n, m, k, l, r;     cin >> n >> m;     int a[n][m];     pair<int, int> start_end[n][m];     for (i = 0; i < n; i += 1)       for (j = 0; j < m; j += 1) {         cin >> a[i][j];         start_end[i][j].first = i;         start_end[i][j].second = i;       }     for (j = 0; j < m; j += 1)       for (i = 1; i < n; i += 1)         if (a[i][j] >= a[i - 1][j])           start_end[i][j].first = start_end[i - 1][j].first;     int min_l[n];     for (i = 0; i < n; i++) min_l[i] = 100010;     for (i = 0; i < n; i += 1)       for (j = 0; j < m; j += 1)         if (start_end[i][j].first < min_l[i]) min_l[i] = start_end[i][j].first;     cin >> k;     while (k--) {       cin >> l >> r;       cout << ((min_l[r - 1] <= l - 1) ?  Yes n  :  No n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     long long fh = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= fh;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   long long n, a[100005];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       cin >> n;       for (long long i = 1; i <= n; i++) cin >> a[i];       long long x = 0;       for (long long i = n; i >= 1; i--)         if (a[i] < 0)           x += -a[i];         else if (x >= a[i])           x -= a[i];         else           x = 0;       cout << x << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, h;     cin >> n >> m >> h;     vector<int> ms(m), ns(n);     vector<vector<int> > ok(n, vector<int>(m));     for (int i = 0; i < m; i++) {       cin >> ms[i];     }     for (int i = 0; i < n; i++) {       cin >> ns[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> ok[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (ok[i][j] == 0) {           cout << 0 <<    ;         } else {           cout << min(ms[j], ns[i]) <<    ;         }       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int r, g, j, f[200001], sc, kq, mod = round(1e9) + 7;   long long i, h;   int main() {     cin >> r >> g;     f[0] = 1;     for (i = 1; i * (i + 1) / 2 <= r + g; i++) {       for (j = r; j >= 0; j--) {         if (j >= i) f[j] = (f[j] + f[j - i]) % mod;       }     }     h = i - 1;     for (i = 0; i <= r; i++)       if (h * (h + 1) / 2 - i <= g) kq = (kq + f[i]) % mod;     cout << kq;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   vector<pair<int, int> > s;   int co[maxn], deg[maxn];   int main() {     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       pair<int, int> q;       cin >> q.first >> q.second;       s.push_back(q);     }     for (int i = 1; i <= n; i++) {       cin >> co[i];     }     int x = 0;     for (auto i : s) {       if (co[i.first] != co[i.second]) {         deg[i.first]++;         deg[i.second]++;         x++;       }     }     int flag = 0;     for (int i = 1; i <= n; i++) {       if (deg[i] == x) {         flag = i;       }     }     if (flag) {       printf( YES n%d n , flag);     } else {       printf( NO n );     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k, kol = 0;     cin >> n >> k;     string s;     cin >> s;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       a[i] = s[i] -  0 ;     }     for (long long i = 0; i < n - 1 && k; i++) {       if (a[i] == 4 && a[i + 1] == 7) {         if (i % 2 == 0) {           a[i + 1] = 4;           k--;         } else {           if (i > 0 && a[i - 1] == 4) {             if (k % 2 == 1) {               a[i] = 7;             }             break;           }           a[i] = a[i + 1] = 7;           k--;         }       }     }     for (long long i = 0; i < n; i++) {       cout << a[i];     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int n, l;   long long a[300000][3];   long long b[300000][3];   long long t[300000][2];   vector<int> c[3000000];   vector<pair<long long, long long> > g;   long long p[3000000];   long long dab[3000000][2];   void sayno() {     printf( NO );     exit(0);   }   void calc() {     int i, j, k;     long long d = -1;     for (i = 0; i < l; i++) {       if (c[i].size() >= 2) {         d = (t[c[i][1]][1] - t[c[i][0]][1]) /             ((t[c[i][1]][0] - t[c[i][0]][0]) / l);         break;       }     }     if (d == -1) {       int past = 0;       g.clear();       for (i = 1; i <= l; i++) {         if (!c[i % l].size()) continue;         int x = c[past][0], y = c[i % l][0];         if (t[x][0] < t[y][0]) {           long long u = (t[y][0] - t[x][0]) / l;           long long v = t[y][1] - t[x][1];           long long w = (t[y][0] - t[x][0]) % l;           if (u != 0)             g.push_back(pair<long long, long long>((v - w + u - 1) / u, v / u));         } else {           long long u = (t[x][0] - t[y][0]) / l + 1;           long long v = t[x][1] - t[y][1];           long long w = t[y][0] + u * l - t[x][0];           if (u != 0)             g.push_back(pair<long long, long long>((v + u - 1) / u, (v + w) / u));         }         past = i;       }       sort(g.begin(), g.end());       for (auto e : g) {         if (e.second < g.back().first) sayno();       }       d = g.back().first;     }     memset(p, -1, sizeof(p));     for (i = 0; i < n; i++) {       long long u = t[i][1] - d * (t[i][0] / l);       long long v = t[i][0] % l;       if (p[v] == -1)         p[v] = u;       else if (p[v] != u)         sayno();     }     p[l] = d;     int past = 0;     for (i = 1; i <= l; i++) {       if (p[i] == -1) continue;       if (p[i] - p[past] < 0 || p[i] - p[past] > i - past) sayno();       for (j = 0; j < p[i] - p[past]; j++) {         dab[past + j][1] = 1;       }       for (j = p[i] - p[past]; j < i - past; j++) {         dab[past + j][1] = -1;       }       past = i;     }   }   int main() {     int i, j, k;     cin >> n >> l;     for (i = 0; i <= n; i++) {       if (i != 0) scanf( %I64d%I64d%I64d , &a[i][0], &a[i][1], &a[i][2]);       b[i][0] = a[i][0], b[i][1] = a[i][1] + a[i][2], b[i][2] = a[i][1] - a[i][2];       if ((b[i][1] + b[i][0]) % 2 == 1 || (b[i][2] + b[i][0]) % 2 == 1) sayno();       b[i][1] = (b[i][1] + b[i][0]) / 2, b[i][2] = (b[i][2] + b[i][0]) / 2;       c[b[i][0] % l].push_back(i);     }     n++;     for (i = 0; i < n; i++) t[i][0] = b[i][0], t[i][1] = b[i][1];     calc();     for (i = 0; i < l; i++) dab[i][0] = dab[i][1];     for (i = 0; i < n; i++) t[i][0] = b[i][0], t[i][1] = b[i][2];     calc();     for (i = 0; i < l; i++) {       if (dab[i][0] == -1 & dab[i][1] == -1)         printf( L );       else if (dab[i][0] == 1 && dab[i][1] == 1)         printf( R );       else if (dab[i][0] == -1 && dab[i][1] == 1)         printf( D );       else         printf( U );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<long long> > matmul(vector<vector<long long> > &a,                                     vector<vector<long long> > &b) {     int i, j, k, n = a.size();     vector<vector<long long> > ans(n, vector<long long>(n));     for (i = 0; i < n; i++)       for (j = 0; j < n; j++) {         long long temp = 0;         for (k = 0; k < n; k++)           temp = (temp + a[i][k] * b[k][j]) % (1000000007LL);         ans[i][j] = temp;       }     return ans;   }   vector<vector<long long> > matpwr(vector<vector<long long> > &a, long long p) {     int n = a.size();     vector<vector<long long> > ans(n, vector<long long>(n));     for (int i = 0; i < n; i++) ans[i][i] = 1;     while (p) {       if (p & 1) ans = matmul(ans, a);       a = matmul(a, a);       p >>= 1;     }     return ans;   }   long long pwr(long long base, long long p, long long mod = (1000000007LL)) {     long long ans = 1;     while (p) {       if (p & 1) ans = (ans * base) % mod;       base = (base * base) % mod;       p /= 2;     }     return ans;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long invMod(long long n, long long mod = (1000000007LL)) {     return pwr(n, mod - 2);   }   int n, arr[2000003];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) arr[i] = i;     int start = 1;     for (int iter = 2; iter <= n; iter++) {       int last = arr[start];       for (int j = start + iter; j < start + n; j += iter) {         int temp = last;         last = arr[j];         arr[j] = temp;       }       arr[start + n] = last;       start++;     }     for (int i = start; i < start + n; i++) cout << arr[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[110], b[110], sum = 0;   pair<int, int> dp[110][11000], q = {-1, -1};   pair<int, int> Rec(int i, int W) {     if (i == n) {       if (W >= sum)         return {0, 0};       else         return {1e9, 1e9};     }     if (dp[i][W] != q) return dp[i][W];     pair<int, int> Res1 = {1e9, 1e9}, Res2 = {1e9, 1e9};     Res1 = {0 + Rec(i + 1, W).first, a[i] + Rec(i + 1, W).second};     Res2 = {1 + Rec(i + 1, W + b[i]).first, 0 + Rec(i + 1, W + b[i]).second};     return dp[i][W] = min(Res1, Res2);   }   int main() {     memset(dp, -1, sizeof(dp));     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];     for (int i = 0; i < n; i++) cin >> b[i];     cout << Rec(0, 0).first <<     << Rec(0, 0).second;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200005];   int n;   int mem[200005][27];   int dirr[200005][27];   bool vis[200005][27];   char other(char c, char d) {     if ( a  != c &&  a  != d) return  a ;     if ( b  != c &&  b  != d) return  b ;     return  c ;   }   int solve(int ind, int lst) {     if (ind >= n) return 0;     if (vis[ind][lst]) return mem[ind][lst];     vis[ind][lst] = 1;     int ans1 = -1, ans2 = -1, ans = -1, dir = -1;     if (s[ind] -  a  != lst) ans1 = solve(ind + 1, s[ind] -  a );     ans2 = 1 + solve(ind + 1, other(s[ind + 1], lst +  a ) -  a );     if (ans1 == -1 || ans2 <= ans1)       dir = 1, ans = ans2;     else       dir = 0, ans = ans1;     dirr[ind][lst] = dir;     return mem[ind][lst] = ans;   }   int main() {     ios::sync_with_stdio(false);     scanf( %s , s);     n = strlen(s);     solve(0, 26);     int lst = 26;     for (int i = 0; i < n; i++)       if (dirr[i][lst] == 0)         lst = s[i] -  a ;       else         s[i] = lst = other(s[i + 1], lst +  a ), lst -=  a ;     puts(s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, t1, t2;   vector<int> q1, q2;   vector<vector<int> > Visted;   int des(int point1, int point2, int point3, int point4) {     return abs(point1 - point3) + abs(point2 - point4);   }   int main() {     cin >> n >> m >> t1;     Visted.resize(n + 10, vector<int>(m + 10));     q1.resize(t1);     for (int i = 0; i < t1; i++) cin >> q1[i];     cin >> t2;     q2.resize(t2);     for (int i = 0; i < t2; i++) cin >> q2[i];     sort(q1.begin(), q1.end());     sort(q2.begin(), q2.end());     for (int i = 0; i < t1; i++) {       bool take = false;       int desEnd = -1e9, X, Y;       for (int j = 1; j <= n; j++) {         for (int z = 1; z <= m; z++) {           if (!Visted[j][z] && des(0, 0, j, z) <= q1[i] &&               des(0, m + 1, j, z) > desEnd) {             desEnd = des(0, m + 1, j, z);             take = true;             X = j, Y = z;           }         }       }       if (take) {         Visted[X][Y] = 1;       } else {         cout <<  NO ;         return 0;       }     }     for (int i = 0; i < t2; i++) {       bool take = false;       int desEnd = 1e9, X, Y;       for (int j = 1; j <= n; j++) {         for (int z = 1; z <= m; z++) {           if (!Visted[j][z] && des(0, m + 1, j, z) <= q2[i] &&               des(0, m + 1, j, z) < desEnd) {             take = true;             X = j, Y = z;           }         }       }       if (take) {         Visted[X][Y] = 1;       } else {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class TH>   void _dbg(const char *sdbg, TH h) {     cerr << sdbg <<  =  << h << endl;   }   template <class TH, class... TA>   void _dbg(const char *sdbg, TH h, TA... a) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, a...);   }   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [ ;     for (auto vv : V) os << vv <<  , ;     return os <<  ] ;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class T>   using min_heap = priority_queue<T, vector<T>, greater<T>>;   template <class T>   using max_heap = priority_queue<T>;   const int mod = 1e9 + 7;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   struct PairHash {     template <typename T1, typename T2>     std::size_t operator()(const pair<T1, T2> &p) const {       return hash<T1>()(p.first) ^ hash<T2>()(p.second);     }   };   void solve(int ncase) {     int a, b, c, d;     cin >> a >> b >> c >> d;     int minx = min({a, b, c});     a -= minx;     b -= minx;     c -= minx;     cout << (((a % 2 + b % 2 + c % 2 + (d + 3 * 1LL * minx) % 2) <= 1) ||                      (minx >= 1 && ((a + 1) % 2 + (b + 1) % 2 + (c + 1) % 2 +                                     (d + 3 * 1LL * minx - 3) % 2) <= 1)                  ?  Yes                   :  No )          << endl;   }   void solve_all_cases() {     int T = 1;     cin >> T;     int ncase = 0;     while (T--) {       solve(++ncase);     }   }   int main() {     cout << std::fixed;     cout << setprecision(6);     solve_all_cases();   }


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


#include <bits/stdc++.h>   using namespace std;   int j, i, a, b, c, k, d, e, f[1005], n, mi, ma;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> f[i];       ma = max(f[i], ma);     }     for (i = 0; i < n - 1; i++)       for (j = i + 1; j < n; j++) {         c = 0;         for (k = i; k <= j; k++) c = f[k] ^ c;         ma = max(ma, c);       }     cout << ma;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target(         avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   long long MOD = 1e9 + 7;   long long k;   vector<long long> v, w, num;   vector<pair<long long, pair<long long, long long> > > zp;   vector<vector<long long> > dp;   long long st(long long t, long long id, long long mod) {     long long res = 1, a = t, n = id;     while (n) {       if (n & 1) res = (res * a) % mod;       a = (a * a) % mod;       n >>= 1;     }     return res % mod;   }   void add(long long id) {     vector<long long> mem(k + 1);     dp.push_back(mem);     long long lst = dp.size() - 1;     for (int i = 0; i < k + 1; i++) {       dp[lst][i] = dp[lst - 1][i];       if (i >= w[id])         dp[lst][i] = max(dp[lst - 1][i], dp[lst - 1][i - w[id]] + v[id]);     }   }   void del() { dp.pop_back(); }   long long ans() {     long long lst = dp.size() - 1;     long long anss = 0;     for (int i = 1; i < k + 1; i++) {       anss = ((10000019 * (long long)anss) + (long long)dp[lst][k - i + 1]) % MOD;       if (anss > MOD) anss -= MOD;     }     return anss;   }   void get(long long l, long long r) {     if (r == l + 1) {       if (zp[l].first == 3) {         zp[l].second.first = ans();       }       return;     }     long long mid = (l + r) / 2;     long long kol = 0;     for (int i = mid; i < r; i++) {       if (zp[i].first == 2) {         if (num[zp[i].second.second] < l) {           add(zp[i].second.second);           kol++;         }       }     }     get(l, mid);     while (kol--) del();     kol = 0;     for (int i = l; i < mid; i++) {       if (zp[i].first == 1) {         if (zp[i].second.second >= r) {           add(zp[i].second.first);           kol++;         }       }     }     get(mid, r);     while (kol--) del();   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),         cout << fixed << setprecision(20);     long long n;     cin >> n >> k;     v.resize(n), w.resize(n), num.resize(n);     vector<long long> mem(k + 1);     dp.push_back(mem);     for (int i = 0; i < n; i++) {       cin >> v[i] >> w[i];       zp.push_back({1, {i, MOD}});       num[i] = i;     }     long long q;     cin >> q;     while (q--) {       long long sz = zp.size();       zp.push_back({0, {num.size(), MOD}});       cin >> zp[zp.size() - 1].first;       if (zp.back().first == 1) {         long long vv, ww;         cin >> vv >> ww;         v.push_back(vv);         w.push_back(ww);         num.push_back(sz);       }       if (zp.back().first == 2) {         long long x;         cin >> x;         x--;         zp[num[x]].second.second = sz;         zp[sz].second.second = x;       }     }     get(0, zp.size());     for (auto i : zp) {       if (i.first == 3) {         cout << i.second.first << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long w = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) w = w * 10 + c - 48, c = getchar();     return w;   }   long long n, s[100005], e[100005];   bool f[100005][2];   bool check(long long x, long long y, long long op) {     if ((y & 1) && (!op)) return (y - x) & 1;     long long h = y >> 1;     if (x > h) return op ? 1 : (y - x) & 1;     return check(x, h, op ^ 1);   }   signed main() {     n = read();     for (long long i = 1; i <= n; i++)       s[i] = read(), e[i] = read(), f[i][0] = check(s[i], e[i], 0),       f[i][1] = check(s[i], e[i], 1);     bool need = f[n][0];     for (long long i = n - 1; i > 0; i--) need = f[i][need];     printf(need ?  1   :  0  );     need = f[n][1];     for (long long i = n - 1; i > 0; i--) need = f[i][need];     printf(need ?  1  :  0 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 16, Inf = 1e9, lastS = (1 << N) - 1;   static int n, sqrn, R, B, ans, lasts;   struct TCard {     bool c;     int r, b;   } card[N];   static int f[lastS][N * N + 1][2], cardr[lastS], cardb[lastS];   inline int GetF(int s, int rem, bool c) {     rem = min(rem, sqrn);     if (s == lasts) return 0;     auto &fs = f[s][rem][c];     if (fs != -1) return fs;     fs = Inf;     for (int i = 0; i < n; ++i) {       if (s & 1 << i) continue;       int R = max(0, card[i].r - cardr[s]), B = max(0, card[i].b - cardb[s]),           turn, _r, _b;       if (c) {         turn = max(R - rem, B);         _r = rem + turn - R;         _b = turn - B;       } else {         turn = max(B - rem, R);         _b = rem + turn - B;         _r = turn - R;       }       if (_r)         fs = min(fs, turn + GetF(s ^ 1 << i, _r, 1));       else         fs = min(fs, turn + GetF(s ^ 1 << i, _b, 0));     }     return fs;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     sqrn = n * n;     lasts = (1 << n) - 1;     for_each(card, card + n, [](TCard &C) {       char tmp;       cin >> tmp >> C.r >> C.b;       C.c = tmp ==  R ;       if (C.r > n) R += C.r - n, C.r = n;       if (C.b > n) B += C.b - n, C.b = n;     });     for (int s = 1; s <= lasts; ++s) {       int i = __builtin_ctz(s);       cardr[s] = cardr[s ^ 1 << i] + card[i].c;       cardb[s] = cardb[s ^ 1 << i] + !card[i].c;     }     memset(f, -1, sizeof f);     if (R > B)       ans = R + GetF(0, R - B, 0);     else       ans = B + GetF(0, B - R, 1);     cout << ans + n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename... Args>   void logger(string vars, Args&&... values) {}   template <typename T>   inline void maxa(T& a, T b) {     a = max(a, b);   }   template <typename T>   inline void mina(T& a, T b) {     a = min(a, b);   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int mxN = 2e5 + 5;   const int mod = 1e9 + 7;   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     vector<char> ans(n);     for (int& i : a) cin >> i;     string s;     cin >> s;     sort(a.begin(), a.end());     int cnt = 0;     for (int i = 1; i < n; i++) cnt += (s[i] != s[i - 1]);     int l = n - cnt - 1;     int r = n - cnt - 1;     cout << a[l] <<     << s[0] <<   n ;     ans[l] = s[0];     for (int i = 1; i < (int)(s.size()); i++) {       if (s[i] != s[i - 1]) {         ans[++r] = ans[r] ==  L  ?  R  :  L ;         cout << a[r] <<     << ans[r] <<   n ;       } else {         ans[--l] = ans[l] ==  L  ?  R  :  L ;         cout << a[l] <<     << ans[l] <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 + 100;   map<pair<long long, long long>, int> rat;   int n;   pair<long long, long long> px[maxn], py[maxn];   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     cin >> n;     for (int i = 1, a, b, c; i <= n; i++) {       cin >> a >> b >> c;       px[i] = make_pair(c * b, a * a + b * b);       py[i] = make_pair(a * c, a * a + b * b);     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       rat.clear();       long long two0 = 0;       for (int j = i + 1; j <= n; j++) {         long long a = px[j].first * px[i].second - px[j].second * px[i].first;         long long b = py[j].first * py[i].second - py[j].second * py[i].first;         long long g = gcd(abs(a), abs(b));         if (g != 0) a /= g, b /= g;         if (a == 0 && b == 0) {           two0++;           ans += j - i - 1;         } else {           if (a == 0) b = 1;           if (b == 0) a = 1;           if (a < 0 && b < 0) a *= -1, b *= -1;           if (a > 0 && b < 0) a *= -1, b *= -1;           ans += two0;           if (rat.count(make_pair(a, b))) {             ans += rat[make_pair(a, b)];             rat[make_pair(a, b)]++;           } else             rat[make_pair(a, b)] = 1;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 25;   int dp[MAXN][MAXN][MAXN];   int n, t;   int main() {     scanf( %d%d , &n, &t);     t = 2 * t;     dp[1][0][1] = dp[1][0][2] = dp[1][0][3] = 1;     for (int i = 1; i < n; ++i)       for (int j = 0; j <= t; ++j)         for (int k = 1; k <= 4; ++k)           for (int l = 1; l <= 4; ++l) {             if ((i == 1 && l > k) || (i != 1 && l != k)) {               int nj = j;               if (j % 2 && l < k)                 ++nj;               else if (j % 2 == 0 && l > k)                 ++nj;               dp[i + 1][nj][l] += dp[i][j][k];             }           }     int ans = 0;     for (int i = 1; i <= 4; ++i) ans += dp[n][t][i];     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     multiset<long long int> s;     map<string, int> mp;     while (t--) {       char ch;       long long int x;       cin >> ch >> x;       string str(18,  0 );       string temp = to_string(x);       int j = 17;       for (int i = ((int)(temp).size()) - 1; i >= 0; i--) {         if ((temp[i] -  0 ) % 2 != 0) {           str[j] =  1 ;         }         j--;       }       if (ch ==  + ) {         mp[str]++;       } else if (ch ==  - ) {         mp[str]--;       } else {         cout << mp[str] <<   n ;       }     }   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:666000000 )   using namespace std;   const int INF = (1 << 30) - 1;   const long double EPS = 1e-9;   const long double PI = fabs(atan2(0.0, -1.0));   int n;   void load() { cin >> n; }   const int SZ = 1010;   int sv[SZ];   int rec(const int v) {     if (v < SZ && -1 != sv[v]) return sv[v];     bool can[10];     int p9;     memset(can, false, sizeof(can));     {       int p = 0;       int tmp = v;       while (tmp != 0) {         can[tmp % 10] = true;         if (9 == tmp % 10) p9 = p;         tmp /= 10;         p *= 10;       }     }     if (v >= SZ) {       if (can[9] && p9 > 10) {         int cnt = 9 * (p9 / 10) - 8;         return cnt + rec(v - cnt * 9);       }       for (int i = 9; i >= 1; i--)         if (can[i]) return 1 + rec(v - i);     }     int res = INT_MAX;     for (int i = 1; i <= 9; i++)       if (can[i]) res = min(res, 1 + rec(v - i));     if (v < SZ) sv[v] = res;     return res;   }   void solve() {     memset(sv, -1, sizeof(sv));     sv[0] = 0;     int res = rec(n);     cout << res;   }   int main() {     load();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   map<int, int> dic;   int n, a[N + 10], ma[N + 10], ma2[N + 10];   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     ma[1] = a[1];     ma2[1] = -1;     for (int i = 2; i <= n; i++) {       if (a[i] > ma[i - 1]) {         ma2[i] = ma[i - 1];         ma[i] = a[i];       } else {         ma[i] = ma[i - 1];         if (ma2[i - 1] < a[i]) {           ma2[i] = a[i];         } else           ma2[i] = ma2[i - 1];       }       if (a[i] != ma[i] && a[i] == ma2[i]) {         dic[ma[i]]++;       }     }     int tot = -1e6, idx = -1;     for (int i = 1; i <= n; i++) {       int temp = dic[a[i]];       if (a[i] == ma[i]) temp--;       if (temp > tot) {         tot = temp;         idx = a[i];       } else if (temp == tot) {         idx = min(idx, a[i]);       }     }     cout << idx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[1000005] = {0};   long long b[1000005] = {0};   long long c[1000005] = {0};   long long d[1000005] = {0};   long long s;   long long i, j = 0, l;   long long count1 = 0;   long long count2 = 0;   long long count3 = 0;   long long count4 = 0;   long long ans = 0;   bool cmp(long long aa, long long bb) { return aa > bb; }   int main() {     long long n;     scanf( %lld n , &n);     for (i = 0; i < n; i++) {       cin >> s >> j;       if (s == 11) {         a[count1++] = j;         ans += j;       } else if (s == 10) {         b[count2++] = j;       } else if (s == 1) {         c[count3++] = j;       } else {         d[count4++] = j;       }     }     sort(b, b + count2, cmp);     sort(c, c + count3, cmp);     for (i = 0; i < min(count2, count3); i++) ans += (b[i] + c[i]);     for (i = 0; i < abs(count2 - count3); i++) {       if (count3 > count2)         d[count4 + i] = c[min(count2, count3) + i];       else if (count3 < count2)         d[count4 + i] = b[min(count2, count3) + i];     }     count4 += abs(count2 - count3);     sort(d, d + count4, cmp);     for (i = 0; i < count1 && i < count4; i++) ans += d[i];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, k;     cin >> n >> k;     long long int ans = 1;     while (k % 2 == 0) {       k = k / 2;       ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e4 + 10, mod = 1e9 + 7, M = 510;   const double PI = 3.1415926535;   long long res[40], p[40], ei[40], sum[N], cnt;   double pre[N];   int path[100];   void dfs(int u, int s, long long va) {     if (u == -1) {       sum[s] = ((long long)sum[s] + va) % mod;       return;     }     for (int i = 0; i <= cnt; i++) {       path[i]++;       if (res[i] - path[i] + 1)         dfs(u - 1, s + i, (long long)va * (res[i] - path[i] + 1) % mod);       path[i]--;     }   }   int main() {     int n;     scanf( %d , &n);     vector<int> temp;     int t = n;     while (t) t /= 10, cnt++;     p[1] = 1;     for (int i = 2; i <= 11; i++) p[i] = p[i - 1] * 10;     ei[0] = 1;     for (int i = 1; i < 11; i++) ei[i] = ei[i - 1] * 8;     for (int i = 0; i < (1 << cnt); i++) {       vector<int> temp;       for (int j = 0; j < cnt; j++)         if (i >> j & 1) temp.push_back(j);       int len = temp.size();       for (int j = 0; j < 1 << len; j++) {         int a[15] = {0};         for (int k = 0; k < len; k++)           if (j >> k & 1)             a[temp[k]] = 7;           else             a[temp[k]] = 4;         long long f = p[cnt], va = 0;         for (long long k = cnt - 1, r = 1; k >= 0; k--, r *= 10)           va += (long long)a[k] * r;         if (va > n) continue;         for (int k = 0; k < cnt; k++) {           if (a[k]) {             f /= 10;             continue;           }           for (int r = 9; r >= 0; r--)             if ((long long)r * f + va <= n) {               a[k] = r, va = r * f + va;               break;             }           f /= 10;         }         long long num = 0, ans = 0;         for (int k = 0; k < cnt; k++) {           if (num < temp.size() && temp[num] == k) {             num++;             if (k == cnt - 1) ans++;             continue;           }           if (a[k] == 7 || a[k] == 4) {             int sum = cnt - 1 - k;             int ts = temp.size() - num;             int tnum = a[k] + 1;             if (a[k] == 4)               tnum--;             else               tnum -= 2;             ans = ans + ei[sum - ts] * (long long)tnum;             break;           } else {             int sum = cnt - 1 - k;             int ts = temp.size() - num;             int tnum = a[k] + 1;             if (a[k] > 7)               tnum -= 3;             else if (a[k] > 4)               tnum -= 2;             else               tnum--;             if (k == cnt - 1) tnum++;             ans = ans + ei[sum - ts] * (long long)tnum;           }         }         res[len] = (res[len] + (long long)ans);       }     }     res[0]--;     dfs(5, 0, 1);     long long ans = 0, pre = 0;     for (int i = 1; i <= cnt; i++) {       pre = pre + sum[i - 1];       ans = (ans + pre * res[i]) % mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, good;   bool prime[100010];   vector<int> fact, num, lis;   int main() {     memset(prime, true, sizeof(prime));     for (int i = 2; i * i <= 100000; i++)       if (prime[i])         for (int j = 2; i * j <= 100000; j++) prime[i * j] = false;     for (int i = 2; i <= 100000; i++)       if (prime[i]) {         num.push_back(i);         lis.push_back(0);       }     scanf( %d , &N);     while (N--) {       scanf( %d , &good);       int temp = good;       fact.clear();       int longest = 0;       for (int i = 0; i < num.size() && num[i] * num[i] <= good; i++)         if (good % num[i] == 0) {           fact.push_back(i);           longest = max(longest, lis[i] + 1);           while (temp % num[i] == 0) temp /= num[i];         }       if (temp > 1) {         int i = lower_bound(num.begin(), num.end(), temp) - num.begin();         fact.push_back(i);         longest = max(longest, lis[i] + 1);       }       for (int i = 0; i < fact.size(); i++)         lis[fact[i]] = max(lis[fact[i]], longest);     }     int ans = 1;     for (int i = 0; i < num.size(); i++) ans = max(ans, lis[i]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2300;   int dp[N], a[N], res = 0, n;   void dfs(int u, int d) {     if (d == n) {       dp[u] = 0;       return;     }     int l = u * 2, r = l + 1;     dfs(l, d + 1);     dfs(r, d + 1);     int x = dp[l] + a[l], y = dp[r] + a[r];     if (x < y) swap(x, y);     dp[u] = x;     res += x - y;   }   int main() {     cin >> n;     for (int i = 2; i < (1 << n + 1); i++) {       scanf( %d , &a[i]);     }     dfs(1, 0);     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, root, val, rem;   int main() {     cin >> n;     root = floor((sqrt(1.0 + 8.0 * n) - 1.0) / 2.0);     val = root * (root + 1) / 2;     if (n == val) --root;     val = root * (root + 1) / 2;     rem = n - val;     cout << rem << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 2;   const long long M = 1e6 + 2;   const long long mod = 998244353;   long long ar[N], fact[M], inv[M], cnt[N];   long long binpow(long long x, long long y) {     long long tich = 1;     while (y) {       if (y & 1) {         tich *= x;         tich %= mod;       }       x *= x;       x %= mod;       y >>= 1;     }     return tich;   }   long long C(long long x, long long y) {     return ((fact[y] * inv[y - x]) % mod * inv[x]) % mod;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, i, j, k, l, ans = 0, sum = 0;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> ar[i];       cnt[ar[i] % n]++;       sum += ar[i];     }     fact[0] = 1;     for (i = 1; i < M - 1; i++) {       fact[i] = (fact[i - 1] * i) % mod;     }     inv[M - 2] = binpow(fact[M - 2], mod - 2);     for (i = M - 2; i > 0; i--) {       inv[i - 1] = (inv[i] * i) % mod;     }     sort(ar + 1, ar + 1 + n);     long long pos = 0;     for (i = 1; i < n; i++) {       if (ar[i + 1] < i) {         pos = i;         break;       }     }     if (pos) {       j = 1;       for (i = 0; i < pos; i++) {         while (ar[j] < i) {           j++;         }         ans += C(n - 1, i - (j - 1) + n - 1);         if (ans >= mod) {           ans -= mod;         }       }       cout << ans;     } else {       for (i = 1; i <= n; i++) {         sum -= ar[i] % n;       }       sum /= n;       for (i = 1; i <= n; i++) {         sum = sum + cnt[n - i] - 1;         if (sum >= 0) {           ans += C(n - 1, sum + n - 1);           if (ans >= mod) {             ans -= mod;           }         }       }       cout << ans;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, int>> v;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       v.push_back(make_pair(a, b));     }     int x1 = v[0].first;     int y1 = v[0].second;     vector<int> p1, p2;     for (int i = 1; i < m; i++) {       int a = v[i].first;       int b = v[i].second;       if (x1 != a && x1 != b) {         p1.push_back(i);       }       if (y1 != a && y1 != b) {         p2.push_back(i);       }     }     if (p1.size() == 0 || p2.size() == 0) {       cout <<  YES  << endl;       return 0;     }     x1 = v[p1[0]].first;     y1 = v[p1[0]].second;     int c1 = 0, c2 = 0, c3 = 0, c4 = 0;     for (int i = 1; i < p1.size(); i++) {       int a = v[p1[i]].first;       int b = v[p1[i]].second;       if (x1 != a && x1 != b) {         c1++;       }       if (y1 != a && y1 != b) {         c2++;       }     }     x1 = v[p2[0]].first;     y1 = v[p2[0]].second;     for (int i = 1; i < p2.size(); i++) {       int a = v[p2[i]].first;       int b = v[p2[i]].second;       if (x1 != a && x1 != b) {         c3++;       }       if (y1 != a && y1 != b) {         c4++;       }     }     if (c1 == 0 || c2 == 0) {       cout <<  YES  << endl;     } else if (c3 == 0 || c4 == 0) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool chmax(T &a, T b) {     return a < b ? (a = b, 1) : 0;   }   template <class T>   inline bool chmin(T &a, T b) {     return a > b ? (a = b, 1) : 0;   }   int main() {     int n, m;     cin >> n >> m;     map<int, vector<int>> obs;     int left = n;     while (m--) {       int x, y;       cin >> x >> y;       if (x == 1)         chmin(left, y - 1);       else         obs[x].emplace_back(y);     }     vector<pair<int, int>> segs = {{1, left}};     int prv = 1;     for (auto &p : obs) {       auto &v = p.second;       sort(begin(v), end(v));       if (p.first != prv + 1) {         segs.assign(1, {segs.begin()->first, n});       }       vector<pair<int, int>> segs2;       auto it = segs.begin();       int p_v = 0, sz_v = v.size();       int lst = -1;       while (it != segs.end() && p_v < sz_v) {         chmax(it->first, lst);         if (it->first > it->second) {           it++;           continue;         }         if (v[p_v] <= it->first) {           it->first += v[p_v++] == it->first;           continue;         }         segs2.emplace_back(it->first, v[p_v] - 1);         lst = v[p_v++] + 1;       }       if (p_v == sz_v) {         while (it != segs.end()) {           chmax(it->first, lst);           if (it->first <= it->second) break;           it++;         }         if (it != segs.end()) {           segs2.emplace_back(it->first, n);         }       }       if ((segs = segs2).empty()) return !(cout << -1 << endl);       prv = p.first;     }     if (prv < n) {       segs.assign(1, {segs.begin()->first, n});     }     cout << (segs.rbegin()->second == n ? (n - 1) * 2 : -1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       if (n > k)         cout << k << endl;       else {         int ne = (k - 1) / (n - 1);         cout << k + ne << endl;       }     }   }


#include <bits/stdc++.h>   int mat[110][110];   int main() {     int n, k, i, j;     scanf( %d %d , &n, &k);     if (n * n < k) {       printf( -1 n );       return 0;     }     for (i = 0; i < n; i++) {       for (j = i; j < n; j++) {         if (i == j) {           if (k > 0) {             k--;             mat[i][j] = 1;           } else             break;         } else {           if (k >= 2) {             mat[i][j] = 1;             mat[j][i] = 1;             k = k - 2;           } else if (k == 0)             break;         }       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         printf( %d  , mat[i][j]);       }       printf(  n );     }     return 0;   }