#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long s = 0, w = 1;     register char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();     return s * w;   }   void print(long long x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) print(x / 10);     putchar(x % 10 +  0 );   }   long long n, c, x, y, res = 1, now = 1;   signed main() {     n = read(), x = read(), y = read(), c = read();     if (c == 1) {       puts( 0 );       return 0;     }     for (; c > res; now++) {       long long L = min(now, y - 1);       if (L == now) res--;       res += max(0ll, L - max(now - x + 1, 1ll) + 1) +              max(0ll, L - max(x + now - n, 1ll) + 1);       long long R = min(now, n - y);       if (R == now) res--;       res += max(0ll, R - max(now - x + 1, 0ll) + 1) +              max(0ll, R - max(x + now - n, 0ll) + 1);     }     printf( %lld n , --now);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int rdi() {     int d;     scanf( %d , &d);     return d;   }   inline char rdc() {     scanf(   );     return getchar();   }   inline string rds() {     string s;     cin >> s;     return s;   }   inline double rddb() {     double d;     scanf( %lf , &d);     return d;   }   template <class T>   inline bool setmin(T& a, T b) {     return a > b ? a = b, true : false;   }   template <class T>   inline bool setmax(T& a, T b) {     return a < b ? a = b, true : false;   }   struct debugger {     template <typename T>     debugger& operator,(const T& x) {       cerr << x <<  , ;       return *this;     }   } dbgr;   const int N = 131072, M = 128;   char s[N];   int n, c[3], cnt[N][3];   int Abs(int x) { return x < 0 ? -x : +x; }   int main() {     scanf( %s , s + 1), n = strlen(s + 1);     for (int i = (1); i <= (n); ++i)       memcpy(cnt[i], cnt[i - 1], sizeof cnt[i]), ++cnt[i][s[i] -  x ];     for (int repp_b = (rdi()), repp = 0; repp < repp_b; ++repp) {       int l = rdi(), r = rdi();       for (int i = (0); i < (3); ++i) c[i] = cnt[r][i] - cnt[l - 1][i];       int mx = *max_element(c, c + 3);       int mn = *min_element(c, c + 3);       puts(r - l + 1 < 3 || mx - mn <= 1 ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[4];   int y[4];   int newx[4];   int newy[4];   int T;   int get() {     int answ = INT_MAX;     for (auto y1 : y)       for (auto y2 : y) {         int delta = abs(y1 - y2);         if (delta == 0) continue;         set<int> s;         for (auto x1 : x)           for (auto x2 : x)             for (auto d : {0, -delta, -2 * delta, 1, -delta + 1, -2 * delta + 1})               s.insert((x1 + x2 + d) / 2);         for (auto x1 : s) {           int p[4] = {3, 2, 1, 0};           for (int ori = 0; ori < 24; ori++) {             next_permutation(p, p + 4);             int xs[4] = {x1, x1, x1 + delta, x1 + delta};             int ys[4] = {y1, y2, y1, y2};             bool flag = false;             for (int i = 0; i < 4; i++)               if (xs[i] != x[p[i]] && ys[i] != y[p[i]]) {                 flag = true;               }             if (flag) continue;             int t = 0;             for (int i = 0; i < 4; i++)               t = max(t, abs(xs[i] - x[p[i]]) + abs(ys[i] - y[p[i]]));             if (answ > t) {               answ = t;               for (int i = 0; i < 4; i++) {                 newx[p[i]] = xs[i];                 newy[p[i]] = ys[i];               }             }           }         }       }     return answ;   }   int boom = 1e9;   int main() {     scanf( %d , &T);     while (T--) {       for (int i = 0; i < 4; i++) {         scanf( %d%d , &x[i], &y[i]);         x[i] = x[i] + boom;         y[i] = y[i] + boom;       }       int t1 = get();       swap(x, y);       swap(newx, newy);       int t2 = get();       swap(x, y);       swap(newx, newy);       if (t1 < t2) get();       if (min(t1, t2) == INT_MAX) {         puts( -1 );       } else {         printf( %d n , min(t1, t2));         for (int i = 0; i < 4; i++)           printf( %d %d n , newx[i] - boom, newy[i] - boom);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<char> sequ;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     long long num;     cin >> n;     vector<long long> a(n);     vector<long long> b(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     if (n == 1 && a[0] == b[0]) {       cout <<  SMALL n0 n ;       return 0;     }     if (n == 1) {       cout <<  IMPOSSIBLE n ;       return 0;     }     long long pep_op = 0, rev_op = 0;     if (n == 2) {       long long a0 = a[0], a1 = a[1], b0 = b[0], b1 = b[1];       if (a0 > a1) {         swap(a0, a1);       }       while (1) {         if ((a0 == b0 && a1 == b1) || (a0 == b1 && a1 == b0)) {           if (a[0] != a0) {             rev_op++;             sequ.push_back( R );           }           if (pep_op > 200000)             cout <<  BIG n  << pep_op <<   n ;           else {             cout <<  SMALL n  << pep_op + rev_op <<   n ;             int sz = sequ.size();             for (int i = sz - 1; i >= 0; i--) cout << sequ[i];             cout <<   n ;           }           return 0;         }         if (b0 > b1) {           swap(b0, b1);           sequ.push_back( R );           rev_op++;         }         if (a0 > b0 || a1 > b1) {           cout <<  IMPOSSIBLE n ;           return 0;         }         long long temp = (b1 - max(b0, a1)) % b0;         long long pref = (b1 - max(b0, a1)) / b0;         pep_op = pref + pep_op;         if (pep_op <= 200000) {           while (pref--) sequ.push_back( P );         }         b1 = temp + max(b0, a1);         if (b0 + b1 > a0 + a1) {           long long temp1 = b0;           b0 = b1 - b0;           b1 = temp1;           sequ.push_back( P );           sequ.push_back( R );           pep_op++;           rev_op++;         }       }       return 0;     }     while (b[0] + b[n - 1] > a[0] + a[n - 1]) {       if (b[1] != b[0]) {         bool order = true;         if (b[1] > b[0]) {           for (int i = 1; i < n; i++) {             if (b[i] <= b[i - 1]) {               order = false;               break;             }           }         } else if (b[0] > b[1]) {           reverse(b.begin(), b.end());           for (int i = 1; i < n; i++) {             if (b[i] <= b[i - 1]) {               order = false;               break;             }           }           if (order == true) {             sequ.push_back( R );             rev_op++;           }         }         if (order == true) {           for (int i = n - 1; i > 0; i--) b[i] = b[i] - b[i - 1];           sequ.push_back( P );           pep_op++;         } else           break;       } else         break;     }     int count = 0;     int rcount = 0;     for (int i = 0; i < n; i++) {       if (a[i] == b[i]) count++;     }     for (int i = 0, j = n - 1; i < n; i++, j--) {       if (a[i] == b[j]) rcount++;     }     if (rcount == n && count != n) {       sequ.push_back( R );       rev_op++;     }     if (count == n || rcount == n) {       if (pep_op <= 200000) {         cout <<  SMALL n  << pep_op + rev_op <<   n ;         int sz = sequ.size();         for (int i = sz - 1; i >= 0; i--) cout << sequ[i];         cout <<   n ;       } else         cout <<  BIG n  << pep_op <<   n ;     } else {       cout <<  IMPOSSIBLE n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     int a;     scanf( %d%d , &n, &x);     int sum = 0;     while (n--) {       scanf( %d , &a);       sum += a;     }     int count = 0;     if (sum == 0) {     } else {       if (abs(sum) <= x) {         count = 1;       } else {         count = abs(sum) / abs(x);         if (abs(sum) % abs(x) != 0) count++;       }     }     cout << count << endl;   }


