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;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(int x) {
  write(x);
  puts("");
}
const int maxn = 200005;
struct edge {
  int link, next;
} e[maxn << 1];
int n, tot, fa[maxn][20], head[maxn], dep[maxn];
inline void add(int u, int v) {
  e[++tot] = (edge){v, head[u]};
  head[u] = tot;
}
inline void insert(int u, int v) {
  add(u, v);
  add(v, u);
}
inline void init() {
  n = read();
  for (int i = 2; i <= n; i++) {
    insert(i, read());
  }
}
inline void dfs(int u, int pre) {
  fa[u][0] = pre;
  dep[u] = dep[pre] + 1;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].link;
    if (v != pre) {
      dfs(v, u);
    }
  }
}
inline void build() {
  for (int j = 1; j <= 18; j++) {
    for (int i = 1; i <= n; i++) {
      fa[i][j] = fa[fa[i][j - 1]][j - 1];
    }
  }
}
inline void pre() {
  dfs(1, 0);
  build();
}
int a, b, len;
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int delta = dep[x] - dep[y];
  for (int i = 0; i <= 18; i++) {
    if (delta & (1 << i)) x = fa[x][i];
  }
  for (int i = 18; i >= 0; i--) {
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  }
  if (x == y)
    return x;
  else
    return fa[x][0];
}
inline void solve() {
  pre();
  writeln(1);
  a = 1;
  b = 2;
  len = 1;
  for (int i = 3; i <= n; i++) {
    int aa = a, bb = b;
    int t1 = lca(a, i), t2 = lca(b, i);
    int s1 = dep[a] + dep[i] - 2 * dep[t1];
    int s2 = dep[b] + dep[i] - 2 * dep[t2];
    if (s1 > len) {
      len = s1;
      a = aa;
      b = i;
    }
    if (s2 > len) {
      len = s2;
      a = i;
      b = bb;
    }
    writeln(len);
  }
}
int main() {
  init();
  solve();
  return 0;
}
