#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5, INF = 1e9;
int n, k;
int a[N];
int dp[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] == 0) {
      dp[i] += min(i, k + 1);
      dp[i] += min(n - i, k);
    } else {
      int l, r;
      int v = a[i];
      int ll, rr;
      l = max(v - k, 1);
      r = min(v + k, n);
      ll = max(i - k, 1);
      rr = min(i + k, n);
      if (ll > r)
        dp[i] = dp[v] + rr - ll + 1;
      else if (r == rr)
        dp[i] = dp[v];
      else if (r == ll)
        dp[i] = dp[v] + rr - ll;
      else
        dp[i] = dp[v] + rr - r;
    }
  }
  for (int i = 1; i <= n; ++i) {
    cout << dp[i] << " ";
  }
}