#include <bits/stdc++.h>   int main() {     static char xx[100 + 1], yy[100 + 1];     int n, i;     scanf( %s%s , xx, yy);     n = strlen(xx);     for (i = 0; i < n; i++)       if (xx[i] < yy[i]) {         printf( -1 n );         return 0;       }     printf( %s n , yy);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   int main() {     int T = read();     while (T--) {       int n = read(), a = read(), flag = 0, k;       for (int i = 2; i <= n; i++) {         int b = read();         if (abs(a - b) >= 2) {           k = i;           flag = 1;         }         a = b;       }       if (flag)         cout <<  YES n  << k - 1 <<     << k << endl;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool foiare[1024], cand[1024], foivert[1024];   int n, a[32];   int main() {     scanf( %d , &n);     memset(foiare, false, sizeof(foiare));     memset(foivert, false, sizeof(foivert));     for (int i = 0; i < n; i++) {       for (int j = 1; j <= 1000; j++)         if (!foivert[j]) {           bool podej = true;           memset(cand, false, sizeof(cand));           for (int k = 0; k < i; k++)             if (foiare[a[k] + j] or a[k] + j > 1000) {               podej = false;               break;             } else if (cand[a[k] + j]) {               podej = false;               break;             } else               cand[a[k] + j] = true;           if (podej) {             a[i] = j;             foivert[j] = true;             for (int k = 0; k < i; k++) foiare[a[k] + a[i]] = true;             break;           }         }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (j) printf(   );         if (i == j)           printf( 0 );         else           printf( %d , a[i] + a[j]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   int n, m;   long double p[3010][310], delta[310], f[310][3010], ans = 0, lastf[3010];   int num[310];   void solve(int cur) {     num[cur]++;     if (num[cur] >= n) {       delta[cur] = 0;       return;     }     memcpy(lastf, f[cur], sizeof(f[cur]));     f[cur][0] = 0;     for (int i = 1; i <= n; i++)       f[cur][i] = f[cur][i - 1] * (1 - p[i][cur]) + lastf[i - 1] * p[i][cur];     delta[cur] -= f[cur][n];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %Lf , &p[i][j]);         p[i][j] /= 1000;       }     }     for (int i = 1; i <= m; i++) {       f[i][0] = 1;       for (int j = 1; j <= n; j++) f[i][j] = f[i][j - 1] * (1 - p[j][i]);       delta[i] = 1 - f[i][n];     }     for (int i = 1; i <= n; i++) {       long double mx = 0;       int k = 0;       for (int j = 1; j <= m; j++) {         if (delta[j] > mx) mx = delta[j], k = j;       }       ans += mx;       if (!k) break;       solve(k);     }     printf( %.10Lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[10000], b[10000];   void mergesort(int *a, int *b, int n) {     int i0, i1, iRight, iEnd, width, i, j;     for (width = 1; width < n; width <<= 1)       for (i = 0; i < n; i += (width << 1)) {         i0 = i;         i1 = iRight = min(i + width, n);         iEnd = min(i + (width << 1), n);         for (j = i; j < iEnd; j++)           if (i0 < iRight && (a[i0] <= a[i1] || i1 == iEnd))             b[j] = a[i0++];           else             b[j] = a[i1++];         for (j = i; j < iEnd; j++) a[j] = b[j];       }   }   int main() {     int n, x, y;     cin >> n >> x >> y;     int i;     for (i = 0; i < n; i++) cin >> a[i];     mergesort(a, b, n);     int count = 0;     i = 0;     while (count < y) {       i++;       count++;     }     if (a[i] == a[i - 1])       cout <<  0 ;     else       cout << a[i] - a[i - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Test() {     long long n;     cin >> n;     string s[n];     for (long long i = 0; i < n; i++) {       cin >> s[i];     }     long long ans = 0;     for (char i =  a ; i <=  e ; i++) {       vector<pair<long long, long long> > v;       for (long long j = 0; j < n; j++) {         long long cnti = 0, len = s[j].size();         for (long long k = 0; k < len; k++) {           if (s[j][k] == i) {             ++cnti;           }         }         v.push_back(make_pair(2 * cnti - len, cnti));       }       sort(v.begin(), v.end());       long long curr = 0, oth = 0, temp = 0;       for (long long j = n - 1; j >= 0; j--) {         long long length = ((2 * v[j].second) - v[j].first);         long long x = v[j].second;         long long y = (length - v[j].second);         if ((curr + x) > (oth + y)) {           curr += x;           oth += y;           ++temp;         }       }       ans = max(ans, temp);     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout << fixed << setprecision(10);     long long tests;     cin >> tests;     for (long long tc = 1; tc <= tests; tc++) Test();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   const int MAXM = 4e5 + 5;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   int n, m, q, res[MAXN];   int tot, point[MAXN][2];   int x[MAXN], y[MAXN];   int f[MAXM], s[MAXM];   int find(int x) {     if (f[x] == x)       return x;     else       return find(f[x]);   }   void work(int xl, int xr, int yl, int yr) {     if (xl > xr) return;     vector<pair<int, pair<int, int>>> rev;     auto merge = [&](int x, int y) {       x = find(x), y = find(y);       if (x == y) return;       if (s[x] < s[y]) swap(x, y);       rev.emplace_back(x, make_pair(f[x], s[x]));       rev.emplace_back(y, make_pair(f[y], s[y]));       s[x] += s[y], f[y] = x;       return;     };     auto addedge = [&](int x, int y) {       merge(point[x][0], point[y][1]);       merge(point[x][1], point[y][0]);       return;     };     auto check = [&](int x, int y) {       return find(point[x][0]) != find(point[y][0]);     };     auto clear = [&]() {       reverse(rev.begin(), rev.end());       for (auto x : rev) {         f[x.first] = x.second.first;         s[x.first] = x.second.second;       }       rev.clear();       return;     };     if (yl == yr) {       for (int i = xl; i <= xr; i++) res[i] = yl;       return;     }     bool fail = false;     int mid = (yl + yr + 1) / 2, divp = 0;     for (int i = max(yl, 1); i < mid && !fail; i++) {       fail |= !check(x[m - i + 1], y[m - i + 1]);       if (!fail) addedge(x[m - i + 1], y[m - i + 1]);     }     if (fail) {       clear();       work(xl, xr, yl, mid - 1);       return;     }     divp = xl;     for (int i = xl; i <= xr - 1; i++) {       if (check(x[i], y[i])) {         divp++;         addedge(x[i], y[i]);       } else         break;     }     clear();     for (int i = max(yl, 1); i < mid; i++) addedge(x[m - i + 1], y[m - i + 1]);     work(xl, divp, mid, yr);     clear();     fail = false;     for (int i = xl; i <= divp; i++) {       if (!check(x[i], y[i])) {         fail = true;         break;       }       addedge(x[i], y[i]);     }     if (!fail) work(divp + 1, xr, yl, mid - 1);     clear();   }   int main() {     read(n), read(m), read(q);     for (int i = 1; i <= m; i++) read(x[i]), read(y[i]);     for (int i = 1; i <= n; i++) {       point[i][0] = ++tot;       f[tot] = tot, s[tot] = 1;       point[i][1] = ++tot;       f[tot] = tot, s[tot] = 1;     }     work(1, m, 0, m);     for (int i = 1; i <= q; i++) {       int l, r;       read(l), read(r);       if (res[l] >= m - r + 1)         puts( NO );       else         puts( YES );     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int p, q, l, r;     scanf( %d %d %d %d , &p, &q, &l, &r);     std::vector<std::pair<int, int> > fixed;     std::vector<std::pair<int, int> > changing;     for (int k = 0; k < p; k++) {       int a, b;       scanf( %d %d , &a, &b);       fixed.push_back(std::pair<int, int>(a, b));     }     for (int k = 0; k < q; k++) {       int a, b;       scanf( %d %d , &a, &b);       changing.push_back(std::pair<int, int>(a, b));     }     bool done;     int output(0);     for (int k = l; k <= r; k++) {       done = 0;       for (int x = 0; x < fixed.size(); x++) {         if (done) {           continue;         }         for (int y = 0; y < changing.size(); y++) {           if ((fixed[x].second < k + changing[y].first) ||               (k + changing[y].second < fixed[x].first)) {             continue;           } else {             done = 1;             ++output;             break;           }         }       }     }     printf( %d n , output);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int mod = 1000000007;   const int inf = 0x3f3f3f3f;   const int maxn = 200005;   void task() {     int n;     cin >> n;     vector<int> row(n, 0), coulmn(n, 0);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         int a;         cin >> a;         row[i] += a;         coulmn[j] += a;       }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (coulmn[j] > row[i]) ans++;     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T = 1;     while (T--) {       task();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     int a[k + 1];     for (int i = 0; i < k; i++) cin >> a[i];     long long int comb[1005][1005];     comb[0][0] = 1;     for (int i = 1; i < 1005; i++) {       comb[i][0] = 1;       for (int j = 1; j <= i; j++) {         comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % 1000000007;       }     }     long long sum = 0, ans = 1;     for (int i = 0; i < k; i++) {       ans = (ans * comb[sum + a[i] - 1][a[i] - 1]) % 1000000007;       sum += a[i];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 50005, M = 50005;   int mo;   struct matrix {     int a[2][2];     int *operator[](const int i) { return a[i]; }     const int *operator[](const int i) const { return a[i]; }     friend matrix operator*(const matrix &a, const matrix &b) {       matrix c;       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) {           long long s = 0;           for (int k = 0; k < 2; k++) s += (long long)a[i][k] * b[k][j];           c[i][j] = s % mo;         }       return c;     }   };   int n, m;   long long k;   int s[N];   pair<long long, int> a[M];   inline int gs(long long i) {     pair<long long, int> *it = lower_bound(a, a + m, pair<long long, int>(i, 0));     if (it < a + m && it->first == i) return it->second;     return s[i % n];   }   matrix t[N * 4];   void build(int cur, int beg, int end) {     if (end - beg == 1) {       t[cur][1][0] = 1 % mo;       t[cur][0][1] = s[beg];       t[cur][1][1] = s[(beg + 1) % n];       return;     }     int mid = beg + end >> 1;     build(cur << 1, beg, mid);     build(cur << 1 | 1, mid, end);     t[cur] = t[cur << 1] * t[cur << 1 | 1];   }   matrix ans;   void query(int cur, int beg, int end, int L, int R) {     if (end <= L || beg >= R) return;     if (beg >= L && end <= R) {       ans = ans * t[cur];       return;     }     int mid = beg + end >> 1;     query(cur << 1, beg, mid, L, R);     query(cur << 1 | 1, mid, end, L, R);   }   long long p[M * 2], *top = p;   long long q[M * 2], *toq = q;   void power(long long s) {     matrix a = t[1];     for (; s; s >>= 1, a = a * a)       if (s & 1) ans = ans * a;   }   int main() {     scanf( %I64d%d , &k, &mo);     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &s[i]), s[i] %= mo;     scanf( %d , &m);     for (int i = 0; i < m; i++)       scanf( %I64d%d , &a[i].first, &a[i].second), a[i].second %= mo;     sort(a, a + m);     for (int i = 0; i < m; i++)       p[i << 1] = a[i].first - 1, p[i << 1 | 1] = a[i].first;     p[m * 2] = k;     sort(p, p + m * 2 + 1);     top = unique(p, p + m * 2 + 1);     for (int i = 0; i < top - p; i++) q[i] = p[i] / n;     toq = unique(q, q + (top - p));     build(1, 0, n);     ans[0][0] = ans[1][1] = 1 % mo;     ans[0][1] = ans[1][0] = 0;     long long block = 0;     for (int i = 0, j = 0; i < toq - q; i++) {       power(q[i] - block);       block = q[i];       long long id = block * n;       for (; j < top - p && p[j] / n == block; j++) {         query(1, 0, n, id % n, p[j] % n);         id = p[j];         if (id == k) {           printf( %d n , ans[1][0]);           return 0;         }         matrix tmp;         tmp[0][0] = 0;         tmp[1][0] = 1 % mo;         tmp[0][1] = gs(id);         tmp[1][1] = gs(id + 1);         ans = ans * tmp;         id++;       }       query(1, 0, n, id - block * n, n);       id = (++block) * n;     }   }


