#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     if (n & (n - 1)) {       cout <<  NO  <<   n ;     } else {       cout <<  YES  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int ttt;     cin >> ttt;     while (ttt--) {       int n, m;       cin >> n >> m;       vector<pair<int, int>> v(n * m);       for (int i = 0; i < n * m; i++) {         cin >> v[i].first;         v[i].second = i;       }       sort((v).begin(), (v).end());       for (int i = 0; i < n * m; i++) {         v[i].second *= -1;       }       int ans = 0;       for (int i = 0; i < n; i++) {         sort(v.begin() + i * m, v.begin() + (i + 1) * (m));         for (int l = 0; l < m; l++) {           for (int j = 0; j < l; j++) {             if (v[i * m + l].second < v[i * m + j].second) ans++;           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0;     bool flg = false;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) flg = true;     for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);     return flg ? -x : x;   }   int n, m;   char a[64][64];   void solve() {     n = read(), m = read();     for (int i(1), _i(n); i <= _i; i++) scanf( %s , a[i] + 1);     int tot = 0;     for (int i(1), _i(n); i <= _i; i++)       for (int j(1), _j(m); j <= _j; j++) tot += a[i][j] ==  A ;     if (!tot) return puts( MORTAL ), void();     if (tot == n * m) return puts( 0 ), void();     {       bool g = 1;       for (int i(1), _i(n); i <= _i; i++) g = g && a[i][1] ==  A ;       if (g) return puts( 1 ), void();       g = 1;       for (int i(1), _i(n); i <= _i; i++) g = g && a[i][m] ==  A ;       if (g) return puts( 1 ), void();       g = 1;       for (int i(1), _i(m); i <= _i; i++) g = g && a[1][i] ==  A ;       if (g) return puts( 1 ), void();       g = 1;       for (int i(1), _i(m); i <= _i; i++) g = g && a[n][i] ==  A ;       if (g) return puts( 1 ), void();     }     {       for (int x : {1, n})         for (int y : {1, m})           if (a[x][y] ==  A ) return puts( 2 ), void();       for (int i(1), _i(n); i <= _i; i++) {         bool g = 1;         for (int j(1), _j(m); j <= _j; j++) g = g && a[i][j] ==  A ;         if (g) return puts( 2 ), void();       }       for (int j(1), _j(m); j <= _j; j++) {         bool g = 1;         for (int i(1), _i(n); i <= _i; i++) g = g && a[i][j] ==  A ;         if (g) return puts( 2 ), void();       }     }     {       for (int i(1), _i(n); i <= _i; i++)         for (int j(1), _j(m); j <= _j; j++) {           if (a[i][j] ==  A  && (i == 1 || i == n || j == 1 || j == m))             return puts( 3 ), void();         }     }     puts( 4 );   }   int main() {     for (int T = read(); T--;) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct per {     string name;     int score;   } store[55];   bool cmp(per a, per b) { return a.score > b.score; }   int main() {     int n, tmp;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> store[i].name;       cin >> tmp;       store[i].score = 0;       store[i].score += tmp * 100;       cin >> tmp;       store[i].score -= tmp * 50;       for (int j = 0; j < 5; j++) {         cin >> tmp;         store[i].score += tmp;       }     }     sort(store, store + n, cmp);     cout << store[0].name << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int f[50005][65], a[50005], po[50005], cnt, tr[65][200005], la[65][200005];   void pushup(int num, int id) {     tr[num][id] = max(tr[num][id << 1], tr[num][id << 1 | 1]);   }   void pushdo(int num, int id) {     if (la[num][id] != 0) {       la[num][id << 1] += la[num][id];       la[num][id << 1 | 1] += la[num][id];       tr[num][id << 1] += la[num][id];       tr[num][id << 1 | 1] += la[num][id];       la[num][id] = 0;     }   }   void upda(int num, int id, int l, int r, int x, int y, int p) {     if (x <= l && r <= y) {       tr[num][id] += p;       la[num][id] += p;       return;     }     pushdo(num, id);     int m = (l + r) >> 1;     if (x <= m) upda(num, id << 1, l, m, x, y, p);     if (y > m) upda(num, id << 1 | 1, m + 1, r, x, y, p);     pushup(num, id);   }   int query(int num, int id, int l, int r, int x, int y) {     if (x <= l && r <= y) return tr[num][id];     pushdo(num, id);     int m = (l + r) >> 1, ans = 0;     if (x <= m) ans = max(ans, query(num, id << 1, l, m, x, y));     if (y > m) ans = max(ans, query(num, id << 1 | 1, m + 1, r, x, y));     return ans;   }   inline int min(int x, int y) {     if (x < y) return x;     return y;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= k; i++) upda(0, 1, 0, n, i, i, -2e9);     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= min(i, k); j++) {         upda(j, 1, 0, n, po[a[i]], i - 1, 1);       }       po[a[i]] = i;       for (int j = 1; j <= min(i, k); j++) {         f[i][j] = query(j - 1, 1, 0, n, 0, i - 1);         upda(j, 1, 0, n, i, i, f[i][j]);       }     }     printf( %d n , f[n][k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n], b[n], o = 0, z = 0, sorted = 1;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (i > 0 && a[i] < a[i - 1]) sorted = 0;       }       for (int i = 0; i < n; i++) {         cin >> b[i];         if (b[i])           o++;         else           z++;       }       if ((z && o) || (sorted))         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void dfs(const vector<vector<int> >& edge_list, vector<bool>& visited, int i,            int& edges) {     visited[i] = true;     for (int j : edge_list[i]) {       if (!visited[j]) dfs(edge_list, visited, j, edges);       if (j >= i) ++edges;     }   }   int main() {     int n, m, u, v;     scanf( %d %d , &n, &m);     vector<int> deg_noloop(n, 0);     vector<vector<int> > edge_list(n);     vector<bool> visited(n, false);     long long nonloops = 0, loops = 0, good_paths = 0;     int start = 0, edges = 0;     for (int i = 0; i < m; i++) {       scanf( %d %d , &u, &v);       --u;       --v;       start = u;       if (u != v) {         edge_list[u].push_back(v);         edge_list[v].push_back(u);         ++deg_noloop[u];         ++deg_noloop[v];         ++nonloops;       } else {         edge_list[u].push_back(v);         ++loops;       }     }     dfs(edge_list, visited, start, edges);     for (int i = 0; i < n; i++) {       long long deg = deg_noloop[i];       if (deg >= 2) good_paths += (deg) * (deg - 1) / 2;     }     good_paths += loops * nonloops + (loops) * (loops - 1) / 2;     if (edges < m) good_paths = 0;     printf( %lld n , good_paths);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100111;   long long n, arr[N], x, k;   int main() {     cin >> n;     while (n--) {       cin >> k >> x;       long long u = 9 * k;       cout << u - (9 - x) << endl;     }   }


