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 dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const long long linf = 4000000000000000000LL;
const long long inf = 1000000007;
const long double pi = 3.1415926535;
void pv(vector<int> a) {
  for (auto& x : a) cout << x << " ";
  cout << '\n';
}
void pv(vector<long long> a) {
  for (auto& x : a) cout << x << " ";
  cout << '\n';
}
void pv(vector<vector<int> > a) {
  for (int i = (0); i < (int(a.size())); ++i) {
    cout << i << '\n';
    pv(a[i]);
    cout << '\n';
  }
}
void pv(vector<vector<long long> > a) {
  for (int i = (0); i < (int(a.size())); ++i) {
    cout << i << '\n';
    pv(a[i]);
  }
  cout << '\n';
}
void pv(vector<string> a) {
  for (auto& x : a) cout << x << '\n';
  cout << '\n';
}
void setIO(string second) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (int(second.size())) {
    freopen((second + ".in").c_str(), "r", stdin);
    if (second != "test1") freopen((second + ".out").c_str(), "w", stdout);
  }
}
int SZ = 20;
struct tree {
  map<int, int> index;
  int n;
  vector<int> depth;
  int d1, d2;
  vector<vector<int> > jump;
  vector<int> parent;
  int dia;
  void init(int x) {
    n = 1;
    depth.resize(n);
    d1 = 0, d2 = 0;
    jump.resize(1, vector<int>(SZ));
    fill(jump[0].begin(), jump[0].end(), -1);
    index.insert({x, int(index.size())});
    parent.resize(1, -1);
  }
  int get(int a, int b) {
    for (int j = (0); j < (SZ); ++j) {
      if (b & (1 << j)) {
        a = jump[a][j];
      }
    }
    return a;
  }
  int LCA(int a, int b) {
    if (depth[a] < depth[b]) swap(a, b);
    a = get(a, depth[a] - depth[b]);
    if (a == b) return a;
    int j = SZ;
    while (j) {
      j--;
      int ta = jump[a][j], tb = jump[b][j];
      if (ta != tb) a = ta, b = tb;
    }
    return parent[a];
  }
  int dist(int a, int b) { return depth[a] + depth[b] - 2 * depth[LCA(a, b)]; }
  void add(int x, int p) {
    index.insert({x, int(index.size())});
    x = int(index.size()) - 1;
    p = index[p];
    n++;
    depth.push_back(0);
    depth[x] = depth[p] + 1;
    parent.push_back(0);
    parent[x] = p;
    jump.push_back(vector<int>(SZ));
    jump[x][0] = p;
    for (int i = (0); i < (SZ - 1); ++i) {
      jump[x][i + 1] = (jump[x][i] == -1 ? -1 : jump[jump[x][i]][i]);
    }
    int dist1 = dist(x, d1), dist2 = dist(x, d2);
    if (dist1 > dia) {
      dia = dist1;
      d2 = x;
    }
    if (dist2 > dia) {
      dia = dist2;
      d1 = x;
    }
  }
  int get() { return dia; }
};
int main() {
  setIO("");
  vector<tree> a;
  map<int, int> index;
  int cur = 0, curi = 0;
  index.insert({cur++, curi++});
  a.resize(curi);
  a[curi - 1].init(cur - 1);
  int n;
  cin >> n;
  while (n > 1) {
    int x;
    cin >> x;
    x--;
    index.insert({cur++, index[x]});
    a[index[x]].add(cur - 1, x);
    cout << a[index[x]].get() << " ";
    n--;
  }
}
