malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct arr {     int l, r, add, cnt, sum[50];   } a[110005 * 4];   int data[110005], i, n, m, opt, L, R;   const int P = 95542721;   inline int calc(int x) {     while (x > 47) x -= 48;     return x;   }   inline void down(int k) {     if (!a[k].cnt || a[k].l == a[k].r) return;     int W = a[k].cnt;     a[k].cnt = 0;     a[(k << 1)].add = calc(a[(k << 1)].add + W);     a[(k << 1)].cnt = calc(a[(k << 1)].cnt + W);     a[(k << 1 | 1)].add = calc(a[(k << 1 | 1)].add + W);     a[(k << 1 | 1)].cnt = calc(a[(k << 1 | 1)].cnt + W);   }   inline void up(int k) {     for (int i = 0; i < 48; i++)       a[k].sum[i] = (a[(k << 1)].sum[calc(a[(k << 1)].add + i)] +                      a[(k << 1 | 1)].sum[calc(a[(k << 1 | 1)].add + i)]) %                     P;   }   void build(int k, int l, int r) {     a[k].l = l;     a[k].r = r;     a[k].add = a[k].cnt = 0;     if (l == r) {       a[k].sum[0] = data[l];       for (int i = 1; i <= 47; i++)         a[k].sum[i] = (a[k].sum[i - 1] * 1ll * a[k].sum[i - 1] % P * 1ll *                        a[k].sum[i - 1] % P);       return;     }     int mid = (l + r) >> 1;     if (l <= mid) build((k << 1), l, mid);     if (r > mid) build((k << 1 | 1), mid + 1, r);     for (int i = 0; i < 48; i++)       a[k].sum[i] = (a[(k << 1)].sum[i] + a[(k << 1 | 1)].sum[i]) % P;   }   void update(int k) {     if (L <= a[k].l && a[k].r <= R) {       a[k].cnt = calc(a[k].cnt + 1);       a[k].add = calc(a[k].add + 1);       return;     }     down(k);     int mid = (a[k].l + a[k].r) >> 1;     if (L <= mid) update((k << 1));     if (R > mid) update((k << 1 | 1));     a[k].add = 0;     up(k);   }   int Query(int k) {     if (L <= a[k].l && a[k].r <= R) return a[k].sum[calc(a[k].add)];     down(k);     int res = 0;     int mid = (a[k].l + a[k].r) >> 1;     if (L <= mid) res = Query((k << 1));     if (R > mid) (res += Query((k << 1 | 1))) %= P;     return res;   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &data[i]);     build(1, 1, n);     scanf( %d , &m);     while (m--) {       scanf( %d%d%d , &opt, &L, &R);       if (opt == 1)         printf( %d n , Query(1));       else         update(1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int _inf = 0xc0c0c0c0;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long _INF = 0xc0c0c0c0c0c0c0c0;   const long long mod = (int)1e9 + 7;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long ksm(long long a, long long b, long long mod) {     int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ans;   }   long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }   void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       exgcd(b, a % b, y, x, d);       y -= x * (a / b);     }   }   int dp[10025];   int main() {     int c, d, n, m, k, V, ans = inf;     scanf( %d%d , &c, &d);     scanf( %d%d , &n, &m);     scanf( %d , &k);     memset(dp, 0x3f, sizeof(dp));     dp[0] = 0;     for (int j = n; j <= n * m; ++j) {       dp[j] = min(dp[j], dp[j - n] + c);     }     for (int j = 1; j <= n * m; ++j) {       dp[j] = min(dp[j], dp[j - 1] + d);     }     for (int i = n * m - k; i <= n * m; ++i) {       ans = min(ans, dp[i]);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const string str =  VC ;   const int maxn = 300;   char s[2];   int l, n, m;   char buf[maxn];   int alpha[26];   vector<int> G[maxn * 2];   bool mark[maxn * 2];   int stk[maxn * 2], top;   bool dfs(int u) {     if (s[u & 1] == 0) return false;     if (mark[u ^ 1]) return false;     if (mark[u]) return true;     while (top == 2 * maxn)       ;     mark[stk[top++] = u] = true;     for (int v : G[u])       if (!dfs(v)) return false;     return true;   }   string ans;   void check(string tmp) {     if (ans ==    || tmp < ans) ans = tmp;   }   void solve(int st) {     for (int i = 0; i < 2 * n; i++) mark[i] = 0;     for (int i = 0; i < st; i++) {       top = 0;       if (!dfs(i << 1 | alpha[buf[i] -  a ])) return;     }     for (int i = 2 * st; i < 2 * n; i += 2) {       if (mark[i] || mark[i ^ 1]) continue;       top = 0;       if (s[0] < s[1]) {         if (!dfs(i)) {           while (top) mark[stk[--top]] = false;           if (!dfs(i ^ 1)) return;         }       } else {         if (!dfs(i ^ 1)) {           while (top) mark[stk[--top]] = false;           if (!dfs(i)) return;         }       }     }     string tmp(buf, buf + st);     for (int i = st; i < n; i++) tmp += s[mark[i << 1 | 1]];     check(tmp);   }   int main() {     scanf( %s , buf);     l = strlen(buf);     for (int i = l - 1; i >= 0; i--) s[alpha[i] = str.find(buf[i])] =  a  + i;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d %s , &x, buf);       x--;       x = x << 1 | str.find(buf[0]);       scanf( %d %s , &y, buf);       y--;       y = y << 1 | str.find(buf[0]);       G[x].push_back(y);       G[y ^ 1].push_back(x ^ 1);     }     scanf( %s , buf);     for (int i = 0; i <= n; i++) {       if (i < n) {         char ch = buf[i];         for (buf[i]++; buf[i] <  a  + l; buf[i]++) solve(i + 1);         buf[i] = ch;       } else         solve(n);     }     if (ans !=   )       puts(ans.c_str());     else       puts( -1 );   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int n, k, x, sum, a[24], BadPoint[2], dp[(1 << 24)];   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     cin >> k;     for (int i = 0; i < k; i++) cin >> BadPoint[i];     dp[0] = 1;     for (int mask = 1; mask < (1 << n); mask++) {       sum = 0;       for (int i = 0; i < n; i++) {         if ((mask >> i) & 1) {           dp[mask] += dp[(mask ^ (1 << i))];           if (dp[mask] >= MOD) dp[mask] -= MOD;           sum += a[i];         }       }       for (int i = 0; i < k; i++)         if (sum == BadPoint[i]) dp[mask] = 0;     }     cout << dp[(1 << n) - 1];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     int a = 2, b = 3, c = 5, d = 7;     int ab = 6, ac = 10, ad = 14, bc = 15, bd = 21, cd = 35;     int abc = 30, bcd = 105, abd = 42, acd = 70;     int abcd = 210;     cout << n - (n / a + n / b + n / c + n / d) +                 (n / ab + n / ac + n / ad + n / bc + n / bd + n / cd) -                 (n / abc + n / bcd + n / abd + n / acd) + n / abcd;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> ar[110];   set<int> se;   int findstart(int k) {     while (ar[k].first != 0) k = ar[k].first;     return k;   }   int findend(int k) {     while (ar[k].second != 0) k = ar[k].second;     return k;   }   void addalltoend(int i) {     se.insert(ar[i].second);     while (ar[i].second != 0) {       i = ar[i].second;       se.insert(ar[i].second);     }   }   int main() {     int n, en, nen;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ar[i].first >> ar[i].second;     }     int i = 0;     while (ar[i].first == 0 && ar[i].second == 0 && i != n + 1) {       i++;     }     if (n == 1) {       cout << 0 <<     << 0;       return 0;     }     if (n != 1 && i == n + 1) {       for (i = 1; i < n; i++) {         cout << i - 1 <<     << i + 1 <<   n ;       }       cout << i - 1 <<     << 0 <<   n ;       return 0;     }     i = findstart(i);     en = findend(i);     se.insert(i);     addalltoend(i);     se.erase(0);     for (set<int>::const_iterator it = se.begin(); it != se.end(); it++)       for (int i = 1; i <= n; i++) {         if (ar[i].first == 0 && ar[i].second != 0 &&             se.find(ar[i].second) == se.end()) {           ar[en].second = i;           ar[i].first = en;           i = findstart(i);           addalltoend(i);           en = findend(i);         }       }     for (int i = 1; i <= n; i++) {       if (ar[i].first == 0 && ar[i].second == 0) {         ar[en].second = i;         ar[i].first = en;         en = i;       }     }     for (int i = 1; i <= n; i++)       cout << ar[i].first <<     << ar[i].second <<   n ;     for (set<int>::const_iterator it = se.begin(); it != se.end(); it++) return 0;   }
#include <bits/stdc++.h>   using namespace std;   void calc(int n, int p) {     int j = 1, k = 1;     int cnt = 0;     int here = 1;     for (int i = 0; i < 2 * n + p; i++) {       cout << j <<    ;       j += k;       if (j > n) j -= n;       cout << j << endl;       cnt++;       int tmp = j + k;       if (tmp > n) tmp -= n;       tmp += k;       if (tmp > n) tmp -= n;       if (j == here || tmp == j) {         if (cnt == n) {           cnt = 0;           k++;           j = 1;           here = 1;         } else {           j++;           here++;         }       }     }   }   int main() {     int t;     cin >> t;     vector<pair<int, int> > out;     for (int i = 0; i < t; i++) {       int n, p;       cin >> n >> p;       calc(n, p);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[1001][1001];   int vis[1001][1001];   int n, m;   void dfs(int x, int y) {     vis[x][y] = 1;     if (x - 1 >= 0 && !vis[x - 1][y] && a[x - 1][y] ==  # ) {       dfs(x - 1, y);     }     if (x + 1 < n && !vis[x + 1][y] && a[x + 1][y] ==  # ) {       dfs(x + 1, y);     }     if (y - 1 >= 0 && !vis[x][y - 1] && a[x][y - 1] ==  # ) {       dfs(x, y - 1);     }     if (y + 1 < m && !vis[x][y + 1] && a[x][y + 1] ==  # ) {       dfs(x, y + 1);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     int f1 = 0, f2 = 0, f3 = 0;     int awr = 0, awc = 0, c = 0, ans = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (!f1 && a[i][j] ==  # ) {           f1 = 1;         } else if (f1 && !f2 && a[i][j] ==  . ) {           f2 = 1;         } else if (f1 && f2 && !f3 && a[i][j] ==  # ) {           f3 = 1;         }       }       if (f1 && f2 && f3) {         cout <<  -1 n ;         goto here;       } else {         f1 = f2 = f3 = 0;       }     }     for (int j = 0; j < m; ++j) {       for (int i = 0; i < n; ++i) {         if (!f1 && a[i][j] ==  # ) {           f1 = 1;         } else if (f1 && !f2 && a[i][j] ==  . ) {           f2 = 1;         } else if (f1 && f2 && !f3 && a[i][j] ==  # ) {           f3 = 1;         }       }       if (f1 && f2 && f3) {         cout <<  -1 n ;         goto here;       } else {         f1 = f2 = f3 = 0;       }     }     for (int i = 0; i < n; ++i) {       c = 0;       for (int j = 0; j < m; ++j) {         if (a[i][j] ==  . ) {           c++;         }       }       if (c == m) {         awr = 1;         break;       }     }     for (int j = 0; j < m; ++j) {       c = 0;       for (int i = 0; i < n; ++i) {         if (a[i][j] ==  . ) {           c++;         }       }       if (c == n) {         awc = 1;         break;       }     }     if (awr ^ awc) {       cout <<  -1 n ;       goto here;     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (a[i][j] ==  #  && !vis[i][j]) {           ans++;           dfs(i, j);         }       }     }     cout << ans <<   n ;   here:;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n];       set<long long> s;       for (long long i = 0; i < n; i++) {         cin >> a[i];         s.insert(a[i]);       }       cout << s.size() <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int_fast64_t viz[100001], ans;   vector<int_fast64_t> v(100001);   void dfs(int_fast64_t node) {     ans++;     viz[node] = 1;     if (!viz[v[node]]) dfs(v[node]);   }   void solve() {     int_fast64_t n;     cin >> n;     for (int_fast64_t i = 1; i <= n; i++) cin >> v[i];     vector<int_fast64_t> res;     for (int_fast64_t i = 1; i <= n; i++) {       ans = 0;       if (!viz[i]) dfs(i);       res.push_back(ans);     }     sort(res.begin(), res.end());     if (res.size() > 1) {       int_fast64_t maxi = res[res.size() - 1] + res[res.size() - 2];       res.pop_back();       res.pop_back();       res.push_back(maxi);       ans = 0;       for (int_fast64_t i = 0; i < res.size(); i++) ans += res[i] * res[i];       cout << ans;     } else       cout << n * n;   }   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     ;     solve();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   void solve() {     int n;     cin >> n;     set<int> s;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       s.insert(a);     }     for (int cnt = 1; cnt <= 1023; cnt++) {       bool vis[1025];       memset(vis, 0, sizeof(vis));       bool h = 1;       for (auto x : s) {         if (vis[x ^ cnt] || s.count(x ^ cnt) == 0) {           h = 0;           break;         }         vis[x ^ cnt] = 1;       }       if (h) {         cout << cnt;         return;       }     }     cout << -1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   ifstream fin( A.in );   ofstream fout( A.out );   int n, m, a, b, v[100001], viz[100001];   vector<int> G[100001];   long long sum;   struct sor {     int x, i;   } s[100001];   bool cmp(sor a, sor b) { return a.x > b.x; }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> v[i];       s[i].x = v[i];       s[i].i = i;     }     for (int i = 1; i <= m; ++i) {       cin >> a >> b;       G[a].push_back(b);       G[b].push_back(a);     }     sort(s + 1, s + n + 1, cmp);     for (int i = 1; i <= n; ++i) {       viz[s[i].i] = 1;       for (vector<int>::iterator it = G[s[i].i].begin(); it != G[s[i].i].end();            ++it) {         if (!viz[*it]) sum += v[*it];       }     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};   const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};   const int INF = 1000000000;   const long long LINF = 1000000000000000000;   const long long MOD = 1000000007;   const double PI = acos(-1.0);   const double EPS = 1e-10;   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   inline void add(T& a, T b) {     a = ((a + b) % MOD + MOD) % MOD;   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int N;     cin >> N;     vector<int> a(N);     stack<int> st;     for (int i = 0; i < N; i++) {       cin >> a[i];     }     int ma = *max_element(a.begin(), a.end());     for (int i = 0; i < N; i++) {       if (a[i] == ma) continue;       int j = i;       while (j < N && a[j] != ma) {         if (st.empty() || st.top() > a[j])           st.push(a[j]);         else if (!st.empty() && a[j] == st.top())           st.pop();         else {           cout <<  NO  << endl;           return 0;         }         j++;       }       if (!st.empty()) {         cout <<  NO  << endl;         return 0;       }       i = j;     }     cout <<  YES  << endl;   }
#include <bits/stdc++.h>   using namespace std;   typedef int matrix[130][130];   long long n;   vector<int> v[130];   int k, q[30], d, f[30], h[130], len[30], r[30], ans;   matrix a, b, t;   char c;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   void mul(matrix a, matrix b) {     for (int i = 0; i < len[0]; i++)       for (int j = 0; j < len[0]; j++) {         t[i][j] = 0;         for (int k = 0; k < len[0]; k++)           t[i][j] = (t[i][j] + a[i][k] * b[k][j]) % 12345;       }     for (int i = 0; i < len[0]; i++)       for (int j = 0; j < len[0]; j++) a[i][j] = t[i][j];   }   void pow(long long n) {     for (int i = 0; i < len[0]; i++) a[i][i] = 1;     for (int i = 0; n >> i; i++) {       if ((n >> i) & 1) mul(a, b);       mul(b, b);     }   }   int main() {     scanf( %I64d%d , &n, &k);     for (int i = 0; i < 26; i++) q[i] = 1;     for (int i = 0; i < k; i++)       scanf(  %c%d , &c, &d), c -=  A , q[c] *= d / gcd(d, q[c]),           f[c] = 1, v[c].push_back(d);     len[26] = 1;     for (int j = 25; j >= 0; j--) len[j] = len[j + 1] * q[j];     for (int j = 0; j < len[0]; j++) {       for (int i = 0; i < 26; i++) r[i] = j / len[i + 1] % q[i];       h[j] = 1;       for (int i = 0; i < 26; i++)         if (v[i].size()) {           bool fg = 0;           for (int d : v[i]) fg |= (r[i] % d == 0);           h[j] &= fg;         }       for (int i = 0; i < 26; i++)         if (f[i])           b[j][(r[i] + 1 == q[i]) ? j + len[i + 1] - len[i] : j + len[i + 1]]++;     }     pow(n);     for (int i = 0; i < len[0]; i++) ans += h[i] * a[0][i];     printf( %d n , ans % 12345);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   int n;   int cnt;   int sum;   int head[maxn];   int size[maxn];   int T[maxn];   int top;   int temp[2];   struct edge {     int u, v, w, next;   } e[maxn * 2];   void addedge(int u, int v, int w) {     e[cnt].u = u;     e[cnt].v = v;     e[cnt].w = w;     e[cnt].next = head[u];     head[u] = cnt++;   }   void add_edge(int u, int v, int w) {     addedge(u, v, w);     addedge(v, u, w);   }   void dfs(int u, int f) {     size[u] = T[u];     for (int i = head[u]; ~i; i = e[i].next) {       int v = e[i].v;       if (v != f) {         dfs(v, u);         size[u] += size[v];       }     }     if (size[u] * 3 == sum && u != e[head[0]].v) {       temp[top++] = u;       size[u] = 0;     }   }   int main() {     cnt = 0;     memset(head, -1, sizeof(head));     scanf( %d , &n);     int a, b;     sum = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a, &b);       add_edge(a, i, 1);       T[i] = b;       sum += b;     }     if (sum % 3) {       cout << -1 << endl;     } else {       top = 0;       temp[0] = -1;       temp[1] = -1;       dfs(e[head[0]].v, 0);       if (temp[0] != -1 && temp[1] != -1) {         cout << temp[0] <<     << temp[1] << endl;       } else {         cout << -1 << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 + 10;   int a[maxn][maxn];   vector<int> G[maxn], R[maxn], topo;   bool v[maxn];   void rdfs(int now) {     v[now] = true;     for (int u : R[now])       if (!v[u]) rdfs(u);     topo.push_back(now);   }   void dfs(int now) {     v[now] = true;     for (int u : G[now])       if (!v[u]) dfs(u);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         cin >> a[i][j];         if (a[i][j]) G[i].push_back(j), R[j].push_back(i);       }     for (int i = 1; i <= n; ++i)       if (!v[i]) rdfs(i);     reverse(topo.begin(), topo.end());     memset(v, false, sizeof(v));     dfs(topo[0]);     for (int i = 1; i <= n; ++i)       if (!v[i]) return cout <<  NO  << endl, 0;     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   int n;   int arr[8005];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n;       multiset<int> ms;       for (int i = 0; i < n; i++) {         cin >> arr[i];         ms.insert(arr[i]);       }       int ans = 0;       for (int i = 0; i < n; i++) {         int sum = arr[i];         for (int j = i + 1; j < n; j++) {           sum += arr[j];           while (ms.find(sum) != ms.end()) {             ans++;             ms.erase(ms.find(sum));           }         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v[2];   long long get(long long a, long long b) { return (a + b != 0); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     string s;     long long ans, x, y, a, b, c, d;     long long minx, maxx, miny, maxy, maxl, maxr, maxu, maxd;     while (t--) {       cin >> s;       x = 0;       y = 0;       minx = 0;       maxx = 0;       miny = 0;       maxy = 0;       maxl = 0;       maxr = 0;       maxu = 0;       maxd = 0;       for (auto it : s) {         if (it ==  W ) y++;         if (it ==  S ) y--;         if (it ==  A ) x--;         if (it ==  D ) x++;         maxx = max(maxx, x);         minx = min(minx, x);         maxy = max(maxy, y);         miny = min(miny, y);         maxu = max(maxu, y - miny);         maxd = max(maxd, maxy - y);         maxr = max(maxr, x - minx);         maxl = max(maxl, maxx - x);       }       a = max(maxl, maxr);       b = max(get(maxl, maxr), a - (maxl != maxr));       c = max(maxu, maxd);       d = max(get(maxu, maxd), c - (maxu != maxd));       a++;       b++;       c++;       d++;       ans = min(a * d, b * c);       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 1020;   int n, m, d, tmp;   int h[maxn], dis1[maxn], dis2[maxn];   bool mark[maxn], isaffected[maxn];   vector<int> adj[maxn];   pair<int, int> temp;   void dfsa(int v) {     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (!mark[u]) {         mark[u] = true;         h[u] = h[v] + 1;         dfsa(u);         if (h[u] > tmp && isaffected[u]) {           tmp = h[u];           temp.first = u;         }       }     }   }   void dfsb(int v) {     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (!mark[u]) {         mark[u] = true;         h[u] = h[v] + 1;         dfsb(u);         if (h[u] > tmp && isaffected[u]) {           tmp = h[u];           temp.second = u;         }       }     }   }   void dfs1(int v) {     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (!mark[u]) {         mark[u] = true;         dis1[u] = dis1[v] + 1;         dfs1(u);       }     }   }   void dfs2(int v) {     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (!mark[u]) {         mark[u] = true;         dis2[u] = dis2[v] + 1;         dfs2(u);       }     }   }   int main() {     cin >> n >> m >> d;     for (int i = 1; i <= m; i++) {       int x;       cin >> x;       isaffected[x] = true;     }     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     mark[1] = true;     dfsa(1);     for (int i = 1; i <= n; i++) {       h[i] = 0;       mark[i] = false;     }     h[temp.first] = 0;     tmp = 0;     mark[temp.first] = true;     dfsb(temp.first);     for (int i = 1; i <= n; i++) {       mark[i] = false;     }     dis1[temp.first] = 0;     mark[temp.first] = true;     dfs1(temp.first);     for (int i = 1; i <= n; i++) {       mark[i] = false;     }     dis2[temp.second] = 0;     mark[temp.second] = true;     dfs2(temp.second);     for (int i = 1; i <= n; i++) {       mark[i] = false;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (max(dis1[i], dis2[i]) <= d) {         ans++;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int c, v0, v1, a, l;   int main() {     scanf( %d %d %d %d %d , &c, &v0, &v1, &a, &l);     int s = 0, d = v0 - a;     for (int i = 1;; i++) {       d += a;       if (d >= v1) d = v1;       if (i == 1)         s += d;       else         s += d - l;       if (s >= c) {         printf( %d n , i);         return 0;       }     }   }