malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<set<int> > A;   set<int>::iterator it;   int main() {     int n, m, a;     cin >> n;     A.resize(n);     int D[101];     for (int i = 1; i <= 100; ++i) D[i] = 0;     for (int i = 0; i < n; ++i) {       cin >> m;       for (int j = 0; j < m; ++j) {         cin >> a;         ++D[a];         A[i].insert(a);       }     }     for (int i = 0; i < n; ++i) {       bool yes = 1;       for (int j = 0; j < n; ++j) {         if (i != j) {           bool y = 0;           for (it = A[j].begin(); it != A[j].end(); ++it)             if (A[i].count(*it) == 0) y = 1;           if (y == 0) yes = 0;         }       }       if (yes)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   int main() {     int n, a[1010], temp, lamak, maxin, max, i, j;     long int count;     while (scanf( %d , &n) != EOF) {       count = 0;       for (i = 0; i < n; i++) {         scanf( %d , &a[i]);       }     again:       max = 0;       for (i = 0; i < n; i++) {         if (a[i] >= max) {           max = a[i];           maxin = i;         }       }       if (max > a[0]) {         a[maxin] = a[maxin] - 1;         a[0] = a[0] + 1;         count = count + 1;         goto again;       }       if (max == a[0] && maxin != 0) {         a[maxin] = a[maxin] - 1;         a[0] = a[0] + 1;         count = count + 1;         printf( %ld n , count);       } else {         printf( %ld n , count);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char s[1007][1007];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> s[i][j];       }     }     if (n < 3) {       cout <<  0 ;     } else {       int res = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (s[i][j] ==  X  && s[i - 1][j + 1] ==  X  &&               s[i + 1][j - 1] ==  X  && s[i - 1][j - 1] ==  X  &&               s[i + 1][j + 1] ==  X ) {             res++;           }         }       }       cout << res;     }     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:336777216 )   using namespace std;   int IT_MAX = 1 << 17;   const long long MOD = 1000000009;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1);   const double ERR = 1e-8;   vector<pair<long long, long long> > Vu;   int main() {     int N, K, M, i, j;     scanf( %d %d %d , &N, &K, &M);     for (i = 1; i <= N; i++) {       int t;       scanf( %d , &t);       if (!Vu.empty() && Vu.back().first == t) {         Vu.back().second++;         if (Vu.back().second == K) Vu.pop_back();       } else         Vu.emplace_back(t, 1);     }     long long s = 0;     for (auto it : Vu) s += it.second;     if (M == 1 || s == 0) return !printf( %lld n , s);     s *= M;     int st = 0, en = (int)Vu.size() - 1;     while (st < en) {       if (Vu[st].first != Vu[en].first) return !printf( %lld n , s);       if (Vu[st].second + Vu[en].second == K) {         s -= (long long)(M - 1) * K;         st++, en--;         continue;       }       if (Vu[st].second + Vu[en].second > K) s -= (long long)(M - 1) * K;       return !printf( %lld n , s);     }     long long x = Vu[st].second * M;     if (x % K == 0) {       return !printf( 0 n );     } else {       return !printf( %lld n , s - (x / K) * K);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MXN = 1e5 + 1;   const int MAXN = 1e3 + 1;   const long long INF = 1e16;   const int MOD = 65000;   const int MAX = 1e2;   const double EPS = 1e-9;   long long n;   long long a, b, c, d, e, first, g, h;   int main() {     ios_base::sync_with_stdio(0);     string second;     cin >> second;     for (int i = 0; i < second.size(); ++i) {       if (second[i] ==  B ) ++a;       if (second[i] ==  u ) ++b;       if (second[i] ==  l ) ++c;       if (second[i] ==  b ) ++d;       if (second[i] ==  a ) ++e;       if (second[i] ==  s ) ++first;       if (second[i] ==  u ) ++g;       if (second[i] ==  r ) ++h;     }     g = g / 2;     e = e / 2;     cout << min(a, min(b, min(c, min(d, min(e, min(first, min(g, h)))))));     return 0;   }
#include <iostream>   #include <vector>   #include <algorithm>   using namespace std;      int main() {    int testCase;     cin >> testCase;    while (testCase--) {     vector<int> balls;     int ball;     cin >> ball;     while (ball--) {      int num;      cin >> num;      balls.push_back(num);     }     int maxNum = 1;     int lastNum = balls[0];     int count = 1;     for (int i = 1;i < balls.size();i++) {      if (balls[i] != lastNum) {       lastNum = balls[i];       maxNum = max(count, maxNum);       count = 1;      }      else {       count++;      }     }     maxNum = max(count, maxNum);     cout << maxNum << endl;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2000000005;   const long long INFLL = 1000000000000000009;   const long long MOD = 1000000007;   long long W[1005][1005], N, M, K;   int main() {     for (int i = (1); i <= (1000); i++) W[i][0] = 1;     for (int j = (1); j <= (1000); j++) {       long long s = 0;       for (int i = (3); i <= (1000); i++) {         s = (s + W[i - 2][j - 1]) % MOD;         W[i][j] = (W[i - 1][j] + s) % MOD;       }     }     cin >> N >> M >> K;     cout << (W[N][K] * W[M][K]) % MOD;   }
#include <bits/stdc++.h>   #define int long long      #pragma GCC target ( avx2 )   #pragma GCC optimization ( O3 )   #pragma GCC optimization ( unroll-loops )      /*#include <ext/pb_ds/assoc_container.hpp>   #include <ext/pb_ds/tree_policy.hpp>   using namespace __gnu_pbds;   #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>*/      using namespace std;         signed main() {       //ios_base::sync_with_stdio(0);       //cin.tie(0);       //cout.tie(0);       int n;       cin >> n;       int a[n];       for (int i = 0; i < n; ++i) cin >> a[i];       vector <pair <int, pair <int, int> > > goga;       for (int i = 0; i < n; ++i) {           for (int j = i + 1; j < n; ++j) {               if (a[i] > a[j]) goga.push_back({a[i] - a[j], {i, j}});               else goga.push_back({a[j] - a[i], {j, i}});           }       }       sort(goga.begin(), goga.end());       reverse(goga.begin(), goga.end());       for (int i = 0; i < goga.size(); ++i) {           if (goga[i].first >= 0 && i < goga.size()) {           int first = goga[i].second.first, second = goga[i].second.second;           cout <<  ?   << first + 1 <<     << second + 1 << endl;           string lol;           cin >> lol;           if (lol ==  Yes ) {               cout <<  !   << first + 1 <<     << second + 1 << endl;               return 0;           }           }       }       cout <<  !   << 0 <<     << 0 << endl;       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1004;   int a[N];   int main() {     int n;     scanf( %d , &n);     vector<pair<int, int> > vec;     int i;     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       vec.push_back(make_pair(a[i], i));     }     sort(vec.begin(), vec.end());     reverse(vec.begin(), vec.end());     int ans = 0;     for (i = 0; i < vec.size(); i++) {       ans = ans + (i)*vec[i].first + 1;     }     printf( %d n , ans);     for (i = 0; i < vec.size(); i++) printf( %d  , vec[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ms, type[5005], dp[5005];   int main() {     scanf( %d %d , &n, &ms);     for (int i = 1; i <= n; i++) {       double x;       scanf( %d %lf , type + i, &x);     }     for (int i = 1; i <= n; i++) {       int j = type[i];       for (int k = j; k >= 1; k--) {         dp[j] = max(dp[j], 1 + dp[k]);       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       ans = max(ans, dp[i]);     }     printf( %d n , n - ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char s[105];     cin >> s;     vector<int> a;     string ans =   ;     int j, ct = 0;     for (int i = 0; i <= n - 1;) {       if (s[i] ==  o  && s[i + 1] ==  g  && s[i + 2] ==  o  && i <= n - 3) {         ct = 0;         for (j = i + 3; j < n - 1;) {           if (s[j] ==  g  && s[j + 1] ==  o ) {             ct = 1;             j = j + 2;             i = j;           } else {             i = j;             break;           }         }         i = j;         if (ct == 1) {           ans +=  *** ;         } else {           ans +=  *** ;         }       } else {         ans += s[i];         i++;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 1e5 + 13;   int n, m;   set<int> e[N];   set<pair<int, int> > q;   int p[N];   int tin[N], cnt, w[N], ans;   int gcd(int a, int b) { return (!a ? b : gcd(b % a, a)); }   void init() {     for (int i = 0; i < N; ++i) p[i] = i;   }   int find(int u) {     if (p[u] == u) return u;     return p[u] = find(p[u]);   }   void uni(int a, int b) {     a = find(a);     b = find(b);     if (a == b) return;     if (e[a].size() < e[b].size()) swap(a, b);     for (int to : e[b]) e[a].insert(find(to));     p[b] = a;     e[b].clear();   }   void print(int ans) {     printf( %d n , ans);     exit(0);   }   pair<int, int> getMax() {     auto it = q.end();     --it;     pair<int, int> res = (*it);     return res;   }   void merge(int id) {     if (id != find(id)) return;     vector<int> ver;     for (int v : e[id]) ver.push_back(find(v));     e[id].clear();     for (int i = 0; i < ver.size(); ++i) {       int pi = find(ver[i]);       q.erase(make_pair(e[pi].size(), pi));     }     for (int i = 1; i < ver.size(); ++i) uni(ver[i], ver[i - 1]);     int lv = find(ver[0]);     id = find(id);     e[id].insert(lv);     q.insert(make_pair(e[lv].size(), lv));     q.insert(make_pair(e[id].size(), id));     if (e[id].find(id) != e[id].end()) print(1);   }   void compress() {     for (int i = 0; i < n; ++i) {       q.insert(make_pair(e[i].size(), find(i)));     }     while (true) {       pair<int, int> cur = getMax();       if (cur.first < 2) return;       q.erase(cur);       merge(cur.second);     }   }   void dfs(int u) {     w[u] = 1;     tin[u] = cnt;     ++cnt;     for (int to : e[u]) {       int vt = find(to);       if (!w[vt])         dfs(vt);       else if (w[vt] == 1) {         ans = gcd(ans, tin[u] - tin[vt] + 1);       }     }     w[u] = 2;     --cnt;   }   void solve() {     init();     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d %d , &u, &v);       --u;       --v;       if (u == v) print(1);       e[u].insert(find(v));     }     compress();     for (int i = 0; i < n; ++i)       if (!w[find(i)]) dfs(find(i));     if (ans == 0) ans = n;     printf( %d n , ans);   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sum(int a[], int size) {     int sum = 0;     for (int i = 0; i < size; i++) {       sum = sum + a[i];     }     return sum;   }   int main() {     int n;     cin >> n;     int a1[n], a2[n - 1], a3[n - 3];     for (int i = 0; i < n; i++) {       cin >> a1[i];     }     for (int i = 0; i < n - 1; i++) {       cin >> a2[i];     }     for (int i = 0; i < n - 2; i++) {       cin >> a3[i];     }     cout << sum(a1, n) - sum(a2, n - 1) << endl          << sum(a2, n - 1) - sum(a3, n - 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dir[8][2] = {{1, 0}, {-1, 0}, {0, 1},  {0, -1},                    {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   int main() {     int n, k, p, x, y;     int cntY = 0, a[1100] = {0}, sum = 0;     scanf( %d %d %d %d %d , &n, &k, &p, &x, &y);     for (int i = 1; i <= k; i++) {       scanf( %d , &a[i]);       sum += a[i];       if (a[i] >= y) cntY++;     }     int Mid = (n + 1) / 2;     if (cntY >= Mid) {       sum += (n - k);       if (sum > x)         printf( -1 n );       else {         for (int i = 1; i <= (n - k); i++) printf( 1%c , i == n - k ?   n  :    );       }     } else {       sum += y * (Mid - cntY) + n - k - Mid + cntY;       if (sum > x || k - cntY >= Mid)         printf( -1 n );       else {         for (int i = 1; i <= (Mid - cntY); i++)           printf( %d%c , y, i == n - k ?   n  :    );         for (int i = 1; i <= n - k - Mid + cntY; i++)           printf( 1%c , i == n - k - Mid + cntY ?   n  :    );       }     }     return 0;   }
#include <bits/stdc++.h>   const double PI = acos(-1);   const double EPS = 1e-6;   const long long MOD = 998244353;   const long long N = 30 + 10;   template <typename T>   inline T Abs(T x) {     return x < 0 ? x * -1 : x;   }   template <typename T>   inline T Max(T x, T y, T z) {     return std::max(std::max(x, y), z);   }   template <typename T>   inline T Min(T x, T y, T z) {     return std::min(std::min(x, y), z);   }   template <typename T>   inline void Ckmax(T &x, T y) {     x = std::max(x, y);   }   template <typename T>   inline void Ckmin(T &x, T y) {     x = std::min(x, y);   }   template <typename T>   inline T Sqr(T x) {     return x * x;   }   template <typename T>   inline T Pow(T x, T y) {     T r = 1;     while (y > 0) {       if (y % 2 > 0) (r *= x) %= MOD;       (x *= x) %= MOD;       y /= 2;     }     return r % MOD;   }   template <typename T>   T Pow(T x, T y, T z) {     T r = 1;     while (y > 0) {       if (y % 2 > 0) (r *= x) %= z;       (x *= x) %= z;       y /= 2;     }     return r % z;   }   template <typename T>   inline T gcd(T x, T y) {     return y > 0 ? gcd(y, x % y) : x;   }   template <typename T>   inline T lcm(T x, T y) {     return x / gcd(x, y) * y;   }   inline void cinspu(void) {     std::ios::sync_with_stdio(0);     std::cin.tie(0);   }   inline long long fac(long long x) {     long long r = 1;     for (; x > 1; --x) (r *= x) %= MOD;     return r;   }   int a[N], b[N], ans[N], tim;   int print(char z, int x, int y) {     ++tim;     printf( %c %d %d n , z, x, y);     fflush(stdout);     if (z ==  ? ) {       int r;       scanf( %d , &r);       return r;     }     return -2;   }   int main() {     const char q =  ? ;     for (int i = 29, x = 0, y = 0; i >= 0; --i) {       int n = (1 << i), r;       if (ans[i])         r = ans[i] - 3;       else         r = print(q, x, y);       if (r > 0) {         int p = print(q, x + n, y + n);         if (p > 0) {           int t = print(q, x + n, y);           if (t > 0) {             a[i] = b[i] = 0;             ans[i - 1] = 3 + r;           } else {             a[i] = b[i] = 1;             ans[i - 1] = 3 + p;             x += n;             y += n;           }         } else {           a[i] = 1;           b[i] = 0;           x += n;         }       } else if (r < 0) {         int p = print(q, x + n, y + n);         if (p < 0) {           int t = print(q, x + n, y);           if (t > 0) {             a[i] = b[i] = 0;             ans[i - 1] = 3 + r;           } else {             a[i] = b[i] = 1;             ans[i - 1] = 3 + p;             x += n;             y += n;           }         } else {           a[i] = 0;           b[i] = 1;           y += n;         }       } else {         r = print(q, x + n, y);         if (r > 0) {           a[i] = b[i] = 0;         } else {           a[i] = b[i] = 1;           x += n;           y += n;         }       }     }     int x = 0;     for (int i = 0; i < 30; ++i) x += a[i] * (1 << i);     int y = 0;     for (int i = 0; i < 30; ++i) y += b[i] * (1 << i);     print( ! , x, y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     if (m == 3 && n > 4) {       cout <<  -1  << endl;       return 0;     }     int cnt = 0, ans = 0;     for (int i = 0; i < m; i++) printf( %d %d n , i, ans += (cnt++));     if (m < n) cout << m + 100000 <<     << ans << endl;     for (int i = m + 1; i < n; i++) printf( %d %d n , i + 100000, ans -= (--cnt));     return 0;   }
#include <bits/stdc++.h>   const long long INF = 1e18;   void swap(long long &a, long long &b) {     long long temp;     temp = a;     a = b;     b = temp;   }   using namespace std;   void solve() {     long long n, k, ans;     cin >> n >> k;     ans = n;     for (long long i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i <= k) ans = min(ans, i);         if (i <= k) ans = min(ans, n / i);       }     }     cout << ans;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     cin >> n >> x;     int pos = 1;     long long ans = 0;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       ans += 1LL * (l - pos) % x + (r - l + 1);       pos = r + 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int strike[10010];   bool isIn(long long x, long long y, long long cx, long long cr) {     return (x - cx) * (x - cx) + y * y <= cr * cr;   }   int main() {     int n, m;     cin >> n;     vector<pair<pair<long long, long long>, int> > mish(n + 2);     for (int i = 1; i <= n; i++)       cin >> mish[i].first.first >> mish[i].first.second, mish[i].second = i;     n += 1;     mish[0].first.first = -100000;     mish[0].first.second = 0;     mish[n].first.first = 100000;     mish[n].first.second = 0;     sort(mish.begin(), mish.end());     for (int i = 1; i <= n; i++) strike[i] = -1;     cin >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       int l = 0, r = n;       while (l < r) {         int s = (l + r) / 2 + 1;         if (x < mish[s].first.first)           r = s - 1;         else           l = s;       }       if (strike[mish[l].second] == -1 &&           isIn(x, y, mish[l].first.first, mish[l].first.second))         strike[mish[l].second] = i;       if (strike[mish[l + 1].second] == -1 &&           isIn(x, y, mish[l + 1].first.first, mish[l + 1].first.second))         strike[mish[l + 1].second] = i;     }     int c = 0;     for (int i = 1; i < n; i++)       if (strike[i] != -1) c++;     cout << c << endl;     for (int i = 1; i < n; i++) cout << strike[i] <<    ;   exit:     return (0);   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 2000000000;   const int N = 300005;   int p[N], sum[N], dp[N];   vector<int> g[N];   bool cmp(int q, int w) { return (sum[q] > sum[w]); }   void dfs(int v, int pr = 0) {     p[v] = pr;     sum[v] = 1;     if (pr && g[v].size() == 1) {       dp[v] = v;       return;     }     vector<int> a;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (to == pr) continue;       dfs(to, v);       a.push_back(to);       sum[v] += sum[to];     }     sort((a).begin(), (a).end(), cmp);     int n = a.size();     int first = dp[a[0]];     while (sum[v] - sum[first] > sum[v] / 2) {       first = p[first];     }     dp[v] = first;   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     for (int i = 2; i <= n; i++) {       int first;       cin >> first;       g[i].push_back(first);       g[first].push_back(i);     }     dfs(1);     for (int i = 1; i <= m; i++) {       int first;       cin >> first;       cout << dp[first] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long mn = (long long)(1e9);   long long n, ans, k, a[311111], near[2111111], x;   bool mark[2111111];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       mark[a[i]] = 1;       mn = min(mn, a[i]);     }     for (int i = 1; i <= 2000000; i++) {       near[i] = x;       if (mark[i]) x = i;     }     for (int i = mn; i >= 1; i--) {       long long mx = -(long long)(1e9);       for (int j = 0; j <= 1000000; j += i) {         if (near[j + i] >= j) mx = max(mx, near[j + i] - j);       }       if (mx != -(long long)(1e9) && mx <= k) {         cout << i;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long mod = 1e9 + 7;   unsigned long long power(long long x, unsigned 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;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   const long long maxn = 3000 * 3000;   long long g[maxn];   deque<pair<long long, long long>> d;   long long mat[3001][3001];   long long mn[3001][3001];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, m, a, b, x, y, z;     cin >> n >> m >> a >> b;     cin >> g[0] >> x >> y >> z;     for (long long i = 1; i < n * m + 1; i++) {       g[i] = (g[i - 1] * x + y) % z;     }     for (long long i = 1; i < n + 1; i++) {       for (long long j = 1; j < m + 1; j++) {         mat[i][j] = g[(i - 1) * m + j - 1];       }     }     for (long long i = 1; i < n + 1; i++) {       d.clear();       for (long long j = 1; j < m + 1; j++) {         while (d.size() && d.back().first > mat[i][j]) {           d.pop_back();         }         d.push_back({mat[i][j], j});         if (j >= b) {           mn[i][j] = d.front().first;           if (j - d.front().second >= b - 1) {             d.pop_front();           }         }       }     }     d.clear();     for (long long j = b; j < m + 1; j++) {       d.clear();       for (long long i = 1; i < n + 1; i++) {         while (d.size() && d.back().first > mn[i][j]) {           d.pop_back();         }         d.push_back({mn[i][j], i});         if (i >= a) {           mat[i][j] = d.front().first;           if (i - d.front().second >= a - 1) {             d.pop_front();           }         }       }     }     long long ans = 0;     for (long long i = a; i < n + 1; i++) {       for (long long j = b; j < m + 1; j++) {         ans += mat[i][j];       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   int main() {     std::ios_base::sync_with_stdio(0);     std::cout.tie(0);     std::cin.tie(0);     int n;     std::cin >> n;     int a[n];     for (int i = 0; i < n; ++i) std::cin >> a[i];     std::sort(a, a + n);     for (int i = n - 1; i >= 0; --i) {       int t = sqrt(a[i]);       if (t * t != a[i]) {         std::cout << a[i] <<   n ;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   typedef int arr[55][55];   char s0[55], s1[55], opr[9];   int x[55], y[55], z[55], f[55][55], n0, n1, m;   bool b[55][55][55];   arr e0, e1;   void work(int &n, char *s, arr &e) {     n = strlen(s);     memset(b, 0, sizeof(b));     for (int i = 0; i < n; i++) b[i][i + 1][s[i] - 97] = 1;     for (int j = 2; j <= n; j++)       for (int i = 0; i + j <= n; i++)         for (int k = i + 1; k < i + j; k++)           for (int c = 0; c < m; c++)             b[i][i + j][z[c]] |= b[i][k][x[c]] && b[k][i + j][y[c]];     for (int i = 0; i < n; i++)       for (int j = i + 1; j <= n; j++)         for (int k = 0; k < 26; k++)           if (b[i][j][k]) e[i][j] |= 1 << k;   }   int main() {     scanf( %s%s%d , s0, s1, &m);     for (int i = 0; i < m; i++)       scanf( %s , opr), x[i] = opr[3] - 97, y[i] = opr[4] - 97,                         z[i] = opr[0] - 97;     work(n0, s0, e0), work(n1, s1, e1);     memset(f, 6, sizeof(f));     f[0][0] = 0;     for (int i = 0; i <= n0; i++)       for (int x = 0; x <= n1; x++)         for (int j = i + 1; j <= n0; j++)           for (int y = x + 1; y <= n1; y++)             if (e0[i][j] & e1[x][y] && f[i][x] + 1 < f[j][y])               f[j][y] = f[i][x] + 1;     printf( %d n , f[n0][n1] <= 100 ? f[n0][n1] : -1);     return 0;   }