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;
vector<vector<int>> st;
vector<int> dep, mxd;
int a, lg;
int lca(int x, int y) {
  int dx = dep[x], dy = dep[y];
  for (; abs(dx - dy) > 0;) {
    int k = mxd[abs(dx - dy)];
    if (dx > dy) {
      dx -= 1 << k;
      x = st[k][x];
    } else {
      dy -= 1 << k;
      y = st[k][y];
    }
  }
  for (int k = mxd[dep[x]]; x != y; k = abs(k - 1)) {
    if (st[k][x] != st[k][y] || k == 0) {
      x = st[k][x];
      y = st[k][y];
    }
  }
  return x;
}
int dist(int x, int y) { return dep[x] + dep[y] - 2 * dep[lca(x, y)]; }
int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  ;
  cin >> a;
  lg = ceil(log2(a));
  mxd = vector<int>(250000);
  mxd[2] = 1;
  for (int q = 3; q < 250000; q++)
    mxd[q] = 2 << mxd[q - 1] > q ? mxd[q - 1] : mxd[q - 1] + 1;
  int v1 = 0, v2 = 1, d = 1;
  st = vector<vector<int>>(lg, vector<int>(a));
  dep = vector<int>(a);
  vector<int> vr(a);
  dep[0] = 1;
  for (int q = 0; q < lg; q++) st[q][0] = -1;
  for (int q = 0; q < a - 1; q++) {
    int x = q + 1, p;
    cin >> p;
    p--;
    st[0][x] = p;
    vr.push_back(p);
    dep[x] = dep[p] + 1;
  }
  for (int q = 1; q < lg; q++)
    for (int w = 1; w < a; w++)
      st[q][w] = 1 << q >= dep[w] ? -1 : st[q - 1][st[q - 1][w]];
  cout << 1 << " ";
  for (int q = 1; q < a - 1; q++) {
    int x = q + 1, p = vr[q];
    if (q == 0) continue;
    if (dist(v1, x) > d) {
      d++;
      v2 = x;
    } else if (dist(v2, x) > d) {
      d++;
      v1 = x;
    }
    cout << d << " ";
  }
}
