import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int array[] = null;
		int count = 0;

		Scanner scanner = new Scanner(System.in);

		//入力値を扱いやすいように配列化
		for(int i = 0; scanner.hasNext(); i++) {
			if(i == 0) array = new int[Integer.parseInt(scanner.next())];

			array[i] = Integer.parseInt(scanner.next());
		}

		for(int i = 0; i < (array.length -2); i++) {
			
			//3個ずつ比較
			int temp[] = new int[] {array[i], array[i+1], array[i+2]};
			
			//照準ソート
			Arrays.sort(temp);
			
			//ソート前とソート後で真ん中の値を比較
			if(array[i+1] == temp[1]) count++;
			
		}

		System.out.print(count);

		scanner.close();
	}

} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		int array[] = null;
		int count = 0;

		Scanner scanner = new Scanner(System.in);

		//入力値を扱いやすいように配列化
		for(int i = 0; scanner.hasNext(); i++) {
			if(i == 0) array = new int[Integer.parseInt(scanner.next())];

			array[i] = Integer.parseInt(scanner.next());
		}

		for(int i = 0; i < (array.length -2); i++) {
			
			//3個ずつ比較
			int temp[] = new int[] {array[i], array[i+1], array[i+2]};
			
			//照準ソート
			Arrays.sort(temp);
			
			//ソート前とソート後で真ん中の値を比較
			if(array[i+1] == temp[1]) count++;
			
		}

		System.out.print(count);

		scanner.close();
	}

} Main public static void main(String[] args) {

		int array[] = null;
		int count = 0;

		Scanner scanner = new Scanner(System.in);

		//入力値を扱いやすいように配列化
		for(int i = 0; scanner.hasNext(); i++) {
			if(i == 0) array = new int[Integer.parseInt(scanner.next())];

			array[i] = Integer.parseInt(scanner.next());
		}

		for(int i = 0; i < (array.length -2); i++) {
			
			//3個ずつ比較
			int temp[] = new int[] {array[i], array[i+1], array[i+2]};
			
			//照準ソート
			Arrays.sort(temp);
			
			//ソート前とソート後で真ん中の値を比較
			if(array[i+1] == temp[1]) count++;
			
		}

		System.out.print(count);

		scanner.close();
	} main {

		int array[] = null;
		int count = 0;

		Scanner scanner = new Scanner(System.in);

		//入力値を扱いやすいように配列化
		for(int i = 0; scanner.hasNext(); i++) {
			if(i == 0) array = new int[Integer.parseInt(scanner.next())];

			array[i] = Integer.parseInt(scanner.next());
		}

		for(int i = 0; i < (array.length -2); i++) {
			
			//3個ずつ比較
			int temp[] = new int[] {array[i], array[i+1], array[i+2]};
			
			//照準ソート
			Arrays.sort(temp);
			
			//ソート前とソート後で真ん中の値を比較
			if(array[i+1] == temp[1]) count++;
			
		}

		System.out.print(count);

		scanner.close();
	} int array[] = null; array null int count = 0; count 0 Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) for(int i = 0; scanner.hasNext(); i++) {
			if(i == 0) array = new int[Integer.parseInt(scanner.next())];

			array[i] = Integer.parseInt(scanner.next());
		} int i = 0; int i = 0; i 0 scanner.hasNext() scanner.hasNext scanner i++ i++ i {
			if(i == 0) array = new int[Integer.parseInt(scanner.next())];

			array[i] = Integer.parseInt(scanner.next());
		} {
			if(i == 0) array = new int[Integer.parseInt(scanner.next())];

			array[i] = Integer.parseInt(scanner.next());
		} if(i == 0) array = new int[Integer.parseInt(scanner.next())]; i == 0 i 0 array = new int[Integer.parseInt(scanner.next())] array new int[Integer.parseInt(scanner.next())] Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner array[i] = Integer.parseInt(scanner.next()) array[i] array i Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner for(int i = 0; i < (array.length -2); i++) {
			
			//3個ずつ比較
			int temp[] = new int[] {array[i], array[i+1], array[i+2]};
			
			//照準ソート
			Arrays.sort(temp);
			
			//ソート前とソート後で真ん中の値を比較
			if(array[i+1] == temp[1]) count++;
			
		} int i = 0; int i = 0; i 0 i < (array.length -2) i (array.length -2) array.length array array.length 2 i++ i++ i {
			
			//3個ずつ比較
			int temp[] = new int[] {array[i], array[i+1], array[i+2]};
			
			//照準ソート
			Arrays.sort(temp);
			
			//ソート前とソート後で真ん中の値を比較
			if(array[i+1] == temp[1]) count++;
			
		} {
			
			//3個ずつ比較
			int temp[] = new int[] {array[i], array[i+1], array[i+2]};
			
			//照準ソート
			Arrays.sort(temp);
			
			//ソート前とソート後で真ん中の値を比較
			if(array[i+1] == temp[1]) count++;
			
		} int temp[] = new int[] {array[i], array[i+1], array[i+2]}; temp new int[] {array[i], array[i+1], array[i+2]} Arrays.sort(temp) Arrays.sort Arrays temp if(array[i+1] == temp[1]) count++; array[i+1] == temp[1] array[i+1] array i+1 i 1 temp[1] temp 1 count++ count System.out.print(count) System.out.print System.out System System.out count scanner.close() scanner.close scanner String[] args args public class Main {

	public static void main(String[] args) {

		int array[] = null;
		int count = 0;

		Scanner scanner = new Scanner(System.in);

		//入力値を扱いやすいように配列化
		for(int i = 0; scanner.hasNext(); i++) {
			if(i == 0) array = new int[Integer.parseInt(scanner.next())];

			array[i] = Integer.parseInt(scanner.next());
		}

		for(int i = 0; i < (array.length -2); i++) {
			
			//3個ずつ比較
			int temp[] = new int[] {array[i], array[i+1], array[i+2]};
			
			//照準ソート
			Arrays.sort(temp);
			
			//ソート前とソート後で真ん中の値を比較
			if(array[i+1] == temp[1]) count++;
			
		}

		System.out.print(count);

		scanner.close();
	}

} public class Main {

	public static void main(String[] args) {

		int array[] = null;
		int count = 0;

		Scanner scanner = new Scanner(System.in);

		//入力値を扱いやすいように配列化
		for(int i = 0; scanner.hasNext(); i++) {
			if(i == 0) array = new int[Integer.parseInt(scanner.next())];

			array[i] = Integer.parseInt(scanner.next());
		}

		for(int i = 0; i < (array.length -2); i++) {
			
			//3個ずつ比較
			int temp[] = new int[] {array[i], array[i+1], array[i+2]};
			
			//照準ソート
			Arrays.sort(temp);
			
			//ソート前とソート後で真ん中の値を比較
			if(array[i+1] == temp[1]) count++;
			
		}

		System.out.print(count);

		scanner.close();
	}

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int array[] = null;
		int count = 0;

		Scanner scanner = new Scanner(System.in);

		//入力値を扱いやすいように配列化
		for(int i = 0; scanner.hasNext(); i++) {
			if(i == 0) array = new int[Integer.parseInt(scanner.next())];

			array[i] = Integer.parseInt(scanner.next());
		}

		for(int i = 0; i < (array.length -2); i++) {
			
			//3個ずつ比較
			int temp[] = new int[] {array[i], array[i+1], array[i+2]};
			
			//照準ソート
			Arrays.sort(temp);
			
			//ソート前とソート後で真ん中の値を比較
			if(array[i+1] == temp[1]) count++;
			
		}

		System.out.print(count);

		scanner.close();
	}

}