malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long dp[1001][2 * 1001][2];   long long MOD = 998244353;   int main() {     ios_base::sync_with_stdio(false);     int n, k;     cin >> n >> k;     dp[1][1][0] = 2;     dp[1][2][0] = 0;     dp[1][1][1] = 0;     dp[1][2][1] = 2;     for (int i = 2; i <= n; ++i) {       for (int j = 1; j <= min(2 * n, k); ++j) {         dp[i][j][0] = dp[i - 1][j][0] + dp[i - 1][j - 1][0] + dp[i - 1][j][1] * 2;         dp[i][j][0] %= MOD;         dp[i][j][1] =             dp[i - 1][j][1] + dp[i - 1][j - 2][1] + dp[i - 1][j - 1][0] * 2;         dp[i][j][1] %= MOD;       }     }     cout << (dp[n][k][0] + dp[n][k][1]) % MOD <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double eps = 1e-6;   const long long _mod = 1000000007LL;   const int save[10][4] = {{0}, {0}, {6, 2, 4, 8}, {1, 3, 9, 7}, {6, 4},                            {0}, {0}, {1, 7, 9, 3}, {6, 8, 4, 2}, {1, 9}};   int todigit(char c) { return (isdigit(c)) ? (c - 48) : c; }   int toint(string s) {     int r = 0;     istringstream sin(s);     sin >> r;     return r;   }   long long tolong(string s) {     long long r = 0;     istringstream sin(s);     sin >> r;     return r;   }   double todouble(string s) {     double r = 0.0;     istringstream sin(s);     sin >> r;     return r;   }   bool bit_check(int k, int p) { return (bool)(k & (1 << p)); }   int bit_set(int k, int p) { return k = (k | (1 << p)); }   template <class T>   string toString(T n) {     ostringstream ost;     ost << n;     ost.flush();     return ost.str();   }   template <class T>   T Abs(T x) {     return x > 0 ? x : -x;   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   template <class T>   inline T max_(T a, T b) {     return a > b ? a : b;   }   template <class T>   inline T min_(T a, T b) {     return a < b ? a : b;   }   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   int di(string num, int b);   int dig(int num);   int main() {     int a, b;     cin >> a >> b;     int mn = max(dig(a), dig(b));     mn++;     int mx = 0;     for (int i = mn; i < 17; ++i) {       mx = max(mx, di(toString(a + b), i));     }     printf( %d n , mx);     return 0;   }   int di(string num, int b) {     int n = 0;     for (int i = 0; i < num.size(); ++i) {       n = (n * b) + (num[i] -  0 );     }     int cnt = 0;     while (n) {       n = n / b;       ++cnt;     }     return cnt;   }   int dig(int num) {     int mn = 0;     while (num) {       mn = max(mn, num % 10);       num = num / 10;     }     return mn;   }
#include <bits/stdc++.h>   using namespace std;   int n, mem[505][505];   string s;   int dp(int i, int j) {     if (i > j) return 0;     int &ans = mem[i][j];     if (ans != -1) return ans;     ans = dp(i + 1, j) + 1;     for (int k = i + 1; k <= j; k++)       if (s[i] == s[k]) ans = min(ans, dp(i + 1, k - 1) + dp(k, j));     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     memset(mem, -1, sizeof(mem));     cin >> n >> s;     cout << dp(0, n - 1) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n][2];     for (int i = 0; i < n; i++) {       cin >> a[i][0] >> a[i][1];     }     int sum1 = 0;     int sum2 = 0;     for (int i = 0; i < n; i++) {       if (abs(sum1 + a[i][0] - sum2) <= 500) {         sum1 += a[i][0];         a[i][0] = -1;       } else {         sum2 += a[i][1];       }     }     if (abs(sum1 - sum2) > 500) {       cout <<  -1 ;     } else {       for (int i = 0; i < n; i++) {         if (a[i][0] == -1) {           cout <<  A ;         } else {           cout <<  G ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, j;     cin >> t;     for (j = 0; j <= t - 1; j++) {       int a, b, c, n;       cin >> a >> b >> n;       n = n % 3;       c = a ^ b;       if (n == 0) {         cout << a << endl;       } else if (n == 1) {         cout << b << endl;       } else {         cout << c << endl;       }     }   }
#include <bits/stdc++.h>   char _;   using namespace std;   int N, C, D;   pair<int, int> A[400000];   long long Z, ZO, ZOZ, O, OZ, OZO;   inline bool cmp(const pair<int, int>& a, const pair<int, int>& b) {     if ((b.second < 0) ^ (a.second < 0))       return 1LL * a.first * b.second > 1LL * b.first * a.second;     return 1LL * a.first * b.second < 1LL * b.first * a.second;   }   inline bool eq(const pair<int, int>& a, const pair<int, int>& b) {     return 1LL * a.first * b.second == 1LL * b.first * a.second;   }   int main() {     do {       while ((N = getchar()) <  0 )         ;       for (N -=  0 ;  0  <= (_ = getchar()); N = (N << 3) + (N << 1) + _ -  0 )         ;     } while (0);     do {       while ((C = getchar()) <  0 )         ;       for (C -=  0 ;  0  <= (_ = getchar()); C = (C << 3) + (C << 1) + _ -  0 )         ;     } while (0);     do {       while ((D = getchar()) <  0 )         ;       for (D -=  0 ;  0  <= (_ = getchar()); D = (D << 3) + (D << 1) + _ -  0 )         ;     } while (0);     for (int i = 0; i < N; i++) {       do {         while ((A[i].first = getchar()) <  0 )           ;         for (A[i].first -=  0 ;  0  <= (_ = getchar());              A[i].first = (A[i].first << 3) + (A[i].first << 1) + _ -  0 )           ;       } while (0);       do {         while ((A[i].second = getchar()) <  0 )           ;         for (A[i].second -=  0 ;  0  <= (_ = getchar());              A[i].second = (A[i].second << 3) + (A[i].second << 1) + _ -  0 )           ;       } while (0);       A[i].first -= C, A[i].second -= D;     }     sort(A, A + N, cmp);     for (int i = 0, j; i < N; i = j) {       long long NZ = Z, NZO = ZO, NZOZ = ZOZ, NO = O, NOZ = OZ, NOZO = OZO;       for (j = i; j < N && eq(A[i], A[j]); j++) {         if (A[j].second < 0) {           NOZO += OZ;           NZO += Z;           NO++;         } else {           NZOZ += ZO;           NOZ += O;           NZ++;         }       }       Z = NZ, ZO = NZO, ZOZ = NZOZ, O = NO, OZ = NOZ, OZO = NOZO;     }     int L = 0, R = 0, D = 0;     for (int i = 0; i < N; i++)       if (A[i].second == 0) {         if (A[i].first < 0)           L++;         else           R++;       }     for (int i = 0; i < N; i++)       if (A[i].second < 0) D++;     printf( %lld n , OZO + ZOZ - 1LL * L * R * D);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3F3F3F3F;   const int NEGINF = 0xC0C0C0C0;   const double EPS = 1e-8;   int cmp(double x, double y = 0, double tol = EPS) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   string s;   bool test(long long inx) {     int pos = 0;     int m = 0;     int im = 0;     for (auto &x : s) {       if (x ==  R )         pos++;       else         pos--;       if (inx >= 0 && pos == inx) pos--;       if (pos < m) {         m = pos;         im = &x - &(s[0]);       }     }     return im == s.size() - 1;   }   int main() {     cin >> s;     if (s.back() ==  R )       for (auto &x : s) x =  R  +  L  - x;     if (test(-1)) {       cout <<  1 n ;       return 0;     } else if (!test(1)) {       cout <<  0 n ;       return 0;     }     long long m = 1, M = 0x7fffffffffffffffll;     long long ans = 1;     while (M >= m) {       long long med = m + (M - m) / 2;       if (test(med)) {         ans = med;         m = med + 1;       } else         M = med - 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[500005];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int kk = 1;     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       if (a[i] >= a[kk] * 2) {         ++kk;       }     }     --kk;     kk = min(n / 2, kk);     printf( %d n , n - kk);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int now[30];   char s[maxn];   int num[maxn];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s + 1);     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= 30; j++) {         if (s[i] >= now[j]) {           num[i] = j;           now[j] = s[i];           ans = max(ans, j);           break;         }       }     }     printf( %d n , ans);     for (int i = 1; i <= n; i++) {       printf( %d  , num[i]);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 305;   long long dist[10][N][N], I[2][N][N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         if (i != j) dist[0][i][j] = INT_MIN;         I[0][i][j] = dist[0][i][j];       }     for (int i = 1; i <= m; i++) {       int x, y, c1, c2;       cin >> x >> y >> c1 >> c2;       dist[0][x][y] = c1;       dist[0][y][x] = c2;     }     for (int c = 1; c < 10; c++) {       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) dist[c][i][j] = dist[c - 1][i][j];       for (int i = 1; i <= n; i++)         for (int k = 1; k <= n; k++)           for (int j = 1; j <= n; j++)             dist[c][i][j] =                 max(dist[c][i][j], dist[c - 1][i][k] + dist[c - 1][k][j]);     }     bool ok = 0;     for (int i = 1; i <= n; i++)       if (dist[9][i][i] > 0) {         ok = 1;         break;       }     if (!ok) {       cout << 0;       return 0;     }     int ans = 1;     for (int bit = 9; bit >= 0; bit--) {       ok = 0;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) I[1][i][j] = I[0][i][j];       for (int i = 1; i <= n; i++)         for (int k = 1; k <= n; k++)           for (int j = 1; j <= n; j++)             I[1][i][j] = max(I[1][i][j], I[0][i][k] + dist[bit][k][j]);       for (int i = 1; i <= n; i++)         if (I[1][i][i] > 0) {           ok = 1;           break;         }       if (!ok) {         ans += (1 << bit);         for (int i = 1; i <= n; i++)           for (int j = 1; j <= n; j++) I[0][i][j] = I[1][i][j];       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200025;   int n, m, i, j, t, k, s, mod, a[maxn], fat[maxn];   bool flg, vis[maxn << 1];   inline int Pow(int x, int y, int mo) {     int ret = 1;     while (y) {       if (y & 1) ret = 1ll * ret * x % mo;       x = 1ll * x * x % mo;       y >>= 1;     }     return ret;   }   int father(int x) { return x == fat[x] ? x : fat[x] = father(fat[x]); }   void solve(int delt) {     for (i = 1; i <= n; ++i) fat[i] = i;     for (i = 1; i <= n; ++i) {       k = (a[i] - delt + mod) % mod;       t = lower_bound(a + 1, a + n + 1, k) - a;       if (a[t] == k) fat[father(t)] = father(i);     }     t = 0;     for (i = 1; i <= n; ++i) {       if (fat[i] == i)         t++;       else         fat[i] = i;     }     delt = delt * 1ll * Pow(t, mod - 2, mod) % mod;     for (i = 1; i <= n; ++i) {       k = (a[i] - delt + mod) % mod;       t = lower_bound(a + 1, a + n + 1, k) - a;       if (a[t] == k) fat[father(t)] = father(i);     }     for (i = 2; i <= n; ++i)       if (father(i) ^ father(1)) break;     if (i > n) {       for (i = 1; i <= n; ++i) {         k = (a[i] - delt + mod) % mod;         t = lower_bound(a + 1, a + n + 1, k) - a;         if (a[t] != k) break;       }       if (i > n) {         if (flg)           printf( %d %d n , a[1], delt);         else           t = (1ll * n * delt + a[1]) % mod, printf( %d %d n , t, delt);       } else {         if (flg)           printf( %d %d n , a[i], delt);         else           t = (1ll * n * delt + a[i]) % mod, printf( %d %d n , t, delt);       }       exit(0);     }   }   int main() {     scanf( %d%d , &mod, &n);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     a[n + 1] = mod + 114514;     if (n == 1 || n == mod) {       printf( %d %d n , a[1], 1);       return 0;     }     if (n == 2) {       printf( %d %d n , a[1], (a[2] - a[1] + mod) % mod);       return 0;     }     sort(a + 1, a + n + 1);     flg = 1;     if (2 * n > mod) {       flg = 0;       for (i = 1; i <= n; ++i) vis[a[i]] = 1;       n = 0;       for (i = 0; i < mod; ++i)         if (!vis[i]) a[++n] = i;       a[n + 1] = mod + 114514;       if (n == 1) {         printf( %d %d n , (a[1] + 1) % mod, 1);         return 0;       }     }     solve(a[2] - a[1]);     solve((a[1] - a[2] + mod) % mod);     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char mainstr[111111];   char substr1[111];   char substr2[111];   int main() {     while (scanf( %s %s %s , mainstr, substr1, substr2) != EOF) {       bool flag1 = false, flag2 = false;       int len = strlen(mainstr);       int len1 = strlen(substr1);       int len2 = strlen(substr2);       char *pos = search(mainstr, mainstr + len, substr1, substr1 + len1);       if (pos != mainstr + len && search(pos + len1, mainstr + len, substr2,                                          substr2 + len2) != mainstr + len)         flag1 = true;       reverse(mainstr, mainstr + len);       pos = search(mainstr, mainstr + len, substr1, substr1 + len1);       if (pos != mainstr + len && search(pos + len1, mainstr + len, substr2,                                          substr2 + len2) != mainstr + len)         flag2 = true;       if (flag1 && flag2)         printf( both n );       else if (flag1)         printf( forward n );       else if (flag2)         printf( backward n );       else         printf( fantasy n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000 * 100 + 10, LG = 20;   int n, h[N], st[N], en[N], par[N][LG], seg[N << 2], lazy[N << 2], TM, ver[N],       ans[N];   vector<int> adj[N];   struct Query {     int l, r, id;     Query(int x = 0, int y = 0, int z = 0) { l = x, r = y, id = z; }   };   vector<Query> query[N];   void dfs(int v) {     st[v] = TM++;     ver[st[v]] = h[v];     for (int i = 1; i < LG; i++) par[v][i] = par[par[v][i - 1]][i - 1];     for (auto u : adj[v])       if (u != par[v][0]) {         par[u][0] = v;         h[u] = h[v] + 1;         dfs(u);       }     en[v] = TM;   }   int k_par(int v, int k) {     for (int i = 0; i < LG; i++)       if (k >> i & 1) v = par[v][i];     return v;   }   int lca(int v, int u) {     if (h[v] < h[u]) swap(v, u);     v = k_par(v, h[v] - h[u]);     if (v == u) return v;     for (int i = LG - 1; i >= 0; i--)       if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];     return par[v][0];   }   int d(int v, int u) { return h[v] + h[u] - 2 * h[lca(v, u)]; }   void build(int l = 0, int r = n, int id = 1) {     if (l + 1 == r) {       seg[id] = ver[l];       return;     }     int mid = l + r >> 1;     build(l, mid, id << 1), build(mid, r, id << 1 | 1);     seg[id] = max(seg[id << 1], seg[id << 1 | 1]);   }   void add(int id, int x) {     seg[id] += x;     lazy[id] += x;   }   void shift(int id) {     add(id << 1, lazy[id]);     add(id << 1 | 1, lazy[id]);     lazy[id] = 0;   }   int get(int s, int e, int l = 0, int r = n, int id = 1) {     if (s <= l && e >= r) return seg[id];     if (s >= r || e <= l) return 0;     shift(id);     int mid = l + r >> 1;     return max(get(s, e, l, mid, id << 1), get(s, e, mid, r, id << 1 | 1));   }   void upd(int s, int e, int x, int l = 0, int r = n, int id = 1) {     if (s <= l && e >= r) {       add(id, x);       return;     }     if (s >= r || e <= l) return;     shift(id);     int mid = l + r >> 1;     upd(s, e, x, l, mid, id << 1), upd(s, e, x, mid, r, id << 1 | 1);     seg[id] = max(seg[id << 1], seg[id << 1 | 1]);   }   void dfs_ans(int v) {     for (auto q : query[v]) ans[q.id] = max(ans[q.id], get(q.l, q.r));     for (auto u : adj[v])       if (u != par[v][0]) {         upd(st[u], en[u], -1);         upd(0, st[u], +1);         upd(en[u], n, +1);         dfs_ans(u);         upd(st[u], en[u], +1);         upd(0, st[u], -1);         upd(en[u], n, -1);       }   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1, v, u; i < n; i++) {       cin >> v >> u;       --v, --u;       adj[v].push_back(u);       adj[u].push_back(v);     }     dfs(0);     build();     int Q;     cin >> Q;     for (int i = 0, v, u; i < Q; i++) {       cin >> v >> u;       --v, --u;       if (h[v] < h[u]) swap(v, u);       int dis = d(v, u);       int w = k_par(v, (dis - 1) / 2);       query[v].push_back(Query(st[w], en[w], i));       query[u].push_back(Query(0, st[w], i));       query[u].push_back(Query(en[w], n, i));     }     dfs_ans(0);     for (int i = 0; i < Q; i++) cout << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; ++i) {         cin >> a[i];       }       int ans = 0;       function<void(int, int)> dfs = [&](int p, int s) {         if (p == n) {           if (!s) {             ++ans;           }           return;         }         dfs(p + 1, s - a[p]);         dfs(p + 1, s);         dfs(p + 1, s + a[p]);       };       dfs(0, 0);       cout << (ans >= 2 ?  YES  :  NO ) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void print(vector<int> v) {     for (int i = 0; i < v.size(); i++) {       if (v[i] != 0) {         cout << v[i];       }     }     cout << endl;   }   void solve(vector<int>& v, int even, int odd) {     if (v.size() == 1) {       cout << -1 << endl;       return;     } else if (v.size() == 2) {       if (odd != 2) {         cout << -1 << endl;         return;       } else {         print(v);         return;       }     } else if (odd == 0) {       cout << -1 << endl;       return;     } else {       while (v[v.size() - 1] % 2 == 0) {         v.pop_back();         even--;       }       if (odd == 1) {         cout << -1 << endl;         return;       } else if (odd % 2 == 0) {         print(v);         return;       } else {         for (int i = 0; i < v.size(); i++) {           if (v[i] % 2 == 1) {             v.erase(v.begin() + i);             print(v);             return;           }         }       }     }   }   int main() {     int t;     cin >> t;     while (t--) {       int e = 0, o = 0;       int n;       cin >> n;       string s;       cin >> s;       vector<int> v(n);       for (int i = 0; i < s.size(); i++) {         v[i] = s[i] - 48;         if (v[i] % 2 == 0)           e++;         else           o++;       }       solve(v, e, o);     }   }
#include <bits/stdc++.h>   const long long N = 200200;   const long long Q = 100100;   const long long mod = 998244353;   const long long block = 500;   using namespace std;   string s;   int cnt;   bool t;   void solve() {     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) {         t = 1;       } else if (t) {         cnt++;       }     }     if (cnt >= 6) {       cout <<  yes             <<   n ;     } else {       cout <<  no             <<   n ;     }   }   bool mtest = false;   int main() {     ios_base::sync_with_stdio(0);     int TE = 1;     if (mtest) cin >> TE;     while (TE--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int N;   int a[MAXN];   vector<int> lol;   int main(int argc, char *argv[]) {     scanf( %d , &N);     int p = 1;     while (p < MAXN) {       lol.push_back(p);       p <<= 1;     }     for (int i = 0, _i = N; i < _i; ++i) {       scanf( %d , a + i);     }     long long ans = 0;     for (int i = 0, _i = N - 1; i < _i; ++i) {       ans += a[i];       cout << ans <<   n ;       a[i + *(--upper_bound(lol.begin(), lol.end(), N - i - 1))] += a[i];       a[i] = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long cap[200005];   int n, m;   inline long long tri(int n) { return n * (n + 1LL) / 2; }   inline long long arithsum(int a, int d, int n) {     long long ret = a * (long long)n;     ret += tri(n - 1) * d;     return ret;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %lld , &cap[i]);     }     long long ret = 0;     for (int rep = 1; (rep)*n <= m; rep++) {       long long total = 0;       bool bad = false;       long long currVal = min(arithsum(m, -n, rep), cap[n - 1]);       for (int i = 0; i < n; i++) {         currVal = min(currVal, cap[i] + m - rep * (i + 1));       }       for (int i = n - 1; !bad && i >= 0; i--) {         total += currVal;         if (i > 0) {           long long drop = currVal - cap[i - 1];           if (drop > m - rep) bad = true;           currVal = min(currVal - rep, cap[i - 1]);         }       }       long long lowFirst = arithsum(1, n, rep);       if (!bad && currVal >= lowFirst) {         ret = max(ret, total);       }     }     printf( %lld n , ret);   }
#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   struct edge {     int v, next;   };   int ans, ans2, f[1005][1 << 12];   int Pow(int a, int b) {     int rec = 1;     for (; b; b >>= 1, a = 1ll * a * a % mod)       if (b & 1) rec = 1ll * rec * a % mod;     return rec;   }   struct nade {     int head[1005], edgenum, d[1005][1005], num[1005], sta[1005], n;     edge e[1005 << 1];     void add(int u, int v) {       e[++edgenum] = edge{v, head[u]};       head[u] = edgenum;     }     void dfs(int u, int fa) {       num[u] = sta[u] = 0;       for (int i = head[u], v; i; i = e[i].next)         if ((v = e[i].v) ^ fa) {           dfs(d[u][num[u]++] = v, u);           sta[u] |= 1 << v - 1;         }     }   } s, t;   int dfs(int u, int i, int sta) {     if (!i) return !sta;     int &rec = f[s.d[u][i - 1]][sta];     if (rec != -1) return rec;     rec = dfs(u, i - 1, sta);     for (int v = s.d[u][i - 1], k = 0; k < t.n; k++)       if (sta >> k & 1)         rec = (rec + 1ll * dfs(u, i - 1, sta ^ (1 << k)) *                          dfs(v, s.num[v], t.sta[k + 1])) %               mod;     return rec;   }   int main() {     scanf( %d , &s.n);     for (int i = 1, u, v; i < s.n; i++) {       scanf( %d%d , &u, &v);       s.add(u, v);       s.add(v, u);     }     scanf( %d , &t.n);     for (int i = 1, u, v; i < t.n; i++) {       scanf( %d%d , &u, &v);       t.add(u, v);       t.add(v, u);     }     s.dfs(1, 0);     memset(f, -1, sizeof f);     for (int r = 1; r <= t.n; r++) {       t.dfs(r, 0);       for (int i = 1; i <= s.n; i++)         ans = (ans + dfs(i, s.num[i], t.sta[r])) % mod;       memset(f, -1, sizeof f);     }     s = t;     s.dfs(1, 0);     for (int r = 1; r <= t.n; r++) {       t.dfs(r, 0);       ans2 = (ans2 + dfs(1, s.num[1], t.sta[r])) % mod;       memset(f, -1, sizeof f);     }     ans = 1ll * ans * Pow(ans2, mod - 2) % mod;     printf( %d , ans);   }