#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 7;
int n, k, a[MAX], dp[MAX];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  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] = 1 + min(k, i - 1) + min(k, n - i);
    } else {
      int prev = a[i];
      if (prev + k >= i) {
        dp[i] = dp[prev];
        dp[i] += min(min(i + k, n) - min(prev + k, n), n - i);
      } else {
        if (prev + k < i - k) {
          dp[i] = dp[prev] + 1 + min(k, i - 1);
        } else {
          dp[i] = dp[prev] + 1 + min(k - ((prev + k) - (i - k) + 1), i - 1);
        }
        dp[i] += min(k, n - i);
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    cout << dp[i] << " ";
  }
  cout << "\n";
  return 0;
}
