#include <bits/stdc++.h>   using namespace std;   struct Tree {     int ch[10];     int len;     int fail;   } T[100010];   int tot;   void insert(char* str, int len) {     int now = 0;     for (int i = 0; i < len; i++) {       if (!T[now].ch[str[i] -  0 ]) {         T[now].ch[str[i] -  0 ] = ++tot;         T[tot].len = i + 1;       }       now = T[now].ch[str[i] -  0 ];     }     return;   }   queue<int> q;   void bfs() {     for (int i = 0; i < 10; i++)       if (T[0].ch[i]) {         q.push(T[0].ch[i]);         T[T[0].ch[i]].fail = 0;       }     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < 10; i++)         if (T[u].ch[i]) {           T[T[u].ch[i]].fail = T[T[u].fail].ch[i];           q.push(T[u].ch[i]);         } else           T[u].ch[i] = T[T[u].fail].ch[i];     }     return;   }   int d, D;   int dp[61][60010][2][2];   void add(int& x, int y) {     x += y;     if (x >= 1000000007) x -= 1000000007;     return;   }   int solve(int* a) {     memset(dp, 0, sizeof(dp));     dp[d][0][0][0] = 1;     for (int i = d; i >= 1; i--)       for (int j = 0; j <= tot; j++)         for (int k = 0; k < 2; k++) {           for (int l = 0; l <= a[i]; l++) {             int v = T[j].ch[l];             int tk = k || (T[v].len >= D);             int o = (l < a[i]);             add(dp[i - 1][v][tk][o], dp[i][j][k][0]);           }           for (int l = 0; l <= 9; l++) {             int v = T[j].ch[l];             int tk = k || (T[v].len >= D);             add(dp[i - 1][v][tk][1], dp[i][j][k][1]);           }         }     int ans = 0;     for (int i = 0; i <= tot; i++) {       add(ans, dp[0][i][1][0]);       add(ans, dp[0][i][1][1]);     }     return ans;   }   char x[61], y[61], str[1010];   int tmp[61];   int main() {     scanf( %s , str);     scanf( %s , x + 1);     scanf( %s , y + 1);     int len = strlen(str);     d = strlen(x + 1);     D = d / 2;     for (int i = 0; i + D <= len; i++) insert(str + i, D);     bfs();     for (int i = 1; i <= d; i++) tmp[i] = x[d - i + 1] -  0 ;     tmp[1]--;     for (int i = 1; i <= d; i++)       if (tmp[i] < 0) {         tmp[i + 1]--;         tmp[i] += 10;       }     int ans1 = solve(tmp);     for (int i = 1; i <= d; i++) tmp[i] = y[d - i + 1] -  0 ;     int ans2 = solve(tmp);     printf( %d n , (ans2 - ans1 + 1000000007) % 1000000007);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void prepare() {     ios_base::sync_with_stdio(0);     cin.tie(0);     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   int main() {     long double d, l, v1, v2;     cin >> d >> l >> v1 >> v2;     long double ans = (l - d) / (v1 + v2);     cout << fixed << setprecision(10) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     T x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -f;       c = getchar();     }     while (isdigit(c)) {       x = (x << 3) + (x << 1) + (c - 48);       c = getchar();     }     return x * f;   }   const int inf = 1e9 + 1e7, MAXN = 2e5 + 1e1;   int a[MAXN], b[MAXN], q0[MAXN], q1[MAXN], n, ans, cnt, a0, a1, l0, r0, l1, r1;   void Solve() {     n = read<int>(), ans = cnt = a0 = a1 = l0 = r0 = l1 = r1 = 0;     for (int i = 1; i <= n; i++) scanf( %1d , &a[i]);     for (int i = 1; i <= n; i++) {       if (a[i]) {         if (a1)           --a1, ++a0, b[i] = q1[l1], q0[r0++] = q1[l1++];         else           ++ans, ++a0, b[i] = (++cnt), q0[r0++] = cnt;       } else {         if (a0)           --a0, ++a1, b[i] = q0[l0], q1[r1++] = q0[l0++];         else           ++ans, ++a1, b[i] = (++cnt), q1[r1++] = cnt;       }     }     printf( %d n , ans);     for (int i = 1; i <= n; i++) printf( %d  , b[i]);     printf(  n );     return;   }   int main(void) {     int t = read<int>();     while (t--) Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, a, b, c;   int main() {     cin >> t;     while (t--) {       cin >> a >> b >> c;       int res = 0;       if (c & 1) res = 3;       if (res) {         if (b & 1) res = 1;         if (a & 1)           res = 0;         else           res = 1;       } else {         if (b & 1) res = 2;         if (a & 1)           res = 1;         else           res = 0;       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T inline sqr(T x) {     return x * x;   }   template <class T>   inline void relaxMin(T &a, T b) {     a = min(a, b);   }   template <class T>   inline void relaxMax(T &a, T b) {     a = max(a, b);   }   template <class T>   inline T sign(T x) {     return x > 0 ? 1 : (x < 0 ? -1 : 0);   }   template <class T>   inline T myAbs(T a) {     return a > 0 ? a : -a;   }   template <class T>   T iteratorK(T a, int k) {     while (k--) a++;     return a;   }   void err(const char *fmt, ...) {}   void Assert(bool f, const char *fmt =   , ...) {     if (!f) {       va_list list;       va_start(list, fmt);       err(fmt, list);       exit(1);     }   }   unsigned R() { return (rand() << 15) + rand(); }   double start = clock();   void TimeStamp() {     fprintf(stderr,  time = %.2f n , (clock() - start) / CLOCKS_PER_SEC);     start = clock();   }   const int maxN = (int)1e5 + 10;   int n, a, d;   int main() {     scanf( %d%d%d , &n, &a, &d);     long double minT = 0;     for (int i = 0; i < (int)(n); i++) {       int t, v;       scanf( %d%d , &t, &v);       long double D, T, T0 = (long double)v / a;       if ((D = 0.5 * T0 * T0 * a) >= d)         T = sqrt((long double)2.0 * d / a);       else         T = T0 + (long double)(d - D) / v;       T += t;       minT = T = max(minT, T);       printf( %.20f n , (double)T);     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   const int INF = (int)1e9 + 7;   int parent[(int)1e5 + 2];   int deep[(int)1e5 + 2];   long long setSum[(int)1e5 + 2];   int a[(int)1e5 + 2];   inline void input() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void make_set(int v) {     parent[v] = v;     setSum[v] = a[v];     deep[v] = 0;   }   int find_set(int v) {     if (v == parent[v]) return v;     parent[v] = find_set(parent[v]);     return parent[v];   }   void union_sets(int a, int b) {     a = find_set(a);     b = find_set(b);     if (a != b) {       if (deep[a] < deep[b]) swap(a, b);       if (deep[a] = deep[b]) ++deep[a];       setSum[parent[a]] += setSum[parent[b]];       parent[b] = a;     }   }   int main() {     input();     int n;     cin >> n;     vector<int> p(n + 1);     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       cin >> p[i];     }     long long mxSum = 0;     vector<long long> ans = {0};     for (int i = n; i > 0; --i) {       make_set(p[i]);       if (find_set(p[i] - 1) != 0) {         union_sets(p[i], p[i] - 1);       }       if (find_set(p[i] + 1) != 0) {         union_sets(p[i], p[i] + 1);       }       mxSum = max(setSum[p[i]], mxSum);       ans.push_back(mxSum);     }     for (int i = n - 1; i >= 0; --i) {       cout << ans[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[100005];   long long int n, len, k;   class data {    public:     set<pair<long long int, long long int> > mx, mn;     long long int sum1, ksum;     data() { ksum = 0, sum1 = 0; }     void ins(long long int v, long long int index) {       sum1 += v;       ksum += v;       mx.insert(make_pair(v, index));       if (int((mx).size()) > k) {         pair<long long int, long long int> p = *(mx.begin());         mx.erase(p);         ksum -= p.first;         p.first = -p.first;         mn.insert(p);       }     }     void rem(long long int v, long long int index) {       sum1 -= v;       if (mx.count(make_pair(v, index))) {         ksum -= v;         mx.erase(make_pair(v, index));         if (int((mn).size()) > 0) {           pair<long long int, long long int> p = *(mn.begin());           mn.erase(p);           p.first = -p.first;           mx.insert(p);           ksum += p.first;         }       } else if (mn.count(make_pair(-v, index))) {         mn.erase(make_pair(-v, index));       }     }   };   data ap, an;   void ADD(long long int v, long long int index) {     if (v < 0)       an.ins(-v, index);     else       ap.ins(v, index);   }   void REMOVE(long long int v, long long int index) {     if (v < 0)       an.rem(-v, index);     else       ap.rem(v, index);   }   int main() {     long long int ans = 0;     cin >> n >> len;     for (long long int i = 0; i < n; i++) cin >> a[i];     cin >> k;     for (long long int i = 0; i < n; i++) {       ADD(a[i], i);       if (i >= len) REMOVE(a[i - len], i - len);       if (i >= len - 1)         ans = max(ans, max(ap.sum1 - an.sum1 + 2 * an.ksum,                            an.sum1 + 2 * ap.ksum - ap.sum1));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f[20];   vector<long long> lu;   void go(int x, int y, long long p) {     if (x == y) return;     lu.push_back(p * 10 + 4);     lu.push_back(p * 10 + 7);     go(x, y + 1, p * 10 + 4);     go(x, y + 1, p * 10 + 7);   }   bool ok(long long x) {     if (!x) return 0;     while (x) {       if (!(x % 10 == 4 || x % 10 == 7)) return 0;       x /= 10;     }     return 1;   }   void radix(long long k, vector<long long> &num) {     k--;     int len = num.size();     int aw, get;     for (get = 1, aw = len - 1; get < len; get++, aw--)       if (f[get] > k) break;     get--;     while (k) {       long long a = k / f[get];       k = k % f[get];       swap(num[aw], num[aw + a]);       sort(num.begin() + aw + 1, num.end());       aw++;       get--;     }   }   int main() {     go(13, 0, 0);     sort(lu.begin(), lu.end());     int p = lu.size();     f[0] = 1;     for (long long i = 1; i < 15; i++) f[i] = f[i - 1] * i;     long long n, k;     vector<long long> num;     while (cin >> n >> k) {       long long ans = 0;       if (n > 13) {         for (long long i = 12; i >= 0; i--) num.push_back(n - i);         for (int i = 0; i < p; i++) {           if (lu[i] <= n - 13) ans++;         }         radix(k, num);         for (long long i = 12, j = 0; i >= 0; i--, j++) {           if (ok(num[j]) && ok(n - i)) ans++;         }       } else if (f[n] >= k) {         for (int i = 0; i < n; i++) num.push_back(i + 1);         radix(k, num);         for (int i = 0; i < n; i++) {           if (ok(num[i]) && (ok(i + 1))) ans++;         }       }       if (n <= 13)         if (f[n] < k) ans = -1;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool cmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool cmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   template <typename L, typename R>   ostream &operator<<(ostream &out, pair<L, R> t) {     return out <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &out, vector<T> t) {     for (unsigned i = 0; i < t.size(); i++)       out << (  ( [!i]) << t[i] << ( ,) [i == t.size() - 1]);     return out;   }   const int NX = 101234;   int n, m, k, q;   int fa[NX], edge[NX][6], intree[NX][6], f[NX], g[NX];   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   int main() {     scanf( %d%d%d , &n, &k, &m);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       if (u > v) swap(u, v);       int width = v - u;       edge[u][width] = true;     }     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= k; i++) {       for (int j = 1; j <= n; j++) {         if (!edge[j][i]) continue;         int u = find(j), v = find(j + i);         if (u != v) {           fa[u] = v;           intree[j][i] = true;           ++f[i + j];           ++g[j];         }       }     }     for (int i = 1; i <= n; i++) {       f[i] += f[i - 1];       g[i] += g[i - 1];     }     int q;     scanf( %d , &q);     while (q--) {       int l, r;       scanf( %d%d , &l, &r);       int ans = r - l + 1 - (f[r] - g[l - 1]);       for (int i = l - 1; i + k > r; i--)         for (int j = k; i + j > r; j--) {           if (intree[i][j]) --ans;         }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long n = s.size(), i, j;     long long displaced_left[n], displaced_right[n], minimum = INT_MAX;     for (i = 0, j = s.size() - 1; i < n; i++, j--) {       if (i == 0) {         displaced_left[i] = 0, displaced_right[j] = 0;         continue;       }       if (s[i - 1] >=  a  && s[i - 1] <=  z )         displaced_left[i] = displaced_left[i - 1] + 1;       else         displaced_left[i] = displaced_left[i - 1];       if (s[j + 1] >=  A  && s[j + 1] <=  Z )         displaced_right[j] = 1 + displaced_right[j + 1];       else         displaced_right[j] = displaced_right[j + 1];     }     for (i = 0; i < n; i++)       minimum = min(minimum, displaced_left[i] + displaced_right[i]);     cout << minimum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ch;     cin >> n;     if (n == 0)       cout <<  O-|-OOOO n ;     else       while (n != 0) {         ch = n % 10;         string s;         switch (ch) {           case 0:             s =  O-|-OOOO ;             break;           case 1:             s =  O-|O-OOO ;             break;           case 2:             s =  O-|OO-OO ;             break;           case 3:             s =  O-|OOO-O ;             break;           case 4:             s =  O-|OOOO- ;             break;           case 5:             s =  -O|-OOOO ;             break;           case 6:             s =  -O|O-OOO ;             break;           case 7:             s =  -O|OO-OO ;             break;           case 8:             s =  -O|OOO-O ;             break;           case 9:             s =  -O|OOOO- ;             break;         }         cout << s <<   n ;         n /= 10;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, q, m;     cin >> n >> q >> m;     vector<int> b(n + 1), a(m + 1);     for (int i = 1; i <= n; i++) cin >> b[i];     int t[q], l[q], r[q];     for (int i = 0; i < q; i++) cin >> t[i] >> l[i] >> r[i];     for (int i = 1; i <= m; i++) {       cin >> a[i];     }     for (int i = 1; i <= m; i++) {       for (int j = q - 1; j >= 0; j--) {         if (l[j] > a[i] || r[j] < a[i]) continue;         if (t[j] & 1) {           if (a[i] == l[j]) {             a[i] = r[j];           } else {             --a[i];           }         } else {           a[i] = r[j] + l[j] - a[i];         }       }     }     for (int i = 1; i <= m; i++) {       cout << b[a[i]] <<    ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) {       solve();     }   }


