#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int pw[2] = {(int)1e7 + 19, (int)1e7 + 79};
const int maxn = 1e6 + 88;
const int inf = 2e9 + 88;
const int logn = 22;
const int maxa = 3e6 + 88;
const int block = 1300;
const long long infll = 1e18 + 88;
const char sgl[5] = {'a', 'e', 'i', 'o', 'u'};
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int knightx[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int knighty[] = {-1, 1, -2, 2, -2, 2, -1, 1};
const int kingx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int kingy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const char sep = 'a' - 1;
const double eps = 1e-9;
const int maxn1 = 1e3 + 88;
vector<int> g[maxn];
int r[maxn], cnt[maxn], a[maxn];
int n, k;
void calc(int v, int p) {
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    r[to] = min(to + k, n);
    cnt[to] = cnt[v] + r[to] - max(r[v], to - k - 1);
    calc(to, v);
  }
}
bool solve() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int i, j, x, y, l;
  cin >> n >> k;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) g[a[i]].push_back(i + 1);
  r[0] = 0, cnt[0] = 0;
  calc(0, 0);
  for (i = 1; i <= n; i++) cout << cnt[i] << " ";
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
