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;
template <class T>
inline void umax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void umin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
inline T gcd(T a, T b) {
  return __gcd(a, b);
}
template <class T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
long long modpow(long long a, long long n, long long temp) {
  long long res = 1, y = a;
  while (n > 0) {
    if (n & 1) res = (res * y) % temp;
    y = (y * y) % temp;
    n /= 2;
  }
  return res % temp;
}
long long ison(long long mask, long long pos) { return (mask & (1 << pos)); }
long long cbit(long long n) {
  long long k = 0;
  while (n) n &= (n - 1), k++;
  return k;
}
long long nbit(long long n) {
  long long k = 0;
  while (n) n /= 2, k++;
  return k;
}
long long mod = 1e9 + 7;
int sgn(long long x) { return x < 0 ? -1 : !!x; }
const double eps = 1e-7;
const double pi = acos(-1.0);
inline void inc(long long &x, long long y) {
  x += y;
  if (x >= mod) x -= mod;
}
inline void dec(long long &x, long long y) {
  x -= y;
  if (x < 0) x += mod;
}
inline void chmax(long long &x, long long y) {
  if (y > x) x = y;
}
inline void mulm(long long &x, long long y) {
  x *= y;
  if (x >= mod) x -= mod;
}
long long xo(long long i) {
  if ((i & 3) == 0) return i;
  if ((i & 3) == 1) return 1;
  if ((i & 3) == 2) return i + 1;
  return 0;
}
long long anc[20][200005], d[200005];
long long lca(long long a, long long b) {
  if (d[a] > d[b]) swap(a, b);
  long long diff = d[b] - d[a];
  for (long long i = 0; i < 20; i++)
    if (diff & (1ll << i)) b = anc[i][b];
  for (long long i = 19; i >= 0; i--) {
    if (anc[i][a] != anc[i][b]) a = anc[i][a], b = anc[i][b];
  }
  if (a == b) return a;
  return anc[0][a];
}
long long dist(long long a, long long b) {
  long long l = lca(a, b);
  return d[a] + d[b] - 2 * d[l];
}
int main() {
  long long i, j, k, l, m, n;
  cin >> n;
  for (i = 2; i <= n; i++) cin >> anc[0][i];
  for (i = 1; i < 20; i++) {
    for (j = 1; j <= n; j++) {
      anc[i][j] = anc[i - 1][anc[i - 1][j]];
    }
  }
  for (i = 2; i <= n; i++) d[i] = d[anc[0][i]] + 1;
  long long a = 1, b = 1, c = 0;
  for (i = 2; i <= n; i++) {
    long long ta = dist(a, i);
    long long tb = dist(b, i);
    if (ta > c)
      b = i, c = ta;
    else if (tb > c)
      a = i, c = tb;
    cout << c << " ";
  }
}
