#include <bits/stdc++.h>   using namespace std;                               const int N=2e5+7;      int n;   int x=-1,y=-1,z=-1;          int a[N], t[N*4];   vector<int> suff(N), pref(N);       void build(int v=1, int tl=1, int tr=n){     if(tl==tr) t[v]=a[tl];     else {       int tm = (tl+tr)/ 2;       build(v*2, tl, tm);       build(v*2+1,tm+1,tr);       t[v]=min(t[v*2], t[v*2+1]);     }   }   int get(int v, int tl, int tr, int l, int r){     if(l<=tl and tr<=r) return t[v];     if(r < tl || tr< l) return INT_MAX;     int tm=(tl + tr)>>1;     return min(get(v*2, tl, tm, l, r), get(v*2+1, tm+1,tr,l,r));   }   void calc(){     pref[1]=a[1];     for(int i=2;i<=n;i++) pref[i]=max(pref[i-1], a[i]);     suff[n]=a[n];     for(int i=n-1;i>=1;i--) suff[i]=max(suff[i+1], a[i]);   }   int main(){     ios_base::sync_with_stdio(false);     cin.tie(0);     int tt;     cin>>tt;     while(tt--){            cin>>n;                        for(int i = 1; i <= n; i++) cin>>a[i];       build();      calc();      bool flag=false;      int x, y, z;      for(int i=n;i>=3;i--){       int value = suff[i];       auto j1 = lower_bound(pref.begin(), pref.begin()+i-1, value);        int start = j1 - pref.begin();          auto j2 = upper_bound(pref.begin(), pref.begin()+i-1, value);       int end = j2 - pref.begin();       //cout<<start<<     <<end<<   ;       if(start >= end) continue;              int low= start, high=end;       while(high - low > 1) {         int mid = (low + high) / 2;         if (get(1,1,n,mid, i-1)<value) {           low=mid;         } else {           high=mid;         }       }       //cout<<     << high <<   n ;       if (high < i and get(1,1,n,high,i-1) == value and pref[high-1] == value) {        x = high-1;        y = i-high;        z = n-i+1;         flag=true;       }      }      if(!flag)       cout<< NO n ;      else       cout<< YES n <<x<<     << y <<     << z <<  n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int x;     cin >> x;     if (x % 4 == 0)       printf( 1 A );     else if (x % 4 == 1)       printf( 0 A );     else if (x % 4 == 2)       printf( 1 B );     else if (x % 4 == 3)       printf( 2 A );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, a, b, flag = 0, check = 1;     cin >> n >> a >> x >> b >> y;     for (int i = a, j = b; check != 0; i++, j--) {       if (i == n + 1) {         i = 1;       }       if (j == 0) {         j = n;       }       if (i == j) {         flag = 1;         break;       }       if (i == x || j == y) {         check = 0;       }     }     if (flag == 1) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     cout << 9 * n <<     << 8 * n <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1005][10];   int main() {     int n, s = 0;     cin >> n;     for (int i = 0; i < n; i++) {       int c = 0;       for (int j = 0; j < 3; j++) {         cin >> a[i][j];         if (a[i][j]) c++;       }       if (c >= 2) s++;     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int n = 5e5, f[N], s[N];   vector<int> v[N];   int q, a[N], c[N];   int main() {     int i, j, t;     long long ans;     for (i = 1; i <= n; i = i + 1) {       if (i == 1) f[i] = 1;       for (j = i; j <= n; j = j + i) {         v[j].push_back(i);         if (j > i) f[j] -= f[i];       }     }     scanf( %d%d , &n, &q);     for (i = 1; i <= n; i = i + 1) scanf( %d , a + i);     ans = 0;     while (q--) {       scanf( %d , &i);       t = v[a[i]].size();       if (c[i]) {         c[i] = 0;         i = a[i];         for (j = 0; j < t; j = j + 1) ans -= f[v[i][j]] * (--s[v[i][j]]);       } else {         c[i] = 1;         i = a[i];         for (j = 0; j < t; j = j + 1) ans += f[v[i][j]] * (s[v[i][j]]++);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Line {     double kx;     double b;     double x1;     double x2;   };   double CONST = pow(10, 12);   long long n, k, ai;   double bi;   vector<double> pre, summ, resumm;   vector<double> data;   double intersec(Line f, Line s) { return (s.b - f.b) / (f.kx - s.kx); }   long long bs(double number, vector<Line> &v) {     long long l = 0;     long long r = v.size();     while (r - l > 1) {       long long m = (l + r) / 2;       if (v[m].x1 <= number)         l = m;       else         r = m;     }     return l;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     double s1 = 0, s2 = 0, s3 = 0;     for (long long i = 0; i < n; i++) {       cin >> ai;       bi = ai;       s1 += bi;       s2 += s1 / bi;       s3 += 1 / bi;       data.push_back(bi);       pre.push_back(s2);       summ.push_back(s1);       resumm.push_back(s3);     }     vector<double> answers;     for (long long i = 0; i < n; i++) {       answers.push_back(pre[i]);     }     for (long long p = 1; p < k; p++) {       vector<Line> st;       vector<double> na;       for (long long i = 0; i < answers.size() - 1; i++) {         Line ll;         ll.kx = -summ[i + p - 1];         ll.b = summ[i + p - 1] * resumm[i + p - 1] + answers[i] - pre[i + p - 1];         while (st.size() > 0) {           double t = intersec(ll, st.back());           if (t <= st.back().x1) {             st.pop_back();           } else {             st.back().x2 = t;             break;           }         }         ll.x2 = CONST;         if (st.size() == 0)           ll.x1 = 0;         else           ll.x1 = st.back().x2;         st.push_back(ll);         long long ind = bs(resumm[i + p], st);         double an = pre[i + p] + st[ind].kx * resumm[i + p] + st[ind].b;         na.push_back(an);       }       answers = na;     }     cout.precision(30);     cout << answers.back() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int x, y, z;     cin >> x >> y >> z;     if (x > 0) {       cout <<  0 ;       for (int i = 1; i <= x; i++) cout <<  0 ;     }     if (y > 0) {       if (x == 0) cout <<  0 ;       cout <<  1 ;       y--;     } else if (z > 0 && y == 0 && x == 0) {       cout <<  1 ;     }     for (int i = 1; i <= z; i++) cout <<  1 ;     int m = 0;     while (y > 0) {       cout << m;       if (m == 0)         m = 1;       else         m = 0;       y--;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t > 0) {       solve();       t -= 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   const int oo = maxn;   int n;   int a[maxn], b[maxn], c[maxn], it[maxn * 8], itmin[maxn * 8];   int findit(int u, int v, int l, int r, int i) {     if (r < u || v < l) return oo;     if (u <= l && r <= v) {       return (itmin[i]);     }     int mid = (l + r) >> 1;     return (         min(findit(u, v, l, mid, i * 2), findit(u, v, mid + 1, r, i * 2 + 1)));   }   void updateit(int u, int w, int l, int r, int i) {     if (r < u || u < l) return;     if (u == l && u == r) {       it[i] += w;       if (it[i] == 0)         itmin[i] = oo;       else         itmin[i] = u;       return;     }     int mid = (l + r) >> 1;     updateit(u, w, l, mid, i * 2);     updateit(u, w, mid + 1, r, i * 2 + 1);     if (it[i * 2] == 0) {       it[i] = it[i * 2 + 1];       itmin[i] = itmin[i * 2 + 1];       return;     }     if (it[i * 2 + 1] == 0) {       it[i] = it[i * 2];       itmin[i] = itmin[i * 2];       return;     }     it[i] = it[i * 2] + it[i * 2 + 1];     itmin[i] = min(itmin[i * 2], itmin[i * 2 + 1]);   }   void nhap() {     cin >> n;     for (int i = 1; i <= n; i++) {       updateit(i, 0, 1, n, 1);     }     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i] %= n;     }     for (int i = 1; i <= n; i++) {       cin >> b[i];       b[i] %= n;       updateit(b[i] + 1, 1, 1, n, 1);     }   }   void xuli() {     for (int i = 1; i <= n; i++) c[i] = -1;     for (int i = 1; i <= n; i++) {       int x = n - a[i];       int j = findit(x + 1, n, 1, n, 1);       if (j != oo) {         c[i] = (a[i] + j - 1) % n;         updateit(j, -1, 1, n, 1);         continue;       } else {         j = findit(1, n, 1, n, 1);         c[i] = (a[i] + j - 1) % n;         updateit(j, -1, 1, n, 1);         continue;       }     }     for (int i = 1; i <= n; i++) {       cout << c[i] <<    ;     }   }   int main() {     nhap();     xuli();   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int neg = 1, num = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) neg = -1;     for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c -  0 ;     return neg * num;   }   struct node {     int x, y;   } p[6000010];   int n, m, cnt, a[2010], b[2010], c[2010], d[2010], suf[6000010];   int ans = 2147483647;   bool cmp(node f, node g) { return f.x == g.x ? f.y < g.y : f.x < g.x; }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++)       a[i] = read(), b[i] = read(), p[i].x = 0, p[i].y = 0;     for (int i = 1; i <= m; i++) c[i] = read(), d[i] = read();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         p[++cnt].x = max(0, c[j] - a[i] + 1);         p[cnt].y = max(0, d[j] - b[i] + 1);       }     sort(p + 1, p + cnt + 1, cmp);     suf[cnt] = p[cnt].y;     for (int i = cnt - 1; i >= 1; i--) suf[i] = max(suf[i + 1], p[i].y);     int pos = 0;     for (int i = 0; i <= 1e6; i++) {       while (p[pos + 1].x <= i && pos < cnt) pos++;       ans = min(ans, i + suf[pos + 1]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int x, y, t;     Node(int x = -1, int y = -1, int t = 0) : x(x), y(y) {}   };   Node a[1005];   string G[1005];   int row[1005], col[1005];   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> G[i];       G[i] =     + G[i];     }     memset(row, 0, sizeof(row));     memset(col, 0, sizeof(col));     int cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (G[i][j] ==  * ) {           row[i]++;           col[i]++;           int flag = 0;           for (int k = 0; k < cnt; k++) {             if (a[k].x == i || a[k].y == j) {               flag = 1;               if (a[k].x == i)                 a[k].t = -a[k].x;               else if (a[k].y == j)                 a[k].t = a[k].y;               break;             }           }           if (!flag && cnt < 10) a[cnt++] = Node(i, j);         }       }     }     int cntr = 0, cntc = 0;     for (int i = 1; i <= n; i++) {       if (row[i] > 1) cntr++;     }     for (int i = 1; i <= m; i++) {       if (col[i] > 1) cntc++;     }     if (cnt > 2 || cntr > 1 || cntc > 1)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       if (cnt == 0)         cout << 1 <<     << 1 << endl;       else if (cnt == 1)         cout << a[0].x <<     << a[0].y << endl;       else {         if (a[0].t != 0 && a[1].t != 0) {           int x, y;           if (a[0].t > 0)             x = -a[1].t, y = a[0].t;           else             x = -a[0].t, y = a[1].t;           cout << x <<     << y << endl;         } else if (a[0].t != 0) {           if (a[0].t > 0)             cout << a[1].x <<     << a[0].y << endl;           else             cout << a[0].x <<     << a[1].y << endl;         } else if (a[1].t != 0) {           if (a[1].t < 0)             cout << a[1].x <<     << a[0].y << endl;           else             cout << a[0].x <<     << a[1].y << endl;         } else {           cout << a[0].x <<     << a[1].y << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 17;   vector<int> adj[N];   int n, k;   int cnt[N];   bool mark[N];   long long int ans = 0;   int findCentroid(int v, int n, int &ans, int par = -1) {     int sum = 1;     int mx = 0;     for (int u : adj[v]) {       if (u != par && !mark[u]) {         int x = findCentroid(u, n, ans, v);         sum += x;         mx = max(mx, x);       }     }     mx = max(mx, n - sum);     if (mx <= n / 2) {       ans = v;     }     return sum;   }   int getSubTreeSize(int v, int par = -1) {     int res = 1;     for (int u : adj[v]) {       if (par != u && !mark[u]) {         res += getSubTreeSize(u, v);       }     }     return res;   }   void addToCnt(int v, int plus, int depth = 1, int par = -1) {     if (depth > k) return;     cnt[depth] += plus;     for (int u : adj[v]) {       if (u != par && !mark[u]) {         addToCnt(u, plus, depth + 1, v);       }     }   }   void findMiddleCentroidPaths(int v, int depth = 1, int par = -1) {     if (k - depth >= 0) ans += cnt[k - depth];     for (int u : adj[v]) {       if (u != par && !mark[u]) {         findMiddleCentroidPaths(u, depth + 1, v);       }     }   }   void findBeginCentroidPaths(int v, int depth = 0, int par = -1) {     if (depth == k) {       ans++;       return;     }     for (int u : adj[v]) {       if (u != par && !mark[u]) {         findBeginCentroidPaths(u, depth + 1, v);       }     }   }   void centroidDecomposition(int root, int siz) {     int centroid;     findCentroid(root, siz, centroid);     mark[centroid] = true;     findBeginCentroidPaths(centroid);     for (int v : adj[centroid]) {       if (mark[v]) continue;       findMiddleCentroidPaths(v);       addToCnt(v, +1);     }     for (int v : adj[centroid]) {       if (mark[v]) continue;       addToCnt(v, -1);     }     for (int v : adj[centroid]) {       if (!mark[v]) {         centroidDecomposition(v, getSubTreeSize(v));       }     }     mark[centroid] = false;   }   int main() {     cin >> n >> k;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       adj[v].push_back(u);       adj[u].push_back(v);     }     centroidDecomposition(0, n);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   char a[105][105];   int main() {     ios::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) cout << a[j][i] << a[j][i];       cout << endl;       for (int j = 1; j <= m; j++) cout << a[j][i] << a[j][i];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long;   using pint = pair<int, int>;   using plint = pair<lint, lint>;   struct fast_ios {     fast_ios() {       cin.tie(nullptr), ios::sync_with_stdio(false),           cout << fixed << setprecision(20);     };   } fast_ios_;   template <typename T, typename V>   void ndarray(vector<T> &vec, const V &val, int len) {     vec.assign(len, val);   }   template <typename T, typename V, typename... Args>   void ndarray(vector<T> &vec, const V &val, int len, Args... args) {     vec.resize(len),         for_each(begin(vec), end(vec), [&](T &v) { ndarray(v, val, args...); });   }   template <typename T>   bool chmax(T &m, const T q) {     return m < q ? (m = q, true) : false;   }   template <typename T>   bool chmin(T &m, const T q) {     return m > q ? (m = q, true) : false;   }   int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); }   template <typename T1, typename T2>   pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) {     return make_pair(l.first + r.first, l.second + r.second);   }   template <typename T1, typename T2>   pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) {     return make_pair(l.first - r.first, l.second - r.second);   }   template <typename T>   vector<T> sort_unique(vector<T> vec) {     sort(vec.begin(), vec.end()),         vec.erase(unique(vec.begin(), vec.end()), vec.end());     return vec;   }   template <typename T>   int arglb(const std::vector<T> &v, const T &x) {     return std::distance(v.begin(), std::lower_bound(v.begin(), v.end(), x));   }   template <typename T>   int argub(const std::vector<T> &v, const T &x) {     return std::distance(v.begin(), std::upper_bound(v.begin(), v.end(), x));   }   template <typename T>   istream &operator>>(istream &is, vector<T> &vec) {     for (auto &v : vec) is >> v;     return is;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &vec) {     os <<  [ ;     for (auto v : vec) os << v <<  , ;     os <<  ] ;     return os;   }   template <typename T, size_t sz>   ostream &operator<<(ostream &os, const array<T, sz> &arr) {     os <<  [ ;     for (auto v : arr) os << v <<  , ;     os <<  ] ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const deque<T> &vec) {     os <<  deq[ ;     for (auto v : vec) os << v <<  , ;     os <<  ] ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &vec) {     os <<  { ;     for (auto v : vec) os << v <<  , ;     os <<  } ;     return os;   }   template <typename T, typename TH>   ostream &operator<<(ostream &os, const unordered_set<T, TH> &vec) {     os <<  { ;     for (auto v : vec) os << v <<  , ;     os <<  } ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const multiset<T> &vec) {     os <<  { ;     for (auto v : vec) os << v <<  , ;     os <<  } ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) {     os <<  { ;     for (auto v : vec) os << v <<  , ;     os <<  } ;     return os;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {     os <<  (  << pa.first <<  ,  << pa.second <<  ) ;     return os;   }   template <typename TK, typename TV>   ostream &operator<<(ostream &os, const map<TK, TV> &mp) {     os <<  { ;     for (auto v : mp) os << v.first <<  =>  << v.second <<  , ;     os <<  } ;     return os;   }   template <typename TK, typename TV, typename TH>   ostream &operator<<(ostream &os, const unordered_map<TK, TV, TH> &mp) {     os <<  { ;     for (auto v : mp) os << v.first <<  =>  << v.second <<  , ;     os <<  } ;     return os;   }   template <int md>   struct ModInt {     using lint = long long;     static int mod() { return md; }     static int get_primitive_root() {       static int primitive_root = 0;       if (!primitive_root) {         primitive_root = [&]() {           std::set<int> fac;           int v = md - 1;           for (lint i = 2; i * i <= v; i++)             while (v % i == 0) fac.insert(i), v /= i;           if (v > 1) fac.insert(v);           for (int g = 1; g < md; g++) {             bool ok = true;             for (auto i : fac)               if (ModInt(g).pow((md - 1) / i) == 1) {                 ok = false;                 break;               }             if (ok) return g;           }           return -1;         }();       }       return primitive_root;     }     int val;     ModInt() : val(0) {}     ModInt &_setval(lint v) { return val = (v >= md ? v - md : v), *this; }     ModInt(lint v) { _setval(v % md + md); }     explicit operator bool() const { return val != 0; }     ModInt operator+(const ModInt &x) const {       return ModInt()._setval((lint)val + x.val);     }     ModInt operator-(const ModInt &x) const {       return ModInt()._setval((lint)val - x.val + md);     }     ModInt operator*(const ModInt &x) const {       return ModInt()._setval((lint)val * x.val % md);     }     ModInt operator/(const ModInt &x) const {       return ModInt()._setval((lint)val * x.inv() % md);     }     ModInt operator-() const { return ModInt()._setval(md - val); }     ModInt &operator+=(const ModInt &x) { return *this = *this + x; }     ModInt &operator-=(const ModInt &x) { return *this = *this - x; }     ModInt &operator*=(const ModInt &x) { return *this = *this * x; }     ModInt &operator/=(const ModInt &x) { return *this = *this / x; }     friend ModInt operator+(lint a, const ModInt &x) {       return ModInt()._setval(a % md + x.val);     }     friend ModInt operator-(lint a, const ModInt &x) {       return ModInt()._setval(a % md - x.val + md);     }     friend ModInt operator*(lint a, const ModInt &x) {       return ModInt()._setval(a % md * x.val % md);     }     friend ModInt operator/(lint a, const ModInt &x) {       return ModInt()._setval(a % md * x.inv() % md);     }     bool operator==(const ModInt &x) const { return val == x.val; }     bool operator!=(const ModInt &x) const { return val != x.val; }     bool operator<(const ModInt &x) const { return val < x.val; }     friend std::istream &operator>>(std::istream &is, ModInt &x) {       lint t;       return is >> t, x = ModInt(t), is;     }     friend std::ostream &operator<<(std::ostream &os, const ModInt &x) {       return os << x.val;     }     ModInt pow(lint n) const {       ModInt ans = 1, tmp = *this;       while (n) {         if (n & 1) ans *= tmp;         tmp *= tmp, n >>= 1;       }       return ans;     }     static std::vector<ModInt> facs, facinvs, invs;     static void _precalculation(int N) {       int l0 = facs.size();       if (N > md) N = md;       if (N <= l0) return;       facs.resize(N), facinvs.resize(N), invs.resize(N);       for (int i = l0; i < N; i++) facs[i] = facs[i - 1] * i;       facinvs[N - 1] = facs.back().pow(md - 2);       for (int i = N - 2; i >= l0; i--) facinvs[i] = facinvs[i + 1] * (i + 1);       for (int i = N - 1; i >= l0; i--) invs[i] = facinvs[i] * facs[i - 1];     }     lint inv() const {       if (this->val < std::min(md >> 1, 1 << 21)) {         while (this->val >= int(facs.size())) _precalculation(facs.size() * 2);         return invs[this->val].val;       } else {         return this->pow(md - 2).val;       }     }     ModInt fac() const {       while (this->val >= int(facs.size())) _precalculation(facs.size() * 2);       return facs[this->val];     }     ModInt facinv() const {       while (this->val >= int(facs.size())) _precalculation(facs.size() * 2);       return facinvs[this->val];     }     ModInt doublefac() const {       lint k = (this->val + 1) / 2;       return (this->val & 1)                  ? ModInt(k * 2).fac() / (ModInt(2).pow(k) * ModInt(k).fac())                  : ModInt(k).fac() * ModInt(2).pow(k);     }     ModInt nCr(const ModInt &r) const {       return (this->val < r.val)                  ? 0                  : this->fac() * (*this - r).facinv() * r.facinv();     }     ModInt nPr(const ModInt &r) const {       return (this->val < r.val) ? 0 : this->fac() * (*this - r).facinv();     }     ModInt sqrt() const {       if (val == 0) return 0;       if (md == 2) return val;       if (pow((md - 1) / 2) != 1) return 0;       ModInt b = 1;       while (b.pow((md - 1) / 2) == 1) b += 1;       int e = 0, m = md - 1;       while (m % 2 == 0) m >>= 1, e++;       ModInt x = pow((m - 1) / 2), y = (*this) * x * x;       x *= (*this);       ModInt z = b.pow(m);       while (y != 1) {         int j = 0;         ModInt t = y;         while (t != 1) j++, t *= t;         z = z.pow(1LL << (e - j - 1));         x *= z, z *= z, y *= z;         e = j;       }       return ModInt(std::min(x.val, md - x.val));     }   };   template <int md>   std::vector<ModInt<md>> ModInt<md>::facs = {1};   template <int md>   std::vector<ModInt<md>> ModInt<md>::facinvs = {1};   template <int md>   std::vector<ModInt<md>> ModInt<md>::invs = {0};   using mint = ModInt<998244353>;   template <int LEN, class S, S (*op)(S, S), class F, S (*reversal)(S),             S (*mapping)(F, S), F (*composition)(F, F), F (*id)()>   struct lazy_rbst {     inline uint32_t _rand() {       static uint32_t x = 123456789, y = 362436069, z = 521288629, w = 88675123;       uint32_t t = x ^ (x << 11);       x = y;       y = z;       z = w;       return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));     }     struct Node {       Node *l, *r;       S val, sum;       F lz;       bool is_reversed;       int sz;       Node(const S &v)           : l(nullptr),             r(nullptr),             val(v),             sum(v),             lz(id()),             is_reversed(false),             sz(1) {}       Node() : l(nullptr), r(nullptr), lz(id()), is_reversed(false), sz(0) {}       template <class OStream>       friend OStream &operator<<(OStream &os, const Node &n) {         os <<  [ ;         if (n.l) os << *(n.l) <<  , ;         os << n.val <<  , ;         if (n.r) os << *(n.r);         return os <<  ] ;       }     };     using Nptr = Node *;     std::array<Node, LEN> data;     int d_ptr;     int size(Nptr t) const { return t != nullptr ? t->sz : 0; }     lazy_rbst() : d_ptr(0) {}       protected:     Nptr update(Nptr t) {       t->sz = 1;       t->sum = t->val;       if (t->l) {         t->sz += t->l->sz;         t->sum = op(t->l->sum, t->sum);       }       if (t->r) {         t->sz += t->r->sz;         t->sum = op(t->sum, t->r->sum);       }       return t;     }     void all_apply(Nptr t, F f) {       t->val = mapping(f, t->val);       t->sum = mapping(f, t->sum);       t->lz = composition(f, t->lz);     }     void _toggle(Nptr t) {       auto tmp = t->l;       t->l = t->r, t->r = tmp;       t->sum = reversal(t->sum);       t->is_reversed ^= true;     }     void push(Nptr &t) {       _duplicate_node(t);       if (t->lz != id()) {         if (t->l) {           _duplicate_node(t->l);           all_apply(t->l, t->lz);         }         if (t->r) {           _duplicate_node(t->r);           all_apply(t->r, t->lz);         }         t->lz = id();       }       if (t->is_reversed) {         if (t->l) _toggle(t->l);         if (t->r) _toggle(t->r);         t->is_reversed = false;       }     }     virtual void _duplicate_node(Nptr &) {}     Nptr _make_node(const S &val) {       if (d_ptr >= LEN) throw;       return &(data[d_ptr++] = Node(val));     }       public:     Nptr new_tree() { return nullptr; }     int mem_used() const { return d_ptr; }     bool empty(Nptr t) const { return t == nullptr; }     Nptr merge(Nptr l, Nptr r) {       if (l == nullptr or r == nullptr) return l != nullptr ? l : r;       if (_rand() % uint32_t(l->sz + r->sz) < uint32_t(l->sz)) {         push(l);         l->r = merge(l->r, r);         return update(l);       } else {         push(r);         r->l = merge(l, r->l);         return update(r);       }     }     std::pair<Nptr, Nptr> split(Nptr &root, int k) {       if (root == nullptr) return std::make_pair(nullptr, nullptr);       push(root);       if (k <= size(root->l)) {         auto p = split(root->l, k);         root->l = p.second;         return std::make_pair(p.first, update(root));       } else {         auto p = split(root->r, k - size(root->l) - 1);         root->r = p.first;         return std::make_pair(update(root), p.second);       }     }     void insert(Nptr &root, int pos, const S &x) {       auto p = split(root, pos);       root = merge(p.first, merge(_make_node(x), p.second));     }     void erase(Nptr &root, int pos) {       auto p = split(root, pos);       auto p2 = split(p.second, 1);       root = merge(p.first, p2.second);     }     void set(Nptr &root, int pos, const S &x) {       auto p = split(root, pos);       auto p2 = split(p.second, 1);       _duplicate_node(p2.first);       *p2.first = Node(x);       root = merge(p.first, merge(p2.first, p2.second));     }     void apply(Nptr &root, int l, int r, const F &f) {       auto p = split(root, l);       auto p2 = split(p.second, r - l);       all_apply(p2.first, f);       root = merge(p.first, merge(p2.first, p2.second));     }     S prod(Nptr &root, int l, int r) {       auto p = split(root, l);       auto p2 = split(p.second, r - l);       if (p2.first != nullptr) push(p2.first);       S res = p2.first->sum;       root = merge(p.first, merge(p2.first, p2.second));       return res;     }     S get(Nptr &root, int pos) { return prod(root, pos, pos + 1); }     void reverse(Nptr &root) { _duplicate_node(root), _toggle(root); }     void reverse(Nptr &root, int l, int r) {       auto p2 = split(root, r);       auto p1 = split(p2.first, l);       reverse(p1.second);       root = merge(merge(p1.first, p1.second), p2.second);     }     void assign(Nptr &root, const std::vector<S> &init) {       d_ptr = 0;       int N = init.size();       root = N ? _assign_range(0, N, init) : new_tree();     }     Nptr _assign_range(int l, int r, const std::vector<S> &init) {       if (r - l == 1) {         Nptr t = _make_node(init[l]);         return update(t);       }       return merge(_assign_range(l, (l + r) / 2, init),                    _assign_range((l + r) / 2, r, init));     }     void dump(Nptr &t, std::vector<S> &vec) {       if (t == nullptr) return;       push(t);       dump(t->l, vec);       vec.push_back(t->val);       dump(t->r, vec);     }     void re_alloc(Nptr &root) {       std::vector<S> mem;       dump(root, mem);       assign(root, mem);     }   };   using S = int;   S op(S l, S r) { return l > r ? l : r; }   using F = pair<bool, int>;   S reversal(S x) { return x; }   S mapping(F f, S x) { return f.first ? f.second + x : x; }   F composition(F f, F g) {     if (!f.first) return g;     if (!g.first) return f;     return {true, f.second + g.second};   }   F id() { return {false, 0}; }   lazy_rbst<2000000, S, op, F, reversal, mapping, composition, id> tree;   mint solve() {     int N, M;     cin >> N >> M;     vector<pint> xy(M);     for (auto &[x, y] : xy) cin >> x >> y;     auto root = tree.new_tree();     tree.assign(root, {0});     for (auto [x, y] : xy) {       const int len = root->sz;       int lo = 1, hi = len + 1;       while (hi - lo > 1) {         int c = (lo + hi) / 2;         (tree.prod(root, 0, c) < y - 1 ? lo : hi) = c;       }       if (lo == len) {         tree.insert(root, len, y);       } else if (tree.get(root, lo) == y - 1) {         tree.apply(root, lo, len, {true, 1});       } else {         tree.apply(root, lo, len, {true, 1});         tree.insert(root, lo, y);       }     }     int sz = root->sz;     if (tree.get(root, 0) == 0) sz--;     sz = N - 1 - sz;     return mint(N + sz).nCr(sz);   }   int main() {     int T;     cin >> T;     while (T--) cout << solve() <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, test, n, m, value;     cin >> test;     while (test--) {       int s = 0;       cin >> n >> m;       for (i = 1; i <= n; i++) {         cin >> value;         s += value;       }       if (s == m) {         printf( YES n );       } else {         printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 5;   int a[maxn];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     while (m--) {       int l, r, x;       scanf( %d%d%d , &l, &r, &x);       int cnt1 = 0, cnt2 = 0;       for (int i = l; i <= r; i++) {         if (a[i] < a[x]) cnt1++;         if (a[i] == a[x]) cnt2++;       }       if (cnt1 + l - 1 < x && cnt2 + cnt1 + l - 1 >= x)         puts( Yes );       else         puts( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, int> getFactors(long long n) {     long long num = n;     long long sqrn = sqrt(n);     map<long long, int> ret;     for (long long i = 2; i <= sqrn; i++)       while (num % i == 0) {         ret[i]++;         num /= i;       }     if (num > 1 && num != n) ret[num]++;     return ret;   }   void solve(long long n) {     map<long long, int> factors = getFactors(n);     if (factors.size() == 0) {       cout << 1 <<   n  << 0 <<   n ;       return;     }     vector<long long> keys;     for (auto &p : factors) keys.push_back(p.first);     if (keys.size() > 2 ||         (keys.size() == 2 && (factors[keys[0]] > 1 || factors[keys[1]] > 1))) {       cout << 1 <<   n ;       cout << keys[0] * keys[1] <<   n ;       return;     }     if (keys.size() == 1 && factors[keys[0]] > 2) {       cout << 1 <<   n ;       cout << keys[0] * keys[0] <<   n ;       return;     }     cout << 2 <<   n ;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     solve(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[100005], u[100005], w[100005], dist[100005];   vector<pair<int, int> > edges[100005];   priority_queue<pair<int, int>, vector<pair<int, int> >,                  greater<pair<int, int> > >       pq;   int main() {     int n, m, s, l;     while (cin >> n >> m >> s) {       for (int i = 0; i < m; ++i) {         cin >> v[i] >> u[i] >> w[i];         edges[v[i]].push_back(make_pair(u[i], w[i]));         edges[u[i]].push_back(make_pair(v[i], w[i]));       }       cin >> l;       pq.push(make_pair(0, s));       memset(dist, 0x3f, sizeof(dist));       dist[s] = 0;       int c, d, nxt;       while (pq.size()) {         c = pq.top().second;         pq.pop();         for (int i = 0; i < edges[c].size(); ++i) {           nxt = edges[c][i].first;           if (dist[nxt] > dist[c] + edges[c][i].second) {             dist[nxt] = dist[c] + edges[c][i].second;             pq.push(make_pair(dist[nxt], nxt));           }         }       }       int tmp;       int cnt = 0;       for (int i = 1; i <= n; ++i)         if (dist[i] == l) ++cnt;       for (int i = 0; i < m; ++i) {         if (dist[u[i]] < l && dist[u[i]] + w[i] > l) {           tmp = dist[u[i]] + w[i];           if (dist[v[i]] + tmp - l >= l) ++cnt;         }         if (dist[v[i]] < l && dist[v[i]] + w[i] > l) {           tmp = dist[v[i]] + w[i];           if (dist[u[i]] + tmp - l > l) ++cnt;         }       }       cout << cnt <<   n ;       for (int i = 1; i <= n; ++i) edges[i].clear();       while (pq.size()) pq.pop();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1000000 + 10;   const int Mod = 998244353;   const int alp = 3;   int n, S;   int C[MAX];   int dp[MAX];   namespace opt {   int N;   int a[MAX], b[MAX], w[MAX], tmp[MAX];   int Pow(int a, int b) {     int k = 1;     for (; b; b /= 2, a = (long long)a * a % Mod)       if (b % 2 == 1) k = (long long)k * a % Mod;     return k;   }   void FFT(int *a, int S, int d) {     if (d == N) return;     FFT(a, S, d << 1);     FFT(a, S + d, d << 1);     for (int i = S, j = S, p = 0; i < N / 2; i += d, j += d << 1, p += d) {       int G = a[j], K = a[j + d];       tmp[i] = ((long long)G + (long long)w[p] * K) % Mod;       tmp[i + N / 2] = ((long long)G + (long long)w[p + N / 2] * K) % Mod;     }     for (int i = S; i < N; i += d) a[i] = tmp[i];   }   void conv(int *aa, int *bb, int *c, int n) {     for (int i = 0; i < n; ++i) a[i] = aa[i], b[i] = bb[i];     if (n <= 500) {       for (int i = 0; i < n * 2; ++i) c[i] = 0;       for (int i = 0; i < n; ++i)         for (int j = 0; j < n; ++j)           c[i + j] = (c[i + j] + (long long)a[i] * b[j]) % Mod;       for (int i = 0; i < n; ++i) a[i] = b[i] = 0;       return;     }     N = 1;     for (; N < n; N <<= 1)       ;     N <<= 1;     w[0] = 1;     w[1] = Pow(alp, (Mod - 1) / N);     for (int i = 2; i <= N; ++i) w[i] = (long long)w[i - 1] * w[1] % Mod;     FFT(a, 0, 1);     FFT(b, 0, 1);     for (int i = 0; i < N; ++i) a[i] = (long long)a[i] * b[i] % Mod;     for (int i = 0; i < N; ++i) b[i] = a[i ? (N - i) : 0];     FFT(b, 0, 1);     int InvN = Pow(N, Mod - 2);     for (int i = 0; i < N; ++i) {       c[i] = (long long)b[i] * InvN % Mod;       a[i] = b[i] = 0;     }   }   }  // namespace opt   int a[MAX], b[MAX], c[MAX];   void solve(int l, int r) {     if (r == l + 1) return;     int mid = (l + r) / 2;     solve(l, mid);     int i;     int need = r - l;     for (long long i = 0; i < need; i++) a[i] = b[i] = 0;     if (l > 0) {       for (long long i = 0; i < mid - l; i++) a[i] = dp[i + l];       for (long long i = 0; i < need; i++) b[i] = dp[i];       opt::conv(a, b, c, need);       for (long long i = 0; i < need; i++) {         c[i] *= 2;         if (c[i] >= Mod) c[i] -= Mod;       }     } else {       for (long long i = 0; i < mid - l; i++) a[i] = b[i] = dp[i + l];       opt::conv(a, b, c, need);     }     for (long long i = 0; i < need; i++) {       a[i] = c[i];       b[i] = C[i];     }     opt::conv(a, b, c, need);     for (long long i = mid; i < r; i++) {       dp[i] += c[i - l];       if (dp[i] >= Mod) dp[i] -= Mod;     }     solve(mid, r);   }   int main() {     int i;     scanf( %d%d , &n, &S);     for (long long i = 1; i <= n; i++) {       int a;       scanf( %d , &a);       C[a] = 1;     }     int N = 1;     for (; N <= S; N *= 2)       ;     dp[0] = 1;     solve(0, N);     for (long long i = 1; i <= S; i++) printf( %d n , dp[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long aX[100001];   long long aY[100001];   int main() {     long long n, k;     cin >> n >> k;     long long x, y;     cin >> x >> y;     long long mod = n * 2;     for (int i = 0; i < n; i++) cin >> aX[i] >> aY[i];     k = k % mod;     long long cx = 0, cy = 0;     for (int i = 1; i <= k; i++) {       cx = 2 * aX[(i - 1) % n] - cx;       cy = 2 * aY[(i - 1) % n] - cy;     }     if (k % 2 == 1)       cx -= x, cy -= y;     else       cx += x, cy += y;     cout << cx <<     << cy << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[100005];   long long int l1[100005];   long long int l2[100005];   long long int d[100005];   long long int e[100005];   long long int tree[100005];   long long int tree2[100005];   void update(long long int idx, long long int val, long long int n) {     while (idx <= n) {       tree[idx] += val;       idx += (idx & -idx);     }   }   long long int read(long long int idx) {     long long int sum = 0;     while (idx > 0) {       sum += tree[idx];       idx -= (idx & -idx);     }     return sum;   }   void update2(long long int idx, long long int val, long long int n) {     while (idx <= n) {       tree2[idx] += val;       idx += (idx & -idx);     }   }   long long int read2(long long int idx) {     long long int sum = 0;     while (idx > 0) {       sum += tree2[idx];       idx -= (idx & -idx);     }     return sum;   }   int corona(int x, int y) {     long long int s = 0, s1, s2;     for (int i = x + 1; i <= y; i++) {       if (l1[i] < l1[i - 1]) {         s++;         break;       }     }     if (s == 0)       return abs(y - x) + 1;     else {       s1 = corona(x, (x + y) / 2);       s2 = corona(((x + y) / 2) + 1, y);       return max(s1, s2);     }   }   int main() {     long long int n, a, q, b, t, c, m, k, x, y, x3 = 0, x4 = 0, x5 = 0;     string s3, s4;     cin >> t;     while (t--) {       cin >> n >> a >> b >> c;       cin >> s3;       for (int i = 0; i < s3.size(); i++) {         if (s3[i] ==  R ) {           if (b > 0) {             b--;             x3++;             l1[i] =  P ;           }         } else if (s3[i] ==  P ) {           if (c > 0) {             c--;             x3++;             l1[i] =  S ;           }         } else if (s3[i] ==  S ) {           if (a > 0) {             a--;             x3++;             l1[i] =  R ;           }         }       }       if (x3 >= ceil(n / 2.0)) {         cout <<  YES n ;         for (int i = 0; i < s3.size(); i++) {           if (l1[i] == 0 && a > 0) {             l1[i] =  R ;             a--;           } else if (l1[i] == 0 && b > 0) {             l1[i] =  P ;             b--;           } else if (l1[i] == 0 && c > 0) {             l1[i] =  S ;             c--;           }           s4 += (char)l1[i];         }         cout << s4 << endl;       } else         cout <<  NO n ;       x3 = 0;       s4 =   ;       memset(l1, 0, sizeof l1);     }     return 0;   }


