malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double eps = 1e-6;   const double PI = acos(-1);   const double R = 0.57721566490153286060651209;   const int maxn = 1005;   struct Edge {     int from, to, cap, flow, cost;     Edge(int u, int v, int c, int f, int cc)         : from(u), to(v), cap(c), flow(f), cost(cc) {}   };   struct MCMF {     int n, m;     vector<Edge> edges;     vector<int> G[maxn];     int inq[maxn];     int d[maxn];     int p[maxn];     int a[maxn];     void init(int n) {       this->n = n;       for (int i = 0; i <= n; ++i) G[i].clear();       edges.clear();     }     void add(int from, int to, int cap, int cost) {       edges.emplace_back(Edge(from, to, cap, 0, cost));       edges.emplace_back(Edge(to, from, 0, 0, -cost));       m = int(edges.size());       G[from].emplace_back(m - 2);       G[to].emplace_back(m - 1);     }     bool spfa(int s, int t, int &flow, int &cost) {       for (int i = 1; i <= n; ++i) d[i] = INF;       memset(inq, 0, sizeof(inq));       d[s] = 0;       inq[s] = 1;       p[s] = 0;       queue<int> q;       a[s] = INF;       q.push(s);       while (!q.empty()) {         int u = q.front();         q.pop();         inq[u] = 0;         for (int i = 0; i < int(G[u].size()); ++i) {           Edge &e = edges[G[u][i]];           if (e.cap > e.flow && d[e.to] > d[u] + e.cost) {             d[e.to] = d[u] + e.cost;             p[e.to] = G[u][i];             a[e.to] = min(a[u], e.cap - e.flow);             if (!inq[e.to]) {               q.push(e.to);               inq[e.to] = 1;             }           }         }       }       if (d[t] == INF) return false;       flow += a[t];       cost += d[t] * a[t];       for (int u = t; u != s; u = edges[p[u]].from) {         edges[p[u]].flow += a[t];         edges[p[u] ^ 1].flow -= a[t];       }       return true;     }     int MincostMaxflow(int s, int t, int &cost) {       int flow = 0;       cost = 0;       while (spfa(s, t, flow, cost))         ;       return flow;     }   } mcmf;   int n, m, mincost;   void solve() {     string S;     cin >> S;     cin >> n;     map<int, int> num, mp[n + 1];     vector<int> a(n + 1);     for (int i = 0; i < S.length(); i++) {       num[S[i] -  a  + 1]++;     }     for (int i = 1; i <= n; i++) {       string T;       cin >> T >> a[i];       for (int j = 0; j < T.length(); j++) {         mp[i][T[j] -  a  + 1]++;       }     }     int s = 0, t = n + 26 + 1;     mcmf.init(t);     for (int i = 1; i <= 26; i++) {       if (!num[i]) continue;       mcmf.add(s, i, num[i], 0);       for (int j = 1; j <= n; j++) {         if (!mp[j][i]) continue;         mcmf.add(i, j + 26, mp[j][i], j);       }     }     for (int i = 1; i <= n; i++) {       mcmf.add(i + 26, t, a[i], 0);     }     int maxflow = mcmf.MincostMaxflow(s, t, mincost);     if (maxflow == S.length())       cout << mincost <<   n ;     else       cout << -1 <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int OO = 0x3f3f3f3f, NegOO = -1 * OO, N = 1e6 + 5, mod = 1e9 + 7;   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   int main() {     int t;     cin >> t;     while (t--) {       int n, x, y, d;       cin >> n >> x >> y >> d;       if (x == y) {         cout << 0 <<   n ;         continue;       } else if (x < y) {         int mx = 1e9 + 5;         int ans1 = mx, ans2 = mx, ans3 = mx;         if ((y - x) % d == 0) ans1 = (y - x) / d;         if ((y - 1) % d == 0)           ans2 = (x - 1) / d + ((x - 1) % d != 0) + (y - 1) / d;         if ((n - y) % d == 0)           ans3 = (n - x) / d + ((n - x) % d != 0) + (n - y) / d;         int ans = min(min(ans1, ans2), ans3);         cout << ((ans != mx) ? ans : -1) <<   n ;       } else {         int mx = 1e9 + 5;         int ans1 = mx, ans2 = mx, ans3 = mx;         if ((x - y) % d == 0) ans1 = (x - y) / d;         if ((y - 1) % d == 0)           ans2 = (x - 1) / d + ((x - 1) % d != 0) + (y - 1) / d;         if ((n - y) % d == 0)           ans3 = (n - x) / d + ((n - x) % d != 0) + (n - y) / d;         int ans = min(min(ans1, ans2), ans3);         cout << ((ans != mx) ? ans : -1) <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> g[200000];   long long c[200000];   long long cnt;   void dfs(long long v, long long p = -1) {     cnt++;     long long cnt1 = cnt;     for (long long to : g[v]) {       if (to != p) {         dfs(to, v);       }     }     c[v] = cnt - cnt1 + 1;   }   signed main() {     long long t;     cin >> t;     for (long long q = 0; q < t; q++) {       long long k;       cin >> k;       k *= 2;       vector<pair<long long, long long>> edge;       long long t[k];       for (long long i = 0; i < k - 1; i++) {         long long a, b;         cin >> a >> b >> t[i];         a--;         b--;         g[a].push_back(b);         g[b].push_back(a);         edge.push_back({a, b});       }       dfs(0);       long long mnsum = 0, mxsum = 0;       for (long long i = 0; i < k - 1; i++) {         long long c1 = min(c[edge[i].first], c[edge[i].second]);         mnsum += c1 % 2 * t[i];         mxsum += min(c1, k - c1) * t[i];       }       cout << mnsum <<     << mxsum <<   n ;       for (long long i = 0; i < k; i++) {         g[i].clear();       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 410;   const int inf = 0x7fffffff;   int a[maxn];   int n;   int main() {     int ans = inf;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 2; i <= n; i++)       for (int j = i; j <= n; j++) {         int x = a[i - 1] - 1, y = 0;         for (int k = i; k <= j; k++) {           int t = x / a[k];           y += t;           x -= t * a[k];         }         x = a[i - 1] - 1 - x + a[j];         y++;         if (x < ans) {           int o = x;           for (int k = 1; k <= n; k++) {             int t = x / a[k];             y -= t;             x -= t * a[k];           }           if (y < 0) ans = o;         }       }     if (ans == inf)       puts( -1 );     else       printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int prime[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};   int main() {     int n;     cin >> n;     vector<int> res;     int limit = 2 * n * n;     for (int i = 0; i < 15; i++) {       res.clear();       res.push_back(1);       for (int j = 0; j <= i; j++) {         int p = prime[j];         int sz = res.size();         for (int k = 0; k < sz; k++) {           int x = res[k];           while (x * p <= limit) {             x *= p;             res.push_back(x);           }         }       }       if (res.size() >= n) {         break;       }     }     sort(res.begin(), res.end(), greater<int>());     for (int i = 0; i < n; i++) {       cout << res[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long nax = 1e5 + 7;   const long long mod = 1e9 + 7;   const long long inf = numeric_limits<long long>::max();   long long n, m;   bool check(vector<long long> &vec) {     vector<long long> freq(n + 1, 0);     for (long long i = 0; i < n; i++) {       if (vec[i] > n) return false;       freq[vec[i]]++;       if (freq[vec[i]] > 1) {         return false;       }     }     for (long long i = 0; i < n; i++) {       if (freq[i + 1] != 1) return false;     }     return true;   }   void test() {     cin >> n;     vector<long long> vec;     vec.push_back(0);     long long first = 0;     for (long long i = 1; i < n; i++) {       long long t;       cin >> t;       vec.push_back(vec.back() + t);       first = min(first, vec.back());     }     first = 1 - first;     for (long long &x : vec) x += first;     if (check(vec))       for (long long x : vec) cout << x <<    ;     else       cout << -1;   }   signed main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     long long T = 1;     while (T--) {       test();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int test;     cin >> test;     while (test--) {       int n;       cin >> n;       vector<vector<int>> v(n, vector<int>(n, 0));       for (int i = 0; i < n; i++) {         v[i][i] = 1;         v[(i + 1) % n][i] = 1;       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) cout << v[i][j] <<    ;         cout <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int inf = (long long int)1e18 + 19;   const long long int mod = (long long int)1e9 + 7;   void cazz() {     long long int t = 1, i;     long double j, n;     cin >> t;     while (t--) {       cin >> n;       i = 3, j = -1;       while (j < n) {         j = (((long double)180 * (i - 2)) / i);         i++;       }       if (j == n) {         cout <<  YES n ;         continue;       }       cout <<  NO n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cazz();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000 * 1000 + 10;   vector<int> vec[N];   vector<int> d[2];   bool mark[N];   void dfs(int v, int hh) {     mark[v] = true;     d[hh].push_back(v);     for (int u : vec[v])       if (!mark[u]) dfs(u, 1 - hh);   }   int main() {     int o;     cin >> o;     while (o--) {       int n, m;       cin >> n >> m;       for (int i = 0; i < n; i++) vec[i].clear(), mark[i] = false;       ;       d[0].clear();       d[1].clear();       for (int i = 0; i < m; i++) {         int a, b;         cin >> a >> b;         a--, b--;         vec[a].push_back(b);         vec[b].push_back(a);       }       dfs(0, 0);       if ((int)d[0].size() > (int)d[1].size()) swap(d[0], d[1]);       cout << (int)d[0].size() << endl;       for (int a : d[0]) cout << a + 1 <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int inf = 1000000007;   const double pi = 2 * acos(0.0);   using namespace std;   int gcd(int a, int b) {     a = abs(a);     b = abs(b);     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   int main() {     map<long long, int> m;     long long n, k;     scanf( %lld%lld , &n, &k);     long long arr[n];     for (long long i = 0; i < n; i++) {       scanf( %lld , &arr[i]);       m.insert(make_pair(arr[i], 1));     }     vector<long long> ans;     long long sum = 0;     for (int i = 1; i < 1e9; i++) {       if (sum > k) {         ans.pop_back();         break;       }       if (m[i] != 1) {         sum += i;         ans.push_back(i);       }     }     printf( %d n , ans.size());     for (long long i : ans) {       printf( %d  , i);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500005;   int ult;   int cont;   int prim;   char cad[MAXN];   bool Solve(int a, int n, int T) {     int c = 0, time = 0;     queue<int> s;     prim = -1;     for (int i = 0; i < n && c < cont; i++, time++) {       if (cad[i] ==  H  && a > 0) {         c++;         a--;         if (prim == -1) prim = i;       } else if (cad[i] ==  H ) {         s.push(i);         if (prim == -1) prim = i;       } else if (cad[i] ==  S ) {         a++;         if (a >= s.size()) {           if (!s.empty()) {             int aux = abs(s.front() - i);             time += aux;             s.pop();             a--;             c++;             while (!s.empty()) {               c++;               a--;               s.pop();             }             if (c < cont) time += aux;           }         }       }       if (c == cont) ult = i;     }     time = min(time, ult + 1 + (ult - prim));     return (time <= T && c == cont);   }   int main() {     int n;     long long int T;     scanf( %d %lld , &n, &T);     scanf(  n%s , cad);     for (int i = 0; i < n; i++)       if (cad[i] ==  H ) cont++;     int ini = 0, fin = cont;     while (ini < fin) {       int med = (ini + fin) / 2;       if (!Solve(med, n, T))         ini = med + 1;       else         fin = med;     }     if (Solve(ini, n, T))       printf( %d n , ini);     else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, k, m, n, a[100400], t, w, q, sum = 0;     char s[105000];     long double x, y;     cin >> q;     for (j = 0; j < q; j++) {       cin >> n;       cin >> s;       if (n > 2) {         cout <<  YES  << endl;         cout << 2 << endl;         cout << s[0] <<    ;         for (i = 1; i < n; i++) cout << s[i];         cout << endl;       } else {         if (s[0] -  0  < s[1] -  0 ) {           cout <<  YES  << endl;           cout << 2 << endl;           cout << s[0] <<     << s[1] << endl;         } else           cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   long long fact(int i) {     if (i <= 1)       return 1;     else       return i * fact(i - 1);   }   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int arr[4];       for (int i = 0; i < 4; i++) {         cin >> arr[i];       }       int minus = arr[0] + arr[1];       string final[4];       if (minus % 2 == 0) {         final[0] =  Tidak ;         final[1] =  Tidak ;         if (arr[2] == 0) {           if (arr[1] == 0) {             final[2] =  Tidak ;           } else {             final[2] =  Ya ;           }         } else {           final[2] =  Ya ;         }         if (arr[3] == 0) {           if (arr[0] == 0) {             final[3] =  Tidak ;           } else {             final[3] =  Ya ;           }         } else {           final[3] =  Ya ;         }       } else {         final[2] =  Tidak ;         final[3] =  Tidak ;         if (arr[0] == 0) {           if (arr[3] == 0) {             final[0] =  Tidak ;           } else {             final[0] =  Ya ;           }         } else {           final[0] =  Ya ;         }         if (arr[1] == 0) {           if (arr[2] == 0) {             final[1] =  Tidak ;           } else {             final[1] =  Ya ;           }         } else {           final[1] =  Ya ;         }       }       for (int i = 0; i < 4; i++) {         cout << final[i] <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a;   void SieveOfEratosthenes(int n) {     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (int p = 2; p <= n; p++)       if (prime[p]) a.push_back(p);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     SieveOfEratosthenes(100000);     for (int i = 2; i <= n; i++) {       for (int j = 0; j < a.size(); j++) {         if (i % a[j] == 0) {           cout << j + 1 <<    ;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(int a, int b) { return (a > b); }   int main() {     int a, b, n, l, t, m, x, ans, r;     long long cek;     scanf( %d %d %d , &a, &b, &n);     for (int i = 1; i <= n; i++) {       scanf( %d %d %d , &l, &t, &m);       if (t < a + (long long)(l - 1) * b)         printf( -1 n );       else {         x = 1;         ans = l;         while (x > 0) {           r = ans + x;           cek = ((a + (long long)(r - 1) * b + a + (long long)(l - 1) * b) *                  (r - l + 1)) /                 2;           cek = max(cek / m + (cek % m == 0 ? 0 : 1), a + (long long)(r - 1) * b);           if (cek <= t)             ans += x, x *= 2;           else             x /= 2;         }         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fun(string s, int i) {     int k = 0;     while (s[i] ==  0  & i >= 0) {       k++;       i--;     }     return k;   }   int main(int argc, char const *argv[]) {     string s;     int a, k = 0, count = 1;     cin >> a;     cin >> s;     string ans =   ;     int i = s.size() - 1;     if (s[i] ==  0 ) {       while (s[i] ==  0 ) {         ans = ans +  0 ;         i--;       }     }     while (i >= 0) {       k = 0;       if (s[i] ==  1 ) {         while (s[i] ==  1  && i >= 0) {           k++;           i--;         }         ans = ans + char( 0  + k);       } else if (s[i] ==  0 ) {         int t = fun(s, i);         i = i - t;         while (t > 1) {           ans = ans +  0 ;           t = t - 1;         }       }     }     reverse(ans.begin(), ans.end());     int myint1 = stoi(ans);     cout << myint1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 55;   int n, m, dp[MAX_N][MAX_N][MAX_N][MAX_N];   char a[MAX_N][MAX_N];   int dfs(int x1, int y1, int x2, int y2) {     if (dp[x1][y1][x2][y2] >= 0) {       return dp[x1][y1][x2][y2];     }     if (x1 == x2 && y1 == y2) {       return dp[x1][y1][x2][y2] = a[x1][y1] ==  # ;     }     int &ans = dp[x1][y1][x2][y2];     ans = max(x2 - x1 + 1, y2 - y1 + 1);     for (int i = x1; i < x2; ++i) {       ans = min(ans, dfs(x1, y1, i, y2) + dfs(i + 1, y1, x2, y2));     }     for (int j = y1; j < y2; ++j) {       ans = min(ans, dfs(x1, y1, x2, j) + dfs(x1, j + 1, x2, y2));     }     return ans;   }   int main() {     scanf( %d , &n);     memset(dp, -1, sizeof dp);     for (int i = 1; i <= n; ++i) {       scanf( %s , a[i] + 1);     }     printf( %d n , dfs(1, 1, n, n));   }
#include <bits/stdc++.h>   using namespace std;   const long long int delta = 1e9 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int x;     int d;     cin >> x >> d;     vector<long long int> ans;     long long int cur = 1;     for (int i = 31; i >= 0; i--) {       long long int cnt = (1LL << i);       while (x >= cnt) {         x -= cnt;         for (int j = 0; j < i; j++) {           ans.push_back(cur);         }         cur += d;         ans.push_back(cur);         cur += d;       }     }     cout << ans.size() <<   n ;     for (auto a : ans) cout << a <<    ;     cout << endl;     ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string str;     cin >> str;     int n = str.length();     map<char, int> mp;     for (int i = 0; i < n; i++) {       mp[str[i]]++;     }     if (mp.size() % 2 == 1)       cout <<  IGNORE HIM! ;     else       cout <<  CHAT WITH HER! ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353LL, INV2 = (MOD + 1) / 2;   const int MAXN = 500;   long long DP[MAXN + 1][MAXN + 1];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int N, K;     cin >> N >> K;     for (int k = 1; k <= min(N, K); ++k) {       DP[k][0] = 2;       for (int n = 1; n <= N; ++n) {         for (int m = n - 1; m >= 0 && n - m <= k; --m) DP[k][n] += DP[k][m];         DP[k][n] %= MOD;       }     }     long long ans = 0;     for (int k = 1; k <= N && k < K; ++k) {       long long aux = (DP[k][N] + MOD - DP[k - 1][N]) *                       DP[min((K + k - 1) / k - 1, N)][N] % MOD;       aux = aux * INV2 % MOD;       ans += aux;       ans %= MOD;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long cubes[100001], x;   long long my_pow(long long x) { return x * x * x; }   pair<long long, long long> best;   void rec(long long m, long long steps, long long subtracted) {     if (m == 0) {       best = max(best, make_pair(steps, subtracted));       return;     }     long long x = 1;     while (my_pow(x + 1) <= m) ++x;     rec(m - my_pow(x), steps + 1, subtracted + my_pow(x));     if (x - 1 >= 0)       rec(my_pow(x) - 1 - my_pow(x - 1), steps + 1, subtracted + my_pow(x - 1));   }   int main() {     long long m;     scanf( %I64d , &m);     rec(m, 0, 0);     printf( %I64d %I64d , best.first, best.second);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long long infl = 0x3f3f3f3f3f3f3f3fLL;   const long long infi = 0x3f3f3f3f;   mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());   const long long mod = 1e9 + 7;   const long long N = 1e6 + 5;   void solve() {     long long m;     cin >> m;     cout << (m / 4 + 1) % mod * ((m / 2 - m / 4 + 1) % mod + mod) % mod <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cout << fixed << setprecision(15);     long long t = 1;     cin >> t;     while (t--) solve();     return 0;   }   long long powm(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   long long divide(long long a, long long b) {     return (a % mod) * powm(b, mod - 2) % mod;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
#include <bits/stdc++.h>   using namespace std;   int ABS(int a) {     if (a < 0) return (-a);     return a;   }   void input() {}   int n, table;   int a[55];   double dp[55][55][55][55];   int aim;   double f(int idx, int sum, int k, int cnt) {     if (idx == n) {       if (sum != aim || cnt == 0) return 0;       return (k * cnt * 1.0) / ((double)(n)-k);     }     double &res = dp[idx][sum][k][cnt];     if (res > -0.5) return res;     double invK = (k + 1.0) / (idx + 1.0);     double invNK = (idx - k + 1.0) / (idx + 1.0);     res = 0.0;     if (sum + a[idx] <= aim) {       res += invK * f(idx + 1, sum + a[idx], k + 1, cnt);     }     if (aim + a[idx] > table) cnt++;     res += invNK * f(idx + 1, sum, k, cnt);     return res;   }   int main() {     input();     cin >> n;     int sum = 0;     for (int i = (0); i < (n); ++i) {       cin >> a[i];       sum += a[i];     }     cin >> table;     if (sum <= table) {       printf( %d n , n);       return 0;     }     double ans = 0.0;     for (int i = (1); i < (table + 1); ++i) {       for (int I = (0); I < (55); ++I)         for (int j = (0); j < (55); ++j)           for (int k = (0); k < (55); ++k)             for (int l = (0); l < (55); ++l) dp[I][j][k][l] = -1.0;       aim = i;       ans += f(0, 0, 0, 0);     }     printf( %.12lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   const int MAXK = 20;   int times[MAXN];   int dp[MAXN][MAXK];   int subtree[MAXN];   int marc[MAXN];   int prof[MAXN];   vector<int> graph[MAXN];   vector<pair<int, int>> arcs;   void init_dfs(int u) {     marc[u] = 1;     for (int v : graph[u]) {       if (marc[v]) continue;       dp[v][0] = u;       for (int i = 1; i < MAXK; ++i) dp[v][i] = dp[dp[v][i - 1]][i - 1];       prof[v] = prof[u] + 1;       init_dfs(v);     }   }   inline int lca(int a, int b) {     if (prof[a] > prof[b]) swap(a, b);     int d = prof[b] - prof[a];     for (int i = 0; i < MAXK; ++i)       if (d & (1 << i)) b = dp[b][i];     if (a == b) return a;     for (int i = MAXK - 1; i >= 0; --i)       if (dp[a][i] != dp[b][i]) {         a = dp[a][i];         b = dp[b][i];       }     return dp[a][0];   }   inline void add_path(int u, int v) {     ++times[u];     --times[v];   }   inline void add_arc(int u, int v) {     graph[u].push_back(v);     graph[v].push_back(u);     arcs.push_back({u, v});   }   void final_dfs(int u) {     marc[u] = 2;     subtree[u] = times[u];     for (int v : graph[u]) {       if (marc[v] == 2) continue;       final_dfs(v);       subtree[u] += subtree[v];     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n - 1; ++i) {       int u, v;       scanf( %d%d , &u, &v);       add_arc(u, v);     }     init_dfs(1);     int k;     scanf( %d , &k);     for (int i = 0; i < k; ++i) {       int u, v;       scanf( %d%d , &u, &v);       int w = lca(u, v);       add_path(u, w);       add_path(v, w);     }     final_dfs(1);     for (auto [u, v] : arcs) {       if (prof[u] < prof[v]) swap(u, v);       printf( %d  , subtree[u]);     }     printf(  n );   }