import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		final int N = Integer.parseInt(scan.nextLine());
		final int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(scan.next());
		}
		scan.close();

		int count = 0;
		for (int i = 0; i + 2 < N; i++) {
			if (array[i] < array[i + 1] && array[i + 1] < array[i + 2]) {
				count++;
			} else if (array[i + 2] < array[i + 1] && array[i + 1] < array[i]) {
				count++;
			}
		}

		System.out.println(count);

	}

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

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		final int N = Integer.parseInt(scan.nextLine());
		final int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(scan.next());
		}
		scan.close();

		int count = 0;
		for (int i = 0; i + 2 < N; i++) {
			if (array[i] < array[i + 1] && array[i + 1] < array[i + 2]) {
				count++;
			} else if (array[i + 2] < array[i + 1] && array[i + 1] < array[i]) {
				count++;
			}
		}

		System.out.println(count);

	}

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

		Scanner scan = new Scanner(System.in);
		final int N = Integer.parseInt(scan.nextLine());
		final int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(scan.next());
		}
		scan.close();

		int count = 0;
		for (int i = 0; i + 2 < N; i++) {
			if (array[i] < array[i + 1] && array[i + 1] < array[i + 2]) {
				count++;
			} else if (array[i + 2] < array[i + 1] && array[i + 1] < array[i]) {
				count++;
			}
		}

		System.out.println(count);

	} main {

		Scanner scan = new Scanner(System.in);
		final int N = Integer.parseInt(scan.nextLine());
		final int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(scan.next());
		}
		scan.close();

		int count = 0;
		for (int i = 0; i + 2 < N; i++) {
			if (array[i] < array[i + 1] && array[i + 1] < array[i + 2]) {
				count++;
			} else if (array[i + 2] < array[i + 1] && array[i + 1] < array[i]) {
				count++;
			}
		}

		System.out.println(count);

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) final int N = Integer.parseInt(scan.nextLine()); N Integer.parseInt(scan.nextLine()) Integer.parseInt Integer scan.nextLine() scan.nextLine scan final int[] array = new int[N]; array new int[N] N for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(scan.next());
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			array[i] = Integer.parseInt(scan.next());
		} {
			array[i] = Integer.parseInt(scan.next());
		} array[i] = Integer.parseInt(scan.next()) array[i] array i Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan scan.close() scan.close scan int count = 0; count 0 for (int i = 0; i + 2 < N; i++) {
			if (array[i] < array[i + 1] && array[i + 1] < array[i + 2]) {
				count++;
			} else if (array[i + 2] < array[i + 1] && array[i + 1] < array[i]) {
				count++;
			}
		} int i = 0; int i = 0; i 0 i + 2 < N i + 2 i 2 N i++ i++ i {
			if (array[i] < array[i + 1] && array[i + 1] < array[i + 2]) {
				count++;
			} else if (array[i + 2] < array[i + 1] && array[i + 1] < array[i]) {
				count++;
			}
		} {
			if (array[i] < array[i + 1] && array[i + 1] < array[i + 2]) {
				count++;
			} else if (array[i + 2] < array[i + 1] && array[i + 1] < array[i]) {
				count++;
			}
		} if (array[i] < array[i + 1] && array[i + 1] < array[i + 2]) {
				count++;
			} else if (array[i + 2] < array[i + 1] && array[i + 1] < array[i]) {
				count++;
			} array[i] < array[i + 1] && array[i + 1] < array[i + 2] array[i] < array[i + 1] array[i] array i array[i + 1] array i + 1 i 1 array[i + 1] < array[i + 2] array[i + 1] array i + 1 i 1 array[i + 2] array i + 2 i 2 {
				count++;
			} count++ count if (array[i + 2] < array[i + 1] && array[i + 1] < array[i]) {
				count++;
			} array[i + 2] < array[i + 1] && array[i + 1] < array[i] array[i + 2] < array[i + 1] array[i + 2] array i + 2 i 2 array[i + 1] array i + 1 i 1 array[i + 1] < array[i] array[i + 1] array i + 1 i 1 array[i] array i {
				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 scan = new Scanner(System.in);
		final int N = Integer.parseInt(scan.nextLine());
		final int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(scan.next());
		}
		scan.close();

		int count = 0;
		for (int i = 0; i + 2 < N; i++) {
			if (array[i] < array[i + 1] && array[i + 1] < array[i + 2]) {
				count++;
			} else if (array[i + 2] < array[i + 1] && array[i + 1] < array[i]) {
				count++;
			}
		}

		System.out.println(count);

	}

} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		final int N = Integer.parseInt(scan.nextLine());
		final int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(scan.next());
		}
		scan.close();

		int count = 0;
		for (int i = 0; i + 2 < N; i++) {
			if (array[i] < array[i + 1] && array[i + 1] < array[i + 2]) {
				count++;
			} else if (array[i + 2] < array[i + 1] && array[i + 1] < array[i]) {
				count++;
			}
		}

		System.out.println(count);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		final int N = Integer.parseInt(scan.nextLine());
		final int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(scan.next());
		}
		scan.close();

		int count = 0;
		for (int i = 0; i + 2 < N; i++) {
			if (array[i] < array[i + 1] && array[i + 1] < array[i + 2]) {
				count++;
			} else if (array[i + 2] < array[i + 1] && array[i + 1] < array[i]) {
				count++;
			}
		}

		System.out.println(count);

	}

}