malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int N, K;   char s[1100000];   int cnt[1100000][3], tot[1100000];   int pb[1100000], pw[1100000];   bool can(int p, int f) {     if (p < K) return false;     if (f) {       if (p - pb[p - 1] - 1 < K) return false;       if (p > K && s[p - K - 1] ==  W ) return false;       return true;     } else {       if (p - pw[p - 1] - 1 < K) return false;       if (p > K && s[p - K - 1] ==  B ) return false;       return true;     }   }   int main() {     int b, w, i;     scanf( %d%d , &N, &K);     scanf( %s , s);     if (N < K * 2) {       puts( 0 );       return 0;     }     b = w = -1;     for (i = 0; i < N; i++) {       if (s[i] ==  B ) b = i;       if (s[i] ==  W ) w = i;       pb[i] = b;       pw[i] = w;     }     cnt[0][0] = 1;     tot[0] = 1;     for (i = 1; i <= N; i++) {       if (s[i - 1] ==  X )         tot[i] = tot[i - 1] * 2 % 1000000007;       else         tot[i] = tot[i - 1];       if (s[i - 1] ==  X )         cnt[i][2] = cnt[i - 1][2] * 2 % 1000000007;       else         cnt[i][2] = cnt[i - 1][2];       if (can(i, 1)) {         cnt[i][2] += cnt[max(i - K - 1, 0)][1];         cnt[i][2] %= 1000000007;         if (can(i - K, 0)) {           cnt[i][2] += cnt[max(i - K * 2 - 1, 0)][0];           cnt[i][2] %= 1000000007;         }       }       if (s[i - 1] ==  X )         cnt[i][0] = cnt[i - 1][0] * 2 % 1000000007;       else         cnt[i][0] = cnt[i - 1][0];       if (can(i, 0)) {         cnt[i][0] -= cnt[max(i - K - 1, 0)][0];         if (cnt[i][0] < 0) cnt[i][0] += 1000000007;       }       cnt[i][1] = tot[i];       cnt[i][1] -= cnt[i][0];       if (cnt[i][1] < 0) cnt[i][1] += 1000000007;       cnt[i][1] -= cnt[i][2];       if (cnt[i][1] < 0) cnt[i][1] += 1000000007;     }     printf( %d n , cnt[N][2]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char grid[10][10];   bool colW[10], colB[10];   int main() {     int Case = 1;     int l, p, q;     char dump[2];     while (gets(grid[1])) {       for (int i = 2; i <= 8; i++) {         gets(grid[i]);       }       memset(colB, false, sizeof(colB));       memset(colW, false, sizeof(colW));       bool found = false;       int white, black;       for (int i = 1; i <= 8 && !found; i++) {         for (int j = 0; j < 8 && !found; j++) {           if (grid[i][j] ==  W ) {             if (!colB[j]) {               found = true;               white = i - 1;             }           } else if (grid[i][j] ==  B ) {             colB[j] = true;           }         }       }       found = false;       for (int i = 8; i >= 1 && !found; i--) {         for (int j = 0; j < 8 && !found; j++) {           if (grid[i][j] ==  B ) {             if (!colW[j]) {               found = true;               black = 8 - i;             }           } else if (grid[i][j] ==  W ) {             colW[j] = true;           }         }       }       if (white <= black)         puts( A );       else         puts( B );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 5 + 1e5;   int main() {     int a, b, c, m, ans = 0;     ios::sync_with_stdio(0);     cin.tie();     cin >> a >> b;     c = a - b;     if (c < 0)       cout << 0;     else if (c == 0)       cout <<  infinity ;     else {       for (int i = 1; i * i <= c; ++i) {         if (c % i == 0) {           m = i;           if ((m * (a / m)) == c) ++ans;           if (i != (c / i)) {             m = c / i;             if ((m * (a / m)) == c) ++ans;           }         }       }       cout << ans;     }   }
#include <bits/stdc++.h>   using namespace std;   int num(string s) {     if (s ==  00 ) return 0;     if (s ==  10 ) return 2;     if (s ==  11 ) return 3;     return 1;   }   void solve(int x) {     vector<int> v[4], vv[4];     int n;     cin >> n;     int ans = 0;     for (int i = 0; i < n; i++) {       string s;       int x;       cin >> s >> x;       v[num(s)].push_back(x);       vv[num(s)].push_back(x);     }     for (int i = 0; i < 4; i++) {       sort(vv[i].begin(), vv[i].end(), greater<int>());       sort(v[i].begin(), v[i].end(), greater<int>());       for (int j = 1; j < v[i].size(); j++) v[i][j] += v[i][j - 1];     }     int t1, t2;     int sz = v[3].size();     if (sz) ans += v[3][sz - 1];     t1 = sz;     t2 = sz;     int tot = sz;     sz = min(v[1].size(), v[2].size());     if (sz > 0) ans += v[1][sz - 1] + v[2][sz - 1];     int i = sz, j = sz, k = 0;     t1 += sz;     t2 += sz;     tot += sz + sz;     int mx = 2 * t1 - tot;     vector<int> fin;     while (i < v[1].size()) fin.push_back(vv[1][i++]);     while (j < v[2].size()) fin.push_back(vv[2][j++]);     while (k < v[0].size()) fin.push_back(vv[0][k++]);     sort(fin.begin(), fin.end(), greater<int>());     i = 0;     while (mx && i < fin.size()) {       mx--;       ans += fin[i++];     }     cout << ans;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     int T = t;     while (t--) {       solve(T - t);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k;   struct node {     int ma[10];     int mi[10];     int cnt = 1;     bool operator==(const node &a) const {       bool f0 = false, f1 = false;       for (int i = 0; i < k; ++i) {         if (ma[i] > a.mi[i]) f0 = true;         if (mi[i] < a.ma[i]) f1 = true;       }       if (f0 & f1) return true;       return false;     }     bool operator<(const node &a) const {       for (int i = 0; i < k; ++i) {         if (ma[i] > a.mi[i]) return false;       }       return true;     }   };   int n;   set<node> se;   node cur;   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < k; ++j) {         scanf( %d , &cur.mi[j]);         cur.ma[j] = cur.mi[j];       }       cur.cnt = 1;       set<node>::iterator it = se.find(cur);       while (it != se.end()) {         for (int i = 0; i < k; ++i) {           cur.mi[i] = min(cur.mi[i], it->mi[i]);           cur.ma[i] = max(cur.ma[i], it->ma[i]);         }         cur.cnt += it->cnt;         se.erase(it);         it = se.find(cur);       }       se.insert(cur);       it = se.end();       --it;       printf( %d n , it->cnt);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Max = 510;   int arr[Max][Max];   int ps[Max][Max];   bool check(int i, int j);   int calcPs(int minX, int minY, int maxX, int maxY);   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (int j = 0; j < m; j++) {         if (s[j] ==  0 )           arr[i][j] = 0;         else           arr[i][j] = 1;       }     }     for (int i = 1; i < n; i++) {       for (int j = 1; j < m; j++) {         ps[i][j] = ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1] + check(i, j);       }     }     long long result = 0;     for (int i = 1; i < n - 1; i++) {       for (int j = i; j < n - 1; j++) {         int l = 1;         int r = 1;         while (r < m - 1 && l < m - 1) {           int calcedPs = calcPs(i, l, j, r);           if (calcedPs >= k) {             result += m - r - 1;             l++;           } else             r++;         }       }     }     cout << result;   }   bool check(int i, int j) {     return arr[i][j] == 1 && arr[i][j + 1] == 1 && arr[i + 1][j] == 1 &&            arr[i][j - 1] == 1 && arr[i - 1][j] == 1;   }   int calcPs(int minX, int minY, int maxX, int maxY) {     minX--;     minY--;     return ps[maxX][maxY] - ps[minX][maxY] - ps[maxX][minY] + ps[minX][minY];   }
#include <bits/stdc++.h>   using namespace std;   char s[1000005];   int main() {     int n, k;     while (scanf( %d%d , &n, &k) != EOF) {       if (k > n || (n > 1 && k == 1)) {         printf( -1 n );         break;       } else {         if ((n - k) % 2) {           for (int i = 1; i <= n - k + 1; i++) {             s[i] =  a ;             s[i + 1] =  b ;             i++;           }           s[n - k + 2] =  a ;           int c = 99;           for (int i = n - k + 3; i <= n; i++) {             s[i] = c;             c++;           }         } else {           for (int i = 1; i <= n - k; i++) {             s[i] =  a ;             s[i + 1] =  b ;             i++;           }           int c = 97;           for (int i = n - k + 1; i <= n; i++) {             s[i] = c;             c++;           }         }       }       for (int i = 1; i <= n; i++) printf( %c , s[i]);       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   string toStr(const T &x) {     stringstream s;     s << x;     return s.str();   }   template <class T>   int toInt(const T &x) {     stringstream s;     s << x;     int r;     s >> r;     return r;   }   const double pi = acos(-1);   const double Pi2 = acos(0);   struct point {     double x, y;     point() {}     point(double X, double Y) : x(X), y(Y) {}     point sub(point a) { return point(x - a.x, y - a.y); }     point add(point a) { return point(x + a.x, y + a.y); }     double cross(point a) { return x * a.y - y * a.x; }     point multbyscalar(double ua) { return point(ua * x, ua * y); }   };   int lucky(string cad) {     for (int i = 0; i < cad.size(); ++i)       if (cad[i] !=  4  and cad[i] !=  7 ) return 0;     return 1;   }   int main() {     int n, x, y;     cin >> n >> x >> y;     int pin = 1;     n >>= 1;     if ((x == n or x == n + 1) and (y == n or y == n + 1)) pin = 0;     if (pin)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t, i, n, x, j;     cin >> t;     while (t--) {       cin >> n;       vector<int> a, b;       for (i = 0; i < n; i++) {         cin >> x;         a.push_back(x);       }       for (i = 0; i < n; i++) {         cin >> x;         b.push_back(x);       }       sort(a.begin(), a.end());       sort(b.begin(), b.end());       for (i = 0; i < n; i++) {         cout << a[i] <<    ;       }       cout <<   n ;       for (i = 0; i < n; i++) {         cout << b[i] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   struct XD {     double x, y, z;     void input() { scanf( %lf%lf%lf , &x, &y, &z); }     XD operator+(const XD& b) const {       XD a;       a.x = x + b.x;       a.y = y + b.y;       a.z = z + b.z;       return a;     }   };   XD a, v;   double r;   inline double MIN(double a, double b) { return a < b ? a : b; }   inline double solve(XD a, XD b, XD v, double r) {     double c1, c2, c3;     c1 = v.x * v.x + v.y * v.y + v.z * v.z;     c2 = v.x * (a.x - b.x) * 2 + v.y * (a.y - b.y) * 2 + v.z * (a.z - b.z) * 2;     c3 = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) +          (a.z - b.z) * (a.z - b.z) - r * r;     if (c2 * c2 - 4 * c1 * c3 < 0) return 1e100;     double s1 = (-c2 - sqrt(c2 * c2 - 4 * c1 * c3)) / (2 * c1);     if (s1 < 0)       return 1e100;     else       return s1;   }   int main() {     a.input();     v.input();     scanf( %lf , &r);     int n, i;     scanf( %d , &n);     double mint = 1e100;     for (i = 0; i < n; i++) {       XD cen;       cen.input();       double ri;       scanf( %lf , &ri);       mint = MIN(mint, solve(a, cen, v, r + ri));       int q;       scanf( %d , &q);       while (q--) {         XD dif;         dif.input();         mint = MIN(mint, solve(a, cen + dif, v, r));       }     }     if (mint > 1e99)       puts( -1 );     else       printf( %.10lf n , mint);   }
#include <bits/stdc++.h>   bool compare(int a, int b) { return a < b; }   void swapped(char s1, char s2) {     char temp = s1;     s1 = s2;     s2 = temp;   }   long long int modd(long long int n, long long int k) {     return (k + (n % k)) % k;   }   bool i(long long first) { return first && (!(first & (first - 1))); }   bool p(long long n) {     long long i, flag = 1;     for (i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         flag = 0;         break;       }     }     if (flag == 1) {       return true;     } else {       return false;     }     return 0;   }   using namespace std;   void solve() {     long long n;     cin >> n;     if (n == 1) {       cout <<  FastestFinger  <<   n ;       return;     }     if (n == 2) {       cout <<  Ashishgup  <<   n ;       return;     }     if (i(n)) {       cout <<  FastestFinger  <<   n ;       return;     }     if (n & 1) {       cout <<  Ashishgup  <<   n ;       return;     }     n /= 2;     if (p(n)) {       cout <<  FastestFinger  <<   n ;       return;     } else {       cout <<  Ashishgup  <<   n ;       return;     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, mn, mx;     cin >> n >> m >> mn >> mx;     set<int> temp;     for (int i = 0; i < m; ++i) {       int x;       cin >> x;       temp.insert(x);     }     if (*temp.begin() < mn or *temp.rbegin() > mx) {       cout <<  Incorrect  << endl;       return 0;     }     int off = 0;     if (*temp.begin() != mn) off++;     if (*temp.rbegin() != mx) off++;     if (n - m >= off) {       cout <<  Correct  << endl;     } else {       cout <<  Incorrect  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x, s, t;   int main(void) {     cin >> t >> s >> x;     int a = (x - t) / s;     if (t == x) {       cout <<  YES  << endl;     } else if (a <= 0) {       cout <<  NO  << endl;     } else if (t + a * s == x || t + a * s + 1 == x) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   const int oo = 0x3f3f3f3f;   inline long long read() {     char ch = getchar();     int x = 0, f = 1;     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long N, M, a[MAXN], b[MAXN], leftt, rightt, mid, ans, cnt, st, nd;   bool vis[MAXN];   namespace solution {   void init() {     N = read();     M = read();     for (int i = 1; i <= N; i++) a[i] = read();     for (int i = 1; i <= M; i++) b[i] = read();     sort(a + 1, a + N + 1);     sort(b + 1, b + M + 1);   }   bool check(long long length) {     int t = 1;     for (int i = 1; i <= M; i++) {       st = b[i] - length;       nd = b[i] + length;       while (t <= N && a[t] >= st && a[t] <= nd) t++;     }     return t > N;   }   void slove() {     leftt = 0;     rightt = 2000000000;     while (leftt + 1 < rightt) {       mid = (leftt + rightt) >> 1;       if (check(mid))         rightt = mid;       else         leftt = mid;     }     if (check(leftt))       ans = leftt;     else       ans = rightt;   }   void output() { cout << ans << endl; }   }  // namespace solution   int main() {     using namespace solution;     init();     slove();     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD(1000000007);   const int INF((1 << 30) - 1);   const int MAXN(30);   string a[MAXN];   int type[200] = {0};   int main() {     int n, m, x;     scanf( %d%d%d , &n, &m, &x);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i =  A ; i <=  Z ; i++) type[i] = INF;     for (int i =  a ; i <=  z ; i++) type[i] = INF;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (a[i][j] !=  S )           type[a[i][j]] = 1;         else {           for (int k = 0; k < n; k++)             for (int l = 0; l < m; l++)               if (a[k][l] !=  S )                 type[a[k][l] -  a  +  A ] =                     min(type[a[k][l] -  a  +  A ],                         (i - k) * (i - k) + (j - l) * (j - l));         }       }     int q;     scanf( %d , &q);     int ans = 0;     while (q--) {       char c;       scanf(  %c , &c);       if (type[c] == INF) {         printf( -1 );         return 0;       } else if (c >=  A  && c <=  Z  && type[c] > x * x)         ans++;     }     printf( %d , ans);   }
#include <bits/stdc++.h>   int dp[51 * 10001];   int main(void) {     int n, d, a, sum, i, j;     while (scanf( %d%d , &n, &d) != EOF) {       sum = 0;       memset(dp, 0, sizeof(dp));       dp[0] = 1;       for (i = 0; i < n; i++) {         scanf( %d , &a);         sum += a;         for (j = sum; j >= a; j--) {           if (dp[j - a] == 1) dp[j] = 1;         }       }       int k = 0;       int ans = 0;       while (true) {         i = k + d;         while (dp[i] == 0 && i > k) i--;         if (k == i) break;         k = i;         ans++;       }       printf( %d %d n , k, ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 150000;   struct node {     long long l, r, sm, mx;   } tr[4 * maxn];   inline node comb(node ll, node rr) {     node ret;     ret.l = max(ll.l, ll.sm + rr.l);     ret.r = max(rr.r, rr.sm + ll.r);     ret.sm = ll.sm + rr.sm;     ret.mx = max(max(ll.mx, rr.mx), ll.r + rr.l);     return ret;   }   inline void pushup(int o) { tr[o] = comb(tr[o * 2], tr[o * 2 + 1]); }   long long a[maxn];   void build(int o, int l, int r) {     if (l == r) {       tr[o].l = tr[o].r = tr[o].sm = tr[o].mx = a[l];       return;     }     build(o * 2, l, (l + r) / 2);     build(o * 2 + 1, (l + r) / 2 + 1, r);     pushup(o);   }   node query(int o, int l, int r, int ql, int qr) {     if (ql <= l && qr >= r) return tr[o];     if (qr <= (l + r) / 2) return query(o * 2, l, (l + r) / 2, ql, qr);     if (ql > (l + r) / 2) return query(o * 2 + 1, (l + r) / 2 + 1, r, ql, qr);     node ll = query(o * 2, l, (l + r) / 2, ql, qr),          rr = query(o * 2 + 1, (l + r) / 2 + 1, r, ql, qr);     return comb(ll, rr);   }   long long b[maxn];   int main() {     long long n, q, c;     scanf( %lld%lld%lld , &n, &q, &c);     long long x;     scanf( %lld , &x);     n--;     for (int i = 1; i <= n; i++) scanf( %lld , b + i);     for (int i = 1; i <= n; i++) {       scanf( %lld , &x);       a[i] = (b[i] - b[i - 1]) * 50 - c * x;     }     build(1, 1, n);     long long ans = 0;     while (q--) {       long long l, r;       scanf( %lld%lld , &l, &r);       r--;       node tmp = query(1, 1, n, l, r);       ans += max(tmp.mx, 0LL);     }     cout << fixed << setprecision(9) << 0.01 * ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   long long chess[5][2004][2004];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int N, r1, r2, c1, c2;     cin >> N;     for (int i = 1; i < N + 1; i += 1)       for (int j = 1; j < N + 1; j += 1)         cin >> chess[0][i][j],             chess[1][i][j] = chess[0][i][j] + chess[1][i - 1][j - 1],             chess[2][i][j] = chess[0][i][j] + chess[2][i - 1][j + 1];     for (int i = N; i >= 1; i -= 1)       for (int j = N; j >= 1; j -= 1)         chess[3][i][j] = chess[0][i][j] + chess[3][i + 1][j + 1],         chess[4][i][j] = chess[0][i][j] + chess[4][i + 1][j - 1];     long long ec = -1, oc = -1, t;     for (int i = 1; i < N + 1; i += 1)       for (int j = 1; j < N + 1; j += 1) {         t = chess[0][i][j] + chess[1][i - 1][j - 1] + chess[2][i - 1][j + 1] +             chess[3][i + 1][j + 1] + chess[4][i + 1][j - 1];         if (i + j & 1 && oc < t)           r1 = i, c1 = j, oc = t;         else if ((i + j & 1) == 0 && ec < t)           r2 = i, c2 = j, ec = t;       }     cout << oc + ec <<   n  << r1 <<     << c1 <<     << r2 <<     << c2 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[300009];   vector<pair<pair<long long int, long long int>,               pair<long long int, long long int>>>       v;   long long int ans = 1;   vector<int> vec;   bool check(int idx, long long int mid) {     long long int dist, i, j, x, fuel = mid, cnt = v[idx].second.second,                                  kitna_chlegi;     for (i = v[idx].first.first; i < v[idx].first.second; i++) {       x = a[i + 1] - a[i];       kitna_chlegi = fuel / v[idx].second.first;       if (kitna_chlegi < x) {         if (cnt == 0 || mid / v[idx].second.first < x) {           return 0;         }         fuel = mid;         cnt--;       }       fuel -= x * v[idx].second.first;     }     return 1;   }   void update(int idx) {     if (check(idx, ans)) {       return;     }     long long int l = ans, r = 1000000000000000000, temp = r;     bool f;     while (l <= r) {       long long int mid = (l + r) >> 1;       f = check(idx, mid);       if (f) {         temp = min(temp, mid);         r = mid - 1;       } else {         l = mid + 1;       }     }     ans = max(ans, temp);   }   int main() {     long long int i, j, k, x, y, t, n, m, p;     scanf( %lld%lld , &n, &m);     for (i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     for (i = 0; i < m; i++) {       scanf( %lld%lld , &x, &y);       scanf( %lld%lld , &j, &k);       v.push_back(make_pair(make_pair(x, y), make_pair(j, k)));       vec.push_back(i);     }     random_shuffle(vec.begin(), vec.end());     for (i = 0; i < m; i++) {       update(vec[i]);     }     cout << ans << endl;     ;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   int node[(ll)(1e5 + 7)], in[(ll)(1e5 + 7)], out[(ll)(1e5 + 7)],       ti = 1, hie[(ll)(1e5 + 7)];   int dp[(ll)(1e5 + 7)][17];   vector<int> gr[(ll)(1e5 + 7)], hi[(ll)(1e5 + 7)];   void dfs(int node, int h) {     hi[h].push_back(ti);     hie[node] = h;     in[node] = ti++;     for (int x : gr[node]) {       dfs(x, h + 1);     }     out[node] = ti++;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<int> ve;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 17; j++) {         dp[i][j] = -1;       }     }     for (int i = 1; i <= n; i++) {       int val;       cin >> val;       if (val) {         dp[i][0] = val;         gr[val].push_back(i);       } else {         ve.push_back(i);       }     }     for (int x : ve) {       dfs(x, 1);     }     for (int j = 1; j < 17; j++) {       for (int i = 1; i <= n; i++) {         if (dp[i][j - 1] != -1) {           dp[i][j] = dp[dp[i][j - 1]][j - 1];         }       }     }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int x, p;       cin >> x >> p;       for (int j = 0; (1 << j) <= p; j++) {         if ((1 << j) & p) {           x = dp[x][j];         }       }       if (x == -1) {         cout <<  0  ;         continue;       }       int hh = hie[x] + p;       int xx = (upper_bound(hi[hh].begin(), hi[hh].end(), out[x]) -                 lower_bound(hi[hh].begin(), hi[hh].end(), in[x]));       cout << max(0, xx - 1) <<    ;     }     cout <<   n ;   }