#include <complex>   #include <queue>   #include <set>   #include <unordered_set>   #include <list>   #include <chrono>   #include <random>   #include <iostream>   #include <algorithm>   #include <cmath>   #include <string>   #include <vector>   #include <map>   #include <unordered_map>   #include <stack>   #include <iomanip>   #include <fstream>      using namespace std;      const int N = 200001;   int cntA[N], cntB[N], A[N], B[N];      int gcd(int a, int b)   {       if (b == 0) return a;       else return gcd(b, a % b);   }      int lcm(int a, int b)   {       return a * b / gcd(a, b);   }      bool isPrime(int n)   {       int d = 2;       while (d * d <= n && n % d) d++;       return n - 1 && d * d > n;   }      void localTest()   {       int a, b, k; cin >> a >> b >> k;       memset(A, 0, N);       memset(B, 0, N);       memset(cntA, 0, N);       memset(cntB, 0, N);       for (int i = 0; i < k; i++)       {           cin >> A[i];           cntA[A[i]]++;       }       for (int i = 0; i < k; i++)       {           cin >> B[i];           cntB[B[i]]++;       }          long long ans = 0;       for (int i = 0; i < k; i++) ans += k - cntA[A[i]] - cntB[B[i]] + 1;          cout << ans / 2 <<   n ;       //не недооценивай первую задачу, если она для первого и второго дивизионов       //внимательно читай условия       //всё будет хорошо   }      int main()   {       cin.tie(nullptr)->sync_with_stdio(false);       int globalTests = 1;          cin >> globalTests;          while (globalTests--) localTest();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, int>> v;     int row[1010] = {0}, col[1010] = {0};     char g[1010][1010];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> g[i][j];         if (g[i][j] ==  * ) row[i]++, col[j]++, v.push_back({i, j});       };     int mx_col = 0, mx_row = 0, max_covered = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (row[i] + col[j] - (g[i][j] ==  * ) > max_covered)           mx_row = i, mx_col = j,           max_covered = row[i] + col[j] - (g[i][j] ==  * );     for (auto i : v)       if (i.first != mx_row && i.second != mx_col) {         cout <<  NO ;         return 0;       }     cout <<  YES  << endl << mx_row + 1 <<     << mx_col + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[110];     while (scanf( %s , s) != EOF) {       int l = strlen(s);       int ans = 0;       for (int i = 0; i < l; i++) {         if (s[i] ==  Q ) {           for (int j = i + 1; j < l; j++) {             if (s[j] ==  A ) {               for (int k = j + 1; k < l; k++) {                 if (s[k] ==  Q ) {                   ans++;                 }               }             }           }         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     unsigned int m = 0, n = 0, s;     scanf( %d%d , &m, &n);     s = (m * n) / 2;     printf( %d , s);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:2560000000000 )   using namespace std;   map<int, int> sell;   map<int, int> buy;   int main() {     int n, s;     cin >> n >> s;     for (int i = 1; i <= n; i++) {       int p, d;       char c;       cin >> c >> p >> d;       if (c ==  S ) {         sell[p] += d;       } else {         buy[-p] += d;       }     }     map<int, int>::iterator it = sell.begin();     vector<pair<int, int>> ans;     for (int i = 1; i <= s && it != sell.end(); i++) {       ans.push_back(make_pair(it->first, it->second));       it++;     }     for (int i = ans.size() - 1; i >= 0; i--) {       cout <<  S   << ans[i].first <<     << ans[i].second << endl;     }     map<int, int>::iterator it1 = buy.begin();     for (int i = 1; i <= s && it1 != buy.end(); i++) {       cout <<  B   << -it1->first <<     << it1->second << endl;       it1++;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1003;   const int mod = 1e9 + 7;   int a[N][N];   int c[N];   int n;   int sum;   int main() {     int i, j;     scanf( %d , &n);     for (i = 0; i < n; i++)       for (j = 0; j < n; j++) scanf( %d , &a[i][j]);     for (i = 0; i < n; i++) sum += a[i][i] * a[i][i];     sum %= 2;     int m;     scanf( %d , &m);     int op, x;     while (m--) {       scanf( %d , &op);       if (op == 3) {         printf( %d , sum);       } else {         scanf( %d , &x);         sum = sum - a[x][x] + (a[x][x] ^ 1);         a[x][x] ^= 1;         sum &= 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream& operator<<(ostream& os, const pair<A, B>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename C>   ostream& operator<<(ostream& os, const vector<C>& v) {     for (__typeof((v).begin()) __it = (v).begin(); __it != (v).end(); __it++)       os << *(__it) <<    ;     return os;   }   const int inf = 0x3f3f3f3f;   const double eps = 1e-5;   const int maxm = 123;   const int maxn = 1024;   int ms[maxn];   int res[maxn];   int n;   bool can(int pos, int col) {     int prev = (pos + n - 1) % n;     if (res[prev] == col) return false;     int next = (pos + n + 1) % n;     if (res[next] == col) return false;     return true;   }   int main() {     int m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int t;       cin >> t;       ms[i] = t;     }     int maxpr = -1;     bool fail = false;     memset(res, 0x3f, sizeof(res));     for (int i = 0; i < n; i++) {       vector<pair<int, int> > cs;       for (int j = 0; j < m; j++)         if (ms[j] && can(i, j)) {           pair<int, int> t(ms[j], j);           if (j == maxpr) t.first += inf;           cs.push_back(t);         }       if ((int((cs).size())) == 0) {         fail = true;         break;       }       sort(cs.begin(), cs.end());       int ncolor = cs.rbegin()->second;       ms[ncolor]--;       res[i] = ncolor;       if (!i) maxpr = ncolor;     }     if (fail) {       puts( -1 );       return 0;     }     for (int i = 0; i < n; i++) cout << res[i] + 1 <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   struct que {     int l, r, id;     long long ans;   } q[N];   int block, s[N], tong[N * 20], k;   bool cmp1(que i, que j) {     if (i.l / block != j.l / block) return i.l / block < j.l / block;     return i.r < j.r;   }   bool cmp2(que i, que j) { return i.id < j.id; }   int read() {     int x = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   inline void print(long long x) {     if (x > 9) print(x / 10);     putchar(x % 10 +  0 );   }   long long ans = 0;   void add(int x) {     ans += (long long)tong[s[x] ^ k];     tong[s[x]]++;   }   void del(int x) {     tong[s[x]]--;     ans -= (long long)tong[s[x] ^ k];   }   int main() {     int n, m, x;     scanf( %d%d%d , &n, &m, &k);     block = sqrt(n);     for (int i = 1; i <= n; ++i) scanf( %d , &x), s[i] = s[i - 1] ^ x;     for (int i = 1; i <= m; ++i)       scanf( %d%d , &q[i].l, &q[i].r), q[i].l--, q[i].id = i;     sort(q + 1, q + m + 1, cmp1);     int l = 0, r = 0;     tong[0] = 1;     for (int i = 1; i <= m; i++) {       for (; l < q[i].l; l++) del(l);       for (; l > q[i].l; l--) add(l - 1);       for (; r < q[i].r; r++) add(r + 1);       for (; r > q[i].r; r--) del(r);       q[i].ans = ans;     }     sort(q + 1, q + m + 1, cmp2);     for (int i = 1; i <= m; ++i) cout << q[i].ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const int oo = ~0u >> 2, mo = (int)1e9 + 7;   const int mn = 110000, mm = 110000 * 2, ml = 18;   struct Edge {     int y, l;   } E[mm];   int g[mn], d[mn], s[mn], blg[mn];   int fa[mn][ml], f[mn];   bool o[mn];   int n, m, tt(1);   void add(int x, int y) {     E[++tt].y = y, E[tt].l = g[x], g[x] = tt;     E[++tt].y = x, E[tt].l = g[y], g[y] = tt;   }   int LOG2(int x) {     int t = (int)log2(x);     while ((1 << t) > x) --t;     while ((1 << (t + 1)) <= x) ++t;     return t;   }   int find(int x) {     int i = x, t;     while (f[i] != i) i = f[i];     while (x != i) t = f[x], f[x] = i, x = t;     return x;   }   struct Stack {     int x, i;     Stack() {}     Stack(int _x) { x = _x, i = -1; }     void init(int _x) { x = _x, i = -1; }   } Q[mn];   void init() {     for (int i = 1; i <= n; ++i)       if (!d[i]) {         int r = 0;         d[i] = 1, fa[i][0] = i, blg[i] = i, f[i] = i;         Q[++r].init(i);         while (r) {           int x = Q[r].x, &i = Q[r].i, y;           (d[0] = max(d[0], d[x]));           if (i == -1)             f[x] = x, i = g[x];           else {             y = E[i].y;             if (find(x) == find(y)) o[x] |= o[y];             i = E[i].l;           }           y = E[i].y;           if (!i) {             --r;             continue;           }           if (!d[y]) {             d[y] = d[x] + 1, fa[y][0] = x, blg[y] = blg[x], f[y] = y;             Q[++r].init(y);           } else if (d[x] > d[y] + 1) {             int z = find(x);             while (d[z] > d[y] + 1) f[z] = fa[z][0], z = find(z);             o[x] |= !((d[x] - d[y]) % 2);           }         }         Q[r = 1].init(i);         while (r) {           int x = Q[r].x, &i = Q[r].i, y;           if (i == -1)             s[x] += o[find(x)], i = g[x];           else             i = E[i].l;           y = E[i].y;           if (!i) {             --r;             continue;           }           if (d[y] == d[x] + 1) {             if (find(x) == find(y)) o[y] |= o[x];             s[y] = s[x], Q[++r].init(y);           }         }       }     int t = LOG2(d[0]);     for (int j = 1; j <= t; ++j)       for (int i = 1; i <= n; ++i) fa[i][j] = fa[fa[i][j - 1]][j - 1];   }   int lca(int x, int y) {     if (d[x] < d[y]) swap(x, y);     while (d[x] > d[y]) x = fa[x][LOG2(d[x] - d[y])];     if (x == y) return x;     for (int i = LOG2(d[x]); i >= 0; --i)       if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];     return fa[x][0];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);     }     init();     scanf( %d , &tt);     while (tt--) {       int x, y, z;       scanf( %d%d , &x, &y);       if (blg[x] != blg[y]) {         printf( No n );         continue;       }       z = lca(x, y);       if (((d[x] + d[y]) & 1) || s[x] + s[y] - 2 * s[z])         printf( Yes n );       else         printf( No n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, a;     cin >> n >> a;     double angd = 180 * 1.0 / n;     cout <<  2 1  ;     int x = floor(a / angd);     if (x == 0)       cout << 3 << endl;     else if (a - x * angd < (1 + x) * angd - a)       cout << min(x + 2, n) << endl;     else       cout << min(x + 3, n) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   using V = vector<T>;   int gcdex(int a, int b, int &x, int &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     int x1, y1;     int g = gcdex(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return g;   }   inline int ADD_MOD(int a, int b) { return (a + b) % 1000000007; }   inline int MUL_MOD(int a, int b) { return (int64_t(a) * b) % 1000000007; }   inline int SUB_MOD(int a, int b) { return a >= b ? a - b : a + 1000000007 - b; }   int DIV_MOD(int a, int b) {     int x, y;     gcdex(b, 1000000007, x, y);     int b1 = (x % 1000000007 + 1000000007) % 1000000007;     return MUL_MOD(a, b1);   }   const long double EPS = 1. / 1e9;   inline bool EPS_EQUAL(long double a, long double b) {     return abs(a - b) <= EPS;   }   inline bool EPS_LESS(long double a, long double b) { return b - a > EPS; }   inline bool EPS_GREATER(long double a, long double b) { return a - b > EPS; }   const int INF = 1e9;   const int64_t INF64 = 2e18;   void get_cycle(V<int> &a, V<uint8_t> &visited, int start, V<int> &c) {     int i = start;     while (a[i] != start) {       c.push_back(a[i]);       visited[a[i]] = 1;       i = a[i];     }     c.push_back(start);     visited[start] = 1;   }   void add_out_cycle(V<int> &b, V<int> &c) {     for (int i = 0; i < c.size(); ++i) {       int prev = i > 0 ? c[i - 1] : c.back();       b[prev] = c[i];     }   }   void add_odd_cycle(V<int> &b, V<int> &c) {     int len = c.size();     V<int> outC(len);     for (int i = 0; i < len; ++i) {       if (i % 2 == 0) {         outC[i] = c[(len + i) / 2];       } else {         outC[i] = c[i / 2];       }     }     add_out_cycle(b, outC);   }   void add_even_cycle(V<int> &b, V<int> &c1, V<int> &c2) {     int len = c1.size();     V<int> outC(len * 2);     for (int i = 0; i < len; ++i) {       outC[i * 2] = c1[i];       outC[i * 2 + 1] = c2[i];     }     add_out_cycle(b, outC);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(15);     int n;     cin >> n;     V<int> a(n);     for (auto &i : a) {       cin >> i;       --i;     }     V<int> b(n);     V<uint8_t> visited(n);     V<V<int> > evenCycles(n + 1);     int evenCyclesCount = 0;     for (int i = 0; i < n; ++i) {       if (!visited[i]) {         V<int> c;         get_cycle(a, visited, i, c);         int len = c.size();         if (len % 2 == 1) {           add_odd_cycle(b, c);         } else {           if (!evenCycles[len].empty()) {             add_even_cycle(b, evenCycles[len], c);             evenCycles[len].clear();             evenCyclesCount--;           } else {             swap(evenCycles[len], c);             evenCyclesCount++;           }         }       }     }     if (evenCyclesCount > 0) {       cout << -1 << endl;       return 0;     }     for (auto &i : b) {       cout << i + 1 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   int n, a[N][N];   deque<int> p[N];   int ptr[N], mat[N];   bool vis[N][N];   void upd(int x) {     while (!p[x].empty() && vis[x][p[x].front()]) p[x].pop_front();     while (!p[x].empty() && vis[x][p[x].back()]) p[x].pop_back();     if (p[x].empty()) {       cout << -1 << endl;       exit(0);     }   }   inline void del(int x, int y) { vis[x][y] = vis[y][x] = 1; }   void add(int x, int y) {     mat[y] = x;     while (1) {       upd(y);       if (p[y].back() != x)         del(p[y].back(), y);       else         break;     }   }   int nxt(int x) {     upd(x);     int y = p[x].front();     p[x].pop_front();     upd(x);     p[x].push_front(y);     return mat[p[x][1]];   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     if (n & 1) {       cout << -1 << endl;       return 0;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i != j) cin >> a[i][j], p[i].push_back(j);       }       sort(p[i].begin(), p[i].end(),            [&](int x, int y) { return a[i][x] < a[i][y]; });     }     queue<int> q;     for (int i = 1; i <= n; i++) q.push(i);     while (!q.empty()) {       int x = q.front();       q.pop();       while (1) {         upd(x);         int y = p[x].front(), z = mat[y];         if (z && a[y][z] < a[y][x]) assert(0);         if (z) {           mat[y] = 0;           q.push(z);         }         add(x, y);         break;       }     }     int cur = 1;     while (1) {       while (cur <= n) {         upd(cur);         if (p[cur].size() > 1)           break;         else           ++cur;       }       if (cur > n) {         for (int i = 1; i <= n; i++) cout << p[i].front() << endl;         return 0;       }       vector<int> c1, c2;       int x = cur, y = cur;       do x = nxt(x), y = nxt(nxt(y));       while (x != y);       do c1.push_back(y), y = nxt(y);       while (x != y);       for (auto &i : c1) {         int y = p[i][0];         c2.push_back(y);         mat[y] = 0;         del(i, y);       }       for (int i = 0; i < int(c1.size()); i++)         add(c1[i], c2[(i + 1) % c1.size()]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using Int = long long;   template <class T1, class T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &a) {     return os <<  (  << a.first <<  ,   << a.second <<  ) ;   };   template <class T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cerr << *i <<    ;     cerr << endl;   }   template <class T>   bool chmin(T &t, const T &f) {     if (t > f) {       t = f;       return true;     }     return false;   }   template <class T>   bool chmax(T &t, const T &f) {     if (t < f) {       t = f;       return true;     }     return false;   }   constexpr int MAX_N = 1010;   constexpr int MAX_K = 1010;   constexpr int MUL[4][4] = {       {0, 0, 0, 0},       {0, 1, 2, 3},       {0, 2, 3, 1},       {0, 3, 1, 2},   };   int N, K;   char typ[MAX_K][10], mix[MAX_K][10];   int M[MAX_K], J[MAX_K][MAX_N];   int fs[MAX_N], gs[MAX_N];   int aLen;   vector<bitset<2 * MAX_N>> a;   int main() {     for (; ~scanf( %d%d , &N, &K);) {       for (int k = 0; k < K; ++k) {         scanf( %s%d , typ[k], &M[k]);         for (int m = 0; m < M[k]; ++m) {           scanf( %d , &J[k][m]);           --J[k][m];         }         if (!strcmp(typ[k],  mix )) {           scanf( %s , mix[k]);         }       }       fill(fs, fs + N, 1);       fill(gs, gs + N, 0);       aLen = 0;       a.assign(2 * K, bitset<2 * MAX_N>());       for (int k = 0; k < K; ++k) {         if (!strcmp(typ[k],  mix )) {           const int num = string( WRYB ).find(mix[k]);           for (int m = 0; m < M[k]; ++m) {             const int i = J[k][m];             switch (gs[i]) {               case 0: {                 const int p = (fs[i] >> 0) & 1;                 const int q = (fs[i] >> 1) & 1;                 a[aLen + 0][i << 1 | 0] = p;                 a[aLen + 0][i << 1 | 1] = q;                 a[aLen + 1][i << 1 | 0] = q;                 a[aLen + 1][i << 1 | 1] = p ^ q;               } break;               case 1: {                 const int p = (fs[i] >> 0) & 1;                 const int q = (fs[i] >> 1) & 1;                 a[aLen + 0][i << 1 | 0] = p;                 a[aLen + 0][i << 1 | 1] = p ^ q;                 a[aLen + 1][i << 1 | 0] = q;                 a[aLen + 1][i << 1 | 1] = p;               } break;               default:                 assert(false);             }           }           a[aLen + 0][N << 1] = (num >> 0) & 1;           a[aLen + 1][N << 1] = (num >> 1) & 1;           aLen += 2;         } else if (!strcmp(typ[k],  RY )) {           for (int m = 0; m < M[k]; ++m) {             const int i = J[k][m];             fs[i] = MUL[2][MUL[fs[i]][fs[i]]];             gs[i] ^= 1;           }         } else if (!strcmp(typ[k],  RB )) {           for (int m = 0; m < M[k]; ++m) {             const int i = J[k][m];             fs[i] = MUL[3][MUL[fs[i]][fs[i]]];             gs[i] ^= 1;           }         } else if (!strcmp(typ[k],  YB )) {           for (int m = 0; m < M[k]; ++m) {             const int i = J[k][m];             fs[i] = MUL[1][MUL[fs[i]][fs[i]]];             gs[i] ^= 1;           }         } else {           assert(false);         }       }       a.resize(aLen);       int r = 0;       vector<int> hs;       for (int h = 0; h < N << 1; ++h) {         for (int i = r; i < aLen; ++i) {           if (a[i][h]) {             swap(a[r], a[i]);             break;           }         }         if (a[r][h]) {           for (int i = r + 1; i < aLen; ++i) {             if (a[i][h]) {               a[i] ^= a[r];             }           }           ++r;           hs.push_back(h);         }       }       bool ok = true;       for (int i = r; i < aLen; ++i) {         ok = ok && !a[i][N << 1];       }       if (ok) {         bitset<2 * MAX_N> sol;         for (int i = r; i--;) {           sol[hs[i]] = (int)a[i][N << 1] ^ ((a[i] & sol).count() & 1);         }         puts( YES );         for (int i = 0; i < N; ++i) {           putchar( .RYB [(int)sol[i << 1 | 0] << 0 | (int)sol[i << 1 | 1] << 1]);         }         puts(  );       } else {         puts( NO );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, flag = 0;       cin >> n;       long long int a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < (n - 1); i++) {         if (a[i] > a[i + 1]) {           flag = 0;         } else {           flag = 1;           break;         }       }       if (flag == 0) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       long long int ml = 0, mr = 0, j;       j = i;       while (j < n - 1 && s[j] !=  R ) {         s[j] ==  L  ? mr++ : mr += 0;         j++;       }       j = i - 1;       while (j > -1 && s[j] !=  L ) {         s[j] ==  R  ? ml++ : ml += 0;         j--;       }       cout << 1 + max(ml, mr) <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     pair<long long, long long> a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i + 1;     }     sort(a, a + n);     long long mx = 0, mx_start = 0, mx_end = 0;     long long j;     long long mn = n;     for (long long i = 0; i < n; i++) {       long long c = a[i].second;       long long d, ck = 0;       for (j = i; j < n; j++) {         if (a[i].first != a[j].first) {           d = a[j - 1].second;           break;         } else           ck++;       }       if (j == n) {         d = a[j - 1].second;         i = n - 1;       } else         i = j - 1;       if (ck > mx) {         mx = ck;         mx_start = c;         mx_end = d;         mn = d - c + 1;       } else if (ck == mx && (d - c + 1) < mn) {         mx = ck;         mx_start = c;         mx_end = d;         mn = d - c + 1;       }     }     cout << mx_start <<     << mx_end << endl;     return 0;   }


