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;
int arr[200005], n;
vector<int> adj[200005];
int lvl[200005], par[200005], table[200005][25];
void dfs(int u, int p) {
  if (u == 1)
    lvl[u] = 0;
  else
    lvl[u] = lvl[p] + 1;
  par[u] = p;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v != p) dfs(v, u);
  }
}
void pre() {
  memset(table, -1, sizeof table);
  for (int i = 1; i <= n; i++) table[i][0] = par[i];
  for (int j = 1; j < 25; j++) {
    for (int i = 1; i <= n; i++) {
      if (table[i][j - 1] != -1) table[i][j] = table[table[i][j - 1]][j - 1];
    }
  }
}
int query(int u, int v) {
  if (u == v) return 0;
  if (lvl[u] > lvl[v]) swap(u, v);
  int diff = lvl[v] - lvl[u];
  int ans = 0;
  for (int i = 0; i < 25; i++) {
    if (diff & (1 << i)) {
      ans += (1 << i);
      v = table[v][i];
    }
  }
  if (u == v) return ans;
  for (int i = 25 - 1; i >= 0; i--) {
    if (table[u][i] != -1 && (table[u][i] != table[v][i])) {
      u = table[u][i];
      v = table[v][i];
      ans += 2 * (1 << i);
    }
  }
  ans += 2;
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int v, u = i;
    scanf("%d", &v);
    arr[i] = v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, -1);
  pre();
  pair<int, int> P = make_pair(1, 1);
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    int u = P.first, v = P.second, w = i;
    int d1 = query(u, w);
    if (d1 > ans) {
      ans = d1;
      P = make_pair(u, w);
    }
    int d2 = query(v, w);
    if (d2 > ans) {
      ans = d2;
      P = make_pair(v, w);
    }
    int d3 = query(u, v);
    if (d3 > ans) {
      ans = d3;
      P = make_pair(u, v);
    }
    printf("%d ", ans);
  }
}
