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 MAX_N = 200030;
int ans[20][MAX_N], h[MAX_N];
int v1, v2;
int lca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  int l;
  for (l = 1; 1 << l <= h[u]; l++)
    ;
  l--;
  for (int i = l; i >= 0; i--)
    if (h[u] - (1 << i) >= h[v]) u = ans[i][u];
  if (u == v) return u;
  for (int i = l; i >= 0; i--)
    if (ans[i][u] != -1 && ans[i][u] != ans[i][v]) {
      u = ans[i][u];
      v = ans[i][v];
    }
  return ans[0][u];
}
int main() {
  int n, v;
  cin >> n;
  h[0] = 0;
  for (int i = 0; i < 20; i++)
    for (int j = 0; j < n; j++) ans[i][j] = -1;
  v1 = v2 = 0;
  int best = -1;
  for (int u = 1; u < n; u++) {
    int v;
    cin >> v;
    v--;
    ans[0][u] = v;
    h[u] = h[v] + 1;
    for (int i = 1; i < 20; i++)
      if (ans[i - 1][u] != -1) ans[i][u] = ans[i - 1][ans[i - 1][u]];
    int a1 = lca(v1, u), a2 = lca(v2, u);
    int d1 = h[u] - h[a1] + h[v1] - h[a1];
    int d2 = h[u] - h[a2] + h[v2] - h[a2];
    if (d1 > best) {
      v2 = u;
      best = d1;
    }
    if (d2 > best) {
      v1 = u;
      best = d2;
    }
    cout << (u == 1 ? "" : " ") << best;
  }
  cout << endl;
}
