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 int N = 2e5 + 10;
int n, f[N][20], u, v, d[N], tin[N], tout[N], timer, vmax;
vector<int> ke[N];
void dfs(int u) {
  tin[u] = ++timer;
  for (int j = 1; j <= vmax; j++) f[u][j] = f[f[u][j - 1]][j - 1];
  for (auto v = ke[u].begin(); v != ke[u].end(); v++) {
    if (f[*v][0] == 0) {
      f[*v][0] = u;
      d[*v] = d[u] + 1;
      dfs(*v);
    }
  }
  tout[u] = ++timer;
}
bool check(int u, int v) { return (tin[u] <= tin[v] && tout[u] >= tout[v]); }
int lca(int u, int v) {
  if (check(u, v)) return u;
  if (check(v, u)) return v;
  for (int j = vmax; j >= 0; j--)
    if (!check(f[u][j], v)) u = f[u][j];
  return f[u][0];
}
int dis(int u, int v) {
  int pp = lca(u, v);
  return d[u] + d[v] - 2 * d[pp];
}
int main() {
  cin >> n;
  u = v = 1;
  vmax = int(log(n) / log(2));
  f[1][0] = 1;
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    ke[i].push_back(p);
    ke[p].push_back(i);
  }
  dfs(1);
  for (int w = 2; w <= n; w++) {
    if (dis(u, w) < dis(v, w)) swap(u, v);
    if (dis(u, v) < dis(u, w)) v = w;
    cout << dis(u, v) << ' ';
  }
}