#include <bits/stdc++.h>   char abc[1000001];   int main() {     char ab[1000001];     scanf( %s , ab);     int abcc = strlen(ab);     int i, x = 0, y = 0;     for (i = 0; i < abcc; i++) {       x += ab[i] ==  x  ? 1 : 0;       y += ab[i] ==  y  ? 1 : 0;     }     if (x > y)       for (i = 0; i < x - y; i++) abc[i] =  x ;     else       for (i = 0; i < y - x; i++) abc[i] =  y ;     printf( %s , abc);   }


#include <bits/stdc++.h>   using namespace std;   void solve(int test) {     int x;     cin >> x;     int no = x % 10;     int cnt = 0;     while (x) {       cnt++;       x /= 10;     }     int ans = (no - 1) * 10;     while (cnt) {       ans += cnt;       cnt--;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << setprecision(20);     long long int t = 1, k;     cin >> t;     k = t;     while (t--) {       solve(k - t);     }     cerr <<  Timpe elapsed :  << clock() * 1000.0 / CLOCKS_PER_SEC <<   mps n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[19][19];   int n;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       a[i][1] = 1;       a[1][i] = 1;     }     for (int i = 2; i <= n; i++) {       for (int j = 2; j <= n; j++) {         a[i][j] = a[i - 1][j] + a[i][j - 1];       }     }     cout << a[n][n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p, q, i = 1, j, k, temp = 0, flag = 0;     string s;     cin >> n >> p >> q;     cin >> s;     if (n % p == 0 && n != p + q || n % q == 0 && n != p + q) {       if (n % p == 0) {         cout << n / p << endl;         for (i = 0; i < n; i++) {           cout << s[i];           if ((i + 1) % p == 0) cout << endl;         }       } else {         cout << n / q << endl;         for (i = 0; i < n; i++) {           cout << s[i];           if ((i + 1) % q == 0) cout << endl;         }       }     } else {       while (1) {         j = n - (p * i);         k = n - (q * i);         if (j < 0 || k < 0) break;         if (j % q == 0) {           temp = 1;           break;         }         if (k % p == 0) {           flag = 1;           break;         }         if (j < 0 && k < 0) break;         i++;       }       if (temp == 1) {         cout << i + (j / q) << endl;         for (int x = 0; x < i * p; x++) {           cout << s[x];           if ((x + 1) % p == 0) cout << endl;         }         j = 1;         for (int x = i * p; x < n; x++) {           cout << s[x];           if ((j) % q == 0) cout << endl;           j++;         }       } else if (flag == 1) {         cout << i + (k / p) << endl;         for (int x = 0; x < i * q; x++) {           cout << s[x];           if ((x + 1) % q == 0) cout << endl;         }         j = 1;         for (int x = i * q; x < n; x++) {           cout << s[x];           if ((j) % p == 0) cout << endl;           j++;         }       } else {         cout <<  -1  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     for (int i = 0; i <= (c / b); i++) {       int tmp = c - (i * b);       if (tmp % a == 0) {         cout <<  Yes  << endl;         return 0;       }     }     cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, a[105], nr = 0, poz = 0;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       if (a[i] <= k)         nr++;       else {         poz = i;         break;       }     }     if (poz || nr == 0)       for (int i = n - 1; i > poz; i--)         if (a[i] <= k)           nr++;         else           break;     cout << nr;   }


