#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, k;
  cin >> n >> k;
  long long a[n + 3], val[n + 3];
  for (int i = int(1); i <= int(n); i++) cin >> a[i];
  long long cur = k + 1, hg = min(n, 2 * k + 1);
  for (int i = int(1); i <= int(n); i++) {
    val[i] = min(cur, hg);
    cur++;
  }
  cur = k + 1;
  for (int i = n; i > 0; i--) {
    val[i] = min(val[i], min(cur, hg));
    cur++;
  }
  for (int i = int(1); i <= int(n); i++) {
    if (a[i] == 0) continue;
    val[i] += val[a[i]];
    int l = max(1ll, i - k), r = min(n, a[i] + k);
    if (l <= r) val[i] -= r - l + 1;
  }
  for (int i = int(1); i <= int(n); i++) cout << val[i] << " ";
}
