Nikita plays a new computer game. There are m levels in this game. In the beginning of each level a new class appears in the game; this class is a child-class of the class yi (and yi is called parent-class for this new class). Thus, the classes form a tree. Initially there is only one class with index 1.

Changing the class to its neighbour (child-class or parent-class) in the tree costs 1 coin. You can not change the class back. The cost of changing the class a to the class b is equal to the total cost of class changes on the path from a to b in the class tree.

Suppose that at i -th level the maximum cost of changing one class to another is x. For each level output the number of classes such that for each of these classes there exists some other class y, and the distance from this class to y is exactly x.

Input

First line contains one integer number m — number of queries (1 ≤ m ≤ 3·105).

Next m lines contain description of queries. i -th line (1 ≤ i ≤ m) describes the i -th level and contains an integer yi — the index of the parent-class of class with index i + 1 (1 ≤ yi ≤ i). 

Output

Suppose that at i -th level the maximum cost of changing one class to another is x. For each level output the number of classes such that for each of these classes there exists some other class y, and the distance from this class to y is exactly x.

Examples

Input

4
1
1
2
1


Output

2
2
2
3


Input

4
1
1
2
3


Output

2
2
2
2
#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  register int data = 0, w = 1;
  register char ch = 0;
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar();
  return w * data;
}
const int MAX_N = 3e5 + 5;
int N, maxd, f[20][MAX_N], dep[MAX_N];
void add(int x, int fa) {
  dep[x] = dep[fa] + 1, f[0][x] = fa;
  for (int i = 1; i < 20; i++) f[i][x] = f[i - 1][f[i - 1][x]];
}
int LCA(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 19; ~i; i--)
    if (dep[f[i][u]] >= dep[v]) u = f[i][u];
  if (u == v) return v;
  for (int i = 19; ~i; i--)
    if (f[i][u] != f[i][v]) u = f[i][u], v = f[i][v];
  return f[0][u];
}
int dist(int u, int v) { return dep[u] + dep[v] - dep[LCA(u, v)] * 2; }
vector<int> s1, s2;
int main() {
  N = gi();
  add(1, 0), s1.push_back(1);
  for (int i = 1; i <= N; i++) {
    int x = i + 1;
    add(x, gi());
    int d1 = s1.empty() ? 0 : dist(x, s1[0]);
    int d2 = s2.empty() ? 0 : dist(x, s2[0]);
    if (max(d1, d2) > maxd) {
      maxd = max(d1, d2);
      if (d1 > d2) {
        for (int v : s2)
          if (dist(x, v) == d1) s1.push_back(v);
        s2 = {x};
      } else {
        for (int v : s1)
          if (dist(x, v) == d2) s2.push_back(v);
        s1 = {x};
      }
    } else if (max(d1, d2) == maxd) {
      if (d1 > d2)
        s2.push_back(x);
      else
        s1.push_back(x);
    }
    printf("%lld\n", s1.size() + s2.size());
  }
  return 0;
}