#include <bits/stdc++.h>   using namespace std;   string s[1010];   int main() {     int n;     cin >> n;     bool f = 1;     for (int i = 0; i < n; ++i) {       cin >> s[i];       if (f && s[i].substr(0, 2) ==  OO ) {         f = 0;         s[i][0] =  + ;         s[i][1] =  + ;       }       if (f && s[i].substr(3, 2) ==  OO ) {         f = 0;         s[i][3] =  + ;         s[i][4] =  + ;       }     }     if (f) {       cout <<  NO ;     } else {       cout <<  YES  << endl;       for (int i = 0; i < n; ++i) cout << s[i] << endl;     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define ll int long long   #define mp make_pair   //#define for(i,n) for(int i=0;i<n;i++)   #define F first   #define S second   #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   #define N 1000000007   #define pq priority queue   #define pb push_back   #define pf push_front   #define mt make_tuple   #define prec(a) fixed<<setprecision(9)<<a   #define endl   n    #define fast_set s.max_load_factor(0.25);s.reserve(500);   #define cy cout<< YES <<endl;   #define cn cout<< NO <<endl;   #define all(v) v.begin(),v.end()   #define allr(v) v.rbegin(),v.rend()   const long double PI = (long double)(3.1415926535897932384626433832795);   bool check(int a,int b,int hh,int mm)   {        int savea=a,saveb=b;    int arr[10];    memset(arr,-1,sizeof(arr));    arr[0]=0;    arr[1]=1;    arr[2]=5;    arr[5]=2;    arr[8]=8;    int h=0,m=0;    h=arr[(b%10)]*10+arr[(b/10)];    m=arr[(a%10)]*10+arr[(a/10)];    if(arr[a%10] == -1 || arr[a/10] == -1 || arr[b%10] == -1 || arr[b/10] == -1){     return 0;    }    return (h<hh&&m<mm);   }   int main()    {    fast;    int test,n,i,j,k;    cin>>test;    while(test--)    {     string str;     cin>>n>>k>>str;     if(n%k!=0)     {      cout<< -1 <<endl;     }     else     {      int hash1[26]={0};      n=str.length();      for(i=0;i<n;i++)      {       hash1[str[i]- a ]++;      }      for(i=0;i<26;i++)      {       if(hash1[i]%k!=0)       {        break;       }      }      if(i==26)      {       cout<<str<<endl;      }      else      {       for(i=n-1;i>=0;i--)       {        hash1[str[i]- a ]--;        for(j=str[i]- a +1;j<26;j++)        {         bool flag=1;         hash1[j]++;         int it=0,cnt=0;         for(it=0;it<26;it++)         {          cnt+=((k-(hash1[it]%k))%k);         }         int avail = n-i-1;         if(cnt>avail||(avail-cnt)%k!=0)         {          flag=0;         }         hash1[j]--;         if(flag)         {          break;         }        }        if(j<26)        {         break;        }       }       if(i<0)       {        cout<<i<<endl;       }       else       {        //cout<<i<<   <<j<<endl;        str[i]= a +j;        hash1[j]++;        int it=0,mini=0;        vector<int>s;        int sum=0;        for(it=0;it<26;it++)        {         if(hash1[it]>0)          mini=min(mini,it);         int a=((k-(hash1[it]%k))%k);         sum+=a;         while(a--)         {          mini=min(mini,it);          s.pb(it);         }        }        //cout<<sum<<endl;        int a=n-i-1-sum;        while(a--)        {         s.pb(mini);        }        int c=0;        //cout<<s.size()<<endl;        sort(all(s));        for(j=i+1;j<n;j++)        {         str[j]= a +s[c];         c++;                 }        cout<<str<<endl;       }      }     }    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, counter, a, b, c;     cin >> t;     while (t--) {       cin >> a >> b >> c;       counter = 0;       while (++counter) {         (a < b) ? a += b : b += a;         if (max(a, b) > c) break;       }       cout << counter << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   set<pair<int, int> > ss;   struct Node {     int l, r, ope;     bool operator<(const Node &b) const {       if (l != b.l) return l < b.l;       return ope > b.ope;     }   };   Node a[200010];   int num[100010], ans[100010];   int main() {     int n, m;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &a[i].l, &a[i].r);       a[i].ope = -1 - i;     }     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d%d%d , &a[i + n].l, &a[i + n].r, &num[i]);       a[i + n].ope = i;     }     sort(a, a + n + m);     for (int i = 0; i < n + m; i++) {       if (a[i].ope >= 0) {         ss.insert(make_pair(a[i].r, a[i].ope));       } else {         if (ss.size() == 0) {           puts( NO );           return 0;         }         set<pair<int, int> >::iterator pos =             ss.lower_bound(make_pair(a[i].r, -1));         if (pos == ss.end()) {           puts( NO );           return 0;         }         pair<int, int> x = *pos;         num[x.second]--;         ans[-(a[i].ope + 1)] = x.second + 1;         if (num[x.second] == 0) {           ss.erase(pos);         }       }     }     puts( YES );     for (int i = 0; i < n; i++) {       printf( %d  , ans[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const long long INFLL = 0x3f3f3f3f3f3f3f3f;   const int MAXN = 5e5 + 5;   int n, k;   struct nodes {     int maxn[12], minn[12], siz;     bool operator<(const nodes& x) const {       int f = 1;       for (int i = 1; i <= k; i++)         if (maxn[i] > x.minn[i]) f = 0;       return f;     }   };   int main() {     cin >> n >> k;     multiset<nodes> s;     for (int i = 1; i <= n; i++) {       nodes now;       for (int j = 1; j <= k; j++) {         scanf( %d , &now.maxn[j]);         now.minn[j] = now.maxn[j];       }       now.siz = 1;       auto p = s.lower_bound(now);       auto p2 = s.upper_bound(now);       nodes nxt = now;       vector<multiset<nodes>::iterator> v;       for (auto sp = p; sp != p2; sp++) {         for (int i = 1; i <= k; i++) {           nxt.maxn[i] = max(nxt.maxn[i], sp->maxn[i]);           nxt.minn[i] = min(nxt.minn[i], sp->minn[i]);         }         nxt.siz += sp->siz;         v.push_back(sp);       }       for (int i = 0; i < v.size(); i++) s.erase(v[i]);       s.insert(nxt);       printf( %d n , s.rbegin()->siz);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 15;   int a[N], dp[N][2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i += 1) {       cin >> a[i];     }     int ans = 0;     for (int i = n; i >= 1; i -= 1) {       dp[i][0] = 1;       if (i == n) continue;       if (a[i] < a[i + 1]) dp[i][0] += dp[i + 1][0];     }     for (int i = 1; i <= n; i += 1) {       dp[i][1] = 1;       if (i == 1) continue;       if (a[i] > a[i - 1]) {         dp[i][1] += dp[i - 1][1];       }     }     for (int i = 1; i <= n; i += 1) {       int x = dp[i + 1][0];       int y = dp[i - 1][1];       ans = max(ans, min(n, x + 1));       ans = max(ans, min(n, y + 1));       if (a[i - 1] + 1 < a[i + 1]) ans = max(ans, min(n, x + y + 1));     }     if (n == 1) ans = 1;     cout << min(ans, n) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100100;   const long long Mod = 1e9 + 7;   long long Rec(long long i, long long j, long long c);   long long p[N];   long long x[N];   vector<long long> Adj[N];   vector<long long> Dp[N][2];   int main() {     long long n;     cin >> n;     for (long long i = 2; i <= n; i++)       scanf( %I64d , p + i), Adj[++p[i]].push_back(i);     for (long long i = 1; i <= n; i++) scanf( %I64d , x + i);     for (long long i = 0; i < N; i++)       Dp[i][0] = Dp[i][1] = vector<long long>(Adj[i].size(), -1);     cout << Rec(1, 0, 0);   }   long long Rec(long long i, long long j, long long c) {     if (j == 0) c += x[i];     if (c > 1) return 0;     if (j == Adj[i].size()) return c;     if (Dp[i][c][j] + 1) return Dp[i][c][j];     long long Res1 = (Rec(i, j + 1, c) * Rec(Adj[i][j], 0, 0)) % Mod;     long long Res2 = (c ? Rec(i, j + 1, 1) * Rec(Adj[i][j], 0, 1) : 0) % Mod;     long long Res3 = (!c ? (Rec(i, j + 1, 1) * Rec(Adj[i][j], 0, 0)) % Mod +                                (Rec(i, j + 1, 0) * Rec(Adj[i][j], 0, 1)) % Mod                          : 0) %                      Mod;     return Dp[i][c][j] = (Res1 + Res2 + Res3) % Mod;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   map<char, bool> m;   int main() {     cin >> n >> s;     char pl =  a ;     int sum = 0, sum2 = 0;     int len = s.size();     int book = 0;     for (int i = 0; i < len / 2; ++i) {       if (isalpha(s[i])) {         if (!m[s[i]]) {           m[s[i]] = 1;           sum2++;         }         if (s[len - i - 1] ==  ? ) {           s[len - i - 1] = s[i];         } else if (s[i] != s[len - i - 1]) {           puts( IMPOSSIBLE );           return 0;         }       }     }     for (int i = len / 2; i < len; ++i) {       if (isalpha(s[i])) {         if (!m[s[i]]) {           m[s[i]] = 1;           sum2++;         }         if (s[len - i - 1] ==  ? ) {           s[len - i - 1] = s[i];         } else if (s[i] != s[len - i - 1]) {           puts( IMPOSSIBLE );           return 0;         }       } else         sum++;     }     sum2 = n - sum2;     if (sum2 > sum) {       puts( IMPOSSIBLE );       return 0;     }     int tot = sum - sum2;     for (int i = 0; i <= len / 2; ++i) {       if (s[i] ==  ? ) {         if (tot) {           s[i] =  a ;           s[len - i - 1] =  a ;           tot--;         } else {           while (m[pl]) pl++;           s[i] = pl;           s[len - i - 1] = pl;           m[pl] = 1;         }       }     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortcol(const vector<long long int>& v1, const vector<long long int>& v2) {     if (v1[0] == v2[0]) return v1[1] < v2[1];     return v1[0] < v2[0];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m;     cin >> n >> m;     vector<vector<long long int> > A(m, vector<long long int>(n));     vector<long long int> sum(n);     for (long long int i = 0; i < m; i++)       for (long long int j = 0; j < n; j++) cin >> A[i][j];     for (long long int i = 0; i < m; i++) {       for (long long int j = 0; j < n - 1; j++) A[i][j] = A[i][n - 1] - A[i][j];       A[i][n - 1] = i;     }     long long int max = 0, store = -1;     for (long long int i = 0; i < n - 1; i++) {       vector<vector<long long int> > B(m, vector<long long int>(2));       for (long long int j = 0; j < m; j++) {         B[j][0] = A[j][i];         B[j][1] = A[j][n - 1];       }       sort(B.begin(), B.end(), sortcol);       long long int ans = 0, val = 0, check = 0;       for (long long int j = 0; j < m; j++) {         ans += B[j][0];         if (ans > 0) {           val = j;           if (val > max) {             max = val;             store = i;           }           check = 1;           break;         }       }       if (check == 1) continue;       val = m;       if (val > max) {         max = val;         store = i;       }     }     cout << m - max << endl;     vector<vector<long long int> > B(m, vector<long long int>(2));     for (long long int j = 0; j < m; j++) {       B[j][0] = A[j][store];       B[j][1] = A[j][n - 1];     }     sort(B.begin(), B.end(), sortcol);     for (long long int i = max; i < m; i++) cout << B[i][1] + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     int x1, x2, y1, y2;     cin >> n >> m >> k;     map<int, vector<pair<int, int> > > cols;     map<int, vector<pair<int, int> > > rows;     map<int, int> sc;     map<int, int> sr;     for (int i = 0; i < k; i++) {       cin >> x1 >> y1 >> x2 >> y2;       if (x1 == x2)         cols[x1].push_back(make_pair(min(y1, y2), max(y1, y2)));       else         rows[y1].push_back(make_pair(min(x1, x2), max(x1, x2)));     }     vector<pair<int, int> > sizes;     map<int, vector<pair<int, int> > >::iterator it;     vector<pair<int, int> > cuts;     int ans = 0;     for (it = cols.begin(); it != cols.end(); it++) {       cuts = (*it).second;       int sum = 0, last = 0;       sort(cuts.begin(), cuts.end());       for (int i = 0; i < cuts.size(); i++) {         if (cuts[i].first >= last) {           sum += cuts[i].second - cuts[i].first;           last = cuts[i].second;         }         if (cuts[i].second > last) {           sum += cuts[i].second - last;           last = cuts[i].second;         }       }       ans ^= (m - sum);       sc[(*it).first] = m - sum;     }     for (it = rows.begin(); it != rows.end(); it++) {       cuts = (*it).second;       int sum = 0, last = 0;       sort(cuts.begin(), cuts.end());       for (int i = 0; i < cuts.size(); i++) {         if (cuts[i].first >= last) {           sum += cuts[i].second - cuts[i].first;           last = cuts[i].second;         }         if (cuts[i].second > last) {           sum += cuts[i].second - last;           last = cuts[i].second;         }       }       ans ^= (n - sum);       sr[(*it).first] = n - sum;     }     if ((n - 1 - cols.size()) % 2) ans ^= m;     if ((m - 1 - rows.size()) % 2) ans ^= n;     if (ans == 0)       cout <<  SECOND  << endl;     else {       cout <<  FIRST  << endl;       if (cols.size() < n - 1 && (ans ^ m) < m) {         int col = 1;         while (cols.find(col) != cols.end()) col++;         cout << col <<   0   << col <<     << m - (ans ^ m) << endl;         return 0;       }       if (rows.size() < m - 1 && (ans ^ n) < n) {         int row = 1;         while (rows.find(row) != rows.end()) row++;         cout <<  0   << row <<     << n - (ans ^ n) <<     << row << endl;         return 0;       }       for (it = cols.begin(); it != cols.end(); it++) {         int x = (*it).first;         if ((sc[x] ^ ans) >= sc[x]) continue;         int need = (sc[x] ^ ans), last = 0, sum = 0;         cuts = (*it).second;         sort(cuts.begin(), cuts.end());         for (int i = 0; i < cuts.size() && need; i++) {           if (cuts[i].first >= last) {             sum += cuts[i].first - last;             if (sum <= need)               last = cuts[i].second;             else               last = cuts[i].first - (sum - need);             continue;           }           if (cuts[i].second > last) {             last = cuts[i].second;           }         }         if (sum < need) last += (need - sum);         cout << x <<     << last <<     << x <<     << m << endl;         return 0;       }       for (it = rows.begin(); it != rows.end(); it++) {         int x = (*it).first;         if ((sr[x] ^ ans) >= sr[x]) continue;         int need = (sr[x] ^ ans), last = 0, sum = 0;         cuts = (*it).second;         sort(cuts.begin(), cuts.end());         for (int i = 0; i < cuts.size() && need; i++) {           if (cuts[i].first >= last) {             sum += cuts[i].first - last;             if (sum <= need)               last = cuts[i].second;             else               last = cuts[i].first - (sum - need);             continue;           }           if (cuts[i].second > last) {             last = cuts[i].second;           }         }         if (sum < need) last += (need - sum);         cout << last <<     << x <<     << n <<     << x << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) {       long long int n;       cin >> n;       long long int a[n];       for (int i = 0; i < n; i += 1) cin >> a[i];       long long int pre[n];       pre[0] = a[0];       for (long long int i = 1; i < n; i += 1) {         pre[i] = a[i];         pre[i] += pre[i - 1];       }       long long int q;       cin >> q;       for (long long int i = 0; i < q; i += 1) {         long long int x, y;         cin >> x >> y;         x -= 1, y -= 1;         long long int tmp = pre[y] - pre[x] + a[x];         tmp = tmp / 10;         cout << tmp <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, q, i, j, l, r;     cin >> n >> q;     int auxi[n + 2], sum[n + 2];     memset(auxi, 0, sizeof(auxi));     memset(sum, 0, sizeof(sum));     vector<pair<int, int> > v;     for (i = 0; i < q; i++) {       cin >> l >> r;       v.push_back({l, r});       auxi[r + 1] -= 1;       auxi[l] += 1;     }     int net = 0;     for (i = 0; i <= n + 1; i++) {       net += auxi[i];       sum[i] += net;     }     int ans = 0;     for (i = 0; i < q; i++) {       for (j = 0; j <= n; j++) {         auxi[j] = sum[j];       }       int count = 0;       for (j = v[i].first; j <= v[i].second; j++) {         auxi[j]--;       }       int prefix[n + 1];       prefix[0] = 0;       for (j = 1; j <= n; j++) {         prefix[j] = prefix[j - 1] + (auxi[j] == 1);         if (auxi[j]) count++;       }       for (j = i + 1; j < q; j++) {         ans = max(ans, count - prefix[v[j].second] + prefix[v[j].first - 1]);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   const int MAXN = 2e5 + 10;   const int mod = 1e9 + 7;   void reduce(int& x) { x += x >> 31 & mod; }   int mul(int a, int b) { return (long long)a * b % mod; }   int pow(int a, int b, int res = 1) {     for (; b; b >>= 1, a = mul(a, a))       if (b & 1) res = mul(res, a);     return res;   }   const int MAXS = 1e6 + 1;   int pri[MAXS], npri[MAXS], tot;   int fac[MAXS], inv[MAXS];   void sieve() {     inv[0] = inv[1] = 1;     fac[1] = 1;     for (int i = 2; i != MAXS; ++i) {       inv[i] = mul(inv[mod % i], mod - mod / i);       if (!npri[i]) fac[pri[++tot] = i] = i;       for (int j = 1, t; j <= tot && (t = i * pri[j]) < MAXS; ++j) {         npri[t] = true;         fac[t] = pri[j];         if (i % pri[j] == 0) break;       }     }   }   int A[MAXN];   int n, m;   int pre[MAXN];   int tr[MAXN];   void add(int x, int v) {     for (; x; x &= x - 1) tr[x] = mul(tr[x], v);   }   int lst[MAXS], ansl[MAXN];   int ls[MAXN];   std::vector<int> qs[MAXN];   int qry(int x) {     int r = 1;     for (; x <= n; x += x & -x) r = mul(r, tr[x]);     return r;   }   int main() {     std::ios_base::sync_with_stdio(false), std::cin.tie(0);     sieve();     std::cin >> n;     pre[0] = 1;     for (int i = 1; i <= n; ++i) {       std::cin >> A[i];       pre[i] = mul(pre[i - 1], A[i]);       tr[i] = 1;     }     std::cin >> m;     for (int i = 1, r; i <= m; ++i) {       std::cin >> ls[i] >> r;       qs[r].push_back(i);     }     for (int i = 1; i <= n; ++i) {       std::set<int> hl;       int x = A[i];       while (x > 1) hl.insert(fac[x]), x /= fac[x];       for (auto t : hl) {         add(lst[t], mul(inv[t - 1], t));         add(lst[t] = i, mul(inv[t], t - 1));       }       for (auto t : qs[i]) {         ansl[t] = pow(pre[ls[t] - 1], mod - 2, pre[i]);         ansl[t] = mul(ansl[t], qry(ls[t]));       }     }     for (int i = 1; i <= m; ++i) std::cout << ansl[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const int N = 9;   const int MAX = 100007;   const int H = 1 << 9;   int n;   int letter[MAX][N];   int dist[N][N];   int ch[MAX];   vector<int> l[N];   bool checked[N];   int mask[MAX];   int cnt[N][H];   void BFS(int x) {     vector<int> vis(n, 0);     queue<int> bfs;     for (int i = 0; i < 8; ++i) {       checked[i] = 0;     }     for (int i = 0; i < n; ++i) {       letter[i][x] = (int)1e9 + 7;       if (ch[i] == x) {         vis[i] = 1;         bfs.push(i);         letter[i][x] = 0;       }     }     while (!bfs.empty()) {       int v = bfs.front();       bfs.pop();       if (v && !vis[v - 1]) {         vis[v - 1] = 1;         letter[v - 1][x] = letter[v][x] + 1;         bfs.push(v - 1);       }       if (v + 1 < n && !vis[v + 1]) {         vis[v + 1] = 1;         letter[v + 1][x] = letter[v][x] + 1;         bfs.push(v + 1);       }       if (!checked[ch[v]]) {         checked[ch[v]] = 1;         for (auto& u : l[ch[v]]) {           if (!vis[u]) {             vis[u] = 1;             letter[u][x] = letter[v][x] + 1;             bfs.push(u);           }         }       }     }   }   int FindDist(int x, int y) {     int res = abs(x - y);     for (int i = 0; i < 8; ++i) {       res = min(res, 1 + letter[x][i] + letter[y][i]);     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; ++i) {       ch[i] = s[i] -  a ;     }     for (int i = 0; i < 8; ++i) {       for (int j = 0; j < n; ++j) {         if (ch[j] == i) {           l[i].push_back(j);         }       }     }     for (int i = 0; i < 8; ++i) {       BFS(i);     }     for (int i = 0; i < 8; ++i) {       for (int j = 0; j < 8; ++j) {         dist[i][j] = (int)1e9 + 7;         for (auto& v : l[i]) {           dist[i][j] = min(dist[i][j], letter[v][j]);         }       }     }     int maxxx = 2 * 8 - 1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < 8; ++j) {         int temp = letter[i][j] - dist[ch[i]][j];         assert(temp < 2);         mask[i] |= temp << j;       }     }     pair<long long, long long> result = make_pair(0, 0);     for (int i = 0; i < n; ++i) {       for (int j = max(0, i - maxxx); j < i; ++j) {         int d = FindDist(i, j);         if (d > result.first) {           result.first = d;           result.second = 1;         } else if (d == result.first) {           result.second++;         }       }     }     for (int i = 0; i < n; ++i) {       for (int c = 0; c < 8; ++c) {         for (int m = 0; m < 1 << 8; ++m) {           if (cnt[c][m]) {             int temp = (int)1e9 + 7;             for (int d = 0; d < 8; ++d) {               temp = min(temp, 1 + dist[c][d] + ((m >> d) & 1) + dist[ch[i]][d] +                                    ((mask[i] >> d) & 1));             }             if (temp > result.first) {               result.first = temp;               result.second = cnt[c][m];             } else if (temp == result.first) {               result.second += cnt[c][m];             }           }         }       }       if (i - maxxx >= 0) {         int z = i - maxxx;         cnt[ch[z]][mask[z]]++;       }     }     cout << result.first <<     << result.second;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[200005], cnt = 0;   bool vis[200005];   void f(int x) {     while (!vis[x]) vis[x] = 1, x = a[x];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     for (int i = 1; i <= n; ++i)       if (!vis[i]) {         ++cnt;         f(i);       }     if (cnt == 1) cnt = 0;     bool f = 0;     for (int j, i = 1; i <= n; ++i) scanf( %d , &j), f ^= (j & 1);     cnt += !f;     printf( %d n , cnt);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long n;   long long arr[100005];   int c5;   int find(long long a, long long b, long long c) {     long long arr[4];     arr[0] = a;     arr[1] = b;     arr[2] = c;     sort(arr, arr + 3);     if (arr[0] < arr[1] && arr[1] < arr[2])       return 6;     else if (arr[0] == arr[1] && arr[1] < arr[2])       return 3;     else if (arr[0] < arr[1] && arr[1] == arr[2])       return 3;     else       return 1;   }   int main() {     cin >> n;     if (n % 6 != 0) {       printf( 0 n );       return 0;     }     n /= 3;     for (long long x = 1; x * x <= n; x++) {       if (n % x == 0) {         arr[c5++] = x;         if (x * x != n) arr[c5++] = n / x;       }     }     sort(arr, arr + c5);     long long x, y, z;     int ans = 0, cnt = 0;     long long a, b, c;     for (int i = 0; i < c5; i++) {       x = arr[i];       for (int j = i; j < c5 && arr[i] * arr[j] * arr[j] <= n; j++) {         if (n % (arr[i] * arr[j]) == 0) {           y = arr[j];           z = n / (arr[i] * arr[j]);           if (x <= y <= z) {             if (x - y + z > 0 && y - x + z > 0 && y - z + x > 0 &&                 (x - y + z) % 2 == 0) {               cnt++;               a = (x - y + z) / 2;               b = (y - x + z) / 2;               c = (y - z + x) / 2;               ans += find(a, b, c);             }           }         }       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   int main() {     map<int, int> m, p;     int n;     cin >> n;     for (int i = (1); i <= (n); i++) {       int u, v;       cin >> u >> v;       m[u]++;       if (v != u) p[v]++;     }     int ans = 1e9;     if (n % 2) n++;     for (auto i : m) {       int cval = i.second;       int poss = p[i.first];       int reqd = n / 2;       int now = reqd - cval;       if (now <= poss) ans = min(ans, max(0, now));     }     for (auto i : p) {       int poss = i.second;       int cval = m[i.first];       int reqd = n / 2;       int now = reqd - cval;       if (now <= poss) ans = min(ans, max(0, now));     }     if (ans == 1e9)       cout <<  -1 n ;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long prime = 1e9 + 7;   const long long maxN = 1e5 + 5;   const long double pi = 3.1415926536;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k, a, rem = 1e18, t = 1, b = 0;     cin >> n >> k;     for (long long i = (long long)(1); i <= (long long)(k); i++) {       cin >> a;       if ((a <= n) && (n % a < rem)) {         rem = n % a;         t = i;         b = n / a;       }     }     cout << t <<     << b;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v[3000];   long long h[200000], pw[200000];   string st, st1, st2;   long l1, l2, l, ans, fl, g1[20000], g2[20000];   long long gethash(long a, long b) {     return (h[b + 1] - h[a]) * pw[st.size() - b + 1];   }   int main() {     cin >> st;     cin >> st1 >> st2;     pw[0] = 1;     for (int i = 1; i <= 3000; i++) pw[i] = pw[i - 1] * 29;     for (int i = 1; i <= st.size(); i++) h[i] = h[i - 1] + st[i - 1] * pw[i];     l = st.size();     l1 = st1.size();     l2 = st2.size();     for (int i = 0; i <= l - l1; i++) {       fl = 0;       for (int j = 0; j < l1; j++)         if (st1[j] != st[i + j]) {           fl++;           break;         }       if (fl == 0) g1[i] = 1;     }     for (int i = 0; i <= l - l2; i++) {       fl = 0;       for (int j = 0; j < l2; j++)         if (st2[j] != st[i + j]) {           fl++;           break;         }       if (fl == 0) g2[i + l2 - 1] = 1;     }     long lll = max(l1, l2);     for (int i = 0; i < l; i++)       for (int j = i; j < l; j++)         if (g1[i] && g2[j] && (j - i + 1 >= lll)) {           v[j - i + 1].push_back(gethash(i, j));         }     for (int i = 1; i <= l; i++) {       sort(v[i].begin(), v[i].end());       if (v[i].size()) ans++;       for (int j = 1; j < v[i].size(); j++)         if (v[i][j] != v[i][j - 1]) ++ans;     }     cout << ans << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt_9s(long long int num);   long long int power(int num, int exp);   int main() {     long long int num, sale, rem;     cin >> num >> sale;     while (1) {       rem = power(10, cnt_9s(num) + 1);       if (sale >= num % rem + 1)         sale -= (num % rem + 1), num -= (num % rem + 1);       else         break;     }     cout << num << endl;     return 0;   }   long long int power(int num, int exp) {     long long int res = 1;     while (exp != 0) res *= num, exp--;     return res;   }   int cnt_9s(long long int num) {     int cnt = 0;     while (num != 0)       if (num % 10 == 9)         cnt++, num /= 10;       else         break;     return cnt;   }


