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;
long long mod = 1000003;
vector<vector<int> > p;
vector<int> pa;
vector<int> lv;
vector<vector<int> > adj;
void dfs(int u, int parent, int l) {
  lv[u] = l;
  for (int j = 0; j < (int)adj[u].size(); j++) {
    int v = adj[u][j];
    if (v != parent) {
      dfs(v, u, l + 1);
    }
  }
}
int lca(int x, int y) {
  if (lv[x] < lv[y]) {
    swap(x, y);
  }
  int gap = lv[x] - lv[y];
  for (int i = 20; i >= 0; i--) {
    if ((1 << i) & gap) {
      x = p[x][i + 1];
    }
  }
  if (x == y) return x;
  for (int i = 20; i >= 0; i--) {
    if (p[x][i] != p[y][i]) {
      x = p[x][i];
      y = p[y][i];
    }
  }
  return p[x][1];
}
int d(int x, int y) { return lv[x] + lv[y] - 2 * lv[lca(x, y)]; }
int main() {
  int n;
  cin >> n;
  pa.assign(n + 10, -1);
  p.assign(n + 10, vector<int>(23, -1));
  lv.assign(n + 10, -1);
  adj.assign(n + 10, vector<int>(0, 0));
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    x--;
    adj[x].push_back(i);
    adj[i].push_back(x);
    pa[i] = x;
  }
  for (int i = 1; i <= 22; i++) {
    for (int j = 0; j < n; j++) {
      if (i == 1) {
        p[j][i] = pa[j];
      } else {
        if (p[j][i - 1] != -1) p[j][i] = p[p[j][i - 1]][i - 1];
      }
    }
  }
  dfs(0, -1, 0);
  int pu = 0;
  int pv = 1;
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (i == 1) {
      cout << 1 << endl;
    } else {
      if (ans < d(pu, i)) {
        ans = d(pu, i);
        pv = i;
      }
      if (ans < d(i, pv)) {
        ans = d(i, pv);
        pu = i;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