#include <bits/stdc++.h>   int main() {     int q;     std::cin >> q;     std::vector<int> V;     for (int i = 0; i < q; ++i) {       int n;       std::cin >> n;       std::vector<int> v1;       std::vector<int> v2(n);       for (int j = 0; j < n; ++j) {         std::cin >> v2[j];         v1.push_back(j + 1);       }       for (int k = 0; k < v1.size(); ++k) {         int count = 1;         int num = k;         while (v1[k] != v2[num]) {           num = v2[num] - 1;           ++count;         }         V.push_back(count);       }       V.push_back(0);     }     for (int i = 0; i < V.size(); ++i) {       if (V[i] == 0)         std::cout <<   n ;       else {         std::cout << V[i] <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5001;   int n, tmp[N];   vector<int> g[N];   bool vst[N];   void dfs(int c, int p) {     bool dp[N];     fill(dp, dp + n + 1, false);     dp[0] = true;     tmp[c] = 1;     for (int ch : g[c]) {       if (ch != p) {         dfs(ch, c);         tmp[c] += tmp[ch];         for (int i = n - 1; i >= 0; --i) {           if (dp[i]) {             dp[i + tmp[ch]] = true;           }         }       }     }     for (int i = 1; i <= n; ++i) {       dp[n - i - 1] |= dp[i];     }     for (int i = 1; i <= n; ++i) {       vst[i] |= dp[i];     }   }   int main() {     scanf( %d , &n);     for (int i = (1), _i = (n - 1); i <= _i; ++i) {       int u, v;       scanf( %d %d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1, 1);     int cnt = 0;     for (int i = (1), _i = (n - 1 - 1); i <= _i; ++i) {       if (vst[i]) {         cnt += 1;       }     }     printf( %d n , cnt);     for (int i = (1), _i = (n - 1 - 1); i <= _i; ++i) {       if (vst[i]) {         printf( %d %d n , i, n - i - 1);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const unsigned long long base = 311;   unsigned long long TH[maxn][3], L[3], P[maxn];   int Sol, lona, lonb;   void calc_Hash(string& a, int id) {     int lon = L[id];     for (int i = (1); i <= (lon); i += (1)) {       TH[i][id] = TH[i - 1][id] * base + (unsigned long long)(a[i] -  0 );     }     return;   }   void calc_pot(int N) {     P[0] = 1;     for (int i = (1); i <= (N); i += (1)) {       P[i] = P[i - 1] * base;     }     return;   }   bool completa(int tam, int id) {     int lon = L[id];     unsigned long long H = TH[tam][1];     bool flag = true;     for (int i = (tam); i <= (lon); i += (tam)) {       if (TH[i][id] - TH[i - tam][id] * P[tam] != H) {         flag = false;         break;       }     }     return flag;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string A, B;     cin >> A >> B;     lona = A.size();     lonb = B.size();     L[1] = lona;     L[2] = lonb;     A =     + A;     B =     + B;     calc_pot(((lona) > (lonb) ? (lona) : (lonb)));     calc_Hash(A, 1);     calc_Hash(B, 2);     int l = ((lona) < (lonb) ? (lona) : (lonb));     for (int i = (1); i <= (l); i += (1)) {       if (!(lona % i) && !(lonb % i)) {         if (completa(i, 1) && completa(i, 2)) {           Sol++;         }       }     }     cout << Sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 5;   long long n, k, a[N], res;   void solo() {     cin >> n;     for (int i = 1; i <= n; i++) cout << i + 1 <<    ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solo();       cout << endl;     }     cerr <<   n  << (double)clock() / CLOCKS_PER_SEC * 1000 <<   ms ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   vector<string> vec[1003], v;   bool mat[26][26], flag, ok[26], vis[26], run[26];   int ind[26];   inline bool func(int x, int y) {     vector<int> vs, vt;     for (int i = 0; i < v[x].size(); i++) vs.push_back(v[x][i]);     for (int i = 0; i < v[y].size(); i++) vt.push_back(v[y][i]);     reverse(vs.begin(), vs.end());     reverse(vt.begin(), vt.end());     while (!vs.empty() && !vt.empty()) {       if (vt.back() != vs.back())         return mat[vs.back() -  a ][vt.back() -  a ] = 1;       else         vs.pop_back(), vt.pop_back();     }     if (!vs.empty())       return 0;     else       return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     flag = 1;     string str;     int n, k, p;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> p;       for (int j = 0; j < k; j++) {         cin >> str, vec[p].emplace_back(str);         for (int l = 0; l < str.size(); l++) ok[str[l] -  a ] = 1;       }     }     for (int i = 0; i < n; i++)       for (int j = 0; j < k; j++) v.emplace_back(vec[i][j]);     for (int i = 0; i < v.size() - 1 && flag; i++) flag = func(i, i + 1);     for (int i = 0; i < 26; i++)       for (int j = 0; j < 26; j++) ind[j] += mat[i][j];     int cnt = 0, tot = 0;     for (int i = 0; i < 26; i++) tot += ok[i];     queue<int> q;     for (int i = 0; i < 26; i++)       if (ok[i] && !ind[i]) q.push(i);     vector<int> res;     while (!q.empty() && flag) {       int x = q.front();       q.pop();       res.push_back(x);       for (int i = 0; i < 26; i++)         if (mat[x][i]) {           ind[i]--;           if (!ind[i]) q.push(i);         }     }     if (flag && res.size() == tot) {       for (int i = 0; i < res.size(); i++) cout << (char)(res[i] +  a );       cout <<   n ;     } else       cout <<  IMPOSSIBLE n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long;   using pi = pair<int, int>;   const int MAXN = 1005;   const int MAXM = 1005;   struct edge_color {     int deg[2][MAXN];     pi has[2][MAXN][MAXN];     int color[MAXM];     int c[2];     void clear(int n) {       for (int t = 0; t < 2; t++) {         for (int i = 0; i <= n; i++) {           deg[t][i] = 0;           for (int j = 0; j <= n; j++) {             has[t][i][j] = pi(0, 0);           }         }       }     }     void dfs(int x, int p) {       auto i = has[p][x][c[!p]];       if (has[!p][i.first][c[p]].second)         dfs(i.first, !p);       else         has[!p][i.first][c[!p]] = pi(0, 0);       has[p][x][c[p]] = i;       has[!p][i.first][c[p]] = pi(x, i.second);       color[i.second] = c[p];     }     int solve(vector<pi> v, vector<int> &cv) {       int m = ((int)(v).size());       int ans = 0;       for (int i = 1; i <= m; i++) {         int x[2];         x[0] = v[i - 1].first;         x[1] = v[i - 1].second;         for (int d = 0; d < 2; d++) {           deg[d][x[d]] += 1;           ans = max(ans, deg[d][x[d]]);           for (c[d] = 1; has[d][x[d]][c[d]].second; c[d]++)             ;         }         if (c[0] != c[1]) dfs(x[1], 1);         for (int d = 0; d < 2; d++) has[d][x[d]][c[0]] = pi(x[!d], i);         color[i] = c[0];       }       cv.resize(m);       for (int i = 1; i <= m; i++) {         cv[i - 1] = color[i];         color[i] = 0;       }       return ans;     }   } EC;   int cnt[2][MAXN];   int idx[2][MAXN], L, R;   int main() {     int n, m, t;     scanf( %d %d %d , &n, &m, &t);     for (int i = 0; i < n; i++) scanf( %*d );     vector<pi> ans;     for (int i = 0; i < m; i++) {       int l, r;       scanf( %d %d , &l, &r);       if (cnt[0][l] == 0) idx[0][l] = ++L;       if (cnt[1][r] == 0) idx[1][r] = ++R;       cnt[0][l]++;       cnt[1][r]++;       if (cnt[0][l] == t) cnt[0][l] = 0;       if (cnt[1][r] == t) cnt[1][r] = 0;       ans.emplace_back(idx[0][l], idx[1][r]);     }     vector<int> color;     EC.solve(ans, color);     for (auto &i : color) printf( %d n , i);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string start, end;     cin >> start >> end;     string srev = start;     reverse(srev.begin(), srev.end());     vector<int> vs[26], vr[26];     int slen = start.length();     for (int i = 0; i < slen; i++) {       vs[start[i] -  a ].push_back(i);       vr[srev[i] -  a ].push_back(i);     }     int elen = end.length();     bool flag = true;     for (int i = 0; i < elen; i++) {       if (vs[end[i] -  a ].size() == 0) {         flag = false;         break;       }     }     if (!flag)       cout << -1 << endl;     else {       int no = 0;       vector<pair<int, int> > res;       for (int i = 0; i < elen;) {         int size = vs[end[i] -  a ].size();         pair<int, int> p;         int maxl, ans = 0, index, tmp;         for (int j = 0; j < size; j++) {           index = vs[end[i] -  a ][j];           tmp = index;           maxl = i;           while ((index < slen - 1) && (maxl < elen - 1) &&                  start[index + 1] == end[maxl + 1]) {             index++;             maxl++;           }           if (maxl - i + 1 > ans) {             ans = maxl - i + 1;             p = make_pair(tmp, index);           }         }         maxl = i;         for (int j = 0; j < size; j++) {           index = vr[end[i] -  a ][j];           tmp = index;           maxl = i;           while ((index < slen - 1) && (maxl < elen - 1) &&                  srev[index + 1] == end[maxl + 1]) {             index++;             maxl++;           }           if (maxl - i + 1 > ans) {             ans = maxl - i + 1;             p = make_pair(slen - 1 - tmp, slen - 1 - index);           }         }         i += ans;         no++;         res.push_back(p);       }       cout << no << endl;       for (int i = 0; i < res.size(); i++)         cout << res[i].first + 1 <<     << res[i].second + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long s, x1, x2, t1, t2, p, d;     cin >> s >> x1 >> x2 >> t1 >> t2 >> p >> d;     long long ans = abs(x1 - x2) * t2;     long long i = p, t = 0;     while (i != x1) {       i += d;       t += t1;       if (i == s)         d = -1;       else if (i == 0)         d = 1;     }     while (i != x2) {       i += d;       t += t1;       if (i == s)         d = -1;       else if (i == 0)         d = 1;     }     ans = min(ans, t);     cout << ans <<   n ;   }   void solve(bool testcase) {     long long t;     cin >> t;     while (t--) solve();   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mo = (int)1e9 + 7;   const int maxn = 1000010;   int n;   long long fac[maxn], ans;   int a[maxn], num[maxn], num1[maxn], pos[maxn], mul[maxn];   int pre[maxn], ne[maxn];   vector<int> v[maxn];   inline void init() {     fac[0] = 1;     for (int i = 1; i <= n + 2; ++i) fac[i] = fac[i - 1] * i % mo, mul[i] = 1;     for (int i = 2; i <= n; ++i) {       if (!v[i].size()) {         num[n / i]++;         pos[i] = n / i;         for (int j = i; j <= n; j += i) v[j].push_back(i), mul[j] *= i;       }     }     for (int i = 1; i <= n; ++i) num1[mul[i]]++;     num[1]++;     pos[1] = 1;     v[1].push_back(1);   }   int main() {     scanf( %d , &n);     init();     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i)       if (a[i]) {         num1[mul[a[i]]]--;         if (v[a[i]].size() != v[i].size()) return puts( 0 ), 0;         for (int j = 0; j < v[i].size() - 1; j++)           if (v[a[i]][j] != v[i][j]) return puts( 0 ), 0;         long long x = v[a[i]].back(), y = v[i].back();         if (pos[x] != pos[y]) return puts( 0 ), 0;         if (pre[x] && pre[x] != y) return puts( 0 ), 0;         if (ne[y] && ne[y] != x) return puts( 0 ), 0;         if (!pre[x] && !ne[y]) num[pos[x]]--;         pre[x] = y;         ne[y] = x;       }     ans = 1;     for (int i = 1; i <= n; ++i)       ans = ans * fac[num[i]] % mo, ans = ans * fac[num1[i]] % mo;     printf( %lld n , ans);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};   const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};   const int MAX = 2 * 1000 + 10;   const long long INF = 1e18;   const int MOD = 1e9 + 7;   long long n, m, x, y, a[MAX], b[MAX], c[MAX], d[MAX];   long long dp[MAX][20];   long long sol(long long n, long long ind) {     if (n < 0) return -MOD;     if (ind > m or n == 0) return 0;     if (dp[n][ind] != -1) return dp[n][ind];     long long &ans = dp[n][ind];     ans = y + sol(n - x, ind);     for (long long i = 0; i <= n; i++) {       if (i * c[ind] > n or i * b[ind] > a[ind]) break;       ans = max(ans, i * d[ind] + sol(n - i * c[ind], ind + 1));     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m >> x >> y;     for (long long i = 1; i <= m; i++) {       cin >> a[i] >> b[i] >> c[i] >> d[i];     }     memset(dp, -1, sizeof(dp));     cout << sol(n, 0) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> A(n);     for (int& a : A) scanf( %d , &a);     sort(A.begin(), A.end());     int m = A[n - 1];     vector<bool> B(m + 2);     for (int a : A) {       if (a > 1 && !B[a - 1])         B[a - 1] = true;       else if (!B[a])         B[a] = true;       else if (!B[a + 1])         B[a + 1] = true;     }     printf( %lu n , count(B.begin(), B.end(), true));   }


#include <bits/stdc++.h>   using namespace std;   long long numbit(long long x) { return (1LL << x) - 1LL; }   long long getbit(long long x, long long i) { return (x >> i) & 1LL; }   long long onbit(long long x, long long i) { return x | (1LL << i); }   long long offbit(long long x, long long i) { return x & (~(1LL << i)); }   const int oo = 1000111000;   const int Nmax = 1e5 + 10;   const long long mod = 1e9 + 7;   const long double PI = 3.14159265358979323846;   int p[Nmax * 2], c[Nmax * 2];   int ch[Nmax * 2];   bool ok[Nmax * 2];   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     int test;     cin >> test;     for (long long e = (1); e <= (test); e++) {       int n;       cin >> n;       for (long long i = (1); i <= (n); i++) cin >> p[i];       for (long long i = (1); i <= (n); i++) cin >> c[i];       memset(ok, false, sizeof(ok));       memset(ch, 0, sizeof(ch));       int cnt = 0;       vector<int> circle[n + 1];       for (long long i = (1); i <= (n); i++)         if (!ok[i]) {           cnt++;           int j = i;           while (!ok[j]) {             circle[cnt].push_back(j);             ok[j] = true;             j = p[j];           }         }       int res = n + 1;       for (long long i = (1); i <= (cnt); i++) {         int it = 0;         for (long long m = (1); m <= (circle[i].size()); m++)           if (circle[i].size() % m == 0) {             if (m >= res) break;             int j = 0;             it++;             bool ok = false;             while (j < circle[i].size()) {               if (ch[circle[i][j]] == it) {                 j++;                 continue;               }               ok = true;               int h = j;               while (ok) {                 if (ch[circle[i][h]] == it ||                     c[circle[i][j]] != c[circle[i][h]]) {                   ok = false;                   break;                 }                 ch[circle[i][h]] = it;                 h = (h + m) % circle[i].size();                 if (h == j) break;               }               if (ok) break;               j++;             }             if (ok) {               res = min(res, int(m));               break;             }           }       }       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int p, n, a[100100], b[100100];   bool ok(double t) {     double charging = t * p;     for (int i = 0; i < n; ++i) {       double x = b[i] - a[i] * t;       if (x >= 0)         continue;       else         charging += x;       if (charging < 0) return 0;     }     return 1;   }   int main() {     cin >> n >> p;     for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];     double low = 0, high = 1e11, tol = 1e-7, mid;     while (high - low > tol) {       mid = (high + low) / 2;       if (ok(mid))         low = mid;       else         high = mid;     }     if (low < 9.9e10)       cout << setprecision(10) << fixed << mid;     else       cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, tot, vis[50005];   pair<long double, long double> stk[50005 << 1];   int bit[50005 << 1];   const long double Pi = acos(-1);   struct Point {     long double x, y;     Point() {}     Point(long double a, long double b) { x = a, y = b; }     Point operator+(Point p) { return Point(x + p.x, y + p.y); }     Point operator-(Point p) { return Point(x - p.x, y - p.y); }     Point operator*(long double c) { return Point(x * c, y * c); }     Point operator/(long double c) { return Point(x / c, y / c); }   } P, S[50005];   long double Abs(long double x) { return x > 0 ? x : -x; }   bool Equal(long double a, long double b) { return Abs(a - b) < 1e-8; }   long double Cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }   Point Rotate(Point p, long double a) {     return Point(p.x * cos(a) - p.y * sin(a), p.x * sin(a) + p.y * cos(a));   }   bool Onleft(int x) {     Point a = Point(0, S[x].y), b = Point(1, S[x].x + S[x].y);     return Cross(a - P, b - P) > 0;   }   long double Length(Point p) { return sqrt(p.x * p.x + p.y * p.y); }   long double Getang(long double x) {     while (x < -Pi) x += Pi * 2;     while (x > Pi) x -= Pi * 2;     return x;   }   void Update(int x, int v) {     for (int i = x; i <= tot; i += i & -i) bit[i] += v;   }   int Getsum(int x) {     int ret = 0;     for (int i = x; i; i -= i & -i) ret += bit[i];     return ret;   }   Point Intersect(int i, int j) {     long double x = (S[j].y - S[i].y) / (S[i].x - S[j].x);     return Point(x, S[i].x * x + S[i].y);   }   int Solve(long double r) {     tot = 0;     for (int i = 1; i <= n; i++) {       long double dis =           Abs(S[i].x * P.x - P.y + S[i].y) / sqrt(S[i].x * S[i].x + 1);       if (dis > r) continue;       long double ang = asin(dis / r);       ang = Getang(ang);       if (ang > Pi / 2) ang = Pi / 2 - ang;       Point T(100, 100 * S[i].x);       if (vis[i]) T = T * -1;       Point t1 = Rotate(T, ang) * -1;       Point t2 = Rotate(T, -ang);       long double a1 = Getang(atan2(t1.y, t1.x));       long double a2 = Getang(atan2(t2.y, t2.x));       if (a1 > a2) swap(a1, a2);       stk[++tot] = make_pair(a1, a2);       stk[++tot] = make_pair(a2, a1);     }     sort(stk + 1, stk + tot + 1);     for (int i = 1; i <= tot; i++) bit[i] = 0;     int cnt = 0;     for (int i = 1; i <= tot; i++) {       if (stk[i].second > stk[i].first)         Update(i, 1);       else {         int p = lower_bound(stk + 1, stk + tot + 1,                             make_pair(stk[i].second, stk[i].first)) -                 stk;         cnt += Getsum(i) - Getsum(p);         Update(p, -1);       }     }     return cnt;   }   set<pair<long double, int> > s;   long double Calc(long double r) {     tot = 0;     long double cnt = 0;     for (int i = 1; i <= n; i++) {       long double dis =           Abs(S[i].x * P.x - P.y + S[i].y) / sqrt(S[i].x * S[i].x + 1);       if (dis > r) continue;       long double ang = asin(dis / r);       ang = Getang(ang);       if (ang > Pi / 2) ang = Pi / 2 - ang;       Point T(100, 100 * S[i].x);       if (vis[i]) T = T * -1;       Point t1 = Rotate(T, ang) * -1;       Point t2 = Rotate(T, -ang);       long double a1 = Getang(atan2(t1.y, t1.x));       long double a2 = Getang(atan2(t2.y, t2.x));       if (a1 > a2) swap(a1, a2);       stk[++tot] = make_pair(a1, i + 500);       stk[++tot] = make_pair(a2, a1);     }     sort(stk + 1, stk + tot + 1);     for (int i = 1; i <= tot; i++) {       if (stk[i].second > stk[i].first)         s.insert(make_pair(stk[i].first, (int)(stk[i].second - 500 + 0.1)));       else {         set<pair<long double, int> >::iterator p =             s.lower_bound(make_pair(stk[i].second, 0));         if (p == s.end()) continue;         set<pair<long double, int> >::iterator t = p;         for (t++; t != s.end(); t++)           cnt += Length(Intersect(t->second, p->second) - P);         s.erase(p);       }     }     return cnt;   }   int main() {     scanf( %d , &n);     int x, y;     scanf( %d%d , &x, &y);     P = Point((long double)x / 1000, (long double)y / 1000);     scanf( %d , &m);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       S[i] = Point((long double)x / 1000, (long double)y / 1000);     }     for (int i = 1; i <= n; i++) vis[i] = Onleft(i);     long double l = 0, r = 1e10;     int c;     for (int i = 1; i <= 80; i++) {       long double mid = (l + r) / 2;       c = Solve(mid);       if (c >= m)         r = mid;       else         l = mid;     }     c = Solve(l - 1e-8);     printf( %.12lf n , double(Calc(l - 1e-8) + (m - c) * l));   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[5001], b[1000001], d[1000001];   void doc() {     for (int i = 1; i <= n; i++) cin >> a[i];   }   void xuli() {     sort(a + 1, a + n + 1);     for (int i = 1; i < n; i++)       for (int j = i + 1; j <= n; j++) d[a[j] - a[i]]++;     int m = 0;     while (true) {       m++;       int dem = 0, res = 0;       for (int j = m; j <= 1000001; j += m) dem += d[j];       if (dem > (k * (k + 1)) / 2) continue;       for (int i = 1; i <= n; i++) {         if (b[a[i] % m] == m) res++;         b[a[i] % m] = m;       }       if (res <= k) break;     }     cout << m;   }   int main() {     cin >> n >> k;     doc();     xuli();   }


