Breaking news from zombie neurology! It turns out that – contrary to previous beliefs – every zombie is born with a single brain, and only later it evolves into a complicated brain structure. In fact, whenever a zombie consumes a brain, a new brain appears in its nervous system and gets immediately connected to one of the already existing brains using a single brain connector. Researchers are now interested in monitoring the brain latency of a zombie. Your task is to write a program which, given a history of evolution of a zombie's nervous system, computes its brain latency at every stage.

Input

The first line of the input contains one number n – the number of brains in the final nervous system (2 ≤ n ≤ 200000). In the second line a history of zombie's nervous system evolution is given. For convenience, we number all the brains by 1, 2, ..., n in the same order as they appear in the nervous system (the zombie is born with a single brain, number 1, and subsequently brains 2, 3, ..., n are added). The second line contains n - 1 space-separated numbers p2, p3, ..., pn, meaning that after a new brain k is added to the system, it gets connected to a parent-brain <image>.

Output

Output n - 1 space-separated numbers – the brain latencies after the brain number k is added, for k = 2, 3, ..., n.

Example

Input

6
1
2
2
1
5


Output

1 2 2 3 4 
#include <bits/stdc++.h>
using namespace std;
int N;
vector<vector<int> > adjlist;
int A[200005][25], L[200005];
void dfs(int i, int l) {
  L[i] = l;
  for (int j = 0; j < (int)adjlist[i].size(); j++) dfs(adjlist[i][j], l + 1);
}
void precompute() {
  for (int j = 1; j <= 20; j++)
    for (int i = 0; i < N; i++)
      if (A[i][j - 1] != -1)
        A[i][j] = A[A[i][j - 1]][j - 1];
      else
        A[i][j] = -1;
  dfs(0, 0);
}
int lca(int p, int q) {
  if (L[p] < L[q]) swap(p, q);
  for (int i = 20; i >= 0; i--)
    if (L[p] - (1 << i) >= L[q]) p = A[p][i];
  if (p == q) return p;
  for (int i = 20; i >= 0; i--)
    if (A[p][i] != -1 && A[p][i] != A[q][i]) {
      p = A[p][i];
      q = A[q][i];
    }
  return A[p][0];
}
int main() {
  scanf("%d", &N);
  adjlist.assign(N, vector<int>());
  A[0][0] = -1;
  for (int i = 1; i < N; i++) {
    int x;
    scanf("%d", &x);
    adjlist[x - 1].push_back(i);
    A[i][0] = x - 1;
  }
  precompute();
  int ki = 0, ka = 0, diameter = 0;
  for (int i = 1; i < N; i++) {
    int tmp = L[ki] + L[i] - 2 * L[lca(ki, i)];
    if (tmp > diameter) {
      ka = i;
      diameter = tmp;
    }
    tmp = L[ka] + L[i] - 2 * L[lca(ka, i)];
    if (tmp > diameter) {
      ki = i;
      diameter = tmp;
    }
    printf("%d ", diameter);
  }
  puts("");
  return 0;
}
