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>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <class T>
int sgn(T x) {
  return x > 0 ? 1 : (x < 0 ? -1 : 0);
}
const long double pi = 2 * asinl((long double)1.0);
int n;
int m;
const int N = 2e5 + 10;
vector<int> v[N];
int h[N], t[2 * N], f[8 * N], tout[N], p[N], ct;
int build(int x, int lc, int rc) {
  if (lc == rc) return f[x] = t[lc];
  int m = (lc + rc) / 2;
  return f[x] = min(build(2 * x + 1, lc, m), build(2 * x + 2, m + 1, rc));
}
int get(int x, int lc, int rc, int l, int r) {
  if (lc > r || rc < l) return 1e9;
  if (lc >= l && rc <= r) return f[x];
  int m = (lc + rc) / 2;
  return min(get(2 * x + 1, lc, m, l, r), get(2 * x + 2, m + 1, rc, l, r));
}
int lca2(int x, int y) {
  int l = tout[x], r = tout[y];
  if (l > r) swap(l, r);
  r--;
  return get(0, 0, ct - 1, l, r);
}
pair<int, int> dist(int x, int y) {
  if (x == y) return make_pair(0, -1);
  int res = lca2(x, y);
  return make_pair(h[x] + h[y] - 2 * h[p[res]], res);
}
void go(int x, int h) {
  ::h[x] = h;
  for (auto y : v[x]) {
    go(y, h + 1);
  }
  tout[x] = ct;
  t[ct++] = x;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d", &p[i]);
    p[i]--;
    v[p[i]].push_back(i);
  }
  go(0, 0);
  build(0, 0, ct - 1);
  vector<int> center = {0};
  int r = 0;
  for (int i = 1; i < n; i++) {
    pair<pair<int, int>, int> res = {{1e9, 0}, 0};
    for (auto y : center) {
      res = min(make_pair(dist(i, y), y), res);
    }
    if (res.first.first > r && ((int)center.size()) == 2) {
      center = {res.second};
      r = res.first.first;
    } else if (res.first.first > r && ((int)center.size()) == 1) {
      if (p[res.first.second] != res.second) {
        center.push_back(p[res.second]);
      } else {
        center.push_back(res.first.second);
      }
    }
    cout << 2 * r + (1 - ((int)center.size()) % 2) << " ";
  }
  return 0;
}
