malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   struct edge {     int v, next;   } e[200010];   int ecnt = 0, head[100010];   int n;   int d[100010];   int leg[100010];   void addedge(int a, int b) {     e[++ecnt].v = b;     e[ecnt].next = head[a];     head[a] = ecnt;   }   void del(int x) {     while (d[x] <= 2) {       d[x] = 0;       int xx = x;       for (int i = head[x]; ~i; i = e[i].next) {         if (d[e[i].v]) {           x = e[i].v;           break;         }       }       if (x == xx) break;     }     leg[x]++;   }   bool solve() {     for (int i = (1); i <= (n); i++) {       if (d[i]) {         int cnt = 0;         for (int j = head[i]; ~j; j = e[j].next) {           int v = e[j].v;           if (d[v]) {             if (leg[v] > 2)               cnt++;             else if (d[v] - leg[v] > 1)               cnt++;           }         }         if (cnt > 2) return false;       }     }     return true;   }   int main() {     cin >> n;     memset((head), (-1), sizeof(head));     memset((d), (0), sizeof(d));     memset((leg), (0), sizeof(leg));     for (int i = (1); i <= (n - 1); i++) {       int u, v;       scanf( %d%d , &u, &v);       addedge(u, v);       addedge(v, u);       d[u]++;       d[v]++;     }     for (int i = (1); i <= (n); i++) {       if (d[i] == 1) del(i);     }     puts(solve() ?  Yes  :  No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 9;   int n, a[N];   struct pp {     int val, id;   } p[N];   bool cmp(pp x, pp y) { return x.val < y.val; }   int f[N], siz[N], vis[N];   int find(int x) { return x == f[x] ? x : (f[x] = find(f[x])); }   bool merge(int u, int v) {     if (!vis[u] || !vis[v]) return 0;     int fu = find(u), fv = find(v);     if (fu == fv) return 0;     f[fu] = fv;     siz[fv] += siz[fu];     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) p[i].val = a[i], p[i].id = i;     sort(p + 1, p + n + 1, cmp);     for (int i = 1; i <= n; i++) f[i] = i, siz[i] = 1;     int mx = 0, cnt = 0, ans = 1, num = 0;     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; i++) {       cnt++;       int x = p[i].id;       vis[x] = 1;       if (x < n && merge(x, x + 1)) cnt--;       if (x > 1 && merge(x, x - 1)) cnt--;       int fa = find(x);       mx = max(mx, siz[fa]);       if (1ll * cnt * mx == i) {         if (cnt > num) num = cnt, ans = p[i].val + 1;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   vector<int> a[MAXN];   int n, tot, father[MAXN], p[MAXN], ans[MAXN];   void work(int pos, int fa) {     father[pos] = fa;     for (unsigned i = 0; i < a[pos].size(); i++)       if (a[pos][i] != fa) work(a[pos][i], pos);     p[++tot] = pos;   }   int f(int x) {     if (ans[x] != -1) return ans[x];     static int res[MAXN];     int tans = 0;     for (int i = 1; i <= n; i++) {       int Max = 1, Nax = 1, pos = p[i];       for (unsigned i = 0; i < a[pos].size(); i++)         if (a[pos][i] != father[pos]) {           int tmp = res[a[pos][i]] + 1;           if (tmp > Max) {             Nax = Max;             Max = tmp;           } else             chkmax(Nax, tmp);         }       if (Max + Nax - 1 >= x)         tans++, res[pos] = 0;       else         res[pos] = Max;     }     return ans[x] = tans;   }   int main() {     read(n);     for (int i = 1; i <= n - 1; i++) {       int x, y;       read(x), read(y);       a[x].push_back(y);       a[y].push_back(x);     }     work(1, 0);     memset(ans, -1, sizeof(ans));     for (int i = 1, nxt; i <= n; i = nxt + 1) {       int now = f(i);       if (now >= 65 || f(i + 1) != now) {         ans[nxt = i] = now;         continue;       }       int l = i + 1, r = n;       while (l < r) {         int mid = (l + r + 1) / 2;         if (f(mid) == now)           l = mid;         else           r = mid - 1;       }       nxt = l;       for (int j = i; j <= nxt; j++) ans[j] = now;     }     for (int i = 1; i <= n; i++) writeln(ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 250005;   int n, m, k, dep[maxn], fa[maxn];   bool leaf[maxn], vis[maxn];   vector<int> e[maxn];   void dfs(int p) {     leaf[p] = vis[p] = 1;     for (int i = 0, v; i < e[p].size(); ++i) {       if (vis[v = e[p][i]]) continue;       leaf[p] = 0;       dep[v] = dep[p] + 1;       fa[v] = p;       dfs(v);     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1, u, v; i <= m; ++i) {       scanf( %d%d , &u, &v);       e[u].push_back(v), e[v].push_back(u);     }     dep[1] = 1, dfs(1);     int tmp = (n + k - 1) / k;     for (int i = 1; i <= n; ++i) {       if (dep[i] >= tmp) {         printf( PATH n );         printf( %d n , dep[i]);         while (i) {           printf( %d  , i);           i = fa[i];         }         return 0;       }     }     printf( CYCLES n );     vector<int> pos;     for (int i = 1; i <= n && pos.size() < k; ++i)       if (leaf[i]) pos.push_back(i);     for (int i = 1; i <= k; ++i) {       bool f = 0;       int p = pos[i - 1];       for (int j = 0, v; j < e[p].size(); ++j) {         v = e[p][j];         if (v != fa[p] && (dep[p] - dep[v] + 1) % 3) {           printf( %d n , dep[p] - dep[v] + 1);           f = 1;           while (fa[p] != fa[v]) {             printf( %d  , p);             p = fa[p];           }           printf( %d n , p);           break;         }       }       if (f) continue;       vector<int> bad;       for (int j = 0, v; j < e[p].size() && bad.size() < 2; ++j)         if ((v = e[p][j]) != fa[p]) bad.push_back(v);       int x = bad[0], y = bad[1];       if (dep[x] > dep[y]) swap(x, y);       printf( %d n , dep[y] - dep[x] + 2);       printf( %d  , p);       while (fa[x] != fa[y]) {         printf( %d  , y);         y = fa[y];       }       printf( %d n , y);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using i64 = long long;   const int N = 2e5 + 5;   struct Nod {     i64 sum;     int max_pos, max_pos2;   };   Nod pom[N * 4];   int v[N];   int n, q, update_pos, update_val, current_pos;   i64 query_sum, peak_sum;   static void pom_build(int nod, int l, int r) {     if (l == r) {       pom[nod] = {v[l], l, n + 1};       return;     }     int med = (l + r) / 2;     pom_build(2 * nod, l, med);     pom_build(2 * nod + 1, med + 1, r);     pom[nod].sum = pom[2 * nod].sum + pom[2 * nod + 1].sum;     if (v[pom[2 * nod].max_pos] > v[pom[2 * nod + 1].max_pos]) {       pom[nod].max_pos = pom[2 * nod].max_pos;       pom[nod].max_pos2 = v[pom[2 * nod].max_pos2] > v[pom[2 * nod + 1].max_pos]                               ? pom[2 * n].max_pos2                               : pom[2 * nod + 1].max_pos;     } else {       pom[nod].max_pos = pom[2 * nod + 1].max_pos;       pom[nod].max_pos2 = pom[2 * nod + 1].max_pos2;     }   }   static void internal_update(int nod, int l, int r) {     if (l == r) {       pom[nod].sum = update_val;       return;     }     int med = (l + r) / 2;     if (update_pos <= med)       internal_update(2 * nod, l, med);     else       internal_update(2 * nod + 1, med + 1, r);     pom[nod].sum = pom[2 * nod].sum + pom[2 * nod + 1].sum;     if (v[pom[2 * nod].max_pos] > v[pom[2 * nod + 1].max_pos]) {       pom[nod].max_pos = pom[2 * nod].max_pos;       pom[nod].max_pos2 = v[pom[2 * nod].max_pos2] > v[pom[2 * nod + 1].max_pos]                               ? pom[2 * n].max_pos2                               : pom[2 * nod + 1].max_pos;     } else {       pom[nod].max_pos = pom[2 * nod + 1].max_pos;       pom[nod].max_pos2 = pom[2 * nod + 1].max_pos2;     }   }   static int find_peak(int nod, int l, int r) {     if (l == r) return l;     if (v[pom[1].max_pos] == 0) return n >= 2 ? 2 : -1;     int med = (l + r) / 2;     if (current_pos < med && (pom[2 * nod].max_pos != current_pos                                   ? v[pom[2 * nod].max_pos]                                   : v[pom[2 * nod].max_pos2]) >= query_sum)       return find_peak(2 * nod, l, med);     else if (current_pos < r &&              (pom[2 * nod + 1].max_pos != current_pos                   ? v[pom[2 * nod + 1].max_pos]                   : v[pom[2 * nod + 1].max_pos2]) >= query_sum) {       peak_sum += pom[2 * nod].sum;       return find_peak(2 * nod + 1, med + 1, r);     } else       return -1;   }   static void update(int pos, int val) {     update_val = val;     update_pos = pos;     v[pos] = val;     internal_update(1, 1, n);   }   static int query() {     int pos = 0;     peak_sum = 0;     query_sum = 0;     current_pos = 0;     while ((pos = find_peak(1, 1, n)) != -1) {       query_sum = peak_sum + v[pos];       if (peak_sum == v[pos]) return pos;       current_pos = pos;       peak_sum = 0;     }     return -1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int pos, val;     cin >> n >> q;     for (int i = 1; i <= n; ++i) cin >> v[i];     pom_build(1, 1, n);     while (q--) {       cin >> pos >> val;       update(pos, val);       cout << query() <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const long long mod = 998244353;   long long binpow(long long a, long long n) {     if (n == 0) return 1;     if (n % 2 != 0)       return binpow(a, n - 1) * a;     else {       long long b = binpow(a, n / 2);       return b * b;     }   }   long long gcd(long long a, long long b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   bool check(vector<int> a, vector<int> b) {     for (int i = 0; i < 26; i++)       if (b[i] > a[i]) return false;     return true;   }   void solve() {     int n, m, k;     cin >> n >> m >> k;     if (m < n || k < n)       cout <<  No  << endl;     else       cout <<  Yes  << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long mod = 1e9 + 7;   long long ExtendedEuclid(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long g = ExtendedEuclid(b, a % b, x, y);     long long nx = y, ny = x - a / b * y;     x = nx;     y = ny;     return g;   }   long long modInverse(long long x, long long m) {     long long a, q;     ExtendedEuclid(x, m, a, q);     if (a < 0) {       a = a + (abs(a) + m - 1) / m * m;     }     return a;   }   long long n, m, q;   vector<vector<set<long long>>> adj;   void solve(int testcase) {     cin >> n >> m;     adj = vector<vector<set<long long>>>(n, vector<set<long long>>(2));     for (long long i = 0; i < m; i++) {       long long u, v;       cin >> u >> v;       u--;       v--;       adj[u][(v > u)].insert(v);       adj[v][(u > v)].insert(u);     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (adj[i][1].size() == 0) ans++;     }     cin >> q;     while (q--) {       long long op;       cin >> op;       if (op == 3) {         cout << ans <<   n ;       } else if (op == 1) {         long long u, v;         cin >> u >> v;         u--;         v--;         if (u > v) swap(u, v);         if (adj[u][1].size() == 0) ans--;         adj[u][(v > u)].insert(v);         adj[v][(u > v)].insert(u);       } else if (op == 2) {         long long u, v;         cin >> u >> v;         u--;         v--;         if (u > v) swap(u, v);         if (adj[u][1].size() == 1) ans++;         adj[u][(v > u)].erase(adj[u][(v > u)].find(v));         adj[v][(u > v)].erase(adj[v][(u > v)].find(u));       }     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 0;     solve(t);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC diagnostic ignored  -Wmissing-declarations    inline int safe_mul(const int x, const int y)       __attribute__((warn_unused_result));   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     int c = (n - k) / 2;     string ans;     for (int i = 0; i < n; ++i) ans.push_back( 0  + (i % (c + 1) < c));     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 123456;   const int mod = 1e9 + 7;   class table {    public:     int id;     int size;   };   class group {    public:     int id;     int size;     int income;   };   bool byIncome(const group &r1, const group &r2) {     return r1.income > r2.income;   }   bool bySize(const table &t1, const table &t2) { return t1.size < t2.size; }   bool canFit(table &t, const group &g) { return t.size < g.size; }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<group> groups(n);     for (int i = 0; i < n; i++) {       groups[i].id = i + 1;       cin >> groups[i].size >> groups[i].income;     }     int k;     cin >> k;     vector<table> tables(k);     for (int i = 0; i < k; i++) {       tables[i].id = i + 1;       cin >> tables[i].size;     }     sort(groups.begin(), groups.end(), byIncome);     sort(tables.begin(), tables.end(), bySize);     int sum = 0;     vector<pair<int, int> > v;     for (int i = 0; i < n; i++) {       group g = groups[i];       vector<table>::iterator t =           lower_bound(tables.begin(), tables.end(), g, canFit);       if (t == tables.end()) {         continue;       }       sum += g.income;       v.push_back(make_pair(g.id, t->id));       tables.erase(t);     }     cout << v.size() <<     << sum << endl;     for (int i = 0; i < v.size(); i++) {       cout << v[i].first <<     << v[i].second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, limak;     cin >> n;     int len = n - 1;     cin >> limak;     int array[n - 1];     for (int i = 0; i < len; i++) cin >> array[i];     sort(array, array + len);     int cnt = 0;     while (array[len - 1] >= limak) {       cnt++;       limak++;       array[len - 1]--;       sort(array, array + len);     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc;     cin >> tc;     while (tc--) {       long long int n, k;       cin >> n >> k;       long long int a[n], m = INT_MIN;       for (long long int i = 0; i < n; i++) {         cin >> a[i];         m = max(m, a[i]);       }       long long int ans[n];       if (k & 1) {         for (long long int i = 0; i < n; i++) cout << m - a[i] <<    ;       } else {         long long int d = INT_MIN;         for (long long int i = 0; i < n; i++) {           a[i] = m - a[i];           d = max(d, a[i]);         }         for (long long int i = 0; i < n; i++) cout << d - a[i] <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     return os <<  (  << p.first <<  ,   << p.se <<  ) ;   }   template <typename T1, typename T2>   inline ostream& operator<<(ostream& os, const map<T1, T2>& c) {     bool first = true;     os <<  [ ;     for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) {       if (!first) os <<  ,  ;       os << *it;       first = false;     }     return os <<  ] ;   }   template <typename T>   inline ostream& operator<<(ostream& os, const vector<T>& v) {     bool first = true;     os <<  [ ;     for (long long i = (0); i <= (((int)(v).size()) - 1); i += (1)) {       if (!first) os <<  ,  ;       os << v[i];       first = false;     }     return os <<  ] ;   }   template <typename T>   inline ostream& operator<<(ostream& os, const set<T>& c) {     bool first = true;     os <<  [ ;     for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) {       if (!first) os <<  ,  ;       os << *it;       first = false;     }     return os <<  ] ;   }   const int dx4[] = {-1, 0, 0, +1};   const int dx8[] = {-1, -1, -1, 0, 0, +1, +1, +1};   const int dy4[] = {0, -1, +1, 0};   const int dy8[] = {-1, 0, +1, -1, +1, -1, 0, +1};   unsigned long long m;   bool first;   vector<int> r, l;   int main() {     int(n);     scanf( %d , &(n));     cin >> m;     cerr << ( m ) <<   =   << (m) << endl;     m--;     r.push_back(n);     n--;     for (long long i = (0); i <= (n - 1); i += (1))       if (m & (1LL << i))         r.push_back(n - i);       else         l.push_back(n - i);     bool first = true;     for (long long i = (((int)(l).size()) - 1); i >= (0); i -= (1)) {       if (!first) cout <<    ;       first = false;       cout << l[i];     }     for (long long i = (0); i <= (((int)(r).size()) - 1); i += (1)) {       if (!first) cout <<    ;       first = false;       cout << r[i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     int mat[n + 1][m + 1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &mat[i][j]);       }     }     vector<int> dp(n + 1, 0);     for (int j = 1; j <= m; j++) {       vector<int> dp2(n + 1, 0);       for (int k = n - 1; k >= 1; k--) {         if (mat[k][j] <= mat[k + 1][j]) dp2[k] = 1 + dp2[k + 1];       }       for (int i = 1; i <= n; i++) dp[i] = max(dp[i], dp2[i]);     }     int q, l, r;     scanf( %d , &q);     while (q--) {       scanf( %d , &l);       scanf( %d , &r);       if (l + dp[l] >= r)         printf( Yes );       else         printf( No );       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   inline int max(int a, int b) { return a > b ? a : b; }   map<int, int> mp;   int a[200005], id;   inline int read(int x) {     if (mp.count(x) > 0) return mp[x];     mp[x] = ++id;     return id;   }   int main() {     int n;     scanf( %d , &n);     int x;     for (int i = 1; i <= n; ++i) {       scanf( %d , &x);       ++a[read(x)];     }     sort(a + 1, a + 1 + id);     int ans = 0, last, now, pos;     for (int i = 1; i <= n; ++i) {       last = 1;       now = 0;       for (int k = i; k <= n; k <<= 1) {         pos = lower_bound(a + last, a + id + 1, k) - a;         if (pos > id) break;         now += k;         last = pos + 1;       }       ans = max(ans, now);     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     int ans = b / a;     if (b % a) {       cout <<  -1  << endl;       return 0;     }     int cnt = 0;     while (ans % 2 == 0) {       ans = ans / 2;       cnt++;     }     while (ans % 3 == 0) {       ans = ans / 3;       cnt++;     }     if (ans == 1)       cout << cnt << endl;     else       cout <<  -1  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int N = 2e2 + 10, M = 1e6 + 10;   const int alp = 10;   vector<pair<int, int> > pos;   pair<int, int> s[M];   int n, m, q, a[N][N], f[N][N], h[N][N], len[N][N], dx[10], dy[10], deg[N][N],       g[M];   string str;   bool check(int x, int y) { return x > 0 && x <= n && y > 0 && y <= m; }   void DFS(int sx, int sy) {     int top = 1, spe = 0;     int v = 0;     s[1] = pair<int, int>(sx, sy);     while (!spe) {       int cx = s[top].first, cy = s[top].second;       h[cx][cy] = top;       int nx = cx + dx[a[cx][cy]], ny = cy + dy[a[cx][cy]];       if (!check(nx, ny))         spe = top;       else {         if (f[nx][ny]) {           spe = top + 1;           v = f[nx][ny];           s[top + 1] = pair<int, int>(nx, ny);           break;         }         if (!h[nx][ny])           s[++top] = pair<int, int>(nx, ny);         else           spe = h[nx][ny];       }     }     for (auto i = spe; i <= top; i++) v |= (1 << (a[s[i].first][s[i].second]));     for (auto i = 1; i <= top; i++) f[s[i].first][s[i].second] = v;     for (auto i = spe - 1; i >= 1; i--)       len[s[i].first][s[i].second] = len[s[i + 1].first][s[i + 1].second] + 1;   }   void prepare() {     cin >> n >> m >> q;     for (auto i = 1; i <= n; i++) {       cin >> str;       for (auto j = 1; j <= m; j++) a[i][j] = str[j - 1] -  0 ;     }     for (auto i = 0; i < alp; i++) cin >> dx[i] >> dy[i];     for (auto i = 1; i <= n; i++)       for (auto j = 1; j <= m; j++) {         int nx = i + dx[a[i][j]], ny = j + dy[a[i][j]];         if (check(nx, ny)) deg[nx][ny]++;       }     for (auto i = 1; i <= n; i++)       for (auto j = 1; j <= m; j++)         if (!deg[i][j]) {           DFS(i, j);           pos.push_back(pair<int, int>(i, j));         }     for (auto i = 1; i <= n; i++)       for (auto j = 1; j <= m; j++)         if (!f[i][j]) {           DFS(i, j);           pos.push_back(pair<int, int>(i, j));         }   }   string solve() {     int n1 = str.length();     g[n1] = 0;     for (auto i = n1 - 1; i >= 0; i--) g[i] = g[i + 1] | (1 << (str[i] -  0 ));     for (auto x : pos) {       int cur = 0;       pair<int, int> cx = x;       while (cur < n1 && len[cx.first][cx.second]) {         int v = a[cx.first][cx.second];         if (str[cur] -  0  == v) cur++;         int nx = cx.first + dx[v], ny = cx.second + dy[v];         cx = pair<int, int>(nx, ny);       }       if ((g[cur] & f[cx.first][cx.second]) == g[cur]) return  YES ;     }     return  NO ;   }   int main() {     prepare();     while (q--) {       cin >> str;       cout << solve() <<   n ;     }   }