#include <bits/stdc++.h>
using namespace std;
class BChat {
 public:
  int N, K;
  vector<int> ans, R, used;
  vector<vector<int>> G;
  void input(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in >> N >> K;
    ans = vector<int>(N);
    R = vector<int>(N);
    used = vector<int>(N, 0);
    G = vector<vector<int>>(N, vector<int>());
    for (int(i) = (0); (i) < (N); ++(i)) {
      int a;
      in >> a, a--;
      ans[i] = min(N - 1, i + K) - max(0, i - K) + 1;
      R[i] = min(N - 1, i + K);
      if (a > -1) G[i].push_back(a);
    }
  }
  void dfs(int s) {
    used[s] = 1;
    for (auto u : G[s]) {
      if (not used[u]) dfs(u);
      if (s - K <= R[u])
        ans[s] = ans[u] + R[s] - R[u];
      else
        ans[s] += ans[u];
    }
  }
  void solve(std::istream& in, std::ostream& out) {
    input(in, out);
    for (int(i) = (0); (i) < (N); ++(i)) dfs(i);
    for (int(i) = (0); (i) < (N); ++(i)) out << ans[i] << ' ';
    out << '\n';
  }
};
int main() {
  BChat solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