#include <bits/stdc++.h>   using namespace std;   const int Max_L = 100000 + 100, inf = ~0U >> 2;   pair<int, int> Ret[1000];   int main() {     int L, b, f;     cin >> L >> f >> b;     int n;     cin >> n;     set<pair<int, int> > S;     S.insert(pair<int, int>(-inf, -inf));     S.insert(pair<int, int>(inf, inf));     for (int i = 0; i < n; i++) {       int t, len;       cin >> t >> len;       if (t == 1) {         bool ok = false;         for (typeof(S.begin()) it = S.begin(); it != S.end(); it++) {           if (it == --S.end()) continue;           int l = max(it->second + f, 0);           ++it;           int r = min(it->first - b, L);           --it;           if (r - l >= len) {             ok = true;             cout << l << endl;             Ret[i] = pair<int, int>(l, l + len);             S.insert(Ret[i]);             break;           }         }         if (!ok) cout << -1 << endl;       } else {         len--;         S.erase(Ret[len]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k;     cin >> n >> k;     string s;     cin >> s;     string ans;     for (long long i = 0; i < k; i++) {       ans.push_back(s[i]);     }     for (long long i = k; i < n; i++) {       ans.push_back(ans[i - k]);     }     cout << n << endl;     if (ans >= s) {       cout << ans << endl;     } else {       long long i = k - 1;       while (i >= 0 && ans[i] ==  9 ) {         ans[i] =  0 ;         for (long long j = i; j < n; j += k) {           ans[j] =  0 ;         }         i--;       }       for (; i < n; i += k) {         ans[i]++;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> seq;     int n;     long e;     cin >> n;     int first = 0;     long long s = 0;     int f = 0;     for (int i = 0; i < n; i++) {       cin >> e;       if (e != 1) {         s += e;         f++;       } else {         first++;       }       if (s > f && (s - f + 1) % 2 == 0) {         cout << 1 << endl;       } else {         cout << 2 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long int, long long int> > points, hull;   bool comp(pair<long long int, long long int> a,             pair<long long int, long long int> b) {     if (a.first != b.first) return a.first < b.first;     return a.second < b.second;   }   int cross(pair<long long int, long long int> a,             pair<long long int, long long int> b,             pair<long long int, long long int> c) {     return a.first * (b.second - c.second) + b.first * (c.second - a.second) +                c.first * (a.second - b.second) >=            0;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       long long int x, y;       cin >> x >> y;       y = y - x * x;       points.push_back({x, y});     }     sort(points.begin(), points.end(), comp);     int sz = 1;     hull.push_back(points[0]);     for (int i = 1; i < points.size(); i++) {       while (sz >= 2 && cross(hull[sz - 2], hull[sz - 1], points[i]))         hull.pop_back(), sz--;       hull.push_back(points[i]);       sz++;     }     int ans = 0;     for (int i = 0; i < sz - 1; i++) {       if (hull[i].first != hull[i + 1].first) ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, sum = 0, sumtotal;   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> x;       sum += x;     }     sumtotal = n * (n + 1) / 2;     cout << sumtotal - sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:167177216 )   int main() {     double y1, y2, yw, xa, ya, r;     cin >> y1 >> y2 >> yw >> xa >> ya >> r;     double ll = 0, rr = xa;     yw -= r;     double yt = y1 + r + 1e-9;     for (int i = 0; i < 300; ++i) {       double xm = (ll + rr) / 2;       double dx1 = -xm, dy1 = yt - yw;       double a1 = acos(-dy1 / sqrt(dx1 * dx1 + dy1 * dy1));       dx1 = xa - xm, dy1 = ya - yw;       double a2 = acos(-dy1 / sqrt(dx1 * dx1 + dy1 * dy1));       if (a1 > a2)         rr = xm;       else         ll = xm;     }     double xm = (ll + rr) / 2;     double a = yw - yt, b = -xm, c = -b * yt;     double d = fabs(b * y2 + c) / sqrt(a * a + b * b);     if (d + 1e-9 < r) {       cout << -1 << endl;       return 0;     }     cout.precision(20);     cout << xm << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d[100000];     string ch;     long long res = 0;     bool b = 0;     cin >> n >> ch;     for (int i = 0; i < n; i++) cin >> d[i];     for (int i = 0; i < n; i++) {       if (ch[res] ==  < )         res -= d[res];       else         res += d[res];       if (res < 0 || res >= n) {         b = 1;         break;       }     }     if (b)       cout <<  FINITE  << endl;     else       cout <<  INFINITE  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000;   int centroid[maxn];   int parent[maxn];   int subtree[maxn];   int heaviest[maxn];   vector<int> graph[maxn];   void dfs(int u, int p = 0) {     parent[u] = p;     subtree[u] = 1;     heaviest[u] = 0;     int vert = 0;     for (auto v : graph[u]) {       if (v == p) continue;       dfs(v, u);       subtree[u] += subtree[v];       if (subtree[v] > heaviest[u]) {         heaviest[u] = subtree[v];         vert = v;       }     }     if ((int)graph[u].size() == 0 or (2 * heaviest[u] <= subtree[u]))       centroid[u] = u;     else {       int curr = centroid[vert];       centroid[u] = curr;       while (curr != u) {         int P = parent[curr];         int rem = subtree[u] - subtree[P];         if (2 * heaviest[P] > subtree[u]) break;         if (2 * rem <= subtree[u]) centroid[u] = P;         curr = parent[curr];       }     }   }   int main() {     int n;     scanf( %d , &n);     int q;     scanf( %d , &q);     for (int i = 2; i <= n; i++) {       int p;       scanf( %d , &p);       graph[p].push_back(i);     }     dfs(1);     while (q--) {       int v;       scanf( %d , &v);       printf( %d n , centroid[v]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, r1, r2;   string ans;   bool pytaj(int x, int y) {     cout << 1 <<     << x <<     << y <<   n ;     fflush(stdout);     cin >> ans;     return ans[0] ==  T ;   }   int znajdz(int l, int r) {     if (r < l) return -1;     while (l < r) {       int d = (r - l + 1 - 2 + 2) / 4;       int a = l + d;       int b = r - d;       if (pytaj(a, b))         r = (l + r) / 2;       else         l = (l + r + 1) / 2;     }     return l;   }   bool sprawdz(int x) {     if (x - 1 >= 1 && !pytaj(x, x - 1)) return 0;     if (x + 1 <= n && !pytaj(x, x + 1)) return 0;     return 1;   }   int32_t main() {     cin >> n >> k;     r1 = znajdz(1, n);     r2 = znajdz(1, r1 - 1);     if (r2 == -1 || !sprawdz(r2)) r2 = znajdz(r1 + 1, n);     cout << 2 <<     << r1 <<     << r2 <<   n ;     fflush(stdout);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 5;   int c[N][26], fa[N], l[N], sz[N], np = 1, cnt = 1;   int a[N], b[N];   int q, len, vi[N];   char s[N];   void expend(int x) {     int p = np;     np = ++cnt;     l[np] = l[p] + 1;     sz[np] = 1;     for (; p && !c[p][x]; p = fa[p]) c[p][x] = np;     if (!p) {       fa[np] = 1;       return;     }     int q = c[p][x];     if (l[q] == l[p] + 1) {       fa[np] = q;       return;     }     int nq = ++cnt;     l[nq] = l[p] + 1;     memcpy(c[nq], c[q], 104);     fa[nq] = fa[q], fa[q] = fa[np] = nq;     for (; c[p][x] == q; p = fa[p]) c[p][x] = nq;   }   void init() {     for (int i = 1; i <= cnt; ++i) ++b[l[i]];     for (int i = 1; i <= len; ++i) b[i] += b[i - 1];     for (int i = cnt; i; --i) a[b[l[i]]--] = i;     for (int i = cnt; i; --i) sz[fa[a[i]]] += sz[a[i]];   }   int walk() {     int re = 0, u = 1, cur = 0;     for (int i = 0; i < (len << 1); ++i) {       int x = s[i] - 97;       if (c[u][x])         ++cur, u = c[u][x];       else {         while (u && !c[u][x]) u = fa[u];         if (u)           cur = l[u] + 1, u = c[u][x];         else           cur = 0, u = 1;       }       if (i >= len && cur >= len) {         int p = u;         while (p && !(len >= l[fa[p]] + 1 && len <= l[p])) p = fa[p];         if (!p) p = 1;         if (vi[p] != q + 1) vi[p] = q + 1, re += sz[p];       }     }     return re;   }   int main() {     scanf( %s%d , s, &q), len = strlen(s);     for (int i = 0; i < len; ++i) expend(s[i] - 97);     init();     while (q--) {       scanf( %s , s), len = strlen(s);       memcpy(s + len, s, len);       printf( %d n , walk());     }   }


