#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1), f(n + 1);
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  for (int i = 1; i < n + 1; i++) {
    if (a[i] == 0)
      f[i] = min(i - 1, k) + min(n - i, k) + 1;
    else {
      f[i] = f[a[i]];
      if (a[i] + k < n) f[i] += min(i - a[i], 2 * k + 1) - max(0, k - n + i);
    }
    cout << f[i] << ' ';
  }
}