#include <bits/stdc++.h>   using namespace std;   int exgcd(int a, int b, int &x, int &y) {     if (b == 0) {       y = 0;       x = 1;       return a;     }     int r = exgcd(b, a % b, x, y);     int tmp = y;     y = x - (a / b) * y;     x = tmp;     return r;   }   int t, n, a[200005], s, ans[200005], k1, k2, len, nos[200005];   set<int> se[200005];   unordered_map<int, int> vis, id;   int main() {     while (~scanf( %d%d , &t, &n)) {       vis.clear();       id.clear();       for (int i = 0; i < 200005; ++i) se[i].clear();       memset(ans, -1, 4 * n + 4);       a[0] = s = 0;       for (int i = 1; i <= n; ++i) {         scanf( %d , &a[i]);         s = (s + a[i]) % t;       }       a[1] = 0;       for (int i = 2; i <= n; ++i) a[i] = (a[i - 1] + a[i]) % t;       int g = exgcd(s, t, k1, k2), cnt = 0, len = t / g;       for (int i = 1; i <= n; ++i) {         if (!vis.count(a[i])) {           vis[a[i]] = true;           if (!id[a[i] % g]) id[a[i] % g] = ++cnt;           nos[i] = 1LL * k1 * (a[i] % g - a[i]) / g % len;           nos[i] = (nos[i] + len) % len;           se[id[a[i] % g]].insert(nos[i]);         } else           ans[i] = 0;       }       for (int i = 1; i <= n; ++i) {         if (ans[i] == -1) {           set<int>::iterator it = se[id[a[i] % g]].find(nos[i]);           if (it == se[id[a[i] % g]].begin())             it = --se[id[a[i] % g]].end();           else             --it;           int s1 = nos[i], s2 = *it, tmp = s1 - s2;           ans[i] = tmp != 0 ? (tmp + len) % len : len;         }       }       for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const double EPS = 1E-9;   const double PI = acos((double)0) * 2;   const int MAXN = 210000;   struct pt {     int x, y, id;     bool operator<(const pt& p) const {       return make_pair(x, y) < make_pair(p.x, p.y);     }   };   int n, k;   pt a[MAXN], b[MAXN];   bool read() {     if (!(cin >> n >> k)) return false;     for (int i = 0; i < int(n); ++i) {       scanf( %d%d , &a[i].x, &a[i].y);       a[i].id = i;     }     return true;   }   int killed[MAXN], cu;   inline void skip(pt p[], int& ptr) {     while (ptr < n && killed[p[ptr].id] == cu) ++ptr;   }   bool check(pt delta) {     ++cu;     int already = 0;     int pa = 0, pb = 0;     for (;;) {       skip(a, pa);       skip(b, pb);       if (pa == n && pb == n) break;       if (pa == n) {         ++pb;         if (++already > k) return false;         continue;       }       if (pb == n) {         ++pa;         if (++already > k) return false;         continue;       }       pt tmp = b[pb];       tmp.x += delta.x;       tmp.y += delta.y;       if (tmp.x == a[pa].x && tmp.y == a[pa].y) {         ++pa;         ++pb;         continue;       }       if (++already > k) return false;       if (tmp < a[pa]) {         killed[b[pb].id] = cu;         ++pb;       } else {         killed[a[pa].id] = cu;         ++pa;       }     }     return already <= k;   }   void solve() {     if (k >= n) {       puts( -1 );       return;     }     for (int i = 0; i < int(n); ++i) {       b[i] = a[i];       b[i].x *= -1;       b[i].y *= -1;     }     sort(a, a + n);     sort(b, b + n);     set<pt> ans;     for (int c1 = 0; c1 < int(min(n, k + 13)); ++c1)       for (int c2 = 0; c2 < int(min(n, k + 13)); ++c2) {         pt delta;         delta.x = a[c2].x - b[c1].x;         delta.y = a[c2].y - b[c1].y;         if (!ans.count(delta))           if (check(delta)) ans.insert(delta);       }     printf( %d n , ans.size());     for (set<pt>::iterator i = ans.begin(); i != ans.end(); ++i) {       pt p = *i;       printf( %.1lf %.1lf n , p.x / 2.0, p.y / 2.0);     }   }   int main() {     if (!read()) throw;     solve();   }


