#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, j, buf, j1;
  cin >> n >> k;
  vector<int> vec(n + 1);
  vector<int> ans(n + 1);
  for (int i = 1; i <= n; i++) cin >> vec[i];
  for (int i = 1; i <= n; i++) {
    buf = n + 1;
    j = i;
    while ((vec[j] != j) && (vec[j] != 0)) {
      if (min(buf - j - 1, k) + min(k, j - 1) + 1 > 0)
        ans[i] += min(buf - j - 1, k) + min(k, j - 1) + 1;
      buf = j - k;
      j = vec[j];
    }
    if (min(buf - j - 1, k) + min(k, j - 1) + 1 > 0)
      ans[i] += min(buf - j - 1, k) + min(k, j - 1) + 1;
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
