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 int64_t INF = 1e9, MOD = 1e9 + 7, MAXN = 2 * 1e5 + 5, MAXL = 18;
const long double EPS = 1e-9, PI = acos(-1);
int64_t timer = 0, lg = 1;
vector<int64_t> tin(MAXN), tout(MAXN), height(MAXN);
vector<vector<int64_t>> up(MAXN, vector<int64_t>(MAXL));
void dfs(int64_t vert, const vector<vector<int64_t>> &graph, int64_t par = 0,
         int64_t h = 0) {
  tin[vert] = ++timer;
  height[vert] = h;
  up[vert][0] = par;
  for (int64_t i = 1; i <= lg; ++i) up[vert][i] = up[up[vert][i - 1]][i - 1];
  for (int64_t elem : graph[vert])
    if (elem != par) dfs(elem, graph, vert, h + 1);
  tout[vert] = ++timer;
}
bool upper(int64_t a, int64_t b) {
  return tin[a] <= tin[b] && tout[b] <= tout[a];
}
int64_t lca(int64_t a, int64_t b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int64_t i = lg; i > -1; --i)
    if (!upper(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
int64_t way(int64_t a, int64_t b) {
  int64_t c = lca(a, b);
  return height[a] + height[b] - 2 * height[c];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int64_t n;
  cin >> n;
  vector<vector<int64_t>> graph(n);
  for (int64_t i = 1; i < n; ++i) {
    int64_t par;
    cin >> par;
    graph[par - 1].push_back(i);
  }
  while ((1 << lg) <= n) lg++;
  dfs(0, graph);
  pair<int64_t, int64_t> cur_diam(0, 1);
  vector<int64_t> answer;
  int64_t cur_dist = 1;
  answer.push_back(cur_dist);
  for (int64_t i = 2; i < n; ++i) {
    int64_t first = way(cur_diam.first, i), second = way(cur_diam.second, i);
    if (first > cur_dist) {
      cur_diam = make_pair(cur_diam.first, i);
      cur_dist = first;
    }
    if (second > cur_dist) {
      cur_diam = make_pair(cur_diam.second, i);
      cur_dist = second;
    }
    answer.push_back(cur_dist);
  }
  for (int64_t elem : answer) cout << elem << " ";
  return 0;
}
