#include<iostream>
using namespace std;

struct element{
	int label;
	bool koristen;
};

struct BinaryTree{
	element elementi[ 2000 ];
};

void InitB( int x, BinaryTree* stablo ){
	for( int i = 0; i < 2000; i++ ) 
			elementi[ i ].koristen = false; 
	stablo->elementi[ 1 ].koristen = true; 
	stablo->elementi[ 1 ].label = x; 
}

int RootB( BinaryTree* stablo ){
	if( stablo->elementi[ 1 ].koristen ) 
		return 1;					
	return 0;						
}

int LabelB( int n, BinaryTree* stablo ){
	return stablo->elementi[ n ].label;
}

void ChangeLabelB( int x, int n, BinaryTree* stablo ){
	stablo->elementi[ n ].label = x;
}

void CreateLeftB( int x, int n, BinaryTree* stablo ){
	if( stablo->elementi[ 2*n ].koristen ) 
		cout << "ERROR!" << endl;
	else{
		stablo->elementi[ 2*n ].koristen = true;
		stablo->elementi[ 2*n ].label = x;
	}
}

void CreateRightB( int x, int n, BinaryTree* stablo ){
	if( stablo->elementi[ 2*n+1 ].koristen )
		cout << "ERROR!" << endl;
	else{
		stablo->elementi[ 2*n+1 ].koristen = true;
		stablo->elementi[ 2*n+1 ].label = x;
	}
}



int LeftChildB( int n, BinaryTree* stablo ){
	if( stablo->elementi[ 2*n ].koristen ) / 
		return (2*n ); 
	else
	return 0;
}


int RightChildB( int n, BinaryTree* stablo ){
	if( stablo->elementi[ 2*n+1 ].koristen )
		return (2*n+1);
	else
	return 0;
}



void DeleteB( int n, BinaryTree* stablo ){
	if( n ){ 
		DeleteB( LeftChildB( n, stablo ), stablo ); 
		DeleteB( RightChildB( n, stablo ), stablo ); 
		stablo->elementi[ n ].koristen = false; 
	}
} 

bool ExistsLeftChildB( int n, BinaryTree* stablo ){
	if(LeftChildB( n, stablo ) != 0)
	return true;
	else
		return false;
}

bool ExistsRightChildB( int n, BinaryTree* stablo ){
	if(RightChildB( n, stablo ) != 0)
	return true;
	else
		return false;
}

int ParentB( int n, BinaryTree* stablo ){
	if( n == 1 ) 
		return 0; 
	else
		return n/2;
}