#include <bits/stdc++.h>      #define fi first   #define se second   #define DB double   #define U unsigned   #define P std::pair   #define LL long long   #define LD long double   #define pb emplace_back   #define MP std::make_pair   #define SZ(x) ((int)x.size())   #define all(x) x.begin(),x.end()   #define CLR(i,a) memset(i,a,sizeof(i))   #define FOR(i,a,b) for(int i = a;i <= b;++i)   #define ROF(i,a,b) for(int i = a;i >= b;--i)   #define DEBUG(x) std::cerr << #x <<  =  << x << std::endl      const int MAXN = 400+5;   const int ha = 998244353;   int n,c[26];   int f[2][MAXN][MAXN][3][3];   int g[2][MAXN][2][2],pw[MAXN];   int F[MAXN][MAXN],G[MAXN];   // 0=a 1=b 2=oth      inline void add(int &x,int y){       x += y-ha;x += x>>31&ha;   }      int main(){       pw[0] = 1;FOR(i,1,MAXN-1) pw[i] = 25ll*pw[i-1]%ha;       scanf( %d ,&n);       FOR(i,0,25) scanf( %d ,c+i);       int now = 0;       f[now][0][0][2][2] = 24*24;       f[now][1][0][2][0] = f[now][1][0][0][2] = 24;       f[now][0][1][2][1] = f[now][0][1][1][2] = 24;       f[now][1][1][0][1] = f[now][1][1][1][0] = 1;       f[now][2][0][0][0] = f[now][0][2][1][1] = 1;       FOR(i,3,n){           CLR(f[now^1],0);           FOR(a,0,n){               FOR(b,0,n){                   FOR(c,0,2){                       FOR(d,0,2){                           // cd?                           int gx = f[now][a][b][c][d];                           if(!gx) continue;                           if(c != 0) add(f[now^1][a+1][b][d][0],gx);                           if(c != 1) add(f[now^1][a][b+1][d][1],gx);                           add(f[now^1][a][b][d][2],1ll*gx*(c==2?23:24)%ha);                       }                   }               }           }           now ^= 1;       }       FOR(i,0,n) FOR(j,0,n) FOR(x,0,2) FOR(y,0,2) add(F[i][j],f[now][i][j][x][y]);       ROF(i,n,0) ROF(j,n,1) add(F[i][j],F[i+1][j]),add(F[i][j],F[i][j+1]),add(F[i][j],ha-F[i+1][j+1]);       now = 0;       g[now][0][1][1] = 25*25;       g[now][1][0][1] = g[now][1][1][0] = 25;       g[now][2][0][0] = 1;       FOR(i,3,n){           CLR(g[now^1],0);           FOR(a,0,n){               FOR(c,0,1){                   FOR(d,0,1){                       int gx = g[now][a][c][d];                       if(!gx) continue;                       if(c != 0) add(g[now^1][a+1][d][0],gx);                       add(g[now^1][a][d][1],1ll*gx*(c==1?24:25)%ha);                   }               }           }           now ^= 1;       }   //    DEBUG(g[now][3][0][1]);       FOR(i,0,n) FOR(x,0,1) FOR(y,0,1) add(G[i],g[now][i][x][y]);       ROF(i,n,0) add(G[i],G[i+1]);       auto calc = [&](int n){           return 26ll*pw[n-1]%ha;       };       int ans = 1ll*calc(n/2)*calc((n+1)/2)%ha;       FOR(i,0,25) add(ans,ha-G[c[i]+1]);       FOR(i,0,25) FOR(j,i+1,25) add(ans,F[c[i]+1][c[j]+1]);       printf( %d n ,ans);       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[510];   vector<pair<int, int> > edges;   vector<int> leaf, nonleaf;   int d = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       if (a[i] == 1)         leaf.push_back(i);       else         nonleaf.push_back(i);     }     d = nonleaf.size() - 1 + min((int)leaf.size(), 2);     int reserved = -1;     if (!leaf.empty()) reserved = leaf.back(), leaf.pop_back();     for (int i = 0; i < (int)nonleaf.size() - 1; i++) {       int k = nonleaf[i];       while (!leaf.empty() && a[k] > 1) {         edges.push_back({leaf.back(), k});         leaf.pop_back();         a[k]--;       }       a[k]--;       a[nonleaf[i + 1]]--;       edges.push_back({k, nonleaf[i + 1]});     }     int tp = 501;     if (!nonleaf.empty()) tp = nonleaf.back();     if (reserved != -1) leaf.push_back(reserved);     while (!leaf.empty() && a[tp] > 0) {       edges.push_back({leaf.back(), tp});       leaf.pop_back();       a[tp]--;     }     if (leaf.empty()) {       printf( YES %d n , d);       printf( %d n , (int)edges.size());       for (auto k : edges) {         printf( %d %d n , k.first, k.second);       }     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1234567;   const long long MOD = 998244353;   void solve() {     long long n, m, i, j = 0, k, l = 0, ok = 0, o = 0, p, ans = 0, x, y, a[30];     string s;     cin >> n >> k >> s;     for (long long i = 0; i < k / 2; i++) {       map<char, long long> mg;       for (j = 0; j < n; j += k) {         mg[s[i + j]]++;         mg[s[j + k - i - 1]]++;       }       l = 0;       for (auto it : mg) l = max(l, it.second);       ans += l;     }     if (k % 2) {       map<char, long long> mg;       for (j = 0; j < n; j += k) {         mg[s[j + k / 2]]++;       }       l = 0;       for (auto it : mg) l = max(l, it.second);       ans += l;     }     cout << (n - ans) << endl;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     tuple<long long, long long, long long> p[200010];     int n;     cin >> n;     long long k, a, x, y, m;     long long b;     long long ans = 0;     long long cnt = 0;     long long sm = 0;     for (int i = 0; i < n; i++) {       cin >> k >> a >> x >> y >> m;       long long t = 0;       sm += k;       for (int j = 0; j < k; j++) {         if (cnt <= 200000) p[cnt++] = {t, a, i};         b = (a * x + y) % m;         if (b < a && j != k - 1) t++;         a = b;       }       ans = max(ans, t);     }     cout << ans << endl;     if (cnt <= 200000) {       sort(p, p + cnt,            [](tuple<long long, long long, long long> &a,               tuple<long long, long long, long long> &b) -> bool {              if (get<0>(a) == get<0>(b)) {                return get<1>(a) < get<1>(b) ||                       (get<1>(a) == get<1>(b) && get<2>(a) < get<2>(b));              }              return get<0>(a) < get<0>(b);            });       for (int i = 0; i < cnt; i++) {         cout << get<1>(p[i]) <<     << get<2>(p[i]) + 1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 210;   const double eps = 1e-9;   int n;   int lsh[maxn * 2], ln, K;   map<int, int> mt;   int To[maxn];   int li[maxn], ri[maxn];   double f[2][maxn][maxn];   double ans[maxn][maxn];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &li[i], &ri[i]);       lsh[++ln] = li[i];       lsh[++ln] = ri[i];     }     sort(lsh + 1, lsh + ln + 1);     lsh[0] = lsh[1] - 1;     K = 0;     for (int i = 1; i <= ln; i++) {       if (lsh[i] != lsh[i - 1]) {         To[mt[lsh[i]] = ++K] = lsh[i];       }     }     for (int i = 1; i <= n; i++) {       li[i] = mt[li[i]], ri[i] = mt[ri[i]];     }     for (int i = 1; i <= n; i++) {       for (int x = li[i]; x < ri[i]; x++) {         double inow = (double)(To[x + 1] - To[x]) / (To[ri[i]] - To[li[i]]);         memset(f, 0, sizeof(f));         int now = 1;         f[now][0][0] = 1.0;         for (int j = 1; j <= n; j++) {           if (i == j) {             continue;           }           int L = To[li[j]], R = To[ri[j]];           now = !now;           if (x < li[j]) {             for (int x1 = 0; x1 < j; x1++) {               for (int x2 = 0; x2 < j - x1; x2++) {                 if (f[!now][x1][x2] > eps) {                   double tmp = f[!now][x1][x2];                   f[!now][x1][x2] = 0;                   f[now][x1][x2] += tmp;                 }               }             }           } else if (ri[j] <= x) {             for (int x1 = 0; x1 < j; x1++) {               for (int x2 = 0; x2 < j - x1; x2++) {                 if (f[!now][x1][x2] > eps) {                   double tmp = f[!now][x1][x2];                   f[!now][x1][x2] = 0;                   f[now][x1 + 1][x2] += tmp;                 }               }             }           } else {             double p1 = (double)(To[x] - L) / (R - L),                    p2 = (double)(To[x + 1] - To[x]) / (R - L),                    p3 = (double)(R - To[x + 1]) / (R - L);             for (int x1 = 0; x1 < j; x1++) {               for (int x2 = 0; x2 < j - x1; x2++) {                 if (f[!now][x1][x2] > eps) {                   double tmp = f[!now][x1][x2];                   f[!now][x1][x2] = 0;                   f[now][x1 + 1][x2] += tmp * p1;                   f[now][x1][x2 + 1] += tmp * p2;                   f[now][x1][x2] += tmp * p3;                 }               }             }           }         }         for (int x1 = 0; x1 < n; x1++) {           for (int x2 = 0; x2 < n - x1; x2++) {             if (f[now][x1][x2] > eps) {               double tmp = f[now][x1][x2], temp = 1.0 / (x2 + 1.0);               for (int l = 0; l <= x2; l++) {                 ans[i][x1 + l + 1] += inow * tmp * temp;               }             }           }         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         printf( %.10lf  , ans[i][j]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     vector<string> ans;     string email =   ;     bool isPoss = true;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  @ ) {         if ((i + 1 < s.length()) && (s[i + 1] !=  @ )) {           if (email ==   ) {             isPoss = false;             break;           } else {             email += s[i];             email += s[i + 1];             ans.push_back(email);             i++;             email =   ;           }         } else {           isPoss = false;           break;         }       } else {         email += s[i];       }     }     if ((email !=   ) && (isPoss) && (ans.size() > 0)) {       ans[ans.size() - 1] = ans[ans.size() - 1] + email;     }     if ((ans.size() == 0) || (!isPoss)) {       cout <<  No solution ;     } else {       cout << ans[0];       for (int i = 1; i < ans.size(); i++) {         cout <<  ,  << ans[i];       }     }   }


