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>
const int INF = 200000000;
using namespace std;
int timer, lg, n;
vector<vector<int> > g;
vector<vector<int> > dp(200005);
int time_in[200005], time_out[200005], parent[200005], a[200005];
void DFS(int, int);
bool issubtree(int, int);
int lca(int, int);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  g.resize(n + 1);
  lg = log2(n + 1);
  for (int k = 0; k <= n; k++) dp[k].resize(lg + 1);
  for (int k = 2; k <= n; k++) {
    int x;
    cin >> x;
    a[k] = x;
    g[x].push_back(k);
    g[k].push_back(x);
  }
  int u = 1;
  int v = 2;
  int dist = 1;
  DFS(1, 0);
  cout << 1 << ' ';
  for (int k = 3; k <= n; k++) {
    int lca1 = lca(u, k);
    int lca2 = lca(v, k);
    if (lca1 > lca2) {
      if (lca1 >= dist) {
        v = k;
        dist = lca1;
      }
    } else {
      if (lca2 >= dist) {
        u = k;
        dist = lca2;
      }
    }
    cout << dist << ' ';
  }
  return 0;
}
void DFS(int v, int p) {
  parent[v] = p;
  dp[v][0] = p;
  for (int k = 1; k <= lg; k++) dp[v][k] = dp[dp[v][k - 1]][k - 1];
  time_in[v] = timer++;
  for (int k = 0; k < g[v].size(); k++) {
    int to = g[v][k];
    if (to == p) continue;
    DFS(to, v);
  }
  time_out[v] = timer++;
}
bool issubtree(int a, int b) {
  if (time_in[a] <= time_in[b] && time_out[b] <= time_out[a]) return 1;
  return 0;
}
int lca(int a, int b) {
  if (issubtree(a, b)) {
    int cnt = 0;
    for (int k = lg; k >= 0; k--) {
      if (dp[b][k] == 0) continue;
      if (issubtree(dp[b][k], a)) continue;
      b = dp[b][k];
      cnt += pow(2, k);
    }
    return cnt + 1;
  }
  if (issubtree(b, a)) {
    int cnt = 0;
    for (int k = lg; k >= 0; k--) {
      if (dp[a][k] == 0) continue;
      if (issubtree(dp[a][k], b)) continue;
      a = dp[a][k];
      cnt += pow(2, k);
    }
    return cnt + 1;
  }
  int cnt = 0;
  int sav = a;
  for (int k = lg; k >= 0; k--) {
    if (dp[a][k] == 0) continue;
    if (issubtree(dp[a][k], b)) continue;
    a = dp[a][k];
    cnt += pow(2, k);
  }
  a = sav;
  for (int k = lg; k >= 0; k--) {
    if (dp[b][k] == 0) continue;
    if (issubtree(dp[b][k], a)) continue;
    b = dp[b][k];
    cnt += pow(2, k);
  }
  return cnt + 2;
}
