malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int SIZE = 2100;   struct kstr {     int C[30];     bool mask[110];   } A[SIZE];   int CC[30];   int main() {     int K, N, len;     char S[110];     cin >> K >> S >> N;     len = strlen(S);     for (int i = 0; i != len; i++) CC[S[i] -  a ]++;     for (int i = 0; i != K; i++) {       for (int j = 0; j != len; j++) A[i].mask[j] = true;       for (int j = 0; j != 30; j++) A[i].C[j] = CC[j];     }     int a;     char ch;     while (N--) {       cin >> a >> ch;       int sumch = 0;       for (int i = 0; i != K; i++)         if (sumch + A[i].C[ch -  a ] >= a) {           a -= sumch;           A[i].C[ch -  a ]--;           for (int j = 0; j != len; j++) {             if (S[j] == ch && A[i].mask[j]) a--;             if (!a) {               A[i].mask[j] = false;               break;             }           }           break;         } else           sumch += A[i].C[ch -  a ];     }     for (int i = 0; i != K; i++)       for (int j = 0; j != len; j++)         if (A[i].mask[j]) cout << S[j];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v[100000];   int f[100000];   int d[100000];   void dfs(int x) {     int i;     for (i = 0; i < v[x].size(); i++) {       if (f[v[x][i].first] == 0) {         d[v[x][i].first] = d[x] + v[x][i].second;         f[v[x][i].first] = 1;         dfs(v[x][i].first);       }     }   }   int main() {     int n, i, j;     long long sum = 0;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) {       int x, y, w;       scanf( %d %d %d , &x, &y, &w);       v[x - 1].push_back(make_pair(y - 1, w));       v[y - 1].push_back(make_pair(x - 1, w));       sum += w * 2;     }     f[0] = 1;     dfs(0);     sort(d, d + n);     sum -= d[n - 1];     printf( %I64d n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fast_io() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   long long r(long long num, long long den) {     if (den == 1)       return num;     else if (num == 1)       return den;     if (num > den)       return num / den + r(num % den, den);     else       return den / num + r(num, den % num);   }   void solve() {     long long a, b;     cin >> a >> b;     cout << r(a, b) << endl;   }   int main() {     fast_io();     solve();     return 0;   }
#include <bits/stdc++.h>   int n;   int a[(200010) << 1], b[(200010) << 1];   int pa[(200010) << 1], sa[(200010) << 1];   int pb[(200010) << 1], sb[(200010) << 1];   struct node {     int x, y;   } p[(200010)];   long long solve(int t) {     memset(a, 0, sizeof(a));     memset(b, 0, sizeof(b));     memset(pa, 0, sizeof(pa));     memset(pb, 0, sizeof(pb));     memset(sa, 0, sizeof(sa));     memset(sb, 0, sizeof(sb));     for (int i = 0; i < (200010) << 1; ++i) {       b[i] = ((200010) << 1) - 1;     }     for (int i = 0; i < n; ++i) {       if ((p[i].x & 1) ^ t) continue;       a[p[i].x] = std::max(a[p[i].x], p[i].y);       b[p[i].x] = std::min(b[p[i].x], p[i].y);     }     pb[0] = sb[((200010) << 1) - 1] = ((200010) << 1) - 1;     for (int i = 1; i < (200010) << 1; ++i) {       pa[i] = std::max(pa[i - 1], a[i]);       pb[i] = std::min(pb[i - 1], b[i]);     }     for (int i = ((200010) << 1) - 2; ~i; --i) {       sa[i] = std::max(sa[i + 1], a[i]);       sb[i] = std::min(sb[i + 1], b[i]);     }     long long ret = 0;     for (int i = 1 + t; i < ((200010) << 1) - 1; i += 2) {       int l = std::min(pa[i - 1], sa[i + 1]);       int r = std::max(pb[i - 1], sb[i + 1]);       if (l <= r) {         ret += (200010);         continue;       }       if ((l ^ i) & 1) ++l;       if ((r ^ i) & 1) --r;       ret += ((((200010) << 1) - 1 - l) >> 1) + 1;       ret += (r >> 1) + 1;     }     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       p[i] = {x + y + (200010), x - y + (200010)};     }     long long ans =         1ll * ((200010) << 1) * (((200010) << 1) - 2) / 2 - solve(0) - solve(1);     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void pisz(int n) { printf( %d n , n); }   const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},                          {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   template <typename T, typename TT>   ostream& operator<<(ostream& s, pair<T, TT> t) {     return s <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& s, vector<T> t) {     for (int i = 0; i < ((int)((t).size())); i++) s << t[i] <<    ;     return s;   }   int main() {     int n;     string A;     int cursor;     cin >> n >> cursor >> A;     cursor--;     n--;     cursor = min(cursor, n - cursor);     int middle = n / 2;     int leftmost = cursor, rightmost = cursor;     for (int i = cursor; i <= middle; i++)       if (A[i] != A[n - i]) rightmost = i;     for (int i = cursor; i >= 0; i--)       if (A[i] != A[n - i]) leftmost = i;     int vertical_moves = 0;     for (int i = leftmost; i <= rightmost; i++)       vertical_moves += min(abs(A[i] - A[n - i]), 26 - abs(A[i] - A[n - i]));     int horizontal_moves = min((cursor - leftmost) + (rightmost - leftmost),                                (rightmost - cursor) + (rightmost - leftmost));     int total_moves = horizontal_moves + vertical_moves;     cout << total_moves;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MXN = 1e3 + 7;   const int mod = 998244353;   int n, m;   int ar[MXN][MXN];   int br[MXN];   struct lp {     int m, v;   } A[MXN][MXN], B[MXN][MXN];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) scanf( %d , &ar[i][j]);     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         br[j] = ar[i][j];       }       sort(br + 1, br + 1 + m);       int k = unique(br + 1, br + 1 + m) - br - 1;       for (int j = 1; j <= m; ++j) {         A[i][j].m = k;         A[i][j].v = lower_bound(br + 1, br + 1 + k, ar[i][j]) - br;       }     }     for (int i = 1; i <= m; ++i) {       for (int j = 1; j <= n; ++j) {         br[j] = ar[j][i];       }       sort(br + 1, br + 1 + n);       int k = unique(br + 1, br + 1 + n) - br - 1;       for (int j = 1; j <= n; ++j) {         B[j][i].m = k;         B[j][i].v = lower_bound(br + 1, br + 1 + k, ar[j][i]) - br;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         int t = abs(A[i][j].v - B[i][j].v);         if (A[i][j].v > B[i][j].v) {           printf( %d  , max(A[i][j].m, B[i][j].m + t));         } else if (A[i][j].v < B[i][j].v) {           printf( %d  , max(A[i][j].m + t, B[i][j].m));         } else {           printf( %d  , max(A[i][j].m, B[i][j].m));         }       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   bool ok(int x) {     if (x < 0) return false;     for (int i = 0; i * i <= x; i++)       if (i * i == x) return true;     return false;   }   int main() {     int n;     scanf( %d , &n);     int mx = -10000000;     for (int i = (0); i < (n); ++i) {       int x;       scanf( %d , &x);       if (ok(x)) continue;       mx = max(mx, x);     }     printf( %d n , mx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, a, b, c, d;       cin >> n >> a >> b >> c >> d;       if ((a + b) * n < c - d)         cout <<  No n ;       else if ((a - b) * n > c + d)         cout <<  No n ;       else         cout <<  Yes n ;     }     return 0;   }
#include <bits/stdc++.h>   int M[50] = {0,       2,       3,       5,       7,        13,      17,                19,      31,      61,      89,      107,      127,     521,                607,     1279,    2203,    2281,    3217,     4253,    4423,                9689,    9941,    11213,   19937,   21701,    23209,   44497,                86243,   110503,  132049,  216091,  756839,   859433,  1257787,                1398269, 2976221, 3021377, 6972593, 13466917, 20996011};   int main(void) {     int i, n, x = 1;     scanf( %d , &n);     for (i = 1; i < M[n]; i++) {       x *= 2;       x %= 1000000007;     }     printf( %d , (x + 1000000007 - 1) % 1000000007);   }
#include <bits/stdc++.h>   using namespace std;   long long a[200100];   int main() {     long long k, Answer = 0;     int n;     cin >> n >> k;     for (int i = 0; i < n; i++) scanf( %I64d , &a[i]);     for (int i = 0; i < n; i++) {       Answer += a[i] / k;       a[i] = a[i] % k;       if (a[i] + a[i + 1] >= k)         a[i + 1] += a[i];       else if (a[i] > 0) {         a[i + 1] = 0;         Answer++;       }     }     cout << Answer;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void substr(int start, int end, char in[], char out[]) {     for (int i = start; i < end; ++i) out[i - start] = in[i];     out[end - start] =   0 ;   }   int main() {     int n, p, q;     char s[100];     cin >> n >> p >> q;     cin >> s;     int pdivmax = n / p + 1, qdivmax = n / q + 1;     bool divided = false;     if (p == q) {       if (n % p == 0) {         cout << n / p << endl;         for (int i = 0; i < n; i += p) {           char out[100];           substr(i, i + p, s, out);           cout << out << endl;         }         divided = true;       }     } else {       for (int i = 0; i < pdivmax; ++i) {         for (int j = 0; j < qdivmax; ++j) {           if (p * i + q * j == n) {             cout << i + j << endl;             for (int k = 0; k < p * i; k += p) {               char out[100];               substr(k, k + p, s, out);               cout << out << endl;             }             for (int k = p * i; k < n; k += q) {               char out[100];               substr(k, k + q, s, out);               cout << out << endl;             }             divided = true;             break;           }         }         if (divided) break;       }     }     if (!divided) cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, k, l, m, t;     vector<int> a[10001];     cin >> n;     for (i = 1; i < n; i++) {       cin >> m >> t;       a[m].push_back(t);       a[t].push_back(m);     }     l = 0;     m = 0;     int b[30001], c[30001];     for (t = 1; t <= n; t++) {       j = 0;       for (i = 0; i < a[t].size(); i++) {         j++;         b[j] = a[t][i];       }       l = 0;       for (i = 1; i <= a[t].size(); i++) {         for (j = 0; j < a[b[i]].size(); j++) {           l++;           c[l] = a[b[i]][j];         }       }       for (i = 1; i <= l; i++)         if (c[i] > t) m++;     }     cout << m << endl;   }
#include <bits/stdc++.h>   using namespace std;   bool not_prime[100000];   long long int primes[100000];   int p, prime_factors[100000], pf_count[100000], q;   int a[10000];   void find_primes() {     long long int i, j;     p = 0;     for (i = 2; i < 100000; i++) {       if (not_prime[i] == false) {         primes[p++] = i;         for (j = 2; i * j < 100000; j++) {           not_prime[i * j] = false;         }       }     }   }   void factor(long long int n) {     q = 0;     for (int i = 0; i < p; i++) {       int count = 0;       while (n % primes[i] == 0) {         count++;         n /= primes[i];       }       if (count > 0) {         prime_factors[q] = i;         pf_count[q++] = count;       }     }     if (n > 1) {       primes[p++] = n;       prime_factors[q] = p - 1;       pf_count[q++] = 1;     }   }   int rec(int d, long long int b) {     int ret = 0;     if (d == q) {       long long int x = 1;       for (int i = 0; i < q; i++) {         for (int j = 0; j < a[i]; j++) x *= primes[prime_factors[i]];       }       if (x <= b)         return 0;       else         return 1;     }     for (int j = pf_count[d]; j >= 0; j--) {       a[d] = j;       int tmp = rec(d + 1, b);       if (tmp == 0) break;       ret += tmp;     }     return ret;   }   int main() {     long long int a, b, n;     int ans = 0;     cin >> a >> b;     n = a - b;     if (a == b) {       cout <<  infinity  << endl;     } else if (a < b) {       cout << 0 << endl;     } else {       find_primes();       factor(n);       cout << rec(0, b) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[3], b[3];     int k, d;     cin >> a[0] >> a[1] >> a[2] >> k;     for (int i = 0; i < 3; i++) {       a[i]--;       b[i] = 0;     }     sort(a, a + 3);     for (int i = 0; i < 3; i++) {       d = k / (3 - i);       for (int j = i; j < 3; j++) {         int t = min(a[i], d);         b[j] += t;         a[j] -= t;         k -= t;         if (d % (3 - i) > j && a[j]) {           k--;           b[j]++;           a[j]--;         }       }     }     cout << (long long)(b[0] + 1) * (b[1] + 1) * (b[2] + 1);   }
#include <bits/stdc++.h>   using namespace std;   bool prime(long long int i) {     if (i == 1) return false;     if ((i == 2) || (i == 3)) return true;     if ((i % 2 == 0) || (i % 3 == 0))       return false;     else {       for (long long int j = 5; j * j <= i; j += 6)         if ((i % j == 0) || (i % (j + 2) == 0)) return false;     }     return true;   }   int main() {     long long p, y, ans;     cin >> p >> y;     int f = 0;     if (p == y) {       cout <<  -1 ;       return 0;     }     for (long long i = y; i > p; i--) {       int f1 = 0;       if (prime(i)) {         f = 1;         ans = i;         break;       }       for (long long j = 2; j <= p; j++) {         if (i % j == 0) {           f1 = 1;           break;         }       }       if (f1 == 0) {         ans = i;         f = 1;         break;       }     }     if (f == 1) {       cout << ans;     } else {       cout <<  -1 ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 600;   int mat[2000][2000];   int quad[20][20];   int cont[20][20];   int main() {     int n, m;     scanf( %d%d , &n, &m);     int foi = 0;     int result = -1;     for (int i = 0; i < m; i++) {       int x, y;       for (int h = 0; h < 5; h++) {         for (int k = 0; k < 5; k++) {           quad[h][k] = 0;           cont[h][k] = 0;         }       }       scanf( %d%d , &x, &y);       x--;       y--;       mat[x][y]++;       int maiorX = max(x - 2, 0);       int menorX = min(x + 2, n - 1) + 1;       int maiorY = max(y - 2, 0);       int menorY = min(y + 2, n - 1) + 1;       for (int h = maiorX; h < menorX; h++) {         for (int k = maiorY; k < menorY; k++) {           if (mat[h][k]) {             cont[h - maiorX][k - maiorY]++;             if (h - maiorX - 1 >= 0) {               cont[h - maiorX][k - maiorY] += cont[h - maiorX - 1][k - maiorY];             }           }         }       }       int pode = 0;       for (int h = 0; h < 5; h++) {         int soma = 0;         for (int k = 0; k < 5; k++) {           if (cont[h][k] >= 3) {             soma++;             if (soma >= 3) {               pode = 1;             }           } else {             soma = 0;           }         }       }       if (foi == 0 && pode) {         result = i + 1;         foi = 1;       }     }     printf( %d n , result);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void prnt(bool ok) { cout << (ok ?  YES  :  NO ); }   const int ppr = 257;   const long long INF = 2e18;   const int inf = 2e9;   const int mod = 1e9 + 7;   const int N = 3e6 + 123;   const long double pi = 3.141592653589793238462643;   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, 1, 0, -1};   long long n, m, a[N], b[N], q, cur;   vector<long long> g[N];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     while (m--) {       long long x, y;       cin >> x >> y;       if (x < y) swap(x, y);       g[y].push_back(x);       a[x]++;       b[y]++;     }     for (long long i = 1; i <= n; i++) cur += a[i] * b[i];     cin >> q;     cout << cur <<   n ;     while (q--) {       long long x;       cin >> x;       cur -= a[x] * b[x];       a[x] += g[x].size();       b[x] = 0;       for (auto to : g[x]) {         cur -= a[to] * b[to];         b[to]++;         a[to]--;         cur += a[to] * b[to];         g[to].push_back(x);       }       g[x].clear();       cout << cur <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = (int)1e5 + 5;   string check(char x, int n) {     string it =   ;     it.push_back(x);     string z =   ;     for (int i = 0; i < n; i++) {       z = z +  0 ;     }     it = it + z;     return it;   }   int main() {     int tc;     cin >> tc;     while (tc--) {       int x;       int count = 0;       vector<string> v;       cin >> x;       string it = to_string(x);       int size = it.length();       for (int i = 0; i < size; i++) {         if (it[size - 1 - i] !=  0 ) {           string second = check(it[size - 1 - i], i);           count++;           v.push_back(second);         }       }       reverse(v.begin(), v.end());       cout << count << endl;       for (auto& i : v) {         cout << i <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f[2010][2010], n, s, ans, m;   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       s = 0;       for (int j = 0; j <= m - 2; ++j)         s = (s + f[i - 1][j]) % 1000000007,         f[i][j] = ((j == 0 ? 1 : f[i][j - 1]) + s) % 1000000007;     }     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= m - 2; ++j)         ans = (ans + (m - j - 1) * (f[i][j] - f[i - 1][j]) % 1000000007 *                          f[n - i + 1][j] % 1000000007) %               1000000007;     cout << (ans + 1000000007) % 1000000007;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3F3F3F3F;   const int MAXN = 100001;   char str[MAXN];   inline void solve(int test) {     int t, sx, sy, ex, ey;     scanf( %d %d %d %d %d , &t, &sx, &sy, &ex, &ey);     scanf( %s , str);     ;     int X, Y;     X = ex - sx, Y = ey - sy;     pair<char, char> S;     if (Y < 0)       S.first =  S ;     else       S.first =  N ;     if (X < 0)       S.second =  W ;     else       S.second =  E ;     X = abs(X);     Y = abs(Y);     for (int i = 0; i < t; ++i) {       char G = str[i];       if (S.first == G)         Y--;       else if (S.second == G)         X--;       if (X <= 0 && Y <= 0) {         printf( %d n , i + 1);         return;       }     }     printf( -1 n );   }   int main() {     solve(0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   char buf[1000];   string nextLine(int length = 100) {     cin.getline(buf, length);     string s(buf);     return s;   }   string next(int length = 100) {     string tmp;     cin >> tmp;     return tmp;   }   int nextInt() {     int tmp;     scanf( %d , &tmp);     return tmp;   }   long long mod = 1E9 + 7;   long long add(long long a, long long b) { return (a + b) % mod; }   const int MAXN = 5010;   string s1, s2;   int m, n;   long long dp[MAXN][MAXN];   long long get(int starta, int startb) {     if (starta == m) return 0;     if (startb == n) return 0;     long long &ret = dp[starta][startb];     if (ret != -1) return ret;     ret = 0;     if (s2[startb] == s1[starta]) {       ret++;       ret = add(ret, get(starta + 1, startb + 1));     }     ret = add(ret, get(starta, startb + 1));     return ret;   }   int main() {     s1 = next();     s2 = next();     m = ((int)(s1).size());     n = ((int)(s2).size());     long long sum = 0;     for (int i = 0, _i = (MAXN); i < _i; ++i)       for (int j = 0, _j = (MAXN); j < _j; ++j) dp[i][j] = -1;     for (int i = 0, _i = (m); i < _i; ++i) {       sum = add(sum, get(i, 0));     }     cout << sum << endl;   }
#include <iostream>           #include <string>           #include<bits/stdc++.h>           #include<algorithm>           using namespace std;           int main()           {               int t;               cin>>t;               while(t--)               {                   long long n,k;                   cin>>n>>k;                   long long a=n,b=1;                   if(n%2==0)                   {                       k--;                       k=k%n;                       cout<<b+k<<endl;                   }                   else                   {                       k--;                       long long t=n/2;                       long long y=k/t;                       long long j=k+y+1;                       long long ans=j%n;                       if(!ans)ans=n;                       cout<<ans<<endl;                   }               }           }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e5;   int n;   char ans[maxN + 1];   string s;   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     cin.ignore();     for (int i = 0; i < n; i++) {       getline(cin, s);       for (int j = 0; j < s.length(); j++) {         if (ans[j] == 0) ans[j] =  ? ;         if (s[j] ==  ?  || ans[j] ==  X ) continue;         if (ans[j] ==  ?  && s[j] !=  ? )           ans[j] = s[j];         else if (ans[j] !=  ?  && s[j] !=  ?  && ans[j] != s[j])           ans[j] =  X ;       }     }     for (int i = 0; i < s.length(); i++) {       if (ans[i] ==  X )         ans[i] =  ? ;       else if (ans[i] ==  ? )         ans[i] =  a ;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[100020];   char b[100020];   int zf[100020];   int zb[100020];   int main() {     scanf( %s , a);     scanf( %s , b);     int la = strlen(a);     int lb = strlen(b);     zf[0] = 0;     zb[la] = lb;     for (int i = 1; i <= la; i++) {       if (a[i - 1] == b[zf[i - 1]]) {         zf[i] = zf[i - 1] + 1;       } else {         zf[i] = zf[i - 1];       }     }     for (int i = la - 1; i >= 0; i--) {       if (a[i] == b[zb[i + 1] - 1]) {         zb[i] = zb[i + 1] - 1;       } else {         zb[i] = zb[i + 1];       }     }     int ans = lb + 1;     int p = -1;     for (int i = 0; i <= la; i++) {       int tmp = max(zb[i] - zf[i], 0);       if (ans > tmp) {         ans = tmp;         p = i;       }     }     for (int i = 0; i < zf[p]; i++) {       printf( %c , b[i]);     }     for (int i = max(zf[p], zb[p]); i < lb; i++) {       printf( %c , b[i]);     }     if (ans == lb) {       printf( - );     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int maxn = 1e6 + 500;   const long long int mod = 998244353;   int dep[maxn], low[maxn], ans[maxn], dp[maxn];   int head[maxn], cnt;   int n, k;   struct C {     int next, to;   } E[maxn];   void add(int x, int y) {     E[cnt].to = y;     E[cnt].next = head[x];     head[x] = cnt++;   }   void dfs1(int u, int fa) {     low[u] = 0x7f7f7f7f;     dep[u] = dep[fa] + 1;     if (head[u] == -1) {       low[u] = dep[u];       dp[u] = 1;     } else {       for (int i = head[u]; i + 1; i = E[i].next) {         int v = E[i].to;         dfs1(v, u);         low[u] = min(low[u], low[v]);         if (low[v] - k <= dep[u]) dp[u] += dp[v];       }     }   }   int dfs(int u, int fa) {     if (head[u] == -1) return 1;     int ans = 0;     for (int i = head[u]; i + 1; i = E[i].next) {       int v = E[i].to;       int temp = dp[u];       if (low[v] - k <= dep[u]) temp -= dp[v];       ans = max(ans, temp + dfs(v, u));     }     return ans;   }   int main() {     int x;     scanf( %d%d , &n, &k);     memset(head, -1, sizeof head);     for (int i = 2; i <= n; i++) {       scanf( %d , &x);       add(x, i);     }     dfs1(1, 0);     printf( %d n , dfs(1, 0));   }