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;
using namespace std;
const int rmax = 20;
vector<vector<int> > g;
vector<vector<int> > parent;
vector<int> t_in, t_out;
int timer;
void dfs(int v) {
  t_in[v] = timer++;
  for (int to : g[v]) {
    dfs(to);
  }
  t_out[v] = timer++;
}
bool ancestor(int u, int v) {
  return t_in[u] <= t_in[v] && t_out[u] >= t_out[v];
}
int help(int u, int w) {
  if (u == w) {
    return 0;
  }
  int ans = 0;
  for (int r = rmax - 1; r >= 0; --r) {
    if (!ancestor(parent[u][r], w)) {
      ans += (1 << r);
      u = parent[u][r];
    }
  }
  return ans + 1;
}
int path_len(int u, int v) {
  if (ancestor(u, v)) {
    return help(v, u);
  }
  int old_u = u;
  for (int r = rmax - 1; r >= 0; --r) {
    if (!ancestor(parent[u][r], v)) {
      u = parent[u][r];
    }
  }
  int w = parent[u][0];
  return help(old_u, w) + help(v, w);
}
int main() {
  int n;
  cin >> n;
  g.resize(n);
  parent.resize(n);
  t_in.resize(n), t_out.resize(n);
  for (int i = 0; i < n; ++i) {
    parent[i].resize(rmax);
  }
  parent[0][0] = 0;
  for (int i = 1; i < n; ++i) {
    int p;
    cin >> p;
    --p;
    g[p].push_back(i);
    parent[i][0] = p;
  }
  dfs(0);
  for (int r = 1; r < rmax; ++r) {
    for (int i = 0; i < n; ++i) {
      int t = parent[i][r - 1];
      parent[i][r] = parent[t][r - 1];
    }
  }
  int u = 0, v = 1;
  cout << "1 ";
  int diam = 1;
  for (int i = 2; i < n; ++i) {
    int x = path_len(i, u);
    int y = path_len(i, v);
    if (x > diam) {
      diam = x;
      v = i;
    }
    if (y > diam) {
      diam = y;
      u = i;
    }
    cout << diam << " ";
  }
  cout << "\n";
}
