#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const long long inf = 0x3f3f3f3f;
const long long INFF = 1e18 + 5;
const long long INF = 1e9;
const long long MX = 2e6 + 5;
const long long MXL = 105;
const long long mod = 1e9 + 7;
const double ERROR = 1e-7;
long long n, k, arr[MX], dp[MX], l, r;
vector<long long> v[MX];
void solve() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  for (long long i = 1; i <= n; i++) {
    if (!arr[i]) {
      dp[i] = min(i - 1, k) + min(n - i, k) + 1;
      cout << dp[i] << " ";
      continue;
    }
    dp[i] = dp[arr[i]] + min(min(n - i, k) + min(i - 1, k) + 1,
                             min(n, i + k) - min(n, arr[i] + k));
    cout << dp[i] << " ";
  }
  cout << "\n";
}
int32_t main() { solve(); }