#include <bits/stdc++.h>   using namespace std;   int k;   bool primes[200000][100];   int okay[5000000];   int okayN;   int nLeft[1000];   bool isPrime[1000];   bool used[5000000];   vector<int> ans;   bool compare(int a, int b) {     if (nLeft[a] > nLeft[b]) return 1;     if (nLeft[a] < nLeft[b]) return 0;     return (a < b);   }   int main() {     scanf( %d , &k);     okayN = 1;     okay[0] = 1;     isPrime[1] = 0;     for (int p = 2; true; ++p) {       bool prime = 1;       for (int i = 2; i * i <= p; ++i) {         if (p % i == 0) prime = 0;       }       if (!prime) {         isPrime[p] = 0;         continue;       }       isPrime[p] = 1;       for (int i = okayN - 1; i >= 0; --i) {         int j = okay[i] * p;         while (j <= 2 * k * k) {           for (int m = 2; m < p; ++m) primes[okayN][m] = primes[i][m];           primes[okayN][p] = 1;           okay[okayN++] = j;           j *= p;         }       }       for (int i = 2; i <= p; ++i) nLeft[i] = (k + 1) / 2;       int need[1000];       int needN = 0;       for (int i = 2; i <= p; ++i)         if (isPrime[i]) need[needN++] = i;       for (int i = 0; i < okayN; ++i) used[i] = 0;       bool ok = 1;       bool anybad = 0;       ans.clear();       while (ans.size() < k) {         int best = 0;         for (int i = 1; i < okayN; ++i) {           if (used[i]) continue;           for (int j = 0; j < needN; ++j) {             if (primes[i][need[j]] && !primes[best][need[j]]) {               best = i;               break;             }             if (!primes[i][need[j]] && primes[best][need[j]]) {               break;             }           }         }         ans.push_back(okay[best]);         if (used[best]) {           ok = 0;           break;         }         used[best] = 1;         anybad = 0;         for (int j = 0; j < needN; ++j) {           if (nLeft[need[j]]) anybad = 1;           if (primes[best][need[j]] && nLeft[need[j]]) --nLeft[need[j]];         }         sort(need, need + needN, compare);       }       if (ok && !anybad) {         for (int i = 0; i < ans.size(); ++i) printf( %d  , ans[i]);         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int inf = 0x7fffffff / 2;   int n, m;   int fa[maxn];   int vis[maxn];   struct edge {     int u;     int v;     int w;   } e[maxn];   struct ex {     int mi;     int mx;     int sum;   } ex[maxn];   int father(int x) {     if (x != fa[x]) fa[x] = father(fa[x]);     return fa[x];   }   void join(int x, int y) {     ex[father(y)].mi = min(ex[father(y)].mi, ex[father(x)].mi);     ex[father(y)].mx = max(ex[father(y)].mx, ex[father(x)].mx);     ex[father(y)].sum += ex[father(x)].sum;     fa[father(x)] = father(y);   }   int judge_node(int x) {     x = father(x);     int mi = ex[x].mi;     int mx = ex[x].mx;     int sum = ex[x].sum;     if (mi == -inf) return 1;     mi = ((mi - 1) * mi) / 2;     mx = ((mx + 1) * mx) / 2;     if ((mx - mi) != sum)       return 1;     else       return 0;   }   void init(int u, int v) {     ex[u].sum = u;     ex[v].sum = v;     ex[u].mx = u;     ex[u].mi = u;     ex[v].mx = v;     ex[v].mi = v;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       fa[i] = i;       ex[i].mi = inf;       ex[i].mx = -inf;       ex[i].sum = 0;     }     for (int i = 1; i <= m; i++) {       cin >> e[i].u >> e[i].v;       init(e[i].u, e[i].v);     }     for (int i = 1; i <= m; i++) {       if (father(e[i].u) != father(e[i].v)) {         join(e[i].u, e[i].v);       }     }     int ans = 0;     int mxx = -inf, last;     for (int i = 1; i <= n; i++) {       if (judge_node(i) && vis[father(i)] == 0) {         int l = ex[father(i)].mi;         int r = ex[father(i)].mx;         for (int j = l; j < r; j++) {           if (father(j) != father(i)) {             join(i, j);             ans++;             last = j;           }           l = ex[father(i)].mi;           r = ex[father(i)].mx;         }         vis[father(last)] = 1;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7, INF = 0x3f3f3f3f;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long qpow(long long a, long long n) {     long long r = 1 % P;     for (a %= P; n; a = a * a % P, n >>= 1)       if (n & 1) r = r * a % P;     return r;   }   long long inv(long long first) {     return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;   }   inline int rd() {     int first = 0;     char p = getchar();     while (p <  0  || p >  9 ) p = getchar();     while (p >=  0  && p <=  9 ) first = first * 10 + p -  0 , p = getchar();     return first;   }   const int N = 5e3 + 10;   int n, a, b, k;   int dp[N][N], s[N];   int main() {     scanf( %d%d%d%d , &n, &a, &b, &k);     dp[0][a] = 1;     int ans = 0;     for (int i = 0; i <= k; ++i) {       for (int first = 1; first <= n; ++first) {         int &r = dp[i][first];         if (i) (r += dp[i][first - 1]) %= P;         if (!r) continue;         if (i == k) (ans += r) %= P;         int w = abs(first - b);         if (w == 1) continue;         (dp[i + 1][max(first - w + 1, 0)] += r) %= P;         (dp[i + 1][first] -= r) %= P;         (dp[i + 1][first + 1] += r) %= P;         (dp[i + 1][min(first + w, n + 1)] -= r) %= P;       }     }     if (ans < 0) ans += P;     printf( %d n , ans);   }


