#include <bits/stdc++.h>   using namespace std;   int t, n, m, cur;   int nxt[200200][26], link[200200], dp[200200], cnt[200200], ord[200200],       occur[200200];   char s[200200];   void extend(int c) {     int x = cur, y = cur = ++m;     dp[y] = dp[x] + 1;     occur[y] = 1;     while (x && !nxt[x][c]) nxt[x][c] = y, x = link[x];     if (!x)       link[y] = 1;     else {       int z = nxt[x][c];       if (dp[z] == dp[x] + 1)         link[y] = z;       else {         int u = ++m;         memcpy(nxt[u], nxt[z], sizeof nxt[u]);         link[u] = link[z], link[z] = link[y] = u;         dp[u] = dp[x] + 1;         while (x && nxt[x][c] == z) nxt[x][c] = u, x = link[x];       }     }   }   void build(char *s) {     memset(nxt, 0, sizeof nxt), memset(link, 0, sizeof link),         memset(dp, 0, sizeof dp);     n = strlen(s), m = 0;     cur = ++m;     for (int i = 0; i < n; i++) extend(s[i] -  a );     memset(cnt, 0, sizeof cnt);     for (int i = 1; i <= m; i++) cnt[dp[i]]++;     for (int i = 1; i <= n; i++) cnt[i] += cnt[i - 1];     for (int i = m; i >= 1; i--) ord[cnt[dp[i]]--] = i;   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %s , s);       memset(occur, 0, sizeof occur);       build(s);       for (int i = m; i >= 1; i--) occur[link[ord[i]]] += occur[ord[i]];       long long ans = 0;       for (int i = 1; i <= m; i++)         ans += 1ll * occur[i] * occur[i] * (dp[i] - dp[link[i]]);       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e4;   long long F[maxN + 1];   void fact() {     F[0] = F[1] = 1;     for (int i = 2; i <= maxN; i++) F[i] = (1LL * F[i - 1] * i) % 998244353;   }   long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) {         res = (1LL * res * a) % 998244353, b--;       } else {         a = (1LL * a * a) % 998244353, b >>= 1;       }     }     return res;   }   long long C(long long n, long long r) {     if (r > n) return 0;     long long res = F[n];     res = (1LL * res * power(F[r], 998244353 - 2)) % 998244353;     res = (1LL * res * power(F[n - r], 998244353 - 2)) % 998244353;     return res;   }   void solve() {     long long n, k;     cin >> n >> k;     string second;     cin >> second;     if (!k) {       cout <<  1 n ;       return;     }     long long ans = 1, l = 0, r = 0, cnt = 0;     while (r < n) {       if (second[r] ==  1 ) {         if (cnt == k) {           (ans += (C(r - l, k) - 1 + 998244353) % 998244353) %= 998244353;           while (l < n && second[l] !=  1 ) l++;           l++, cnt--;           ans = (ans - C(r - l, k - 1) + 1 + 998244353) % 998244353;         }         cnt++;       }       r++;     }     if (cnt == k) (ans += (C(r - l, k) - 1 + 998244353) % 998244353) %= 998244353;     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0), fact();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[250001];   int a, ans[250001], n, i, q, kol;   bool pole[250001];   void dfs(int nom) {     int i;     kol++;     pole[nom] = true;     for (i = 0; i < v[nom].size(); i++)       if (!pole[v[nom][i]]) dfs(v[nom][i]);     ans[nom] = kol;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> q;     while (q--) {       cin >> n;       for (i = 1; i <= n; i++) {         v[i].clear();         pole[i] = false;       }       for (i = 1; i <= n; i++) {         cin >> a;         v[i].push_back(a);       }       for (i = 1; i <= n; i++)         if (!pole[i]) {           kol = 0;           dfs(i);         }       for (i = 1; i <= n - 1; i++) cout << ans[i] <<    ;       cout << ans[n] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   const long long INF = 1e18L + 7;   template <class n, class second>   ostream &operator<<(ostream &p, pair<n, second> x) {     return p <<  <  << x.first <<  ,   << x.second <<  > ;   }   template <class n>   auto operator<<(ostream &p, n y) ->       typename enable_if<!is_same<n, string>::value,                          decltype(y.begin(), p)>::type {     int o = 0;     p <<  { ;     for (auto c : y) {       if (o++) p <<  ,  ;       p << c;     }     return p <<  } ;   }   void dor() { cerr <<   n ; }   template <class n, class... second>   void dor(n p, second... y) {     cerr << p <<    ;     dor(y...);   }   template <class n, class second>   void mini(n &p, second y) {     if (p > y) p = y;   }   template <class n, class second>   void maxi(n &p, second y) {     if (p < y) p = y;   }   const int mod = 998244353;   const int N = 507;   int n, m;   int tab[N];   int dp[N][N][3];   int vis[N][N][3];   int pie[N];   int dru[N];   void solve(int a, int b, int t) {     if (vis[a][b][t]) return;     vis[a][b][t] = 1;     if (a > b) {       if (t == 2)         dp[a][b][t] = 1;       else         dp[a][b][t] = 0;       return;     }     int col = inf;     int ind = -1;     if (t == 2) {       for (int i = a; i <= b; ++i) {         if (col > tab[i]) {           col = tab[i];           ind = i;         }       }       solve(a, ind, 1);       solve(ind, b, 0);       dp[a][b][t] = (long long)dp[a][ind][1] * dp[ind][b][0] % mod;     } else if (t == 0) {       for (int i = a; i <= b; ++i) {         solve(a + 1, i, 2);         solve(i + 1, b, 2);         dp[a][b][t] += (long long)dp[a + 1][i][2] * dp[i + 1][b][2] % mod;         if (dp[a][b][t] >= mod) dp[a][b][t] -= mod;       }     } else if (t == 1) {       for (int i = a; i <= b; ++i) {         solve(a, i - 1, 2);         solve(i, b - 1, 2);         dp[a][b][t] += (long long)dp[a][i - 1][2] * dp[i][b - 1][2] % mod;         if (dp[a][b][t] >= mod) dp[a][b][t] -= mod;       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> tab[i];     }     solve(1, n, 2);     cout << dp[1][n][2] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[3005], b[3005], df[3005];   long long F[3005][3005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       a[i] = a[i] - i;       b[i] = a[i];     }     sort(b + 1, b + n + 1);     int m = 0;     b[0] = b[1] - 1;     for (int i = 1; i <= n; ++i) {       if (b[i] > b[i - 1]) df[++m] = b[i];     }     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= m; ++j) {         F[i][j] = 1e18;       }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         F[i][j] = min(F[i][j - 1], F[i - 1][j] + abs(a[i] - df[j]));       }     }     long long rs = 1e18;     for (int i = 1; i <= m; ++i) rs = min(rs, F[n][i]);     cout << rs;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( -O2 )   using namespace std;   const int LIM = 2e5 + 5, MOD = 1e9 + 7;   int t, n, m, k, x, y;   template <typename... T>   void read(T &...args) {     ((cin >> args), ...);   }   template <typename... T>   void print(T &&...args) {     ((cout << args <<    ), ...);   }   int main() {     int n;     read(n);     long long int arr[n];     for (int i = 0; i < n; i++) read(arr[i]);     sort(arr, arr + n);     long long int val = pow(arr[n - 1], 1.0 / (n - 1));     long long int a1 = 0, a2 = 0;     for (int i = 0; i < n; i++) {       a1 += abs(pow(val, i) - arr[i]);     }     val++;     for (int i = 0; i < n; i++) {       a2 += abs(pow(val, i) - arr[i]);     }     long long int curr = pow(val, n - 2), curr2 = pow(val, n - 1);     if (curr2 / curr == val)       cout << min(a1, a2) << endl;     else       cout << a1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct frac {     long long p, q;   } frac;   const double eps = 1e-8;   int n;   int nb[100100];   vector<int> G[100100];   bool col[100100];   int cur[100100];   int onstk[100100];   inline bool operator<(frac a, frac b) { return a.p * b.q < b.p * a.q; }   inline bool operator==(frac a, frac b) { return a.p * b.q == b.p * a.q; }   inline bool operator>(frac a, frac b) { return a.p * b.q > b.p * a.q; }   inline bool operator>=(frac a, double b) {     return ((double)a.p / (double)a.q) >= b;   }   inline bool operator!=(frac a, frac b) { return a.p * b.q != b.p * a.q; }   inline frac newfrac(long long a, long long b) {     frac x;     x.p = a;     x.q = b;     return x;   }   inline bool valid(double z, bool pr) {     priority_queue<pair<frac, int>, vector<pair<frac, int> >,                    greater<pair<frac, int> > >         S;     for (int i = (1); i <= (n); i++) {       cur[i] = 0;       onstk[i] = false;     }     for (int x = (1); x <= (n); x++) {       if (col[x]) {         for (int j = (0); j < (G[x].size()); j++) {           int y = G[x][j];           if (col[y]) {             cur[x]++;           }         }         S.push(make_pair(newfrac(cur[x], nb[x]), x));         onstk[x] = true;       }     }     bool ok = false;     while (!S.empty()) {       if (!onstk[S.top().second]) {         S.pop();         continue;       }       if (S.top().first >= z) {         ok = true;         break;       } else {         int x = S.top().second;         S.pop();         onstk[x] = false;         for (int j = (0); j < (G[x].size()); j++) {           int y = G[x][j];           if (onstk[y]) {             cur[y]--;             S.push(make_pair(newfrac(cur[y], nb[y]), y));           }         }       }     }     if (pr) {       int cnt = 0;       vector<int> V;       for (int i = (1); i <= (n); i++) {         if (onstk[i]) {           cnt++;           V.push_back(i);         }       }       printf( %d n , cnt);       for (int i = (0); i < (V.size()); i++) {         printf( %d , V[i]);         if (i < V.size() - 1) {           printf(   );         }       }       printf(  n );     }     return ok;   }   int main() {     int m, k, x, y;     scanf( %d%d%d , &n, &m, &k);     for (int i = (1); i <= (n); i++) {       nb[i] = 0;       col[i] = true;     }     for (int i = (1); i <= (k); i++) {       scanf( %d , &x);       col[x] = false;     }     for (int i = (1); i <= (m); i++) {       scanf( %d%d , &x, &y);       nb[x]++;       nb[y]++;       if ((col[y]) and (col[x])) {         G[x].push_back(y);         G[y].push_back(x);       }     }     double l = 0.0, r = 1.0;     while ((r - l) > eps) {       double mid = (l + r) / 2;       if (valid(mid, false)) {         l = mid;       } else {         r = mid;       }     }     col[0] = valid(l, true);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int A, B, C, D;   struct Point {     long long x, y;     Point(long long x, long long y) : x(x), y(y) {}   };   bool operator<(const Point& a, const Point& b) {     return a.x < b.x || (a.x == b.x && a.y > b.y);   }   int main() {     int n;     scanf( %d , &n);     scanf( %d/%d %d/%d , &A, &B, &C, &D);     vector<Point> P;     for (int i = 0; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       long long x = (long long)B * v - (long long)A * u;       long long y = (long long)C * u - (long long)D * v;       if (x > 0 && y > 0) {         P.emplace_back(Point(x, y));       }     }     sort(P.begin(), P.end());     vector<long long> len;     for (auto& it : P) {       int idx = lower_bound(len.begin(), len.end(), it.y) - len.begin();       if (idx == len.size()) {         len.emplace_back(it.y);       } else {         len[idx] = it.y;       }     }     printf( %d n , len.size());     return 0;   }


