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 long long N = 2e5 + 100, mod = 1e9 + 7, sz = 400, inf = 1e9, lg = 20;
long long h[N], d[N][lg];
long long c1 = 0, c2 = 1, ans = 0;
long long lca(long long a, long long b) {
  while (h[a] > h[b]) {
    for (long long i = lg - 1; i >= 0; i--) {
      if (h[d[a][i]] <= h[b]) continue;
      a = d[a][i];
    }
    a = d[a][0];
  }
  while (h[a] < h[b]) {
    for (long long i = lg - 1; i >= 0; i--) {
      if (h[d[b][i]] <= h[a]) continue;
      b = d[b][i];
    }
    b = d[b][0];
  }
  if (a == b) return a;
  for (long long i = lg - 1; i >= 0; i--) {
    if (d[a][i] == d[b][i]) continue;
    a = d[a][i];
    b = d[b][i];
  }
  return d[a][0];
}
long long len(long long a, long long b) {
  return h[a] + h[b] - 2 * h[lca(a, b)];
}
void upd(long long a, long long b) {
  long long l = len(a, b);
  if (l > ans) {
    ans = l;
    c1 = a;
    c2 = b;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long p;
    cin >> p;
    p--;
    h[i] = h[p] + 1;
    d[i][0] = p;
    for (long long k = 1; k < lg; k++) d[i][k] = d[d[i][k - 1]][k - 1];
    upd(i, c1);
    upd(i, c2);
    cout << ans << ' ';
  }
}