#include <bits/stdc++.h>   using namespace std;   char s[1000005];   int main() {     int k, a[10], i, sum, num, maxr;     while (~scanf( %d%s , &k, s)) {       memset(a, 0, sizeof(a));       num = sum = 0;       maxr = -1;       for (i = 0; s[i]; i++) {         int t = s[i] -  0 ;         maxr = max(maxr, t);         a[t]++;         sum += t;       }       if (sum >= k)         puts( 0 );       else {         int flag = 0;         for (i = 0; i <= maxr; i++) {           while (a[i]) {             a[i]--;             sum -= i;             sum += 9;             num++;             if (sum >= k) {               flag = 1;               break;             }           }           if (flag) {             printf( %d n , num);             break;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     int n;     scanf( %d , &n);     memset(a, -1, sizeof(int) * 100005);     int cnt = 1;     for (int i = 2; i <= n; i++) {       if (a[i] == -1) {         for (int j = i; j <= n; j += i) {           if (a[j] == -1) a[j] = cnt;         }         cnt++;       }     }     for (int i = 2; i <= n; i++) {       printf( %d  , a[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isprime[2000005];   void setprime() {     for (long long i = 0; i < 2000005; i++) isprime[i] = true;     isprime[0] = false;     isprime[1] = false;     for (long long i = 2; i < 2000005; i++) {       for (long long j = 2; i * j < 2000005; j++) isprime[i * j] = false;     }   }   long long choose(long long n, long long k) {     if (k == 0) return 1;     return (n * choose(n - 1, k - 1)) / k;   }   long long gcd(long long a, long long b) {     if (!a) return b;     return gcd(b % a, a);   }   long long n, m, temp;   pair<long long, long long> p[100005];   bool start[100005];   vector<pair<pair<long long, long long>, long long> > ans;   long long min1 = LONG_LONG_MAX;   long long end1;   void dfs(long long x) {     if (p[x].first != 0) {       min1 = min(min1, p[x].second);       dfs(p[x].first);     } else {       end1 = x;       return;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long u, v, w;       cin >> u >> v >> w;       p[u] = make_pair(v, w);       start[v] = 1;     }     for (long long i = 1; i < n + 1; i++) {       if (!start[i]) {         min1 = LONG_LONG_MAX;         end1 = -1;         dfs(i);         if (min1 != LONG_LONG_MAX)           ans.push_back(make_pair(make_pair(i, end1), min1));       }     }     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (long long i = 0; i < ans.size(); i++) {       cout << ans[i].first.first <<     << ans[i].first.second <<                << ans[i].second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   const int MAXN = 107;   int A[50007];   int F[107][107];   unsigned long long b[107][107];   struct matrix {     int n, m;     int arr[MAXN][MAXN];     matrix() {}     matrix(int x, int y, int V = 0) {       n = x;       m = y;       for (int j = 0; j < n; j++)         for (int i = 0; i < m; i++) arr[j][i] = V;     }     matrix(int x, int y, int A[MAXN][MAXN]) {       n = x;       m = y;       for (int j = 0; j < n; j++)         for (int i = 0; i < m; i++) arr[j][i] = A[j][i];     }     matrix operator*(matrix &mat) {       matrix res(n, mat.m, 0);       long long theta;       for (int j = 0; j < n; j++) {         for (int i = 0; i < mat.m; i++) {           theta = 0;           for (int k = 0; k < m; k++) {             theta += 1ll * arr[j][k] * mat.arr[k][i];             theta %= MOD;           }           res.arr[j][i] = theta;         }       }       return res;     }     matrix power(long long K) {       matrix res(n, m, 0), b(n, m, 0);       for (int j = 0; j < n; j++) res.arr[j][j] = 1;       b = (*this);       while (K > 0) {         if ((K & 1)) res = res * b;         K /= 2;         b = b * b;       }       return res;     }   };   int main() {     int n, k, x;     unsigned long long b;     cin >> n >> b >> k >> x;     for (int i = 0; i < n; i++) cin >> A[i];     for (int j = 0; j < x; j++)       for (int i = 0; i < n; i++) F[j][(j * 10 + A[i]) % x]++;     matrix M(x, x, F);     matrix B(x, x, 0);     B = M.power(b);     cout << B.arr[0][k] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   void f() {     int n;     string s, t;     cin >> n >> s >> t;     map<char, int> d1, d2;     for (int i = 0; i < n; i++) {       ++d1[s[i]];       ++d2[t[i]];     }     if (d1 != d2) {       cout << -1;       return;     }     int ans = 0;     int l = 1, r = n, mid;     while (l <= r) {       mid = (l + r) / 2;       bool cs = false;       for (int left = 0; left + mid - 1 < n; left++) {         int ptr = left;         for (int i = 0; i < n && ptr < left + mid; i++) {           if (s[i] == t[ptr]) {             ++ptr;           }         }         if (ptr == left + mid) {           cs = true;           break;         }       }       if (cs) {         ans = mid;         l = mid + 1;       } else {         r = mid - 1;       }     }     cout << n - ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int q;     cin >> q;     while (q--) {       f();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int dp[1000000 + 10], cnt[1000000 + 10];   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int a;       scanf( %d , &a);       int t = 0, temp = a;       while (temp <= 1e6) {         dp[temp] += t;         cnt[temp]++;         t++;         temp = (temp << 1);       }       t = 0;       while (a) {         if (a & 1 && a != 1) {           int nt = t + 2, temp = a - 1;           while (temp <= 1e6) {             dp[temp] += nt;             cnt[temp]++;             nt++;             temp = (temp << 1);           }         }         t++;         a = (a >> 1);         dp[a] += t;         cnt[a]++;       }     }     int ans = 0x3f3f3f3f;     for (int i = 1; i <= 1e6; i++) {       if (cnt[i] == n) ans = min(ans, dp[i]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool compare(int a, int b) { return a > b; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (long long int i = 0; i < n + 1; i++) {       for (long long int j = 0; j < 2 * (n - i); j++) {         cout <<    ;       }       for (long long int j = 0; j < i + 1; j++) {         if (i)           cout << j <<    ;         else           cout << j;       }       for (int j = i - 1; j >= 0; j--) {         if (j)           cout << j <<    ;         else           cout << j;       }       cout << endl;     }     for (int i = n - 1; i >= 1; i--) {       for (long long int j = 0; j < 2 * (n - i); j++) {         cout <<    ;       }       for (long long int j = 0; j < i + 1; j++) {         cout << j <<    ;       }       for (int j = i - 1; j >= 0; j--) {         if (j)           cout << j <<    ;         else           cout << j;       }       cout << endl;     }     for (long long int j = 0; j < 2 * (n); j++) {       cout <<    ;     }     cout <<  0 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 9;   int n;   long long a[N], l[N], r[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 1; i <= n - 1; ++i) cin >> a[i];     long long tmp;     l[1] = 0;     for (int i = 2; i <= n; ++i) {       tmp = (a[i - 1] % 2 == 0) ? a[i - 1] : a[i - 1] - 1;       if (a[i - 1] >= 2) l[i] = l[i - 1] + tmp;     }     r[n] = 0;     for (int i = n - 1; i >= 1; --i) {       tmp = (a[i] % 2 == 0) ? a[i] : a[i] - 1;       if (a[i] >= 2) r[i] = r[i + 1] + tmp;     }     tmp = 0;     long long delta;     long long res = 0;     for (int i = n - 1; i >= 1; --i) {       delta = (a[i] % 2 == 0) ? a[i] - 1 : a[i];       tmp = max(tmp + delta, r[i]);       res = max(res, l[i] + tmp);     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     for (int i = 1; i <= n; ++i) {       if (n % i == 0) {         reverse(s.begin(), s.begin() + i);       }     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int arr[n];     int freq[101] = {0};     for (int i = 0; i < n; i++) {       cin >> arr[i];       freq[arr[i]]++;     }     sort(freq, freq + 101, greater<int>());     int max = freq[0];     int num = 0;     for (int i = 0; i < 101; i++) {       if (freq[i] > 0) {         num++;       }     }     int b;     int a = (float)k;     int c = (float)max;     if (k > max) {       b = 1;     } else if (c % a == 0) {       b = max / k;     } else if (k < max && a % c != 0) {       b = (max / k) + 1;     }     cout << (b * k * num) - n << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool color[200005], vis[200005];   int height[200005], dp[200005];   vector<vector<int> > v(200005);   int ans;   void dfs(int a) {     vis[a] = true;     dp[a] = 0;     for (int i = 0; i < v[a].size(); i++) {       if (!vis[v[a][i]]) {         dfs(v[a][i]);         ans = max(ans, dp[a] + dp[v[a][i]] + (color[a] != color[v[a][i]]));         dp[a] = max(dp[a], dp[v[a][i]] + (color[a] != color[v[a][i]]));       }     }     ans = max(ans, dp[a]);   }   int main() {     ios_base::sync_with_stdio(0);     ;     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> color[i + 1];     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1);     cout << (ans + 1) / 2;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     unordered_map<int, int> mp;     vector<int> v[n + 1];     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     vector<int> t;     int ans = 0;     while (1) {       int num = 0;       vector<int> t;       for (int i = 1; i <= n; i++) {         if (v[i].size() == 1) {           num++;           t.push_back(i);         }       }       if (num > 0) {         ans++;         for (int i = 0; i < num; i++) {           int neigh = v[t[i]][0];           v[t[i]].clear();           v[neigh].erase(remove(v[neigh].begin(), v[neigh].end(), t[i]),                          v[neigh].end());         }       } else {         break;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   const int M = 1e9 + 7;   const ll MLL = 1e18L + 9;   #pragma unused(M)   #pragma unused(MLL)   template <ostream& out = cout, class... T>   void prints(T&&...) {}   template <ostream& out = cout, class... T>   void printd(T&&...) {}   template <ostream& out = cout, class... T>   void printb(T&&...) {}   template <ostream& out = cout, class... T>   void printArr(T&&...) {}   ll modPow(ll base, ll ex, ll m) {     ll ret = 1;     while (ex) {       if (ex & 1) {         ret = ret * base % m;       }       ex >>= 1;       base = base * base % m;     }     return ret;   }   ll modFact(ll n, ll m) {     if (!n) {       return 1;     }     static vector<ll> memo = {1, 1};     if (n < (ll)memo.size()) {       return memo[n];     }     for (int i = memo.size(); i <= n; i++) {       memo.push_back(memo.back() * i % m);     }     return memo[n];   }   pair<ll, pair<ll, ll>> exGCD(ll a, ll b) {     bool inv = false;     if (a < b) {       swap(a, b);       inv = true;     }     vector<ll> r = {a, b}, ks;     while (b) {       ks.push_back(a / b);       r.push_back(a = a % b);       swap(a, b);     }     ll gcd = a;     ll x = 0, y = 1, u = 1, v = -ks[0];     for (unsigned long i = 1; i < ks.size(); i++) {       ll k = ks[i];       ll x2 = u, y2 = v, u2 = x - k * u, v2 = y - k * v;       x = x2;       y = y2;       u = u2;       v = v2;     }     if (inv) {       swap(x, y);     }     return {gcd, {x, y}};   }   ll modInv(ll n, ll m) {     return modPow(n, m - 2, m);     auto p = exGCD(n, m);     return (p.second.first + m) % m;   }   ll modC(ll n, ll k, ll m) {     return modFact(n, m) * modInv(modFact(k, m) * modFact(n - k, m) % m, m) % m;   }   int solve(vector<int> as) {     bool p = true;     int n = as.size();     for (int i = 0; i < n - 1; i++) {       for (int j = 0; j < n - i - 1; j++) {         as[j] = as[j] + as[j + 1] * (p ? 1 : -1);         p = !p;       }     }     return as[0];   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<int> as(n);     for (int i = 0; i < n; i++) {       cin >> as[i];     }     for (int i = 1; i <= 31; i++) {       vector<int> as(i, 1), diffs(i);       int n1 = solve(as);       for (int j = 0; j < i; j++) {         as[j]++;         diffs[j] = solve(as) - n1;         as[j]--;       }       prints(i / 4, diffs);     }     int num = n / 4;     vector<int> v1, v2, v3, v4;     for (int i = 0; i < num; i++) {       int mc = modC(2 * num - 1, i, M);       v1.push_back(mc);       v1.push_back(-mc);     }     for (int i = 0; i < num; i++) {       int mc2 = modC(2 * num, i, M);       v2.push_back(mc2);       v2.push_back(0);       v3.push_back(mc2);       v3.push_back(mc2);     }     int mc2 = modC(2 * num, num, M);     v2.push_back(mc2);     v3.push_back(mc2);     {       vector<int> vv(v1.rbegin(), v1.rend());       v1.insert(v1.end(), vv.begin(), vv.end());     }     for (int i = v1.size() / 2; i < v1.size(); i++) {       v1[i] *= -1;     }     {       vector<int> vv(v2.rbegin() + 1, v2.rend());       v2.insert(v2.end(), vv.begin(), vv.end());     }     {       vector<int> vv(v3.rbegin(), v3.rend());       v3.insert(v3.end(), vv.begin(), vv.end());     }     v4 = v3;     for (uint i = 0; i < v4.size(); i++) {       if (i & 1) {         v4[i] *= 2;       } else if (i) {         v4[i] -= v3[i - 2];       }     }     v4.push_back(-v4[0]);     prints(1);     prints(num, v1);     prints(num, v2);     prints(num, v3);     prints(num, v4);     int r = n % 4;     auto& vvv = (r == 0 ? v1 : r == 1 ? v2 : r == 2 ? v3 : v4);     ll ans = 0;     for (int i = 0; i < n; i++) {       ans = (ans + 1ll * vvv[i] * as[i] + M) % M;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f;   unordered_map<int, int> cnt;   int maxi = 0;   int x[100005];   int head[100005], ne[200005], to[200005];   int idx = 0;   int son[100005];   int sz[100005];   long long sum = 0;   long long s[100005];   void Insert(int a, int b) {     to[++idx] = b;     ne[idx] = head[a];     head[a] = idx;   }   void Add(int root, int fa) {     cnt[x[root]]++;     if (cnt[x[root]] == maxi) {       sum += x[root];     } else if (cnt[x[root]] > maxi) {       maxi = cnt[x[root]];       sum = x[root];     }     for (int i = head[root]; i != -1; i = ne[i]) {       int a = to[i];       if (a == fa) continue;       Add(a, root);     }   }   void dfs1(int root, int fa) {     sz[root] = 1;     for (int i = head[root]; i != -1; i = ne[i]) {       int a = to[i];       if (a == fa) continue;       dfs1(a, root);       sz[root] += sz[a];       if (sz[a] > sz[son[root]]) {         son[root] = a;       }     }   }   void dfs2(int root, int fa) {     for (int i = head[root]; i != -1; i = ne[i]) {       int a = to[i];       if (a == fa || a == son[root]) continue;       dfs2(a, root);       maxi = 0;       sum = 0;       cnt.clear();     }     if (son[root]) dfs2(son[root], root);     for (int i = head[root]; i != -1; i = ne[i]) {       int a = to[i];       if (a == fa || a == son[root]) continue;       Add(a, root);     }     cnt[x[root]]++;     if (cnt[x[root]] == maxi) {       sum += x[root];     } else if (cnt[x[root]] > maxi) {       maxi = cnt[x[root]];       sum = x[root];     }     s[root] = sum;   }   int main() {     int n;     memset(head, -1, sizeof(head));     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &x[i]);     }     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       Insert(b, a);       Insert(a, b);     }     dfs1(1, 0);     dfs2(1, 0);     for (int i = 1; i <= n; i++) {       printf( %lld%c , s[i], i == n ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   int n, q;   vector<pair<int, int> > query[maxn];   vector<int> G[maxn];   long long ans[maxn];   long long add[maxn];   void dfs(int v, int p, int d, long long sum) {     for (auto p : query[v]) {       int l = d;       int r = d + p.first + 1;       add[l] += p.second;       if (r < maxn) add[r] -= p.second;     }     sum += add[d];     ans[v] = sum;     for (int u : G[v]) {       if (u == p) continue;       dfs(u, v, d + 1, sum);     }     for (auto p : query[v]) {       int l = d;       int r = d + p.first + 1;       add[l] -= p.second;       if (r < maxn) add[r] += p.second;     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d%d , &x, &y);       G[x].emplace_back(y);       G[y].emplace_back(x);     }     scanf( %d , &q);     while (q--) {       int v, d, x;       scanf( %d%d%d , &v, &d, &x);       query[v].push_back(make_pair(d, x));     }     dfs(1, 0, 1, 0);     for (int i = 1; i <= n; i++) {       printf( %I64d  , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = -1e9;   const int maxn = 400;   int dp[maxn][maxn][maxn];   int a[maxn][maxn];   int main() {     int n;     cin >> n;     for (int i = 0; i <= n + 1; i++)       for (int j = 0; j <= n + 1; j++) a[i][j] = inf;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) cin >> a[i][j];     for (int i = 0; i <= n + 1; i++)       for (int j = 0; j <= n + 1; j++)         for (int k = 0; k <= n + 1; k++) dp[i][j][k] = inf;     dp[1][1][1] = a[1][1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         for (int k = 1; k <= n; k++) {           int l = i + j - k;           if (dp[i][j][k] > inf) continue;           if (l <= 0 or l >= n + 1) {             dp[i][j][k] = inf;             continue;           }           int t1 = dp[i - 1][j][k - 1] + a[i][j] + a[k][l];           int t2 = dp[i - 1][j][k] + a[i][j] + a[k][l];           int t3 = dp[i][j - 1][k - 1] + a[i][j] + a[k][l];           int t4 = dp[i][j - 1][k] + a[i][j] + a[k][l];           dp[i][j][k] = max(max(t1, t2), max(t3, t4));           if (i == k and j == l) dp[i][j][k] -= a[i][j];           if (dp[i][j][k] < -1e7) dp[i][j][k] = 0;         }       }     }     cout << dp[n][n][n];     return 0;   }