#include <bits/stdc++.h>   int n;   int main() {     int i;     scanf( %d , &n);     for (i = 20; i >= 0; i--) {       if (n & (1 << i)) printf( %d  , i + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   struct all {     int t, num;     char x, type;   } a[N];   bool cmp(all a, all b) { return a.t < b.t; }   int redhome[N], redaway[N];   int yellhome[N], yellaway[N];   string home, away;   int n;   int main() {     cin >> home >> away;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i].t >> a[i].x >> a[i].num >> a[i].type;     sort(a + 1, a + n + 1, &cmp);     for (int i = 1; i <= n; ++i) {       if (a[i].x ==  h ) {         if (a[i].type ==  r ) {           if (redhome[a[i].num] == 0) {             redhome[a[i].num] = a[i].t;             cout << home <<     << a[i].num <<     << a[i].t << endl;           }         } else {           if (yellhome[a[i].num] == 0)             yellhome[a[i].num] = a[i].t;           else if (redhome[a[i].num] == 0) {             redhome[a[i].num] = a[i].t;             cout << home <<     << a[i].num <<     << a[i].t << endl;           }         }       } else {         if (a[i].type ==  r ) {           if (redaway[a[i].num] == 0) {             redaway[a[i].num] = a[i].t;             cout << away <<     << a[i].num <<     << a[i].t << endl;           }         } else {           if (yellaway[a[i].num] == 0)             yellaway[a[i].num] = a[i].t;           else if (redaway[a[i].num] == 0) {             redaway[a[i].num] = a[i].t;             cout << away <<     << a[i].num <<     << a[i].t << endl;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   void qread(int &x) {     int neg = 1;     x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = 10 * x + c -  0 , c = getchar();     x *= neg;   }   const int maxn = 100005;   int n, l, r, k, ans, ansu, ansv;   vector<pair<int, int> > edge[maxn];   vector<int> num;   int oriw[maxn], w[maxn], dep[maxn], lvl[maxn], son[maxn];   int pos[maxn], dis[maxn];   pair<int, int> val[maxn];   namespace Segtree {   int sz;   pair<int, int> t[maxn * 4];   void init(int _sz) {     for (sz = 1; sz < _sz; sz <<= 1)       ;     for (int(i) = 0; (i) < sz << 1; i++) t[i] = make_pair(-1e9, -1e9);   }   void update(int v, pair<int, int> val) {     v += sz - 1;     t[v] = val;     for (v >>= 1; v; v >>= 1) t[v] = max(t[v << 1], t[v << 1 | 1]);   }   pair<int, int> query(int l, int r) {     pair<int, int> res = make_pair(-1e9, -1e9);     for (l += sz - 1, r += sz - 1; l <= r; l >>= 1, r >>= 1) {       if (l & 1) res = max(res, t[l]), l++;       if ((r + 1) & 1) res = max(res, t[r]), r--;     }     return res;   }   }  // namespace Segtree   void prework1(int x, int p, int d) {     dep[x] = lvl[x] = d;     for (int(i) = 0; (i) < edge[x].size(); i++) {       pair<int, int> y = edge[x][i];       if (y.first == p) continue;       prework1(y.first, x, d + 1);       if (!son[x] || lvl[y.first] > lvl[son[x]]) son[x] = y.first;       lvl[x] = max(lvl[x], lvl[y.first]);     }   }   void prework2(int x, int p) {     pos[x] = ++k;     if (son[x]) prework2(son[x], x);     for (int(i) = 0; (i) < edge[x].size(); i++) {       pair<int, int> y = edge[x][i];       if (y.first == p || y.first == son[x]) continue;       prework2(y.first, x);     }   }   void work(int x, int p, int cur) {     val[pos[x]] = make_pair(cur, x);     dis[x] = cur;     Segtree::update(pos[x], make_pair(cur, x));     for (int(i) = 0; (i) < edge[x].size(); i++) {       int y = edge[x][i].first;       if (y == son[x]) work(y, x, cur + w[edge[x][i].second]);     }     for (int(i) = 0; (i) < edge[x].size(); i++) {       int y = edge[x][i].first;       if (y == p || y == son[x]) continue;       work(y, x, cur + w[edge[x][i].second]);       int tmp = lvl[y] - dep[y];       for (int(d) = 0; (d) < tmp + 1; d++) {         int ql = max(l - d - 1, 0), qr = min(r - d - 1, lvl[x] - dep[x]);         pair<int, int> val2 = Segtree::query(pos[x] + ql, pos[x] + qr);         if (val[pos[y] + d].first + val2.first - 2 * dis[x] > ans) {           ans = val[pos[y] + d].first + val2.first - 2 * dis[x];           ansu = val[pos[y] + d].second;           ansv = val2.second;         }       }       for (int(d) = 0; (d) < tmp + 1; d++) {         val[pos[x] + d + 1] = max(val[pos[x] + d + 1], val[pos[y] + d]);         Segtree::update(pos[x] + d + 1, val[pos[x] + d + 1]);       }     }     pair<int, int> val2 =         Segtree::query(pos[x] + l, pos[x] + min(r, lvl[x] - dep[x]));     if (val2.first - dis[x] > ans) {       ans = val2.first - dis[x];       ansu = x;       ansv = val2.second;     }   }   bool check(int x) {     for (int(i) = 1; (i) <= n - 1; i++) {       if (oriw[i] < x)         w[i] = -1;       else         w[i] = 1;     }     Segtree::init(n);     for (int(i) = 1; (i) <= n; i++) val[i] = make_pair(-1e9, -1e9);     ans = -1e9;     work(1, 0, 0);     return ans >= 0;   }   int main() {     scanf( %d%d%d , &n, &l, &r);     for (int(i) = 1; (i) <= n - 1; i++) {       int u, v;       scanf( %d%d%d , &u, &v, &oriw[i]);       edge[u].push_back(make_pair(v, i));       edge[v].push_back(make_pair(u, i));       num.push_back(oriw[i]);     }     prework1(1, 0, 0);     prework2(1, 0);     sort(num.begin(), num.end());     num.resize(unique(num.begin(), num.end()) - num.begin());     int l = 0, r = num.size();     while (r - l > 1) {       int mid = (l + r) >> 1;       if (check(num[mid]))         l = mid;       else         r = mid;     }     check(num[l]);     printf( %d %d n , ansu, ansv);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   struct custom_hash {     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return x + FIXED_RANDOM;     }   };   void solve() {     long long n;     cin >> n;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         cout << n / i <<     << n - (n / i) <<   n ;         return;       }     }     cout << 1 <<     << n - 1 <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 200 + 17, inf = 2e18 + 17;   long long a[MAXN], b[MAXN], n, m, k, t[MAXN][MAXN], np;   void fillA() {     for (int i = 1; i <= m; i++)       for (int j = 0; i - j > 0 && j < n; j++) a[i] = min(t[j + 1][i - j], a[i]);     for (int i = 1; i <= n; i++)       for (int j = 0; i + j <= n && j < m; j++)         a[i + m - 1] = min(a[i + m - 1], t[i + j][m - j]);   }   void fillBackT() {     for (int i = 1; i <= m; i++)       for (int j = 0; i - j > 0 && j < n; j++) t[j + 1][i - j] = a[i];     for (int i = 1; i <= n; i++)       for (int j = 0; i + j <= n && j < m; j++) t[i + j][m - j] = a[i + m - 1];   }   long long count(int x) {     a[x] = 0;     long long dp[MAXN][MAXN] = {};     if (a[1] == 1)       dp[1][1] = 0;     else       dp[1][1] = 1;     for (int i = 2; i <= np; i++)       for (int j = 0; j <= np; j++) {         if (a[i] == 1)           dp[i][j] = dp[i - 1][j + 1];         else if (a[i] == 0)           dp[i][j] = (j > 0 ? dp[i - 1][j - 1] : 0);         else           dp[i][j] =               min(inf, (dp[i - 1][j + 1] + (j > 0 ? dp[i - 1][j - 1] : 0)));       }     return dp[np][0];   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> t[i][j];     fill(a, a + MAXN, inf);     fillA();     np = n + m - 1;     iota(b + 1, b + np + 1, 1);     sort(b + 1, b + np + 1, [](int i, int j) { return a[i] < a[j]; });     for (int i = 1; i <= np; i++) {       long long tmp = count(b[i]);       if (tmp >= k)         a[b[i]] = 0;       else {         a[b[i]] = 1;         k -= tmp;       }     }     fillBackT();     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) cout << (t[i][j] ?  )  :  ( );       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int high = 2e5 + 6;   long long cnt[200005], dif[200005];   int main() {     long long n, m, k, i, j, ans, l, r, d, sum = 0, q;     scanf( %lld%lld%lld , &n, &k, &q);     for (i = 0; i < n; i++) {       scanf( %lld%lld , &l, &r);       dif[l]++;       dif[r + 1]--;     }     for (i = 1; i <= high; i++) {       dif[i] += dif[i - 1];     }     for (i = 1; i <= high; i++) {       if (dif[i] >= k) {         cnt[i] = 1;       }     }     for (i = 1; i <= high; i++) {       cnt[i] += cnt[i - 1];     }     while (q--) {       scanf( %lld%lld , &l, &r);       printf( %lld n , cnt[r] - cnt[l - 1]);     }   }


#include <bits/stdc++.h>   const long long int MOD = 1000000007ll;   const int mxsz = 200005;   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     long long int n, m, a;     cin >> n >> m >> a;     int ar1[n + 1], ar2[m + 1];     for (int i = 1; i <= n; i++) {       cin >> ar1[i];     }     for (int i = 1; i <= m; i++) {       cin >> ar2[i];     }     sort(ar1 + 1, ar1 + n + 1);     sort(ar2 + 1, ar2 + m + 1);     vector<long long int> b, p;     for (int i = 1; i <= min(n, m); i++) {       b.push_back(ar1[n - i + 1]);       p.push_back(ar2[i]);     }     int l = 0, r = min(n, m);     int ans = 0;     while (l <= r) {       int mid = (l + r) / 2;       long long int tmp = a;       for (int i = 0; i < mid; i++) {         tmp -= (long long int)max(0LL, p[mid - i - 1] - b[i]);         if (tmp < 0) {           break;         }       }       if (tmp >= 0) {         l = mid + 1;         ans = mid;       } else {         r = mid - 1;       }     }     cout << ans <<    ;     long long int tmp = 0;     for (int i = 0; i < ans; i++) {       tmp += (long long int)p[i];     }     cout << max(0LL, tmp - a);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[1000], y[1000], k, n, m;   bool chck(int xx) {     vector<int> v;     v.push_back(1);     v.push_back(m);     for (int i = 0; i < k; ++i) {       v.push_back(max(1, x[i] - xx));       v.push_back(max(1, x[i] - xx - 1));       v.push_back(min(m, x[i] + xx));       v.push_back(min(m, x[i] + xx + 1));     }     sort(v.begin(), v.end());     int mn = 1e9, mx = -1, tmp, nm, c;     bool l;     vector<pair<int, int> > f;     for (int i = 0; i < v.size(); ++i) {       tmp = v[i];       f.clear();       for (int j = 0; j < k; ++j) {         if (x[j] - xx <= tmp && x[j] + xx >= tmp) {           f.push_back(make_pair(max(1, y[j] - xx), 0));           f.push_back(make_pair(min(n, y[j] + xx), 1));         }       }       sort(f.begin(), f.end());       c = 0;       nm = 0;       l = 0;       for (int j = 0; j < f.size(); ++j) {         if (nm == 0) {           if (f[j].first != c + 1) {             break;           }         }         c = f[j].first;         if (f[j].second == 0)           ++nm;         else           --nm;         if (c == n) {           l = 1;           break;         }       }       if (!l) {         mn = min(mn, tmp);         mx = max(mx, tmp);       }     }     mx = min(mx, m);     mn = max(1, mn);     if (mx - mn + 1 > xx + xx + 1) {       return 0;     }     v.clear();     v.push_back(1);     v.push_back(n);     for (int i = 0; i < k; ++i) {       v.push_back(max(1, y[i] - xx));       v.push_back(max(1, y[i] - xx - 1));       v.push_back(min(n, y[i] + xx));       v.push_back(min(n, y[i] + xx + 1));     }     sort(v.begin(), v.end());     mn = 1e9, mx = -1;     for (int i = 0; i < v.size(); ++i) {       tmp = v[i];       f.clear();       for (int j = 0; j < k; ++j) {         if (y[j] - xx <= tmp && y[j] + xx >= tmp) {           f.push_back(make_pair(max(1, x[j] - xx), 0));           f.push_back(make_pair(min(m, x[j] + xx), 1));         }       }       sort(f.begin(), f.end());       c = 0;       nm = 0;       l = 0;       for (int j = 0; j < f.size(); ++j) {         if (nm == 0) {           if (f[j].first != c + 1) {             break;           }         }         c = f[j].first;         if (f[j].second == 0)           ++nm;         else           --nm;         if (c == m) {           l = 1;           break;         }       }       if (!l) {         mn = min(mn, tmp);         mx = max(mx, tmp);       }     }     mx = min(mx, n);     mn = max(1, mn);     if (mx - mn + 1 > xx + xx + 1) {       return 0;     }     return 1;   }   int main() {     while (cin >> m >> n >> k) {       for (int i = 0; i < k; ++i) {         scanf( %d%d , &x[i], &y[i]);       }       int st = 0, nd = 1e9, md;       while (st < nd) {         md = (st + nd) / 2;         if (chck(md)) {           nd = md;         } else {           st = md + 1;         }       }       printf( %d n , nd);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cansel_sync = (ios::sync_with_stdio(0), cin.tie(0), 0);   const int N = 200010;   const int inf = ~0u >> 2;   const long long INF = ~0ull >> 2;   long long read() {     long long x;     if (scanf( %lld , &x) == -1) exit(0);     return x;   }   const double pi = acos(-1.0);   double readf() {     double x;     if (scanf( %lf , &x) == -1) exit(0);     return x;   }   template <typename T>   T sqr(const T &x) {     return x * x;   }   int mod = (1 ? 1000000007 : 998244353);   long long mul(long long a, long long b, long long m = mod) { return a * b % m; }   long long qpow(long long a, long long b, long long m = mod) {     long long ans = 1;     for (; b; a = mul(a, a, m), b >>= 1)       if (b & 1) ans = mul(ans, a, m);     return ans;   }   long long getinv(long long v, long long m = mod) { return qpow(v, m - 2, m); }   long long n, x, t, l, r, sum;   void solve() {     cin >> n >> x;     sum = 0;     l = inf, r = -inf;     for (long long i = (0), _ = (n); i < _; i++) {       cin >> t;       if (t % x != 0) l = min(l, i), r = max(r, i);       sum += t % x;     }     if (sum % x != 0) {       cout << n << endl;       return;     }     if (l != inf) {       cout << max(n - l - 1, r) << endl;       return;     }     cout << -1 << endl;   }   signed main() {     long long T;     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1E5;   vector<int> vf, vz;   int main() {     ios_base::sync_with_stdio(false);     int n, k, p;     cin >> n >> k >> p;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x % 2 == 0)         vz.push_back(x);       else         vf.push_back(x);     }     int tf = vf.size(), tz = vz.size();     if (tf < (k - p) || p > tz + (tf - (k - p)) / 2 || (k - p) % 2 != tf % 2)       cout <<  NO ;     else {       if ((tf - (k - p)) % 2 == 1) {         cout <<  NO ;       }       if ((tf - (k - p)) % 2 == 0) {         cout <<  YES  << endl;         if (p == 0) {           for (int i = 0; i < k - 1; i++) cout <<  1   << vf[i] << endl;           cout << tf - (k - 1) + tz;           for (int i = k - 1; i < tf; i++) cout <<     << vf[i];           for (int i = 0; i < tz; i++) cout <<     << vz[i];           cout << endl;         } else if (tz >= p) {           for (int i = 0; i < p - 1; i++) cout <<  1   << vz[i] << endl;           cout << tz - p + 1 + tf - (k - p);           for (int i = p - 1; i < tz; i++) cout <<     << vz[i];           for (int i = 0; i < tf - (k - p); i++) cout <<     << vf[i];           cout << endl;           for (int i = tf - (k - p); i < tf; i++) cout <<  1   << vf[i] << endl;         } else {           for (int i = 0; i < tz; i++) cout <<  1   << vz[i] << endl;           for (int i = 0; i < (p - tz) - 1; i++)             cout <<  2   << vf[i * 2] <<     << vf[i * 2 + 1] << endl;           cout << tf - (p - tz - 1) * 2 - (k - p);           for (int i = (p - tz - 1) * 2; i < tf - (k - p); i++)             cout <<     << vf[i];           cout << endl;           for (int i = tf - (k - p); i < tf; i++) cout <<  1   << vf[i] << endl;         }       }     }   }