#include <bits/stdc++.h>   double pi = 3.1415926535897931159979635;   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long cf = 0, cs = 0, c47 = 0, c74 = 0;     string a;     cin >> a;     long long s = a.size();     for (int i = 0; i < s; i++) {       if (a[i] ==  4 ) {         cf++;         if (a[i - 1] ==  7  && i > 0) c74++;       } else if (a[i] ==  7 ) {         cs++;         if (a[i - 1] ==  4  && i > 0) c47++;       }     }     if (cf == 0 && cs == 0)       cout <<  -1 n ;     else       s = max(c47, max(c74, max(cf, cs)));     if (s == cf)       cout <<  4 n ;     else if (s == cs)       cout <<  7 n ;     else if (s == c47)       cout <<  47 n ;     else if (s == c74)       cout <<  74 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int heights(long long int n) {     long long int count = 0, m, k;     for (long long int x = 1; x <= n; x++) {       m = 3 * x * x + x;       if (m > 2 * n)         break;       else {         k = x + n;         if (k % 3 == 0) count++;       }     }     return count;   }   int main() {     long long int n;     cin >> n;     cout << heights(n);     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int w;   string ch(string s, char x, string b) {     int n = s.size();     bool cx = 0;     char mina =  z ;     for (int i = 0; i < n; i++) {       if (s[i] == x && b[i] > s[i]) {         cx = 1;         mina = min(mina, b[i]);       }     }     if (!cx) {       return s;     }     w++;     for (int i = 0; i < n; i++) {       if (s[i] == x) s[i] = mina;     }     return s;   }   void solve() {     w = 0;     int n;     cin >> n;     string a, b;     cin >> a >> b;     for (int i = 0; i < n; i++) {       if (b[i] < a[i]) {         cout <<  -1 n ;         return;       }     }     for (int i = 0; i < 20; i++) {       a = ch(a, ((char)i + 97), b);     }     cout << w <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t) {       t--;       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 84;   const int VERTS = SIZE * SIZE;   int n, m;   int v, s, t;   int pict[SIZE][SIZE];   const int dir[4][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};   inline bool good(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; }   struct Edge {     int a, b;     int flow;     int cap, cost;     int anti;   };   vector<Edge> edges;   vector<int> nbr[VERTS];   void AddEdge(int a, int b, int cap, int cost) {     Edge e1;     e1.a = a;     e1.b = b;     e1.flow = 0;     e1.cap = cap;     e1.cost = cost;     e1.anti = edges.size() + 1;     Edge e2;     e2.a = b;     e2.b = a;     e2.flow = 0;     e2.cap = 0;     e2.cost = -cost;     e2.anti = edges.size();     nbr[a].push_back(edges.size());     nbr[b].push_back(edges.size() + 1);     edges.push_back(e1);     edges.push_back(e2);   }   bool used[VERTS];   int dist[VERTS];   int father[VERTS];   int deq[VERTS];   bool Dijkstra(int &allFlow, int &allCost) {     memset(dist, 63, sizeof(dist));     memset(father, -1, sizeof(father));     memset(used, false, sizeof(used));     dist[s] = 0;     int l = 0, r = 1;     deq[0] = s;     while (l < r) {       int best = deq[l++];       used[best] = true;       for (int i = 0; i < nbr[best].size(); i++) {         int eidx = nbr[best][i];         const Edge &e = edges[eidx];         if (e.flow == e.cap) continue;         int newd = dist[best] + e.cost;         if (dist[e.b] > newd) {           bool first = dist[e.b] > 1000000000;           dist[e.b] = newd;           father[e.b] = eidx;           if (used[e.b]) {             used[e.b] = false;             deq[--l] = e.b;           }           if (first) deq[r++] = e.b;         }       }     }     if (!used[t]) return false;     allFlow++;     int curr = t;     while (curr != s) {       int eidx = father[curr];       Edge &e = edges[eidx];       int pp = e.a;       e.flow++;       edges[e.anti].flow--;       allCost += e.cost;       curr = pp;     }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &pict[i][j]);     s = n * m;     t = n * m + 1;     v = n * m + 2;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if ((i + j) & 1) {           AddEdge(s, i * m + j, 1, 0);           for (int d = 0; d < 4; d++) {             int ni = i + dir[d][0];             int nj = j + dir[d][1];             if (!good(ni, nj)) continue;             AddEdge(i * m + j, ni * m + nj, 1, pict[i][j] != pict[ni][nj]);           }         } else           AddEdge(i * m + j, t, 1, 0);       }     int tflow = 0, tcost = 0;     while (Dijkstra(tflow, tcost))       ;     printf( %d n , tcost);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const double oula = 0.57721566490153286060651209;   using namespace std;   map<long long, string> mp;   int main() {     std::ios::sync_with_stdio(false);     long long n;     cin >> n;     long long nn = sqrt(n);     string tmp;     for (long long i = 2; i <= nn; i++) {       long long num = i * i;       int co = 2;       while (num <= n) {         tmp = to_string(i) +  ^  + to_string(co);         if (!mp.count(num)) mp[num] = to_string(num);         if (mp[num].size() > tmp.size()) mp[num] = tmp;         co++;         num *= i;       }     }     string ans = to_string(n);     map<long long, string>::iterator it;     for (it = mp.begin(); it != mp.end(); it++) {       tmp =   ;       long long a = n / it->first, b = n % it->first;       if (a > 1) {         if (mp.count(a))           tmp = mp[a];         else           tmp = to_string(a);         tmp +=  * ;       }       tmp += it->second;       if (b) tmp = tmp +  +  + (mp.count(b) ? mp[b] : to_string(b));       if (ans.size() > tmp.size()) ans = tmp;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int N;   int axor[1 << 16];   int degree[1 << 16], s[1 << 16];   vector<pair<int, int>> edge;   set<pair<int, int>> q;   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       scanf( %d %d , &degree[i], &s[i]);       q.insert({degree[i], i});     }     for (int i = 0; i < N; i++) {       int x, y;       x = (*q.begin()).second;       if (degree[x] == 0) {         q.erase({degree[x], x});         continue;       }       if (degree[x] > 1)         while (true)           ;       y = s[x] ^ axor[x];       axor[x] ^= y;       if (axor[x] != s[x])         while (true)           ;       axor[y] ^= x;       q.erase({degree[y], y});       q.erase({degree[x], x});       degree[x]--;       degree[y]--;       q.insert({degree[y], y});       if (x == y)         while (true)           ;       edge.push_back({x, y});     }     for (int i = 0; i < N; i++)       if (axor[i] != s[i])         while (true)           ;     printf( %d n , edge.size());     for (auto i : edge) {       printf( %d %d n , i.first, i.second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {     unsigned long long int max = a > b ? a : b;     unsigned long long int min = a < b ? a : b;     if (max % min == 0) return min;     if (max % min == 1) return 1;     return gcd(min, max % min);   }   int main() {     int flag = 0;     unsigned long long int l, r;     cin >> l >> r;     if (l - r < 2) {       cout <<  -1 ;       return 0;     }     unsigned long long int i, j, k;     for (i = l; i <= r - 2; i++) {       for (j = i + 1; j <= r - 1; j++) {         if (gcd(i, j) == 1) {           for (k = j + 1; k <= r; k++) {             if (gcd(j, k) == 1 && gcd(i, k) != 1) {               flag = 1;               cout << i <<     << j <<     << k;               break;             }           }         }         if (flag == 1) break;       }       if (flag == 1) break;     }     if (flag == 0) cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, n, m, k = 0, T, maxx = -0x3f3f3f3f;   int main() {     scanf( %lld , &T);     while (T--) {       scanf( %lld%lld , &n, &k);       long long t = 0, tmp = 0;       if (n == 2 && k == 3) {         cout <<  No  << endl;         continue;       }       while (t < k) {         t = t * 4 + 1;         if (t > k) break;         tmp++;       }       if (tmp > n || (tmp == n && k != t))         cout <<  NO n ;       else {         if (t > k) t = (t - 1) / 4;         cout <<  YES  ;         long long s = ((1ll) << tmp);         tmp = n - tmp;         t = k - t;         if (t >= 2 * s - 1)           cout << tmp - 1 << endl;         else           cout << tmp << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   map<vector<long long>, long long> mp;   int main() {     long long n;     cin >> n;     long long a[] = {2, 3, 5, 7};     vector<long long> t;     for (long long mask = 1; mask < (1 << 4); mask++) {       t.clear();       for (long long j = 0; j < 4; j++) {         if (mask & (1 << j)) t.push_back(a[j]);       }       sort(t.begin(), t.end());       long long y = 1;       for (auto v : t) y *= v;       mp[t] += n / y;     }     for (auto x : mp) {       if (x.first.size() % 2) {         n -= x.second;         continue;       }       n += x.second;     }     cout << n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2005;   const int dx[10] = {0, 0, 0, 1, -1, 1, 1, -1, -1};   const int dy[10] = {0, 1, -1, 0, 0, -1, 1, -1, 1};   int n, area, sx, sy;   bool p[maxN][maxN], vis[maxN][maxN];   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) scanf( %d , &p[i][j]);   }   void fixNoise() {     int cnt;     for (int tme = 1; tme <= 5; ++tme)       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n; ++j) {           cnt = 0;           for (int k = 0; k <= 8; ++k) cnt += p[i + dx[k]][j + dy[k]];           if (cnt < 5)             p[i][j] = 0;           else             p[i][j] = 1;         }   }   void dfs(int x, int y) {     int xx, yy;     vis[x][y] = 1;     ++area;     sx += x;     sy += y;     for (int i = 1; i <= 4; ++i) {       xx = x + dx[i];       yy = y + dy[i];       if (xx < 1 || yy < 1 || xx > n || yy > n || !p[xx][yy] || vis[xx][yy])         continue;       dfs(xx, yy);     }   }   void work() {     double ox, oy, r;     int circle = 0, rectangle = 0;     fixNoise();     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (p[i][j] && !vis[i][j]) {           area = 0;           sx = 0;           sy = 0;           dfs(i, j);           if (area >= 158) {             ox = double(sx) / area;             oy = double(sy) / area;             r = ((i - ox) * (i - ox)) + ((j - oy) * (j - oy));             if (area / r > 2.9)               ++circle;             else               ++rectangle;           }         }     printf( %d %d n , circle, rectangle);   }   int main() {     init();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       int sum = n - n % k;       sum += min(n % k, k / 2);       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     int floor[n][2 * m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < 2 * m; j++) {         cin >> floor[i][j];       }     }     int count = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 2 * m - 1; j += 2) {         if (floor[i][j] == 1 || floor[i][j + 1] == 1) {           count++;         }       }     }     cout << count <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     map<int, int> mx, my;     map<pair<int, int>, int> mp;     for (int i = 0; i < n; i++) {       int first, second;       cin >> first >> second;       mx[first]++;       my[second]++;       mp[{first, second}]++;     };     long long ans = 0;     for (auto it : mx) {       ans += (long long)it.second * (it.second - 1) / 2;     }     for (auto it : my) {       ans += (long long)it.second * (it.second - 1) / 2;     }     for (auto it : mp) {       ans -= (long long)it.second * (it.second - 1) / 2;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int up[200005];   int down[200005];   vector<int> answer;   bool done = true;   ;   int main() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       cin >> up[i];     }     for (int i = 1; i < n; i++) {       cin >> down[i];     }     answer.push_back(0);     int previous = 0;     for (int i = 1; i < n; i++) {       if (!done) {         break;       }       done = false;       for (int j = 0; j < 4; j++) {         int x = previous & j;         int z = previous | j;         if ((x == down[i]) && (z == up[i])) {           previous = j;           done = true;           answer.push_back(previous);           break;         }       }     }     if (done) {       cout <<  YES  << endl;       for (int i = 0; i < answer.size(); i++) {         cout << answer[i] <<    ;       }     } else {       answer.clear();       previous = 1;       answer.push_back(1);       done = true;       for (int i = 1; i < n; i++) {         if (!done) {           break;         }         done = false;         for (int j = 0; j < 4; j++) {           int x = previous & j;           int z = previous | j;           if ((x == down[i]) && (z == up[i])) {             previous = j;             done = true;             answer.push_back(previous);             break;           }         }       }       if (done) {         cout <<  YES  << endl;         for (int i = 0; i < answer.size(); i++) {           cout << answer[i] <<    ;         }       } else {         answer.clear();         previous = 2;         answer.push_back(2);         done = true;         for (int i = 1; i < n; i++) {           if (!done) {             break;           }           done = false;           for (int j = 0; j < 4; j++) {             int x = previous & j;             int z = previous | j;             if ((x == down[i]) && (z == up[i])) {               previous = j;               done = true;               answer.push_back(previous);               break;             }           }         }         if (done) {           cout <<  YES  << endl;           for (int i = 0; i < answer.size(); i++) {             cout << answer[i] <<    ;           }         } else {           answer.clear();           previous = 3;           answer.push_back(3);           done = true;           for (int i = 1; i < n; i++) {             if (!done) {               break;             }             done = false;             for (int j = 0; j < 4; j++) {               int x = previous & j;               int z = previous | j;               if ((x == down[i]) && (z == up[i])) {                 previous = j;                 done = true;                 answer.push_back(previous);                 break;               }             }           }           if (done) {             cout <<  YES  << endl;             for (int i = 0; i < answer.size(); i++) {               cout << answer[i] <<    ;             }           } else {             cout <<  NO  << endl;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int modexpo(long long int x, long long int y) {     if (y == 0) return 1;     if (y % 2) {       long long int viky = modexpo(x, y / 2);       return (((x * viky) % 1000000000) * viky) % 1000000000;     } else {       long long int viky = modexpo(x, y / 2);       return (viky * viky) % 1000000000;     }   }   long long int a[1111];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t, i, j, l, m, n, r, q, k, c, x;     cin >> n;     for (i = 1; i < n; i++) {       cin >> l >> r;       a[r]++;       a[l]++;     }     c = 0;     for (i = 1; i <= n; i++) {       if (a[i] == 1) c++;     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int ax, ay, bx, by, cx, cy;   double k1, k2, k3;   int main() {     long long int dis_ab, dis_ac, dis_bc, max_dis = -1;     cin >> ax >> ay >> bx >> by >> cx >> cy;     dis_ab = (ax - bx) * (ax - bx) + (ay - by) * (ay - by);     k1 = (double)(ax - bx) / (ay - by);     dis_ac = (ax - cx) * (ax - cx) + (ay - cy) * (ay - cy);     k2 = (double)(ax - cx) / (ay - cy);     dis_bc = (bx - cx) * (bx - cx) + (by - cy) * (by - cy);     k3 = (double)(bx - cx) / (by - cy);     if (k1 == k2 && k2 == k3)       cout <<  No ;     else {       if (dis_ab == dis_bc)         cout <<  Yes ;       else         cout <<  No ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000001;   const double EPS = 10e-9;   const int MAXN = 100005;   pair<int, int> t[MAXN << 1];   int MOD;   void rob() {     int n;     scanf( %d , &n);     int tmp;     for (typeof(0) i = (0); i < (n); ++i) {       scanf( %d , &tmp);       t[i] = make_pair(tmp, i);     }     for (typeof(0) i = (0); i < (n); ++i) {       scanf( %d , &tmp);       t[n + i] = make_pair(tmp, i);     }     scanf( %d , &MOD);     n <<= 1;     sort(t, t + n);     long long res = 1;     int i = 0;     int pow;     int fac;     while (i < n) {       fac = 1;       pow = 0;       for (++i; i < n; ++i) {         if (t[i].first != t[i - 1].first) break;         if (t[i].second == t[i - 1].second) ++pow;         ++fac;       }       for (typeof(1) j = (1); j <= (fac); ++j) {         if (pow && !(j & 1)) {           res = (res * (j >> 1)) % MOD;           --pow;         } else {           res = (res * j) % MOD;         }       }     }     printf( %I64d n , res);   }   int main() {     int test = 1;     while (test--) rob();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   int arr[MAX];   int n;   int query(int x, int y, int z) {     cout <<  ?   << x <<     << y <<     << z << endl;     int a;     cin >> a;     return a;   }   array<int, 3> col[2];   int ans[MAX];   vector<int> v;   int main() {     int t;     cin >> t;     while (t--) {       v.clear();       col[0] = col[1] = {-1, -1, -1};       cin >> n;       for (int i = 1; i <= n; i += 3) {         arr[i] = query(i, i + 1, i + 2);         col[arr[i]] = {i, i + 1, i + 2};       }       int x = -1, y = -1;       for (int i = 0; i < 3; ++i) {         if (query(col[0][0], col[0][1], col[1][i])) {           y = col[1][i];           break;         }       }       if (y == -1) {         x = col[0][0];         if (query(col[1][0], col[1][1], x))           y = col[1][0];         else if (query(col[1][0], col[1][2], x))           y = col[1][0];         else           y = col[1][1];       } else         x = col[0][2];       ans[x] = 0, ans[y] = 1;       for (int i = 1; i <= n; i += 3) {         if (i == col[arr[i]][0]) {           for (int j = i; j <= i + 2; ++j) {             if (j == x || j == y) continue;             ans[j] = query(x, y, j);           }           continue;         }         int c = x;         if (!arr[i]) c = y;         int a = query(i, i + 1, c);         int b = query(i, i + 2, c);         int idx = -1;         if (a != arr[i] && b != arr[i])           idx = i;         else if (a != arr[i])           idx = i + 1;         else if (b != arr[i])           idx = i + 2;         for (int j = i; j <= i + 2; ++j) {           if (idx == j)             ans[j] = !arr[i];           else             ans[j] = arr[i];         }       }       for (int i = 1; i <= n; ++i) {         if (!ans[i]) v.push_back(i);       }       cout <<  !   << v.size() <<    ;       for (auto &i : v) cout << i <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   struct node {     double x;     double y;     double t;     double p;     bool operator<(const node& W) const { return t < W.t; }   } q[N];   double dp[N];   bool check(node a, node b) {     double dx = a.x - b.x;     double dy = a.y - b.y;     return sqrt(dx * dx + dy * dy) <= b.t - a.t;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> q[i].x >> q[i].y >> q[i].t >> q[i].p;     }     sort(q + 1, q + n + 1);     dp[1] = q[1].p;     for (int i = 2; i <= n; i++) {       dp[i] = q[i].p;       for (int j = 1; j <= i - 1; j++)         if (check(q[j], q[i])) dp[i] = max(dp[i], dp[j] + q[i].p);     }     double res = 0;     for (int i = 1; i <= n; i++) res = max(res, dp[i]);     printf( %.6lf n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int x[505], y[505];   int x_koord[1005], y_koord[1005], kk, kkx, kky;   int z[1055][1055];   bool popuni(int sz) {     kk = 0;     for (int i = 1; i <= k; i++) {       int xl = x[i] - sz;       if (xl < 1) {         xl = 1;       }       int xr = x[i] + sz + 1;       if (xr > n + 1) {         xr = n + 1;       }       int yl = y[i] - sz;       if (yl < 1) {         yl = 1;       }       int yr = y[i] + sz + 1;       if (yr > m + 1) {         yr = m + 1;       }       kk++;       x_koord[kk] = xl;       y_koord[kk] = yl;       kk++;       x_koord[kk] = xr;       y_koord[kk] = yr;     }     kk++;     x_koord[kk] = 1;     y_koord[kk] = 1;     kk++;     x_koord[kk] = n + 1;     y_koord[kk] = m + 1;     sort(x_koord + 1, x_koord + kk + 1);     kkx = unique(x_koord + 1, x_koord + kk + 1) - x_koord - 1;     sort(y_koord + 1, y_koord + kk + 1);     kky = unique(y_koord + 1, y_koord + kk + 1) - y_koord - 1;     memset(z, 0, sizeof(z));     for (int i = 1; i <= k; i++) {       int xl = x[i] - sz;       if (xl < 1) {         xl = 1;       }       int xr = x[i] + sz + 1;       if (xr > n + 1) {         xr = n + 1;       }       int yl = y[i] - sz;       if (yl < 1) {         yl = 1;       }       int yr = y[i] + sz + 1;       if (yr > m + 1) {         yr = m + 1;       }       xl = lower_bound(x_koord + 1, x_koord + kkx + 1, xl) - x_koord;       xr = lower_bound(x_koord + 1, x_koord + kkx + 1, xr) - x_koord;       yl = lower_bound(y_koord + 1, y_koord + kky + 1, yl) - y_koord;       yr = lower_bound(y_koord + 1, y_koord + kky + 1, yr) - y_koord;       z[xl][yl]++;       z[xl][yr]--;       z[xr][yl]--;       z[xr][yr]++;     }     int loy = 2e9, hiy = -2e9, lox = 2e9, hix = -2e9;     int any = 0;     for (int i = 1; i < kkx; i++) {       for (int j = 1; j < kky; j++) {         z[i][j] += z[i - 1][j] + z[i][j - 1] - z[i - 1][j - 1];         if (z[i][j] == 0) {           any = 1;           lox = min(lox, x_koord[i]);           hix = max(hix, x_koord[i + 1]);           loy = min(loy, y_koord[j]);           hiy = max(hiy, y_koord[j + 1]);         }       }     }     if (!any) {       return true;     }     cerr << sz <<     << lox <<     << hix <<     << loy <<     << hiy <<   n ;     return max(hiy - loy, hix - lox) / 2 <= sz;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     cin >> n >> m >> k;     for (int i = 1; i <= k; i++) {       cin >> x[i] >> y[i];     }     int l = 0, r = 1e9, o = 1e9;     while (l <= r) {       int m = (l + r) / 2;       if (popuni(m)) {         o = m;         r = m - 1;       } else {         l = m + 1;       }     }     cout << o;   }


