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;
int n;
vector<int> adj[200005];
int depth[200005];
int timer = 0;
int in_t[200005], out_t[200005];
int anc[200005][20];
void dfs(int x, int p) {
  depth[x] = depth[p] + 1;
  in_t[x] = timer++;
  anc[x][0] = p;
  for (int i = 1; i < 20; i++) {
    anc[x][i] = anc[anc[x][i - 1]][i - 1];
  }
  for (auto i : adj[x]) {
    if (i == p) continue;
    dfs(i, x);
  }
  out_t[x] = timer;
}
bool is_anc(int a, int b) {
  return (in_t[a] <= in_t[b] && out_t[b] <= out_t[a]);
}
int lca(int a, int b) {
  if (is_anc(a, b)) return a;
  if (is_anc(b, a)) return b;
  int cur = a;
  for (int i = 19; i >= 0; i--) {
    if (!is_anc(anc[cur][i], b)) cur = anc[cur][i];
  }
  return anc[cur][0];
}
int dist(int a, int b) {
  int l = lca(a, b);
  return depth[a] + depth[b] - 2 * depth[l];
}
int e1, e2;
int main() {
  cin >> n;
  int pi;
  for (int i = 1; i < n; i++) {
    cin >> pi;
    pi--;
    adj[i].push_back(pi);
    adj[pi].push_back(i);
  }
  depth[0] = 0;
  dfs(0, 0);
  e1 = e2 = 0;
  for (int i = 1; i < n; i++) {
    int cur = dist(e1, e2);
    int d1 = dist(i, e1);
    if (d1 > cur) {
      cout << d1 << " ";
      e2 = i;
      continue;
    }
    int d2 = dist(i, e2);
    if (d2 > cur) {
      cout << d2 << " ";
      e1 = i;
      continue;
    }
    cout << cur << " ";
  }
  cout << endl;
}