#include <bits/stdc++.h>   using namespace std;   char a[100100];   int main() {     scanf( %s , a);     int en;     int len = strlen(a);     int r = 0, l = 0;     int ll, rr;     int flag = 0;     int last;     int cnt = 0;     for (int i = 0; a[i] !=   0 ; i++)       if (a[i] ==  # ) en = i;     for (int i = 0; i < len; i++) {       if (a[i] ==  ( )         l++;       else {         r++;         if (a[i] ==  # ) cnt++;       }       if (r > l) {         flag = 1;         break;       }       if (i == en) ll = l, rr = r;     }     last = l - r + 1;     rr += last - 1;     if (ll < rr) flag = 1;     for (int i = en + 1; i < len; i++) {       if (a[i] ==  ( )         ll++;       else         rr++;       if (rr > ll) {         flag = 1;         break;       }     }     if (rr != ll) flag = 1;     if (flag)       puts( -1 );     else {       for (int i = 0; i < cnt - 1; i++) puts( 1 );       printf( %d n , last);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 300010;   int n;   int maxx;   int node[2 * MAX][30];   int cau[MAX];   int site;   int other;   void in() {     scanf( %d , &n);     int a, b;     char c;     for (int i = 1; i < n; i++) {       scanf( %d %d %c , &a, &b, &c), node[a][c -  a ] = b;     }   }   int w = 1;   int mix(int x, int y) {     if (x == 0 || y == 0) return x + y;     int now = ++other;     site++;     for (int i = 0; i < 26; i++) node[now][i] = mix(node[x][i], node[y][i]);     return now;   }   void dfs(int x, int deep) {     other = n + 1;     int now = other;     site = 0;     for (int i = 0; i < 26; i++) now = mix(now, node[x][i]);     cau[deep] += site;     for (int i = 0; i < 26; i++)       if (node[x][i] > 0) dfs(node[x][i], deep + 1);   }   void work() {     dfs(1, 1);     maxx = 1;     for (int i = 1; i <= n; i++)       if (n - cau[maxx] > n - cau[i]) maxx = i;   }   void out() {     printf( %d n , n - cau[maxx]);     printf( %d n , maxx);   }   int main() {     in();     work();     out();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class IO {     static const int bufSize = 1 << 18;     char inBuf[bufSize], outBuf[bufSize];     char *ip1 = inBuf, *ip2 = inBuf;     int goodReadBit = 0, op1 = -1, op2 = bufSize - 1;     template <typename T>     __inline__ __attribute__((always_inline)) void __RI(T& x) {       int ch = gc(), neg = 1;       x = 0;       for (; !(isdigit(ch) || ch ==  -  || ch == EOF); ch = gc())         ;       if (ch == EOF) {         goodReadBit = 0;         return;       }       if (ch ==  - ) neg = -1, ch = gc();       for (; isdigit(ch); ch = gc()) x = x * 10 + (ch - 48) * neg;     }     template <typename T>     __inline__ __attribute__((always_inline)) void __RC(T& x) {       unsigned char ch;       while (isspace(ch = gc()))         ;       x = ch;     }     __inline__ __attribute__((always_inline)) void __RS(string& x) {       char ch;       x.clear();       for (ch = gc(); isspace(ch); ch = gc())         ;       if (ch == EOF) {         goodReadBit = 0;         return;       }       for (; !isspace(ch); ch = gc()) x.push_back(ch);     }       public:     __inline__ __attribute__((always_inline)) int gc() {       return ip1 == ip2 && (ip2 = (ip1 = inBuf) + fread(inBuf, 1, bufSize, stdin),                             ip1 == ip2)                  ? EOF                  : *ip1++;     }     __inline__ __attribute__((always_inline)) IO& R(char& x) {       __RC(x);       return (*this);     }     __inline__ __attribute__((always_inline)) IO& R(unsigned char& x) {       __RC(x);       return (*this);     }     __inline__ __attribute__((always_inline)) IO& R(string& x) {       __RS(x);       return (*this);     }     template <typename T1, typename T2>     __inline__ __attribute__((always_inline)) IO& R(pair<T1, T2>& x) {       R(x.first), R(x.second);       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO& R(vector<T>& x) {       for (auto& i : x) R(i);       return (*this);     }     template <typename T, typename... Args>     __inline__ __attribute__((always_inline)) IO& RA(T* a, int n) {       for (int i = 0; i < n; ++i) R(a[i]);       return (*this);     }     template <typename T, typename... Args>     __inline__ __attribute__((always_inline)) IO& R(T& x, Args&... args) {       R(x), R(args...);       return (*this);     }     template <typename T, typename... Args>     __inline__ __attribute__((always_inline)) IO& RA(T* a, int n, Args... args) {       for (int i = 0; i < n; ++i) RA(a[i], args...);       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO& R(T& x) {       static_assert(is_integral<T>::value,  Unsupported types );       if (is_integral<T>::value) __RI(x);       return (*this);     }       private:     char space =    ;     template <typename T>     __inline__ __attribute__((always_inline)) void __WI(T x) {       static char buf[64];       static int len = -1;       if (x >= 0) {         do {           buf[++len] = x % 10 + 48, x /= 10;         } while (x);       } else {         pc( - );         do {           buf[++len] = -(x % 10) + 48, x /= 10;         } while (x);       }       while (len >= 0) {         pc(buf[len]), --len;       }     }       public:     __inline__ __attribute__((always_inline)) void pc(const char& x) {       if (op1 == op2) flush();       outBuf[++op1] = x;     }     __inline__ __attribute__((always_inline)) void flush() {       fwrite(outBuf, 1, op1 + 1, stdout), op1 = -1;     }     __inline__ __attribute__((always_inline)) IO& W(const char& x) {       pc(x);       return (*this);     }     __inline__ __attribute__((always_inline)) IO& W(const char* x) {       while (*x !=   0 ) pc(*(x++));       return (*this);     }     __inline__ __attribute__((always_inline)) IO& W(const string& x) {       W(x.c_str());       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO& W(const vector<T>& x) {       for (auto& i : x) WS(i);       WL();       return (*this);     }     __inline__ __attribute__((always_inline)) IO& WL() {       W(  n );       return (*this);     }     template <typename T1, typename T2>     __inline__ __attribute__((always_inline)) IO& W(const pair<T1, T2>& x) {       WS(x.first), W(x.second);       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO& WL(const T& x) {       W(x), W(  n );       return (*this);     }     __inline__ __attribute__((always_inline)) IO& WS() {       W(   );       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO& WS(const T& x) {       W(x), W(space);       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO& WA(T* a, int n) {       for (int i = 0; i < n; i++) WS(a[i]);       WL();       return (*this);     }     template <typename T, typename... Args>     __inline__ __attribute__((always_inline)) IO& W(const T& x,                                                     const Args&... args) {       W(x), W(space), W(args...);       return (*this);     }     template <typename... Args>     __inline__ __attribute__((always_inline)) IO& WL(const Args&... args) {       W(args...), W(  n );       return (*this);     }     template <typename T, typename... Args>     __inline__ __attribute__((always_inline)) IO& WA(T* a, int n, Args... args) {       for (int i = 0; i < n; i++) WA(a[i], args...);       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO& W(const T& x) {       static_assert(is_integral<T>::value,  Unsupported types );       if (is_integral<T>::value) __WI(x);       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO& operator>>(T& x) {       R(x);       return (*this);     }     template <typename T>     __inline__ __attribute__((always_inline)) IO& operator<<(const T& x) {       W(x);       return (*this);     }     IO() {}   } io;   void EXIT(int code) { io.flush(), exit(code); }   const int8_t INFC = 0x3f;   const int16_t INFS = 0x3f3f;   const int32_t INF = 0x3f3f3f3f;   const int64_t INFL = 0x3f3f3f3f3f3f3f3fLL;   const int BLOCK_SIZE = 512;   struct Block {     int n;     vector<int> cnt, to, lst, &a;     Block(int n, vector<int>& a) : n(n), a(a) {       cnt.assign(n, -1), to.assign(n, -1), lst.assign(n, -1);     }     inline void __upd(int i, int j, int n) {       if (a[j] + i >= n) {         to[i] = a[j] + i - n;         lst[i] = j;         cnt[i] = 1;       } else {         to[i] = to[a[j] + i];         lst[i] = lst[a[j] + i];         cnt[i] = cnt[a[j] + i] + 1;       }     }     void update(int pos) {       if (n == BLOCK_SIZE) {         for (int i = n - 1; i >= 0; i -= 4) {           __upd(i, i + pos, n);           __upd(i - 1, i + pos - 1, n);           __upd(i - 2, i + pos - 2, n);           __upd(i - 3, i + pos - 3, n);         }       } else {         for (int i = n - 1; i >= 0; i--) {           int j = i + pos;           if (a[j] + i >= n) {             to[i] = a[j] + i - n;             lst[i] = j;             cnt[i] = 1;           } else {             to[i] = to[a[j] + i];             lst[i] = lst[a[j] + i];             cnt[i] = cnt[a[j] + i] + 1;           }         }       }     }   };   vector<Block> blocks;   int main() {     int n, q;     io >> n >> q;     vector<int> v(n);     io >> v;     for (int i = 0; i < n; i += BLOCK_SIZE) {       blocks.push_back(Block(min(BLOCK_SIZE, n - i), v));       blocks.back().update(i);     }     while (q--) {       int op, a;       io >> op >> a;       --a;       if (op == 1) {         int bpos = a / BLOCK_SIZE;         a = a % BLOCK_SIZE;         int cnt = 0, ans = 0;         while (bpos < blocks.size()) {           if (a >= blocks[bpos].n) break;           cnt += blocks[bpos].cnt[a];           ans = blocks[bpos].lst[a];           a = blocks[bpos].to[a];           bpos += a / BLOCK_SIZE;           a %= BLOCK_SIZE;           bpos++;         }         io.WL(ans + 1, cnt);       } else {         int b;         io >> b;         v[a] = b;         blocks[a / BLOCK_SIZE].update(a / BLOCK_SIZE * BLOCK_SIZE);       }     }     EXIT(0);   }