#include<bits/stdc++.h>   using namespace std;   # define ll long long   # define read read1<ll>()   # define Type template<typename T>   Type T read1(){    T t=0;    char k;    bool vis=0;    do (k=getchar())== - &&(vis=1);while( 0 >k||k> 9 );    while( 0 <=k&&k<= 9 )t=(t<<3)+(t<<1)+(k^ 0 ),k=getchar();    return vis?-t:t;   }   # define fre(k) freopen(k .in , r ,stdin);freopen(k .out , w ,stdout)   struct A{    int l,r,v;    A(int _l=1,int _r=0,int _v=0){l=_l;r=_r;v=_v;}    A operator &(const A &b){return A(max(l,b.l),min(r,b.r),v&b.v);}   }sl[100005][20],sr[100005][20];   int s,k[100005],la[100005][2];   pair<int,int>a[100005],b[100005];   void pr(int n,bool p){    if(n==1)return;    pr(la[n][p],p^1);    for(int i=la[n][p];i<n;++i)     putchar(p^ 1 ),putchar(   );   }   int main(){    s=read;read;    for(int i=1;i<=s;++i){     k[i]=read;     a[i].first=read;     a[i].second=read;     b[i].first=read;     b[i].second=read;     sr[i][0]=A(a[i].first,a[i].second,b[i].first<=k[i]&&k[i]<=b[i].second);     sl[i][0]=A(b[i].first,b[i].second,a[i].first<=k[i]&&k[i]<=a[i].second);    }for(int i=s;i;--i)     for(int j=0;i+(1<<j+1)-1<=s;++j){      sl[i][j+1]=sl[i][j]&sl[i+(1<<j)][j];      sr[i][j+1]=sr[i][j]&sr[i+(1<<j)][j];     }    int xl=1,xr=1;    for(int i=1;i<=s;++i){     int tv=xr;     if(xl>=i&&a[i].first<=k[i]&&k[i]<=a[i].second&&b[i].first<=k[i-1]&&k[i-1]<=b[i].second){      int j=i;      for(int x=17;x--;)       if(sl[j][x].v&&sl[j][x].l<=k[i-1]&&k[i-1]<=sl[j][x].r)        j+=1<<x;      while(xr<j)la[++xr][1]=i;     }     if(tv>=i&&b[i].first<=k[i]&&k[i]<=b[i].second&&a[i].first<=k[i-1]&&k[i-1]<=a[i].second){      int j=i;      for(int x=17;x--;)       if(sr[j][x].v&&sr[j][x].l<=k[i-1]&&k[i-1]<=sr[j][x].r)        j+=1<<x;      while(xl<j)la[++xl][0]=i;     }    }    if(xl<=s&&xr<=s)return puts( No ),0;    puts( Yes );    if(xl>s)pr(s+1,0);    else pr(s+1,1);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x1, y1, x2, y2;     cin >> n >> m >> x1 >> y1 >> x2 >> y2;     int dx = abs(x1 - x2) - 1;     int dy = abs(y1 - y2) - 1;     if (dx > 3 || dy > 3) {       cout <<  Second  << endl;     } else if (dx <= 2 && dy <= 2) {       cout <<  First  << endl;     } else if (dx <= 1 || dy <= 1) {       cout <<  First  << endl;     } else if (dx < 3 || dy < 3) {       cout <<  Second  << endl;     } else {       cout <<  Second  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> mp;   int t, x;   string s;   char ch;   string transform(string x) {     string s =   ;     for (char ch : x)       if ((ch -  0 ) % 2)         s +=  1 ;       else         s +=  0 ;     while (s.size() < 20) s =  0  + s;     return s;   }   int main() {     ios::sync_with_stdio(false);     cin >> t;     for (int i = 0; i < t; i++) {       cin >> ch >> s;       s = transform(s);       if (ch ==  ? ) {         cout << mp[s] << endl;       } else {         if (ch ==  + ) mp[s]++;         if (ch ==  - ) mp[s]--;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 7;   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f * x;   }   long long n, m, _x, _y, f[300005][2], a[300005], b[300005];   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) b[i] = read();     for (int i = 1; i <= n; i++) {       _x = a[i];       _y = b[i];       for (int j = 0; j <= 1; j++) {         long long x = _x, y = _y, t = 1, cnt, s;         cnt = min(x, y);         x -= cnt;         y -= cnt;         x -= m - f[i - 1][j];         x -= (cnt - 1) * (m - 1);         if (x > 0) {           if (x > m - 1)             s = inf;           else             s = 1 + x;         } else           s = 1;         y -= cnt * (m - 1);         if (y > 0) s = inf;         f[i][j] = s;         x = _x;         y = _y;         x--;         cnt = min(x, y);         x -= cnt;         y -= cnt;         y -= m - f[i - 1][j ^ 1];         x -= cnt * (m - 1);         if (x > 0) {           if (x > m - 1)             s = inf;           else             s = x + 1;         } else           s = 1;         y -= cnt * (m - 1);         if (y > 0) s = inf;         f[i][j] = min(f[i][j], s);         swap(_x, _y);       }     }     if (f[n][0] < inf || f[n][1] < inf)       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char s[200002];   int cnt[200001][26];   void init() {     for (int i = 1; s[i]; ++i) {       for (int j = 0; j < 26; ++j) cnt[i][j] = cnt[i - 1][j];       cnt[i][s[i] -  a ]++;     }   }   int main() {     scanf( %s , s + 1);     init();     int q, l, r;     scanf( %d , &q);     while (q--) {       scanf( %d%d , &l, &r);       int diff = 0;       for (int i = 0; i < 26; ++i) diff += (cnt[l - 1][i] != cnt[r][i]);       if (l == r || s[l] != s[r] || diff > 2)         puts( Yes );       else         puts( No );     }   }


