
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 0; i < n - 2; i++) {
			int max = Integer.MIN_VALUE;
			int min = Integer.MAX_VALUE;
			for (int j = i; j < i + 3; j++) {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			}

			if (p[i+1] < max & min < p[i+1]) {
				count++;
			}

		}

		System.out.println(count);




	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 0; i < n - 2; i++) {
			int max = Integer.MIN_VALUE;
			int min = Integer.MAX_VALUE;
			for (int j = i; j < i + 3; j++) {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			}

			if (p[i+1] < max & min < p[i+1]) {
				count++;
			}

		}

		System.out.println(count);




	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 0; i < n - 2; i++) {
			int max = Integer.MIN_VALUE;
			int min = Integer.MAX_VALUE;
			for (int j = i; j < i + 3; j++) {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			}

			if (p[i+1] < max & min < p[i+1]) {
				count++;
			}

		}

		System.out.println(count);




	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 0; i < n - 2; i++) {
			int max = Integer.MIN_VALUE;
			int min = Integer.MAX_VALUE;
			for (int j = i; j < i + 3; j++) {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			}

			if (p[i+1] < max & min < p[i+1]) {
				count++;
			}

		}

		System.out.println(count);




	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int count = 0; count 0 int[] p = new int[n]; p new int[n] n for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			p[i] = sc.nextInt();
		} {
			p[i] = sc.nextInt();
		} p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc for (int i = 0; i < n - 2; i++) {
			int max = Integer.MIN_VALUE;
			int min = Integer.MAX_VALUE;
			for (int j = i; j < i + 3; j++) {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			}

			if (p[i+1] < max & min < p[i+1]) {
				count++;
			}

		} int i = 0; int i = 0; i 0 i < n - 2 i n - 2 n 2 i++ i++ i {
			int max = Integer.MIN_VALUE;
			int min = Integer.MAX_VALUE;
			for (int j = i; j < i + 3; j++) {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			}

			if (p[i+1] < max & min < p[i+1]) {
				count++;
			}

		} {
			int max = Integer.MIN_VALUE;
			int min = Integer.MAX_VALUE;
			for (int j = i; j < i + 3; j++) {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			}

			if (p[i+1] < max & min < p[i+1]) {
				count++;
			}

		} int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int j = i; j < i + 3; j++) {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			} int j = i; int j = i; j i j < i + 3 j i + 3 i 3 j++ j++ j {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			} {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			} max = Math.max(max, p[j]) max Math.max(max, p[j]) Math.max Math max p[j] p j min = Math.min(min, p[j]) min Math.min(min, p[j]) Math.min Math min p[j] p j if (p[i+1] < max & min < p[i+1]) {
				count++;
			} p[i+1] < max & min < p[i+1] p[i+1] < max p[i+1] p i+1 i 1 max min < p[i+1] min p[i+1] p i+1 i 1 {
				count++;
			} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 0; i < n - 2; i++) {
			int max = Integer.MIN_VALUE;
			int min = Integer.MAX_VALUE;
			for (int j = i; j < i + 3; j++) {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			}

			if (p[i+1] < max & min < p[i+1]) {
				count++;
			}

		}

		System.out.println(count);




	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 0; i < n - 2; i++) {
			int max = Integer.MIN_VALUE;
			int min = Integer.MAX_VALUE;
			for (int j = i; j < i + 3; j++) {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			}

			if (p[i+1] < max & min < p[i+1]) {
				count++;
			}

		}

		System.out.println(count);




	}

} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 0; i < n - 2; i++) {
			int max = Integer.MIN_VALUE;
			int min = Integer.MAX_VALUE;
			for (int j = i; j < i + 3; j++) {
				max = Math.max(max, p[j]);
				min = Math.min(min, p[j]);
			}

			if (p[i+1] < max & min < p[i+1]) {
				count++;
			}

		}

		System.out.println(count);




	}

}
