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;
template <typename T, typename L>
bool smax(T& x, L y) {
  return x < y ? (x = y, true) : false;
}
void pre_dfs(int v, int p);
int f_cen(int v);
int dfs(int v);
int lca(int u, int v);
int get_dist(int v, int u);
void upd(int v);
const int MAXN = 2e5 + 15, LG = 20;
vector<int> adj[MAXN], g[MAXN], sub[MAXN];
vector<pair<int, int>> vec[MAXN];
int par[LG][MAXN];
int sz[MAXN];
int n, mx, cen;
int level[MAXN];
pair<int, int> a[MAXN];
bool mark[MAXN];
int dad[MAXN];
pair<int, int> mx1[MAXN], mx2[MAXN];
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cerr << "HELLO WORLD :)\n";
  cin >> n;
  a[0] = {0, -1};
  for (int i = 1; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
    a[i].first -= 1;
    par[0][a[i].second] = a[i].first;
    g[a[i].first].push_back(a[i].second);
  }
  pre_dfs(0, -1);
  cen = f_cen(0);
  dfs(0);
  dad[cen] = -1;
  memset(mark, 0, sizeof(mark));
  upd(0);
  for (int i = 1; i < n; i++) {
    upd(i);
    cout << mx << ' ';
  }
  return cout << '\n', false;
}
void upd(int v) {
  int p = v;
  mark[v] = true;
  smax(mx, max(0, mx1[v].first) + max(0, mx2[v].first));
  for (int u = dad[v]; ~u; u = dad[u]) {
    int dist = get_dist(v, u);
    if (p == mx1[u].second) {
      smax(mx1[u], make_pair(dist, p));
      if (!mark[u] && mx2[u].first) smax(mx, mx1[u].first + mx2[u].first);
    } else {
      if (dist >= mx1[u].first) {
        mx2[u] = mx1[u];
        mx1[u] = {dist, p};
        if (mx2[u].first && !mark[u]) smax(mx, mx1[u].first + mx2[u].first);
      } else {
        smax(mx2[u], make_pair(dist, p));
        smax(mx, mx1[u].first + mx2[u].first);
      }
    }
    if (mark[u]) smax(mx, max(0, mx1[u].first) + max(0, mx2[u].first));
    p = u;
  }
}
void pre_dfs(int v, int p) {
  sz[v] = 1;
  for (int i = 1; i < LG; i++) par[i][v] = par[i - 1][par[i - 1][v]];
  for (auto u : g[v])
    if (u ^ p) {
      level[u] = level[v] + 1;
      pre_dfs(u, v);
      sz[v] += sz[u];
    }
}
int f_cen(int v) {
  bool flag = 0;
  int ss = sz[v];
  int p = -1;
  while (flag ^= 1)
    for (auto u : g[v])
      if (!mark[u] && u != p && (sz[u] << 1) > ss) {
        p = v;
        v = u;
        flag = 0;
        break;
      }
  return v;
}
int dfs(int v) {
  int root = v;
  v = f_cen(v);
  mark[v] = true;
  int ss = sz[v];
  for (int u = v;; u = par[0][u]) {
    sz[u] -= ss;
    if (u == root) break;
  }
  for (auto u : g[v])
    if (u ^ par[0][v] && !mark[u]) {
      int x = dfs(u);
      adj[v].push_back(x);
      dad[x] = v;
    }
  if (v ^ root) {
    int x = dfs(root);
    adj[v].push_back(x);
    dad[x] = v;
  }
  return v;
}
int lca(int u, int v) {
  if (level[u] < level[v]) swap(u, v);
  int dif = level[u] - level[v];
  for (int i = 0; i < LG; i++)
    if (dif >> i & 1) u = par[i][u];
  if (u == v) return u;
  for (int i = LG - 1; ~i; i--)
    if (par[i][u] != par[i][v]) {
      u = par[i][u];
      v = par[i][v];
    }
  return par[0][v];
}
int get_dist(int v, int u) {
  return level[u] + level[v] - 2 * level[lca(u, v)];
}