#include <bits/stdc++.h>   using namespace std;   queue<int> s1, s2;   int main() {     int n, k1, k2;     cin >> n;     cin >> k1;     int a, b;     for (int i = 0; i < k1; i++) {       cin >> a;       s1.push(a);     }     cin >> k2;     for (int i = 0; i < k2; i++) {       cin >> b;       s2.push(b);     }     int ans = 0;     while (!s1.empty() && !s2.empty() && ans < 2e5 + 10) {       int t1 = s1.front();       int t2 = s2.front();       s1.pop();       s2.pop();       if (t1 > t2) {         s1.push(t2);         s1.push(t1);       }       if (t1 < t2) {         s2.push(t1);         s2.push(t2);       }       ans++;     }     if (s1.empty()) {       cout << ans <<                <<  2  << endl;     }     if (s2.empty()) {       cout << ans <<                <<  1  << endl;     }     if (ans == 2e5 + 10) cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   const int maxn = 100005;   int n, m, a[maxn], pos[maxn];   std::pair<int, int> b[maxn];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       b[i] = std::make_pair(a[i], i);     }     std::sort(b + 1, b + n + 1);     for (int i = 1; i <= n; ++i) pos[b[i].second] = i;     int ans = 0, r = 0;     for (int i = 1; i <= n; ++i) {       if (i > r) ans++;       r = std::max(r, pos[i]);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   const int N = 3e5 + 7;   long long arr[N];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, m, k;     cin >> n >> m >> k;     long long mn = INT_MAX;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (i % 2 == 0) mn = min(mn, arr[i]);     }     if (n % 2 == 0) {       cout << 0 <<   n ;     } else {       cout << min(mn, (m / (n / 2 + 1)) * k) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     cin >> n >> x >> y;     if ((n / 2 == x || n / 2 + 1 == x) && (n / 2 == y || n / 2 + 1 == y)) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ooxx {     int k, x, y;   } a[100];   int alla, allb, dp[250000][121], n;   int main() {     memset(dp, -1, sizeof(dp));     scanf( %d , &n);     int s = 1 << n;     for (int i = 0; i < s; ++i) dp[i][0] = 0;     for (int i = 0; i < n; ++i) {       char x = getchar();       while ((x !=  R ) && (x !=  B )) x = getchar();       scanf( %d%d , &a[i].x, &a[i].y), alla += a[i].x, allb += a[i].y;       if (x ==  R )         a[i].k = 1;       else         a[i].k = 0;     }     for (int i = 0; i < s; ++i) {       int nowa = 0, nowb = 0;       for (int j = 0; j < n; ++j) {         if (i & (1 << j)) {           if (a[j].k == 1)             nowa++;           else             nowb++;         }       }       for (int j = 0; j <= 120; ++j) {         for (int k = 0; k < n; ++k) {           if (i & (1 << k)) continue;           if (dp[i][j] == -1) continue;           dp[i | (1 << k)][j + min(nowa, a[k].x)] =               max(dp[i | (1 << k)][j + min(nowa, a[k].x)],                   dp[i][j] + min(nowb, a[k].y));         }       }     }     int ans = 1000000000;     for (int i = 0; i <= 120; ++i)       if (dp[s - 1][i] != -1) ans = min(ans, max(allb - dp[s - 1][i], alla - i));     return printf( %d , ans + n), 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ned {     int x, y;     bool operator<(const ned &a) const { return x == a.x ? (y < a.y) : x < a.x; }   };   ned ned[4000010];   int n, m, cnt;   int a[2010], b[2010], c[2010], d[2010];   int sma[4000010];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d%d , &a[i], &b[i]);     for (int i = 1; i <= m; ++i) scanf( %d%d , &c[i], &d[i]);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (a[i] <= c[j] && b[i] <= d[j]) {           ned[++cnt] = {c[j] - a[i] + 1, d[j] - b[i] + 1};         }       }     }     sort(ned + 1, ned + cnt + 1);     for (int i = cnt; i >= 1; --i) sma[i] = max(sma[i + 1], ned[i].y);     int ans = 0x3f3f3f3f;     for (int i = 0; i <= cnt; ++i) ans = min(ans, ned[i].x + sma[i + 1]);     ans = ans * (cnt > 0);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1000011;   bool hsh[MAX];   int fact[MAX];   void sieve(int n) {     int i, a;     for (i = 2; i <= n; i++) hsh[i] = true;     for (i = 2; i <= n; i++)       if (hsh[i]) {         a = 2;         fact[i] = i;         while (a * i <= n) hsh[a * i] = false, fact[a * i] = i, a++;       }   }   int factorize(int n) {     set<int> st;     int cnt = 0;     while (n > 1) {       cnt++;       st.insert(fact[n]);       n /= fact[n];     }     if (cnt == 1) return -1;     return *(--st.end());   }   int main() {     cin.sync_with_stdio(false);     int n, m;     sieve(1e6);     cin >> n;     m = factorize(n);     if (m == -1) {       cout << n;       return 0;     }     int pre = n;     int temp = n - m + 1;     int ans = INT_MAX;     while (n >= temp) {       m = factorize(n);       if (m == -1) {         n--;         continue;       }       ans = min(ans, n - m + 1);       n--;     }     if (ans == INT_MAX) ans = pre;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long mod = 1e9 + 7;   int n;   vector<long long> arr;   vector<pair<vector<long long>, vector<long long> > > segTree;   vector<long long> source(4, 1);   vector<long long> e(4);   vector<long long> multVec(const vector<long long>& vec,                             const vector<long long>& mat) {     vector<long long> result(2);     result[0] = (vec[0] * mat[0] + vec[1] * mat[2]) % mod;     result[1] = (vec[0] * mat[1] + vec[1] * mat[3]) % mod;     return result;   }   vector<long long> multMat(const vector<long long>& a,                             const vector<long long>& b) {     vector<long long> result(4);     result[0] = (a[0] * b[0] + a[1] * b[2]) % mod;     result[1] = (a[0] * b[1] + a[1] * b[3]) % mod;     result[2] = (a[2] * b[0] + a[3] * b[2]) % mod;     result[3] = (a[2] * b[1] + a[3] * b[3]) % mod;     return result;   }   vector<long long> binPow(vector<long long> a, long long b) {     if (b == 0) {       return e;     }     return multMat(binPow(multMat(a, a), b / 2), (b % 2 ? a : e));   }   vector<long long> fib(int idx) {     vector<long long> res(2, 1);     return multVec(res, binPow(source, idx - 1));   }   vector<long long> operator+(const vector<long long>& a,                               const vector<long long>& b) {     vector<long long> result(2);     for (int i = 0; i < 2; i++) {       result[i] = (a[i] + b[i]) % mod;     }     return result;   }   void build(int lf, int rg, int cell) {     segTree[cell].second = e;     if (lf + 1 == rg) {       segTree[cell].first = fib(arr[lf]);       return;     }     int middle = (lf + rg) >> 1;     build(lf, middle, (cell << 1) + 1);     build(middle, rg, (cell << 1) + 2);     segTree[cell].first =         segTree[(cell << 1) + 1].first + segTree[(cell << 1) + 2].first;   }   void push(int cell) {     if (segTree[cell].second != e) {       segTree[(cell << 1) + 1].first =           multVec(segTree[(cell << 1) + 1].first, segTree[cell].second);       segTree[(cell << 1) + 1].second =           multMat(segTree[(cell << 1) + 1].second, segTree[cell].second);       segTree[(cell << 1) + 2].first =           multVec(segTree[(cell << 1) + 2].first, segTree[cell].second);       segTree[(cell << 1) + 2].second =           multMat(segTree[(cell << 1) + 2].second, segTree[cell].second);       segTree[cell].second = e;     }   }   void update(int lf, int rg, int a, int b, const vector<long long>& mat,               int cell) {     if (a >= b) {       return;     }     if (lf == a && rg == b) {       segTree[cell].first = multVec(segTree[cell].first, mat);       segTree[cell].second = multMat(segTree[cell].second, mat);       return;     }     push(cell);     int middle = (lf + rg) >> 1;     update(lf, middle, a, min(b, middle), mat, (cell << 1) + 1);     update(middle, rg, max(a, middle), b, mat, (cell << 1) + 2);     segTree[cell].first =         segTree[(cell << 1) + 1].first + segTree[(cell << 1) + 2].first;   }   vector<long long> require(int lf, int rg, int a, int b, int cell) {     if (a >= b) {       return vector<long long>(2, 0);     }     if (lf == a && rg == b) {       return segTree[cell].first;     }     push(cell);     int middle = (lf + rg) >> 1;     return require(lf, middle, a, min(b, middle), (cell << 1) + 1) +            require(middle, rg, max(a, middle), b, (cell << 1) + 2);   }   void solve() {     int m;     cin >> n >> m;     arr.resize(n);     for (int i = 0; i < n; i++) {       scanf( %I64d , &arr[i]);     }     source[0] = 0;     e[0] = e[3] = 1;     segTree.resize(4 * n);     build(0, n, 0);     for (int i = 0; i < m; i++) {       int type;       scanf( %d , &type);       if (type == 1) {         int lf, rg;         long long x;         scanf( %d%d%I64d , &lf, &rg, &x);         update(0, n, lf - 1, rg, binPow(source, x), 0);       } else {         int lf, rg;         scanf( %d%d , &lf, &rg);         printf( %I64d n , require(0, n, lf - 1, rg, 0)[0]);       }     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  { ;     string sep;     for (const auto& x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename T, size_t size>   ostream& operator<<(ostream& os, const array<T, size>& arr) {     os <<  { ;     string sep;     for (const auto& x : arr) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename A, typename B>   ostream& operator<<(ostream& os, const pair<A, B>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr <<     << H;     dbg_out(T...);   }   namespace math {   template <typename V = int32_t>   inline V extGcd(V a, V b, V& x, V& y) {     bool negativeA = false;     if (a < 0) {       negativeA = true;       a = -a;     }     bool negativeB = false;     if (b < 0) {       negativeB = true;       b = -b;     }     x = 1;     y = 0;     V xTmp = 0;     V yTmp = 1;     while (b) {       V q = a / b;       tie(x, xTmp) = make_tuple(xTmp, x - q * xTmp);       tie(y, yTmp) = make_tuple(yTmp, y - q * yTmp);       tie(a, b) = make_tuple(b, a - q * b);     }     if (negativeA) {       x = -x;     }     if (negativeB) {       y = -y;     }     return a;   }   template <typename V = int>   inline void slightFixModInline(V& v, const V& mod) {     if (v < 0) {       v += mod;     }     if (v >= mod) {       v -= mod;     }   }   template <typename V = int>   inline V invMod(V a, V mod) {     V x0, x1, gcd = extGcd(a, mod, x0, x1);     slightFixModInline(x0, mod);     return x0;   }   template <typename V = int32_t, typename V_SQR = int64_t>   inline void mulModInline(V& res, V x, V mod) {     if (!res || !x) {       res = 0;     } else if (res < mod / x) {       res *= x;     } else {       res = static_cast<V_SQR>(res) * x % mod;     }   }   template <typename V = int32_t, typename V_SQR = int64_t>   inline V mulMod(V a, V b, V mod) {     mulModInline<V, V_SQR>(a, b, mod);     return a;   }   }  // namespace math   template <const int& MOD>   struct _m_int {     int val;     _m_int(int64_t v = 0) {       if (v < 0) v = v % MOD + MOD;       if (v >= MOD) v %= MOD;       val = int(v);     }     _m_int(uint64_t v) {       if (v >= MOD) v %= MOD;       val = int(v);     }     _m_int(int v) : _m_int(int64_t(v)) {}     _m_int(unsigned v) : _m_int(uint64_t(v)) {}     static int inv_mod(int a, int m = MOD) { return math::invMod(a, m); }     explicit operator int() const { return val; }     _m_int& operator+=(const _m_int& other) {       val -= MOD - other.val;       if (val < 0) val += MOD;       return *this;     }     _m_int& operator-=(const _m_int& other) {       val -= other.val;       if (val < 0) val += MOD;       return *this;     }     static unsigned fast_mod(uint64_t x, unsigned m = MOD) {       return unsigned(x % MOD);     }     _m_int& operator*=(const _m_int& other) {       val = math::mulMod(val, other.val, MOD);       return *this;     }     _m_int& operator/=(const _m_int& other) { return *this *= other.inv(); }     friend _m_int operator+(const _m_int& a, const _m_int& b) {       return _m_int(a) += b;     }     friend _m_int operator-(const _m_int& a, const _m_int& b) {       return _m_int(a) -= b;     }     friend _m_int operator*(const _m_int& a, const _m_int& b) {       return _m_int(a) *= b;     }     _m_int& operator++() {       val = val == MOD - 1 ? 0 : val + 1;       return *this;     }     _m_int operator++(int) {       _m_int before = *this;       ++*this;       return before;     }     friend bool operator==(const _m_int& a, const _m_int& b) {       return a.val == b.val;     }     friend bool operator!=(const _m_int& a, const _m_int& b) {       return a.val != b.val;     }     _m_int inv() const { return inv_mod(val); }     _m_int pow(int64_t p) const {       if (p < 0) return inv().pow(-p);       _m_int a = *this, result = 1;       while (p > 0) {         if (p & 1) result *= a;         p >>= 1;         if (p > 0) a *= a;       }       return result;     }   };   extern const int MOD = 998244353;   using mod_int = _m_int<MOD>;   template <const int& MOD>   struct NTT {     using ntt_int = _m_int<MOD>;     vector<ntt_int> roots = {0, 1};     vector<int> bit_reverse;     int max_size = -1;     ntt_int root;     void reset() {       roots = {0, 1};       max_size = -1;     }     static bool is_power_of_two(int n) { return (n & (n - 1)) == 0; }     static int round_up_power_two(int n) {       while (n & (n - 1)) n = (n | (n - 1)) + 1;       return max(n, 1);     }     static int get_length(int n) {       assert(is_power_of_two(n));       return __builtin_ctz(n);     }     void bit_reorder(int n, vector<ntt_int>& values) {       if (int(bit_reverse.size()) != n) {         bit_reverse.assign(n, 0);         int length = get_length(n);         for (int i = 1; i < n; i++)           bit_reverse[i] = (bit_reverse[i >> 1] >> 1) | ((i & 1) << (length - 1));       }       for (int i = 0; i < n; i++)         if (i < bit_reverse[i]) swap(values[i], values[bit_reverse[i]]);     }     void find_root() {       max_size = 1 << __builtin_ctz(MOD - 1);       root = 2;       while (!(root.pow(max_size) == 1 && root.pow(max_size / 2) != 1)) root++;     }     void prepare_roots(int n) {       if (max_size < 0) find_root();       assert(n <= max_size);       if (int(roots.size()) >= n) return;       int length = get_length(int(roots.size()));       roots.resize(n);       while (1 << length < n) {         ntt_int z = root.pow(max_size >> (length + 1));         for (int i = 1 << (length - 1); i < 1 << length; i++) {           roots[2 * i] = roots[i];           roots[2 * i + 1] = roots[i] * z;         }         length++;       }     }     void fft_iterative(int n, vector<ntt_int>& values) {       assert(is_power_of_two(n));       prepare_roots(n);       bit_reorder(n, values);       for (int len = 1; len < n; len *= 2)         for (int start = 0; start < n; start += 2 * len)           for (int i = 0; i < len; i++) {             ntt_int even = values[start + i];             ntt_int odd = values[start + len + i] * roots[len + i];             values[start + len + i] = even - odd;             values[start + i] = even + odd;           }     }     void invert_fft(int n, vector<ntt_int>& values) {       ntt_int inv_n = ntt_int(n).inv();       for (int i = 0; i < n; i++) values[i] *= inv_n;       reverse(values.begin() + 1, values.end());       fft_iterative(n, values);     }     const int FFT_CUTOFF = 150;     template <typename T>     vector<T> mod_multiply(const vector<T>& _left, const vector<T>& _right) {       if (_left.empty() || _right.empty()) return {};       vector<ntt_int> left(_left.begin(), _left.end());       vector<ntt_int> right(_right.begin(), _right.end());       int n = int(left.size());       int m = int(right.size());       int output_size = n + m - 1;       int N = round_up_power_two(output_size);       left.resize(N, 0);       right.resize(N, 0);       fft_iterative(N, left);       fft_iterative(N, right);       for (int i = 0; i < N; i++) left[i] *= right[i];       invert_fft(N, left);       return vector<T>(left.begin(), left.begin() + output_size);     }   };   NTT<MOD> ntt;   const int L_MAX = 5e5 + 5;   namespace io {   const int _kReadBufferSize = 1 << 15;   char _readBuffer[_kReadBufferSize];   int _readPos;   int _readLength;   bool _ended = false;   inline void _loadBuffer() {     _readLength = static_cast<int>(         fread(_readBuffer, sizeof(char), _kReadBufferSize, stdin));     _readPos = 0;   }   inline char readChar(bool advance = true) {     if (_ended) {       return 0;     }     if (_readPos >= _readLength) {       _loadBuffer();       if (_readLength == 0) {         _ended = true;         return 0;       }     }     return _readBuffer[advance ? _readPos++ : _readPos];   }   template <typename T>   inline bool readInt(T& res) {     char ch;     while (true) {       ch = readChar(false);       if (!ch) {         return false;       }       if (!isspace(ch)) {         break;       }       ++_readPos;     }     ch = readChar(false);     bool negative = ch ==  - ;     if (negative) {       ++_readPos;     }     res = 0;     while (true) {       ch = readChar(false);       if (!isdigit(ch)) {         break;       }       res = (res << 3) + (res << 1) + (ch & 15);       ++_readPos;     }     if (negative) {       res = -res;     }     return true;   }   const int _kWriteBufferSize = 1 << 15;   int _writePos = 0;   char _writeBuffer[_kWriteBufferSize];   inline void writeChar(char x) {     if (_writePos == _kWriteBufferSize) {       fwrite(_writeBuffer, 1, _kWriteBufferSize, stdout);       _writePos = 0;     }     _writeBuffer[_writePos++] = x;   }   struct _Flusher {     inline void flush() {       if (_writePos) {         fwrite(_writeBuffer, 1, _writePos, stdout);         _writePos = 0;       }       fflush(stdout);     }     inline ~_Flusher() { flush(); }   } _flusher;   template <class T>   inline void writeInt(T x, int padding = 0) {     static char s[32];     if (x < 0) {       writeChar( - );       x = -x;     }     int n = 0;     for (; x || !n; x /= 10) {       s[n++] =  0  + x % 10;     }     for (int i = n; i < padding; ++i) {       writeChar( 0 );     }     for (; n > 0; writeChar(s[--n])) {     }   }   }  // namespace io   int main() {     int N, X, Y;     io::readInt(N);     io::readInt(X);     io::readInt(Y);     vector<mod_int> lines(X + 1, 0);     for (int i = 0; i <= N; i++) {       int a;       io::readInt(a);       lines[a] = 1;     }     vector<mod_int> rev_lines = lines;     reverse(rev_lines.begin(), rev_lines.end());     vector<mod_int> product = ntt.mod_multiply(lines, rev_lines);     vector<int> answers(L_MAX, -1);     for (int f = Y + 1; f < L_MAX; f++)       if (f - Y <= X && product[X + f - Y] != 0)         for (int x = f; x < L_MAX; x += f) answers[x] = 2 * f;     int Q;     io::readInt(Q);     for (int q = 0; q < Q; q++) {       int len;       io::readInt(len);       len /= 2;       io::writeInt(answers[len]);       io::writeChar(q < Q - 1 ?     :   n );     }   }