#include <bits/stdc++.h>   int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};   int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};   using namespace std;   long long power(long long a, long long p, long long M) {     long long r = 1;     a = a % M;     while (p > 0) {       if (p % 2) r = (r * a) % M;       a = (a * a) % M;       p /= 2;     }     return r;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long n, m;   set<long long> e[100005];   stack<long long> cycle, temp;   long long vis[505];   bool found;   void findCycle(long long x) {     temp.push(x);     vis[x] = 1;     for (auto y : e[x]) {       if (vis[y] == 0)         findCycle(y);       else if (vis[y] == 1) {         if (found) return;         cycle = temp;         cycle.push(y);         found = 1;         return;       }     }     if (!temp.empty()) temp.pop();     vis[x] = 2;   }   void fc(long long x) {     vis[x] = 1;     for (auto y : e[x]) {       if (vis[y] == 0)         fc(y);       else if (vis[y] == 1) {         found = 1;         return;       }     }     vis[x] = 2;   }   void solve() {     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long a, b;       scanf( %lld%lld , &a, &b);       e[a].insert(b);     }     for (long long i = 1; i < n + 1; i++) {       if (!vis[i]) {         findCycle(i);         if (found) break;       }     }     if (!found) {       cout <<  YES n ;       return;     }     vector<long long> c;     for (long long i = 0; i < 505; i++) vis[i] = 0;     while (!cycle.empty()) {       c.push_back(cycle.top());       if (vis[cycle.top()]) {         break;       }       vis[cycle.top()] = 1;       cycle.pop();     }     reverse(c.begin(), c.end());     for (long long i = 0; i < c.size() - 1; i++) {       found = 0;       e[c[i]].erase(c[i + 1]);       for (long long j = 0; j < 505; j++) vis[j] = 0;       for (long long j = 1; j < n + 1; j++) {         if (!vis[j]) fc(j);         if (found) {           break;         }       }       if (!found) {         cout <<  YES n ;         return;       }       e[c[i]].insert(c[i + 1]);     }     cout <<  NO n ;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long A, B, N;   long long L, T, M;   bool ok(long long R) {     long long mx = A + (R - 1) * B;     long long mn = A + (L - 1) * B;     long long D = R - L;     if (mx > T) return false;     return (mn * (D + 1) + B * D * (D + 1) / 2) <= T * M;   }   int main(void) {     cin >> A >> B >> N;     while (N--) {       cin >> L >> T >> M;       long long R = L;       long long mn = A + (L - 1) * B;       if (mn > T) {         R = -1;       } else {         long long XR = 1LL << 22;         while (XR > R) {           long long m = (R + XR) / 2;           if (!ok(m))             XR = m;           else             R = m + 1;         }         R -= 1;       }       cout << R <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7, mod = 1e9 + 9, pw = 31;   const double eps = 1e-11;   long long binpow(long long a, long long b) {     long long rec = 1;     while (b) {       if (b % 2 == 1) {         rec *= a;         rec %= INF;       }       a *= a;       a %= INF;       b /= 2;     }     return rec;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int n;     cin >> n;     long long x = binpow(3, n * 3) - binpow(7, n);     if (x < 0) x += INF;     cout << x;     return 0;   }