#include <bits/stdc++.h>   using namespace std;   const int tmw168 = 1e5;   long long a, b, p, q, invp;   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   long long test(long long r) {     r = r * invp % q;     r += a / q * q;     if (r < a) r += q;     return r;   }   int f(long long x, long long y) {     if (min(x, y) > b) return false;     cout << min(x, y) <<   n ;     return true;   }   long long inv(long long a, long long b) {     long long s = 0, t = 1;     long long old_s = 1, old_t = 0;     long long r = b, old_r = a;     while (r != 0) {       long long quotient = old_r / r;       long long tr = r;       r = old_r - quotient * r;       old_r = tr;       long long ts = s;       s = old_s - quotient * s;       old_s = ts;       long long tt = t;       t = old_t - quotient * t;       old_t = tt;     }     old_s = (old_s % q + q) % q;     return old_s;   }   void solve() {     cin >> a >> b >> p >> q;     long long g = gcd(p, q);     p /= g;     q /= g;     p %= q;     int ma = -1, gd = 0;     if (b - a < tmw168) {       for (int i = a; i <= b; i++) {         int cur = min(i * p % q, q - i * p % q);         if (cur > ma) {           ma = cur;           gd = i;         }       }       cout << gd <<   n ;       return;     }     invp = inv(p, q);     for (int i = 0; i < q; i++) {       if (f(test(q / 2 - i), test((q + 1) / 2 + i))) return;     }   }   int main() {     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, pos;     string s;     cin >> n >> s;     bool flag = false;     for (int i = 1; i < n; i++) {       if (s[i] == s[i - 1])         continue;       else {         flag = true;         pos = i;         break;       }     }     if (flag)       cout <<  YES  << endl, cout << s[pos - 1] << s[pos] << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Z = 3 * (int)1e3 + 111;   const int N = 3 * (int)1e5 + 111;   const int INF = (int)1e9 + 111;   const int MOD = (int)1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     double l, d, v, g, r;     cin >> l >> d >> v >> g >> r;     double t(0);     t = d / v;     if (int(t + 1) % int(g + r) <= g) {       if (int(t) % int(g + r) >= g) t = int(t) + 1;     } else {       t += (g + r) - int(t);     }     t += (l - d) / v;     cout << setprecision(20) << t;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1e-9;   const int N = (1 << 15);   const int OO = 200000;   struct edge {     int from, to, w;     edge(int from, int to, int w) : from(from), to(to), w(w) {}     bool operator<(const edge& e) const { return w < e.w; }   };   struct UnionFind {     vector<int> rank, parent;     int forests;     UnionFind(int n) {       rank = vector<int>(n);       parent = vector<int>(n);       int forests = n;       for (int i = 0; i < n; i++) parent[i] = i, rank[i] = 1;     }     int find_set(int x) {       if (x == parent[x]) return x;       return parent[x] = find_set(parent[x]);     }     void link(int x, int y) {       if (rank[x] > rank[y]) swap(x, y);       parent[x] = y;       rank[y] += rank[x];     }     bool union_sets(int x, int y) {       x = find_set(x), y = find_set(y);       if (x != y) {         link(x, y);         forests--;       }       return x != y;     }     long long same_set(int x, int y) {       x = find_set(x), y = find_set(y);       if (x == y) return 0;       long long t = (long long)rank[x] * rank[y];       link(x, y);       forests--;       return t;     }     vector<vector<int>> connected_components() {       vector<vector<int>> list(((int)(parent).size()));       for (int i = 0; i < ((int)(parent).size()); i++) {         list[find_set(i)].push_back(i);       }       return list;     }   };   vector<edge> edgeList;   long long a[100005];   int main() {     long long n, m, b, c;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       cin >> b >> c;       edgeList.push_back(edge(b - 1, c - 1, min(a[b - 1], a[c - 1])));     }     UnionFind uf(n);     double mstCost = 0;     priority_queue<edge> q;     for (int i = 0; i < edgeList.size(); i++) q.push(edgeList[i]);     while (!q.empty()) {       edge e = q.top();       q.pop();       mstCost += uf.same_set(e.from, e.to) * e.w;     }     cout << fixed << setprecision(6) << 2 * mstCost / (n * (n - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int flag = 0;     int count = 0;     if (isupper(s[0])) {       flag = 1;       count = 1;     }     for (int i = 1; i < s.length(); i++) {       if (isupper(s[i])) count++;     }     if (count == s.length()) {       for (int i = 0; i < s.length(); i++) {         s[i] = tolower(s[i]);       }     } else if (count == s.length() - 1 && flag == 0) {       s[0] = toupper(s[0]);       for (int i = 1; i < s.length(); i++) {         s[i] = tolower(s[i]);       }     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int ans[7], flag;   int a[1005], n;   int pos[4][30], pn[4];   struct Pair {     int l, r;   } p[4][300];   int pai[4];   stack<int> s;   bool check() {     for (int i = 1; i <= n; i++) {       if (a[i] != i) return false;     }     return true;   }   void find_pos(int index) {     pn[index] = 0;     pos[index][++pn[index]] = 1;     for (int i = 2; i < n; i++) {       if (!((a[i - 1] == a[i] + 1 && a[i + 1] == a[i] - 1) ||             (a[i - 1] == a[i] - 1 && a[i + 1] == a[i] + 1)))         pos[index][++pn[index]] = i;     }     pos[index][++pn[index]] = n;   }   void to_pair(int index) {     pai[index] = 0;     for (int i = 1; i <= pn[index]; i++) {       for (int j = i; j <= pn[index]; j++) {         p[index][++pai[index]].l = pos[index][i];         p[index][pai[index]].r = pos[index][j];       }     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     find_pos(1);     to_pair(1);     for (int i = 1; i <= pai[1]; i++) {       reverse(a + p[1][i].l, a + p[1][i].r + 1);       find_pos(2);       if (pn[2] > 10) {         reverse(a + p[1][i].l, a + p[1][i].r + 1);         continue;       }       s.push(p[1][i].r);       s.push(p[1][i].l);       to_pair(2);       for (int j = 1; j <= pai[2]; j++) {         reverse(a + p[2][j].l, a + p[2][j].r + 1);         find_pos(3);         if (pn[3] > 6) {           reverse(a + p[2][j].l, a + p[2][j].r + 1);           continue;         }         s.push(p[2][j].r);         s.push(p[2][j].l);         to_pair(3);         for (int k = 1; k <= pai[3]; k++) {           reverse(a + p[3][k].l, a + p[3][k].r + 1);           flag = 0;           if (check()) {             flag = 1;             s.push(p[3][k].r);             s.push(p[3][k].l);             ans[0] = s.size() / 2;             ans[1] = s.top();             s.pop();             ans[2] = s.top();             s.pop();             ans[3] = s.top();             s.pop();             ans[4] = s.top();             s.pop();             ans[5] = s.top();             s.pop();             ans[6] = s.top();             s.pop();             for (int i = 1; i <= 5; i += 2) {               if (ans[i] == ans[i + 1]) {                 ans[0]--;               }             }             cout << ans[0] << endl;             for (int i = 1; i <= 5; i += 2) {               if (ans[i] != ans[i + 1])                 cout << ans[i] <<     << ans[i + 1] << endl;             }           }           if (flag) break;           reverse(a + p[3][k].l, a + p[3][k].r + 1);         }         if (flag) break;         reverse(a + p[2][j].l, a + p[2][j].r + 1);         s.pop();         s.pop();       }       if (flag) break;       reverse(a + p[1][i].l, a + p[1][i].r + 1);       s.pop();       s.pop();     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <typename A, size_t N, typename T>   void Fill(A (&array)[N], const T& val) {     fill((T*)array, (T*)(array + N), val);   }   const int inf = INT_MAX / 2;   const long long int INF = LLONG_MAX / 2;   vector<int> g[100010];   int main() {     int n, m;     scanf( %d%d , &n, &m);     vector<pair<long long int, long long int> > check(m);     for (int i = (0); i < (m); i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       g[x].push_back(y);       g[y].push_back(x);       check[i] = {x, y};     }     int ans[100010] = {};     int idx = 0;     for (int st = (1); st < (4); st++) {       while (idx < n && ans[idx]) idx++;       if (idx == n) {         printf( -1 n );         return 0;       }       ans[idx] = st;       bool used[100010] = {};       used[idx] = 1;       for (int nxt : g[idx]) {         used[nxt] = 1;       }       for (int i = (0); i < (n); i++)         if (!used[i]) {           if (ans[i] && ans[i] != st) {             printf( -1 n );             return 0;           }           ans[i] = st;         }     }     bool f = 1;     int cnt[4] = {};     for (int i = (0); i < (n); i++) {       if (ans[i] == 0) f = 0;       cnt[ans[i]]++;     }     for (int i = (0); i < (m); i++) {       if (ans[check[i].first] == ans[check[i].second]) f = 0;     }     if (m != cnt[1] * cnt[2] + cnt[2] * cnt[3] + cnt[3] * cnt[1]) f = 0;     if (f)       for (int i = (0); i < (n); i++) printf( %d n , ans[i]);     else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void prin(int n) { printf( %d n , n); }   int main() {     int n;     cin >> n;     long long cur = 3, mi = 7;     for (int i = 1; i < 3 * n; i++) {       cur *= 3;       cur %= (int)1e9 + 7;     }     for (int i = 1; i < n; i++) {       mi *= 7;       mi %= (int)1e9 + 7;     }     cout << (((cur - mi) % ((int)1e9 + 7)) + ((int)1e9 + 7)) % ((int)1e9 + 7);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   string print_iterable(T1 begin_iter, T2 end_iter, int counter) {     bool done_something = false;     stringstream res;     res <<  [ ;     for (; begin_iter != end_iter and counter; ++begin_iter) {       done_something = true;       counter--;       res << *begin_iter <<  ,  ;     }     string str = res.str();     if (done_something) {       str.pop_back();       str.pop_back();     }     str +=  ] ;     return str;   }   vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {     vector<int> ord(size);     for (int i = 0; i < size; i++) ord[i] = i;     sort(ord.begin(), ord.end(), compare);     return ord;   }   template <typename T>   bool MinPlace(T& a, const T& b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <typename T>   bool MaxPlace(T& a, const T& b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <typename S, typename T>   ostream& operator<<(ostream& out, const pair<S, T>& p) {     out <<  {  << p.first <<  ,   << p.second <<  } ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, const vector<T>& v) {     out <<  [ ;     for (int i = 0; i < (int)v.size(); i++) {       out << v[i];       if (i != (int)v.size() - 1) out <<  ,  ;     }     out <<  ] ;     return out;   }   template <class TH>   void _dbg(const char* name, TH val) {     clog << name <<  :   << val << endl;   }   template <class TH, class... TA>   void _dbg(const char* names, TH curr_val, TA... vals) {     while (*names !=  , ) clog << *names++;     clog <<  :   << curr_val <<  ,  ;     _dbg(names + 1, vals...);   }   const int MAXN = 301000;   int N;   int d[MAXN];   string S;   int x;   int d2[MAXN];   int compute(int a, int b) {     for (int i = 0; i < a; i++) d2[i] = d[i];     for (int i = b; i < N; i++) d2[i] = d[i];     int diff = 0;     if (S[a] == S[b])       diff = 0;     else if (S[a] ==  ) )       diff = 2;     else       diff = -2;     for (int i = a; i < b; i++) d2[i] = d[i] + diff;     int mm = 1e9;     int cnt = 0;     for (int i = 0; i < N; i++) {       if (d2[i] == mm) cnt++;       if (d2[i] < mm) mm = d2[i], cnt = 1;     }     return cnt;   }   pair<int, pair<int, int>> solve1() {     int a = N;     int b = -1;     for (int i = 0; i < N; i++) {       if (S[i] ==  ) ) a = i;       if (d[i] == x) break;     }     for (int i = N - 1; i >= 0; i--) {       if (d[i] == x) break;       if (S[i] ==  ( ) b = i;     }     if (a > b) return {compute(0, 0), {0, 0}};     return {compute(a, b), {a, b}};   }   pair<int, pair<int, int>> solve2() {     int a = N;     int b = -1;     for (int i = 0; i < N; i++) {       if (S[i] ==  ) ) a = i;       if (d[i] == x or d[i] == x + 1) break;     }     for (int i = N - 1; i >= 0; i--) {       if (d[i] == x or d[i] == x + 1) break;       if (S[i] ==  ( ) b = i;     }     if (a > b) return {compute(0, 0), {0, 0}};     return {compute(a, b), {a, b}};   }   pair<int, pair<int, int>> solve0() {     int nomove = compute(0, 0);     int res = nomove;     pair<int, int> best = {0, 0};     for (int i = 0; i < N; i++) {       if (d[i] == x or d[i] == x + 1) continue;       int a = N;       int b = -1;       for (int j = i; j < N; j++) {         if (S[j] ==  ( ) {           a = j;           break;         }         if (d[j] == x or d[j] == x + 1) break;       }       int last_i = i + 1;       for (int j = i; j < N; j++) {         last_i = j;         if (d[j] == x or d[j] == x + 1) break;       }       for (int j = last_i; j >= a; j--) {         if (S[j] ==  ) ) {           b = j;           break;         }       }       i = last_i;       if (a > b) continue;       int ris = nomove;       for (int j = a; j < b; j++)         if (d[j] == x + 2) ris++;       if (ris > res) {         res = ris;         best = {a, b};       }     }     return {res, best};   }   pair<int, pair<int, int>> solvem1() {     int res = 0;     pair<int, int> best = {0, 0};     for (int i = 0; i < N; i++) {       if (d[i] == x) continue;       int a = N;       int b = -1;       for (int j = i; j < N; j++) {         if (S[j] ==  ( ) {           a = j;           break;         }         if (d[j] == x) break;       }       int last_i = i + 1;       for (int j = i; j < N; j++) {         last_i = j;         if (d[j] == x) break;       }       for (int j = last_i; j >= a; j--) {         if (S[j] ==  ) ) {           b = j;           break;         }       }       i = last_i;       if (a > b) continue;       int ris = 0;       for (int j = a; j < b; j++)         if (d[j] == x + 1) ris++;       if (ris > res) {         res = ris;         best = {a, b};       }     }     return {res, best};   }   pair<int, pair<int, int>> solve_slow() {     pair<int, int> best;     int res = 0;     for (int a = 0; a < N; a++) {       for (int b = a; b < N; b++) {         if (res < compute(a, b)) {           res = compute(a, b);           best = {a, b};         }       }     }     return {res, best};   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> N;     cin >> S;     for (int i = 0; i < N; i++) {       if (i > 0) d[i] = d[i - 1];       if (S[i] ==  ( )         d[i]++;       else         d[i]--;     }     if (d[N - 1] != 0) {       cout << 0 <<   n ;       cout << 1 <<     << 1 <<   n ;       return 0;     }     for (int i = 0; i < N; i++) x = min(x, d[i]);     vector<pair<int, pair<int, int>>> res(4);     res[0] = solve1();     res[1] = solve2();     res[2] = solve0();     res[3] = solvem1();     sort(res.begin(), res.end());     cout << res.back().first <<   n ;     cout << res.back().second.first + 1 <<     << res.back().second.second + 1          <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, i, j, k, c = 0, sm = 0, t = 0, ans = 0;     cin >> n >> m;     int a[n + 2], b[n + 2];     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) {       sm += a[i];       if (sm > m) {         sm -= a[t];         ++t;       } else {         ++c;         if (c < ans) ans = c;       }       if (c < 0) c = 0;     }     if (ans < c) ans = c;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   template <class T1, class T2, class T3>   inline T3 bigMod(T1 b, T2 p, T3 M) {     if (!p) return 1;     if (p & 1) return b * bigMod(b, p - 1, M) % M;     T3 h = bigMod(b, p >> 1, M);     return h * h % M;   }   template <class T1, class T2>   inline T2 modInverse(T1 a, T2 M) {     return bigMod(a % M, M - 2, M);   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     return (a / gcd(a, b)) * b;   }   template <class T>   inline string int2String(T a) {     ostringstream str;     str << a;     return str.str();   }   int cal(int pos, vector<int>& v) {     if (pos < 0 || v.empty()) return 0;     vector<int> on, off;     for (const int& x : v) {       if (((bool)(x & (1LL << (pos)))))         on.push_back(x);       else         off.push_back(x);     }     v.clear();     if (on.empty()) return cal(pos - 1, off);     if (off.empty()) return cal(pos - 1, on);     return min(cal(pos - 1, on), cal(pos - 1, off)) + (1 << pos);   }   int main() {     int n;     scanf( %d , &n);     vector<int> v(n);     for (int i = int(0); i < int(n); i++) scanf( %d , &v[i]);     printf( %d n , cal(30, v));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     map<char, int> m;     vector<int> v;     for (int i = 0; i < s.size(); i++) {       m[s[i]]++;     }     map<char, int>::iterator it = m.begin();     while (it != m.end()) {       v.push_back((*it).second);       it++;     }     if (v.size() > 4 || v.size() == 1) {       cout <<  No ;     } else if (v.size() == 4) {       cout <<  Yes ;     } else if (v.size() == 3) {       if (v[0] > 1 || v[1] > 1 || v[2] > 1)         cout <<  Yes ;       else         cout <<  No ;     } else if (v.size() == 2) {       if (v[0] > 1 && v[1] > 1)         cout <<  Yes ;       else         cout <<  No ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[1 << 20];   int main() {     scanf( %d%d , &n, &m);     map<int, int> p;     for (int i = 1; i <= n; i++) {       int fi;       scanf( %d , &fi);       if (p.count(fi)) {         p[fi] = 0;       } else {         p[fi] = i;       }     }     bool im = false, am = false;     for (int i = 1; i <= m; i++) {       int bi;       scanf( %d , &bi);       if (!p.count(bi)) {         im = true;       } else if (p[bi]) {         a[i] = p[bi];       } else {         am = true;       }     }     if (im) {       puts( Impossible );     } else if (am) {       puts( Ambiguity );     } else {       puts( Possible );       for (int i = 1; i <= m; i++) {         printf( %d%c , a[i], i == m ?   n  :    );       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long qpow(int a, int n, int modulus) {     int ret = 1;     while (n) {       if (n & 1) ret = ret * a % modulus;       a = a * a % modulus;       n >>= 1;     }     return ret;   }   int main() {     int n;     scanf( %d , &n);     if (n < 3)       puts( -1 );     else if (n == 3)       puts( 210 );     else {       int m = 210 - qpow(10, n - 1, 210);       putchar( 1 );       if (m >= 0 && m < 10) {         for (int i = 1; i < n - 1; i++) putchar( 0 );         printf( %d n , m);       } else if (m >= 10 && m < 100) {         for (int i = 1; i < n - 2; i++) putchar( 0 );         printf( %d n , m);       } else {         for (int i = 1; i < n - 3; i++) putchar( 0 );         printf( %d n , m);       }     }     return 0;   }


