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 INF = 1 << 28;
const long long LINF = 1ll << 61;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c != ' ' && c != '\n') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
inline char mygetchar() {
  register char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
int n;
int p[20][200111];
int dis[200111];
int getlca(int x, int y) {
  if (dis[x] < dis[y]) swap(x, y);
  for (int i = 19; i >= 0; i--) {
    if (p[i][x] != -1 && dis[p[i][x]] >= dis[y]) {
      x = p[i][x];
    }
  }
  if (x == y) return x;
  for (int i = 19; i >= 0; i--) {
    if (p[i][x] != p[i][y]) {
      x = p[i][x];
      y = p[i][y];
    }
  }
  return p[0][x];
}
int main() {
  n = getnum();
  for (int i = 0; i < 20; i++) p[i][1] = -1;
  int mxid = 1, mx = 0, ans = 0;
  for (int i = 2; i <= n; i++) {
    int x;
    x = getnum();
    dis[i] = dis[x] + 1;
    if (dis[i] > mx) {
      mxid = i;
      mx = dis[i];
      ans++;
    }
    p[0][i] = x;
    for (int j = 1; j < 20; j++) {
      p[j][i] = p[j - 1][p[j - 1][i]];
    }
    int tmp = getlca(i, mxid);
    ans = max(ans, dis[i] + dis[mxid] - 2 * dis[tmp]);
    putnum(ans), putendl();
  }
  return 0;
}
