
import java.util.Scanner;

/**
 * @author yoshizaki
 * ABC 132
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int len = scanner.nextInt();
        int[] numbers = new int[len];
        for(int i = 0; i < len ; i++) {
            numbers[i] = scanner.nextInt();
        }
        int answer = 0;
        for (int i = 1; i < len - 1 ; i++) {
            if(numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1]) answer++;
            if(numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1]) answer++;
        }
        System.out.println(answer);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int len = scanner.nextInt();
        int[] numbers = new int[len];
        for(int i = 0; i < len ; i++) {
            numbers[i] = scanner.nextInt();
        }
        int answer = 0;
        for (int i = 1; i < len - 1 ; i++) {
            if(numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1]) answer++;
            if(numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1]) answer++;
        }
        System.out.println(answer);
    }
} Main public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int len = scanner.nextInt();
        int[] numbers = new int[len];
        for(int i = 0; i < len ; i++) {
            numbers[i] = scanner.nextInt();
        }
        int answer = 0;
        for (int i = 1; i < len - 1 ; i++) {
            if(numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1]) answer++;
            if(numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1]) answer++;
        }
        System.out.println(answer);
    } main {
        Scanner scanner= new Scanner(System.in);
        int len = scanner.nextInt();
        int[] numbers = new int[len];
        for(int i = 0; i < len ; i++) {
            numbers[i] = scanner.nextInt();
        }
        int answer = 0;
        for (int i = 1; i < len - 1 ; i++) {
            if(numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1]) answer++;
            if(numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1]) answer++;
        }
        System.out.println(answer);
    } Scanner scanner= new Scanner(System.in); scanner new Scanner(System.in) int len = scanner.nextInt(); len scanner.nextInt() scanner.nextInt scanner int[] numbers = new int[len]; numbers new int[len] len for(int i = 0; i < len ; i++) {
            numbers[i] = scanner.nextInt();
        } int i = 0; int i = 0; i 0 i < len i len i++ i++ i {
            numbers[i] = scanner.nextInt();
        } {
            numbers[i] = scanner.nextInt();
        } numbers[i] = scanner.nextInt() numbers[i] numbers i scanner.nextInt() scanner.nextInt scanner int answer = 0; answer 0 for (int i = 1; i < len - 1 ; i++) {
            if(numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1]) answer++;
            if(numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1]) answer++;
        } int i = 1; int i = 1; i 1 i < len - 1 i len - 1 len 1 i++ i++ i {
            if(numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1]) answer++;
            if(numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1]) answer++;
        } {
            if(numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1]) answer++;
            if(numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1]) answer++;
        } if(numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1]) answer++; numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1] numbers[i-1] < numbers[i] numbers[i-1] numbers i-1 i 1 numbers[i] numbers i numbers[i] < numbers[i+1] numbers[i] numbers i numbers[i+1] numbers i+1 i 1 answer++ answer if(numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1]) answer++; numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1] numbers[i-1] > numbers[i] numbers[i-1] numbers i-1 i 1 numbers[i] numbers i numbers[i] > numbers[i+1] numbers[i] numbers i numbers[i+1] numbers i+1 i 1 answer++ answer System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int len = scanner.nextInt();
        int[] numbers = new int[len];
        for(int i = 0; i < len ; i++) {
            numbers[i] = scanner.nextInt();
        }
        int answer = 0;
        for (int i = 1; i < len - 1 ; i++) {
            if(numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1]) answer++;
            if(numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1]) answer++;
        }
        System.out.println(answer);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int len = scanner.nextInt();
        int[] numbers = new int[len];
        for(int i = 0; i < len ; i++) {
            numbers[i] = scanner.nextInt();
        }
        int answer = 0;
        for (int i = 1; i < len - 1 ; i++) {
            if(numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1]) answer++;
            if(numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1]) answer++;
        }
        System.out.println(answer);
    }
} Main

import java.util.Scanner;

/**
 * @author yoshizaki
 * ABC 132
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int len = scanner.nextInt();
        int[] numbers = new int[len];
        for(int i = 0; i < len ; i++) {
            numbers[i] = scanner.nextInt();
        }
        int answer = 0;
        for (int i = 1; i < len - 1 ; i++) {
            if(numbers[i-1] < numbers[i] && numbers[i] < numbers[i+1]) answer++;
            if(numbers[i-1] > numbers[i] && numbers[i] > numbers[i+1]) answer++;
        }
        System.out.println(answer);
    }
}