#include <bits/stdc++.h>   const long long INF64 = 1e18;   using namespace std;   const long long N = 2e5 + 6;   using namespace std;   vector<pair<long long, long long>> pf;   int main() {     long long n, ans = INF64;     cin >> n;     vector<long long> cost(n, 0);     vector<string> s;     for (int i = 0; i < n; i++) cin >> cost[i];     for (int i = 0; i < n; i++) {       string st;       cin >> st;       s.push_back(st);     }     vector<vector<long long>> dp(n, vector<long long>(2, INF64));     dp[n - 1][0] = 0;     dp[n - 1][1] = cost[n - 1];     for (int i = n - 2; i >= 0; i--) {       string currStr(s[i]), currrevStr(s[i]);       string prevStr(s[i + 1]), prevrevStr(s[i + 1]);       reverse(currrevStr.begin(), currrevStr.end());       reverse(prevrevStr.begin(), prevrevStr.end());       if (currStr.compare(prevStr) <= 0) dp[i][0] = min(dp[i][0], dp[i + 1][0]);       if (currStr.compare(prevrevStr) <= 0)         dp[i][0] = min(dp[i][0], dp[i + 1][1]);       if (currrevStr.compare(prevStr) <= 0)         dp[i][1] = min(dp[i][1], dp[i + 1][0] + cost[i]);       if (currrevStr.compare(prevrevStr) <= 0)         dp[i][1] = min(dp[i][1], dp[i + 1][1] + cost[i]);     }     ans = min(ans, min(dp[0][0], dp[0][1]));     if (ans == INF64)       cout << -1;     else       cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100005], n, c, mn[100005], dp[200005], sum;   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> c;     for (int i = 0; i < n; sum += a[i++]) cin >> a[i];     deque<long long> v;     for (int i = n; i--;) {       while (v.size() && v.back() >= i + c) v.pop_back();       while (v.size() && a[i] <= a[v.front()]) v.pop_front();       v.push_front(i);       if (i <= n - c) dp[i] = max(dp[i + 1], a[v.back()] + dp[i + c]);     }     cout << sum - dp[0];   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline T1 max(T1 a, T2 b) {     return a < b ? b : a;   }   template <typename T1, typename T2>   inline T1 min(T1 a, T2 b) {     return a < b ? a : b;   }   const char lf =   n ;   namespace ae86 {   const int bufl = 1 << 15;   char buf[bufl], *s = buf, *t = buf;   inline int fetch() {     if (s == t) {       t = (s = buf) + fread(buf, 1, bufl, stdin);       if (s == t) return EOF;     }     return *s++;   }   inline int ty() {     int a = 0;     int b = 1, c = fetch();     while (!isdigit(c)) b ^= c ==  - , c = fetch();     while (isdigit(c)) a = a * 10 + c - 48, c = fetch();     return b ? a : -a;   }   }  // namespace ae86   using ae86::ty;   const int _ = 100007, __ = _ << 1;   const long long linf = 0x3f3f3f3f3f3f3f3f;   int to[__], ne[__], he[_] = {0}, ecnt = 1;   inline void adde(int a, int b) {     to[++ecnt] = b, ne[ecnt] = he[a], he[a] = ecnt;   }   inline void addde(int a, int b) { adde(a, b), adde(b, a); }   int n, m, qn;   int fa[_] = {0}, dep[_] = {0}, sz[_] = {0}, mxch[_] = {0};   void dfs(int x, int ff) {     fa[x] = ff, dep[x] = dep[ff] + 1, sz[x] = 1, mxch[x] = 0;     for (int i = he[x]; i; i = ne[i]) {       int b = to[i];       if (b == ff) continue;       dfs(b, x), sz[x] += sz[b];       if (sz[mxch[x]] < sz[b]) mxch[x] = b;     }   }   int dfn[_] = {0}, rdfn[_] = {0}, ndf[_] = {0}, top[_] = {0}, dcnt = 0;   void dfs2(int x, int tp) {     dfn[x] = ++dcnt, rdfn[dcnt] = x, top[x] = tp;     if (mxch[x]) dfs2(mxch[x], tp);     for (int i = he[x]; i; i = ne[i]) {       int b = to[i];       if (b == fa[x] || b == mxch[x]) continue;       dfs2(b, b);     }     ndf[x] = dcnt;   }   vector<int> hav[_];   struct cxk {     int x;     long long v;     cxk(int x_ = 0, long long v_ = linf) { x = x_, v = v_; }     friend bool operator<(cxk a, cxk b) {       if (a.v != b.v) return a.v < b.v;       return a.x < b.x;     }   };   const int _t = _ << 2;   cxk t[_t];   long long tadd[_t];   void up(int x) { t[x] = min(t[(x << 1)], t[(x << 1 | 1)]); }   void putadd(int x, long long d) { t[x].v += d, tadd[x] += d; }   void dwn(int x) {     if (tadd[x])       putadd((x << 1), tadd[x]), putadd((x << 1 | 1), tadd[x]), tadd[x] = 0;   }   void plant(int x, int l, int r) {     tadd[x] = 0;     if (l == r) {       t[x] = hav[l].empty() ? cxk() : cxk(l, hav[l].back());       return;     }     plant((x << 1), l, ((l + r) >> 1)),         plant((x << 1 | 1), ((l + r) >> 1) + 1, r), up(x);   }   void change(int x, int l, int r, int tl, int tr, long long dlt) {     if (tl <= l && r <= tr) {       putadd(x, dlt);       return;     }     dwn(x);     if (tl <= ((l + r) >> 1)) change((x << 1), l, ((l + r) >> 1), tl, tr, dlt);     if (tr > ((l + r) >> 1))       change((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr, dlt);     up(x);   }   void dating(int x, int l, int r, int tar) {     if (l == r) {       if (!hav[l].empty()) hav[l].pop_back();       t[x] = hav[l].empty() ? cxk() : cxk(l, hav[l].back() + tadd[x]);       return;     }     dwn(x);     if (tar <= ((l + r) >> 1))       dating((x << 1), l, ((l + r) >> 1), tar);     else       dating((x << 1 | 1), ((l + r) >> 1) + 1, r, tar);     up(x);   }   cxk finder(int x, int l, int r, int tl, int tr) {     if (tl <= l && r <= tr) return t[x];     dwn(x);     if (tr <= ((l + r) >> 1)) return finder((x << 1), l, ((l + r) >> 1), tl, tr);     if (tl > ((l + r) >> 1))       return finder((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr);     return min(finder((x << 1), l, ((l + r) >> 1), tl, tr),                finder((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr));   }   cxk founder(int a, int b) {     cxk ans;     while (top[a] != top[b]) {       if (dep[top[a]] < dep[top[b]]) swap(a, b);       ans = min(ans, finder(1, 1, n, dfn[top[a]], dfn[a])), a = fa[top[a]];     }     if (dep[a] > dep[b]) swap(a, b);     return min(ans, finder(1, 1, n, dfn[a], dfn[b]));   }   int main() {     ios::sync_with_stdio(0), cout.tie(nullptr);     n = ty(), m = ty(), qn = ty();     for (int i = 1, a, b; i < n; i++) a = ty(), b = ty(), addde(a, b);     dfs(1, 0), dfs2(1, 1);     for (int i = 1; i <= m; i++) hav[dfn[ty()]].emplace_back(i);     for (int i = 1; i <= n; i++)       sort(hav[i].begin(), hav[i].end(), greater<int>());     plant(1, 1, n);     for (int qq = 1; qq <= qn; qq++) {       int op = ty();       if (op == 1) {         int a = ty(), b = ty(), lim = ty();         vector<int> ans;         while (lim--) {           int ret = founder(a, b).x;           if (ret <= 0) break;           ans.emplace_back(hav[ret].back()), dating(1, 1, n, ret);         }         cout << ans.size();         for (auto i : ans) cout <<     << i;         cout << lf;       }       if (op == 2) {         int a = ty(), b = ty();         change(1, 1, n, dfn[a], ndf[a], b);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1010;   int n;   int a[MAX], c[MAX];   void init() { cin >> n; }   void process() {     memset(a, 63, sizeof(a));     vector<pair<int, int> > ques;     ques.push_back(make_pair(1, n));     while (!ques.empty()) {       vector<pair<int, int> > newQues;       for (int i = 0; i < ques.size(); i++) {         if (ques[i].first != ques[i].second) {           int l = ques[i].first, r = ques[i].second, mid = (l + r) / 2;           newQues.push_back(make_pair(l, mid));           newQues.push_back(make_pair(mid + 1, r));         }       }       vector<int> b;       for (int i = 0; i < newQues.size(); i += 2) {         for (int j = newQues[i].first; j <= newQues[i].second; j++)           b.push_back(j);       }       if (b.size() > 0) {         cout << b.size() <<   n ;         for (int i = 0; i < b.size(); i++) cout << b[i] <<    ;         cout <<   n ;         fflush(stdout);         for (int i = 1; i <= n; i++) cin >> c[i];         for (int i = 1; i <= n; i++) {           bool check = true;           for (int j = 0; j < b.size(); j++) {             if (b[j] == i) {               check = false;               break;             }           }           if (check) a[i] = min(a[i], c[i]);         }       }       b.resize(0);       for (int i = 1; i < newQues.size(); i += 2) {         for (int j = newQues[i].first; j <= newQues[i].second; j++)           b.push_back(j);       }       if (b.size() > 0) {         cout << b.size() <<   n ;         for (int i = 0; i < b.size(); i++) cout << b[i] <<    ;         cout <<   n ;         fflush(stdout);         for (int i = 1; i <= n; i++) cin >> c[i];         for (int i = 1; i <= n; i++) {           bool check = true;           for (int j = 0; j < b.size(); j++) {             if (b[j] == i) {               check = false;               break;             }           }           if (check) a[i] = min(a[i], c[i]);         }       }       ques = newQues;     }     cout << -1 <<   n ;     for (int i = 1; i <= n; i++) cout << a[i] <<    ;     cout <<   n ;     fflush(stdout);   }   int main() {     ios_base::sync_with_stdio(false);     init();     process();   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300;   long long orign[MAXN], str[2 * MAXN];   int radius[2 * MAXN];   int n, m;   int mp[MAXN][MAXN];   int num[MAXN][26];   long long hashv[MAXN];   long long base[30];   int siz[MAXN];   bool check(int x, int y) {     for (int i = 0; i < 26; i++) {       if (num[x][i] != num[y][i]) return false;     }     return true;   }   void Manacher(int len, int mark = 0) {     for (int i = 0; i < len; i++) {       str[2 * i + 1] = orign[i];       str[2 * i] = mark;     }     str[2 * len] = mark;     len = 2 * len + 1;     int max_right = 0, pos = 0;     for (int i = 0; i < len; i++) {       if (i < max_right)         radius[i] = min(radius[2 * pos - i], max_right - i);       else         radius[i] = 1;       while (i - radius[i] >= 0 && i + radius[i] < len &&              str[i - radius[i]] > -1 && str[i + radius[i]] > -1 &&              check(str[i - radius[i]], str[i + radius[i]])) {         radius[i]++;       }       if (i + radius[i] >= max_right) {         max_right = i + radius[i];         pos = i;       }     }   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     base[0] = 1;     for (int i = 1; i <= 26; i++) base[i] = base[i - 1] * 2;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         char ch;         cin >> ch;         mp[i][j] = ch -  a ;       }     }     long long ans = 0;     for (int l = 1; l <= m; l++) {       memset(num, 0, sizeof(num));       memset(hashv, 0, sizeof(hashv));       memset(siz, 0, sizeof(siz));       for (int r = l; r <= m; r++) {         for (int i = 1; i <= n; i++) {           int id = mp[i][r];           num[i][id]++;           hashv[i] += base[id];           if (num[i][id] & 1)             siz[i]++;           else             siz[i]--;           if (siz[i] > 1)             orign[i - 1] = -i;           else             orign[i - 1] = i;         }         Manacher(n);         for (int i = 0; i < 2 * n + 1; i++) {           if (str[i] > -1) ans += radius[i] / 2;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10000010;   int p[N], num, last[N];   bool flag[N];   int cnt[N], n, m;   void make_prime() {     for (int i = 2; i < N; ++i)       if (!flag[i]) {         p[num++] = i;         last[i] = i;         for (int j = i + i; j < N; j += i) flag[j] = true, last[j] = i;       }   }   int main() {     make_prime();     scanf( %d , &n);     for (int i = 0, x; i < n; ++i) {       scanf( %d , &x);       int s = -1;       while (x != 1) {         if (last[x] != s) cnt[last[x]]++;         s = last[x];         x /= last[x];       }     }     for (int i = 1; i < N; ++i) cnt[i] += cnt[i - 1];     scanf( %d , &m);     for (int i = 0, x, y; i < m; ++i) {       scanf( %d %d , &x, &y);       if (x >= N)         puts( 0 );       else {         y = min(y, N - 1);         printf( %d n , cnt[y] - cnt[x - 1]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int N = 2005;   const int M = 730;   int Head[M * 10], Next[M * 100], vet[M * 100];   int a[N], b[N], d[M * 10], vis[15], p[M][5], dis[M], Dis[M], P[10], len[M],       U[M][12], D[M][12];   int n, cnt, edgenum;   pair<int, int> c[M];   queue<int> q;   inline int F(int x, int y) { return (x - 1) * cnt + y; }   inline void addedge(int u, int v) {     edgenum++;     vet[edgenum] = v;     Next[edgenum] = Head[u];     Head[u] = edgenum;   }   int main() {     scanf( %d , &n);     int ans = INF;     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i], &b[i]);     len[cnt = 1] = 0;     for (int i = 1; i <= 9; i++) {       len[++cnt] = 1;       p[cnt][1] = i;       for (int j = i; j <= 9; j++) {         len[++cnt] = 2;         p[cnt][1] = i, p[cnt][2] = j;         for (int k = j; k <= 9; k++) {           len[++cnt] = 3;           p[cnt][1] = i, p[cnt][2] = j, p[cnt][3] = k;           for (int t = k; t <= 9; t++)             len[++cnt] = 4, p[cnt][1] = i, p[cnt][2] = j, p[cnt][3] = k,             p[cnt][4] = t;         }       }     }     for (int i = 2; i <= cnt; i++) {       memset(vis, 0, sizeof(vis));       for (int j = 1; j <= len[i]; j++) vis[p[i][j]] = 1;       for (int j = 1; j <= 9; j++) {         if (!vis[j]) continue;         int res = j, cur = 0;         for (int k = 1; k <= len[i]; k++)           if (p[i][k] == res)             res = -1;           else             P[++cur] = p[i][k];         for (int k = 1; k <= cnt; k++) {           if (len[k] != cur) continue;           bool flag = 1;           for (int t = 1; t <= cur; t++) flag &= (P[t] == p[k][t]);           if (flag) {             D[i][j] = k;             U[k][j] = i;             break;           }         }       }     }     memset(dis, 0x3f, sizeof(dis));     dis[1] = a[1] - 1;     for (int j = 1; j < 9; j++)       for (int k = 1; k <= cnt; k++)         addedge(F(j, k), F(j + 1, k)), addedge(F(j + 1, k), F(j, k));     for (int j = 1; j <= 9; j++)       for (int k = 1; k <= cnt; k++)         if (D[k][j]) addedge(F(j, k), F(j, D[k][j]));     for (int i = 1; i <= n; i++) {       memset(Dis, 0x3f, sizeof(Dis));       for (int j = 1; j <= cnt; j++)         if (U[j][b[i]]) Dis[U[j][b[i]]] = min(Dis[U[j][b[i]]], dis[j] + 1);       for (int j = 1; j <= cnt; j++) dis[j] = Dis[j];       memset(d, 0x3f, sizeof(d));       for (int j = 1; j <= cnt; j++)         d[F(a[i], j)] = dis[j], c[j] = make_pair(dis[j], j);       sort(c + 1, c + 1 + cnt);       for (int j = 1; j <= cnt; j++)         if (c[j].first != INF) q.push(F(a[i], c[j].second));       while (!q.empty()) {         int u = q.front();         q.pop();         for (int e = Head[u]; e; e = Next[e]) {           int v = vet[e];           if (d[v] > d[u] + 1) d[v] = d[u] + 1, q.push(v);         }       }       if (i == n)         for (int j = 1; j <= 9; j++) ans = min(ans, d[F(j, 1)]);       else         for (int j = 1; j <= cnt; j++) dis[j] = d[F(a[i + 1], j)];     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3003 * 6006;   const int qwq = 303030;   const int inf = 0x3f3f3f3f;   int n, m, k;   int f[N], fa[N], st[123], cnt;   int ans;   int ff[] = {1, 1, 1, 0, -1, -1, -1, 0};   int gg[] = {1, 0, -1, -1, -1, 0, 1, 1};   inline int read() {     int sum = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum * f;   }   inline int dian(int x, int y) {     if (y == 0) y = 2 * m;     if (y == 2 * m + 1) y = 1;     return (x - 1) * (m << 1) + y;   }   int find(int u) {     while (fa[u] != u) u = fa[u];     return u;   }   int Splay(int u) { return fa[u] == u ? u : fa[u] = Splay(fa[u]); }   int main() {     int x, y;     n = read();     m = read();     k = read();     if (m == 1) {       cout << 0;       return 0;     }     for (int i = 1; i <= n * m * 2; i++) fa[i] = i;     while (k--) {       cnt = 0;       x = read();       y = read();       for (int i = 0; i <= 8; i++) {         if (x + ff[i] < 1 || x + ff[i] > n) continue;         int u = dian(x + ff[i], y + gg[i]);         if (!f[u]) continue;         int aa = find(u);         int bb = find(dian(x, y));         if (aa == bb) continue;         st[++cnt] = bb;         fa[bb] = aa;       }       y += m;       for (int i = 0; i < 8; i++) {         if (x + ff[i] < 1 || x + ff[i] > n) continue;         int u = dian(x + ff[i], y + gg[i]);         if (!f[u]) continue;         int aa = find(u);         int bb = find(dian(x, y));         if (aa == bb) continue;         st[++cnt] = bb;         fa[bb] = aa;       }       y -= m;       if (find(dian(x, y)) != find(dian(x, y + m))) {         ans++;         for (int i = 0; i < 8; i++) {           if (x + ff[i] < 1 || x + ff[i] > n) continue;           Splay(dian(x + ff[i], y + gg[i]));         }         y += m;         for (int i = 0; i < 8; i++) {           if (x + ff[i] < 1 || x + ff[i] > n) continue;           Splay(dian(x + ff[i], y + gg[i]));         }         y -= m;         f[dian(x, y)] = f[dian(x, y + m)] = 1;       } else {         for (int i = 1; i <= cnt; i++) fa[st[i]] = st[i];       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, sum;   int main() {     cin >> n;     while (n != 0) {       if (n % 8 == 1) sum++;       n /= 8;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   const int MOD = 1000000007;   bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); }   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};   const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};   int main() {     fastio();     int t = 1;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       int ans = 0;       for (int i = 0; i < (s.length()); i++) {         int x = int(s[i]) - 48;         if (x % 2 == 0) ans += (i + 1);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, int> mp;   int n;   int main() {     scanf( %d , &n);     int t;     long long s = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &t);       s += t;       mp[s]++;     }     int ans = 0;     map<long long, int>::iterator it;     for (it = mp.begin(); it != mp.end(); it++) {       ans = max(ans, it->second);     }     printf( %d n , n - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> edge[100005];   int v[100005];   bool cycle = false;   int mx = -1, last;   void dfs(int u, int dis = 0) {     v[u] = 1;     if (dis > mx) {       mx = dis;       last = u;     }     for (int i = 0; i <= (int)((int)edge[u].size() - 1); i++) {       int first = edge[u][i];       if (!v[first]) dfs(first, dis + 1);     }   }   int main() {     int T, n, m, a, b;     scanf( %d , &n);     scanf( %d , &m);     for (int i = 1; i <= (int)(m); i++) {       scanf( %d%d , &a, &b);       edge[a].push_back(b);       edge[b].push_back(a);     }     dfs(1);     memset(v, 0, sizeof(v));     mx = -1;     dfs(last);     printf( %d , mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   const double EPS = 1e-10;   vector<int> G[50010];   vector<int> chil[50010];   int cnt[50010][510];   void dfs(int pos, int par) {     for (int i = 0; i < (int)G[pos].size(); i++) {       if (G[pos][i] != par) {         chil[pos].push_back(G[pos][i]);         dfs(G[pos][i], pos);       }     }   }   void init(int n) {     memset(cnt, 0, sizeof(cnt));     dfs(0, -1);   }   void calc(int v, int k, long long &sum) {     for (int i = 0; i < (int)chil[v].size(); i++) {       int c = chil[v][i];       calc(c, k, sum);       for (int j = 0; j < k; j++) {         sum += (long long)cnt[c][j] * cnt[v][k - j - 1];       }       for (int j = 0; j < k; j++) {         cnt[v][j + 1] += cnt[c][j];       }     }     cnt[v][0] = 1;     sum += (long long)cnt[v][0] * cnt[v][k];   }   int main() {     int n, k, a, b;     cin >> n >> k;     for (int i = 0; i < n - 1; i++) {       cin >> a >> b;       a--, b--;       G[a].push_back(b);       G[b].push_back(a);     }     init(n);     long long res = 0;     calc(0, k, res);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct P {     int x, y;     bool operator<(const P &p) {       if (x != p.x)         return x < p.x;       else         return y < p.y;     }   };   int main() {     int T;     cin >> T;     for (int t = 0; t < T; ++t) {       int n;       cin >> n;       int bsz = n / 3;       vector<int> buf(bsz);       for (int i = 0; i < n / 3; ++i) {         cout <<  ?   << 3 * i + 1 <<     << 3 * i + 2 <<     << 3 * i + 3 << endl;         cout.flush();         cin >> buf[i];         if (buf[i] == -1) {           break;         }       }       int ind0, ind1;       for (int i = 0; i < bsz; ++i) {         int indl = i;         int indr = (i + 1) % bsz;         if (buf[indl] != buf[indr]) {           vector<int> tbuf(6);           tbuf[0] = buf[indl];           for (int j = 1; j <= 5; ++j) {             int v1 = (3 * indl + j) % n + 1;             int v2 = (3 * indl + j + 1) % n + 1;             int v3 = (3 * indl + j + 2) % n + 1;             cout <<  ?   << v1 <<     << v2 <<     << v3 << endl;             cout.flush();             cin >> tbuf[j];             if (tbuf[j] == -1) {               break;             }             if (tbuf[j - 1] != tbuf[j]) {               if (tbuf[j - 1] == 0) {                 ind0 = (3 * indl + j - 1) % n + 1;                 ind1 = v3;               } else {                 ind1 = (3 * indl + j - 1) % n + 1;                 ind0 = v3;               }               break;             }           }           break;         }       }       vector<int> mapping(n);       mapping[ind1 - 1] = 1;       int tmp;       for (int i = 0; i < bsz; ++i) {         int v1 = 3 * i + 1;         int v2 = 3 * i + 2;         int v3 = 3 * i + 3;         if (buf[i] == 0) {           if (v1 == ind1) {             cout <<  ?   << ind1 <<     << ind0 <<     << v2 << endl;           } else if (v2 == ind1) {             cout <<  ?   << ind1 <<     << v1 <<     << ind0 << endl;           } else {             cout <<  ?   << ind1 <<     << v1 <<     << v2 << endl;           }           cout.flush();           cin >> tmp;           if (tmp == 0) {             mapping[v1 - 1] = 0;             mapping[v2 - 1] = 0;             if (v3 == ind0) {               tmp = 0;             } else if (v3 == ind1) {               tmp = 1;             } else {               cout <<  ?   << ind0 <<     << ind1 <<     << v3 << endl;               cout.flush();               cin >> tmp;             }             mapping[v3 - 1] = tmp;           } else {             mapping[v3 - 1] = 0;             if (ind0 == v1) {               tmp = 0;             } else if (ind1 == v1) {               tmp = 1;             } else {               cout <<  ?   << ind0 <<     << ind1 <<     << v1 << endl;               cout.flush();               cin >> tmp;             }             mapping[v1 - 1] = tmp;             mapping[v2 - 1] = 1 - tmp;           }         } else {           if (v1 == ind0) {             cout <<  ?   << ind0 <<     << ind1 <<     << v2 << endl;           } else if (v2 == ind0) {             cout <<  ?   << ind0 <<     << v1 <<     << ind1 << endl;           } else {             cout <<  ?   << ind0 <<     << v1 <<     << v2 << endl;           }           cout.flush();           cin >> tmp;           if (tmp == 1) {             mapping[v1 - 1] = 1;             mapping[v2 - 1] = 1;             if (v3 == ind0) {               tmp = 0;             } else if (v3 == ind1) {               tmp = 1;             } else {               cout <<  ?   << ind0 <<     << ind1 <<     << v3 << endl;               cout.flush();               cin >> tmp;             }             mapping[v3 - 1] = tmp;           } else {             mapping[v3 - 1] = 1;             if (v1 == ind0) {               tmp = 0;             } else if (v1 == ind1) {               tmp = 1;             } else {               cout <<  ?   << ind0 <<     << ind1 <<     << v1 << endl;               cout.flush();               cin >> tmp;             }             mapping[v1 - 1] = tmp;             mapping[v2 - 1] = 1 - tmp;           }         }       }       vector<int> fake;       for (int i = 0; i < n; ++i) {         if (mapping[i] == 0) {           fake.push_back(i + 1);         }       }       cout <<  !   << fake.size();       for (int i = 0; i < fake.size(); ++i) {         cout <<     << fake[i];       }       cout << endl;       cout.flush();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, a, b, c, d;     scanf( %d%d%d%d%d%d , &n, &k, &a, &b, &c, &d);     if (n <= 4 || k < n + 1) {       puts( -1 );       return 0;     }     printf( %d %d , a, c);     for (int i = 1; i <= n; i++) {       if (i != a && i != b && i != c && i != d) printf(  %d , i);     }     printf(  %d %d n , d, b);     printf( %d %d , c, a);     for (int i = 1; i <= n; i++) {       if (i != a && i != b && i != c && i != d) printf(  %d , i);     }     printf(  %d %d n , b, d);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 2e5 + 10;   const long long inf = 1e18;   const int maxm = 1005;   vector<vector<char>> matrix(maxm, vector<char>(maxm));   struct event {     int x, y, size;   };   int dx[] = {0, 0, 1, -1};   int dy[] = {-1, 1, 0, 0};   class even {    public:     int a, b, c;   };   class evenl {    public:     int a, b, c, ind;   };   struct myComp {     constexpr bool operator()(evenl f, evenl s) const noexcept {       int z = f.b - f.a;       int z2 = s.b - s.a;       z -= f.c;       z2 -= s.c;       return z < z2;     }   };   long long poww(long long a, long long b, long long m) {     if (b == 0) return 1ll;     if (b % 2 == 1) return a * poww(a, b - 1, m) % m;     long long rs = poww(a, b / 2, m);     rs = rs * rs % m;     return rs;   }   long long fact[N];   long long ncr(long long n, long long r) {     long long num = fact[n];     long long deno = fact[n - r] * fact[r] % mod;     deno = poww(deno, mod - 2, mod);     num = num * deno;     num = num % mod;     return num;   }   long long convert(long long a, long long b) {     string s;     while (a > 0) {       long long p = a % b;       s += p +  0 ;       a = a / b;     }     reverse(s.begin(), s.end());     long long res = stoi(s);     return res;   }   long long make(long long a, long long b, long long c) {     while (a < b) a *= c;     return a % b;   }   long long frog_jump(long long pos, long long n) {     while (pos % 2 == 0) {       pos = pos + (n - pos / 2);     }     return (pos + 1) / 2;   }   void solve() {     long long n, q;     cin >> n >> q;     for (int i = 0; i < q; i++) {       long long x;       cin >> x;       if (x % 2 != 0) {         cout << (x + 1) / 2 <<   n ;         continue;       }       long long z = frog_jump(x, n);       cout << z <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   double aa[12];   int sign[12];   int compare(const void *a, const void *b) {     int i = *(int *)a;     int j = *(int *)b;     if (sign[i] != sign[j]) return sign[j] - sign[i];     if (sign[i] == 0) return i - j;     return aa[i] == aa[j] ? i - j : aa[i] > aa[j] ? -sign[i] : sign[i];   }   void power(int i, double x, double y, double z) {     if (x == 1)       sign[i] = 0;     else if (x > 1) {       sign[i] = 1;       aa[i] = z * log(y) + log(log(x));     } else {       sign[i] = -1;       aa[i] = z * log(y) + log(-log(x));     }   }   void power_(int i, double x, double yz) {     if (x == 1)       sign[i] = 0;     else if (x > 1) {       sign[i] = 1;       aa[i] = log(yz) + log(log(x));     } else {       sign[i] = -1;       aa[i] = log(yz) + log(-log(x));     }   }   int main() {     static char ss[12][16] = { x^y^z ,  x^z^y ,  (x^y)^z ,  (x^z)^y ,                                y^x^z ,  y^z^x ,  (y^x)^z ,  (y^z)^x ,                                z^x^y ,  z^y^x ,  (z^x)^y ,  (z^y)^x };     static int ii[12];     double x, y, z;     int i;     scanf( %lf%lf%lf , &x, &y, &z);     power(0, x, y, z);     power(1, x, z, y);     power_(2, x, y * z);     power_(3, x, y * z);     power(4, y, x, z);     power(5, y, z, x);     power_(6, y, x * z);     power_(7, y, x * z);     power(8, z, x, y);     power(9, z, y, x);     power_(10, z, x * y);     power_(11, z, x * y);     for (i = 0; i < 12; i++) ii[i] = i;     qsort(ii, 12, sizeof *ii, compare);     printf( %s n , ss[ii[0]]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, m;     cin >> n >> m;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     vector<int> rightInc(n), leftInc(n);     int end = 0, cur_count = 1;     for (int i = 0; i < n; ++i) {       if (end < i) {         end = i, cur_count = 1;       }       while (end + 1 < n && a[end + 1] >= a[end]) {         end++, cur_count++;       }       rightInc[i] = end - i + 1, cur_count--;     }     reverse(a.begin(), a.end());     end = 0, cur_count = 1;     for (int i = 0; i < n; ++i) {       if (end < i) {         end = i, cur_count = 1;       }       while (end + 1 < n && a[end + 1] >= a[end]) {         end++, cur_count++;       }       leftInc[i] = end - i + 1, cur_count--;     }     reverse(leftInc.begin(), leftInc.end());     while (m--) {       int l, r;       cin >> l >> r;       --l, --r;       if (rightInc[l] + leftInc[r] >= r - l + 1)         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e6 + 7;   const int INF = 0x7fffffff;   int n, m;   struct DATA {     int strid;     int index;   };   vector<DATA> vec;   string str[maxn];   char ans[maxn];   bool cmp(DATA a, DATA b) { return a.index < b.index; }   int main() {     while (cin >> n) {       memset(ans, 0, sizeof(ans));       vec.clear();       for (int i = 0; i < n; i++) {         int num;         cin >> str[i];         scanf( %d , &num);         for (int j = 0; j < num; j++) {           int k;           scanf( %d , &k);           k--;           DATA t;           t.strid = i;           t.index = k;           vec.push_back(t);         }       }       int last = -1;       sort(vec.begin(), vec.end(), cmp);       for (int i = 0; i < vec.size(); i++) {         for (int j = max(last + 1, vec[i].index);              j < vec[i].index + str[vec[i].strid].size(); j++) {           ans[j] = str[vec[i].strid][j - vec[i].index];           last = max(last, j);         }       }       for (int i = 0; i <= last; i++) {         if (ans[i] != 0)           printf( %c , ans[i]);         else {           printf( a );         }       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     long long int arr[100];     for (int i = 0; i < n; i++) cin >> arr[i];     long long int cnt[5];     long long int p[5];     for (int i = 0; i < 5; i++) cin >> p[i];     long long int min = 1000000009;     for (int i = 0; i < 5; i++)       if (p[i] < min) min = p[i];     for (int i = 0; i < 5; i++) cnt[i] = 0;     long long int ps = 0;     for (int i = 0; i < n; i++) {       ps = ps + arr[i];       while (ps >= min) {         long long int pp;         for (int j = 4; j >= 0; j--) {           if (ps < min) break;           pp = ps / p[j];           ps = ps - pp * p[j];           cnt[j] += pp;         }       }     }     for (int i = 0; i < 5; i++) cout << cnt[i] <<    ;     cout <<   n  << ps << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, m, cap, lis[200500], high, low;   long long f(long long x) {     long long res = 0, cnt = 0, buf = 0;     for (int i = (0); i <= ((int)(n)-1); i++)       if (lis[i] <= x) {         if (!cnt) {           res += buf;           buf = 0;         }         cnt++;         buf += lis[i];         res += lis[i];         if (cnt == m) {           cnt = 0;         }       }     return res;   }   long long g(long long x) {     long long res = 0, task = 0, cnt = 0, buf = 0;     for (int i = (0); i <= ((int)(n)-1); i++)       if (lis[i] <= x) {         if (!cnt) {           res += buf;           buf = 0;         }         if (res + lis[i] > cap) break;         res += lis[i];         cnt++;         buf += lis[i];         task++;         if (cnt == m) {           cnt = 0;         }       }     return task;   }   int main() {     ios::sync_with_stdio(0);     cin >> t;     while (t--) {       cin >> n >> m >> cap;       for (int i = (0); i <= ((int)(n)-1); i++) cin >> lis[i];       high = cap, low = 1;       while (high > low) {         long long chs = (high + low) / 2;         if (f(chs) > cap)           high = chs;         else           low = chs + 1;       }       long long gh = g(high), gh1 = g(high - 1);       if (gh > gh1 || high == 1)         cout << gh <<     << high << endl;       else         cout << gh1 <<     << high - 1 << endl;     }   }


