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 long long M = 1e9 + 7;
vector<long long> heh(21, -1);
unordered_map<long long, long long> par;
vector<vector<long long>> up(1e6, heh);
vector<long long> depth(1e6, -1);
bool is_ancest(long long v, long long u) {
  for (long long j = 20; j >= 1; j--) {
    if (depth[up[v][j]] > depth[u]) {
      v = up[v][j];
    }
  }
  return par[v] == u;
}
long long lca(long long v1, long long v2) {
  if (depth[v2] > depth[v1]) {
    swap(v1, v2);
  }
  if (is_ancest(v1, v2)) {
    return v2;
  } else {
    for (long long j = 20; j >= 1; j--) {
      long long v3 = up[v1][j];
      if (!is_ancest(v2, v3)) {
        v1 = v3;
      }
    }
    return par[v1];
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    up[i][0] = i;
  }
  for (long long j = 0; j < 21; j++) {
    up[0][j] = 0;
  }
  depth[0] = 0;
  par[0] = -1;
  long long y1 = 0, y2 = 0;
  long long now_ans = 0;
  for (long long i = 1; i <= n - 1; i++) {
    long long p;
    cin >> p;
    p--;
    par[i] = p;
    depth[i] = depth[p] + 1;
    up[i][0] = i;
    up[i][1] = p;
    for (long long j = 2; j < 21; j++) {
      up[i][j] = up[up[i][j - 1]][j - 1];
    }
    long long num1 = depth[y1] + depth[i] - 2 * depth[lca(y1, i)];
    long long num2 = depth[y2] + depth[i] - 2 * depth[lca(y2, i)];
    if (now_ans < num1) {
      now_ans = num1;
      y2 = i;
    } else if (now_ans < num2) {
      now_ans = num2;
      y1 = i;
    }
    cout << now_ans << ' ';
  }
}
