unittest
{
	assert( [ "5", "1 3 5 4 2" ].parse.expand.solve == 2 );
	assert( [ "9", "9 6 3 2 5 8 7 4 1" ].parse.expand.solve == 5 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	return tuple( ps );
}

auto solve( long[] ps )
{
writefln( "\nsolve( %s )", ps );
	auto ans = 0L;
	for( auto i = 1L; i + 1 < ps.length; i++ )
	{
		ans += ( ( ps[ i - 1 ] < ps[ i ] && ps[ i ] < ps[ i + 1 ] ) || 
		         ( ps[ i + 1 ] < ps[ i ] && ps[ i ] < ps[ i - 1 ] ) );
	}
	return ans;
}
