malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void cp() {     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int main() {     cp();     {       string s, t;       cin >> s >> t;       if (s.length() == t.length() + 1) {         long long m = 0;         long long in = -1;         char f;         long long j = 0;         for (long long i = 0; i < s.length(); i += 1) {           if (s[i] != t[j]) {             f = s.at(i);             in = i;             m++;             j--;           }           j++;         }         vector<long long> ans;         if (m == 1) {           while (in > -1) {             if (s[in] == f) {               in--;             } else {               break;             }           }           in++;           while (in < s.length()) {             if (s[in] == f) {               ans.push_back(in + 1);               in++;             } else {               break;             }           }           cout << ans.size();           cout << endl;           ;           for (long long i = 0; i < ans.size(); i += 1) cout << ans[i] <<    ;         } else {           cout <<  0 n ;         }       } else {         cout <<  0 n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 100 * 1000 + 7;   int a[MX];   int hup[MX], hdown[MX];   long long cup[MX], cdown[MX];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; i++) {       int cost = 0;       if (a[i] <= hup[i - 1]) cost = (hup[i - 1] + 1 - a[i]);       hup[i] = a[i] + cost;       cup[i] = cup[i - 1] + cost;     }     for (int i = n; i >= 1; i--) {       int cost = 0;       if (a[i] <= hdown[i + 1]) cost = (hdown[i + 1] + 1 - a[i]);       hdown[i] = a[i] + cost;       cdown[i] = cdown[i + 1] + cost;     }     long long res = (long long)1e18;     for (int i = 1; i <= n; i++) {       int need = max(hup[i - 1] + 1, hdown[i + 1] + 1);       int cost = 0;       if (a[i] < need) cost = need - a[i];       res = min(res, cup[i - 1] + cdown[i + 1] + cost);     }     printf( %lld n , res);   }
#include <bits/stdc++.h>   using namespace std;   struct ww {     long long x, y;   } c[400][400];   int i, j, k, n, m, ma, ren, C, kuai;   int cov[400], zhi[400];   long long b[400][400], s[400][400];   vector<int> a[100010];   inline void gao(int x) {     int i, n = kuai - 1, g[400], r = 0;     long long jum[400];     for (i = 0; i <= n; i++) b[x][i] += cov[x];     cov[x] = 0;     s[x][0] = b[x][0];     for (i = 1; i <= n; i++) s[x][i] = s[x][i - 1] + b[x][i];     for (i = 0; i <= n; i++) {       long long A = s[x][i], F = 0;       for (; r; r--) {         int wei = g[r];         long long B = s[x][wei];         int cha = i - wei;         if (A >= B) continue;         long long ci = (B - A) / cha + ((B - A) % cha > 0);         if (jum[r] >= ci)           continue;         else {           F = ci;           break;         }       }       g[++r] = i, jum[r] = F;     }     jum[r + 1] = 100010;     for (i = 1; i <= r; i++) c[x][i] = (ww){g[i], jum[i + 1]};     zhi[x] = 1;   }   inline void jian(int x) {     int A = x / kuai, B = x % kuai;     b[A][B] -= x;     gao(A);   }   inline void jia(int x) {     if (x < 0) return;     int A = x / kuai, B = x % kuai, i;     for (i = 0; i <= A - 1; i++) {       cov[i]++;       if (c[i][zhi[i]].y == cov[i]) zhi[i]++;     }     for (i = 0; i <= B; i++) b[A][i]++;     gao(A);   }   inline long long suan(int x) {     ww A = c[x][zhi[x]];     return s[x][A.x] + 1ll * cov[x] * (A.x + 1);   }   inline ww cal() {     int i, id;     long long ma, sum;     ma = -1, sum = 0;     for (i = 0; i <= 400 - 1; i++) {       long long re = sum + suan(i);       if (re > ma) ma = re, id = i * kuai + c[i][zhi[i]].x;       sum += s[i][kuai - 1] + 1ll * cov[i] * kuai;     }     return (ww){ma, id};   }   int main() {     kuai = 300;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       a[y].push_back(x - 1);       ma = max(ma, y);     }     for (i = 0; i <= 400 - 1; i++) gao(i);     ren = n;     for (C = 0; C <= ma + 1; C++) {       ww re = cal();       printf( %I64d %I64d n , 1ll * ren * C * m + re.x, re.y + 1);       for (j = 0; j < a[C].size(); j++) {         int A = a[C][j];         ren--;         jia(A);         jian(A + 1);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans;   int a[200][10];   int p[10];   struct Node {     double l, r;     int w;   } c[10];   struct Point {     int S, T;   } u[10], v[10];   void Op() {     c[1].l = -(1e-7);     c[1].r = 1.00 / 32.00;     c[1].w = 3000;     c[2].l = 1.00 / 32.00;     c[2].r = 1.00 / 16.00;     c[2].w = 2500;     c[3].l = 1.00 / 16.00;     c[3].r = 1.00 / 8.00;     c[3].w = 2000;     c[4].l = 1.00 / 8.00;     c[4].r = 1.00 / 4.00;     c[4].w = 1500;     c[5].l = 1.00 / 4.00;     c[5].r = 1.00 / 2.00;     c[5].w = 1000;     c[6].l = 1.00 / 2.00;     c[6].r = 1.00 / 1.00;     c[6].w = 500;   }   bool Judge(Point R, int t) {     double p = (double)R.T / (double)R.S;     if (p <= c[t].l) return 0;     if (p > c[t].r) return 0;     return 1;   }   void Check() {     int ans1 = 0, ans2 = 0;     for (int i = 1; i <= 5; i++) {       if (a[1][i] != -1) ans1 += c[p[i]].w / 250 * (250 - a[1][i]);       if (a[2][i] != -1) ans2 += c[p[i]].w / 250 * (250 - a[2][i]);       v[i] = u[i];     }     if (ans1 <= ans2) return;     bool ok = 1;     for (int i = 1; i <= 5; i++)       if (!Judge(v[i], p[i])) ok = 0;     if (ok) {       ans = 0;       return;     }     for (int i = 1; i <= 5000; i++) {       for (int j = 1; j <= 5; j++) {         v[j].S++;         if ((double)v[j].T / (double)v[j].S <= c[p[j]].l && a[1][j] != -1)           v[j].T++;       }       bool ok = 1;       for (int j = 1; j <= 5; j++)         if (!Judge(v[j], p[j])) ok = 0;       if (ok) {         ans = min(ans, i);         return;       }     }   }   void Solve(int x) {     if (x > 5) {       Check();       return;     }     for (int i = 1; i <= 6; i++) {       p[x] = i;       Solve(x + 1);     }   }   int main() {     Op();     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= 5; j++) scanf( %d , &a[i][j]);     for (int j = 1; j <= 5; j++) {       u[j].S = u[j].T = 0;       for (int i = 1; i <= n; i++) {         if (a[i][j] != -1) u[j].T++;         u[j].S++;       }     }     ans = 1 << 30;     Solve(1);     if (ans == 1 << 30)       printf( -1 n );     else       printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, x, y, arr1[2] = {0, 0}, arr2[2] = {0, 0};     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t >> x >> y;       if (t == 1) {         arr1[0] += x;         arr1[1] += y;       }       if (t == 2) {         arr2[0] += x;         arr2[1] += y;       }     }     if (arr1[0] >= arr1[1]) {       cout <<  LIVE  << endl;     }     if (arr1[0] < arr1[1]) {       cout <<  DEAD  << endl;     }     if (arr2[0] >= arr2[1]) {       cout <<  LIVE  << endl;     }     if (arr2[0] < arr2[1]) {       cout <<  DEAD  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   bitset<101> usado;   long long dfs(long long nodo) {     if (usado[nodo]) return 0;     usado.set(nodo);     return 1 + dfs(v[nodo]);   }   long long calcmcd(long long a, long long b) {     if (a % b == 0) return b;     return calcmcd(b, a % b);   }   int main() {     ios::sync_with_stdio(false);     bool puede = true;     long long n, aux, resp, mcd, mcm;     vector<long long> pararesp;     cin >> n;     v.resize(n + 1);     for (long long i = 1; i <= n; i++) {       cin >> v[i];       if (usado[v[i]])         puede = false;       else         usado.set(v[i]);     }     if (puede) {       usado.reset();       for (long long i = 1; i <= n; i++) {         while (i <= n && (usado[i] || v[i] == i)) i++;         if (i <= n) {           aux = dfs(i);           if (aux % 2 == 0) aux /= 2;           pararesp.push_back(aux);         }       }       if (pararesp.empty())         resp = 1;       else {         if (pararesp.size() == 1)           resp = pararesp[0];         else {           mcm = pararesp[pararesp.size() - 1];           for (int i = pararesp.size() - 2; i >= 0; i--) {             if (pararesp[i] > mcm)               mcd = calcmcd(pararesp[i], mcm);             else               mcd = calcmcd(mcm, pararesp[i]);             mcm = mcm * pararesp[i] / mcd;           }           resp = mcm;           pararesp.clear();         }       }       cout << resp <<   n ;     } else       cout <<  -1 n ;     v.clear();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t[1000009][11];   int main() {     int n, i, j, x, y, ans;     cin >> ans;     for (i = 0; i <= 10; i++) {       t[0][i] = 1;     }     for (i = 1; i < 1000009; i++) {       for (j = 1; j <= 10; j++) {         x = (i - j >= 0) ? t[i - j][j] : 0;         y = (j > 1) ? t[i][j - 1] : 0;         t[i][j] = x + y;         if (t[i][j] == ans) {           break;         }       }       if (j < 11) break;     }     cout << i <<     << j <<   n ;     for (i = 1; i <= j; i++) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fun() {}   long long mod = 1000000000 + 7;   long long powe(long long x, long long y) {     x = x % mod, y = y % (mod - 1);     long long ans = 1;     while (y > 0) {       if (y & 1) {         ans = (1ll * x * ans) % mod;       }       y >>= 1;       x = (1ll * x * x) % mod;     }     return ans;   }   map<pair<long long, long long>, long long> m;   long long ncr(long long n, long long r) { return n * (n - 1) * (n - 2) / 6; }   int32_t main() {     fun();     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t, temp;     long long n, s, k;     cin >> t;     while (t--) {       cin >> n >> s >> k;       long long a[k];       long long i;       long long num;       for (i = 0; i < k; i++) {         cin >> num;         a[i] = num;       }       sort(a, a + k);       long long num1 = INT_MAX, num2 = INT_MAX;       for (i = s; i >= 1; i--) {         if (!binary_search(a, a + k, i)) {           num1 = i;           break;         }       }       for (i = s; i <= n; i++) {         if (!binary_search(a, a + k, i)) {           num2 = i;           break;         }       }       if (num1 == INT_MAX)         cout << num2 - s <<   n ;       else if (num2 == INT_MAX)         cout << s - num1 <<   n ;       else         cout << min(s - num1, num2 - s) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   double x[100010], y[100010], X, Y, mem[100010];   int id[100010], len;   int cmp(int i, int j) {     if (fabs(x[i] - x[j]) > 1e-8) return x[i] < x[j];     return y[i] > y[j];   }   int main() {     int n, i, j, k, A, B, C, D;     scanf( %d %d/%d %d/%d , &n, &A, &B, &C, &D);     for (i = 0; i < n; i++) {       scanf( %lf %lf , &X, &Y);       x[i] = X;       y[i] = Y;       if (C && D) x[i] -= Y / C * D;       if (A && B) y[i] -= X / B * A;       id[i] = i;     }     sort(id, id + n, cmp);     len = 0;     for (i = 0; i < n; i++)       if (x[id[i]] > 0 && y[id[i]] > 0) {         k = lower_bound(mem, mem + len, y[id[i]] - 1e-8) - mem;         if (k == len) len++;         mem[k] = y[id[i]];       }     printf( %d n , len);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   const long long L = 1e5 + 5;   long long arr[L];   long long bo[L];   long long gi[L];   long long bg[L];   priority_queue<long long> val;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long i, b, g;     cin >> b >> g;     long long ans = 0;     long long x = -1e18, y = 1e18;     for (i = 0; i < b; i++) {       bg[i] = 1;       cin >> bo[i];       arr[i] = g - 1;       ans += bo[i];       x = max(bo[i], x);     }     for (i = 0; i < g; i++) {       cin >> gi[i];       ans += gi[i];       val.push(gi[i]);       y = min(gi[i], y);     }     if (y < x) {       cout << -1 << endl;       return 0;     }     sort(bo, bo + b);     i = b - 1;     while (!val.empty() && i >= 0) {       if (val.top() >= bo[i]) {         if (arr[i] == 0) {           if (bo[i] == val.top()) {             ans -= bo[i];             val.pop();           }           i--;           continue;         }         arr[i]--;         val.pop();       } else         i--;     }     for (i = 0; i < b; i++) ans += arr[i] * bo[i];     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 111;   int a[maxn];   int getid[maxn];   int b[maxn];   int lpos[maxn];   vector<int> savepos[maxn];   vector<int> G[maxn];   vector<int> v;   int n, m, q;   int vis[maxn];   void dfs(int pos, int fa) {     v.push_back(pos);     vis[pos] = 1;     if (v.size() >= n) {       int id = v.size() - n;       lpos[pos] = v[id];     }     for (int d : G[pos]) {       if (d == fa) continue;       dfs(d, pos);     }     v.pop_back();   }   int main() {     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       getid[a[i]] = i;     }     for (int i = 1; i <= m; i++) {       scanf( %d , &b[i]);       savepos[b[i]].push_back(i);     }     for (int i = 1; i <= m; i++) {       int nowval = b[i];       int preid = getid[nowval] - 1;       if (!preid) preid = n;       int preval = a[preid];       int id = lower_bound(savepos[preval].begin(), savepos[preval].end(), i) -                savepos[preval].begin() - 1;       if (id >= 0) {         G[savepos[preval][id]].push_back(i);       }       savepos[nowval].push_back(i);     }     for (int i = 1; i <= m; i++) {       if (!vis[i]) {         v.clear();         dfs(i, -1);       }     }     int p = 0;     for (int i = 1; i <= m; i++) {       lpos[i] = max(lpos[i - 1], lpos[i]);     }     while (q--) {       int l, r;       scanf( %d %d , &l, &r);       if (l <= lpos[r]) {         cout << 1;       } else {         cout << 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int flag[100005];   int ok, a[100005], b[100005], vis[100005];   vector<int> G[100005];   void Sech(int u, int p) {     int i, v;     vis[u] = 1;     if (flag[u] == 1) ok = -1;     flag[u] = -1;     for (i = 0; i < G[u].size(); i++) {       v = G[u][i];       if (v == p || vis[v]) continue;       Sech(v, u);     }   }   int main(void) {     ok = 1;     int n, m, i, j, len2, len1, ans;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) {       if (i == 1) {         scanf( %d , &len2);         for (j = 1; j <= len2; j++) scanf( %d , &b[j]);         continue;       }       for (j = 1; j <= len2; j++) a[j] = b[j];       len1 = len2;       scanf( %d , &len2);       for (j = 1; j <= len2; j++) scanf( %d , &b[j]);       for (j = 1; j <= min(len1, len2); j++) {         if (a[j] < b[j]) {           G[b[j]].push_back(a[j]);           break;         } else if (a[j] > b[j]) {           if (flag[a[j]] == 1 || flag[b[j]] == -1) ok = -1;           flag[a[j]] = -1, flag[b[j]] = 1;           break;         }       }       if (len1 > len2 && j == len2 + 1) {         printf( No n );         return 0;       }     }     if (ok == -1) {       printf( No n );       return 0;     }     for (i = 1; i <= m; i++) {       if (vis[i] == 0 && flag[i] == -1) Sech(i, -1);       if (ok == -1) break;     }     if (ok == -1) {       printf( No n );       return 0;     }     printf( Yes n );     ans = 0;     for (i = 1; i <= m; i++) {       if (flag[i] == -1) ans++;     }     printf( %d n , ans);     for (i = 1; i <= m; i++) {       if (flag[i] == -1) printf( %d  , i);     }     if (ans != 0) printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int toint(char a) { return (a -  0 ); }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tst;     cin >> tst;     while (tst--) {       string a, s;       cin >> a >> s;       long long int num = stoll(a);       long long int sum = stoll(s);       if (s.length() < a.length()) {         cout <<  -1 n ;       } else if (a.length() == s.length()) {         bool no = false;         for (int i = s.length() - 1; i >= 0; i--) {           if ((toint(s[i]) - toint(a[i])) < 0) {             cout <<  -1 n ;             no = true;             break;           }         }         if (!no) {           cout << stoll(s) - stoll(a) <<   n ;         }       } else if (a.length() < s.length()) {         int lastdigit;         int lastsub;         string ans;         bool no = 0;         int strlen = s.length();         while (strlen > 0) {           lastsub = num % 10;           if (sum % 10 - num % 10 < 0) {             lastdigit = (sum % 10) + ((sum % 100) - (sum % 10));             sum /= 100;             num /= 10;             strlen -= 2;           } else {             lastdigit = sum % 10;             sum /= 10;             num /= 10;             strlen--;           }           if (lastdigit - lastsub >= 0 && lastdigit - lastsub <= 9) {             if (strlen != 0) {               ans = to_string(lastdigit - lastsub) + ans;             } else {               if (lastdigit - lastsub != 0) {                 ans = to_string(lastdigit - lastsub) + ans;               }             }           } else {             cout <<  -1 n ;             no = true;             break;           }         }         if (!no) {           cout << ans <<   n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100001], i, l, r, n, j, c44, c1, c4, c, x, ans, h, y, m, step[101],       v, b[100500], d[100500];   string s;   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b + 1, b + n + 1);     for (i = 1; i <= n; i++) {       if (l <= b[i]) {         c++;         l += b[i];       }     }     cout << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000030;   int num[MAXN];   int a[MAXN], b[MAXN];   int dex[MAXN];   int res[MAXN];   int bsch(int le, int ri, int key) {     int l = le, r = ri;     while (l <= r) {       int m = (l + r) / 2;       if (res[m] == key)         return m;       else if (res[m] > key)         r = m - 1;       else         l = m + 1;     }     return l;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);       dex[b[i]] = i;     }     for (int i = 1; i <= n; i++) {       num[i] = dex[a[i]];     }     for (int i = 1; i <= n / 2; i++) {       swap(num[i], num[n - i + 1]);     }     for (int i = 1; i <= n; i++) {       res[i] = 1 << 30;     }     int maxv = 1;     res[1] = num[1];     for (int i = 2; i <= n; i++) {       int s = bsch(1, n, num[i]);       res[s] = num[i];       if (maxv < s) maxv = s;     }     printf( %d n , maxv);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int n, m, num[40][40], len = 0, stat[20], sv[20], ans = 0;   bool vis[10][10], vis2[10][10], usedr[10], have = false;   string s[40];   vector<pair<int, int> > coo[400];   vector<int> pr[20];   bool stane = false;   bool check(int pos) {     map<pair<int, int>, int> mp;     mp.clear();     for (int i = 0; i < pr[pos].size(); ++i) {       int x = stat[pos], y = stat[pr[pos][i]];       if (vis[x][y] || mp[make_pair(x, y)]) return false;       mp[make_pair(x, y)] = mp[make_pair(y, x)] = true;     }     return true;   }   void add(int pos, bool val) {     for (int i = 0; i < pr[pos].size(); ++i) {       int x = stat[pos], y = stat[pr[pos][i]];       vis[x][y] = vis[y][x] = val;     }   }   void dfs(int pos, int curc) {     if (pos == 14) {       ++ans;       if (!have) {         have = true;         for (int i = 0; i < 14; ++i) sv[i] = stat[i];       }       return;     }     if (curc < 7) {       stat[pos] = curc;       if (check(pos)) {         add(pos, true);         dfs(pos + 1, curc + 1);         add(pos, false);       }     }     for (int i = 0; i < curc; ++i) {       if (usedr[i]) continue;       stat[pos] = i;       if (check(pos)) {         usedr[i] = true;         add(pos, true);         dfs(pos + 1, curc);         usedr[i] = false;         add(pos, false);       }     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> s[i];       for (int j = 0; j < m; ++j)         if (s[i][j] ==  A )           s[i][j] =  z  + 1;         else if (s[i][j] ==  B )           s[i][j] =  z  + 2;     }     for (int i = 0; i < n + 5; ++i)       for (int j = 0; j < m + 5; ++j) num[i][j] = -1;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if ( a  <= s[i][j] && s[i][j] <=  z  + 2) {           coo[s[i][j]].push_back(make_pair(i, j));           if (num[i][j] == -1) {             for (int k = i; k < i + 2; ++k)               for (int p = j; p < j + 2; ++p) num[k][p] = len;             ++len;           }         }     for (int i =  a ; i <=  z  + 2; ++i) {       int x = coo[i][0].first, y = coo[i][0].second, xx = coo[i][1].first,           yy = coo[i][1].second;       pr[max(num[x][y], num[xx][yy])].push_back(min(num[x][y], num[xx][yy]));     }     dfs(0, 0);     cout << ans * 5040 << endl;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (!( a  <= s[i][j] && s[i][j] <=  z  + 2))           cout <<  . ;         else           cout << sv[num[i][j]];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int m, k;     cin >> m >> k;     if (m % 2 == 0) {       printf( %d n , m + k * 2);     } else {       int t;       for (int i = 3; i <= m; i += 2) {         if (m % i == 0) {           t = i;           break;         }       }       k--;       m += t;       printf( %d n , m + k * 2);     }   }   int main() {     int n;     cin >> n;     while (n--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long m = 1e9 + 7;   double eps = 1e-6;   bool good[256];   long long n, spos = -1;   int main(int argc, char *argv[]) {     ios::sync_with_stdio(0);     string g, pat;     cin >> g;     cin >> pat;     cin >> n;     for (int i = 0; (i) < (256); ++i) good[i] = false;     for (int i = 0; (i) < (((int)(pat).size())); ++i)       if (pat[i] ==  * ) spos = i;     for (int i = 0; (i) < (((int)(g).size())); ++i) {       good[int(g[i])] = true;     }     for (int i = 0; (i) < (n); ++i) {       string s;       bool pass = true;       cin >> s;       if (spos == -1) {         if (((int)(pat).size()) != ((int)(s).size()))           cout <<  NO  << endl;         else {           for (int j = 0; (j) < (((int)(pat).size())); ++j) {             if (pat[j] !=  ?  && pat[j] != s[j])               pass = false;             else if (pat[j] ==  ?  && !good[int(s[j])])               pass = false;           }           if (pass)             cout <<  YES  << endl;           else             cout <<  NO  << endl;         }       } else {         if (((int)(s).size()) - ((int)(pat).size()) < -1)           cout <<  NO  << endl;         else {           long long offset = ((int)(s).size()) - ((int)(pat).size());           for (int j = 0; (j) < (spos); ++j) {             if (pat[j] !=  ?  && pat[j] != s[j])               pass = false;             else if (pat[j] ==  ?  && !good[int(s[j])])               pass = false;           }           for (long long j = spos + 1 + offset; j < ((int)(s).size()); j++) {             if (pat[j - offset] !=  ?  && pat[j - offset] != s[j])               pass = false;             else if (pat[j - offset] ==  ?  && !good[int(s[j])])               pass = false;           }           for (long long j = spos; j <= spos + offset; j++)             if (good[int(s[j])]) pass = false;           if (pass)             cout <<  YES  << endl;           else             cout <<  NO  << endl;         }       }     }     return 0;   }