#include <bits/stdc++.h>   const int N = 1000001;   int gcd(int a, int b) {     int c;     while (a) {       c = a;       a = b % a;       b = c;     }     return b;   }   void cal(int a, int b, int &s1, int &s2) {     int c;     while (a > 1) {       s1 += b / a;       s2 += b / a - 1;       c = a;       a = b % a;       b = c;     }     s1 += b;     s2 += b - 2;   }   int s[N];   void output(int a, int b) {     int sign = 0, m = 0, c;     while (a > 1) {       for (int i = b / a; i >= 1; --i) s[m++] = sign;       c = a;       a = b % a;       b = c;       sign ^= 1;     }     if (sign)       for (int i = m - 1; i >= 0; --i) s[i] ^= 1;     for (int i = b - 1; i >= 1; --i) s[m++] = 0;     s[m++] = 1;     for (int i = m - 1; i >= 0; --i)       if (s[i])         printf( T );       else         printf( B );     printf(  n );   }   int main() {     int n, r, mis, d;     int s1, s2;     while (scanf( %d%d , &n, &r) != EOF) {       mis = n + 1;       d = -1;       for (int i = 1; i <= r; ++i) {         if (gcd(i, r) != 1) continue;         s1 = s2 = 0;         cal(i, r, s1, s2);         if (s2 < 0) s2 = 0;         if (s1 == n && s2 < mis) mis = s2, d = i;       }       if (mis > n)         printf( IMPOSSIBLE n );       else {         printf( %d n , mis);         output(d, r);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   bool judge(long long k) {     if (n == 1) return 1;     long long num = (long long)m * k, res = 1, C = 1;     for (int i = 1; i <= k; i++) {       if (num < i) return 0;       if ((long long)(k - i + 1) * C >= (long long)n * i)         C = n;       else         C = C * (k - i + 1) / i;       long long temp = min(num / i, C);       res += temp;       if (res >= n) return 1;       num -= temp * i;     }     return 0;   }   int main() {     long long T;     cin >> T;     while (T--) {       cin >> n >> m;       long long l = 0, r = n, mid, ans;       while (l <= r) {         mid = (l + r) / 2;         if (judge(mid)) {           ans = mid;           r = mid - 1;         } else           l = mid + 1;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int k, n, maxb, t;   int b[100010], flag[100010];   int main() {     ios::sync_with_stdio(false);     cin >> k >> n >> maxb >> t;     t = min(t, min(n, maxb));     for (int ti = 1; ti <= k; ti++) {       for (int i = 1; i <= n; i++) cin >> b[i];       for (int i = 0; i <= maxb; i++) flag[i] = 0;       for (int i = 1; i <= t; i++)         for (int j = 1; j <= n; j++)           for (int k = b[j]; k <= maxb && flag[k] == flag[b[j] - 1]; k++)             flag[k]++;       cout << flag[maxb] << endl;     }     return 0;   }


#include <bits/stdc++.h>   const long long MOD1 = 998244353, MOD2 = 1000000007;   long long POWER_MOD1[300001], POWER_MOD2[300001];   struct node {     long long hash1_MOD1, hash1_MOD2, hash2_MOD1, hash2_MOD2;     int len;   } T[1048576], single[2] = {(node){0, 0, 0, 0, 1}, (node){1, 1, 1, 1, 1}};   inline node operator+(const node &a, const node &b) {     return (node){(a.hash1_MOD1 + POWER_MOD1[a.len] * b.hash1_MOD1) % MOD1,                   (a.hash1_MOD2 + POWER_MOD2[a.len] * b.hash1_MOD2) % MOD2,                   (b.hash2_MOD1 + POWER_MOD1[b.len] * a.hash2_MOD1) % MOD1,                   (b.hash2_MOD2 + POWER_MOD2[b.len] * a.hash2_MOD2) % MOD2,                   a.len + b.len};   }   int N, a[300001];   node G(int p, int l, int r, int L, int R) {     if (L <= l && r <= R) return T[p];     int m = l + r >> 1;     if (R <= m) return G(p << 1, l, m, L, R);     if (L > m) return G(p << 1 | 1, m + 1, r, L, R);     return G(p << 1, l, m, L, R) + G(p << 1 | 1, m + 1, r, L, R);   }   void P(int x, int w) {     int p = 1, l = 1, r = N;     while (l < r) {       int m = l + r >> 1;       if (x <= m)         p <<= 1, r = m;       else         p = p << 1 | 1, l = m + 1;     }     T[p] = single[w];     while (p >>= 1) T[p] = T[p << 1] + T[p << 1 | 1];   }   void build(int p, int l, int r) {     if (l == r) {       T[p] = single[0];       return;     }     int m = l + r >> 1;     build(p << 1, l, m);     build(p << 1 | 1, m + 1, r);     T[p] = T[p << 1] + T[p << 1 | 1];   }   int main() {     scanf( %d , &N);     POWER_MOD1[0] = POWER_MOD2[0] = 1;     for (int i = 1; i <= N; i++) {       scanf( %d , a + i);       POWER_MOD1[i] = POWER_MOD1[i - 1] * 2 % MOD1;       POWER_MOD2[i] = POWER_MOD2[i - 1] * 2 % MOD2;     }     build(1, 1, N);     for (int i = 1; i <= N; i++) {       int len = std::min(a[i] - 1, N - a[i]);       node H = G(1, 1, N, a[i] - len, a[i] + len);       if (H.hash1_MOD1 != H.hash2_MOD1 || H.hash1_MOD2 != H.hash2_MOD2) {         puts( YES );         return 0;       }       P(a[i], 1);     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   int main(void) {     long n;     long sum = 0;     int i;     int call = 0;     scanf( %li , &n);     while (n != 1) {       call = 0;       for (i = 2; i <= (long)sqrt((double)n); i++)         if (!(n % i)) {           call = 1;           break;         }       if (call) {         sum += n;         n /= i;       } else {         sum += n;         n = 1;       }     }     printf( %li , sum + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 5;   int n, first[MAX], nextt[MAX * 2], u[MAX * 2], v[MAX * 2], cnt, white, black;   int ans[MAX], father[MAX], tem[MAX];   bool col[MAX];   void add(int a, int b) {     u[cnt] = a, v[cnt] = b;     nextt[cnt] = first[u[cnt]];     first[u[cnt]] = cnt;     ++cnt;   }   void dfs1(int dot, int fa) {     father[dot] = fa;     col[dot] ? ++tem[dot] : --tem[dot];     for (int num = first[dot]; num != -1; num = nextt[num]) {       if (v[num] == fa) continue;       dfs1(v[num], dot);       if (tem[v[num]] > 0) tem[dot] += tem[v[num]];     }   }   void dfs2(int dot, int fa) {     for (int num = first[dot]; num != -1; num = nextt[num]) {       if (v[num] == fa) continue;       int nn = ans[dot];       if (tem[v[num]] > 0) nn -= tem[v[num]];       if (nn > 0) ans[v[num]] += nn;       dfs2(v[num], dot);     }   }   void solve() {     memset(first, -1, sizeof(first));     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &col[i]), col[i] ? ++white : black;     for (int i = 1; i < n; ++i) {       int a, b;       scanf( %d%d , &a, &b);       add(a, b), add(b, a);     }     dfs1(1, 0);     for (int i = 1; i <= n; ++i) ans[i] = tem[i];     dfs2(1, 0);     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);   }   int main(void) {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300005;   long long sum[3][maxn];   int pre[3][maxn];   map<pair<int, int>, int> vis, dp;   int ans[maxn];   map<long long, int> pos;   int dfs(int x, int y) {     if (vis[make_pair((x), (y))])       return dp[make_pair((x), (y))];     else {       vis[make_pair((x), (y))] = 1;       dp[make_pair((x), (y))] =           max(ans[min(x, y)], pre[0][x] > pre[1][y] ? dfs(pre[0][x], y) + 1                                                     : dfs(x, pre[1][y]) + 1);       return dp[make_pair((x), (y))];     }   }   int main() {     int n, a;     cin >> n;     n++;     for (int i = 2; i <= n; i++) {       cin >> a;       sum[0][i] = sum[0][i - 1] + a;     }     for (int i = 2; i <= n; i++) {       cin >> a;       sum[1][i] = sum[1][i - 1] + a;       sum[2][i] = sum[0][i] + sum[1][i];     }     for (int k = 0; k < 3; k++) {       pos.clear();       for (int i = 1; i <= n; i++) {         pre[k][i] = max(pre[k][i - 1], pos[sum[k][i]]);         pos[sum[k][i]] = i;       }     }     ans[0] = pre[0][0] = pre[1][0] = -1;     vis[make_pair((0), (0))] = 1;     dp[make_pair((0), (0))] = -2;     for (int i = 2; i <= n; i++) {       ans[i] = max(ans[pre[2][i]] + 1, dfs(i, i));       dp[make_pair((i), (i))] = ans[i];     }     cout << ans[n] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, cnt = 0, pz = 0, mx = 0;     string s;     cin >> a >> b;     for (int i = 0; i < a; i++) {       for (int j = 0; j < b; j++) {         s += j + 97;       }     }     for (int i = 0; i < a; i++) cout << s[i];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, m;     cin >> n >> m;     char t[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> t[i][j];       }     }     bool check = true;     int count = 0, r, l;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (t[i][j] ==  B ) {           count++;           if (check) {             l = j;             check = false;           }         }       }       if (count) {         r = i + 1 + count / 2;         l = l + 1 + count / 2;         cout << r <<     << l;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   std::mt19937 rnd(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXH = 200000;   const int MAXW = 200000;   const int MAXQ = 200000;   int h, w, nq;   int qx[MAXQ], qy[MAXQ];   bool qans[MAXQ];   int a[MAXW], b[MAXW];   bool can(int cnt) {     for (int y = (0); y < (w); ++y) a[y] = b[y] = 0;     for (int i = (0); i < (cnt); ++i) {       int x = qx[i], y = qy[i];       if (x % 2 == 1 && y % 2 == 1) {         x /= 2, y /= 2;         a[y] = max(a[y], x + 1);       } else {         assert(x % 2 == 0 && y % 2 == 0);         x /= 2, y /= 2;         b[y] = max(b[y], h - x);       }     }     for (int y = w - 2; y >= 0; --y) a[y] = max(a[y], a[y + 1]);     for (int y = 2; y < w; ++y) b[y] = max(b[y], b[y - 1]);     for (int y = (0); y < (w); ++y)       if (a[y] + b[y] > h) return false;     return true;   }   void solve() {     int lo = 0, hi = nq + 1;     while (lo + 1 < hi) {       int mi = lo + (hi - lo) / 2;       if (can(mi))         lo = mi;       else         hi = mi;     }     int res = lo;     for (int i = (0); i < (nq); ++i)       if (i + 1 <= res)         qans[i] = true;       else         qans[i] = false;   }   void run() {     scanf( %d%d%d , &h, &w, &nq);     for (int i = (0); i < (nq); ++i)       scanf( %d%d , &qx[i], &qy[i]), --qx[i], --qy[i];     solve();     for (int i = (0); i < (nq); ++i) printf( %s n , qans[i] ?  YES  :  NO );   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long INF = (1e15);   int a[110];   int main() {     int n, x, y;     scanf( %d%d%d , &n, &x, &y);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     if (x > y) {       printf( %d n , n);     } else {       int ans = 0;       for (int i = 1; i <= n; i++) {         if (a[i] <= x) {           ans++;         }       }       ans++;       ans /= 2;       printf( %d n , ans);     }     return 0;   }