malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1003;   int n, k;   int pos[5][maxn];   int dp[maxn];   bool vis[maxn];   vector<int> v[maxn];   int dfs(int cur) {     if (vis[cur]) return dp[cur];     vis[cur] = true;     for (int i = 0; i < v[cur].size(); i++) {       int nxt = v[cur][i];       dp[cur] = max(dp[cur], 1 + dfs(nxt));     }     return dp[cur];   }   int main() {     cin >> n >> k;     for (__typeof(k) i = 0; i < (k); i++) {       for (__typeof(n) j = 0; j < (n); j++) {         int x;         cin >> x;         pos[i][--x] = j;       }     }     for (__typeof(n) i = 0; i < (n); i++) {       for (__typeof(n) j = 0; j < (n); j++) {         bool flag = 1;         for (__typeof(k) a = 0; a < (k); a++) {           if (pos[a][i] <= pos[a][j]) {             flag = 0;             break;           }         }         if (flag) v[i].push_back(j);       }     }     for (__typeof(n) i = 0; i < (n); i++) dfs(i);     cout << *max_element(dp, dp + n) + 1;   }
#include <bits/stdc++.h>   using namespace std;   string imp =  Impossible n ;   const int N = 2e5 + 5;   int bfstim[N];   long long MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tests;     tests = 1;     cin >> tests;     while (tests--) {       int n;       cin >> n;       if (n > 2) {         cout << n - 2 <<   n ;       } else         cout <<  0 n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = int;   vector<pair<ll, string>> con[101010];   int main() {     ios_base::sync_with_stdio(false);     cout.tie(NULL);     int n, m;     cin >> n >> m;     int reg, sc;     string name;     while (n--) {       cin >> name;       cin >> reg;       cin >> sc;       con[reg].push_back(make_pair(sc, name));     }     for (int i = 1; i <= m; i++) {       sort(con[i].begin(), con[i].end());       reverse(con[i].begin(), con[i].end());       if ((int)con[i].size() > 2 && con[i][1].first == con[i][2].first) {         cout <<  ? n ;       } else {         cout << con[i][0].second <<     << con[i][1].second << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, x, y, a, l, w, z, ss, t, k, e, c, total, nnn, yes,       mx = 531, mn = -1, r, xx, yy, last, cas;   map<string, int> wow;   int main() {     string s;     cin >> s;     wow[s] = 1;     x = 1;     l = s.size();     for (int i = 0; i < l; i++) {       char te = s[l - 1];       for (int j = l - 1; j > 0; j--) {         s[j] = s[j - 1];       }       s[0] = te;       if (wow[s] == 0) {         x++;         wow[s]++;       }     }     cout << x;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int n, p1l, p1r, p2l, p2r;   string s, t, ans;   int main() {     ios_base::sync_with_stdio(false);     cin >> s >> t;     sort(s.begin(), s.end());     sort(t.begin(), t.end());     ans.resize(s.length(), 0);     p1l = 0;     p2r = (int)s.length() - 1;     p1r = ((int)s.length() + 1) / 2 - 1;     p2l = p2r - (int)s.length() / 2 + 1;     n = (int)s.length() - 1;     for (int i = 0, nm = 0; i <= n; ++i, ++nm) {       if (t[p2r] <= s[p1l]) {         if (nm % 2 == 0)           ans[n] = s[p1r--];         else           ans[n] = t[p2l++];         n -= 1;         i -= 1;       } else {         if (nm % 2 == 0)           ans[i] = s[p1l++];         else           ans[i] = t[p2r--];       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> finger;   int seq[100];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> seq[i];     for (int i = 0; i < m; i++) {       int x;       cin >> x;       finger.push_back(x);     }     for (int i = 0; i < n; i++) {       for (vector<int>::iterator itr = finger.begin(); itr != finger.end();            itr++) {         if (*itr == seq[i]) {           cout << *itr <<    ;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> split, ans;   int a[300002];   int p[300002][3];   long long max(long long a, long long b) { return a >= b ? a : b; }   long long min(long long a, long long b) { return a <= b ? a : b; }   int main() {     int n, i, j, l, r;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , a + i);     }     a[0] = a[n + 1] = 0;     long long _0, _1, _2, __0, __1, __2;     _0 = a[1], _1 = 0, _2 = -1;     for (i = 1; i <= n; i++) {       p[i + 1][0] = p[i + 1][1] = p[i + 1][2] = -1;       __0 = __1 = __2 = -1;       if (~_0) {         if (__1 == -1 || _0 < __1) {           __1 = _0;           p[i + 1][1] = 0;         }       }       if (~_1) {         if (__2 == -1 || _1 < __2) {           __2 = _1;           p[i + 1][2] = 1;         }       }       if (~_2) {         if (__0 == -1 || _2 + max(a[i], a[i + 1]) < __0) {           __0 = _2 + max(a[i], a[i + 1]);           p[i + 1][0] = 2;         }         if (__1 == -1 || _2 + a[i] < __1) {           __1 = _2 + a[i];           p[i + 1][1] = 2;         }       }       _0 = __0, _1 = __1, _2 = __2;     }     long long u;     j = 0, u = __0;     if (__1 < u) j = 1, u = __1;     if (__2 < u) j = 2, u = __2;     split.clear();     for (i = n + 1;; i--) {       if (j == 0) {         split.push_back(i - 1);       }       if (i == 1) break;       j = p[i][j];     }     ans.clear();     int t;     for (i = 0; i < split.size(); i++) {       j = split[i];       t = min(a[j], a[j + 1]);       a[j] -= t, a[j + 1] -= t;       if (t) ans.push_back(j);     }     for (i = split.size() - 1; i >= -1; i--) {       l = i == split.size() - 1 ? 0 : split[i + 1] + 1, r = ~i ? split[i] : n + 1;       for (j = l; j <= r; j += 2) {         if (j >= 1 && min(a[j - 1], a[j])) {           t = min(a[j - 1], a[j]);           a[j - 1] -= t, a[j] -= t;           ans.push_back(j - 1);         }         if (j <= n && min(a[j], a[j + 1])) {           t = min(a[j], a[j + 1]);           a[j] -= t, a[j + 1] -= t;           ans.push_back(j);         }       }     }     printf( %d n , ans.size());     for (i = 0; i < ans.size(); i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int u, v, w;     cin >> u >> v;     if (u > v || (u + v) % 2 != 0)       cout << -1 << endl;     else if (u == v && u == 0)       cout << 0 << endl;     else if (u == v)       cout << 1 << endl << u << endl;     else {       w = (v - u) / 2;       if ((u & w) == 0)         cout << 2 << endl << u + w <<     << w << endl;       else         cout << 3 << endl << u <<     << w <<     << w << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 10;   long long ans[M << 2], tag[M << 2];   int a[M], p[M];   void push_up(int p) { ans[p] = min(ans[p << 1], ans[p << 1 | 1]); }   void ps(int p, int l, int r, long long x) {     ans[p] += x;     tag[p] += x;   }   void push_down(int p, int l, int r) {     if (!tag[p]) return;     int mid = l + r >> 1;     ps(p << 1, l, mid, tag[p]);     ps(p << 1 | 1, mid + 1, r, tag[p]);     tag[p] = 0;   }   void add(int p, int p_l, int p_r, int l, int r, int x) {     if (r < l) return;     if (p_l >= l && p_r <= r) {       ans[p] += x;       tag[p] += x;       return;     }     push_down(p, p_l, p_r);     int mid = p_l + p_r >> 1;     if (l <= mid) add(p << 1, p_l, mid, l, r, x);     if (r > mid) add(p << 1 | 1, mid + 1, p_r, l, r, x);     push_up(p);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       add(1, 1, n, p[i] + 1, n, a[i]);     }     long long sum = min(a[1], a[n]);     for (int i = 1; i < n; i++) {       add(1, 1, n, p[i] + 1, n, -a[i]);       add(1, 1, n, 1, p[i] - 1, a[i]);       sum = min(ans[1], sum);     }     printf( %lld n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 9;   const double eps = 1e-11;   const int inf = (int)2e9;   const int mod = (int)1e9 + 7;   const double pi = 3.1415926535897932384626433832795;   int a[N];   int main() {     int n, k;     scanf( %d %d , &n, &k);     int ex = 0;     for (int i = 1; i <= n; i++) {       a[i] = i;       ex += i * (n - i + 1);     }     int cnt = 0;     do {       int cur = 0;       for (int i = 1; i <= n; i++) {         int mn = inf;         for (int j = i; j <= n; j++) {           mn = min(mn, a[j]);           cur += mn;         }       }       if (cur == ex) {         k--;         if (!k) {           for (int i = 1; i <= n; i++) {             printf( %d%c , a[i],    n [i == n]);           }         }       }     } while (next_permutation(a + 1, a + n + 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int dir[405][405], dic[405][405];   int main() {     memset(dir, 63, sizeof(dir));     memset(dic, 63, sizeof(dic));     scanf( %d %d , &n, &m);     for (int i = 1, x, y; i <= m; i++) {       scanf( %d %d , &x, &y);       dir[x][y] = dir[y][x] = 1;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (dir[i][j] == 1061109567) dic[i][j] = 1;     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++)           dir[i][j] = min(dir[i][k] + dir[k][j], dir[i][j]);       }     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           int res = dic[i][k] + dic[k][j];           if (res == dir[i][j]) continue;           dic[i][j] = min(dic[i][j], res);         }       }     }     int ans = max(dic[1][n], dir[1][n]);     if (ans == 1061109567) ans = -1;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, d[100001], b[100001], x, ans = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d , &x);       d[i] = d[--x] + 1;       b[d[i]]++;     }     for (int i = 1; i < n; i++) ans += b[i] % 2;     printf( %d , ans + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   char promocode[1100][10];   int strdif(char a[], char b[]) {     int cnt = 0;     for (int ii = 0; ii < 6; ii++) {       if (a[ii] != b[ii]) cnt++;     }     return cnt;   }   int main() {     scanf( %d n , &n);     for (int ii = 1; ii <= n; ii++) {       scanf( %s , promocode[ii]);     }     int ans = 6;     for (int ii = 1; ii <= n - 1; ii++) {       for (int jj = ii + 1; jj <= n; jj++) {         ans = min(ans, (strdif(promocode[ii], promocode[jj]) - 1) / 2);       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       int y = 1;       for (; y <= n / 2 + 1; y++) {         for (int x = 1; x <= n; x++) {           if (x <= n / 2 + 1 - y || x >= n / 2 + 1 + y)             cout <<  * ;           else             cout <<  D ;         }         cout <<   n ;       }       for (y = n / 2; y > 0; y--) {         for (int x = 1; x <= n; x++) {           if (x <= n / 2 + 1 - y || x >= n / 2 + 1 + y)             cout <<  * ;           else             cout <<  D ;         }         cout <<   n ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int main() {     int n, k;     scanf( %d %d , &n, &k);     vector<int> A(n), acc(n);     for (int i = (0); i < (n); ++i) cin >> A[i];     acc[0] = A[0];     for (int i = (1); i < (n); ++i) acc[i] = A[i] + acc[i - 1];     int rsp = -inf;     for (int i = (0); i < (n); ++i) {       for (int j = (i); j < (n); ++j) {         int sum = acc[j] - (i ? acc[i - 1] : 0);         rsp = max(rsp, sum);         vector<int> v1, v2;         for (int kk = (0); kk < (n); ++kk) {           if (kk < i or kk > j) {             v1.push_back(A[kk]);           } else {             v2.push_back(A[kk]);           }         }         sort(v1.rbegin(), v1.rend());         sort(v2.begin(), v2.end());         int lim = min(v1.size(), v2.size());         for (int kk = (0); kk < (min(k, lim)); ++kk) {           sum -= v2[kk];           sum += v1[kk];           rsp = max(rsp, sum);         }       }     }     printf( %d n , rsp);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   struct node {     int v, w, next;   } edges[maxn << 2];   int head[maxn], cnt;   int n, k;   void add_edge(int u, int v, int w) {     edges[++cnt] = {v, w, head[u]};     head[u] = cnt;   }   long long dp[maxn][2];   void dfs(int rt, int fa) {     vector<long long> vv;     long long ans = 0;     for (int i = head[rt]; i; i = edges[i].next) {       if (edges[i].v == fa) continue;       dfs(edges[i].v, rt);       vv.push_back(dp[edges[i].v][0] + edges[i].w - dp[edges[i].v][1]);       ans += dp[edges[i].v][1];     }     sort(vv.begin(), vv.end(), greater<long long>());     if (k == 1) dp[rt][0] = ans;     for (int i = 0; i < vv.size(); ++i) {       if (i < k && vv[i] > 0) ans += vv[i];       if (i == k - 1 - 1) dp[rt][0] = ans;       if (i == k - 1) dp[rt][1] = ans;     }     if (dp[rt][0] == -1) dp[rt][0] = ans;     if (dp[rt][1] == -1) dp[rt][1] = ans;   }   int main() {     int q;     scanf( %d , &q);     while (q--) {       scanf( %d%d , &n, &k);       memset(head, 0, sizeof(int) * (n + 1));       memset(dp, -1, sizeof(long long) * (n + 1) * 2);       cnt = 0;       for (int i = 0, u, v, w; i < n - 1; ++i) {         scanf( %d%d%d , &u, &v, &w);         add_edge(u, v, w);         add_edge(v, u, w);       }       dfs(1, 0);       printf( %lld n , max(dp[1][0], dp[1][1]));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   inline int read() {     int res = 0, fl = 1;     char r = getchar();     for (; !isdigit(r); r = getchar())       if (r ==  - ) fl = -1;     for (; isdigit(r); r = getchar()) res = (res << 3) + (res << 1) + r - 48;     return res * fl;   }   const int Maxn = 2e5 + 10;   vector<pair<int, int> > g[Maxn];   long double val[Maxn];   int siz[Maxn];   void dfs(int now, int pa) {     siz[now] = 1;     for (int i = g[now].size() - 1; i >= 0; --i) {       int nxt = g[now][i].first;       if (pa == nxt) continue;       val[nxt] += g[now][i].second;       dfs(nxt, now);       val[now] += val[nxt];       siz[now] += siz[nxt];     }   }   long long Time, t[Maxn];   bool cmp(pair<int, int> A, pair<int, int> B) {     return val[A.first] > val[B.first];   }   void Dfs(int now, int pa) {     for (int i = g[now].size() - 1; i >= 0; --i) {       int nxt = g[now][i].first;       if (nxt == pa) continue;       val[nxt] = 10000.00 * val[nxt] / siz[nxt];     }     sort(g[now].begin(), g[now].end(), cmp);     t[now] = Time;     for (int i = g[now].size() - 1; i >= 0; --i) {       int nxt = g[now][i].first;       if (pa == nxt) continue;       Time += g[now][i].second;       Dfs(nxt, now);       Time += g[now][i].second;     }   }   int main() {     int n = read();     for (int i = 1; i < n; ++i) {       int x = read(), y = read(), z = read();       g[x].push_back(make_pair(y, z));       g[y].push_back(make_pair(x, z));     }     dfs(1, 0);     Dfs(1, 0);     long double ans = 0;     for (int i = 1; i <= n; ++i) ans += t[i];     printf( %.6Lf n , 1.00 * ans / (n - 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     node *bit[2];     int cnt = 0;     int index = -1;   };   node *root;   void insert(string &s, int id) {     node *cur = root;     for (char x : s) {       int ch = x -  0 ;       if (!cur->bit[ch]) cur->bit[ch] = new node();       cur = cur->bit[ch];       cur->cnt++;     }     cur->index = id;   }   int already(string &s) {     node *cur = root;     for (char x : s) {       int ch = x -  0 ;       if (!cur->bit[ch])         return -1;       else if (cur->bit[ch]->cnt < 1)         return -1;       cur = cur->bit[ch];     }     return cur->index;   }   void remove(string &s) {     node *cur = root;     for (char x : s) {       int ch = x -  0 ;       cur = cur->bit[ch];       cur->cnt--;     }     cur->index = -1;   }   void test_case() {     root = new node();     int n;     cin >> n;     int a[n];     vector<bool> can(n, true);     int both_zero = 0, both_one = 0;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       a[i] = (s[0] -  0 ) * 2 + (s.back() -  0 );       if (s[0] != s.back()) {         int index = already(s);         if (index != -1) {           can[index] = false;           can[i] = false;           remove(s);         } else {           reverse(s.begin(), s.end());           insert(s, i);         }       } else {         can[i] = false;       }     }     vector<int> possible[2];     vector<int> type(4, 0);     for (int i = 0; i < n; i++) {       if (can[i] == true) {         possible[a[i] - 1].push_back(i + 1);       } else {         type[a[i]]++;       }     }     vector<int> ans[2];     vector<int> valid(2, true);     for (int t = 0; t < 2; t++) {       vector<int> cnt = type;       vector<int> p[2];       p[0] = possible[0];       p[1] = possible[1];       int last = t;       for (int i = 0; i < n; i++) {         bool found = false;         for (int j = 0; j < 4; j++) {           if (last == j / 2 && cnt[j] > 0) {             cnt[j]--;             found = true;             last = j % 2;             break;           }         }         if (found) continue;         if (!p[last].empty()) {           p[last].pop_back();           last = 1 - last;           continue;         }         if (p[1 - last].empty()) {           valid[t] = false;           break;         }         ans[t].push_back(p[1 - last].back());         p[1 - last].pop_back();         last = 1 - last;       }     }     if (valid[0] == false && valid[1] == false) {       cout <<  -1 n ;       return;     }     int id = 0;     if (valid[0] == true && valid[1] == false) {       id = 0;     } else if (valid[0] == false && valid[1] == true) {       id = 1;     } else {       if (ans[0].size() < ans[1].size())         id = 0;       else         id = 1;     }     cout << (int)ans[id].size() <<   n ;     for (int i : ans[id]) cout << i <<    ;     cout <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) test_case();   }
#include <bits/stdc++.h>   using namespace std;   int a[200020], b[200020], c[200020];   int main(void) {     int n, k;     int m;     int i;     int o;     scanf( %d %d , &n, &k);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = 1; i <= n; i++) scanf( %d , &b[i]);     for (i = 1, m = o = 0; i <= n; i++)       if (a[i] < b[i]) {         o += a[i];         --k;       } else {         o += b[i];         c[m++] = a[i] - b[i];       }     if (k > 0) {       sort(c, c + m);       for (i = 0; i < k; i++) o += c[i];     }     printf( %d n , o);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char ans[100010 * 100];   char s[100010 * 10];   int f[100010 * 100];   int getf(int k) { return k == f[k] ? k : f[k] = getf(f[k]); }   int main() {     int n, k, LEN = 0, id;     cin >> n;     for (int i = 0; i < 100010 * 100; i++) f[i] = i;     for (int i = 0; i < n; i++) {       scanf( %s %d , s, &k);       int len = strlen(s);       while (k--) {         scanf( %d , &id);         for (int i = getf(id); i < id + len; i = f[i] = getf(i + 1)) {           ans[i] = s[i - id];         }         LEN = max(LEN, id + len);       }     }     for (int i = 1; i < LEN; i++) {       if (ans[i] ==   0 ) ans[i] =  a ;     }     puts(ans + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void foobar() {     long long int n, i;     cin >> n;     vector<long long int> arr(n);     long long int mm = INT_MAX;     for (i = 0; i < n; ++i) {       cin >> arr[i];       mm = min(mm, arr[i]);     }     for (i = 0; i < n; ++i) {       arr[i] -= mm;       if (arr[i] % 2) {         cout <<  NO  << endl;         return;       }     }     cout <<  YES  << endl;   }   int main() {     long long int test;     cin >> test;     while (test--) foobar();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ofstream out( output.txt );     auto start = chrono::high_resolution_clock::now();     long long t = 1;     for (long long test = 1; test <= t; test++) {       long long n;       cin >> n;       vector<long long> a(n);       pair<long long, long long> b[n];       for (long long i = 0; i <= n - 1; i++)         cin >> a[i], b[i].first = a[i], b[i].second = i;       sort(b, b + n);       long long ord[n];       long long shts = 0, I = 0;       for (long long i = n - 1; i >= 0; i--) {         shts += (b[i].first * I + 1);         ord[I] = b[i].second + 1;         I++;       }       cout << shts <<   n ;       for (long long i = 0; i <= n - 1; i++) cout << ord[i] <<    ;       cout <<   n ;     }     auto stop = chrono::high_resolution_clock::now();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500043;   const int K = 750;   int a[N];   int sum[K][K];   int main() {     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int t, x, y;       scanf( %d %d %d , &t, &x, &y);       if (t == 1) {         a[x] += y;         for (int i = 1; i < K; i++) sum[i][x % i] += y;       } else {         if (x >= K) {           int ans = 0;           for (int i = y; i <= 500000; i += x) ans += a[i];           printf( %d n , ans);         } else           printf( %d n , sum[x][y]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool cmin(T& a, const T& b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool cmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   int read() {     int x = 0, f = 1;     char ch;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return x * f;   }   const int MaxN = 48, MaxM = 1 << (MaxN / 2);   int n, m, F[MaxN];   int find(int x) { return F[x] == x ? x : F[x] = find(F[x]); }   char c[MaxN][MaxN];   int sz[MaxN], b[MaxM], h[MaxM], g[MaxM], f[MaxM];   int main() {     int i, j, k;     n = read();     for (i = 0; i < n; i++) F[i] = i;     for (i = 0; i < n; i++) {       scanf( %s , c[i]);       for (j = 0; j < i; j++)         if (c[i][j] ==  A ) F[find(i)] = find(j);     }     for (i = 0; i < n; i++) sz[find(i)]++;     for (i = 0; i < n; i++)       if (find(i) == i && sz[i] > 1) h[i] = 1 << m, m++;     for (i = 0; i < n; i++)       for (j = 0; j < i; j++)         if (c[i][j] ==  X ) {           int x = find(i), y = find(j);           if (x == y) return puts( -1 ), 0;           if (h[x] && h[y]) f[h[x] | h[y]] = 1;         }     if (!m) return printf( %d n , n - 1), 0;     for (i = 0; i < (1 << m); i++)       for (j = 0; j < m; j++)         if (i >> j & 1) f[i] |= f[i ^ (1 << j)];     for (i = 0; i < (1 << m); i++) {       b[i] = b[i >> 1] + (i & 1);       f[i] = !f[i];       g[i] = 1;     }     for (j = 0; j < m; j++)       for (i = 0; i < (1 << m); i++)         if (i >> j & 1) f[i] += f[i ^ (1 << j)];     for (i = 1; i <= m; i++) {       int t = 0;       for (j = 0; j < (1 << m); j++) {         g[j] = (long long)g[j] * f[j];         if (m - b[j] & 1)           t -= g[j];         else           t += g[j];       }       if (t) return printf( %d n , n + i - 1), 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     int n = s.length();     int x = t.length();     vector<int> lft(x);     vector<int> rgt(x);     int l = 0;     for (int i = 0; i < n && l < x; ++i) {       if (s[i] == t[l]) {         lft[l++] = i;       }     }     l = x - 1;     for (int i = n - 1; i >= 0 && l >= 0; --i) {       if (s[i] == t[l]) {         rgt[l--] = i;       }     }     int mx = 0;     mx = max(mx, lft[0]);     mx = max(mx, rgt[0]);     mx = max(mx, n - 1 - lft[x - 1]);     mx = max(mx, n - 1 - rgt[x - 1]);     for (int i = 1; i < x; ++i) mx = max(mx, rgt[i] - lft[i - 1] - 1);     cout << mx;   }