#include <bits/stdc++.h>
const long long LINF = 1e18;
const int INF = 1e9;
const int M = 1e9 + 7;
const double EPS = 1e-9;
using namespace std;
int n, k;
int a[100100];
int dp[100100];
void f(int s2) {
  int s1 = a[s2];
  if (s1 == 0)
    dp[s2] = min(s2 - 1, k) + 1 + min(n - s2, k);
  else if (s2 - s1 > 2 * k)
    dp[s2] = dp[s1] + k + min(n - s2, k) + 1;
  else if (k < s2 - s1 && s2 - s1 <= 2 * k)
    dp[s2] = dp[s1] + s2 - s1 - k + min(n - s2, k);
  else if (s2 - s1 <= k) {
    dp[s2] = dp[s1] - min(k, n - s1) + s2 - s1 + min(k, n - s2);
  }
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i + 1];
  for (int i = 0; i < n; i++) f(i + 1);
  for (int i = 0; i < n; i++) cout << dp[i + 1] << " ";
  return 0;
}
