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;
vector<int> adj[202020];
int n, q, ans, danc[202020][20], dist[202020], jav[202020], nivel[202020],
    anc[202020][20], pai[202020], av[202020][2], af[202020][2];
int lca(int v, int u) {
  if (nivel[u] < nivel[v]) swap(v, u);
  for (int(i) = (19); (i) >= (0); (i)--)
    if (nivel[u] - (1 << i) >= nivel[v]) u = anc[u][i];
  if (u == v) return u;
  for (int(i) = (19); (i) >= (0); (i)--)
    if (anc[u][i] != anc[v][i]) u = anc[u][i], v = anc[v][i];
  return anc[u][0];
}
int setdist(int v, int p) {
  dist[v] = 1;
  for (int(i) = (0); (i) < (((int)(adj[v]).size())); (i)++)
    if (adj[v][i] != p && !jav[adj[v][i]]) dist[v] += setdist(adj[v][i], v);
  return dist[v];
}
int setcentro(int v, int p, int tam) {
  for (int(i) = (0); (i) < (((int)(adj[v]).size())); (i)++)
    if (adj[v][i] != p && !jav[adj[v][i]] && dist[adj[v][i]] > tam / 2)
      return setcentro(adj[v][i], v, tam);
  return v;
}
int decomposition(int r) {
  r = setcentro(r, r, setdist(r, r));
  jav[r] = 1;
  for (int(i) = (0); (i) < (((int)(adj[r]).size())); (i)++)
    if (!jav[adj[r][i]]) pai[decomposition(adj[r][i])] = r;
  return r;
}
void dfs(int v, int pai) {
  for (int(i) = (0); (i) < (((int)(adj[v]).size())); (i)++)
    if (adj[v][i] != pai) {
      int p = adj[v][i];
      nivel[p] = nivel[v] + 1, anc[p][0] = v;
      for (int(j) = (1); (j) < (20); (j)++)
        anc[p][j] = anc[anc[p][j - 1]][j - 1];
      dfs(p, v);
    }
}
void upd(int v) {
  ans = max(ans, av[v][0]);
  int r = v, ult = r, i = 0;
  v = pai[v];
  while (v != -1) {
    int pv = av[v][1], pf = af[v][1], nv = danc[r][i];
    if (av[v][1] < nv) av[v][1] = nv, af[v][1] = ult;
    if (av[v][0] < av[v][1]) swap(av[v][0], av[v][1]), swap(af[v][0], af[v][1]);
    if (af[v][0] == af[v][1]) af[v][1] = pf, av[v][1] = pv;
    if (af[v][0] != -1 && v <= r && af[v][0] != ult)
      ans = max(ans, nv + av[v][0]);
    else if (v <= r && af[v][1] != -1)
      ans = max(ans, nv + av[v][1]);
    else if (v <= r)
      ans = max(ans, nv);
    ult = v;
    v = pai[v], i++;
  }
}
void distancias(int v) {
  int r = v, i = 0;
  v = pai[v];
  while (v != -1) {
    danc[r][i] = nivel[v] + nivel[r] - 2 * nivel[lca(v, r)];
    i++, v = pai[v];
  }
}
int main() {
  memset(af, -1, sizeof(af));
  memset(av, -1, sizeof(av));
  scanf("%d", &n);
  if (n == 2) {
    cout << 1;
    return 0;
  }
  for (int(i) = (1); (i) < (n); (i)++) {
    int a;
    scanf("%d", &a);
    a--;
    adj[i].push_back(a);
    adj[a].push_back(i);
  }
  dfs(0, 0);
  pai[decomposition(0)] = -1;
  for (int(i) = (0); (i) < (n); (i)++) distancias(i);
  upd(0);
  upd(1);
  upd(2);
  printf("1 2 ");
  for (int(i) = (3); (i) < (n); (i)++) {
    upd(i);
    printf("%d ", ans);
  }
}
