#include <bits/stdc++.h>
unsigned int messagesCount, viewableMsgsCount;
std::vector<bool> messagesStatus;
std::vector<unsigned int> messages;
std::vector<unsigned int> indexes;
unsigned int count = 0;
void traceMessages(unsigned int);
unsigned int calculateMessages();
int main(void) {
  std::cin >> messagesCount >> viewableMsgsCount;
  messages.resize(messagesCount, false);
  messagesStatus.resize(messagesCount);
  for (unsigned int i = 0; i < messagesCount; ++i) {
    std::cin >> messages[i];
  }
  for (unsigned int i = 0; i < messagesCount; ++i) {
    traceMessages(i);
    std::cout << calculateMessages() << " ";
    count = 0;
  }
  std::cout << std::endl;
  return 0;
}
void traceMessages(unsigned int currentMsgIndex) {
  indexes.push_back(currentMsgIndex);
  if (messages[currentMsgIndex] != 0) {
    traceMessages(messages[currentMsgIndex] - 1);
  }
}
unsigned int calculateMessages() {
  unsigned int messagesSum = 0;
  std::sort(indexes.begin(), indexes.end());
  unsigned int index = indexes.back();
  indexes.pop_back();
  unsigned int right = (index + viewableMsgsCount + 1) > messagesCount
                           ? messagesCount
                           : index + viewableMsgsCount + 1;
  unsigned int left = (index - viewableMsgsCount) > messagesCount
                          ? 0u
                          : index - viewableMsgsCount;
  while (true) {
    messagesSum += right - left;
    if (indexes.empty()) {
      break;
    }
    index = indexes.back();
    indexes.pop_back();
    right = left < (index + viewableMsgsCount + 1)
                ? left
                : index + viewableMsgsCount + 1;
    left = (index - viewableMsgsCount) > messagesCount
               ? 0u
               : index - viewableMsgsCount;
  }
  return messagesSum;
}
