#include <bits/stdc++.h>
using namespace std;
long long n, k, z, a[100001];
long long vich(long long p, long long par) {
  long long l = 0, r = 0, zx = 0;
  if (p == 0) return 0;
  if (par != 0) {
    l = p;
    r = par;
    if (r - l > k * 2) {
      if ((p - 1) >= k)
        zx += k;
      else
        zx += p - 1;
      if ((n - p) >= k)
        zx += k;
      else
        zx += n - p;
      return zx + 1;
    } else if (r - l == k * 2) {
      if ((p - 1) >= k)
        zx += k;
      else
        zx += p - 1;
      if ((n - p) >= k)
        zx += k;
      else
        zx += n - p;
      return zx;
    } else if (r - l < k * 2) {
      long long c1 = 0, c2 = 0;
      c1 = p - k;
      if (c1 < 1) c1 = 1;
      c2 = par - k;
      if (c2 < 1) c2 = 1;
      zx += c2 - c1;
      return zx;
    }
  } else {
    if ((p - 1) >= k)
      zx += k;
    else
      zx += p - 1;
    if ((n - p) >= k)
      zx += k;
    else
      zx += n - p;
    return zx + 1;
  }
}
long long funk(long long x, long long c, long long par) {
  if (x == 0) return c;
  if (par == x) return c + vich(x, par);
  funk(a[x], c + vich(a[x], x), x);
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0)
      cout << vich(i, 0) << " ";
    else {
      z = funk(i, vich(i, 0), 0);
      cout << z << " ";
    }
  }
}
