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;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 1;
vector<vector<int> > G(MAXN);
int P[MAXN][21], level[MAXN];
void DFS(int v, int pr = -1) {
  P[v][0] = pr;
  for (auto to : G[v]) {
    if (to != pr) {
      level[to] = level[v] + 1;
      DFS(to, v);
    }
  }
}
int kth(int a, int k) {
  while (k > 0) {
    int t = log2(k);
    k = k - (1 << t);
    a = P[a][t];
  }
  return a;
}
int LCA(int u, int v) {
  if (level[u] < level[v]) swap(u, v);
  u = kth(u, level[u] - level[v]);
  if (u == v) return u;
  for (int i = 20; i >= 0; i--) {
    if (P[u][i] != P[v][i]) {
      u = P[u][i];
      v = P[v][i];
    }
  }
  return P[u][0];
}
int get_len(int u, int v) { return level[u] + level[v] - 2 * level[LCA(u, v)]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  std::cin >> N;
  int a[N + 1];
  for (int i = 2; i <= N; i++) {
    cin >> a[i];
    G[i].push_back(a[i]);
    G[a[i]].push_back(i);
  }
  DFS(1);
  for (int j = 1; j <= 20; j++) {
    for (int i = 1; i <= N; i++) {
      if (P[i][j - 1] == -1)
        P[i][j] = -1;
      else
        P[i][j] = P[P[i][j - 1]][j - 1];
    }
  }
  int l = 1, r = 2, ans = 1;
  cout << ans << ' ';
  for (int i = 3; i <= N; i++) {
    int len = get_len(l, i);
    if (len > ans) {
      r = i;
      ++ans;
    } else {
      len = get_len(r, i);
      if (len > ans) {
        l = i;
        ++ans;
      }
    }
    cout << ans << ' ';
  }
  return 0;
}