// God put a smile upon your face <3      #include <bits/stdc++.h>      #define slld(longvalue) scanf( %lld , &longvalue)      #define ll long long   #define ull unsigned long long   #define pll pair < long long, long long >      #define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)      #define pb push_back      #define bug printf( BUG n )      #define mxlld LLONG_MAX   #define mnlld -LLONG_MAX      #define mxd 2e8   #define mnd -2e8      #define pi 3.14159265359      using namespace std;      bool check(ll n, ll pos)   {    return n & (1LL << pos);   }      ll Set(ll n, ll pos)   {    return n = n | (1LL << pos);   }      const ll N = 400005;   struct info   {    ll x, y, id;   } arr[N];      pll tree[N * 4];      struct segtree   {       ll n;          void treeinit(ll node, ll b, ll e)       {           if(b == e)           {               tree[node] = {arr[b].y, arr[b].id};               return;           }              ll left = node * 2;           ll right = (node * 2) + 1;           ll mid = (b + e) / 2;              treeinit(left, b, mid);           treeinit(right, mid + 1, e);              tree[node] = min(tree[left], tree[right]);       }          void init(ll _n)       {           n = _n;           treeinit(1,1,n);       }          void treeupdate(ll node, ll b, ll e, ll i, ll val)       {           if(i > e || i < b)           {               return;           }              if(b == i && e == i)           {               tree[node].first = val;               return;           }              ll left = node * 2;           ll right = (node * 2) + 1;           ll mid = (b + e) / 2;              treeupdate(left, b, mid, i, val);           treeupdate(right, mid + 1, e, i, val);              tree[node] = min(tree[left], tree[right]);       }          void update(ll i, ll val)       {           treeupdate(1,1,n,i,val);       }          pll treequery(ll node, ll b, ll e, ll i, ll j)       {           if(i > e || j < b)           {               return {mxlld,-1};           }              if(b >= i && e <= j)           {               return tree[node];           }              ll left = node * 2;           ll right = (node * 2) + 1;           ll mid = (b + e) / 2;              pll p1 = treequery(left, b, mid, i, j);           pll p2 = treequery(right, mid + 1, e,i, j);              return min(p1,p2);       }          pll query(ll x, ll y)       {           return treequery(1,1,n,x,y);       }      } seg;      bool comp(info a, info b)   {    if(a.x != b.x) return a.x < b.x;       return a.y < b.y;   }      ll ans[N];   vector < pll > v[N];      int main()   {       ll i, j, k, l, m, n, o, r, q;       ll testcase;       ll input, flag, tag;      //    freopen( input.txt ,  r , stdin);      //    freopen( output.txt ,  w , stdout);          slld(testcase);          for(ll cs = 1; cs <= testcase; cs++)       {     cin >> n;        for(ll i = 1; i <= n; i++)     {      ll h, w;         cin >> h >> w;         arr[i * 2] = {h,w,i};      arr[i * 2 - 1] = {w,h,i};         ans[i] = -1;         v[i].clear();     }        sort(arr + 1, arr + 1 + (n * 2), comp);        for(ll i = 1; i <= (n * 2); i++)     {      v[arr[i].id].push_back({i, arr[i].y});     }        seg.init(n * 2);        ll ptr = 0;        for(ll i = 1; i <= (n * 2); i++)     {      pll ask = seg.query(1,i);      //   cout << arr[i].x <<     << arr[i].y <<   is   << ask.first <<     << ask.second <<   n ;     }        for(ll i = 2; i <= (n * 2); i++)     {   //   for(ll ii = 1; ii <= (n * 2); ii++)   //   {   //    pll ask = seg.query(1,ii);   //   ////    cout << arr[ii].x <<     << arr[ii].y <<   isisis   << ask.first <<     << ask.second <<   n ;   //   }         if(ans[arr[i].id] != -1) continue;         while(arr[ptr + 1].x < arr[i].x) ptr++;         if(v[arr[i].id].front().first != i)      {       seg.update(v[arr[i].id].front().first, mxlld);      }         pll ask = seg.query(1,ptr);      //   cout << arr[i].x <<     << arr[i].y <<     << i <<     << ask.first <<     << ask.second <<     << ptr <<   n ;         if(ask.first < arr[i].y)      {       ans[arr[i].id] = ask.second;      }         if(v[arr[i].id].front().first != i)      {       seg.update(v[arr[i].id].front().first, v[arr[i].id].front().second) ;      }     }        for(ll i = 1; i <= n; i++) cout << ans[i] <<    ;        cout <<   n ;       }         }


