malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int cd(int a, int b) { return a - a / b; }   int main() {     int cnt1, cnt2, x, y;     cin >> cnt1 >> cnt2 >> x >> y;     long long int l = 1, r = 1000000000009;     while (l < r) {       int mid = l + (r - l) / 2;       if (cnt1 <= cd(mid, x) && cnt2 <= cd(mid, y) &&           cnt1 + cnt2 <= cd(mid, x * y))         r = mid;       else         l = mid + 1;     }     cout << r;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll inf = 1e18;   template <typename T>   void printvector(const vector<T>& foo) {     for (auto el : foo) cout << el <<    ;     cout << endl;   }   bool calc(vector<int>& permuration, const vector<vector<int>>& sets,             vector<bool>& used) {     if (permuration.size() == sets.size() + 1) {       for (auto el : permuration) cout << el <<    ;       cout <<   n ;       return true;     }     if (permuration.empty()) {       for (int i = 0; i < sets.size(); i++) {         permuration.push_back(sets[i][0]);         permuration.push_back(sets[i][1]);         used[i] = true;         if (calc(permuration, sets, used)) return true;         swap(permuration[0], permuration[1]);         if (calc(permuration, sets, used)) return true;         used[i] = false;         permuration.pop_back();         permuration.pop_back();       }     }     vector<int> last_elements;     for (size_t next = 0; next < sets.size(); next++) {       if (used[next]) continue;       const auto& row = sets[next];       if (row.size() > permuration.size() + 1) break;       while (last_elements.size() < row.size() - 1) {         last_elements.push_back(             permuration[permuration.size() - last_elements.size() - 1]);       }       sort(last_elements.begin(), last_elements.end());       vector<int> diff;       set_difference(row.begin(), row.end(), last_elements.begin(),                      last_elements.end(), back_inserter(diff));       if (diff.size() > 1) continue;       used[next] = true;       permuration.push_back(diff[0]);       if (calc(permuration, sets, used)) return true;       used[next] = false;       permuration.pop_back();       return false;     }     return false;   }   int main() {     int test;     cin >> test;     while (test--) {       int n;       cin >> n;       vector<vector<int>> sets(n - 1);       for (auto& row : sets) {         int k;         cin >> k;         row.resize(k);         for (auto& el : row) cin >> el;       }       sort(sets.begin(), sets.end(),            [](const vector<int>& a, const vector<int>& b) {              return a.size() < b.size();            });       vector<int> permutation;       vector<bool> used(n, false);       calc(permutation, sets, used);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 110000;   int len, k, n;   long long a[N];   long long resolve() {     int pK = k;     set<pair<long long, int>> av;     set<pair<long long, int>> changed;     long long sumP = 0;     for (int i = 0; i < len; i++) {       av.insert({a[i], i});       sumP += a[i];     }     while (true) {       if (!av.size()) break;       auto lowest = *av.begin();       if (lowest.first >= 0) break;       if (pK == 0) break;       av.erase(av.begin());       changed.insert({-lowest.first, lowest.second});       sumP -= lowest.first;       sumP += (-lowest.first);       pK--;     }     long long best = sumP;     for (int i = 1; i <= n - len; i++) {       if (av.count({a[i - 1], i - 1})) {         av.erase(av.find({a[i - 1], i - 1}));         sumP -= a[i - 1];       } else {         changed.erase(changed.find({-a[i - 1], i - 1}));         sumP -= (-a[i - 1]);         pK++;       }       int j = i + len - 1;       av.insert({a[j], j});       sumP += a[j];       while (pK > 0) {         if (av.size()) {           auto x = *av.begin();           if (x.first < 0) {             av.erase(av.begin());             changed.insert({-x.first, x.second});             sumP -= x.first;             sumP += (-x.first);             pK--;           } else             break;         } else           break;       }       while (pK == 0) {         if (!av.size() || !changed.size()) break;         auto x = *av.begin();         auto y = *changed.begin();         if (x.first > 0) break;         if (x.first * -1 > y.first) {           changed.erase(changed.begin());           av.erase(av.begin());           changed.insert({x.first * -1, x.second});           av.insert({y.first * -1, y.second});           sumP -= y.first;           sumP += (-y.first);           sumP -= x.first;           sumP += (-x.first);         } else           break;       }       best = max(best, sumP);     }     return best;   }   int main() {     scanf( %d %d , &n, &len);     for (int i = 0; i < n; i++) scanf( %lld , a + i);     scanf( %d , &k);     long long ans = resolve();     for (int i = 0; i < n; i++) a[i] *= -1;     ans = max(ans, resolve());     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k, l, c, d, p, nl, np;     cin >> n >> k >> l >> c >> d >> p >> nl >> np;     long long totlime = c * d;     long long totdrink = k * l;     totdrink = totdrink / nl;     long long totsalt = p / np;     long long mn = min(totlime, totdrink);     mn = min(mn, totsalt);     cout << mn / n <<   n ;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans, v[1009], m, c[1009];   vector<int> e;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 2; i <= n; i++) {       if (v[i] == 0 and v[i - 1] == 1 and v[i + 1] == 1) c[++m] = i + 1;     }     ans = m;     for (int i = 1; i < m; i++) {       if (c[i] + 2 == c[i + 1]) {         ans--;         c[i] = -1e9, c[i + 1] - 1e9;         i++;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n, ys, ans;   int main() {     cin >> n;     ys = 0;     ans = 0;     for (int i = n; i > 0; i /= 8) {       ys = i % 8;       if (ys == 1) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using INT = long long;   using pii = pair<int, int>;   const int mod = 1e9 + 7;   int power(int a, int n, int mod, int ans = 1) {     for (; n; n >>= 1, a = (INT)a * a % mod)       if (n & 1) ans = (INT)ans * a % mod;     return ans;   }   int fac[3000111], rev[3000111];   int dp[3000111];   int C(int n, int k) {     if (k < 0 or k > n) return 0;     return (INT)fac[n] * rev[k] % mod * rev[n - k] % mod;   }   void pre() {     for (int i = fac[0] = rev[0] = 1; i < 3000111; i++) {       fac[i] = (INT)fac[i - 1] * i % mod;     }     rev[3000111 - 1] = power(fac[3000111 - 1], mod - 2, mod);     for (int i = 3000111 - 2; i >= 0; i--)       rev[i] = (INT)rev[i + 1] * (i + 1) % mod;   }   int main() {     pre();     int n, q;     cin >> n >> q;     dp[0] = n;     for (int i = 1; i <= n; i++) {       dp[1] = (dp[1] + 3 * i) % mod;       dp[2] = (C(i * 3, 2) + dp[2]) % mod;     }     int r3 = power(3, mod - 2, mod);     for (int i = 3; i <= 3 * n; i++) {       dp[i] = (C(3 * n, i - 2) + 3LL * C(3 * n, i - 1) + 3LL * C(3 * n, i) +                C(3 * n, i + 1) - 3LL * dp[i - 1] - dp[i - 2]) %               mod;       dp[i] = (INT)dp[i] * r3 % mod;       if (dp[i] < 0) dp[i] += mod;     }     while (q--) {       int x;       scanf( %d , &x);       printf( %d n , dp[x]);     }     return 0;   }
#include <bits/stdc++.h>   int a[(1 << 22) + 1];   int n, m;   bool vis[(1 << 22) + 1][2];   bool yes[(1 << 22) + 1];   int mask;   void dfs(int now, int p) {     if (vis[now][p]) return;     vis[now][p] = true;     if (p == 0)       dfs(now, 1);     else {       for (int j = 0; j < n; j++) {         int jj = 1 << j;         if (!(jj & now)) dfs(now | jj, 1);       }       if (yes[now ^ mask]) dfs(now ^ mask, 0);     }   }   int main() {     scanf( %d%d , &n, &m);     int ans = 0;     for (int i = 0; i < (1 << n); i++) yes[i] = vis[i][0] = vis[i][1] = false;     for (int i = 0; i < m; i++) {       scanf( %d , &a[i]);       yes[a[i]] = true;     }     mask = (1 << n) - 1;     for (int i = 0; i < m; i++) {       if (!vis[a[i]][0]) {         ans++;         dfs(a[i], 0);       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 3030;   int head[MAX_N], current, n, siz[MAX_N][MAX_N], fa[MAX_N][MAX_N];   long long f[MAX_N][MAX_N];   struct edge {     int to, nxt;   } edges[MAX_N << 1];   void addpath(int src, int dst) {     edges[current].to = dst, edges[current].nxt = head[src];     head[src] = current++;   }   void dfs(int u, int org) {     siz[org][u] = 1;     for (int i = head[u]; i != -1; i = edges[i].nxt)       if (edges[i].to != fa[org][u])         fa[org][edges[i].to] = u, dfs(edges[i].to, org),         siz[org][u] += siz[org][edges[i].to];   }   long long dp(int u, int v) {     if (u == v) return 0;     if (f[u][v]) return f[u][v];     return (f[u][v] = max(dp(u, fa[u][v]), dp(v, fa[v][u])) +                       1LL * siz[u][v] * siz[v][u]);   }   int main() {     memset(head, -1, sizeof(head));     scanf( %d , &n);     for (int i = 1, u, v; i <= n - 1; i++)       scanf( %d%d , &u, &v), addpath(u, v), addpath(v, u);     for (int i = 1; i <= n; i++) dfs(i, i);     long long ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) ans = max(ans, dp(i, j));     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const int toN = 58;   int pn, p[10000];   int n, a[10000], omask[10000];   int dp[110][1 << 18];   int ans[110][1 << 18];   bool isPrime(int n) {     if (n == 2) return true;     for (int i = 2; i * i <= n; ++i)       if (n % i == 0) return false;     return true;   }   int main() {     pn = 0;     for (int i = 2; i <= toN; ++i)       if (isPrime(i)) p[pn++] = i;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i <= n; ++i) {       for (int m = 0; m < (1 << pn); ++m) dp[i][m] = inf;     }     dp[0][0] = 0;     for (int i = 1; i <= toN; ++i) {       omask[i] = 0;       for (int j = 0; j < pn; ++j)         if (i % p[j] == 0) omask[i] |= (1 << j);     }     for (int m = 0; m < (1 << pn); ++m) {       for (int j = 1; j <= toN; ++j)         if ((omask[j] & m) == 0) {           for (int i = 0; i < n; ++i)             if (dp[i][m] < inf) {               int nm = (m | omask[j]);               if (dp[i + 1][nm] > dp[i][m] + abs(j - a[i])) {                 dp[i + 1][nm] = dp[i][m] + abs(j - a[i]);                 ans[i + 1][nm] = j;               }             }         }     }     int v = 0;     for (int m = 0; m < (1 << pn); ++m)       if (dp[n][v] > dp[n][m]) v = m;     vector<int> ansv;     for (int i = n; i >= 1; --i) {       ansv.push_back(ans[i][v]);       v = v - omask[ans[i][v]];     }     reverse((ansv).begin(), (ansv).end());     for (__typeof(ansv.begin()) it = ansv.begin(); it != ansv.end(); ++it)       cout << *it <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int INF = 0x3f3f3f3f;   int dp[N];   struct node {     int v, id;   } a[N][2];   void up1(int sta, int cost, int i) {     if (a[sta][0].v > cost) {       a[sta][1] = a[sta][0];       a[sta][0] = {cost, i};     } else if (a[sta][1].v > cost) {       a[sta][1] = {cost, i};     }   }   int num = -1, now, cs;   pair<int, int> ans;   void up2(node x, node y, int sta) {     if (x.v == INF || y.v == INF) return;     now = x.v + y.v;     if (dp[sta] > num || (dp[sta] == num && cs > now)) {       num = dp[sta];       cs = now;       ans = {x.id, y.id};     }   }   int main() {     int k, n, m, sta, v, cost;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &k);       sta = 0;       for (int j = 1; j <= k; j++) {         scanf( %d , &v);         sta |= 1 << (v - 1);       }       dp[sta]++;     }     int mx = 0;     for (int i = 0; i < 9; i++) {       for (int j = (1 << 9) - 1; j >= 0; j--) {         if ((1 << i) & j) dp[j] = dp[j] + dp[j ^ (1 << i)];         mx = max(mx, dp[j]);       }     }     for (int j = 0; j < (1 << 9); j++) a[j][0].v = a[j][1].v = INF;     for (int i = 1; i <= m; i++) {       scanf( %d %d , &cost, &k);       sta = 0;       for (int j = 1; j <= k; j++) {         scanf( %d , &v);         sta |= 1 << (v - 1);       }       up1(sta, cost, i);     }     for (int i = 0; i < (1 << 9); i++) {       for (int j = 0; j < (1 << 9); j++) {         if (i == j)           up2(a[i][0], a[i][1], i);         else           up2(a[i][0], a[j][0], i | j);       }     }     printf( %d %d n , ans.first, ans.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   double vb, vs;   double x[105];   double tagx, tagy;   double cal(int p) { return sqrt((x[p] - tagx) * (x[p] - tagx) + tagy * tagy); }   int cmp(double x) {     if (x < (-1e-6))       return -1;     else if (x > 1e-6)       return 1;     else       return 0;   }   int main() {     scanf( %d%lf%lf , &n, &vb, &vs);     for (int i = 0; i < n; i++) scanf( %lf , &x[i]);     scanf( %lf%lf , &tagx, &tagy);     double ans = (double)(0x3f3f3f3f);     int pos;     double min_cal;     for (int i = 1; i < n; i++) {       double time = (x[i] / vb) + (cal(i) / vs);       if (cmp(time - ans) == -1) {         ans = time;         pos = i;         min_cal = cal(i);       } else if (cmp(time - ans) == 0) {         if (cmp(cal(i) - min_cal) == -1) {           ans = time;           pos = i;           min_cal = cal(i);         }       }     }     printf( %d n , pos + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int add(int a, int b) {     a += b;     return a >= mod ? a - mod : a;   }   int sub(int a, int b) {     a -= b;     return a < 0 ? a + mod : a;   }   int mul(int a, int b) { return (long long)a * b % mod; }   int qpow(int a, int b) {     int ret = 1;     for (; b; b >>= 1, a = mul(a, a))       if (b & 1) ret = mul(ret, a);     return ret;   }   const int inv2 = qpow(2, mod - 2);   const int N = 1e6 + 5;   int n;   int hed[N], cnt, to[N], nxt[N];   inline void adde(int u, int v) {     ++cnt;     to[cnt] = v, nxt[cnt] = hed[u];     hed[u] = cnt;   }   int f[N][2];   int ans = 0;   inline void dfs(int x, int pre) {     int way0 = 1;     for (int i = hed[x]; i; i = nxt[i]) {       int v = to[i];       if (v == pre) continue;       dfs(v, x);       way0 = mul(way0, add(mul(inv2, f[v][0]), f[v][1]));     }     int way1 = sub(1, way0);     f[x][0] = way0;     f[x][1] = way1;     ans = add(ans, way1);   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       adde(u, v), adde(v, u);     }     dfs(1, 0);     cout << mul(ans, qpow(2, n)) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int MAXN = 2000 + 5;   int dp[MAXN][MAXN] = {0};   int previous[MAXN] = {0};   void calculatePrevious(const string &s, const string &p) {     int sSize = s.length();     int pSize = p.length();     for (int i = 0; i < sSize; ++i) {       previous[i] = -2;       int currentP = pSize - 1;       int currentS = i;       while (currentP >= 0 && currentS >= 0) {         while (currentS >= 0 && s[currentS] != p[currentP]) {           currentS--;         }         if (currentS >= 0) {           currentP--;           currentS--;         }       }       if (currentP == -1) {         previous[i] = currentS;       }     }   }   int main() {     string s, p;     cin >> s >> p;     int sSize = s.length();     int pSize = p.length();     calculatePrevious(s, p);     for (int i = 1; i <= sSize; ++i) {       for (int j = 0; j < sSize; ++j) {         dp[i][j] = dp[i - 1][j];         if (j > 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);         int prev = previous[i - 1];         if (prev != -2) {           int toDelete = (i - 1) - prev - pSize;           int newDelete = j - toDelete;           int newIndex = prev + 1;           if (newDelete >= 0 && newIndex >= newDelete) {             dp[i][j] = max(dp[i][j], 1 + dp[newIndex][newDelete]);           }         }       }     }     for (int i = 0; i < sSize; ++i) cout << dp[sSize][i] <<    ;     cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, j, i = 0, count = 0, max = 100000000;     string s1, s2;     cin >> n >> m >> s1 >> s2;     vector<int> a, b;     while (i + n <= m) {       count = 0;       for (j = 0; j < n; j++) {         if (s1[j] != s2[i + j]) {           a.push_back(j + 1);           count++;         }       }       if (count < max) {         max = count;         b = a;       }       i++;       a.clear();     }     cout << max << endl;     for (i = 0; i < max; i++) cout << b[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void proc_status() {     ifstream t( /proc/self/status );     cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())          << endl;   }   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   template <typename T>   inline T read() {     register T sum(0), fg(1);     register char ch(getchar());     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) fg = -1;     for (; isdigit(ch); ch = getchar()) sum = sum * 10 -  0  + ch;     return sum * fg;   }   const int MOD = (int)1e9 + 7;   const int MAXN = (int)1e6;   int n;   char s0[MAXN + 5];   inline void input() { scanf( %s , s0 + 1), n = strlen(s0 + 1); }   namespace PAM {   const int MAX_NODE = MAXN * 2, alpha = 26;   int fail[MAX_NODE + 5], trans[MAX_NODE + 5][alpha], nxt[MAX_NODE + 5], cnt;   int len[MAX_NODE + 5], delta[MAX_NODE + 5];   int rt0, rt1, lst;   int S[MAX_NODE + 5], N = 0;   inline void init() {     S[0] = -1;     cnt = 1, lst = 0;     memset(trans[0], 0, sizeof trans[0]);     memset(trans[1], 0, sizeof trans[1]);     len[0] = 0, len[1] = -1;     fail[0] = 1;   }   inline int new_node(int l) {     len[++cnt] = l;     fail[cnt] = 0;     memset(trans[cnt], 0, sizeof trans[cnt]);     return cnt;   }   inline int extend(int ch) {     int p = lst;     S[++N] = ch;     while (S[N - len[p] - 1] != S[N]) p = fail[p];     int np = -1;     if (!trans[p][ch]) {       np = new_node(len[p] + 2);       int t = fail[p];       while (S[N - len[t] - 1] != S[N]) t = fail[t];       fail[np] = trans[t][ch];       delta[np] = len[np] - len[fail[np]];       nxt[np] = delta[np] == delta[fail[np]] ? nxt[fail[np]] : fail[np];       trans[p][ch] = np;     } else       np = trans[p][ch];     return lst = np;   }   }  // namespace PAM   inline void solve() {     static int s[MAXN + 5];     for (int i = 1; i <= n / 2; ++i) {       s[i * 2 - 1] = s0[i] -  a ;       s[i * 2] = s0[n - i + 1] -  a ;     }     static int nd[MAXN + 5];     PAM::init();     for (int i = 1; i <= n; ++i) nd[i] = PAM::extend(s[i]);     static int f[MAXN + 5], g[MAXN + 5];     f[0] = 1;     for (int i = 1; i <= n; ++i)       for (int p = nd[i]; p; p = PAM::nxt[p]) {         g[p] = f[i - PAM::len[PAM::nxt[p]] - PAM::delta[p]];         if (PAM::delta[p] == PAM::delta[PAM::fail[p]])           (g[p] += g[PAM::fail[p]]) %= MOD;         if (i % 2 == 0) (f[i] += g[p]) %= MOD;       }     printf( %d n , (f[n] + MOD) % MOD);   }   int main() {     input();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   const int INF = 0x3f3f3f3f, N = 2000005, M = 2000005, MOD = 1e9 + 7;   int sgn(double x) { return x < -eps ? -1 : (x < eps ? 0 : 1); }   int Rand(int x) { return rand() * rand() % x + 1; }   vector<int> G[N];   int dep[N];   double ans = 0;   void dfs(int x, int _fa, int _dep) {     dep[x] = _dep;     ans += 1. / dep[x];     for (auto v : G[x])       if (v != _fa) {         dfs(v, x, _dep + 1);       }   }   int Solve() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v), G[v].push_back(u);     }     dfs(1, 0, 1);     cout << fixed << setprecision(12) << ans << endl;     return 0;   }   void Pre() {}   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     Pre();     while (Solve())       ;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:50000000 )   using namespace std;   int tt[1000000], kix[1000000], num[1000000], degree[1000000], black[1000000],       fix[1000000];   vector<int> q, g[1000000];   int pirveli, p, i, j, n, m, k, a, b;   int par[100005][20];   long long ans[1000000];   void go(int x, int prev = -1) {     fix[x] = 1;     q.push_back(x);     for (int i = 0; i < g[x].size(); i++) {       int nxt = g[x][i];       if (nxt == prev) continue;       if (fix[nxt] == 0) {         go(nxt, x);         continue;       }       if (num[nxt] != -1) continue;       for (int j = q.size() - 1; j >= 0; j--) {         num[q[j]] = nxt;         if (q[j] == nxt) break;       }     }     q.pop_back();   }   void DFS(int v, int prev, int deg, int raod) {     kix[v] = 1;     degree[v] = deg;     if (tt[v] != 1) raod++;     black[v] = raod;     par[v][0] = num[prev];     for (int j = 1; j <= 19; j++)       if (par[v][j - 1] == -1)         par[v][j] = -1;       else         par[v][j] = par[par[v][j - 1]][j - 1];     for (int i = 0; i < g[v].size(); i++) {       int nxt = g[v][i];       if (nxt == prev) continue;       DFS(nxt, v, deg + 1, raod);     }   }   int LCA(int a, int b) {     for (int i = 18; i >= 0; i--) {       if (degree[a] - (1 << i) >= degree[b]) {         a = par[a][i];       }     }     if (a == b) return a;     for (int i = 18; i >= 0; i--) {       if (par[a][i] != par[b][i]) {         a = par[a][i];         b = par[b][i];       }     }     return par[a][0];   }   int main() {     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> a >> b;       a--;       b--;       g[a].push_back(b);       g[b].push_back(a);     }     for (i = 0; i < n; i++) num[i] = -1;     go(0);     for (i = 0; i <= n; i++)       for (j = 0; j <= 20; j++) par[i][j] = -1;     for (i = 0; i < n; i++) {       if (num[i] == -1 || num[i] == i) continue;       for (j = 0; j < g[i].size(); j++) g[num[i]].push_back(g[i][j]);     }     for (i = 0; i < n; i++)       if ((num[i] == -1 || num[i] == i)) {         for (j = 0; j < g[i].size(); j++) {           int nxt = g[i][j];           if (num[nxt] == i) {             g[i][j] = g[i].back();             g[i].pop_back();             j--;           } else if (num[nxt] == -1)             continue;           else             g[i][j] = num[nxt];         }       }     if (num[0] == -1)       pirveli = 0;     else       pirveli = num[0];     for (i = 0; i < n; i++)       if (num[i] == -1) {         num[i] = i;         tt[i] = 1;       }     DFS(pirveli, -1, 0, 0);     ans[0] = 1;     for (i = 1; i <= n; i++) ans[i] = ans[i - 1] * 2 % 1000000007;     cin >> k;     while (k--) {       cin >> a >> b;       a = num[a - 1];       b = num[b - 1];       if (degree[a] < degree[b]) swap(a, b);       p = LCA(a, b);       p = num[p];       cout << ans[black[a] + black[b] - 2 * black[p] + (tt[p] == 0)] << endl;     }   }