#include <bits/stdc++.h>   const long long int MOD = 1e9 + 7;   const long long int INF = 1011111111;   const long long int LLINF = 1000111000111000111LL;   const long double EPS = 1e-10;   const long double PI = 3.14159265358979323;   using namespace std;   long long int power(int x, int n) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return power((x * x), n / 2);     else       return x * power((x * x), (n - 1) / 2);   }   long long int dp[5005][5005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m, i, j, k;     cin >> n >> k;     vector<long long int> v(n);     for (i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     vector<pair<pair<long long int, long long int>, long long int> > check;     vector<long long int>::iterator it;     for (i = 0; i < n; i++) {       long long int idx;       it = upper_bound(v.begin(), v.end(), v[i] + 5);       if (it == v.end())         idx = n - 1;       else {         idx = it - v.begin();         idx--;       }       check.push_back({{i, idx}, idx - i + 1});     }     long long int ans = 0;     for (i = 0; i < n; i++) {       for (j = 0; j <= k; j++) {         dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);         if (j + 1 <= k)           dp[i + check[i].second][j + 1] =               max(dp[i + check[i].second][j + 1], dp[i][j] + check[i].second);       }     }     cout << dp[n][k];   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, oo = 0x3f3f3f3f, mod = 1e9 + 7;   int a[N], n, tree[N], srt[N], ans[N];   void update(int a, int val) {     while (a <= n) {       tree[a] = max(val, tree[a]);       a += a & -a;     }   }   int query(int a) {     int mx = 0;     while (a > 0) {       mx = max(tree[a], mx);       a -= a & -a;     }     return mx;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       srt[i] = a[i];     }     sort(srt + 1, srt + n + 1);     for (int i = n; i >= 1; i--) {       int idx = lower_bound(srt + 1, srt + n + 1, a[i]) - srt;       update(idx, i);       ans[i] = query(idx - 1);       if (ans[i] == 0)         ans[i]--;       else         ans[i] -= i + 1;     }     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 9;   int n, maxx;   struct p {     int lei, num, x;   } a[maxn];   int da[maxn], b[maxn], vis[maxn];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> b[i];     int w;     cin >> w;     for (int i = 1; i <= w; i++) {       cin >> a[i].lei;       if (a[i].lei == 1) {         cin >> a[i].num >> a[i].x;         vis[a[i].num] = i;         b[a[i].num] = a[i].x;       } else {         cin >> a[i].x;         maxx = max(maxx, a[i].x);       }     }     for (int i = w; i >= 1; i--) {       if (a[i].lei == 1)         da[i] = da[i + 1];       else         da[i] = max(da[i + 1], a[i].x);     }     for (int i = 1; i <= n; i++) {       if (vis[i] == 0)         cout << max(b[i], maxx) <<    ;       else {         int xu = vis[i];         cout << max(b[i], da[xu]) <<    ;       }     }   }