#include <bits/stdc++.h>   using namespace std;   int n, x, y, nr;   int a[110], b[110];   bool used[110];   int main() {     cin >> n;     cin >> x;     for (int i = 1; i <= x; ++i) {       cin >> nr;       used[nr] = true;     }     cin >> y;     for (int i = 1; i <= y; ++i) {       cin >> nr;       used[nr] = true;     }     for (int i = 1; i <= n; ++i) {       if (!used[i]) {         cout <<  Oh, my keyboard! ;         return 0;       }     }     cout <<  I become the guy. ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s[105];   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       s[i] =  Aa ;       s[i][0] += i / 26;       s[i][1] += i % 26;     }     for (int i = 1; i <= n - k + 1; i++) {       string x;       cin >> x;       if (x ==  NO ) s[i + k - 1] = s[i];     }     for (int i = 1; i <= n; i++) cout << s[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 1e6 + 6;   int n, r, c, t = 1, fr[mxn], nxt[mxn], ans[mxn];   char s[6 * mxn];   inline void dfs(int x) {     if (!x) return;     dfs(x >> 1);     for (int i = 1; i <= n; ++i) {       ans[i] = ans[ans[i]];       if (x & 1) ans[i] = nxt[ans[i]];     }   }   int main() {     scanf( %d%d%d , &n, &r, &c);     for (int i = 1; i <= n; ++i) {       scanf( %s , s + fr[i]);       fr[i + 1] = fr[i] + strlen(s + fr[i]);       s[fr[i + 1]++] =    ;     }     for (int i = n + 1, j = n + 1; i; nxt[ans[i] = i] = j, --i)       for (; fr[j] - fr[i] > c + 1; --j)         ;     dfs(r);     for (int i = 2; i <= n; ++i)       if (ans[i] - i > ans[t] - t) t = i;     for (int i = 1; i <= r; ++i, t = nxt[t], putchar(  n ))       for (int j = fr[t]; j + 1 < fr[nxt[t]]; j++) putchar(s[j]);   }


