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 mx = 2e5 + 5, ln = 21;
int up[mx][ln], in[mx], out[mx], tm_, dist[mx];
vector<int> v[mx];
void dfs(int x, int p) {
  in[x] = ++tm_;
  up[x][0] = p;
  for (int i = 1; i < ln; i++) {
    up[x][i] = up[up[x][i - 1]][i - 1];
  }
  for (auto i : v[x]) {
    if (i != p) {
      dist[i] = dist[x] + 1;
      dfs(i, x);
    }
  }
  out[x] = ++tm_;
}
bool is_Ancestor(int x, int y) { return in[x] <= in[y] && out[x] >= out[y]; }
int lca(int x, int y) {
  if (is_Ancestor(x, y)) return x;
  if (is_Ancestor(y, x)) return y;
  for (int i = ln - 1; i >= 0; i--) {
    if (!is_Ancestor(up[x][i], y)) {
      x = up[x][i];
    }
  }
  return up[x][0];
}
int distance(int x, int y) {
  int lca_ = lca(x, y);
  return dist[x] + dist[y] - 2 * dist[lca_];
}
void solveFunction() {
  int n;
  cin >> n;
  vector<int> q;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    q.push_back(x);
    v[i].push_back(x);
    v[x].push_back(i);
  }
  dfs(1, 1);
  pair<int, int> p = {1, 1};
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    int x = p.first, y = p.second;
    int d1 = distance(x, y);
    int d2 = distance(x, i);
    int d3 = distance(y, i);
    int arr[3] = {d1, d2, d3};
    sort(arr, arr + 3);
    if (arr[2] == d1) {
      cout << d1 << " ";
    } else if (arr[2] == d2) {
      cout << d2 << " ";
      p.second = i;
    } else {
      cout << d3 << " ";
      swap(p.first, p.second);
      p.second = i;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    solveFunction();
  }
}
