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 h[500000];
int jump[300000][21];
int n;
int lca(int x, int y) {
  if (h[x] < h[y]) swap(x, y);
  for (int i = 20; i >= 0; i--) {
    int to = jump[x][i];
    if (to == 0) continue;
    if (h[to] < h[y]) continue;
    x = to;
  }
  if (x == y) return x;
  for (int i = 20; i >= 0; i--) {
    int to = jump[x][i];
    int too = jump[y][i];
    if (to == too) continue;
    x = to;
    y = too;
  }
  return jump[x][0];
}
void add(int x, int y) {
  jump[x][0] = y;
  for (int i = 1; i <= 20; i++) jump[x][i] = jump[jump[x][i - 1]][i - 1];
  h[x] = 1 + h[y];
}
int dist(int x, int y) {
  int kek = lca(x, y);
  return h[x] + h[y] - h[kek] - h[kek];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int curd1 = 1;
  int curd2 = 1;
  h[1] = 1;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    add(i, x);
    x = i;
    int cd1 = dist(curd1, curd2);
    int cd2 = dist(curd1, x);
    int cd3 = dist(curd2, x);
    if (cd1 >= cd2 && cd1 >= cd3) {
      cout << cd1 << " ";
      continue;
    }
    if (cd3 > cd2) {
      cout << cd3 << " ";
      curd1 = curd2;
      curd2 = x;
    } else {
      cout << cd2 << " ";
      curd2 = x;
    }
  }
}
