#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, l, r, z;
  cin >> n >> k;
  int *a = new int[n];
  int *b = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = 0;
    if (a[i] == 0) b[i] = i - max(0, i - k) + 1 + min(n - 1, i + k) - i;
  }
  for (int i = 0; i < n; i++) {
    if (b[i] == 0)
      if (a[i] + k < i - k)
        b[i] = b[a[i] - 1] + i - max(0, i - k) + 1 + min(n - 1, i + k) - i;
      else {
        int l1 = max(0, a[i] - 1 - k), l2 = max(0, i - k);
        int r1 = min(n - 1, a[i] - 1 + k), r2 = min(n - 1, i + k);
        if (r1 < i) b[i] = b[a[i] - 1] + i - r1 + r2 - i;
        if (r1 == i) b[i] = b[a[i] - 1] + i - r1 + r2 - i;
        if (r1 > i) {
          b[i] = b[a[i] - 1] + r2 - r1;
        }
      }
  }
  for (int i = 0; i < n; i++) cout << b[i] << endl;
}