#include <bits/stdc++.h>   namespace FastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   template <class T>   inline bool read(T& x) {     bool sign = 0;     char ch = nc();     x = 0;     for (; blank(ch); ch = nc())       ;     if (IOerror) return false;     if (ch ==  - ) sign = 1, ch = nc();     for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ;     if (sign) x = -x;     return true;   }   template <class T, class... U>   bool read(T& h, U&... t) {     return read(h) && read(t...);   }   };  // namespace FastIO   using namespace std;   using namespace FastIO;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int INF = 0x3f3f3f3f;   const int N = 2e5 + 10;   const int mod = 1e9 + 7;   vector<long long> e[N];   long long dis[N][2], siz[N][2], n, ans, w[N];   void dfs(long long u, long long fa) {     siz[u][1] = 1;     dis[u][1] = (w[u] + mod) % mod;     for (auto v : e[u]) {       if (v == fa) continue;       dfs(v, u);       ans =           (ans + dis[u][0] * siz[v][1] % mod + dis[v][1] * siz[u][0] % mod) % mod;       ans =           (ans + dis[u][1] * siz[v][0] % mod + dis[v][0] * siz[u][1] % mod) % mod;       siz[u][0] += siz[v][1];       siz[u][1] += siz[v][0];       dis[u][0] = (dis[u][0] + dis[v][1] - w[u] * siz[v][1] % mod + mod) % mod;       dis[u][1] = (dis[u][1] + dis[v][0] + w[u] * siz[v][0] % mod + mod) % mod;     }   }   signed main() {     read(n);     for (long long i = 1; i <= n; i++) read(w[i]);     for (long long i = 1; i < n; i++) {       long long u, v;       read(u, v);       e[u].push_back(v);       e[v].push_back(u);     }     dfs(1, 1);     ans *= 2;     ans %= mod;     for (long long i = 1; i <= n; i++) ans = (ans + w[i] + mod) % mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct cell {     long long mx, pref, suf, total;   } cell;   int tam[55], vet[300000];   long long sum[55], preffix[55], suffix[55], best[55], v[300000];   long long getMax(int n) {     long long ret = -1000000000000000000LL, aux = 0LL;     for (int i = 0; i < n; i++) {       aux += v[i];       ret = max(ret, aux);       if (aux < 0) aux = 0LL;     }     return ret;   }   cell solve(int b, int e) {     cell r;     if (b == e) {       r.mx = best[vet[b]];       r.total = sum[vet[b]];       r.pref = preffix[vet[b]];       r.suf = suffix[vet[b]];       return r;     }     int m = (b + e) / 2;     cell p1, p2;     p1 = solve(b, m);     p2 = solve(m + 1, e);     r.mx = max(max(p1.mx, p2.mx), p1.suf + p2.pref);     r.total = p1.total + p2.total;     r.pref = max(p1.pref, p1.total + p2.pref);     r.suf = max(p2.suf, p1.suf + p2.total);     return r;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> tam[i];       for (int j = 0; j < tam[i]; j++) {         cin >> v[j];       }       best[i] = getMax(tam[i]);       sum[i] = 0LL;       preffix[i] = suffix[i] = -1000000000000000000LL;       for (int j = 0; j < tam[i]; j++) {         sum[i] += v[j];         preffix[i] = max(preffix[i], sum[i]);       }       sum[i] = 0LL;       for (int j = tam[i] - 1; j >= 0; j--) {         sum[i] += v[j];         suffix[i] = max(suffix[i], sum[i]);       }     }     for (int i = 0; i < m; i++) {       cin >> vet[i];       vet[i]--;     }     cell ans = solve(0, m - 1);     cout << ans.mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1);   inline int sgn(double x) {     if (x < -eps)       return -1;     else if (x > eps)       return 1;     else       return 0;   }   struct Point {     double x, y;     Point(double _x = 0.0, double _y = 0.0) : x(_x), y(_y) {}     Point operator+(const Point &b) const { return Point(x + b.x, y + b.y); }     Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }     double operator*(const Point &b) const { return (x * b.x + y * b.y); }     double operator^(const Point &b) const { return (x * b.y - y * b.x); }     Point operator*(double b) { return Point(x * b, y * b); }     bool operator<(const Point &b) const {       if (sgn(x - b.x) == 0)         return sgn(y - b.y) <= 0;       else         return sgn(x - b.x) < 0;     }     bool operator==(const Point &b) const {       return sgn(x - b.x) == 0 && sgn(y - b.y) == 0;     }     Point rot(double ang) {       return Point(x * cos(ang) - y * sin(ang), x * sin(ang) + y * cos(ang));     }     Point rot(double g1, double g2) {       return Point(x * g2 - y * g1, x * g1 + y * g2);     }     double norm() { return sqrt(x * x + y * y); }     Point unit() {       double ll = norm();       return Point(x / ll, y / ll);     }   };   Point f[2005], p[2005];   bool vis[2005];   double d[2005];   int main() {     int n, m, ans = 0, i, j;     Point o = Point(0, 0);     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %lf%lf , &f[i].x, &f[i].y);       o = o + f[i];     }     o = o * (1.0 / n);     for (i = 0; i < n; i++) {       if (vis[i]) continue;       for (j = i; j < n; j++) {         if (f[i] + f[j] == o * 2.0) {           vis[i] = vis[j] = 1;           break;         }       }     }     for (i = j = 0; i < n; i++) {       if (!vis[i]) f[j++] = f[i] - o;     }     if (!j) return puts( -1 ), 0;     n = j;     for (i = m = 0; i < n; i++) {       Point u = f[0] + f[i];       Point v = Point(-u.y, u.x);       for (j = 0; j < n; j++) d[j] = f[j] * v;       sort(d, d + n);       for (j = 0; j < n; j++)         if (sgn(d[j] + d[n - 1 - j])) break;       if (j == n) {         v = v.unit();         for (j = 0; j < m; j++)           if (!sgn(p[j] ^ v)) break;         if (j == m) {           ans++;           p[m++] = v;         }       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long inf = 10000000;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline bool isLeapYear(long long year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline void normal(long long &a) {     a %= MOD;     (a < 0) && (a += MOD);   }   inline long long modMul(long long a, long long b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a * b) % MOD;   }   inline long long modAdd(long long a, long long b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a + b) % MOD;   }   inline long long modSub(long long a, long long b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long modPow(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline long long modInverse(long long a) { return modPow(a, MOD - 2); }   inline long long modDiv(long long a, long long b) {     return modMul(a, modInverse(b));   }   inline bool checkBit(long long n, int i) { return n & (1LL << i); }   inline long long setBit(long long n, int i) {     return n | (1LL << i);     ;   }   inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   void input(long long n, const long long a[], int co = 0) {     long long i = 1;     for (; i <= n; i++) {     }   }   const int N = 45;   int dp[N][N][N][N];   char Grid[N][N];   int cal[N][N];   int n, m, k;   void dfs() {}   bool cmp() {}   void gen() {     for (int i = int(1); i < int(n + 1); ++i)       for (int j = int(1); j < int(m + 1); ++j) {         cal[i][j] = cal[i - 1][j] + cal[i][j - 1] - cal[i - 1][j - 1] +                     (Grid[i][j] ==  1 );       }   }   void marmarkatkat() {     for (int i = int(1); i < int(n + 1); ++i) {       for (int j = int(1); j < int(m + 1); ++j) {         for (int l = int(i); l < int(n + 1); ++l)           for (int r = int(j); r < int(m + 1); ++r)             dp[i][j][l][r] += (cal[l][r] + cal[i - 1][j - 1] - cal[i - 1][r] -                                cal[l][j - 1]) == 0;       }     }   }   int main() {     scanf( %d %d %d , &n, &m, &k);     memset(cal, 0, sizeof cal);     ;     for (int i = int(1); i < int(n + 1); ++i) {       scanf( %s , Grid[i] + 1);     }     gen();     marmarkatkat();     for (int l = int(1); l < int(n + 1); ++l) {       for (int r = int(1); r < int(m + 1); ++r) {         for (int i = int(n); i >= int(1); --i)           for (int j = int(m); j >= int(1); --j) {             dp[i][j][l][r] += (dp[i + 1][j][l][r] + dp[i][j + 1][l][r] -                                dp[i + 1][j + 1][l][r]);           }       }     }     for (int l = int(1); l < int(n + 1); ++l) {       for (int r = int(1); r < int(m + 1); ++r) {         for (int i = int(n); i >= int(1); --i)           for (int j = int(m); j >= int(1); --j) {             dp[i][j][l][r] +=                 dp[i][j][l - 1][r] + dp[i][j][l][r - 1] - dp[i][j][l - 1][r - 1];           }       }     }     int a, b, x, y;     for (int i = int(0); i < int(k); ++i) {       scanf( %d %d , &a, &b), scanf( %d %d , &x, &y);       ;       printf( %d n , dp[a][b][x][y]);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long MOD = 1e9 + 7;   const long long mod = 998244353;   const long long mxN = 1e6;   void fileio() {}   vector<long long> v[mxN];   vector<long long> vis(mxN);   long long nd;   void dfs(long long x, long long p) {     vis[x] = 1;     for (auto i : v[x]) {       if (i == p) continue;       if (!vis[i])         dfs(i, x);       else         nd = x;     }   }   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     ;     for (long long i = 0; i < n; i++) {       v[i + 1].push_back(a[i]);       v[a[i]].push_back(i + 1);     }     vector<long long> v;     for (long long i = 1; i < n + 1; i++) {       if (vis[i]) continue;       nd = i;       dfs(i, -1);       v.push_back(nd);     }     long long ans = v.size() - 1;     long long root = -1;     for (long long i = 0; i < v.size(); i++) {       if (a[v[i] - 1] == v[i]) {         root = v[i];         break;       }     }     if (root == -1) {       ans++;       a[v[0] - 1] = v[0];       root = v[0];     }     for (long long i = 0; i < v.size(); i++) a[v[i] - 1] = root;     cout << ans <<   n ;     for (long long i = 0; i < a.size(); i++) cout << a[i] <<    ;     cout <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     fileio();     long long tc = 1;     while (tc--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long dx[4] = {-1, 1, 0, 0};   const long long dy[4] = {0, 0, -1, 1};   const long long MAX = 5e3 + 5;   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long n, m, ans, k, Q;   string second;   bool pal[MAX][MAX];   long long cnt[MAX][MAX];   void solve() {     for (int i = 0; i < n; ++i) pal[i][i] = cnt[i][i] = true;     for (int i = 0; i < n - 1; ++i) {       if (second[i] == second[i + 1]) pal[i][i + 1] = true, cnt[i][i + 1] = 1;       cnt[i][i + 1] += 2;     }     for (int len = 3; len <= n; ++len)       for (int i = 0; i < n - len + 1; ++i) {         int j = i + len - 1;         if (second[i] == second[j] && pal[i + 1][j - 1])           pal[i][j] = true;         else           pal[i][j] = false;         cnt[i][j] = pal[i][j] + cnt[i][j - 1] + cnt[i + 1][j] - cnt[i + 1][j - 1];       }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> second;     n = second.length();     solve();     cin >> Q;     while (Q--) {       int lo, hi;       cin >> lo >> hi;       --lo;       --hi;       cout << cnt[lo][hi] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int count = 0;       int n, m;       cin >> n >> m;       char a[n][m];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> a[i][j];         }       }       for (int i = 0; i < n - 1; i++) {         if (a[i][m - 1] !=  D ) {           count++;         }       }       for (int i = 0; i < m - 1; i++) {         if (a[n - 1][i] !=  R ) {           count++;         }       }       cout << count << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5, mod = 998244353;   inline int mod1(int x) { return x < mod ? x : x - mod; }   inline int mod2(int x) { return x < 0 ? x + mod : x; }   inline void add(int &x, int y) { x = mod1(x + y); }   inline void sub(int &x, int y) { x = mod2(x - y); }   inline int pow_mod(int x, int i) {     int y = 1;     while (i) {       if (i & 1) y = (long long)y * x % mod;       x = (long long)x * x % mod;       i >>= 1;     }     return y;   }   int p[26], val[26], m, n, s[MAXN + 5], t[MAXN + 5], vs[MAXN + 5], vt[MAXN + 5],       res[MAXN + 5], f[MAXN * 4 + 5], g[MAXN * 4 + 5], rev[MAXN * 4 + 5];   char str[MAXN + 5];   void NTT(int *a, int n, int flag) {     for (int i = 0; i < n; ++i)       if (i < rev[i]) swap(a[i], a[rev[i]]);     for (int i = 1; i < n; i <<= 1) {       int T = pow_mod(3, (mod - 1) / (i << 1));       if (flag == -1) T = pow_mod(T, mod - 2);       for (int j = 0; j < n; j += (i << 1)) {         for (int k = 0, t = 1; k < i; ++k, t = (long long)t * T % mod) {           int Nx = a[j + k], Ny = (long long)a[i + j + k] * t % mod;           a[j + k] = mod1(Nx + Ny);           a[i + j + k] = mod2(Nx - Ny);         }       }     }     if (flag == -1) {       int invn = pow_mod(n, mod - 2);       for (int i = 0; i < n; ++i) a[i] = (long long)a[i] * invn % mod;     }   }   bool ck(int i) {     for (int j = 0; j < i; ++j)       if (val[i] == val[j]) return 0;     return 1;   }   int main() {     for (int i = 0; i < 26; ++i) {       val[i] = rand() % mod;       while (!ck(i)) add(val[i], 1);     }     for (int i = 0; i < 26; ++i) cin >> p[i], p[i] = val[p[i] - 1];     cin >> str;     m = strlen(str);     reverse(str, str + m);     for (int i = 0; i < m; ++i) vs[i] = val[s[i] = str[i] -  a ];     cin >> str;     n = strlen(str);     for (int i = 0; i < n; ++i) vt[i] = val[t[i] = str[i] -  a ];     int tmp = 0, tmpp = 0;     for (int i = 0; i < m; ++i)       add(tmp, (long long)p[s[i]] * p[s[i]] % mod * vs[i] % mod * vs[i] % mod);     for (int i = 0; i < m; ++i) add(tmpp, (long long)pow_mod(vt[i], 4));     res[m - 1] = (tmpp + tmp) % mod;     for (int i = m; i < n; ++i)       res[i] =           ((res[i - 1] + pow_mod(vt[i], 4) - pow_mod(vt[i - m], 4)) % mod + mod) %           mod;     for (int i = 0; i < m; ++i)       f[i] = (long long)p[s[i]] * vs[i] % mod * mod1(p[s[i]] + vs[i]) % mod;     for (int i = 0; i < n; ++i) g[i] = vt[i];     int len = 1, ct = 0;     while (len <= n + m) len <<= 1, ++ct;     for (int i = 0; i < len; ++i)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (ct - 1));     NTT(f, len, 1);     NTT(g, len, 1);     for (int i = 0; i < len; ++i) f[i] = (long long)f[i] * g[i] % mod;     NTT(f, len, -1);     for (int i = m - 1; i < n; ++i) sub(res[i], mod1(2 * f[i]));     for (int i = 0; i < m; ++i)       f[i] = ((long long)vs[i] * vs[i] % mod +               (long long)p[s[i]] * p[s[i]] % mod + 4LL * vs[i] * p[s[i]] % mod) %              mod;     for (int i = m; i < len; ++i) f[i] = 0;     for (int i = 0; i < n; ++i) g[i] = (long long)vt[i] * vt[i] % mod;     for (int i = n; i < len; ++i) g[i] = 0;     NTT(f, len, 1);     NTT(g, len, 1);     for (int i = 0; i < len; ++i) f[i] = (long long)f[i] * g[i] % mod;     NTT(f, len, -1);     for (int i = m - 1; i < n; ++i) add(res[i], f[i]);     for (int i = 0; i < m; ++i) f[i] = mod1(vs[i] + p[s[i]]);     for (int i = m; i < len; ++i) f[i] = 0;     for (int i = 0; i < n; ++i)       g[i] = (long long)vt[i] * vt[i] % mod * vt[i] % mod;     for (int i = n; i < len; ++i) g[i] = 0;     NTT(f, len, 1);     NTT(g, len, 1);     for (int i = 0; i < len; ++i) f[i] = (long long)f[i] * g[i] % mod;     NTT(f, len, -1);     for (int i = m - 1; i < n; ++i) sub(res[i], mod1(2 * f[i]));     for (int i = m - 1; i < n; ++i)       if (!res[i])         cout <<  1 ;       else         cout <<  0 ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, m, A[12][N], q;   struct node {     int ans, lrt[12], rrt[12];     void trans(int u, int v) {       ans--;       for (int i = 1; i <= n; i++) {         if (lrt[i] == u) lrt[i] = v;         if (rrt[i] == u) rrt[i] = v;       }     }   } t[N << 2];   node _merge(node a, node b, int l, int r) {     node ret;     ret.ans = a.ans + b.ans;     for (int i = 1; i <= n; i++) ret.lrt[i] = a.lrt[i], ret.rrt[i] = b.rrt[i];     for (int i = 1; i <= n; i++) {       if (A[i][l] == A[i][r] && a.rrt[i] != b.lrt[i]) {         ret.trans(a.rrt[i], b.lrt[i]);         a.trans(a.rrt[i], b.lrt[i]);       }     }     return ret;   }   void build(int u, int l, int r) {     if (l == r) {       t[u].ans = n;       for (int i = 1; i <= n; i++) t[u].lrt[i] = t[u].rrt[i] = (l - 1) * n + i;       for (int i = 1; i <= n; i++)         if (A[i][l] == A[i - 1][l]) t[u].trans(t[u].lrt[i], t[u].lrt[i - 1]);       return;     }     int mid = (l + r) / 2;     build(u << 1, l, mid);     build(u << 1 | 1, mid + 1, r);     t[u] = _merge(t[u << 1], t[u << 1 | 1], mid, mid + 1);   }   node query(int u, int l, int r, int L, int R) {     if (l == L && r == R) return t[u];     int mid = (l + r) / 2;     if (R <= mid)       return query(u << 1, l, mid, L, R);     else if (L > mid)       return query(u << 1 | 1, mid + 1, r, L, R);     else       return _merge(query(u << 1, l, mid, L, mid),                     query(u << 1 | 1, mid + 1, r, mid + 1, R), mid, mid + 1);   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &A[i][j]);     build(1, 1, m);     while (q--) {       int l, r;       scanf( %d%d , &l, &r);       printf( %d n , query(1, 1, m, l, r).ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n, l[N], r[N], cnt[4 * N], one[4 * N];   vector<int> g;   map<int, int> mp;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> l[i] >> r[i];       g.push_back(l[i] - 1);       g.push_back(l[i]);       g.push_back(r[i]);       g.push_back(r[i] + 1);     }     sort(g.begin(), g.end());     for (int i = 0, cnt = 0; i < g.size(); ++i) {       if (!i || g[i] != g[i - 1]) cnt++;       mp[g[i]] = cnt;     }     for (int i = 1; i <= n; ++i) {       cnt[mp[l[i]]]++;       cnt[mp[r[i] + 1]]--;     }     for (int i = 1; i <= 4 * n; ++i) {       cnt[i] += cnt[i - 1];       if (cnt[i] == 1) {         one[i] = 1;       }       one[i] += one[i - 1];     }     for (int i = 1; i <= n; ++i) {       if (one[mp[r[i]]] == one[mp[l[i] - 1]]) {         cout << i <<   n ;         return 0;       }     }     cout <<  -1 n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class temp>   inline void Rd(temp &p) {     p = 0;     char c;     while (c = getchar(), c < 48)       ;     do p = p * 10 + (c & 15);     while (c = getchar(), c > 47);   }   int pow(int n, int m) {     int ans = 1;     while (m) {       if (m & 1) ans = 1ll * ans * n % 1000000007;       m >>= 1;       n = 1ll * n * n % 1000000007;     }     return ans;   }   int head[100005], tot = 0;   struct eg {     int v, col, nxt;   } E[100005 << 1];   void add_edge(int u, int v, int w) {     E[++tot] = (eg){v, w, head[u]};     head[u] = tot;     E[++tot] = (eg){u, w, head[v]};     head[v] = tot;   }   int col[100005];   bool dfs(int u) {     for (int j = head[u]; j; j = E[j].nxt) {       int v = E[j].v, c = E[j].col;       if (!~col[v]) {         col[v] = col[u] ^ c ^ 1;         if (!dfs(v)) return false;       } else {         if ((col[u] ^ c ^ 1) != col[v]) return false;       }     }     return true;   }   int main() {     int n, m;     Rd(n), Rd(m);     for (int i = 1; i <= m; i++) {       int u, v, w;       Rd(u), Rd(v), Rd(w);       add_edge(u, v, w);     }     memset(col, -1, sizeof(col));     int sz = 0;     for (int i = 1; i <= n; i++)       if (!~col[i]) {         col[i] = 0;         if (!dfs(i)) {           puts( 0 );           return 0;         }         ++sz;       }     printf( %d n , pow(2, sz - 1));   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6;   const long long LINF = 1e18;   long long int n, cnt = 0, ans = 0, a, b, c, d, cmp[ohara], cmpp, m, h, w, x, y,                    sum[ohara], pos;   int dy[] = {1, 0, -1, 0};   int dx[] = {0, 1, 0, -1};   string alph( abcdefghijklmnopqrstuvwxyz ), s;   bool fl = true;   struct edge {     int to, cost;   };   int main(void) {     cin.tie(0);     ios::sync_with_stdio(false);     cin >> n >> c;     for (long long int(i) = 0; (i) < (int)(n); (i)++) {       cin >> a >> b;       if (a > b) {         pos = b;         b = a;         a = pos;       }       sum[a]++;       sum[b + 1]--;     }     for (long long int i = (1); i < (9999); i++) {       sum[i] += sum[i - 1];     }     for (long long int(i) = 0; (i) < (int)(9999); (i)++) {       if (sum[i] == n) {         cmp[cnt] = i;         cnt++;         fl = false;       }     }     if (fl) {       cout << (-1) << endl;       return 0;     }     ans = INF;     for (long long int(i) = 0; (i) < (int)(cnt); (i)++) {       ans = min(ans, max(cmp[i], c) - min(cmp[i], c));     }     cout << (ans) << endl;     return 0;   }


