import java.util.Scanner;

public class Main {
	static int[] ary;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ary = new int[n];
		for(int i = 0; i < n; i++){
			ary[i] = sc.nextInt();
		}
		int count = 0;
		for(int i = 0; i < n-2; i++){
			if(check(ary[i], ary[i + 1], ary[i + 2])){
				count++;
			}
		}
		System.out.println(count);
	}
	static boolean check(int a, int b, int c){
		return (Math.max(a, Math.max(b, c)) != b)
				&& (Math.min(a, Math.min(b, c)) != b);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static int[] ary;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ary = new int[n];
		for(int i = 0; i < n; i++){
			ary[i] = sc.nextInt();
		}
		int count = 0;
		for(int i = 0; i < n-2; i++){
			if(check(ary[i], ary[i + 1], ary[i + 2])){
				count++;
			}
		}
		System.out.println(count);
	}
	static boolean check(int a, int b, int c){
		return (Math.max(a, Math.max(b, c)) != b)
				&& (Math.min(a, Math.min(b, c)) != b);
	}
} Main static int[] ary; ary public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ary = new int[n];
		for(int i = 0; i < n; i++){
			ary[i] = sc.nextInt();
		}
		int count = 0;
		for(int i = 0; i < n-2; i++){
			if(check(ary[i], ary[i + 1], ary[i + 2])){
				count++;
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ary = new int[n];
		for(int i = 0; i < n; i++){
			ary[i] = sc.nextInt();
		}
		int count = 0;
		for(int i = 0; i < n-2; i++){
			if(check(ary[i], ary[i + 1], ary[i + 2])){
				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 ary = new int[n] ary new int[n] n for(int i = 0; i < n; i++){
			ary[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			ary[i] = sc.nextInt();
		} {
			ary[i] = sc.nextInt();
		} ary[i] = sc.nextInt() ary[i] ary i sc.nextInt() sc.nextInt sc int count = 0; count 0 for(int i = 0; i < n-2; i++){
			if(check(ary[i], ary[i + 1], ary[i + 2])){
				count++;
			}
		} int i = 0; int i = 0; i 0 i < n-2 i n-2 n 2 i++ i++ i {
			if(check(ary[i], ary[i + 1], ary[i + 2])){
				count++;
			}
		} {
			if(check(ary[i], ary[i + 1], ary[i + 2])){
				count++;
			}
		} if(check(ary[i], ary[i + 1], ary[i + 2])){
				count++;
			} check(ary[i], ary[i + 1], ary[i + 2]) check ary[i] ary i ary[i + 1] ary i + 1 i 1 ary[i + 2] ary i + 2 i 2 {
				count++;
			} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args static boolean check(int a, int b, int c){
		return (Math.max(a, Math.max(b, c)) != b)
				&& (Math.min(a, Math.min(b, c)) != b);
	} check {
		return (Math.max(a, Math.max(b, c)) != b)
				&& (Math.min(a, Math.min(b, c)) != b);
	} return (Math.max(a, Math.max(b, c)) != b)
				&& (Math.min(a, Math.min(b, c)) != b); (Math.max(a, Math.max(b, c)) != b)
				&& (Math.min(a, Math.min(b, c)) != b) (Math.max(a, Math.max(b, c)) != b) Math.max(a, Math.max(b, c)) Math.max Math a Math.max(b, c) Math.max Math b c b (Math.min(a, Math.min(b, c)) != b) Math.min(a, Math.min(b, c)) Math.min Math a Math.min(b, c) Math.min Math b c b int a a int b b int c c public class Main {
	static int[] ary;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ary = new int[n];
		for(int i = 0; i < n; i++){
			ary[i] = sc.nextInt();
		}
		int count = 0;
		for(int i = 0; i < n-2; i++){
			if(check(ary[i], ary[i + 1], ary[i + 2])){
				count++;
			}
		}
		System.out.println(count);
	}
	static boolean check(int a, int b, int c){
		return (Math.max(a, Math.max(b, c)) != b)
				&& (Math.min(a, Math.min(b, c)) != b);
	}
} public class Main {
	static int[] ary;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ary = new int[n];
		for(int i = 0; i < n; i++){
			ary[i] = sc.nextInt();
		}
		int count = 0;
		for(int i = 0; i < n-2; i++){
			if(check(ary[i], ary[i + 1], ary[i + 2])){
				count++;
			}
		}
		System.out.println(count);
	}
	static boolean check(int a, int b, int c){
		return (Math.max(a, Math.max(b, c)) != b)
				&& (Math.min(a, Math.min(b, c)) != b);
	}
} Main
import java.util.Scanner;

public class Main {
	static int[] ary;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ary = new int[n];
		for(int i = 0; i < n; i++){
			ary[i] = sc.nextInt();
		}
		int count = 0;
		for(int i = 0; i < n-2; i++){
			if(check(ary[i], ary[i + 1], ary[i + 2])){
				count++;
			}
		}
		System.out.println(count);
	}
	static boolean check(int a, int b, int c){
		return (Math.max(a, Math.max(b, c)) != b)
				&& (Math.min(a, Math.min(b, c)) != b);
	}
}