#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const int N = 579;   const long long P = 1000000007;   int n, b[N];   long long d[N][N];   long long solve(int l, int r) {     if (l == r) return 1;     static bool used[N][N];     static long long ans[N][N];     if (used[l][r]) return ans[l][r];     used[l][r] = true;     ++l;     ++r;     d[l][0] = 1;     for (int i = 0; i < r - l; ++i) {       if (d[l][i + 1] != -1) continue;       int c = l + i;       d[l][i + 1] = 0;       for (int j = 0; j <= i; ++j)         if (b[j + l] < b[c + 1]) (d[l][i + 1] += d[l][j] * solve(j + l, c)) %= P;     }     long long res = 0;     for (int j = 0; j <= r - l - 1; ++j)       (res += d[l][j] * solve(j + l, r - 1)) %= P;     --l;     --r;     return ans[l][r] = res;   }   int main() {     memset(d, -1, sizeof(d));     std::cin >> n;     for (int i = 0; i < n; ++i) std::cin >> b[i];     if (b[0] == 1)       std::cout << solve(0, n - 1) <<   n ;     else       std::cout << 0 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[4];     for (int i = 0; i < 4; i++) cin >> a[i];     int sumtotal = a[0] + a[1] + a[2] + a[3];     if (sumtotal % 2 != 0) {       cout <<  NO ;       return 0;     }     for (int i = 0; i < 4; i++) {       if (a[i] == sumtotal - a[i]) {         cout <<  YES ;         return 0;       } else         for (int j = 0; j < 4; j++) {           if (i != j)             if ((a[i] + a[j]) == (sumtotal - a[i] - a[j])) {               cout <<  YES ;               return 0;             }         }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, double>> ans[52];   int main() {     int n, w, m;     cin >> n >> w >> m;     double s = (n * w) / (m * 1.0), c = w, b = 1, k = 0;     for (int i = 0; i < m; i++) {       double ne = s;       while (1) {         if (ne + 10e-7 > c) {           ans[i].push_back(make_pair(b, c));           ne -= c;           c = w;           b++;           if (++k > 2) {             cout <<  NO ;             return 0;           }           k = 0;           if (abs(ne) < 10e-7) break;         } else {           ans[i].push_back(make_pair(b, ne));           c -= ne;           k++;           break;         }       }     }     cout <<  YES n ;     for (int i = 0; i < m; i++) {       for (auto it : ans[i])         cout << fixed << setprecision(0) << it.first <<     << setprecision(6)              << it.second <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void quickly_quickly_kro() {     long long n;     cin >> n;     vector<long long> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     ;     map<long long, long long> M, N, I;     for (long long i = 0; i < n; i++) {       if (v[i] != 0)         M[v[i]]++;       else         I[i]++;     }     for (long long i = 1; i < n + 1; i++) {       if (M[i] == 0) {         N[i]++;       }     }     for (auto k : I) {       if ((N.find(k.first + 1) != N.end())) {         auto it = N.find(k.first + 1);         if (it != N.begin())           it--;         else           it++;         v[k.first] = it->first;         N.erase(it);       }     }     for (long long i = 0; i < n; i++) {       if (v[i] == 0) {         auto it = N.begin();         pair<long long, long long> p = *it;         v[i] = p.first;         N.erase(it);       }     }     for (long long i = 0; i < n; i++) cout << v[i] <<    ;   }   signed main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) {       quickly_quickly_kro();       cout <<   n ;       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct HashMap {     vector<pair<int, int> > g[1000007];     void ins(int x, int y) {       int id = ((long long)x * 1000000007 + y) % 1000007;       g[id].push_back(make_pair(x, y));     }     bool get(int x, int y) {       int id = ((long long)x * 1000000007 + y) % 1000007;       for (int i = 0; i < g[id].size(); i++)         if (g[id][i].first == x && g[id][i].second == y) return true;       return false;     }   };   int n;   HashMap mp;   vector<int> row[100011];   vector<int> rateB;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       row[y].push_back(x);       mp.ins(x, y);     }     int di = (int)sqrt(n);     long long int ans = 0;     for (int a = 0; a <= 100000; a++) {       if (row[a].size() != 0) {         sort(row[a].begin(), row[a].end());         if (row[a].size() <= di) {           for (int i = 0; i < row[a].size(); i++) {             for (int j = i + 1; j < row[a].size(); j++) {               int x1 = row[a][i];               int x2 = row[a][j];               int dis = x2 - x1;               if (mp.get(x1, a + dis) && mp.get(x2, a + dis)) ans++;               if (a - dis >= 0 && row[a - dis].size() > di &&                   (mp.get(x1, a - dis) && mp.get(x2, a - dis)))                 ans++;             }           }         } else           rateB.push_back(a);       }     }     for (int i = 0; i < rateB.size(); i++) {       for (int j = i + 1; j < rateB.size(); j++) {         int a = rateB[i];         int b = rateB[j];         int u = 0, p = 0;         int dis = b - a;         while (u < row[a].size() && p < row[b].size()) {           if (row[a][u] < row[b][p])             u++;           else if (row[a][u] > row[b][p])             p++;           else {             int x1 = row[a][u];             if (mp.get(x1 + dis, a) && mp.get(x1 + dis, b)) ans++;             u++;             p++;           }         }       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1.01e9;   const double eps = 1e-9;   const int maxn = (int)2e5 + 10;   set<int> S;   int main() {     int n, k, a;     scanf( %d%d%d , &n, &k, &a);     int cur = (n + 1) / (a + 1);     assert(cur >= k);     int m;     scanf( %d , &m);     for (int i = 0; (i) < (m); ++i) {       int x;       scanf( %d , &x);       set<int>::iterator it = S.lower_bound(x);       int left = 0;       int right = n + 1;       if (it != S.end()) {         right = *it;       }       if (it != S.begin()) {         --it;         left = *it;       }       cur -= (right - left) / (a + 1);       cur += (x - left) / (a + 1);       cur += (right - x) / (a + 1);       if (cur < k) {         printf( %d n , i + 1);         return 0;       }       S.insert(x);     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Segment {     int l, r, x, ls, rs, fa;   } seg[2000100];   int n, k, p[100100], cnt, pnt, b[2000100], w, ans[100100], res;   int Dfs(int &id, int l, int r) {     id = ++cnt;     seg[id].l = l, seg[id].r = r;     seg[id].x = 1;     if (r - l == 1) return 1;     int mid = (l + r) >> 1;     seg[id].x += Dfs(seg[id].ls, l, mid);     seg[id].x += Dfs(seg[id].rs, mid, r);     return seg[id].x;   }   void Vis(int x) {     if (!x) return;     b[x] = 1;     Vis(seg[x].ls);     Vis(seg[x].rs);   }   bool cmp(int x, int y) { return seg[x].l < seg[y].l; }   void Solve(int x) {     if (!x) return;     if (b[x]) {       for (int i = seg[x].l; i < seg[x].r; i++) ans[i] = res++;       return;     }     Solve(seg[x].rs);     Solve(seg[x].ls);   }   int main() {     scanf( %d%d , &n, &k);     Dfs(w, 0, n);     k = seg[1].x - k;     for (int i = 1; i <= cnt; i++)       if (!b[i]) {         if (k >= seg[i].x - 1 && seg[i].x > 1) {           k -= seg[i].x - 1;           p[++pnt] = i;           Vis(i);           if (!k) break;         }       }     if (k)       printf( -1 );     else {       res = 1;       Solve(1);       for (int i = n - 1; i >= 0; i--) ans[i] = ans[i] ? ans[i] : res++;       for (int i = 0; i < n; i++) printf( %d  , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s[1100];   int vis[1100];   int num[100];   int main() {     ios::sync_with_stdio(false);     int n, len, k;     cin >> n >> len >> k;     string st;     cin >> st;     for (int i = 0; i < st.size(); i++) {       num[st[i] -  a ]++;     }     int l = 0, r = 25;     for (int i = k + 1; i <= n; i++) {       for (int j = 1; j <= len; j++) {         while (!num[r] && r > l) r--;         s[i] += (char)(r +  a );         num[r]--;       }     }     int now = 0;     int pos = 0;     while (1) {       for (int i = 1; i <= k; i++) {         if (vis[i]) continue;         if (pos >= 1 && i != k && (int)(s[i][pos - 1] -  a ) < now) {           for (int j = pos + 1; j <= len; j++) {             while (!num[r] && r > l) r--;             s[i] += (char)(r +  a );             num[r]--;           }           vis[i] = 1;           continue;         }         while (!num[l] && r > l) l++;         s[i] += (char)(l +  a );         num[l]--;         if (i == k) {           now = l;         }       }       pos++;       if (pos == len) break;     }     sort(s + 1, s + 1 + n);     for (int i = 1; i <= n; i++) cout << s[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T, n, m, nw, a[110][110], id[110][110], pos[110], p[110];   char ch;   bool cmp(int i, int j) { return a[m][i] < a[m][j]; }   queue<int> q;   void find(int x) {     p[x] = 0;     int y = id[x][pos[x]];     pos[x]--;     if (!p[y])       p[y] = x, p[x] = y;     else if (a[y][x] > a[y][p[y]]) {       p[p[y]] = 0, q.push(p[y]);       p[y] = x, p[x] = y;     }     if (!p[x]) q.push(x);   }   void work() {     for (int i = 1; i <= 2 * n; i++) {       for (int j = 1; j <= n; j++) id[i][j] = (i <= n) * n + j;       m = i;       sort(id[i] + 1, id[i] + n + 1, cmp);       p[i] = 0;     }     for (int i = 1; i <= n; i++) pos[i] = n, q.push(i);     while (!q.empty()) {       int u = q.front();       q.pop();       find(u);     }     for (int i = 1; i <= n; i++) assert(p[i]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         assert(!(a[p[i]][i] < a[p[i]][j] && a[j][p[i]] > a[j][p[j]]));   }   void solve() {     bool falg = 0;     scanf( %d , &n);     memset(a, 0, sizeof(a)), memset(id, 0, sizeof(id));     for (int i = 1; i <= n; i++)       for (int j = n + 1; j <= 2 * n; j++)         scanf( %d , &a[i][j]), a[j][i] = -a[i][j];     puts( B ), fflush(stdout);     scanf(  %c%d , &ch, &nw);     if (ch ==  I ) falg ^= 1;     if (nw > n) falg ^= 1;     if (falg)       for (int i = 1; i <= 2 * n; i++)         for (int j = 1; j <= 2 * n; j++) a[i][j] = -a[i][j];     work();     printf( %d n , p[nw]), fflush(stdout);     while (~scanf( %d , &nw)) {       if (nw == -1) return;       printf( %d n , p[nw]), fflush(stdout);     }   }   int main() {     scanf( %d , &T);     while (T--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 9;   vector<int> getBorder(const string str) {     int n = str.size();     vector<int> border(n, -1);     for (int i = 1, j = -1; i < n; i++) {       while (j >= 0 && str[i] != str[j + 1]) {         j = border[j];       }       if (str[i] == str[j + 1]) j++;       border[i] = j;     }     return border;   }   int matchPattern(string txt, string pat, const vector<int> border) {     int freq = 0;     for (int i = 0, j = -1; i < (int)txt.size(); i++) {       while (j >= 0 && txt[i] != pat[j + 1]) {         j = border[j];       }       if (txt[i] == pat[j + 1]) {         j++;       }       if (j + 1 == (int)pat.size()) {         freq++;         j = border[j];       }     }     return freq;   }   string cut(string s, int p, bool pref = true) {     if (!pref) {       reverse(s.begin(), s.end());     }     while ((int)s.size() >= p) s.pop_back();     if (!pref) {       reverse(s.begin(), s.end());     }     return s;   }   const int ms = 210;   string pref[ms], suf[ms];   long long trans[ms];   int bk = 14;   long long getFreq(int n, string pat, long long k) {     std::vector<long long> f(n + 1, 0);     if (pat ==  0 ) f[0]++;     if (pat ==  1 ) f[1]++;     auto border = getBorder(pat);     for (int i = 2; i <= n; i++) {       long long cur = trans[i - 2];       if (i < bk + 4) {         string curString = cut(suf[i - 2], (int)pat.size(), false) +                            cut(pref[i - 1], (int)pat.size());         cur = matchPattern(curString, pat, border);       }       f[i] = f[i - 1] + f[i - 2] + cur;       if (f[i] > k) return k + 1;       trans[i] = cur;     }     return min(f[n], k + 1);   }   int main() {     pref[0] = suf[0] =  0 ;     pref[1] = suf[1] =  1 ;     for (int i = 2; i < ms; i++) {       pref[i] = cut(pref[i - 2] + pref[i - 1], ms);       suf[i] = cut(suf[i - 2] + suf[i - 1], ms, false);     }     int n, m;     long long k;     cin >> n >> k >> m;     if (n == 0) {       cout <<  0 n ;       return 0;     }     if (n == 1) {       cout <<  1 n ;       return 0;     }     string ans;     k--;     while (k >= 0 && (int)ans.size() < m) {       if (ans.size() > 0 &&           suf[n].substr(suf[n].size() - ans.size(), ans.size()) == ans) {         k--;       }       if (k < 0) break;       ans +=  0 ;       long long got = getFreq(n, ans, k);       if (got <= k) {         ans.back() =  1 ;         k -= got;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int tag[10];   int main() {     string a, b;     while (cin >> a >> b) {       memset(tag, 0, sizeof(tag));       ;       int len = a.size();       int len1 = b.size();       for (int i = 0; i < len1; i++) {         int num = b[i] -  0 ;         tag[num]++;       }       for (int i = 0; i < len; i++) {         int p = a[i] -  0 ;         int j = 9;         while (j > p) {           if (!tag[j]) j--;           if (tag[j] && j > p) {             a[i] = j +  0 ;             tag[j]--;             break;           }         }       }       for (int i = 0; i < len; i++) cout << a[i];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   int n, k;   bool d[1001];   long long dp[1001][2][1001];   int cnt[10001];   long long DP(int i, bool f, int j) {     if (i == n) return cnt[j] == k;     if (dp[i][f][j] != -1) return dp[i][f][j];     long long ret = 0;     if (d[i] == 1)       ret = (ret + DP(i + 1, f, j + 1)) % mod;     else if (d[i] == 0 and f)       ret = (ret + DP(i + 1, f, j + 1)) % mod;     ret = (ret + DP(i + 1, f | (d[i] == 1), j)) % mod;     return dp[i][f][j] = ret;   }   int main() {     for (int i = 1; i <= 1000; i++) {       cnt[i] = 1 + cnt[__builtin_popcount(i)];     }     string s;     cin >> s;     n = s.size();     cin >> k;     int i = 0;     for (char c : s) d[i++] = c -  0 ;     memset(dp, -1, sizeof dp);     cout << DP(0, 0, 0) - (k == 1);   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1e18, N = 2e6 + 3, BASE = 130;   int main() {     long long int n, k;     cin >> n >> k;     vector<int> arr(n), up(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = n - 2; i >= 0; i--) {       if (arr[i + 1] == 1) {         up[i] = up[i + 1] + 1;       } else {         up[i] = 0;       }     }     long long int ans = 0;     for (int i = 0; i < n; i++) {       int ind = i;       long long int p = 1;       long long int sum = 0;       int cnt = 0;       while (ind < n && cnt <= 20) {         if (p > INF / arr[ind]) {           break;         }         p *= arr[ind];         sum += arr[ind];         cnt++;         if (p % sum == 0 && p / sum == k) {           ans++;         }         if (up[ind]) {           if (p % k == 0) {             long long int num = p / k;             if (sum + 1 <= num && num <= sum + up[ind]) {               ans++;             }           }         }         sum += up[ind];         ind = ind + 1 + up[ind];       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   void PLAY() {     cout << fixed << setprecision(10);     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     vector<string> x(n), y(m), ans;     for (int i = 0; i < n; i++) {       cin >> x[i];     }     for (int i = 0; i < m; i++) {       cin >> y[i];     }     long long q;     cin >> q;     while (q--) {       long long a;       cin >> a;       a--;       cout << x[a % n] + y[a % m] << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:64000000 )   using namespace std;   const double PI = 2 * acos(0.0);   const double eps = 1e-9;   template <class T>   T jog(T a, T b) {     return a + b;   }   template <class T>   T bog(T a, T b) {     return a - b;   }   template <class T>   T gon(T a, T b) {     return a * b;   }   template <class T>   T sq(T x) {     return x * x;   }   template <class T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd(a, b)) * b;   }   template <class T>   T power(T a, T p) {     T res = 1, x = a;     while (p) {       if (p & 1) res = res * x;       x = x * x;       p >>= 1;     }     return res;   }   template <class T>   T cordinatlenth(T a, T b, T c, T d) {     return sqrt(sq(a - c) + sq(b - d));   }   template <class T>   string toString(T n) {     ostringstream oss;     oss << n;     oss.flush();     return oss.str();   }   int toInt(string s) {     int r = 0;     istringstream sin(s);     sin >> r;     return r;   }   long long bigmod(long long a, long long p, long long mod) {     long long res = 1, x = a;     while (p) {       if (p & 1) res = (res * x) % mod;       x = (x * x) % mod;       p >>= 1;     }     return res;   }   int diraction1[] = {-1, 0, 0, 1, 1, -1, -1, 1};   int diraction2[] = {0, -1, 1, 0, 1, -1, 1, -1};   int horsed1[] = {-2, -2, -1, 1, 2, 2, 1, -1};   int horsed2[] = {1, -1, -2, -2, -1, 1, 2, 2};   void input();   const int INF = 2147483647;   const long long LINF = 9223372036854775807ll;   int n, in[1000010];   int main() {     input();     return 0;   }   void input() {     memset(in, 0, sizeof(in));     cin >> n;     for (int i = 0, tmp; i < n; i++) {       scanf( %d , &tmp);       in[tmp]++;     }     long long ans = 0;     for (int i = 0; i < 1000005; i++) {       if (in[i] == 0 || in[i] == 1) continue;       while (in[i] > 1) {         ans++;         in[i + 1]++;         in[i]--;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int changed;   int answer1, answer2 = 1023;   int main() {     cin >> n;     int i;     for (i = 0; i < n; i++) {       char tp;       cin >> tp;       if (tp ==  | ) {         int number;         cin >> number;         answer1 |= number;         answer2 |= number;         changed |= number;       } else if (tp ==  & ) {         int number;         cin >> number;         answer1 &= number;         answer2 &= number;         number = 1023 - number;         changed |= number;       } else {         int number;         cin >> number;         answer1 ^= number;         answer2 ^= number;       }     }     int answer11 = 0;     int answer22 = 0;     int answer33 = 0;     for (i = 0; i < 10; i++) {       if ((answer1 & (1 << i)) && (answer2 & (1 << i))) {         answer11 += 1 << i;       } else {         if ((answer1 & (1 << i)) && (!(answer2 & (1 << i)))) {           answer33 += 1 << i;           answer22 += 1 << i;         }         if ((!(answer1 & (1 << i))) && (answer2 & (1 << i))) {           answer22 += 1 << i;         }       }     }     cout << 3 << endl;     cout <<  &   << answer22 << endl;     cout <<  |   << answer11 << endl;     cout <<  ^   << answer33 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1;   string s, t;   char c[N];   int cs[2][N], ct[2][N], q;   int main() {     scanf(  %s , c);     s = c;     scanf(  %s , c);     t = c;     int at = 0;     for (auto &i : s) {       at++;       if (i ==  C  || i ==  B ) {         i =  B ;         cs[1][at] = cs[1][at - 1] + 1;       } else {         cs[1][at] = cs[1][at - 1];         cs[0][at] = cs[0][at - 1] + 1;       }     }     at = 0;     for (auto &i : t) {       at++;       if (i ==  C  || i ==  B ) {         i =  B ;         ct[1][at] = ct[1][at - 1] + 1;       } else {         ct[1][at] = ct[1][at - 1];         ct[0][at] = ct[0][at - 1] + 1;       }     }     scanf( %d , &q);     for (int i = 0, a, b, c, d; i < q; i++) {       scanf( %d%d%d%d , &a, &b, &c, &d);       int difs = cs[1][b] - cs[1][a - 1];       int dift = ct[1][d] - ct[1][c - 1];       bool thereis = 0;       int need = dift - difs;       int trails = min(b - a + 1, cs[0][b]);       int trailt = min(d - c + 1, ct[0][d]);       if (need & 1) {         printf( 0 );         continue;       }       if (need < 0) {         printf( 0 );         continue;       }       if (!need) {         if (trails < trailt || (trails - trailt) % 3) {           printf( 0 );           continue;         }         printf( 1 );         continue;       }       if (need && trails > trailt) {         trails = trailt;         thereis = 1;       }       if ((trails - trailt) % 3 || trails < trailt) {         printf( 0 );         continue;       }       thereis |= difs;       if (!thereis && need) {         printf( 0 );         continue;       }       printf( 1 );     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T maxi(T a, T b) {     return a > b ? a : b;   }   template <typename T>   inline T mini(T a, T b) {     return a < b ? a : b;   }   template <typename T>   inline T absl(T a) {     return a > 0 ? a : -a;   }   template <typename T>   inline T gcd(T a, T b) {     T t;     if (a < b) {       while (a) {         t = a;         a = b % a;         b = t;       }       return b;     } else {       while (b) {         t = b;         b = a % b;         a = t;       }       return a;     }   }   template <typename T>   inline T ceiling(T a, T b) {     if (b < 0) {       a *= -1;       b *= -1;     }     if ((double)a / (double)b < 0) return 0;     {       if (a % b == 0) return (a / b);       return ((a / b) + 1);     }   }   vector<int> adj[500000];   map<pair<int, int>, int> m;   vector<pair<int, int> > v(500000);   vector<bool> visited(500000, false);   int d;   void dfs(int u, int c) {     visited[u] = true;     for (auto it : adj[u]) {       if (!visited[it]) {         m[{u, it}] = c % d;         ++c;         dfs(it, c);       }     }   }   void input() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n - 1; ++i) {       int s, d;       cin >> s >> d;       --s;       --d;       adj[s].push_back(d);       adj[d].push_back(s);       v[i].first = s;       v[i].second = d;     }     int b[n];     for (int i = 0; i < n; ++i) {       b[i] = adj[i].size();     }     sort(b, b + n, greater<int>());     d = b[k];     cout << d << endl;     dfs(0, 0);     for (int i = 0; i < n - 1; ++i) {       cout << maxi(m[v[i]], m[{v[i].second, v[i].first}]) + 1 <<    ;     }   }   int main() {     input();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   struct node {     int l, r, sum;   } hjt[maxn * 40];   int a[maxn], root[maxn], cnt;   int last[maxn];   void insert(int l, int r, int pre, int &now, int p, int v) {     hjt[++cnt] = hjt[pre];     now = cnt;     hjt[now].sum = hjt[pre].sum + v;     if (l == r) return;     int m = (l + r) >> 1;     if (p <= m)       insert(l, m, hjt[pre].l, hjt[now].l, p, v);     else       insert(m + 1, r, hjt[pre].r, hjt[now].r, p, v);   }   int query(int now, int l, int r, int k) {     if (l == r) {       if (hjt[now].sum <= k) return l;       return l - 1;     }     int mid = (l + r) >> 1;     int tmp = hjt[hjt[now].l].sum;     if (tmp > k)       return query(hjt[now].l, l, mid, k);     else       return query(hjt[now].r, mid + 1, r, k - tmp);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = n; i >= 1; i--) {       if (last[a[i]]) {         insert(1, n, root[i + 1], root[i], last[a[i]], -1);         insert(1, n, root[i], root[i], i, 1);       } else         insert(1, n, root[i + 1], root[i], i, 1);       last[a[i]] = i;     }     for (int i = 1; i <= n; i++) {       int ans = 0, l = 1, r = 0;       while (l <= n) {         r = query(root[l], 1, n, i);         l = r + 1;         ans++;       }       cout << ans;       if (i == n)         cout <<   n ;       else         cout <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int num = 0;   int e[21][21];   int flag[21];   int dfs(int x, int sum, int mid) {     if (x > n) {       num = num + 1;     } else {       mid = dfs(x + 1, sum, mid);       for (int y = 1; y <= n; y++) {         if (num >= k) {           break;         }         if (flag[y] == 0 && e[x][y] != 0 && sum + e[x][y] <= mid) {           flag[y] = 1;           mid = dfs(x + 1, sum + e[x][y], mid);           flag[y] = 0;         }       }     }     return mid;   }   int main() {     int u, v, w;     cin >> n >> m >> k;     for (int i = 0; i <= 20; i++) {       for (int j = 0; j <= 20; j++) {         e[i][j] = 0;       }     }     int l = 0;     int h = n * 1000;     int mid = 0;     for (int i = 0; i < m; i++) {       cin >> u >> v >> w;       e[u][v] = w;     }     while (l < h) {       num = 0;       mid = (l + h) / 2;       mid = dfs(1, 0, mid);       if (num < k) {         l = mid + 1;       } else {         h = mid;       }     }     cout << h << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 50005;   const int MAXD = 55;   const int MOD = 1e9 + 7;   template <typename T>   inline void read(T &AKNOI) {     T x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     AKNOI = flag * x;   }   namespace ModCalculator {   inline void Inc(int &x, int y) {     x += y;     if (x >= MOD) x -= MOD;   }   inline void Dec(int &x, int y) {     x -= y;     if (x < 0) x += MOD;   }   inline int Add(int x, int y) {     Inc(x, y);     return x;   }   inline int Sub(int x, int y) {     Dec(x, y);     return x;   }   inline int Mul(int x, int y) { return 1LL * x * y % MOD; }   }  // namespace ModCalculator   using namespace ModCalculator;   char s[MAXN], sx[MAXD], sy[MAXD];   int n, d, dg[MAXD];   int tot, ch[MAXN][10], fail[MAXN], ed[MAXN], q[MAXN];   int dp[MAXD][MAXN];   void Insert(int l, int r) {     int p = 0;     for (int i = l; i <= r; ++i) {       int x = s[i] -  0 ;       if (!ch[p][x]) ch[p][x] = ++tot;       p = ch[p][x];     }     ed[p] = 1;   }   void GetFail() {     int head = 1, tail = 0;     for (int i = 0; i < 10; ++i) {       if (ch[0][i]) {         q[++tail] = ch[0][i];       }     }     while (head <= tail) {       int u = q[head++];       for (int i = 0; i < 10; ++i) {         if (ch[u][i]) {           fail[ch[u][i]] = ch[fail[u]][i];           q[++tail] = ch[u][i];         } else {           ch[u][i] = ch[fail[u]][i];         }       }     }   }   int DP(int i, int j, bool full) {     if (i > d) return 1;     if (!full && dp[i][j] != -1) return dp[i][j];     int ret = 0, r = (full ? dg[i] : 9);     for (int k = 0; k <= r; ++k) {       if (ed[ch[j][k]]) continue;       Inc(ret, DP(i + 1, ch[j][k], full && (k == r)));     }     if (!full) dp[i][j] = ret;     return ret;   }   int Calc(char *ss) {     int ret = 0;     for (int i = 1; i <= d; ++i) {       ret = Add(Mul(ret, 10), (dg[i] = ss[i] -  0 ));     }     return Sub(ret, DP(1, 0, 1));   }   void init() {     scanf( %s , s + 1);     n = strlen(s + 1);     scanf( %s , sx + 1);     scanf( %s , sy + 1);     d = strlen(sx + 1);     int d2 = d / 2;     for (int i = 1; i + d2 - 1 <= n; ++i) {       Insert(i, i + d2 - 1);     }     GetFail();   }   void solve() {     int p = d;     for (; sx[p] ==  0 ; sx[p--] =  9 )       ;     sx[p] -= 1;     memset(dp, -1, sizeof(dp));     printf( %d n , Sub(Calc(sy), Calc(sx)));   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mdin(long long a, long long m) {     long long r1 = m, r2 = a, t1 = 0, t2 = 1;     while (r2 > 0) {       long long q = r1 / r2;       long long r = r1 % r2;       r1 = r2;       r2 = r;       long long t = (t1 - q * t2) % m;       t1 = t2;       t2 = t;     }     return (t1 + m) % m;   }   long long ex(long long a, long long n, long long m) {     if (n == 0) return 1;     long long ans = ex((a * a) % m, n / 2, m);     if (n % 2) ans = (a * ans) % m;     return ans;   }   void bfs(int r, vector<int> adj[], int n) {     queue<int> q, l;     vector<int> vis(n + 1, 0);     q.push(r);     l.push(1);     while (!q.empty()) {       int nd = q.front();       q.pop();       int lv = l.front();       l.pop();       for (auto it : adj[nd]) {         if (vis[it] == 0) {           vis[it] = 1;           q.push(it);           l.push(lv + 1);         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       long long n, k;       cin >> n >> k;       if (k > n - 1) {         cout << 0;         return 0;       }       long long f[n + 1], inf[n + 1];       f[0] = 1;       inf[0] = 1;       for (long long i = 1; i <= n; i++) {         f[i] = (i * f[i - 1]) % 998244353;         inf[i] = mdin(f[i], 998244353);       }       if (k == 0) {         cout << f[n] << endl;       } else {         long long ans = (((f[n] * inf[n - k]) % 998244353) * inf[k]) % 998244353;         k = n - k;         long long ml = 0;         int s = 1;         for (long long i = 0; i <= k - 1; i++) {           long long cm = (((f[k] * inf[i]) % 998244353) * inf[k - i]) % 998244353;           long long t = k - i;           long long et = ex(t, n, 998244353);           ml = (ml + (cm * et * s) % 998244353 + 998244353) % 998244353;           s *= -1;         }         ans = (((ml * ans) % 998244353) * 2) % 998244353;         cout << ans << endl;       }     }     return 0;   }