program

funct printInfo( level : int; text : string; ) void
	var i : int;
	begin
		for i = 0; i < level; i = i + 1 do
			print( "    " );
		end
		println( text );
	end

funct power( level, a, n : int; var result : int; ) void

	funct evenPower( level, a, n : int; var result : int; ) void
		var result1 : int;
		begin
			printInfo( level, "Enter evenPower( " + level + ", " + a + ", " + n + ", result = " + result + " )" );
			if n == 0 then
				result = 1;
			else
				power( level + 1, a, n / 2, result1 );
				result = result1 * result1;
			end
			printInfo( level, "Exit evenPower( " + level + ", " + a + ", " + n + ", result = " + result + " )" );
		end

	funct oddPower( level, a, n : int; var result : int; ) void
		var result1 : int;
		begin
			printInfo( level, "Enter oddPower( " + level + ", " + a + ", " + n + ", result = " + result + " )" );
			if n == 1 then
				result = a;
			else
				power( level + 1, a, n / 2, result1 );
				result = a * result1 * result1;
			end
			printInfo( level, "Exit oddPower( " + level + ", " + a + ", " + n + ", result = " + result + " )" );
		end

	begin
		printInfo( level, "Enter power( " + level + ", " + a + ", " + n + ", result = " + result + " )" );
		if n / 2 * 2 == n then
			evenPower( level + 1, a, n, result );
		else
			oddPower( level + 1, a, n, result );
		end
		printInfo( level, "Exit power( " + level + ", " + a + ", " + n + ", result = " + result + " )" );
	end

var result : int;
var n : int;
var a : int;
begin
	a = 2;
	for n = 0; n < 8; n = n + 1 do
		power( 0, a, n, result );
		println( result );
	end
end.
