func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 100;   int ans[N], link[N];   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       int down = max(1, i - k);       int up = min(n, i + k);       int down2 = max(1, x - k);       int up2 = min(n, x + k);       if (x == 0) {         ans[i] = up - down + 1 + ans[x];       } else {         if (up2 < down)           ans[i] = up - down + 1 + ans[x];         else           ans[i] = up - down + 1 + ans[x] - (up2 - down + 1);       }       cout << ans[i] <<    ;     }     return 0;   }   