import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int n = Integer.parseInt(in.readLine());
		int[] p = new int[n];
		String[] tokens = in.readLine().split(" ");
		for (int i = 0; i < n; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
		}
		long count = 0;
		for (int i = 1; i + 1 < n; ++i) {
			if (check(p, i - 1, i, i + 1)) {
				++count;
			}
		}

		System.out.println(count);
		in.close();
	}

	static boolean check(int[] p, int i, int j, int k) {
		if (p[i] < p[j] && p[j] < p[k]) {
			return true;
		} else if (p[i] > p[j] && p[j] > p[k]) {
			return true;
		} else {
			return false;
		}
	}

} import java.util.*; util.* java import java.io.*; io.* java import java.nio.charset.StandardCharsets; StandardCharsets java.nio.charset public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int n = Integer.parseInt(in.readLine());
		int[] p = new int[n];
		String[] tokens = in.readLine().split(" ");
		for (int i = 0; i < n; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
		}
		long count = 0;
		for (int i = 1; i + 1 < n; ++i) {
			if (check(p, i - 1, i, i + 1)) {
				++count;
			}
		}

		System.out.println(count);
		in.close();
	}

	static boolean check(int[] p, int i, int j, int k) {
		if (p[i] < p[j] && p[j] < p[k]) {
			return true;
		} else if (p[i] > p[j] && p[j] > p[k]) {
			return true;
		} else {
			return false;
		}
	}

} Main public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int n = Integer.parseInt(in.readLine());
		int[] p = new int[n];
		String[] tokens = in.readLine().split(" ");
		for (int i = 0; i < n; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
		}
		long count = 0;
		for (int i = 1; i + 1 < n; ++i) {
			if (check(p, i - 1, i, i + 1)) {
				++count;
			}
		}

		System.out.println(count);
		in.close();
	} main {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int n = Integer.parseInt(in.readLine());
		int[] p = new int[n];
		String[] tokens = in.readLine().split(" ");
		for (int i = 0; i < n; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
		}
		long count = 0;
		for (int i = 1; i + 1 < n; ++i) {
			if (check(p, i - 1, i, i + 1)) {
				++count;
			}
		}

		System.out.println(count);
		in.close();
	} InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8); reader new InputStreamReader(System.in, StandardCharsets.UTF_8) BufferedReader in = new BufferedReader(reader); in new BufferedReader(reader) int n = Integer.parseInt(in.readLine()); n Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in int[] p = new int[n]; p new int[n] n String[] tokens = in.readLine().split(" "); tokens in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " for (int i = 0; i < n; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
		} int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
			p[i] = Integer.parseInt(tokens[i]);
		} {
			p[i] = Integer.parseInt(tokens[i]);
		} p[i] = Integer.parseInt(tokens[i]) p[i] p i Integer.parseInt(tokens[i]) Integer.parseInt Integer tokens[i] tokens i long count = 0; count 0 for (int i = 1; i + 1 < n; ++i) {
			if (check(p, i - 1, i, i + 1)) {
				++count;
			}
		} int i = 1; int i = 1; i 1 i + 1 < n i + 1 i 1 n ++i ++i i {
			if (check(p, i - 1, i, i + 1)) {
				++count;
			}
		} {
			if (check(p, i - 1, i, i + 1)) {
				++count;
			}
		} if (check(p, i - 1, i, i + 1)) {
				++count;
			} check(p, i - 1, i, i + 1) check p i - 1 i 1 i i + 1 i 1 {
				++count;
			} ++count count System.out.println(count) System.out.println System.out System System.out count in.close() in.close in String[] args args static boolean check(int[] p, int i, int j, int k) {
		if (p[i] < p[j] && p[j] < p[k]) {
			return true;
		} else if (p[i] > p[j] && p[j] > p[k]) {
			return true;
		} else {
			return false;
		}
	} check {
		if (p[i] < p[j] && p[j] < p[k]) {
			return true;
		} else if (p[i] > p[j] && p[j] > p[k]) {
			return true;
		} else {
			return false;
		}
	} if (p[i] < p[j] && p[j] < p[k]) {
			return true;
		} else if (p[i] > p[j] && p[j] > p[k]) {
			return true;
		} else {
			return false;
		} p[i] < p[j] && p[j] < p[k] p[i] < p[j] p[i] p i p[j] p j p[j] < p[k] p[j] p j p[k] p k {
			return true;
		} return true; true if (p[i] > p[j] && p[j] > p[k]) {
			return true;
		} else {
			return false;
		} p[i] > p[j] && p[j] > p[k] p[i] > p[j] p[i] p i p[j] p j p[j] > p[k] p[j] p j p[k] p k {
			return true;
		} return true; true {
			return false;
		} return false; false int[] p p int i i int j j int k k public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int n = Integer.parseInt(in.readLine());
		int[] p = new int[n];
		String[] tokens = in.readLine().split(" ");
		for (int i = 0; i < n; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
		}
		long count = 0;
		for (int i = 1; i + 1 < n; ++i) {
			if (check(p, i - 1, i, i + 1)) {
				++count;
			}
		}

		System.out.println(count);
		in.close();
	}

	static boolean check(int[] p, int i, int j, int k) {
		if (p[i] < p[j] && p[j] < p[k]) {
			return true;
		} else if (p[i] > p[j] && p[j] > p[k]) {
			return true;
		} else {
			return false;
		}
	}

} public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int n = Integer.parseInt(in.readLine());
		int[] p = new int[n];
		String[] tokens = in.readLine().split(" ");
		for (int i = 0; i < n; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
		}
		long count = 0;
		for (int i = 1; i + 1 < n; ++i) {
			if (check(p, i - 1, i, i + 1)) {
				++count;
			}
		}

		System.out.println(count);
		in.close();
	}

	static boolean check(int[] p, int i, int j, int k) {
		if (p[i] < p[j] && p[j] < p[k]) {
			return true;
		} else if (p[i] > p[j] && p[j] > p[k]) {
			return true;
		} else {
			return false;
		}
	}

} Main
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int n = Integer.parseInt(in.readLine());
		int[] p = new int[n];
		String[] tokens = in.readLine().split(" ");
		for (int i = 0; i < n; ++i) {
			p[i] = Integer.parseInt(tokens[i]);
		}
		long count = 0;
		for (int i = 1; i + 1 < n; ++i) {
			if (check(p, i - 1, i, i + 1)) {
				++count;
			}
		}

		System.out.println(count);
		in.close();
	}

	static boolean check(int[] p, int i, int j, int k) {
		if (p[i] < p[j] && p[j] < p[k]) {
			return true;
		} else if (p[i] > p[j] && p[j] > p[k]) {
			return true;
		} else {
			return false;
		}
	}

}