#include <bits/stdc++.h>   using namespace std;   bool check(string s) {     for (int i = 0; i < s.size() - 1; i++) {       if (s[i] == s[i + 1] && s[i] ==  1 ) {         return false;       }     }     return true;   }   int main() {     int n;     cin >> n;     string v;     cin >> v;     int flag = 0, f = 1;     if (n == 1 && v[0] ==  0 ) {       cout <<  No ;     } else {       if (check(v) == false) {         flag = 1;       } else {         for (int i = 0; i < n; i++) {           if (v[i] ==  0 ) {             v[i] =  1 ;             if (check(v) == true) {               cout <<  No ;               f = 0;               break;             } else {               v[i] =  0 ;             }           }         }       }       if (flag == 1) {         cout <<  No ;       }       if (f == 1 && flag == 0) {         cout <<  Yes ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     string s1, s2;     cin >> s1 >> s2;     long long i, n = s1.size(), k1 = 0, k2 = 0, flag = 0, cnt = 0;     for (i = 0; i < n; i++) {       if (s1[i] ==  4  && s2[i] ==  7 )         k1++;       else if (s1[i] ==  7  && s2[i] ==  4 )         k2++;     }     if (k1 >= k2) {       cnt = k2 + (k1 - k2);     } else {       cnt = k1 + (k2 - k1);     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long i, n, k, a[100001], b[100001];   unsigned long long solve(unsigned long long val) {     unsigned long long cnt = 0;     for (i = 0; i < n; i++) {       if (a[i] * val > b[i]) cnt += val * a[i] - b[i];     }     if (cnt > k) return 0;     return 1;   }   unsigned long long binarysearch(unsigned long long l, unsigned long long r) {     unsigned long long mid, ans = 0;     while (l <= r) {       mid = (l + r) / 2;       if (solve(mid)) {         ans = mid;         l = mid + 1;       } else         r = mid - 1;     }     return ans;   }   int main() {     cin >> n >> k;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     unsigned long long l, r;     l = 0;     r = 0;     for (int i = 0; i < n; i++) r = max((b[i] + k) / a[i], r);     cout << binarysearch(l, r) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 7e3 + 11;   int n;   vector<int> s[2];   const int loose = 0;   const int win = 1;   bool vis[2][maxn][2];   int deg[maxn][2];   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int k, i = 0; i < 2; i++) {       cin >> k;       s[i].resize(k);       for (auto &x : s[i]) cin >> x;     }     queue<pair<int, int> > q[2];     q[loose].push({0, 0});     q[loose].push({0, 1});     vis[loose][0][0] = 1;     vis[loose][0][1] = 1;     while (!q[loose].empty()) {       while (!q[loose].empty()) {         pair<int, int> fr = q[loose].front();         q[loose].pop();         int player = fr.second ^ 1;         int me = fr.first;         for (auto x : s[player]) {           int wp = me - x;           while (wp < 0) wp += n;           if (!vis[win][wp][player] && !vis[loose][wp][player]) {             vis[win][wp][player] = 1;             q[win].push({wp, player});           }         }       }       while (!q[win].empty()) {         pair<int, int> fr = q[win].front();         q[win].pop();         int player = fr.second ^ 1;         int me = fr.first;         for (auto x : s[player]) {           int lp = me - x;           while (lp < 0) lp += n;           if (!vis[loose][lp][player] && !vis[win][lp][player] &&               ++deg[lp][player] == (int)(s[player]).size()) {             vis[loose][lp][player] = 1;             q[loose].push({lp, player});           }         }       }     }     for (int player = 0; player < 2; player++) {       for (int i = 1; i < n; i++) {         if (vis[win][i][player])           cout <<  Win  ;         else if (vis[loose][i][player])           cout <<  Lose  ;         else           cout <<  Loop  ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 505, M = 1e9 + 7;   long long K, m, n, a[N], H[N], num[N], F[N], G[N], x, ans[N], C[N];   inline long long ksm(long long x, long long y) {     long long ans = 1;     for (; y; y >>= 1, x = x * x % M)       if (y & 1) (ans *= x) %= M;     return ans;   }   inline void cf1(long long A[]) {     memset(C, 0, sizeof C);     for (long long i = 0; i < 250; i++)       for (long long j = 0; j < 250; j++) (C[i + j] += A[i] * A[j]) %= M;     long long Inv = ksm(num[250], M - 2);     for (long long i = 499; i >= 250; i--) {       long long t = Inv * C[i] % M;       for (long long j = 0; j <= 250; j++)         (C[-250 + j + i] += M - t * num[j] % M) %= M;     }     for (long long i = 0; i < N; i++) A[i] = C[i];   }   inline void cf(long long A[], long long B[]) {     memset(C, 0, sizeof C);     for (long long i = 0; i < 250; i++)       for (long long j = 0; j < 250; j++) (C[i + j] += A[i] * B[j]) %= M;     long long Inv = ksm(num[250], M - 2);     for (long long i = 499; i >= 250; i--) {       long long t = Inv * C[i] % M;       for (long long j = 0; j <= 250; j++)         (C[-250 + j + i] += M - t * num[j] % M) %= M;     }     for (long long i = 0; i < N; i++) A[i] = C[i];   }   signed main() {     scanf( %lld%lld%lld , &K, &m, &n);     for (long long i = 1; i <= K; i++) scanf( %lld , &a[i]);     while (m--) {       scanf( %lld , &x);       (num[250 - x] += M - 1) %= M;     }     num[250]++;     ans[0] = 1;     for (long long i = 1; i < 250; i++)       for (long long j = 1; j <= i; j++)         (ans[i] += M - ans[i - j] * num[250 - j] % M) %= M;     for (long long i = 1; i <= K; i++) {       memset(F, 0, sizeof F);       memset(G, 0, sizeof G);       F[1] = 1;       long long y = a[i];       G[0] = 1;       for (; y; y >>= 1, cf1(F))         if (y & 1) cf(G, F);       for (long long j = 0; j < 250; j++) (H[j] += G[j]) %= M;     }     memset(G, 0, sizeof G);     G[0] = 1;     for (; n; n >>= 1, cf1(H))       if (n & 1) cf(G, H);     long long Ans = 0;     for (long long i = 0; i < 250; i++) (Ans += G[i] * ans[i]) %= M;     printf( %lld n , Ans);   }


#include<bits/stdc++.h>   #define maxn 1000000   using namespace std;   int n,d;   int a[maxn];   long long prod[10];   long long nprod[10];   long long inf=1e15;   vector<int> ans[10];   vector<int> nans[10];   bool tk[maxn];   int inv[10];   int mp[10];   int omp[10];   int main()   {       scanf( %d %d ,&n,&d);       for(int i=0;i<n;i++) {           scanf( %d ,&a[i]);       }       if(d==0) {           int rem=1;           for(int i=0;i<n;i++) {               rem=(rem*a[i])%10;           }           if(rem==0) {               printf( %d n ,n);               for(int i=0;i<n;i++) printf( %d  ,a[i]);           }           else {               printf( -1 );           }           return 0;       }       if(d==5) {           int rem=1;           int cnt=0;           for(int i=0;i<n;i++) {               if(a[i]%2!=0) {                   cnt++;                   rem=(rem*a[i])%10;               }           }           if(rem==d) {               printf( %d n ,cnt);               for(int i=0;i<n;i++) {                   if(a[i]%2!=0) {                       printf( %d  ,a[i]);                   }               }           }           else {               printf( -1 );           }           return 0;       }       if(d%2==0) {           d=d%5;           inv[1]=1;           inv[4]=4;           inv[2]=3;           inv[3]=2;           prod[1]=prod[2]=prod[3]=prod[4]=inf;           prod[1]=1;           int ac=1;           int pcnt=0;           for(int i=0;i<n;i++) {               if(a[i]%5==0) continue;               if(a[i]%2==0) pcnt++;           }           if(pcnt==0) {               printf( -1 );               return 0;           }           for(int i=0;i<n;i++) {               if(a[i]%5==0) continue;               int r=a[i]%5;               ac=(ac*r)%5;               for(int j=1;j<=4;j++) {                   nprod[j]=prod[j];                   nans[j].clear();                   for(auto k:ans[j]) nans[j].push_back(k);               }               for(int j=1;j<=4;j++) {                   int nrem=(r*j)%5;                   if(nprod[nrem]>prod[j]*a[i]) {                       int tcnt=0;                       if(a[i]%2==0) tcnt++;                       for(auto k:ans[j]) if(a[k]%2==0) tcnt++;                          if(tcnt!=pcnt) {                           nprod[nrem]=prod[j]*a[i];                           nans[nrem].clear();                           for(auto k:ans[j]) nans[nrem].push_back(k);                           nans[nrem].push_back(i);                       }                   }               }               for(int j=1;j<=4;j++) {                   prod[j]=nprod[j];                   ans[j].clear();                   for(auto k:nans[j]) ans[j].push_back(k);               }           }           d=(inv[d]*ac)%5;           //printf( %d n n ,d);           if(prod[d]==inf) {               printf( -1 );               return 0;           }           for(auto v:ans[d]) {               tk[v]=true;           }           int cnt=0;           for(int i=0;i<n;i++) {               if(a[i]%5==0 || tk[i]) continue;               cnt++;           }           if(cnt==0) {               printf( -1 );               return 0;           }           printf( %d n ,cnt);           for(int i=0;i<n;i++) {               if(a[i]%5==0 || tk[i]) continue;               printf( %d  ,a[i]);           }           return 0;       }       mp[1]=1;       mp[2]=3;       mp[3]=7;       mp[4]=9;       inv[1]=1;       inv[9]=9;       inv[7]=3;       inv[3]=7;       omp[1]=1;       omp[3]=2;       omp[7]=3;       omp[9]=4;       prod[1]=prod[2]=prod[3]=prod[4]=inf;       prod[1]=1;       int ac=1;       for(int i=0;i<n;i++) {           if(a[i]%5==0 || a[i]%2==0) continue;           int r=a[i]%10;           ac=(ac*r)%10;           for(int j=1;j<=4;j++) {               nprod[j]=prod[j];               nans[j].clear();               for(auto k:ans[j]) nans[j].push_back(k);           }           for(int j=1;j<=4;j++) {               int nrem=omp[(r*mp[j])%10];               if(nprod[nrem]>prod[j]*a[i]) {                   nprod[nrem]=prod[j]*a[i];                   nans[nrem].clear();                   for(auto k:ans[j]) nans[nrem].push_back(k);                   nans[nrem].push_back(i);               }           }           for(int j=1;j<=4;j++) {               prod[j]=nprod[j];               ans[j].clear();               for(auto k:nans[j]) ans[j].push_back(k);           }       }       d=omp[(inv[d]*ac)%10];       if(prod[d]==inf) {           printf( -1 );           return 0;       }       for(auto v:ans[d]) {           tk[v]=true;       }       int cnt=0;       for(int i=0;i<n;i++) {           if(a[i]%5==0 || a[i]%2==0 || tk[i]) continue;           cnt++;       }       if(cnt==0) {           printf( -1 );           return 0;       }       printf( %d n ,cnt);       for(int i=0;i<n;i++) {           if(a[i]%5==0 || a[i]%2==0 || tk[i]) continue;           printf( %d  ,a[i]);       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   void marmot0814() {     int n;     cin >> n;     int p1 = 1, p2 = 2, p3 = 3;     while (n--) {       int v;       cin >> v;       if (v == p3) {         cout <<  NO n ;         return;       } else if (v == p1) {         swap(p2, p3);       } else {         swap(p1, p3);       }     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t = 1, kase = 0;     while (t--) {       marmot0814();     }   }