When Adam gets a rooted tree (connected non-directed graph without cycles), he immediately starts coloring it. More formally, he assigns a color to each edge of the tree so that it meets the following two conditions: 

  * There is no vertex that has more than two incident edges painted the same color. 
  * For any two vertexes that have incident edges painted the same color (say, c), the path between them consists of the edges of the color c. 



Not all tree paintings are equally good for Adam. Let's consider the path from some vertex to the root. Let's call the number of distinct colors on this path the cost of the vertex. The cost of the tree's coloring will be the maximum cost among all the vertexes. Help Adam determine the minimum possible cost of painting the tree. 

Initially, Adam's tree consists of a single vertex that has number one and is the root. In one move Adam adds a new vertex to the already existing one, the new vertex gets the number equal to the minimum positive available integer. After each operation you need to calculate the minimum cost of coloring the resulting tree.

Input

The first line contains integer n (1 ≤ n ≤ 106) — the number of times a new vertex is added. The second line contains n numbers pi (1 ≤ pi ≤ i) — the numbers of the vertexes to which we add another vertex. 

Output

Print n integers — the minimum costs of the tree painting after each addition. 

Examples

Input

11
1 1 1 3 4 4 7 3 7 6 6


Output

1 1 1 1 1 2 2 2 2 2 3 

Note

The figure below shows one of the possible variants to paint a tree from the sample at the last moment. The cost of the vertexes with numbers 11 and 12 equals 3.

<image>
#include <bits/stdc++.h>
int _max(int x, int y) { return x > y ? x : y; }
int n;
int f[1002000], dp[1002000], ma[1002000], sec[1002000];
bool Update(int x) {
  int o = dp[x], pos = 0;
  if (ma[f[x]] == dp[x]) pos = 1;
  dp[x] = _max(ma[x], sec[x] + 1);
  if (pos == 0) {
    if (ma[f[x]] <= dp[x])
      sec[f[x]] = ma[f[x]], ma[f[x]] = dp[x];
    else if (sec[f[x]] <= dp[x])
      sec[f[x]] = dp[x];
  } else
    ma[f[x]] = dp[x];
  if (dp[x] == o)
    return 0;
  else
    return 1;
}
void gi(int &x) {
  char ch = getchar();
  x = 0;
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
}
void pi(int x) {
  if (x > 9) pi(x / 10);
  putchar(x % 10 + 48);
}
int main() {
  gi(n);
  n++;
  for (int i = 2; i <= n; i++) {
    gi(f[i]);
    dp[i] = 1;
    if (dp[i] > ma[f[i]])
      sec[f[i]] = ma[f[i]], ma[f[i]] = dp[i];
    else if (dp[i] > sec[f[i]])
      sec[f[i]] = dp[i];
    Update(i);
    for (int j = f[i]; j; j = f[j])
      if (!Update(j)) break;
    pi(ma[1]);
    putchar(' ');
  }
  return 0;
}
