#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> g, ans;
string used;
vector<vector<int> > gt;
void dfs(int x, int sum, int l) {
  if (x == -1) return;
  used[x] = 1;
  l = max(l, x - k);
  int r = min(n - 1, x + k);
  sum += r - l + 1;
  ans[x] = sum;
  for (int(i) = (0); (i) < ((int((gt[x]).size()))); (i)++) {
    int to = gt[x][i];
    dfs(to, sum, r + 1);
  }
}
void solve() {
  cin >> n >> k;
  ans.assign(n, 0);
  used.assign(n, 0);
  g.assign(n, 0);
  for (int(i) = (0); (i) < (n); (i)++) {
    cin >> g[i];
    g[i]--;
  }
  gt.resize(n);
  for (int(i) = (0); (i) < (n); (i)++) {
    if (g[i] == -1) continue;
    gt[g[i]].push_back(i);
  }
  for (int(i) = (0); (i) < (n); (i)++) {
    if (used[i]) continue;
    dfs(i, 0, 0);
  }
  for (int(i) = (0); (i) < (n); (i)++) {
    cout << ans[i] << " ";
  }
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0);
  solve();
  return 0;
}