# include <bits/stdc++.h>   using namespace std;            int main(){    ios::sync_with_stdio(false);    int t;    cin>>t;    while(t--){     int n,m;     cin>>n>>m;     int ans=0;     int a[101]={0};     for(int i=0; i<n;i++){      int x;      cin>>x;      a[x]=1;     }     for(int i=0;i<m;i++){      int x;      cin>>x;      if(a[x]==1)       ans++;     }     cout<<ans<<  n ;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, ans, last, d, x, y, a, b;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   void exgcd(long long a, long long b, long long& d, long long& x, long long& y) {     if (!b) {       x = 1, y = 0, d = a;     } else {       exgcd(b, a % b, d, y, x);       y -= (a / b) * x;     }   }   void check(long long x0, long long y0) {     exgcd(a, b, d, x, y);     if ((y0 - x0) % d != 0) return;     long long tmp = abs(b / d);     x *= (y0 - x0) / d;     x = (x % tmp + tmp) % tmp;     long long xx = x0 + 2 * n * x;     if (xx < 0 || xx >= last) return;     ans = min(ans, xx);   }   int main() {     cin >> n >> m >> k;     a = 2 * n, b = -2 * m;     while (k--) {       long long xx, yy;       cin >> xx >> yy;       ans = 1e18;       last = n / gcd(n, m) * m;       check(xx, yy);       check(-xx, yy);       check(xx, -yy);       check(-xx, -yy);       if (ans == 1e18)         cout << -1 << endl;       else         cout << ans << endl;     }   }


#include<bits/stdc++.h>   using namespace std;   using ll = long long;   const ll nax = 1e5 + 69;   int n;   vector<ll>possible;   void fun(ll *a,int l,int r,ll *pref){    if(l>r || l<0 || r>n)     return;    possible.push_back(pref[r+1]-pref[l]);    if(a[r]==a[l])     return;    int mid = (a[l] + a[r])/2;    int ind = lower_bound(a,a+n,mid+1)-a;    fun(a,l,ind-1,pref);    fun(a,ind,r,pref);   }   int main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);       int t;       cin>>t;       while(t--)       {         int q;           cin>>n>>q;           ll a[n];           ll pref[n+1];           pref[0] = 0;           for (int i = 0; i < n; ++i)            cin>>a[i];           sort(a,a+n);           for (int i = 0; i < n; ++i)            pref[i+1] = pref[i] + a[i];           fun(a,0,n-1,pref);           sort(possible.begin(),possible.end());           //for (auto i : possible)           // cout<<i<<   ;           //cout<<endl;           while(q--){            ll s;            cin>>s;            auto it = lower_bound(possible.begin(),possible.end(),s);            if(it!=possible.end() && *it==s)             cout<< Yes n ;            else             cout<< No n ;           }           possible.clear();       }           return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 101010 * 2;   vector<int> vec[maxn];   vector<int> mp[maxn];   bool vis[maxn];   int arr[maxn];   int dfs(int x) {     vis[x] = true;     int ans = vec[x].size();     int siz = mp[x].size();     for (int i = 0; i < siz; i++) {       int y = mp[x][i];       if (vis[y]) continue;       ans = max(ans, dfs(y));     }     return ans;   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       vec[arr[i]].push_back(i);     }     int ans = 0, las = 0, pos = 0;     int maxv = 0;     for (int i = 1; i <= n; i++) {       if (las != arr[i] && las) {         if (vec[arr[i]][0] < pos || maxv > i)           mp[arr[i]].push_back(las), mp[las].push_back(arr[i]);       }       las = arr[i], pos = i;       int siz = vec[arr[i]].size();       maxv = max(maxv, vec[arr[i]][siz - 1]);     }     for (int i = 1; i <= n; i++) {       if (vis[i]) continue;       ans += dfs(i);     }     printf( %d n , n - ans);   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int n) {     if (n == 1) {       return (a);     }     if (n == 0) {       return 1;     }     long long int c = power(a, n / 2);     if (n % 2 == 0) {       return (c * c);     } else {       return c * c * a;     }   }   long long int func(int n, long long int k) {     long long int x = power(2, n - 1);     if (n == 1) return 1;     if (k == x) {       return n;     }     if (k < x) {       return func(n - 1, k);     } else {       return func(n - 1, k - x);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     long long int k;     cin >> n >> k;     cout << func(n, k) << endl;   }


#include <bits/stdc++.h>   int main() {     int n, m, p, q, a, b;     scanf( %d %d %d %d , &n, &m, &p, &q);     scanf( %d %d , &a, &b);     int u = q - m, v = p - n;     if (u < 0) u = -u;     if (v < 0) v = -v;     if ((u) % b == 0 && (v) % a == 0) {       int c = u / b - v / a;       if (c < 0) c = -c;       if (c % 2 == 0)         printf( YES n );       else         printf( NO n );     } else       printf( NO n );   }


