#include <bits/stdc++.h>
using namespace std;
int jopa(int x, int y);
int n, k;
vector<int> D, A;
int main() {
  cin >> n >> k;
  D.assign(n, -1);
  A.assign(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    A[i]--;
  }
  for (int i = 0; i < n; i++) {
    if (D[i] == -1) D[i] = jopa(i, -2);
    cout << D[i] << " ";
  }
}
int jopa(int x, int y) {
  int ans = 0;
  ans += 1 + 2 * k;
  ans -= max(k - x, 0);
  ans -= max(k - (n - 1 - x), 0);
  if (y != -2) ans -= max((x + k) - (y - k) + 1, 0);
  if (A[x] != -1) {
    if (D[A[x]] == -1) {
      ans += jopa(A[x], x);
    } else {
      ans += D[A[x]];
      y = x;
      x = A[x];
      ans -= max(min((x + k), n - 1) - max((y - k), 0) + 1, 0);
      x = y;
    }
  }
  D[x] = ans;
  return ans;
}
