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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;

public class NikitaGame {

	public static int nivel;
	public static int[] classe;
	public static int[][] fase;
	public static int far(int a, int b) {
		return classe[a] + classe[b] - 2 * classe[verificar(a, b)];
	}

	public static int verificar(int x, int y) {
		if (classe[y] < classe[x]) {
			int aux = y;
			y = x;
			x = aux;
		}
		int diferenca = classe[y] - classe[x];
		for (int i = 0; i <= 20; i++) {
			if ((diferenca & (1 << i)) != 0) {
				y = fase[y][i];
			}
		}

		if (x == y) {
			return x;
		}

		for (int i = 20; i >= 0; i--) {
			if (fase[x][i] != fase[y][i]) {
				x = fase[x][i];
				y = fase[y][i];
			}
		}
		return fase[x][0];
	}
	
	public static void main(String[] args) throws IOException {
		BufferedReader ler = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Integer> firstArray = new ArrayList<>();
		ArrayList<Integer> secondArray = new ArrayList<>();

		nivel = Integer.parseInt(ler.readLine()) + 1;
		fase = new int[nivel][21];
		int cont = 0;
		while (cont <= 20) {
			fase[0][cont] = 0;
			cont++;
		}
		classe = new int[nivel];
		firstArray.add(0);

		int aux = 0;
		PrintWriter escrever = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

		for (int contador = 1; contador < nivel; contador++) {
			int pontos = Integer.parseInt(ler.readLine()) - 1;
			classe[contador] = classe[pontos] + 1;
			fase[contador][0] = pontos;

			for (int i = 1; i <= 20; i++) {
				fase[contador][i] = fase[fase[contador][i - 1]][i - 1];
			}

			if (!firstArray.isEmpty() && far(firstArray.get(0), contador) > aux) {
				aux++;
				for (int item : secondArray) {
					if (far(contador, item) == aux) {
						firstArray.add(item);
					}
				}
				secondArray.clear();
				secondArray.add(contador);
			} else if (!secondArray.isEmpty() && far(secondArray.get(0), contador) > aux) {
				aux++;
				for (int item : firstArray) {
					if (far(contador, item) == aux) {
						secondArray.add(item);
					}
				}
				firstArray.clear();
				firstArray.add(contador);
			} else if (!firstArray.isEmpty() && far(firstArray.get(0), contador) == aux) {
				secondArray.add(contador);
			} else if (!secondArray.isEmpty() && far(secondArray.get(0), contador) == aux) {
				firstArray.add(contador);
			}
			escrever.println(firstArray.size() + secondArray.size());
		}
		escrever.close();
	}
}
