malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   set<pair<int, int> > s, e;   long long dp[N];   int l[N], r[N];   struct Point {     int x, h, k;     bool f;   } p[2 * N];   struct temp {     int h, k;   } q[N];   int m;   bool cmp1(const temp &a, const temp &b) { return a.h > b.h; }   bool cmp(const Point &a, const Point &b) {     if (a.x != b.x) return a.x < b.x;     if (a.f != b.f) return a.f;     return a.k < b.k;   }   vector<int> tran[N];   int main() {     set<pair<int, int> >::iterator it;     int n, t;     scanf( %d%d , &n, &t);     for (int i = 0; i < n; i++) {       int h;       scanf( %d%d%d , &h, &l[i + 1], &r[i + 1]);       p[m].x = l[i + 1], p[m].h = h, p[m].k = i + 1, p[m++].f = false;       p[m].x = r[i + 1], p[m].h = h, p[m].k = i + 1, p[m++].f = true;       q[i].h = h, q[i].k = i + 1;     }     l[0] = -(1 << 30), r[0] = (1 << 30);     l[n + 1] = -(1 << 30), r[n + 1] = (1 << 30);     q[n].h = t, q[n].k = 0;     q[n + 1].h = 0, q[n + 1].k = n + 1;     sort(p, p + m, cmp);     sort(q, q + n + 2, cmp1);     s.insert(make_pair(t, 0));     s.insert(make_pair(0, n + 1));     for (int i = 0; i < m; i++) {       if (p[i].f) {         it = s.find(make_pair(p[i].h, p[i].k));         if (it != s.end()) s.erase(it);       } else {         int a, b;         it = s.lower_bound(make_pair(p[i].h, 0));         a = it->second;         --it;         b = it->second;         it = e.find(make_pair(a, b));         if (it != e.end()) e.erase(it);         e.insert(make_pair(a, p[i].k));         e.insert(make_pair(p[i].k, b));         s.insert(make_pair(p[i].h, p[i].k));       }     }     for (it = e.begin(); it != e.end(); it++)       tran[it->first].push_back(it->second);     dp[0] = (1ll << 50);     for (int i = 0; i < n + 2; i++) {       int now = q[i].k;       for (int j = 0; j < tran[now].size(); j++) {         int tag = tran[now][j];         dp[tag] = max(             dp[tag], min(dp[now], min((long long)r[now], (long long)r[tag]) -                                       max((long long)l[now], (long long)l[tag])));       }     }     printf( %I64d n , dp[n + 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename TH>   void _dbg(const char* sdbg, TH h) {     cerr << sdbg <<  =  << h <<   n ;   }   template <typename TH, typename... TA>   void _dbg(const char* sdbg, TH h, TA... t) {     while (*sdbg !=  , ) {       cerr << *sdbg++;     }     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, t...);   }   template <class C>   void mini(C& a4, C b4) {     a4 = min(a4, b4);   }   template <class C>   void maxi(C& a4, C b4) {     a4 = max(a4, b4);   }   template <class T1, class T2>   ostream& operator<<(ostream& out, pair<T1, T2> pair) {     return out <<  (  << pair.first <<  ,   << pair.second <<  ) ;   }   template <class A, class B, class C>   struct Triple {     A first;     B second;     C third;     bool operator<(const Triple& t) const {       if (first != t.first) return first < t.first;       if (second != t.second) return second < t.second;       return third < t.third;     }   };   template <class T>   void ResizeVec(T&, vector<long long>) {}   template <class T>   void ResizeVec(vector<T>& vec, vector<long long> sz) {     vec.resize(sz[0]);     sz.erase(sz.begin());     if (sz.empty()) {       return;     }     for (T& v : vec) {       ResizeVec(v, sz);     }   }   template <class A, class B, class C>   ostream& operator<<(ostream& out, Triple<A, B, C> t) {     return out <<  (  << t.first <<  ,   << t.second <<  ,   << t.third <<  ) ;   }   template <class T>   ostream& operator<<(ostream& out, vector<T> vec) {     out <<  ( ;     for (auto& v : vec) out << v <<  ,  ;     return out <<  ) ;   }   template <class T>   ostream& operator<<(ostream& out, set<T> vec) {     out <<  ( ;     for (auto& v : vec) out << v <<  ,  ;     return out <<  ) ;   }   template <class L, class R>   ostream& operator<<(ostream& out, map<L, R> vec) {     out <<  ( ;     for (auto& v : vec) out << v <<  ,  ;     return out <<  ) ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cout << fixed << setprecision(10);     if (0) cout << fixed << setprecision(10);     cin.tie(0);     long long t;     cin >> t;     for (long long ii = (1); ii <= (t); ++ii) {       long long n;       cin >> n;       vector<long long> v;       long long sum = 0;       long long ma = 0;       for (long long i = (1); i <= (n); ++i) {         long long a;         cin >> a;         v.push_back(a);         sum += a;         maxi(ma, a);       }       if (n == 1) {         cout <<  T n ;         continue;       }       if (2 * ma > sum) {         cout <<  T n ;       } else {         cout << vector<string>{ HL ,  T }[sum % 2] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, j, k;     cin >> n;     long long a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     long long ans = 10000000000;     for (i = 1; i < n - 1; i++) {       long long b[n];       for (k = 0; k < n; k++) {         b[k] = a[k];       }       long long ans1 = 0;       for (j = 0; j < n - 1; j++) {         if (j != i - 1)           ans1 = max(ans1, b[j + 1] - b[j]);         else           ans1 = max(ans1, b[i + 1] - b[i - 1]);       }       ans = min(ans, ans1);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, i, m;     cin >> t;     while (t--) {       cin >> n;       string s;       cin >> s;       if (n % 2 == 0) {         int f = 0;         for (i = 0; i < n; i++) {           long long a1 = int(s[i] -  0 );           if ((i + 1) % 2 == 0 && a1 % 2 == 0) {             f = 1;           }         }         if (f == 1) {           cout <<  2 ;         } else {           cout <<  1 ;         }       } else if (n % 2 != 0) {         int f = 0;         for (i = 0; i < n; i++) {           long long a1 = int(s[i] -  0 );           if ((i + 1) % 2 != 0 && a1 % 2 != 0) {             f = 1;           }         }         if (f == 1) {           cout <<  1 ;         } else {           cout <<  2 ;         }       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, h, value, width = 0;     vector<int> v;     cin >> n;     cin >> h;     for (int i = 0; i < n; i++) {       cin >> value;       v.push_back(value);     }     for (int j = 0; j < v.size(); j++) {       if (v[j] > h)         width = width + 2;       else         width = width + 1;     }     cout << width;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f[1001][1001], s[1001][1001];   long long a[10001], ans[10001];   int main() {     int n, m, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     sort(a + 1, a + n + 1);     a[0] = -10080124100;     long long sum = 0;     for (int t = 1; t * (k - 1) <= a[n]; t++) {       s[0][0] = f[0][0] = 1;       int l = 0;       for (int i = 1; i <= n; i++) {         while (a[l] <= a[i] - t) l++;         for (int j = 0; j <= k; j++) {           if (j != 0) f[i][j] = s[l - 1][j - 1] % 998244353;           s[i][j] = (s[i - 1][j] + f[i][j]) % 998244353;         }         sum = (sum + f[i][k]) % 998244353;       }     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     if (n == 0 || n == 1) {       cout << 0 << endl;       return;     }     long long a[n];     vector<int> pos;     long long even = n / 2, odds = n - even;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] != 0) {         if (a[i] & 1)           odds--;         else           even--;         pos.push_back(i);       }     }     if (pos.size() == 0) {       cout << 1 << endl;       return;     }     vector<pair<int, int>> good;     int bad = 0;     for (int i = 1; i < pos.size(); ++i) {       if (pos[i] - pos[i - 1] != 1) {         if (a[pos[i]] % 2 == a[pos[i - 1]] % 2) {           good.push_back({pos[i], pos[i - 1]});         }       }       if (a[pos[i]] % 2 != a[pos[i - 1]] % 2) bad++;     }     sort(good.begin(), good.end(), [&](pair<int, int> a, pair<int, int> b) {       return a.first - a.second < b.first - b.second;     });     long long ans = bad;     for (auto i : good) {       int k = i.first - i.second - 1;       if (a[i.first] & 1 && odds >= k)         odds -= k;       else if (!(a[i.first] & 1) && even >= k)         even -= k;       else         ans += 2;     }     if (a[0] == 0) {       int cnt = 0;       while (a[cnt] == 0) cnt++;       if (a[cnt] & 1 && odds >= cnt)         odds -= cnt;       else if (!(a[cnt] & 1) && even >= cnt)         even -= cnt;       else         ans++;     }     if (a[n - 1] == 0) {       int cnt = 0, i = n - 1;       while (a[i] == 0) cnt++, --i;       if (!(a[i] & 1 && odds >= cnt || !(a[i] & 1) && even >= cnt)) ans++;     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int maxm = 1e6 + 10;   const int mod = 1e9 + 7;   queue<string> que;   string str;   set<string> se;   int ans, n, k;   void bfs() {     if (k - 1 == 0) return;     que.push(str);     while (que.size()) {       string now = que.front();       que.pop();       for (int i = 0; i < now.size(); i++) {         string zz =   ;         for (int j = 0; j < now.size(); j++)           if (j != i) zz += now[j];         if (se.find(zz) == se.end()) {           se.insert(zz);           que.push(zz);           ans += (n - zz.size());           if (se.size() == k - 1) return;         }       }     }   }   int main() {     scanf( %d %d , &n, &k);     cin >> str;     bfs();     if (se.size() == k - 1)       printf( %d n , ans);     else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1000005;   const long long M = 1000000007;   long long n, m, cc, len;   long long s[5];   int main() {     long long sum = 0;     for (long long i = 0; i < 3; i++) scanf( %I64d , &s[i]), sum += s[i];     sort(s, s + 3);     long long ans = -1;     for (long long i = 0; i < 3; i++)       for (long long j = i + 1; j < 3; j++) {         long long ano = sum - s[i] - s[j];         if ((s[i] + s[j]) % 2 == 0 && ano >= (abs(s[j] - s[i]) / 2)) {           if (ans == -1) ans = s[j];           ans = min(ans, s[j]);         }       }     if (ans == -1) ans = s[2];     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = LLONG_MAX;   const long long MINF = LLONG_MIN;   const int N = 2e5 + 5;   template <typename T>   inline T abs(T x) {     return x < 0 ? -x : x;   }   inline long long pow_mod(long long x, long long n) {     long long r = 1;     while (n) {       if (n % 2) r = (r * x) % MOD;       x = (x * x) % MOD;       n /= 2;     }     return r;   }   inline long long pow_(long long x, long long n) {     long long r = 1;     while (n) {       if (n % 2) r = (r * x);       x = (x * x);       n /= 2;     }     return r;   }   void solve() {     int n, k, d;     cin >> n >> k >> d;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     map<int, int> m;     for (int i = 0; i < d; i++) m[a[i]]++;     int ans = (int)m.size();     for (int i = d; i < n; i++) {       m[a[i - d]]--;       if (!m[a[i - d]]) m.erase(a[i - d]);       m[a[i]]++;       ans = min(ans, (int)m.size());     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t = 1;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9, MOD = 1e9 + 7;   const int n_ = 1e5 + 1000;   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   long long power(long long a, long long n, long long mod) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;         p %= mod;       }       n >>= 1;       a *= a;       a %= mod;     }     return p % mod;   }   int main() {     ios_base::sync_with_stdio(false);     long long n, x, y, a;     scanf( %lld %lld %lld , &n, &x, &y);     a = y - n + 1;     if (a > 0 && a * a + n - 1 >= x) {       for (int(i) = 0; (i) < (n - 1); (i)++) puts( 1 );       printf( %lld n , a);     } else {       puts( -1 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string nsp(string s) {     string t =   ;     for (int i = 0; i < s.size(); i++)       if (s[i] !=    ) t = t + s[i];     return t;   }   string gfbu(string s, char c, int a) {     string t =   ;     for (int i = a; i < s.size() - 1; i++) {       if (s[i] == c) return t;       t += s[i];     }     return t;   }   int in(string s) {     return (s ==  double  ? 2 : (s ==  int  ? 3 : (s ==  T  ? 1 : 5)));   }   vector<int> ext(string s) {     int cnt = gfbu(s,  ( , 0).size() + 1;     vector<int> v;     while (cnt < s.size())       v.push_back(in(gfbu(s,  , , cnt))), cnt += gfbu(s,  , , cnt).size() + 1;     return v;   }   int main() {     int n, m, k;     map<string, int> ints;     map<string, vector<vector<int> > > voids;     cin >> n;     for (int i = 0; i < n; i++) {       string trash, s, vo;       if (i == 0) cin.ignore();       getline(cin, s), s = nsp(s), s.erase(0, 4);       vo = gfbu(s,  ( , 0), voids[vo].push_back(ext(s));     }     cin >> m;     for (int i = 0; i < m; i++) {       string s, t;       cin >> s >> t, ints[t] = in(s);     }     cin >> k;     for (int i = 0; i < k; i++) {       if (i == 0) cin.ignore();       string s, vo;       getline(cin, s), s = nsp(s), vo = gfbu(s,  ( , 0);       int ans = 0, cnt = gfbu(s,  ( , 0).size() + 1;       vector<int> vi;       while (cnt < s.size())         vi.push_back(ints[gfbu(s,  , , cnt)]),             cnt += gfbu(s,  , , cnt).size() + 1;       if (voids[vo].size() == 0) {         cout <<  0 n ;         continue;       }       for (int j = 0; j < voids[vo].size(); j++) {         if (voids[vo][j].size() != vi.size()) continue;         for (int k = 0; k < vi.size(); k++)           if (vi[k] % voids[vo][j][k]) {             ans--;             break;           }         ans++;       }       cout << ans << 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;     cin >> t;     while (t--) {       int n, k, i;       cin >> n >> k;       string s[3];       cin >> s[0] >> s[1] >> s[2];       bool a[3][105];       while (s[0].size() <= n + 2) s[0] +=  . ;       while (s[1].size() <= n + 2) s[1] +=  . ;       while (s[2].size() <= n + 2) s[2] +=  . ;       memset(a, 0, sizeof(a));       if (s[0][0] ==  s )         a[0][0] = true;       else if (s[1][0] ==  s )         a[1][0] = true;       else         a[2][0] = true;       for (i = 0; i < n; i++) {         if (a[0][i]) {           if (s[0][i + 1] ==  . ) {             if (s[0][i + 3] ==  .  && s[0][i + 2] ==  . ) a[0][i + 3] = true;             if (s[1][i + 3] ==  .  && s[1][i + 2] ==  .  && s[1][i + 1] ==  . )               a[1][i + 3] = true;           }         }         if (a[1][i]) {           if (s[1][i + 1] ==  . ) {             if (s[1][i + 3] ==  .  && s[1][i + 2] ==  . ) a[1][i + 3] = true;             if (s[0][i + 3] ==  .  && s[0][i + 1] ==  .  && s[0][i + 2] ==  . )               a[0][i + 3] = true;             if (s[2][i + 3] ==  .  && s[2][i + 1] ==  .  && s[2][i + 2] ==  . )               a[2][i + 3] = true;           }         }         if (a[2][i]) {           if (s[2][i + 1] ==  . ) {             if (s[2][i + 3] ==  .  && s[2][i + 2] ==  . ) a[2][i + 3] = true;             if (s[1][i + 3] ==  .  && s[1][i + 2] ==  .  && s[1][i + 1] ==  . )               a[1][i + 3] = true;           }         }       }       bool flag = false;       if (a[0][n] || a[1][n] || a[2][n] || flag) flag = true;       if (a[0][n + 1] || a[1][n + 1] || a[2][n + 1] || flag) flag = true;       if (a[0][n - 1] || a[1][n - 1] || a[2][n - 1] || flag)         cout <<  YES n ;       else         cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 1000;   const long long INF64 = 1e18;   const int N = 1001000;   const int MOD = 1e9 + 7;   const double EPS = 1E-9;   long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }   int add(int first, int second, int m) {     first += second;     while (first >= m) first -= m;     while (first < 0) first += m;     return first;   }   int sub(int first, int second, int m) { return add(first, -second, m); }   int mul(int first, int second, int m) { return (first * 1ll * second) % m; }   int binpow(int first, int second, int m) {     int z = 1;     while (second) {       if (second & 1) z = mul(z, first, m);       first = mul(first, first, m);       second >>= 1;     }     return z;   }   int divide(int first, int second, int m) {     return mul(first, binpow(second, m - 2, m), m);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int first, t, a, b, da, db;     cin >> first >> t >> a >> b >> da >> db;     if (first == 0) {       cout <<  YES n ;       return 0;     }     for (int ta = 0; ta < t; ++ta) {       for (int tb = 0; tb < t; ++tb) {         if (a - da * ta + b - db * tb == first || a - da * ta == first ||             b - db * tb == first) {           cout <<  YES n ;           return 0;         }       }     }     cout <<  NO n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int score(pair<int, int> a) {     int d = abs(a.first - a.second);     return min(d, n - d);   }   const int N = 1e5 + 7;   int nxt[N], prv[N];   vector<int> regions[N];   vector<int> adj[N];   int level[N];   int sz[N];   void dfs1(int u, int par) {     assert(level[u] == 0);     sz[u] = 1;     for (int v : adj[u]) {       if (v == par || level[v]) continue;       dfs1(v, u);       sz[u] += sz[v];     }   }   int dfs2(int u, int par, int s) {     for (int v : adj[u]) {       if (v == par || level[v]) continue;       if (sz[v] > s / 2) return dfs2(v, u, s);     }     return u;   }   void decompose(int u, int lev) {     assert(level[u] == 0);     dfs1(u, -1);     int v = dfs2(u, -1, sz[u]);     level[v] = lev;     for (int w : adj[v])       if (!level[w]) decompose(w, lev + 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     vector<pair<int, int>> diags;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       diags.push_back({a, b});     }     auto cmp1 = [](pair<int, int> a, pair<int, int> b) {       return score(a) < score(b);     };     sort(diags.begin(), diags.end(), cmp1);     for (int i = 1; i <= n; i++) {       nxt[i] = 1 + i % n;     }     int id = 0, last = 0;     for (auto pr : diags) {       ++id;       int u = pr.first;       int v = pr.second;       int d = (v - u + n) % n;       if (d >= n - d) swap(u, v);       int cur = u;       while (cur != v) {         regions[id].push_back(cur);         cur = nxt[cur];       }       regions[id].push_back(v);       nxt[u] = v;       last = u;     }     ++id;     int cur = last;     while (true) {       regions[id].push_back(cur);       cur = nxt[cur];       if (cur == last) break;     }     map<pair<int, int>, vector<int>> mp;     for (int i = 1; i <= id; i++) {       for (int j = 0; j < regions[i].size(); j++) {         int u = regions[i][j];         int v = regions[i][(j + 1) % regions[i].size()];         if (u > v) swap(u, v);         mp[make_pair(u, v)].push_back(i);       }     }     for (auto pr : mp) {       assert(pr.second.size() <= 2);       if (pr.second.size() != 2) continue;       int u = pr.second[0];       int v = pr.second[1];       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 1; i <= id; i++) {       sort(regions[i].rbegin(), regions[i].rend());     }     vector<int> order;     for (int i = 1; i <= id; i++) {       order.push_back(i);     }     sort(order.begin(), order.end(),          [](int a, int b) { return regions[a] < regions[b]; });     decompose(1, 1);     for (int x : order) cout << level[x] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) {       v.emplace_back(x);     }     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<  ,  ;     err(++it, args...);   }   vector<pair<int, int>> vt[101];   int dp[101][101][26][2];   bool rec(int u, int v, int ch, int side) {     if (dp[u][v][ch][side] != -1) return dp[u][v][ch][side];     int ans = 0;     if (side) {       for (auto g : vt[v]) {         if (g.second >= ch) ans |= !rec(u, g.first, g.second, side ^ 1);       }     } else {       for (auto g : vt[u]) {         if (g.second >= ch) ans |= !rec(g.first, v, g.second, side ^ 1);       }     }     return dp[u][v][ch][side] = ans;   }   int main() {     memset(dp, -1, sizeof dp);     int n, m, i, j, u, v;     cin >> n >> m;     char c;     for (i = 0; i < m; ++i) {       cin >> u >> v >> c;       vt[u].push_back({v, c -  a });     }     for (i = 1; i <= n; ++i) {       for (j = 1; j <= n; ++j) {         if (rec(i, j, 0, 0))           printf( A );         else           printf( B );       }       puts(  );     }   }
#include <bits/stdc++.h>   using namespace std;   double pi = acos(-1);   long long power(long long a, long long b) {     long long p_res = 1;     while (b > 0) {       if (b % 2 == 1) {         p_res *= a;         b--;       }       a *= a;       b /= 2;     }     return p_res;   }   int cc[300001];   int ans[300001];   set<pair<int, int> > ss;   set<pair<int, int> >::iterator it;   vector<int> adj[300001];   int n, q;   int dfs(int here) {     int res = 1;     for (int i = 0; i < adj[here].size(); i++) {       res += dfs(adj[here][i]);     }     cc[here] = res;     return res;   }   void centroid(int here, int prev) {     int mx = 0;     for (int i = 0; i < adj[here].size(); i++) {       int next = adj[here][i];       mx = max(mx, cc[next]);     }     if (2 * mx <= cc[here])       ans[here] = here;     else       ss.insert(make_pair(cc[here], here));     it = ss.lower_bound(make_pair(2 * mx, -1));     while (it != ss.end()) {       int v = it->first;       int i = it->second;       if (v > 2 * cc[here]) break;       if (2 * mx <= v && 2 * (v - cc[here]) <= v) {         ans[i] = here;         ss.erase(it++);       } else         it++;     }     for (int i = 0; i < adj[here].size(); i++) {       centroid(adj[here][i], here);     }   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 2; i <= n; i++) {       int v;       scanf( %d , &v);       adj[v].push_back(i);     }     dfs(1);     centroid(1, -1);     for (int i = 0; i < q; i++) {       int v;       scanf( %d , &v);       printf( %d n , ans[v]);     }     return 0;   }