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 

import java.util.Scanner;

public class Main2 {

	static int n;
	
	static int u;
	
	static int v;
	
	static final int maxn = (int) (2*1e5+100);
	
	static int[][] pa;
	
	static int[] dep;
	
	static int dis_uv = 0;
	
	static void add (int a, int f){
		pa[0][a] = f;
		for ( int i = 0; i < 18; i++ ){
			if (pa[i][a] < 0){
				pa[i+1][a] = -1;
			}else{
				pa[i+1][a] = pa[i][pa[i][a]];
			}
		}
	}
	
	static int lca (int a, int b){
		if (dep[a] > dep[b]){
			int temp = a;
			a = b;
			b = temp;
		}
		for ( int i = 0; i < 18; i++ ){
			if ( ((dep[b]-dep[a]) >> i & 1) == 1 ){
				b = pa[i][b];
			}
		}
		
		if (a == b){
			return a;
		}
		for ( int i = 17; i >= 0; i-- ){
			if (pa[i][a] != pa[i][b]){
				a = pa[i][a];
				b = pa[i][b];
			}
		}
		return pa[0][a];
	}
	
	static int dis (int a, int b){
		return dep[a]+dep[b]-2*dep[lca(a, b)];
	}
	
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		pa = new int[20][maxn];
		dep = new int[maxn];
		n = scanner.nextInt();
		u = 1;
		v = 1;
		add(1, -1);
		
		for ( int i = 2; i <= n; i++ ){
			int a = scanner.nextInt();
			dep[i] = dep[a]+1;
			add(i, a);
			int dis_iu = dis(i, u);
			int dis_iv = dis(i, v);
			if(dis_iu>dis_iv)  
	        {  
	            if(dis_iu>dis_uv)  
	            {  
	                v=i;  
	                dis_uv=dis_iu;  
	            }  
	        }  
	        else if(dis_iv>dis_uv)  
	        {  
	            u=i;  
	            dis_uv=dis_iv;  
	        }  
			System.out.print(dis_uv+" ");
		}
	}
}