#include <bits/stdc++.h>   using namespace std;   char s[1000010];   int n, p[1000010];   int main() {     scanf( %s , s), n = strlen(s);     for (int i = 0; i < n; i++)       if (s[i] ==  1 ) p[n - 1 - i] = 1;     for (int i = 0, j; i < n + 2;)       if (!p[i])         i++;       else {         j = i;         while (p[j]) j++;         if (j - i >= 2) {           p[i] = -1;           for (int k = i + 1; k < j; k++) p[k] = 0;           p[j] = 1;         }         i = j;       }     int S = 0;     for (int i = 0; i < n + 2; i++)       if (p[i] != 0) S++;     printf( %d n , S);     for (int i = 0; i < n + 2; i++)       if (p[i] != 0)         if (p[i] > 0)           printf( +2^%d n , i);         else           printf( -2^%d n , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int i, j, k;     int n;     cin >> n;     int x = n / 4;     string s =  abcd ;     string ans =   ;     if (n % 4 == 0)       for (i = 0; i < x; i++) ans += s;     else {       if (n % 4 == 1) {         for (i = 0; i < x; i++) ans += s;         ans +=  a ;       }       if (n % 4 == 2) {         for (i = 0; i < x; i++) ans += s;         ans +=  ab ;       }       if (n % 4 == 3) {         for (i = 0; i < x; i++) ans += s;         ans +=  abc ;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   const int INF = 1e9;   const long long MOD = 1e9 + 7;   const int N = 1e5 + 5, MO = 350, SQ = 650;   int n, q, A[N], QL[N], QR[N], P[N], T[N], C[N], K[N], Q[N];   vector<int> B, X, Y;   bool CMP(int i, int j) {     if (QL[i] / MO != QL[j] / MO) return QL[i] < QL[j];     return (QL[i] / MO) % 2 ? QR[i] > QR[j] : QR[i] < QR[j];   }   void Update(int x, int y) { T[C[x]]--, C[x] += y, T[C[x]]++; }   void Insert(int x, int y) {     if (x >= SQ && !K[x]) Y.push_back(x);     K[x] += y;   }   int Huf() {     X.clear(), Y.clear();     for (int i : B)       if (C[i] >= SQ) X.push_back(C[i]), K[C[i]]++;     sort(X.begin(), X.end());     int huf = 0, c = 0, x = 0, y = 0;     for (int i = 1; i < SQ; i++)       if (K[i] + T[i]) {         K[i] += T[i];         if (c) huf += i + c, K[i]--, Insert(i + c, 1), c = 0;         if (K[i] & 1) c = i, K[i]--;         if (K[i]) huf += i * K[i], Insert(i + i, K[i] >> 1), K[i] = 0;       }     while (x < (int)(X.size()) || y < (int)(Y.size())) {       while (x + 1 < (int)(X.size()) && X[x + 1] == X[x]) x++;       while (y + 1 < (int)(Y.size()) && Y[y + 1] == Y[y]) y++;       int i = 0;       if (x == (int)(X.size()))         i = Y[y++];       else if (y == (int)(Y.size()))         i = X[x++];       else if (X[x] < Y[y])         i = X[x++];       else         i = Y[y++];       if (c) huf += i + c, K[i]--, Insert(i + c, 1), c = 0;       if (K[i] & 1) c = i, K[i]--;       if (K[i]) huf += i * K[i], Insert(i + i, K[i] >> 1), K[i] = 0;     }     return huf;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     mt19937 Rnd(time(0));     cin >> n;     for (int i = 0; i < n; i++) cin >> A[i], C[A[i]]++;     for (int i = 0; i < N; i++)       if (C[i] >= SQ) B.push_back(i);     for (int i = 0; i < n; i++) C[A[i]]--;     cin >> q;     for (int i = 0; i < q; i++) cin >> QL[i] >> QR[i], QL[i]--, P[i] = i;     sort(P, P + q, CMP);     int L = 0, R = 0;     for (int i = 0; i < q; i++) {       int l = QL[P[i]], r = QR[P[i]];       while (l < L) Update(A[--L], +1);       while (R < r) Update(A[R++], +1);       while (L < l) Update(A[L++], -1);       while (r < R) Update(A[--R], -1);       Q[P[i]] = Huf();     }     for (int i = 0; i < q; i++) cout << Q[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long t, n, i, j, flag = 0, temp, nodes, a, b, m, k, sz, sm, res;     long long mn, mx;     long long l, r;     long long x, y, z;     long long c, d;     t = 1;     vector<pair<int, int>> v;     string s;     char ch;     while (t--) {       flag = 0;       v.clear();       cin >> n;       int A = INT_MAX, B = INT_MIN;       for (i = 0; i < n; i++) {         cin >> a >> b;         v.push_back({a, b});         if (a < A) A = a;         if (B < b) B = b;       }       for (i = 0; i < v.size(); i++) {         if (v[i].first == A && v[i].second == B) {           flag = 1;           break;         }       }       if (flag == 1) {         cout << i + 1 << endl;         continue;       } else {         cout <<  -1 ;         continue;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   char a[N], b[N];   int s[N][26];   void init() {     int n = strlen(a + 1);     memset(s, 0, sizeof(s));     for (int i = n; i >= 1; i--) {       for (int j = 0; j < 26; j++) {         s[i - 1][j] = s[i][j];       }       s[i - 1][a[i] -  a ] = i;     }   }   int main() {     int T;     cin >> T;     while (T--) {       scanf( %s %s , a + 1, b + 1);       init();       int flg = 0;       int p = 0;       int ans = 1;       for (int i = 1; i <= strlen(b + 1); i++) {         int t = b[i] -  a ;         int tt = s[p][t];         if (tt == 0 && p == 0) {           flg = 1;           break;         }         if (tt == 0) {           i--;           ans++;           p = 0;         } else {           p = tt;         }       }       if (flg == 1) {         printf( -1 n );         continue;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 500009;   const long long int mod = 1000000007;   long long int n, k;   string s;   string see;   vector<long long int> v;   void pre() {     see = s;     for (auto i : s) see += i;     for (auto i : s) see += i;   }   int32_t main() {     cin >> n >> k >> s;     pre();     for (long long int i = 0; i < 3 * n;) {       long long int j = i;       long long int pahla = i;       long long int doosra = i - 1;       long long int idharhi = 0;       while (doosra < (3 * n - 1)) {         if (see[i] == see[doosra + 1])           doosra++;         else           break;       }       if (doosra == pahla) {         i++;         continue;       }       for (long long int k = i; k <= doosra; k++) {         v.push_back(k);       }       i = doosra + 1;     }     if (v.size() == 0) {       if (k % 2 == 0) {         cout << s <<   n ;         return 0;       } else {         for (auto i : s) {           if (i ==  W )             cout <<  B ;           else             cout <<  W ;         }         cout <<   n ;         return 0;       }     }     string ans =   ;     for (long long int i = n; i < 2 * n; i++) {       auto it = lower_bound(v.begin(), v.end(), i);       long long int is = it - v.begin();       if (v[is] == i) {         ans += see[i];         continue;       }       is--;       long long int dis1 = i - v[is];       is++;       long long int dis2 = v[is] - i;       assert(dis1 > 0 and dis2 > 0);       if (dis1 > k && dis2 > k) {         if (k % 2 == 0) {           ans += see[i];         } else {           if (see[i] ==  W )             ans +=  B ;           else             ans +=  W ;         }         continue;       } else if (dis1 <= k && dis1 < dis2) {         ans += see[v[is - 1]];       } else if (dis2 <= k && dis2 < dis1) {         ans += see[v[is]];       } else {         ans += see[v[is]];       }     }     assert((long long int)ans.length() == n);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int nod(int a, int b) {     int c;     if (a > b) swap(a, b);     for (;;) {       c = b % a;       b = a;       a = c;       if (a == 0) return b;     }   }   int main() {     int x, y, a, b;     cin >> x >> y >> a >> b;     int d = x * y / nod(x, y);     int c = b / d - (a - 1) / d;     if (c < 0) c = 0;     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10;   int n, q, k;   vector<pair<int, int> > tree[N << 2];   int ask[N], ans[N];   struct que {     int x, y, times, l;   };   queue<que> Q;   int fa[N], h[N], siz[N];   int find(int o) {     if (o != fa[o]) {       return find(fa[o]);     }     return o;   }   struct gu {     int first, second, val;   };   gu merge(int x, int y) {     x = find(x);     y = find(y);     gu re;     re.val = -1;     if (x == y) return re;     if (h[x] > h[y]) swap(x, y);     fa[x] = y;     siz[y] += siz[x];     re.val = h[x] == h[y];     h[y] += h[x] == h[y];     re.first = x;     re.second = y;     return re;   }   void del(int x, int y, int val) {     h[y] -= val;     siz[y] -= siz[x];     fa[x] = x;   }   void add(int o, int l, int r, int L, int R, pair<int, int> x) {     if (l >= L && r <= R) {       tree[o].push_back(x);       return;     }     int mid = (l + r) >> 1;     if (mid >= L) add(o << 1, l, mid, L, R, x);     if (mid < R) add(o << 1 | 1, mid + 1, r, L, R, x);   }   int tp;   gu s[1000100];   void qu(int o, int l, int r) {     int now = tp, sf = 0;     for (int i = 0; i < tree[o].size(); ++i) {       pair<int, int> now = tree[o][i];       s[++tp] = merge(now.first, now.second);     }     if (l == r) {       ans[l] = siz[find(ask[l])];     } else {       int mid = (l + r) >> 1;       qu(o << 1, l, mid);       qu(o << 1 | 1, mid + 1, r);     }     while (tp != now) {       if (s[tp].val != -1) del(s[tp].first, s[tp].second, s[tp].val);       --tp;     }   }   int main() {     scanf( %d%d%d , &n, &q, &k);     for (int i = 1; i <= n; ++i) fa[i] = i, siz[i] = 1, h[i] = 1;     int days = 1;     for (int i = 1; i <= q; ++i) {       int op;       scanf( %d , &op);       if (op == 1) {         int x, y;         scanf( %d%d , &x, &y);         Q.push((que){x, y, days, i});       }       if (op == 2) {         int o;         scanf( %d , &o);         ask[i] = o;       }       if (op == 3) {         ++days;         while (!Q.empty() && Q.front().times <= days - k) {           add(1, 1, q, Q.front().l, i - 1, make_pair(Q.front().x, Q.front().y));           Q.pop();         }       }     }     while (!Q.empty()) {       add(1, 1, q, Q.front().l, q, make_pair(Q.front().x, Q.front().y));       Q.pop();     }     qu(1, 1, q);     for (int i = 1; i <= q; ++i) {       if (ask[i]) printf( %d n , ans[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int s_size = 1e5 + 5;   const int mod = 1e9 + 7;   int f[(s_size + 1) >> 1] = {1}, t[(s_size + 1) >> 1], g[(s_size + 1) >> 1];   int fac[s_size] = {1}, inv[s_size], ans[s_size];   int num(char c);   void fac_inv(void);   int qpow(int a, int b);   int main(void) {     int q, x, y, cnt[55] = {0}, plan[55][55];     string s;     cin >> s >> q;     s =  0  + s;     int length = s.size() - 1, upper = (length >> 1);     for (int i = 1; i <= length; i++) cnt[num(s[i])]++;     fac_inv();     int coe = (static_cast<long long>(fac[upper]) * fac[upper]) % mod;     for (int i = 1; i <= 52; i++)       if (cnt[i] > 0) {         coe = (static_cast<long long>(coe) * inv[cnt[i]]) % mod;         for (int j = upper; j >= cnt[i]; j--) f[j] = (f[j] + f[j - cnt[i]]) % mod;       }     for (int i = 1; i <= 52; i++)       if (cnt[i] > 0) {         plan[i][i] = f[upper];         for (int j = 0; j <= upper; j++)           if (j >= cnt[i])             t[j] = (static_cast<long long>(f[j]) - t[j - cnt[i]] + mod) % mod;           else             t[j] = f[j];         for (int j = i + 1; j <= 52; j++)           if (cnt[j] > 0) {             for (int k = 0; k <= upper; k++) {               if (k >= cnt[j])                 g[k] = (static_cast<long long>(t[k]) - g[k - cnt[j]] + mod) % mod;               else                 g[k] = t[k];               plan[i][j] = (static_cast<long long>(2) * g[upper]) % mod;               plan[j][i] = plan[i][j];             }           }       }     for (int i = 1; i <= q; i++) {       cin >> x >> y;       ans[i] = (static_cast<long long>(coe) * plan[num(s[x])][num(s[y])]) % mod;     }     for (int i = 1; i <= q; i++) cout << ans[i] << endl;     return 0;   }   inline int num(char c) { return islower(c) ? c -  a  + 1 : c -  A  + 27; }   void fac_inv(void) {     for (int i = 1; i <= s_size - 5; i++)       fac[i] = (static_cast<long long>(fac[i - 1]) * i) % mod;     inv[s_size - 5] = qpow(fac[s_size - 5], mod - 2);     for (int i = s_size - 6; i >= 0; i--)       inv[i] = (static_cast<long long>(inv[i + 1]) * (i + 1)) % mod;   }   int qpow(int a, int b) {     int ret = 1;     while (b > 0) {       if ((b & 1) == 1) ret = (static_cast<long long>(ret) * a) % mod;       a = (static_cast<long long>(a) * a) % mod;       b >>= 1;     }     return ret;   }


