malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1000000;   int f[N], sz[N], ak, Ak, n, m, ans[N];   struct data {     int a, b, c, d, e;     data(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0)         : a(a), b(b), c(c), d(d), e(e) {}   } S[N];   struct edge {     int x, y, z, id;     bool operator<(const edge& e) const { return z < e.z; }   } e[N], ee[N];   int find(int x) { return x == f[x] ? x : find(f[x]); }   void me(int x, int y) {     int X = find(x), Y = find(y);     if (X == Y) return;     S[Ak++] = data(X, Y, sz[X], sz[Y], ak);     if (sz[X] & 1 & sz[Y]) ak -= 2;     if (sz[X] > sz[Y]) swap(X, Y);     f[X] = Y;     sz[Y] += sz[X];   }   void pop(int tt) {     while (Ak > tt) {       data haha = S[--Ak];       ak = haha.e;       f[haha.a] = haha.a;       f[haha.b] = haha.b;       sz[haha.a] = haha.c;       sz[haha.b] = haha.d;     }   }   void solve(int l, int r, int x, int y) {     if (x > y) return;     if (l == r) {       for (int i = x; i <= y; i++) ans[i] = l;       return;     }     int mid = (l + r) >> 1, t = y + 1, tt = Ak;     for (int i = l; i <= mid; i++)       if (ee[i].id < x) me(ee[i].x, ee[i].y);     for (int i = x; i <= y; i++) {       if (e[i].z <= mid) me(e[i].x, e[i].y);       if (ak == 0) {         t = i;         break;       }     }     pop(tt);     for (int i = x; i < t; i++)       if (e[i].z < l) me(e[i].x, e[i].y);     solve(l, mid, t, y);     pop(tt);     for (int i = l; i <= mid; i++)       if (ee[i].id < x) me(ee[i].x, ee[i].y);     solve(mid + 1, r, x, t - 1);     pop(tt);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) f[i] = i, sz[i] = 1;     ak = n;     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &e[i].x, &e[i].y, &e[i].z);       e[i].id = i;       ee[i] = e[i];     }     sort(ee + 1, ee + 1 + m);     for (int i = 1; i <= m; i++) e[ee[i].id].z = i;     solve(1, m + 1, 1, m);     ee[m + 1].z = -1;     for (int i = 1; i <= m; i++) printf( %d n , ee[ans[i]].z);     return 0;   }
#include <bits/stdc++.h>   const long long mod = 1000000007;   const int maxn = 100000;   using namespace std;   int main() {     long long n, k;     scanf( %I64d , &n);     scanf( %I64d , &k);     vector<long long> fib(n + 1);     fib[1] = 1;     for (int i = 2; i < n + 1; i++) fib[i] = fib[i - 1] + fib[i - 2];     for (int i = 0; i < n; i++) {       if (fib[n - i] < k) {         cout << i + 2 <<     << i + 1 <<    ;         k -= fib[n - i];         i++;       } else         cout << i + 1 <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   [[maybe_unused]] const int MAX = INT32_MAX, MIN = -INT32_MAX,                              maxInd = 1E6 + 1E5 + 1;   [[maybe_unused]] bool directed = true, end_now = false;   bool possible = false;   int n, k;   struct node_data_structure {     int pre = 0, post = 0;     bool visited = false, processed = false;   } nodes[maxInd];   vector<int> graph[maxInd];   void insert_graph(int pre, int post) {     graph[pre].push_back(post);     nodes[pre].post++;     nodes[post].pre++;     if (!directed) {       graph[post].push_back(pre);       nodes[post].post++;       nodes[pre].pre++;     }   }   [[maybe_unused]] void undoVisit() {     for (auto &i : nodes) {       i.visited = false;       i.processed = false;     }     end_now = false;   }   void dfs(int u, int ac = 1) {     if (end_now) return;     if (u > 1E6) {       if (u - 1E6 < ac) return;       if (u - 1E6 + k > n || u - 1E6 == n) {         end_now = true;         possible = true;         return;       }     } else {       if (u < ac) return;       if (u + k > n || u == n) {         end_now = true;         possible = true;         return;       }     }     nodes[u].visited = true;     for (int v : graph[u]) {       if (!nodes[v].visited) {         dfs(v, ac + 1);       }     }     nodes[u].processed = true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s1, s2;     cin >> n >> k >> s1 >> s2;     for (int i = 1; i < n; i++) {       if (i + k <= n) {         if (s1[i - 1] ==  -  && s2[i - 1 + k] ==  - ) {           insert_graph(i, 1E6 + i + k);         }         if (s2[i - 1] ==  -  && s1[i - 1 + k] ==  - ) {           insert_graph(1E6 + i, i + k);         }       }       if (s1[i] ==  -  && s1[i - 1] ==  - ) {         insert_graph(i, i + 1);         insert_graph(i + 1, i);       }       if (s2[i] ==  -  && s2[i - 1] ==  - ) {         insert_graph(1E6 + i, 1E6 + i + 1);         insert_graph(1E6 + i + 1, 1E6 + i);       }     }     dfs(1);     possible ? cout <<  YES  << endl : cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long mul(long long a, long long b) { return a * b % mod; }   long long add(long long a, long long b) {     long long res = a + b;     if (res >= mod) {       res -= mod;     }     return res;   }   const long long MAXN = 1e6 + 5;   vector<long long> fact(MAXN);   vector<long long> fact_obr(MAXN);   vector<long long> pow_n(MAXN);   vector<long long> pow_m(MAXN);   long long n;   long long m;   long long fast_pow(long long a, long long b) {     if (b == 0) {       return 1;     } else {       if (b % 2 == 1) {         return mul(fast_pow(a, b - 1), a);       } else {         long long res = fast_pow(a, b / 2);         return mul(res, res);       }     }   }   void pre_calc() {     fact[0] = 1;     fact_obr[0] = fast_pow(fact[0], mod - 2);     pow_n[0] = 1;     pow_m[0] = 1;     for (long long i = 1; i < MAXN; ++i) {       fact[i] = mul(fact[i - 1], i);       fact_obr[i] = fast_pow(fact[i], mod - 2);       pow_n[i] = mul(pow_n[i - 1], n);       pow_m[i] = mul(pow_m[i - 1], m);     }   }   long long A(long long n, long long k) { return mul(fact[n], fact_obr[n - k]); }   long long C(long long n, long long k) {     if (k > n) {       return 0;     }     if (n == 0 && k != 0) {       return 0;     }     return mul(A(n, k), fact_obr[k]);   }   long long f(long long y) {     if (y == n) {       return 1;     }     return mul(y, pow_n[n - y - 1]);   }   int32_t main() {     cin >> n >> m;     pre_calc();     long long ans = 0;     for (long long edges = 1; edges < n; ++edges) {       long long _add = 1;       _add = mul(_add, A(n - 2, edges - 1));       _add = mul(_add, f(edges + 1));       _add = mul(_add, C(m - 1, edges - 1));       _add = mul(_add, pow_m[n - edges - 1]);       ans = add(ans, _add);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   struct creature {     long long hp, dmg;     long long div;     bool operator<(const creature& rhs) const { return div > rhs.div; }   };   int n, a, b;   creature in[200050];   long long ans = 0;   int it, use;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> a >> b;     for (int i = 0; i < n; ++i) {       cin >> in[i].hp >> in[i].dmg;       in[i].div = in[i].hp - in[i].dmg;     }     sort(in, in + n);     use = b;     for (int i = 0; i < n; ++i) {       if (use && in[i].hp > in[i].dmg) {         in[i].dmg = in[i].hp;         --use;       }       ans += in[i].dmg;     }     it = b - use;     int icur = it - 1;     in[n] = {0, 0, 0};     long long dx = 0;     if (b && a)       for (int i = 0; i < n; ++i) {         long long tmp = (in[i].hp << a) - in[i].dmg;         if (use)           dx = dx > tmp ? dx : tmp;         else if (i < it)           dx = tmp > dx ? tmp : dx;         else           dx = (tmp - in[icur].div > dx) ? tmp - in[icur].div : dx;       }     cout << ans + dx;     return 0;   }
#include <bits/stdc++.h>   using LL = long long;   const int kN = 200000 + 5;   const int kLog = 19;   const LL inf = 3e14;   std::vector<std::pair<int, int>> edges[kN];   int n, m, s;   LL dist[kN];   int plca[kLog][kN], depth[kN];   int sz[kN];   int get_lca(int a, int b) {     if (depth[a] < depth[b]) std::swap(a, b);     for (int i = 0; i < kLog; ++i)       if (depth[a] - depth[b] >> i & 1) a = plca[i][a];     if (a == b) return a;     for (int i = kLog - 1; i >= 0; --i)       if (plca[i][a] != plca[i][b]) a = plca[i][a], b = plca[i][b];     return plca[0][a];   }   int main() {     scanf( %d%d%d , &n, &m, &s);     s--;     for (int i = 0; i < m; ++i) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       u--;       v--;       edges[u].emplace_back(w, v);       edges[v].emplace_back(w, u);     }     std::priority_queue<std::pair<LL, int>> pq;     std::fill(dist, dist + n, inf);     dist[s] = 0;     pq.emplace(0, s);     std::vector<int> order;     while (!pq.empty()) {       LL tmp;       int u;       std::tie(tmp, u) = pq.top();       pq.pop();       if (-tmp != dist[u]) continue;       order.emplace_back(u);       int lca = -1;       for (auto e : edges[u]) {         if (dist[e.second] > dist[u] + e.first) {           dist[e.second] = dist[u] + e.first;           pq.emplace(-dist[e.second], e.second);         } else if (dist[e.second] + e.first == dist[u]) {           if (lca == -1)             lca = e.second;           else             lca = get_lca(lca, e.second);         }       }       plca[0][u] = lca;       depth[u] = lca == -1 ? 0 : depth[lca] + 1;       for (int i = 1; i < kLog; ++i)         plca[i][u] = plca[i - 1][u] == -1 ? -1 : plca[i - 1][plca[i - 1][u]];     }     int result = 0;     std::fill(sz, sz + n, 1);     for (int i = (int)order.size() - 1; i > 0; --i) {       int u = order[i];       sz[plca[0][u]] += sz[u];       result = std::max(result, sz[u]);     }     printf( %d n , result);   }
#include <bits/stdc++.h>   using namespace std;   int n, w;   double tmp;   vector<double> a;   vector<double> boy;   vector<double> girl;   double volume;   double base;   int main() {     cin >> n >> w;     for (int i = 0; i < (2 * n); i++) {       cin >> tmp;       a.push_back(tmp);     }     sort(a.begin(), a.end());     girl.assign(a.begin(), a.begin() + n);     boy.assign(a.begin() + n, a.end());     if (boy[0] / 2 > girl[0])       base = girl[0];     else       base = boy[0] / 2;     volume = (3 * base * n);     if (volume > w) volume = w;     cout << fixed << setprecision(10) << volume;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int kase, ks = 0;     int i, j, k;     int n;     int arr[1000];     string s;     cin >> n;     for (i = 1; i < n + 1; i++) cin >> arr[i];     int q;     cin >> q;     int x, y;     while (q--) {       cin >> x >> y;       if (x > 1) arr[x - 1] += (y - 1);       if (x < n) arr[x + 1] += (arr[x] - y);       arr[x] = 0;     }     for (i = 1; i < n + 1; i++) cout << arr[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3000 + 12;   int p[maxn];   int Et[maxn];   int mark[maxn][maxn];   queue<pair<int, int> > act;   void input(int n) {     for (int i = 0; i < n; i++) cin >> p[i];   }   void solve(int n, int k) {     int sef = 0;     bool yek = 0;     for (int j = n - 1; j >= 0; j--) {       if (p[j] == 0) sef++;       if (p[j] == 100) yek = 1;       if (sef == n - j) Et[j] = 1;       if (yek) Et[j] = 2;     }     act.push(make_pair(0, 1));     mark[0][1] = 0;     int ans = 0;     int x = 0, y = 1;     while (act.size() && mark[x][y] <= k) {       pair<int, int> a = act.front();       x = a.first, y = a.second;       if (mark[x][y] <= k) ans++;       if (Et[y] != 1 && p[x] != 0 && y + 2 <= n + 1 &&           mark[y + 1][y + 2] > mark[x][y] + 1)         act.push(make_pair(y + 1, y + 2)), mark[y + 1][y + 2] = mark[x][y] + 1;       if (Et[y] != 2 && p[x] != 0 && y + 1 <= n &&           mark[x][y + 1] > mark[x][y] + 1)         act.push(make_pair(x, y + 1)), mark[x][y + 1] = mark[x][y] + 1;       if (Et[y] != 1 && p[x] != 100 && y + 1 <= n &&           mark[y][y + 1] > mark[x][y] + 1)         act.push(make_pair(y, y + 1)), mark[y][y + 1] = mark[x][y] + 1;       act.pop();     }     cout << ans;   }   int main() {     int n, k;     cin >> n >> k;     input(n);     memset(mark, 31, sizeof mark);     solve(n, k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using lli = long long;   using pii = pair<int, int>;   using pll = pair<lli, lli>;   template <typename T>   using Vector = vector<vector<T>>;   template <typename T>   using Prior = priority_queue<T>;   template <typename T>   using prior = priority_queue<T, vector<T>, greater<T>>;   const lli mod = 1E9 + 7;   void solve() {     lli x, len;     string s;     cin >> x >> s;     len = s.size();     for (int i = 1; i <= x; ++i) {       if (s.size() < x) {         if (s[i - 1] ==  2 ) s += s.substr(i, s.size() - i);         if (s[i - 1] ==  3 )           s += s.substr(i, s.size() - i) + s.substr(i, s.size() - i);         len = s.size();       } else {         if (s[i - 1] ==  2 ) len = (2 * len - i) % mod;         if (s[i - 1] ==  3 ) len = (3 * len - 2 * i) % mod;       }     }     cout << (len < 0 ? len + mod : len) <<   n ;   }   int main() {     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, min = 1000;     scanf( %d %d , &n, &m);     vector<int> v(m);     for (int i = 0; i < m; i++) scanf( %d , &v[i]);     sort(v.begin(), v.end());     for (int i = 0; n + i - 1 < m; i++) {       if (min > v[n + i - 1] - v[i]) min = v[n + i - 1] - v[i];     }     printf( %d , min);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[1000007], b[1000007], i, n, x, s, f, t;   int main() {     cin >> n;     for (i = 1; i <= 2 * n; i++) {       cin >> x;       if (a[x] == 0)         a[x] = i;       else if (a[x] != 0)         b[x] = i;     }     s = a[1] - 1;     for (x = 2; x <= n; x++) {       t = a[x] - a[x - 1];       if (t < 0) t = -t;       s = s + t;     }     s = s + b[1] - 1;     for (x = 2; x <= n; x++) {       t = b[x] - b[x - 1];       if (t < 0) t = -t;       s = s + t;     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   char s[N];   int n, a[N], pre[N][26], suf[N][26];   int f[N][26], g[N], mem[27];   inline int mex(int st) { return __builtin_ctz(~st); }   int calc(int l, int r, int c, int fl) {     if (l > r) return 0;     if (~mem[c]) return mem[c];     int st = 0;     for (int j = 0; j < 26; j++) {       int ll = suf[l][j], rr = pre[r][j];       if (rr >= l)         st |= 1 << (g[rr] ^ g[ll] ^ (!fl ? f[ll - 1][c] : calc(l, ll - 1, j, 1)) ^                     (fl ? f[r][j] : calc(rr + 1, r, j, 0)));     }     return mem[c] = mex(st);   }   int main() {     ios::sync_with_stdio(false);     cin >> (s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++) a[i] = s[i] -  a ;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 26; j++) pre[i][j] = pre[i - 1][j];       pre[i][a[i]] = i;     }     for (int j = 0; j < 26; j++) suf[n + 1][j] = n + 1;     for (int i = n; i > 0; --i) {       for (int j = 0; j < 26; j++) suf[i][j] = suf[i + 1][j];       suf[i][a[i]] = i;     }     for (int i = 1; i <= n; i++) {       g[i] = f[i - 1][a[i]] ^ g[pre[i - 1][a[i]]];       memset(mem, -1, sizeof(mem));       for (int j = 0; j < 26; j++) f[i][j] = calc(pre[i][j] + 1, i, j, 0);     }     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r;       memset(mem, -1, sizeof(mem));       if (calc(l, r, 26, 1))         puts( Alice );       else         puts( Bob );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   template <class C>   inline void mini(C& a4, C b4) {     a4 = min(a4, b4);   }   template <class C>   inline void maxi(C& a4, C b4) {     a4 = max(a4, b4);   }   int n, v, e;   int a[307], b[307];   vector<int> GG[307], G[307];   bool del[307], vis[307];   int xx[1000007], yy[1000007], dd[1000007], moves;   long long int go(int x) {     long long int res = a[x] - b[x];     vis[x] = true;     for (__typeof((GG[x]).begin()) i = (GG[x]).begin(); i != (GG[x]).end(); ++i)       if (!vis[*i]) {         G[x].push_back(*i);         G[*i].push_back(x);         res += go(*i);       }     return res;   }   void push(int x, int o, int lim, bool down) {     for (__typeof((G[x]).begin()) i = (G[x]).begin(); i != (G[x]).end(); ++i)       if (*i != o && !del[*i]) {         push(*i, x, INF, down);         int can = lim;         int l = x, r = *i;         if (!down) swap(l, r);         mini(can, a[l]);         mini(can, v - a[r]);         lim -= can;         if (can > 0) {           a[l] -= can;           a[r] += can;           xx[moves] = l;           yy[moves] = r;           dd[moves] = can;           moves++;         }       }   }   int main() {     std::ios_base::sync_with_stdio(0);     cout << setprecision(15) << fixed;     cin >> n >> v >> e;     for (int i = (1); i <= (n); i++) cin >> a[i];     for (int i = (1); i <= (n); i++) cin >> b[i];     while (e--) {       int x, y;       cin >> x >> y;       GG[x].push_back(y);       GG[y].push_back(x);     }     for (int i = (1); i <= (n); i++)       if (!vis[i])         if (go(i) != 0) {           cout <<  NO  << endl;           return 0;         }     bool ok;     do {       ok = false;       for (int i = (1); i <= (n); i++)         if (!del[i]) {           int deg = 0;           for (__typeof((G[i]).begin()) j = (G[i]).begin(); j != (G[i]).end();                ++j)             deg += !del[*j];           if (deg != 1) continue;           if (a[i] != b[i]) push(i, i, abs(a[i] - b[i]), a[i] > b[i]);           del[i] = true;           ok = true;           break;         }     } while (ok);     cout << moves << endl;     for (int i = 0; i < (moves); i++)       cout << xx[i] <<     << yy[i] <<     << dd[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {     return {l.first + r.first, l.second + r.second};   }   typedef void (*callback_function)(void);   const long long ZERO = 0LL;   const long long INF64 = 1e18;   const long long INF32 = 1e9;   const long long MOD = 1e9 + 7;   const long double PI = acos(-1.0L);   const long double EPS = static_cast<long double>(1e-9);   const long long N = 1e6 + 7;   long long n, a[N], del;   void input() {     cin >> n;     for (long long i = (1); i <= (n); i++) {       cin >> a[i];     }   }   void solve() {     map<long long, long long> mp;     for (long long i = (1); i <= (n); i++) {       while (mp[a[i]]) {         a[mp[a[i]]] = 0;         mp[a[i]] = 0;         a[i] *= 2;         del++;       }       mp[a[i]] = i;     }   }   void output() {     cout << n - del << endl;     for (long long i = (1); i <= (n); i++) {       if (a[i]) cout << a[i] <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     {       input();       solve();       output();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[200002], v1, v2, ans[200002], mx, subtr[200002];   vector<long long> g[200002];   void dfs(int v, int d, int p) {     ans[1] += a[v] * d;     for (int to : g[v]) {       if (to == p) continue;       dfs(to, d + 1, v);     }   }   void dfs2(int v, int p) {     long long curr = a[v];     for (int to : g[v]) {       if (to == p) continue;       dfs2(to, v);       curr += subtr[to];     }     subtr[v] = curr;   }   void dfs3(int v, int p) {     for (int to : g[v]) {       if (to == p) continue;       ans[to] = ans[v] + subtr[1] - 2 * subtr[to];       dfs3(to, v);     }     mx = max(mx, ans[v]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n - 1; i++) {       cin >> v1 >> v2;       g[v1].push_back(v2);       g[v2].push_back(v1);     }     dfs(1, 0, -1);     dfs2(1, -1);     dfs3(1, -1);     cout << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void read(int& x) {     bool fu = 0;     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     if (c ==  - ) fu = 1, c = getchar();     for (x = 0; c > 32; c = getchar()) x = x * 10 + c -  0 ;     if (fu) x = -x;   };   char getc() {     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     return c;   }   const int N = 100010;   const int inf = 1000000000;   int n, m, d, i, j, k, l, p, x, y, ans;   bool have[N];   int edge, e[N * 2], b[N * 2], fir[N], last[N];   void clear() {     edge = 0;     memset(fir, -1, sizeof(fir));     memset(b, -1, sizeof(b));   }   void adde(int x, int y) {     e[edge] = y;     if (fir[x] == -1)       fir[x] = edge;     else       b[last[x]] = edge;     last[x] = edge++;   }   int st[N], ed[N], ti, fa[N], dep[N], home[N];   void dfs(int i) {     st[i] = ++ti;     home[ti] = i;     int k;     for (k = fir[i]; k >= 0; k = b[k])       if (e[k] != fa[i]) {         fa[e[k]] = i;         dep[e[k]] = dep[i] + 1;         dfs(e[k]);       }     ed[i] = ti;   }   int key[N * 4], add[N * 4];   void padd(int i, int s) {     add[i] += s;     key[i] += s;   }   void pdown(int i) {     if (add[i]) padd(i * 2, add[i]), padd(i * 2 + 1, add[i]), add[i] = 0;   }   void upd(int i) { key[i] = max(key[i * 2], key[i * 2 + 1]); }   void build(int i, int x, int y) {     if (x != y) {       build(i * 2, x, (x + y) / 2);       build(i * 2 + 1, (x + y) / 2 + 1, y);       upd(i);     } else       key[i] = (have[home[x]]) ? dep[home[x]] : -inf;   }   void find(int i, int x, int y, int l, int r, int s) {     if (y < l || x > r) return;     if (x >= l && y <= r) {       padd(i, s);       return;     }     pdown(i);     find(i * 2, x, (x + y) / 2, l, r, s);     find(i * 2 + 1, (x + y) / 2 + 1, y, l, r, s);     upd(i);   }   void doit(int l, int r, int s) {     find(1, 1, n, l, r, s);     if (l > 1) find(1, 1, n, 1, l - 1, -s);     if (r < n) find(1, 1, n, r + 1, n, -s);   }   void go(int i) {     if (key[1] <= d) ans++;     int k;     for (k = fir[i]; k >= 0; k = b[k])       if (e[k] != fa[i]) {         doit(st[e[k]], ed[e[k]], -1);         go(e[k]);         doit(st[e[k]], ed[e[k]], 1);       }   }   int main() {     read(n);     read(m);     read(d);     for (i = 1; i <= m; i++) read(x), have[x] = 1;     clear();     for (i = 1; i <= n - 1; i++) read(x), read(y), adde(x, y), adde(y, x);     dfs(1);     build(1, 1, n);     go(1);     printf( %d n , ans);     scanf(  n );     return 0;   }