malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int r, c, w;   char a[1005][1005];   int rows[1005], columns[1005];   int main() {     scanf( %d%d , &r, &c);     for (int i = 1; i <= r; i++)       for (int j = 1; j <= c; j++) {         cin >> a[i][j];         if (a[i][j] ==  * ) {           w++;           rows[i]++;           columns[j]++;         }       }     for (int i = 1; i <= r; i++)       for (int j = 1; j <= c; j++) {         if (rows[i] + columns[j] - (a[i][j] ==  * ) == w) {           printf( YES n%d %d , i, j);           return 0;         }       }     printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n;   vector<int> id;   int a[N];   int tr[N];   int find(int u) {     return lower_bound(id.begin(), id.end(), u) - id.begin() + 1;   }   int lowbit(int x) { return x & -x; }   void add(int x, int c) {     for (int i = x; i <= n; i += lowbit(i)) tr[i] += c;   }   int sum(int x) {     int res = 0;     for (int i = x; i; i -= lowbit(i)) res += tr[i];     return res;   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n;       id.clear();       memset(tr, 0, sizeof tr);       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         id.push_back(a[i]);       }       sort(id.begin(), id.end());       id.erase(unique(id.begin(), id.end()), id.end());       int tot = id.size();       long long res = 0;       for (int i = 0; i < n; i++) {         int id = find(a[i]);         int q1 = sum(tot) - sum(id);         int q2 = sum(id - 1);         add(id, 1);         res += (long long)min(q1, q2);       }       cout << res << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[110];   int n, k;   double p[110];   double dp[110][110];   int was[110][110];   double dist(pair<int, int> a, pair<int, int> b) {     double x = a.first - b.first;     double y = a.second - b.second;     return sqrt(x * x + y * y);   }   double rec(int pos, int kol) {     if (pos == n) {       if (kol >= k) return 1;       return 0;     }     if (was[pos][kol]) return dp[pos][kol];     was[pos][kol] = 1;     double res = p[pos] * rec(pos + 1, kol + 1);     res += (1 - p[pos]) * rec(pos + 1, kol);     return dp[pos][kol] = res;   }   int main() {     scanf( %d , &n);     int x, y, e;     scanf( %d%d , &k, &e);     scanf( %d%d , &x, &y);     e = 1000 - e;     for (int i = (0); i < (n); ++i) scanf( %d%d , &a[i].first, &a[i].second);     double l = 0, r = 1e40;     double best = -1;     for (int i = (0); i < (1000); ++i) {       double m = (l + r) / 2;       for (int i = (0); i < (n); ++i) {         double d = dist(make_pair(x, y), a[i]);         if (d <= m)           p[i] = 1;         else {           double k = d * d / m / m;           p[i] = exp(1.0 - k);         }       }       memset(was, 0, sizeof(was));       double prob = rec(0, 0);       if (prob * 1000 >= e) {         best = m;         r = m;       } else         l = m;     }     printf( %.10lf n , best);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300500;   int T[N], L[N], C[N];   int m;   int len = 0;   const int inf = 100500;   int A[N];   int fs = -1, pos = -1;   void apply() {     for (int i = 0; i < m; i++) {       if (i == m - 1) {         pos = len;         fs = m - 1;         goto end;       }       if (T[i] == 1) {         A[len++] = L[i];         if (len >= inf) {           fs = i + 1;           pos = len;           goto end;         }       } else {         assert(L[i] <= len);         for (int q = 0; q < C[i]; q++) {           for (int j = 0; j < L[i]; j++) {             A[len++] = A[j];           }           if (len >= inf) {             for (int u = m - 1; u >= i; u--)               T[u + 1] = T[u], L[u + 1] = L[u], C[u + 1] = C[u];             ++m;             C[i + 1] = C[i] - q - 1;             C[i] = q + 1;             fs = i + 1;             pos = len;             goto end;           }         }       }     }   end:;   }   inline int blen(int o) {     if (T[o] == 1)       return 1;     else       return L[o] * C[o];   }   int main() {     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d , &T[i]);       if (T[i] == 1)         scanf( %d , &L[i]);       else         scanf( %d %d , &L[i], &C[i]);     }     T[m] = 0;     L[m] = -42;     m++;     apply();     int n;     scanf( %d , &n);     int curg = fs;     long long l = pos, r = pos + blen(fs);     for (int i = 0; i < n; i++) {       long long x;       scanf( %I64d , &x);       --x;       int ans = -1;       if (x < len)         ans = A[(int)x];       else {         while (r <= x && curg < m - 1) l = r, r += blen(++curg);         assert(l <= x && x < r);         if (T[curg] == 1)           ans = L[curg];         else           ans = A[(x - l) % L[curg]];       }       printf( %d%c , ans,    n [i + 1 == n]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     string s1, s2, s3;     cin >> t;     map<string, int> mp;     mp[ polycarp ] = 1;     while (t--) {       cin >> s1 >> s2 >> s3;       transform(s1.begin(), s1.end(), s1.begin(), ::tolower);       transform(s3.begin(), s3.end(), s3.begin(), ::tolower);       mp[s1] = mp[s3] + 1;     }     map<string, int>::iterator it;     int ans = 0;     for (it = mp.begin(); it != mp.end(); ++it)       if (it->second > ans) ans = it->second;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int vp, vd, t, f, c, ans = 0;     double tempt;     double curs = 0;     cin >> vp >> vd >> t >> f >> c;     curs = vp * t;     if (vp >= vd) {       cout << 0 << endl;       return 0;     }     while (curs < c) {       tempt = curs / (vd - vp);       curs += tempt * vp;       if (curs >= c)         break;       else         curs += (tempt + f) * vp;       ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const long long INFL = 1e18 + 123;   const double PI = atan2(0, -1);   mt19937 tw(960172);   long long rnd(long long x, long long y) {     static uniform_int_distribution<long long> d;     return d(tw) % (y - x + 1) + x;   }   bool check(string s) {     string tmp = s;     reverse(tmp.begin(), tmp.end());     return tmp != s;   }   void solve() {     string s;     cin >> s;     int ans = 0;     for (int i = 0; i < ((int)(s).size()); ++i) {       string cur =   ;       for (int j = i; j < ((int)(s).size()); ++j) {         cur += s[j];         if (check(cur)) {           ans = max(ans, j - i + 1);         }       }     }     cout << ans <<   n ;   }   int main() {     cerr << fixed << setprecision(15);     cout << fixed << setprecision(15);     ios::sync_with_stdio(false);     int tests = 1;     for (int it = 1; it <= tests; ++it) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     int n;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n;       int arr[2 * n];       for (int j = 0; j < 2 * n; j++) {         cin >> arr[j];       }       sort(arr, arr + 2 * n);       vector<int> left, right;       for (int j = 0; j < 2 * n; j++) {         if (j == 2 * n - 1) {           if (n % 2 == 0) {             if (j % 2 != 0)               left.push_back(arr[j]);             else               right.push_back(arr[j]);           } else {             if (j % 2 == 0)               left.push_back(arr[j]);             else               right.push_back(arr[j]);           }         } else {           if (j % 2 == 0)             left.push_back(arr[j]);           else             right.push_back(arr[j]);         }       }       cout << abs(left[left.size() / 2] - right[right.size() / 2]) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int a[n];     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);     }     sort(a, a + n);     if (n % 2)       printf( %d n , a[n / 2]);     else       printf( %d n , a[n / 2 - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q, n, x, y, f1, f2, f3, f4;     cin >> q;     for (int i = 0; i < q; ++i) {       cin >> n;       int minx = -100000, miny = -100000, maxx = 100000, maxy = 100000;       for (int o = 0; o < n; ++o) {         cin >> x >> y >> f1 >> f2 >> f3 >> f4;         if (f1 == 0 && minx < x) {           minx = x;         }         if (f2 == 0 && maxy > y) {           maxy = y;         }         if (f3 == 0 && maxx > x) {           maxx = x;         }         if (f4 == 0 && miny < y) {           miny = y;         }       }       if (minx > maxx || miny > maxy) {         cout << 0 << endl;       } else {         cout << 1 <<     << minx <<     << miny << endl;       }     }     cin >> n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       int tmp = b + 1;       long long len = -1;       while (tmp != 0) {         tmp /= 10;         len++;       }       long long ans = a * len;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bitset<7000> bit;   int main() {     int n, count = 0;     cin >> n;     while (n--) {       int int1, int2;       string stars;       cin >> int1 >> int2;       if (n >= 1) cin >> stars;       int a = int1 / 10, b = int1 % 10, c = int2 % 10, d = int2 / 10;       int i1 = 1000 * a + 100 * b + 10 * c + d,           i2 = 1000 * d + 100 * a + 10 * b + c,           i3 = 1000 * c + 100 * d + 10 * a + b,           i4 = 1000 * b + 100 * c + 10 * d + a;       if (!bit[i1] && !bit[i2] && !bit[i3] && !bit[i4]) {         count++;         bit.set(i1);         bit.set(i2);         bit.set(i3);         bit.set(i4);       }     }     cout << count << endl;   }
#include <bits/stdc++.h>   using namespace std;   int dx[3] = {-1, 1, 0};   int dy[3] = {1, 1, 1};   int d[5][205];   char mp[5][205];   int n, k, flag;   void dfs(int x, int y) {     d[x][y] = 1;     if (flag) return;     if (y >= n) {       flag = 1;       return;     }     if (mp[x][y + 1] !=  . ) return;     if (x < 2 && !d[x + 1][y + 3]) {       if (mp[x + 1][y + 1] ==  .  && mp[x + 1][y + 2] ==  .  &&           mp[x + 1][y + 3] ==  . )         dfs(x + 1, y + 3);     }     if (x > 0 && !d[x - 1][y + 3]) {       if (mp[x - 1][y + 1] ==  .  && mp[x - 1][y + 2] ==  .  &&           mp[x - 1][y + 3] ==  . )         dfs(x - 1, y + 3);     }     if (!d[x][y + 3]) {       if (mp[x][y + 1] ==  .  && mp[x][y + 2] ==  .  && mp[x][y + 3] ==  . )         dfs(x, y + 3);     }   }   int main() {     int t;     cin >> t;     while (t--) {       memset(d, 0, sizeof(d));       cin >> n >> k;       for (int i = 0; i < 3; i++) {         for (int j = 0; j < n; j++) {           cin >> mp[i][j];         }         mp[i][n] = mp[i][n + 1] = mp[i][n + 2] = mp[i][n + 3] = mp[i][n + 4] =             mp[i][n + 5] = mp[i][n + 6] = mp[i][n + 7] =  . ;       }       flag = 0;       for (int i = 0; i < 3; i++) {         for (int j = 0; j < n; j++) {           if (mp[i][j] ==  s ) {             dfs(i, j);           }         }       }       if (flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cx[] = {-1, 0, 0, 1, -1, -1, 1, 1, 0},       cy[] = {0, -1, 1, 0, -1, 1, 1, -1, 0};   int ingrid(int ii, int jj, int R, int C) {     if (ii < 0 || jj < 0 || ii >= R || jj >= C) return 0;     return 1;   }   int main() {     long long n;     cin >> n;     long long maxx = -1, minn = (1LL << 60);     for (int i = 1; i <= sqrt(n); i++) {       long long a = i;       if (n % a == 0) {         long long c = n / a;         for (int i = a; i <= sqrt(c); i++) {           if (c % i == 0) {             long long b = c / i;             long long c = i;             long long temp = (a + 1) * (b + 2) * (c + 2);             minn = min(minn, temp);             maxx = max(maxx, temp);             temp = (b + 1) * (a + 2) * (c + 2);             minn = min(minn, temp);             maxx = max(maxx, temp);             temp = (c + 1) * (a + 2) * (b + 2);             minn = min(minn, temp);             maxx = max(maxx, temp);           }         }       }     }     cout << minn - n <<     << maxx - n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100100;   const int INF = ~0U >> 1;   int N, idx[MAXN];   map<int, int> mp, o_cnt, ls;   map<int, vector<int> > rs;   int main() {     scanf( %d , &N);     int a;     for (int i = 1; i <= N; ++i) {       scanf( %d , &a);       mp[a] = i;     }     int o = INF;     for (int i = 1; i <= N; ++i) {       scanf( %d , &a);       a = idx[i] = mp[a];       if (i <= a) {         o_cnt[ls[i] = a - i] += 1;       } else {         rs[i - a].push_back(i);       }       o = min(o, abs(a - i));     }     printf( %d n , o);     for (int i = 1; i < N; ++i) {       if ((o_cnt[ls[i]] -= 1) == 0) {         o_cnt.erase(o_cnt.find(ls[i]));       }       ls.erase(ls.find(i));       rs[N + i - idx[i]].push_back(i);       if (rs.count(i)) {         for (vector<int>::iterator it = rs[i].begin(); it != rs[i].end(); ++it) {           o_cnt[ls[*it] = -i] += 1;         }         rs.erase(rs.find(i));       }       o = o_cnt.size() ? o_cnt.begin()->first + i : INF;       o = min(o, rs.size() ? rs.begin()->first - i : INF);       printf( %d n , o);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long n, ans, dp[200005][3], sz[200005][3];   vector<int> gr[200005];   void dfs(int x, int p) {     sz[x][0]++;     for (int i = 0; i < gr[x].size(); i++) {       int u = gr[x][i];       if (u == p) continue;       dfs(u, x);       dp[x][0] += dp[u][1] + sz[u][1] + 1;       dp[x][1] += dp[u][0] + sz[u][0];       sz[x][0] += sz[u][0];       sz[x][1] += sz[u][1];     }   }   void root(int x, int p) {     ans += dp[x][0];     for (int i = 0; i < gr[x].size(); i++) {       int u = gr[x][i];       if (u == p) continue;       dp[x][0] -= dp[u][1] + sz[u][1] + 1;       dp[x][1] -= dp[u][0] + sz[u][0];       sz[x][0] -= sz[u][0];       sz[x][1] -= sz[u][1];       sz[u][1] += sz[x][1];       sz[u][0] += sz[x][0];       dp[u][1] += dp[x][0] + sz[x][0];       dp[u][0] += dp[x][1] + sz[x][1] + 1;       root(u, x);       dp[u][0] -= dp[x][1] + sz[x][1] + 1;       dp[u][1] -= dp[x][0] + sz[x][0];       sz[u][0] -= sz[x][0];       sz[u][1] -= sz[x][1];       sz[x][1] += sz[u][1];       sz[x][0] += sz[u][0];       dp[x][1] += dp[u][0] + sz[u][0];       dp[x][0] += dp[u][1] + sz[u][1] + 1;     }   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       gr[x].push_back(y);       gr[y].push_back(x);     }     dfs(1, 0);     root(1, 0);     cout << ans / 2;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s, t;     cin >> n >> s >> t;     vector<int> a(n + 1);     for (int i = 0; i < n; ++i)       a[i] = (s[n - i - 1] -  a ) + (t[n - i - 1] -  a );     for (int i = 0; i < n; ++i) {       if (a[i] >= 26) {         ++a[i + 1];         a[i] -= 26;       }     }     vector<int> b(n + 1);     b[0] = a[0] / 2;     for (int i = 1; i <= n; ++i) {       b[i] = a[i] / 2;       if (a[i] & 1) b[i - 1] += 13;     }     for (int i = n - 1; i >= 0; --i) cout << char( a  + b[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k, l;     cin >> n >> m >> k >> l;     if (m > n || n - k < l) return cout << -1, 0;     long long ans = k / m;     k %= m;     while (k > 0) {       k -= m;       ans++;     }     l += k;     ans += (l + m - 1) / m;     if (ans * m > n) return cout << -1, 0;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300 * 1000 + 9;   const int LOGN = 19;   const int M = 21;   const long long INF64 = 1e18;   int n, m, q;   vector<pair<int, int> > g[N];   int p[LOGN][N];   int tin[N], tout[N], T;   long long h[N];   set<pair<int, int> > badEdges;   long long d[M + M][N];   bool u[N];   void dfs(int v, int pr) {     tin[v] = T++;     p[0][v] = pr;     u[v] = true;     for (int i = 1; i < LOGN; ++i) p[i][v] = p[i - 1][p[i - 1][v]];     for (auto e : g[v]) {       int to = e.first, len = e.second;       if (!u[to]) {         h[to] = h[v] + len;         dfs(to, v);         if (v < to)           badEdges.erase(make_pair(v, to));         else           badEdges.erase(make_pair(to, v));       }     }     tout[v] = T;   }   bool isAncestor(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }   int getLCA(int a, int b) {     if (isAncestor(a, b)) return a;     if (isAncestor(b, a)) return b;     for (int i = LOGN - 1; i >= 0; --i)       if (!isAncestor(p[i][a], b)) a = p[i][a];     return p[0][a];   }   void dij(int st, long long d[N]) {     set<pair<long long, int> > q;     for (int i = 0; i < n; ++i) d[i] = INF64;     d[st] = 0;     q.insert(make_pair(d[st], st));     while (!q.empty()) {       int v = q.begin()->second;       q.erase(q.begin());       for (auto e : g[v]) {         int to = e.first, len = e.second;         if (d[to] > d[v] + len) {           q.erase(make_pair(d[to], to));           d[to] = d[v] + len;           q.insert(make_pair(d[to], to));         }       }     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       int u, v, w;       scanf( %d %d %d , &u, &v, &w);       --u, --v;       g[u].push_back(make_pair(v, w));       g[v].push_back(make_pair(u, w));     }     for (int v = 0; v < n; ++v)       for (auto e : g[v])         if (v < e.first) badEdges.insert(make_pair(v, e.first));     dfs(0, 0);     int cpos = 0;     for (auto e : badEdges) dij(e.first, d[cpos++]);     scanf( %d , &q);     for (int tc = 0; tc < q; ++tc) {       int u, v;       scanf( %d %d , &u, &v);       --u, --v;       int lca = getLCA(u, v);       long long ans = h[u] + h[v] - 2 * h[lca];       for (int i = 0; i < badEdges.size(); ++i) ans = min(ans, d[i][u] + d[i][v]);       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j;     int n;     scanf( %d , &n);     if ((n * n) % 2 == 1) {       printf( %d n , ((n * n) / 2) + 1);     } else {       printf( %d n , (n * n) / 2);     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         if ((i + j) % 2 == 0) {           printf( C );         } else {           printf( . );         }       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bitset<20> a;   vector<int> w;   int sol = 0;   void verific(int &l, int &r, int &x) {     int sum = 0, i, minim = INT_MAX, maxim = INT_MIN;     for (i = 0; i < w.size(); ++i) {       if (a[i]) {         sum += w[i];         minim = min(minim, w[i]);         maxim = max(maxim, w[i]);       }     }     if (sum >= l and sum <= r and maxim - minim >= x) ++sol;   }   int main() {     int n, i, val, l, r, x;     cin >> n >> l >> r >> x;     for (i = 1; i <= n; ++i) {       cin >> val;       w.push_back(val);     }     for (i = 1; i <= 1 << n; ++i) {       a = i;       if (i & (i - 1) == 0) continue;       verific(l, r, x);     }     cout << sol;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     string s;     cin >> s;     int arr[10] = {0};     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  L ) {         int i = 0;         for (; i < 10; i++) {           if (arr[i] == 0) break;         }         arr[i] = 1;       } else if (s[i] ==  R ) {         int i = 9;         for (; i >= 0; i--) {           if (arr[i] == 0) break;         }         arr[i] = 1;       } else {         int t = s[i] - 48;         arr[t] = 0;       }     }     for (int i = 0; i < 10; i++) cout << arr[i];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int ok(double x, double a[]) {     double z1 = 0, z2 = 0;     for (int i = 0; i < n; i++) {       if (x - a[i] > 0) {         z1 += x - a[i];       }       if (x - a[i] < 0) {         double ans = 1 - (k * (double)1) / 100;         z2 += (a[i] - x) * ans;       }     }     if (z1 <= z2) {       return 1;     }     return 0;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     double a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     double ans = 0, low = 0, high = 10000;     int z = 0;     while (low < high) {       z++;       double mid = (low + high) / 2;       if (ok(mid, a) == 1) {         low = mid;         ans = mid;       } else {         high = mid;       }       if (z == 999) {         break;       }     }     cout << setprecision(12) << ans;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimize( O3 )   bool FLAG = 0;   using namespace std;   const long long MOD = (long long)1e9 + 7, N = (long long)2e6 + 222;   const long long INF = (long long)1e18;   long long dx[] = {0, -1, 0, 1, 0};   long long dy[] = {0, 0, 1, 0, -1};   long long b[N];   inline void solve() {     long long n;     cin >> n;     long long k = 1;     vector<long long> v;     while (n != 0) {       if (n < k) {         v.push_back(n);         n = 0;         break;       }       n -= k;       v.push_back(k);       k += k;     }     sort(v.begin(), v.end());     cout << (long long)(v.size()) - 1 << endl;     for (long long i = 1; i < (long long)(v.size()); ++i) {       cout << v[i] - v[i - 1] <<    ;     }     cout << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[200005];   int t1[200005], t2[200005];   bool vis[200005];   int n, x, a, b;   void dfs1(int step, int t) {     t1[step] = t;     vis[step] = true;     for (int i = 0; i < v[step].size(); i++) {       if (!vis[v[step][i]]) dfs1(v[step][i], t + 1);     }   }   void dfs2(int step, int t) {     t2[step] = t;     vis[step] = true;     for (int i = 0; i < v[step].size(); i++) {       if (!vis[v[step][i]]) dfs2(v[step][i], t + 1);     }   }   int main() {     cin >> n >> x;     for (int i = 1; i <= n - 1; i++) {       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     memset(vis, false, sizeof(vis));     dfs1(1, 0);     memset(vis, false, sizeof(vis));     dfs2(x, 0);     int maxl = 0;     for (int i = 1; i <= n; i++) {       if (t1[i] > t2[i]) maxl = max(maxl, 2 * t1[i]);     }     cout << maxl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       int n, k, temp;       cin >> n >> k;       set<int> s;       for (int i = 0; i < n; i++) {         cin >> temp;         s.insert(temp);       }       set<int>::reverse_iterator it;       int count = 0;       for (it = s.rbegin(); it != s.rend(); it++) {         if ((*it - k * count) <= 0) break;         count++;       }       cout << count <<   n ;     }     return 0;   }