#include <bits/stdc++.h>   using namespace std;   long long int INF = (long long int)1e16;   int n, m, r;   vector<int> s, b;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     s.clear();     b.clear();     cin >> n >> m >> r;     int x, y;     int bax = INT_MAX;     int bay = INT_MIN;     for (int i = 0; i < n; i++) {       cin >> x;       bax = min(bax, x);     }     for (int i = 0; i < m; i++) {       cin >> y;       bay = max(bay, y);     }     int bht = r / bax;     int cost = bht * bay + r % bax;     cout << max(cost, r) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cont[1003], sum[1003];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int ans = 0;     string s1, s2;     cin >> s1 >> s2;     int n = s1.size();     int m = s2.size();     for (int i = 0; i < n; i++) cont[s1[i] -  a ]++;     for (int i = 0; i < m; i++) sum[s2[i] -  a ]++;     for (int i = 0; i < 26; i++) {       if (sum[i] > 0 && cont[i] == 0) {         cout << -1 <<   n ;         return 0;       }       if (sum[i] > cont[i])         ans += cont[i];       else         ans += sum[i];     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long getint() {     long long num = 0, flag = 1;     char c;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) flag = -1;     while (c >=  0  && c <=  9 ) num = num * 10 + c - 48, c = getchar();     return num * flag;   }   int n, m, q, R;   int fir[600005], nxt[600005], to[600005], cnt;   int sz[600005], tp[600005], fa[600005], son[600005], dpt[600005], pos[600005],       cur;   map<pair<int, int>, int> M;   int p[600005], V[600005];   int P_stk[600005], P_Tp;   inline int rotate(int x) {     x = (x + R) % n;     return x ? x : x + n;   }   inline bool cmp(int x, int y) { return pos[x] < pos[y]; }   inline void newnode(int u, int v) {     to[++cnt] = v, nxt[cnt] = fir[u], fir[u] = cnt;   }   inline void dfs1(int u) {     sz[u] = 1;     pos[u] = ++cur;     for (int i = fir[u]; i; i = nxt[i])       if (to[i] != fa[u]) {         fa[to[i]] = u, dpt[to[i]] = dpt[u] + 1;         dfs1(to[i]), sz[u] += sz[to[i]];         if (sz[to[i]] > sz[son[u]]) son[u] = to[i];       }   }   inline void dfs2(int u, int ac) {     tp[u] = ac;     if (son[u]) dfs2(son[u], ac);     for (int i = fir[u]; i; i = nxt[i])       if (to[i] != fa[u] && to[i] != son[u]) dfs2(to[i], to[i]);   }   inline int LCA(int u, int v) {     for (; tp[u] != tp[v] && u && v; u = fa[tp[u]])       if (dpt[tp[u]] < dpt[tp[v]]) swap(u, v);     if (!u || !v) return 0;     return dpt[u] < dpt[v] ? u : v;   }   struct node {     vector<int> G[600005], Id[600005];     int dfn[600005], low[600005], tim, vis[600005], sccno[600005], scccnt;     int stk[600005], Tp;     inline void tarjan(int u) {       dfn[u] = low[u] = ++tim;       stk[++Tp] = u;       for (int i = 0, v; i < G[u].size(); i++)         if (!vis[Id[u][i]]) {           vis[Id[u][i]] = 1;           if (!dfn[v = G[u][i]])             tarjan(v), low[u] = min(low[u], low[v]);           else if (!sccno[v])             low[u] = min(low[u], dfn[v]);         }       if (dfn[u] == low[u]) {         scccnt++;         while (1) {           sccno[stk[Tp]] = scccnt;           if (stk[Tp--] == u) break;         }       }     }     inline void init() {       for (int i = 1; i <= m; i++) {         int u = getint(), v = getint();         G[u].push_back(v), G[v].push_back(u);         Id[u].push_back(i), Id[v].push_back(i);       }       for (int i = 1; i <= n; i++)         if (!dfn[i]) tarjan(i);       for (int u = 1; u <= n; u++)         for (int i = 0; i < G[u].size(); i++)           if (sccno[G[u][i]] != sccno[u]) {             int x = min(sccno[u], sccno[G[u][i]]),                 y = max(sccno[u], sccno[G[u][i]]);             if (!M[make_pair(x, y)])               newnode(x, y), newnode(y, x), M[make_pair(x, y)] = 1;           }     }   } G, H;   int main() {     n = getint(), m = getint(), q = getint();     G.init();     for (int i = 1; i <= G.scccnt; i++)       if (!sz[i]) dfs1(i), dfs2(i, i);     for (int t = 1; t <= q; t++) {       int N = getint(), M = getint(), K = 0, tmp = 0;       P_Tp = 0;       for (int i = 1; i <= N; i++) {         int x = G.sccno[rotate(getint())];         p[++K] = x, V[x] = 1;       }       for (int i = 1; i <= M; i++) {         int x = G.sccno[rotate(getint())], y = G.sccno[rotate(getint())];         if (x == y) continue;         p[++K] = x, p[++K] = y, tmp++;         H.G[x].push_back(y), H.G[y].push_back(x);         H.Id[x].push_back(tmp), H.Id[y].push_back(tmp);       }       sort(p + 1, p + K + 1, cmp), K = unique(p + 1, p + K + 1) - p - 1;       for (int i = K - 1; i; i--) {         int x = LCA(p[i], p[i + 1]);         if (x) p[++K] = x;       }       sort(p + 1, p + K + 1, cmp), K = unique(p + 1, p + K + 1) - p - 1;       for (int i = 1; i <= K; i++) {         while (P_Tp && pos[P_stk[P_Tp]] + sz[P_stk[P_Tp]] <= pos[p[i]]) P_Tp--;         if (P_Tp) {           int x = P_stk[P_Tp], y = p[i];           tmp++;           H.G[x].push_back(y), H.G[y].push_back(x);           H.Id[x].push_back(tmp), H.Id[y].push_back(tmp);         }         P_stk[++P_Tp] = p[i];       }       for (int i = 1; i <= K; i++)         if (!H.dfn[p[i]]) H.tarjan(p[i]);       int pp = 0;       bool flg = 1;       for (int i = 1; i <= K; i++)         if (V[p[i]]) {           if (!pp)             pp = H.sccno[p[i]];           else if (pp != H.sccno[p[i]]) {             flg = 0;             break;           }         }       for (int i = 1; i <= K; i++) {         H.G[p[i]].clear(), H.Id[p[i]].clear();         H.dfn[p[i]] = H.low[p[i]] = H.sccno[p[i]] = V[p[i]] = 0;       }       for (int i = 1; i <= tmp; i++) H.vis[i] = 0;       H.scccnt = H.tim = H.Tp = 0;       R = (R + t * flg) % n;       puts(flg ?  YES  :  NO );     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long m;   int soln[51];   long long mr = 0;   int main() {     cin >> n >> m;     --m;     for (int k = 1; k < n; ++k) {       mr = mr * 2 + (m & 1);       m >>= 1;     }     int i = 1, j = n;     for (int k = 1; k <= n; ++k) {       if (mr & 1)         soln[j--] = k;       else         soln[i++] = k;       mr >>= 1;     }     for (int k = 1; k <= n; ++k) cout << soln[k] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, x;   long long m[200010];   long long answer;   struct node {     long long pre;     long long next;   } p[200010];   int main() {     long long a;     while (~scanf( %I64d %I64d %I64d , &n, &k, &x)) {       answer = p[1].pre = p[n].next = 0;       a = x;       for (long long i = k - 1; i > 0; i--) a *= x;       for (long long i = 1; i <= n; i++) {         scanf( %d , &m[i]);         p[i].pre = (m[i - 1] | p[i - 1].pre);       }       for (long long i = n; i >= 1; i--) {         if (i < n) p[i].next = (p[i + 1].next | m[i + 1]);         answer = max(answer, (p[i].pre | p[i].next | m[i] * a));       }       printf( %I64d n , answer);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z;     cin >> x >> y >> z;     if (z == 0) {       if (x > y)         cout <<  + ;       else if (x < y)         cout <<  - ;       else         cout <<  0 ;     } else {       if (x > y + z)         cout <<  + ;       else if (y > x + z)         cout <<  - ;       else         cout <<  ? ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     char name[100], winner[100];     int sh, uh, a, b, v, c, d, e;     int n, i;     int sum;     int total = sum;     scanf( %d , &n);     scanf( %s %d %d %d %d %d %d %d , name, &sh, &uh, &a, &b, &c, &d, &e);     sum = sh * 100 - uh * 50 + a + b + c + d + e;     total = sum;     strcpy(winner, name);     for (i = 0; i < n - 1; i++) {       scanf( %s %d %d %d %d %d %d %d , name, &sh, &uh, &a, &b, &c, &d, &e);       sum = sh * 100 - uh * 50 + a + b + c + d + e;       if (sum > total) {         total = sum;         strcpy(winner, name);       }     }     printf( %s , winner);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1>   void deb(T1 e) {     cout << e << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   template <class T>   T Abs(T x) {     return x > 0 ? x : -x;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   long long Pow(long long B, long long P) {     long long R = 1;     while (P > 0) {       if (P % 2 == 1) R = (R * B);       P /= 2;       B = (B * B);     }     return R;   }   int BigMod(long long B, long long P, long long M) {     long long R = 1;     while (P > 0) {       if (P % 2 == 1) {         R = (R * B) % M;       }       P /= 2;       B = (B * B) % M;     }     return (int)R;   }   int n, l, k;   vector<int> prize;   vector<double> prb;   double dp[202][202][202];   double rec(int pos, int need_2_win, int bags) {     if (pos >= n) {       if (need_2_win >= l && bags + k >= need_2_win)         return 1.00;       else         return 0.0;     }     double &ret = dp[pos][need_2_win][bags];     if (ret > -.5) return ret;     ret = 0.0;     ret += (prb[pos] / 100.0) *            rec(pos + 1, need_2_win + 1, min(200, bags + prize[pos]));     ret += (max(100.0 - prb[pos], 0.0) / 100.0) * rec(pos + 1, need_2_win, bags);     return ret;   }   int main(void) {     double val;     int a;     scanf( %d %d %d , &n, &l, &k);     for (int i = 0; i < n; i++) {       scanf( %lf , &val);       prb.push_back(val);     }     for (int i = 0; i < n; i++) {       scanf( %d , &a);       prize.push_back(a + 1);     }     memset(dp, -1, sizeof dp);     double ans = rec(0, 0, 0);     printf( %.12lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2000000000;   static inline int Rint() {     struct X {       int dig[256];       X() {         for (int i =  0 ; i <=  9 ; ++i) dig[i] = 1;         dig[ - ] = 1;       }     };     static X fuck;     int s = 1, v = 0, c;     for (; !fuck.dig[c = getchar()];)       ;     if (c ==  - )       s = 0;     else if (fuck.dig[c])       v = c ^ 48;     for (; fuck.dig[c = getchar()]; v = v * 10 + (c ^ 48))       ;     return s ? v : -v;   }   template <typename T>   static inline void cmax(T& a, const T& b) {     if (b > a) a = b;   }   template <typename T>   static inline void cmin(T& a, const T& b) {     if (b < a) a = b;   }   char buff[1024][1024];   char temp[1024][1024];   int n, m;   int sol_row(int u, int v, int a, int b) {     for (int j = 0; j < m; ++j) {       int match1 = 1, match2 = 1;       int p[2];       if (j % 2 == 0)         p[0] = u, p[1] = v;       else         p[0] = a, p[1] = b;       for (int i = 0; i < n; ++i)         if (buff[i][j] !=  0 ) {           if (buff[i][j] != p[i % 2]) match1 = 0;           if (buff[i][j] != p[1 - i % 2]) match2 = 0;         }       if (!match1 && !match2) return 0;       for (int i = 0; i < n; ++i) {         if (match1)           temp[i][j] = p[i % 2];         else           temp[i][j] = p[1 - i % 2];       }     }     return 1;   }   int sol_col(int u, int v, int a, int b) {     for (int i = 0; i < n; ++i) {       int match1 = 1, match2 = 1;       int p[2];       if (i % 2 == 0)         p[0] = u, p[1] = v;       else         p[0] = a, p[1] = b;       for (int j = 0; j < m; ++j)         if (buff[i][j] !=  0 ) {           if (buff[i][j] != p[j % 2]) match1 = 0;           if (buff[i][j] != p[1 - j % 2]) match2 = 0;         }       if (!match1 && !match2) return 0;       for (int j = 0; j < m; ++j) {         if (match1)           temp[i][j] = p[j % 2];         else           temp[i][j] = p[1 - j % 2];       }     }     return 1;   }   int main() {     n = Rint(), m = Rint();     for (int i = (0); i < (n); ++i) scanf( %s , buff[i]);     int pattern[4] = { 1 ,  2 ,  3 ,  4 };     int solved = 0;     do {       if (sol_row(pattern[0], pattern[1], pattern[2], pattern[3])) {         solved = 1;         break;       }       if (sol_col(pattern[0], pattern[1], pattern[2], pattern[3])) {         solved = 1;         break;       }     } while (next_permutation(pattern, pattern + 4));     if (solved)       for (int i = 0; i < n; ++i) puts(temp[i]);     else       puts( 0 );     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, p, q, i, j;     int cnt = 0;     char s[1000];     scanf( %d %d %d n , &n, &p, &q);     gets(s);     while (n % q != 0 && n >= p) {       ++cnt;       n -= p;     }     if (n % q != 0)       puts( -1 );     else {       printf( %d n , cnt + n / q);       for (i = 0; i < cnt; i++) {         for (j = 0; j < p; j++) putchar(s[i * p + j]);         printf(  n );       }       for (i = 0; i < n / q; i++) {         for (j = 0; j < q; j++) putchar(s[cnt * p + i * q + j]);         printf(  n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   char a[4][100][100];   int c[6];   int check(int le, int s, char st) {     int ct = 0;     for (int i = 0; i < s; i++) {       for (int j = 0; j < s; j++) {         if ((i - (s - 1) / 2 + j - (s - 1) / 2) % 2 == 0 && a[le][i][j] != st) {           ct++;         } else if ((i - (s - 1) / 2 + j - (s - 1) / 2) % 2 != 0 &&                    a[le][i][j] == st) {           ct++;         }       }     }     return ct;   }   int main() {     int si;     scanf( %d , &si);     getchar();     for (int k = 0; k < 4; k++) {       for (int i = 0; i < si; i++) {         char s[101];         scanf( %s , &s);         for (int r = 0; r < si; r++) a[k][i][r] = s[r];         getchar();       }       if (k != 3) getchar();     }     c[0] = check(0, si,  1 ) + check(1, si,  1 ) + check(2, si,  0 ) +            check(3, si,  0 );     c[1] = check(0, si,  1 ) + check(1, si,  0 ) + check(2, si,  1 ) +            check(3, si,  0 );     c[2] = check(0, si,  1 ) + check(1, si,  0 ) + check(2, si,  0 ) +            check(3, si,  1 );     c[3] = check(0, si,  0 ) + check(1, si,  1 ) + check(2, si,  1 ) +            check(3, si,  0 );     c[4] = check(0, si,  0 ) + check(1, si,  1 ) + check(2, si,  0 ) +            check(3, si,  1 );     c[5] = check(0, si,  0 ) + check(1, si,  0 ) + check(2, si,  1 ) +            check(3, si,  1 );     int ans = 40000;     for (int i = 0; i < 6; i++) {       ans = min(c[i], ans);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, cnt, maxi;   char c;   int star[105][105];   int lefted[105][105];   int righted[105][105];   int up[105][105];   int down[105][105];   int chk[105][105];   struct ryunha {     int x, y, r;   } ans;   vector<ryunha> res;   int main(void) {     cin >> N >> M;     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= M; j++) {         cin >> c;         while (c !=  .  && c !=  * ) cin >> c;         star[i][j] = (c ==  .  ? 0 : 1);         if (c ==  * ) chk[i][j] = 1;       }     }     for (int i = 1; i <= N; i++) {       cnt = 0;       for (int j = 1; j <= M; j++) {         if (star[i][j])           cnt++;         else           cnt = 0;         lefted[i][j] = cnt;       }     }     for (int i = 1; i <= N; i++) {       cnt = 0;       for (int j = M; j >= 1; j--) {         if (star[i][j])           cnt++;         else           cnt = 0;         righted[i][j] = cnt;       }     }     for (int j = 1; j <= M; j++) {       cnt = 0;       for (int i = 1; i <= N; i++) {         if (star[i][j])           cnt++;         else           cnt = 0;         up[i][j] = cnt;       }     }     for (int j = 1; j <= M; j++) {       cnt = 0;       for (int i = N; i >= 1; i--) {         if (star[i][j])           cnt++;         else           cnt = 0;         down[i][j] = cnt;       }     }     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= M; j++) {         if (star[i][j]) {           maxi = min({lefted[i][j], righted[i][j], up[i][j], down[i][j]});           int change = 0;           if (maxi >= 2) {             if (chk[i][j]) chk[i][j] = 0, change = 1;             for (int k = 1; k <= maxi - 1; k++) {               if (chk[i + k][j]) chk[i + k][j] = 0, change = 1;               if (chk[i - k][j]) chk[i - k][j] = 0, change = 1;               if (chk[i][j - k]) chk[i][j - k] = 0, change = 1;               if (chk[i][j + k]) chk[i][j + k] = 0, change = 1;             }           }           if (change) {             ans.x = i;             ans.y = j;             ans.r = maxi - 1;             res.push_back(ans);           }         }       }     }     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= M; j++) {         if (chk[i][j]) return !printf( -1 );       }     }     printf( %d n , res.size());     for (int i = 0; i < res.size(); i++)       printf( %d %d %d n , res[i].x, res[i].y, res[i].r);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000007;   const long long linf = 1LL << 62;   const unsigned long long ulinf = 1ULL << 63;   const double eps = 0.000001;   const double pi = 3.14159265358979323846;   template <class T>   T abs(T a) {     return a >= 0 ? a : -a;   }   template <class T>   T sqr(T a) {     return a * a;   }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   T mod(T a, T b) {     return (a % b + b) % b;   }   template <class T>   T addmod(T a, T b, T c) {     return (T)mod((long long)a + b, (long long)c);   }   template <class T>   T mulmod(T a, T b, T c) {     return (T)mod((long long)a * b, (long long)c);   }   template <class T>   T powmod(T a, T b, T c) {     return (T)mod(         b ? mulmod(mod(sqr((long long)powmod(a, b >> 1, c)), (long long)c),                    (b & 1LL) ? a : 1LL, (long long)c)           : 1LL,         (long long)c);   }   template <class T>   void maxe(T &a, T b) {     a = max(a, b);   }   template <class T>   void mine(T &a, T b) {     a = min(a, b);   }   template <class T>   void mode(T &a, T b) {     a = mod(a, b);   }   template <class T>   void addmode(T &a, T b, T c) {     a = addmod(a, b, c);   }   template <class T>   void mulmode(T &a, T b, T c) {     a = mulmod(a, b, c);   }   template <class T>   void powmode(T &a, T b, T c) {     a = powmod(a, b, c);   }   int iszero(double a) { return abs(a) <= eps; }   template <class T>   void geti(T &a) {     a = 0;     long long b = 1;     char c = getchar();     if (c ==  - )       b = -1;     else       a = c - 48;     while ((c = getchar()) !=     && c !=   n ) a = a * 10 + c - 48;     a *= b;   }   void fileio_in_out() {     freopen( .in ,  r , stdin);     freopen( .out ,  w , stdout);   }   void fileio_txt() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   const int N = 1111111;   const int M = 1111111;   int test;   long long n, m, k, ans;   long long dp[N];   long long s[N], sinv[N];   const long long md = inf;   long long c(long long a, long long b) {     return s[a] * (sinv[b] * sinv[a - b] % md) % md;   }   long long inv(long long a, long long p) { return powmod(a, p - 2, p); }   long long getans() {     if (n == 0) return k ^ (m > 1);     if (m == 0) return k ^ (n & 1);     s[0] = sinv[0] = 1;     for (long long i = 1; i <= n + m; i++) {       s[i] = s[i - 1] * i % md;       sinv[i] = sinv[i - 1] * inv(i, md) % md;     }     if (k) n--;     dp[0] = (m > 1);     for (long long i = 1; i <= n; i++)       dp[i] = (c(i + m, i) - dp[i - 1] + md) % md;     return dp[n];   }   int main() {     scanf( %I64d%I64d%I64d , &n, &m, &k);     ans = getans();     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200500;   int inp[MAX];   int out[MAX];   bool flag[MAX];   map<long long, int> ID;   map<long long, int> hasInp;   namespace hopcroftKarp {   int ptr[100011], next[200011], zu[200011];   int n, m, match[100011], D[100011], q[100011];   void init(int _n) {     n = _n;     m = 0;     memset(ptr, ~0, sizeof(int) * (n + 1));   }   void add_edge(int u, int v) {     next[m] = ptr[u];     ptr[u] = m;     zu[m] = v;     ++m;   }   bool bfs() {     int u, v;     register int i;     int qh = 0, qt = 0;     for (i = 1; i <= n; i++) {       if (!match[i]) {         D[i] = 0;         q[qt++] = i;       } else         D[i] = (1 << 28);     }     D[0] = (1 << 28);     while (qh < qt) {       u = q[qh++];       if (u != 0) {         for (i = ptr[u]; ~i; i = next[i]) {           v = zu[i];           if (D[match[v]] == (1 << 28)) {             D[match[v]] = D[u] + 1;             q[qt++] = match[v];           }         }       }     }     return D[0] != (1 << 28);   }   bool dfs(int u) {     int v;     register int i;     if (u) {       for (i = ptr[u]; ~i; i = next[i]) {         v = zu[i];         if (D[match[v]] == D[u] + 1) {           if (dfs(match[v])) {             match[v] = u;             match[u] = v;             return true;           }         }       }       D[u] = (1 << 28);       return false;     }     return true;   }   int run() {     int matching = 0;     register int i;     while (bfs())       for (i = 1; i <= n; i++)         if (!match[i] && dfs(i)) matching++;     return matching;   }   void call(int N, long long a, long long b) {     int x, y;     long long vx, vy;     for (int i = 1; i <= N; i++) {       if (flag[i]) continue;       x = i;       y = match[x];       vx = inp[i];       vy = inp[y];       if (vx + vy == a) {         out[x] = out[y] = 0;       } else         out[x] = out[y] = 1;       flag[x] = flag[y] = true;     }     for (int i = 1; i <= N; i++) {       if (i != 1) cout <<    ;       cout << out[i];     }     cout <<   n ;     return;   }   };  // namespace hopcroftKarp   int main() {     long long a, b;     int n;     std::ios_base::sync_with_stdio(false);     cin >> n >> a >> b;     for (int i = 1; i <= n; i++) {       cin >> inp[i];       hasInp[inp[i]] = i;     }     long long x, rx, tx;     int p = 0;     hopcroftKarp::init(n);     for (int i = 1; i <= n; i++) {       x = inp[i];       rx = a - x;       tx = b - x;       if (hasInp.find(rx) != hasInp.end()) {         hopcroftKarp::add_edge(i, hasInp[rx]);       }       if (hasInp.find(tx) != hasInp.end()) {         hopcroftKarp::add_edge(i, hasInp[tx]);       }     }     int cnt = hopcroftKarp::run();     if (2 * cnt >= (n)) {       cout <<  YES n ;       hopcroftKarp::call(n, a, b);     } else       cout <<  NO n ;     return 0;   }