func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, k;   const int maxn = 1e5 + 10;   stack<int> max_seen;   int ans[maxn];   vector<int> to[maxn];   void calc(int a) {     int s = max(a - k, 0), t = min(n, a + k + 1);     if (max_seen.empty())       ans[a] += t - s;     else       ans[a] += t - max(max_seen.top(), s);     max_seen.push(t);     for (int i = 0; i < to[a].size(); i++) {       ans[to[a][i]] = ans[a];       calc(to[a][i]);     }     max_seen.pop();   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x > 0) to[x - 1].push_back(i);     }     for (int i = 0; i < n; i++)       if (ans[i] == 0) calc(i);     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }   