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 MAXN = 2e5 + 22, MOD = 1e9 + 7, MAXL = 22;
int n;
int dp[MAXN][MAXL], dis[MAXN];
vector<int> G[MAXN];
bool mark[MAXN];
void dfs(int v, int u, int d) {
  mark[v] = true;
  dp[v][0] = u;
  dis[v] = d;
  for (int i = 1; i < MAXL; i++) dp[v][i] = dp[dp[v][i - 1]][i - 1];
  for (int i = 0; i < G[v].size(); i++) {
    int w = G[v][i];
    if (!mark[w]) dfs(w, v, d + 1);
  }
}
int par(int v, int x) {
  for (int i = 0; i < MAXL; i++)
    if (x & (1 << i)) v = dp[v][i];
  return v;
}
int LCA(int v, int u) {
  if (dis[v] > dis[u])
    v = par(v, dis[v] - dis[u]);
  else
    u = par(u, dis[u] - dis[v]);
  if (v == u) return u;
  for (int i = MAXL - 1; i >= 0; i--)
    if (dp[v][i] != dp[u][i]) v = dp[v][i], u = dp[u][i];
  return dp[u][0];
}
int fdis(int u, int v) {
  int w = LCA(u, v);
  return dis[u] + dis[v] - 2 * dis[w];
}
void pp() {
  cin >> n;
  for (int i = (1); i <= (n - 1); i++) {
    int x, y = i;
    cin >> x;
    x--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for (int i = (0); i <= (MAXL - 1); i++) dp[0][i] = 0;
  dfs(0, 0, 0);
}
int main() {
  pp();
  int r1, r2, d1, d2, d3;
  for (int i = 1; i < n; i++) {
    if (i == 1)
      r1 = 0, r2 = 1, d1 = 1, d2 = 0, d3 = 0, cout << 1 << " ";
    else {
      d2 = fdis(i, r1);
      d3 = fdis(i, r2);
      if (d1 > max(d2, d3))
        cout << d1 << " ";
      else if (d2 > d3) {
        cout << d2 << " ";
        d1 = d2, r2 = i;
      } else {
        cout << d3 << " ";
        d1 = d3, r1 = i;
      }
    }
  }
  return 0;
}
