#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 2;
int n, k;
int a[maxn], l[maxn], r[maxn], p[maxn], d[maxn];
bool used[maxn];
vector<int> v[maxn];
void fun(int t) {
  used[t] = true;
  if (a[t]) {
    if (!used[a[t]]) {
      fun(a[t]);
    }
    p[t] = p[a[t]];
  } else {
    p[t] = t;
  }
  v[p[t]].push_back(t);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    l[i] = max(i - k, 1);
    r[i] = min(i + k, n);
    fun(i);
  }
  for (int i = 1; i <= n; ++i) {
    if (v[i].size()) {
      d[v[i][0]] = r[v[i][0]] - l[v[i][0]] + 1;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < v[i].size(); ++j) {
      d[v[i][j]] =
          d[a[v[i][j]]] + r[v[i][j]] - max(r[a[v[i][j]]] + 1, l[v[i][j]]) + 1;
    }
  }
  for (int i = 1; i <= n; ++i) {
    cout << d[i] << ' ';
  }
  return 0;
}