#include <bits/stdc++.h>   int cal(int x) {     int sum = 0;     for (int i = 1; i < x; i++) {       sum = sum + i;     }     return sum;   };   char x[101][101];   using namespace std;   int main() {     int n, c1 = 0, c2 = 0, total1 = 0, total2 = 0;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> x[i][j];         if (x[i][j] ==  C ) c1++;       }       total1 = total1 + cal(c1);       c1 = 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (x[j][i] ==  C ) c2++;       }       total2 = total2 + cal(c2);       c2 = 0;     }     cout << total1 + total2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void action() {     string s;     cin >> s;     reverse(s.begin(), s.end());     long long c = 0, f = 0, j;     for (long long i = 0; i < s.length(); i++) {       if (s[i] ==  1 ) {         f++;       }       if (i % 2 == 0) c++;     }     if (f > 1)       cout << c;     else {       if ((s.length()) % 2 == 0)         cout << c;       else         cout << c - 1;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     action();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     int n, k;     std::cin >> n >> k;     int s[n + 1];     for (int i = 1; i < n + 1; ++i) {       std::cin >> s[i];     }     if (k >= n)       std::cout << s[n];     else {       int max = s[n];       for (int i = 1; i <= (n - k); ++i) {         int temp = s[i] + s[2 * (n - k) + 1 - i];         if (max < temp) {           max = temp;         }       }       std::cout << max;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long inf = 1e18;   const long long N = 2e2 + 5;   long long n;   long long a[N];   void solve(long long id) {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long odd = 0, even = 0;     long long oddind = 0, evenind = 0;     for (long long i = 0; i < n; i++) {       if (i % 2 != a[i] % 2) {         if (i % 2) {           oddind++;           even++;         } else {           evenind++;           odd++;         }       }     }     if (oddind == odd) {       cout << odd << endl;     } else       cout <<  -1  << endl;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     cin >> t;     for (long long i = 1; i <= t; i++) solve(i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int tt = 0; tt < int(t); tt++) {       int n;       cin >> n;       map<int, int> c;       for (int i = 0; i < int(n); i++) {         int pi;         cin >> pi;         c[-pi]++;       }       vector<int> pp;       for (auto p : c) pp.push_back(p.second);       bool ok = false;       int g = pp[0];       int i = 1;       int s = 0;       while (s <= g && i < pp.size()) s += pp[i++];       if (g < s) {         int b = 0;         while (b <= g && i < pp.size()) b += pp[i++];         while (i < pp.size() && g + s + b + pp[i] <= n / 2) b += pp[i++];         if (g < b && g + s + b <= n / 2) {           ok = true;           cout << g <<     << s <<     << b << endl;         }       }       if (!ok) cout << 0 <<     << 0 <<     << 0 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     for (int i = 0; i < n / 4; i++) {       cout <<  bbaa ;     }     if (n % 4 == 1) {       cout <<  b ;     }     if (n % 4 == 2) {       cout <<  bb ;     }     if (n % 4 == 3) {       cout <<  bba ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, kol = 0, sum = 0, a;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a;       if (sum + a > m) {         kol++;         sum = a;       } else         sum += a;     }     cout << kol + 1;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   vector<int> v[maxn];   pair<long long, long long> a[maxn];   long long q[maxn], siz[maxn];   bool c[maxn];   long long n, m, k;   set<pair<long long, long long> > s;   map<pair<long long, long long>, bool> mark;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> k;     for (long long y = 0; y < m; y++) {       cin >> a[y].first >> a[y].second;       v[a[y].first].push_back(a[y].second), v[a[y].second].push_back(a[y].first);       siz[a[y].second]++, siz[a[y].first]++;     }     for (long long y = 1; y <= n; y++)       s.insert(pair<long long, long long>(siz[y], y));     for (long long y = m - 1; y >= 0; y--) {       if (y != m - 1 && !mark[a[y + 1]]) {         mark[pair<long long, long long>(a[y + 1].second, a[y + 1].first)] =             mark[pair<long long, long long>(a[y + 1].first, a[y + 1].second)] = 1;         long long i = a[y + 1].second;         siz[i]--;         if (c[i] == 0) {           pair<long long, long long> x =               pair<long long, long long>(siz[i] + 1, i);           s.erase(x);           x.first--;           s.insert(x);         }         i = a[y + 1].first;         siz[i]--;         if (c[i] == 0) {           pair<long long, long long> x =               pair<long long, long long>(siz[i] + 1, i);           s.erase(x);           x.first--;           s.insert(x);         }       }       while (s.size() != 0) {         pair<long long, long long> x = *s.begin();         if (x.first >= k) break;         s.erase(x);         c[x.second] = 1;         for (long long ii = 0; ii < v[x.second].size(); ii++) {           long long i = v[x.second][ii];           if (!mark[pair<long long, long long>(x.second, i)]) {             mark[pair<long long, long long>(x.second, i)] =                 mark[pair<long long, long long>(i, x.second)] = 1;             siz[i]--;             siz[x.second]--;             if (!c[i]) {               pair<long long, long long> z =                   pair<long long, long long>(siz[i] + 1, i);               s.erase(z);               z.first--;               s.insert(z);             }           }         }       }       q[y] = s.size();     }     for (long long y = 0; y < m; y++) cout << q[y] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int dep[100005], present[100005];   int main() {     int n, p;     scanf( %d , &n);     for (int i = 2; i <= n; ++i) {       scanf( %d , &p);       present[dep[i] = dep[p] + 1] ^= 1;     }     printf( %d n , accumulate(present, present + n + 1, 1));   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int cnt[maxn];   int check(int k) {     if (k == 0) return 1;     long long d = 1, ans = maxn;     while (d < maxn) d <<= 1;     while (d >>= 1)       if (ans - d >= 0)         if ((ans - d) * (ans - d - 1) >= 2 * k) ans -= d;     if (ans * (ans - 1) != 2 * k) return -1;     return ans;   }   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     int aa = check(a), dd = check(d);     if (aa == -1 || dd == -1) return cout <<  Impossible  << endl, 0;     bool safe = false;     if (aa == 1 || dd == 1) {       if (b + c == 0) safe = true;     }     if (!safe && (b + c) != aa * dd) return cout <<  Impossible  << endl, 0;     if (safe) {       if (aa == 1) aa = 0;       if (dd == 1) dd = 0;     }     if (aa == 0) {       if (dd == 0) dd = 1;       for (int i = 0; i < dd; ++i) cout << 1;       return 0;     }     if (dd == 0) {       if (aa == 0) aa = 1;       for (int i = 0; i < aa; ++i) cout << 0;       return 0;     }     int f = dd - (b + aa - 1) / aa;     for (int i = 0; i < f; ++i) cout << 1;     int m = b % aa;     for (int i = 0; i < aa; ++i) {       if (m && i == m) cout << 1;       cout << 0;     }     f = b / aa;     for (int i = 0; i < f; ++i) cout << 1;     return 0;   }


#include  bits/stdc++.h    using namespace std;   #define int  long long   #define yes  YES n    #define no  NO n    const int M = 1000000007;      signed main(){       ios_base::sync_with_stdio(0);cin.tie(0);       int T;       cin >> T;       //T = 1;       while(T--){               int n, k;               cin >> n >> k;               int r;               cout << 0 << endl;               cin >> r;               if(r!=1){                   for(int i = 1;i <= n-1;i++){                       cout << (i^(i-1)) << endl;                       cin >> r;                       if(r==1)                           break;                   }               }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     int arr[n];     for (int i = (int)(0); i <= (int)(n - 1); i++) {       cin >> arr[i];     }     int hash1[100005] = {0};     for (int i = (int)(0); i <= (int)(n / 2 - 1); i++) {       if (arr[i] - i > 0) hash1[arr[i] - i]++;     }     for (int i = (int)(n / 2); i <= (int)(n - 1); i++) {       if (arr[i] - (n - i - 1) > 0) hash1[arr[i] - (n - i - 1)]++;     }     int cnt = 0, val = 0;     for (int i = (int)(1); i <= (int)(100000); i++) {       if (cnt < hash1[i]) {         cnt = hash1[i];         val = i;       }     }     cout << n - cnt <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int MaxN = 3e5 + 5;   map<int, int> mp;   struct node {     int x, y;   } arr[MaxN], brr[MaxN];   struct qnode {     int x, y;     bool operator>(const qnode &p) const { return p.y > y; }   } st;   bool cmp(node b, node c) {     if (b.x == c.x) return b.y < c.y;     return b.x < c.x;   }   int main() {     int n, m, u, v, pp;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &pp), mp[pp] = i;     int x = -1, y = inf;     for (int i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       arr[i].x = min(mp[u], mp[v]);       arr[i].y = max(mp[u], mp[v]);     }     sort(arr, arr + m, cmp);     priority_queue<qnode, vector<qnode>, greater<qnode> > pq;     for (int i = 0; i < m; i++) {       if (pq.empty()) {         st.x = arr[i].x, st.y = arr[i].y;         pq.push(st);         continue;       }       while (!pq.empty() && arr[i].y <= pq.top().y) {         pq.pop();       }       st.x = arr[i].x, st.y = arr[i].y;       pq.push(st);     }     int num = 0;     while (!pq.empty()) {       st = pq.top();       pq.pop();       brr[num].x = st.x, brr[num].y = st.y, num++;     }     long long p = (long long)(brr[num - 1].x) * (n - brr[num - 1].y + 1);     for (int i = num - 1; i >= 1; i--)       p += (long long)(brr[i - 1].x - brr[i].x) * (n - brr[i - 1].y + 1);     long long ans = (long long)n + (long long)n * (n - 1) / 2;     printf( %I64d n , ans - p);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline void chkmin(T1 &x, T2 y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   inline void chkmax(T1 &x, T2 y) {     if (x < y) x = y;   }   inline int readChar();   template <class T = int>   inline T readInt();   template <class T>   inline void writeInt(T x, char end = 0);   inline void writeChar(int x);   inline void writeWord(const char *s);   static const int buf_size = 4096;   inline int getChar() {     static char buf[buf_size];     static int len = 0, pos = 0;     if (pos == len) {       pos = 0, len = fread(buf, 1, buf_size, stdin);     }     if (pos == len) {       return -1;     }     return buf[pos++];   }   inline int readChar() {     int c = getChar();     while (c <= 32) {       c = getChar();     }     return c;   }   template <class T>   inline T readInt() {     int s = 1, c = readChar();     T x = 0;     if (c ==  - ) s = -1, c = getChar();     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     return s == 1 ? x : -x;   }   static int write_pos = 0;   static char write_buf[buf_size];   inline void writeChar(int x) {     if (write_pos == buf_size)       fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;     write_buf[write_pos++] = x;   }   template <class T>   inline void writeInt(T x, char end) {     if (x < 0) writeChar( - ), x = -x;     char s[24];     int n = 0;     while (x || !n) s[n++] =  0  + x % 10, x /= 10;     while (n--) writeChar(s[n]);     if (end) writeChar(end);   }   inline void writeWord(const char *s) {     while (*s) writeChar(*s++);   }   struct Flusher {     ~Flusher() {       if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;     }   } flusher;   using namespace std;   const int MAXN = 100228;   int n, m;   int a[MAXN], ans[MAXN], lp[MAXN];   vector<pair<int, int> > vq[MAXN];   int main() {     n = readInt(), m = readInt();     for (int i = 0; i < n; ++i) {       lp[i] = -1;     }     for (int i = 0; i < m; ++i) {       int l = readInt(), r = readInt();       l--, r--;       lp[r] = l;     }     int q = readInt();     for (int i = 0; i < q; ++i) {       int x = readInt(), y = readInt();       x--, y--;       vq[y].push_back({x, i});     }     for (int i = 0; i < n; ++i) {       a[i] = i;     }     for (int i = 0; i < n; ++i) {       int x = lp[i];       for (int j = 0; j <= x; ++j) {         a[j] = a[j] >= x ? i : a[j];       }       for (auto p : vq[i]) {         ans[p.second] = a[p.first];       }     }     for (int i = 0; i < q; ++i) {       writeInt(ans[i] + 1,   n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   long long n;   int main() {     cin >> n;     if (n == 1) {       cout << 0;       return 0;     }     cout << n / 2 - 1 + (n % 2 != 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     int arr[n], brr[m];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i < m; i++) {       cin >> brr[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (arr[i] == brr[j]) {           cout <<  YES  <<   n ;           cout << 1 <<     << arr[i] <<   n ;           return;         }       }     }     cout <<  NO  <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     int t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   void i1d(vector<long long> &v) {     for (auto &i : v) cin >> i;   }   void p1d(vector<long long> &v) {     for (auto i : v) cout << i <<    ;     cout << endl;   }   long long t;   void solve() {     cin >> t;     while (t--) {       long long n;       cin >> n;       string s;       cin >> s;       set<long long> o, z;       map<long long, long long> ans;       for (long long i = 0; i <= n - 1; i++) {         if (s[i] ==  0 )           z.insert(i);         else           o.insert(i);       }       long long ctr = 0;       long long ptr1 = 0, ptr2 = 0;       for (long long i = 0; i <= n - 1; i++) {         if (s[i] ==  0 ) {           auto it = o.upper_bound(i);           if (ans.count(i) == 0) ans[i] = ++ctr;           if (it != o.end()) {             ans[*it] = ans[i];             o.erase(it);           }         } else {           auto it = z.upper_bound(i);           if (ans.count(i) == 0) ans[i] = ++ctr;           if (it != z.end()) {             ans[*it] = ans[i];             z.erase(it);           }         }       }       cout << ctr <<   n ;       for (long long i = 0; i <= n - 1; i++) {         cout << ans[i] <<    ;       }       cout <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     solve();   }