#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> my_messages;
  vector<int> weight;
  int n, k, temp;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    my_messages.push_back(temp - 1);
    weight.push_back(-1);
  }
  for (int i = 0; i < n; i++) {
    if (my_messages[i] == -1) {
      weight[i] = (n - 1 < i + k ? n - 1 : i + k) - (0 > i - k ? 0 : i - k) + 1;
    } else {
      if (i - my_messages[i] <= k) {
        weight[i] =
            weight[my_messages[i]] + (n - 1 - i < k ? n - 1 - i : k) -
            (k - (i - my_messages[i]) < n - 1 - i ? k - (i - my_messages[i])
                                                  : n - 1 - i);
      } else if (i - my_messages[i] <= 2 * k) {
        weight[i] = weight[my_messages[i]] + (n - 1 - i < k ? n - 1 - i : k) +
                    ((i - my_messages[i]) - k);
      } else {
        weight[i] = weight[my_messages[i]] + ((n - 1 < i + k ? n - 1 : i + k) -
                                              (0 > i - k ? 0 : i - k) + 1);
      }
    }
  }
  for (int j : weight) {
    cout << j << " ";
  }
  cout << endl;
  cin.ignore();
  cin.ignore();
  cin.ignore();
  cin.ignore();
}
