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 in[200001], out[200001], p[200001][21], h[200001], timer;
vector<int> g[200001];
void dfs(int cur) {
  in[cur] = ++timer;
  for (int i(0); i < g[cur].size(); ++i) dfs(g[cur][i]);
  out[cur] = ++timer;
}
bool is_A_of(int ver, int A) { return in[A] <= in[ver] && out[A] >= out[ver]; }
int LCA(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  if (is_A_of(u, v)) return v;
  int up(20);
  for (; up && (!p[v][up] || is_A_of(u, p[v][up])); --up)
    ;
  return LCA(u, p[v][up]);
}
int get_dist(int u, int v) { return h[u] + h[v] - 2 * h[LCA(u, v)]; }
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  h[1] = 0;
  int q;
  for (int i(0); i < n - 1; ++i) {
    cin >> q;
    g[q].push_back(i + 2);
    p[i + 2][0] = q;
    h[i + 2] = h[q] + 1;
  }
  dfs(1);
  for (int H(1); H <= 20; ++H)
    for (int i(1); i <= n; ++i) p[i][H] = p[p[i][H - 1]][H - 1];
  int u(1), v(1), dist(0);
  for (int i(2); i <= n; ++i) {
    int dist1(get_dist(i, u)), dist2(get_dist(i, v));
    if (dist1 > dist2) {
      if (dist1 > dist) v = i, dist = dist1;
    } else {
      if (dist2 > dist) u = i, dist = dist2;
    }
    cout << dist << ' ';
  }
}
