import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i<n; i++){
            list.add(sc.nextInt());
        }

        int answer =0;
        for (int i = 0; i < n-2; i++){
            if (secondIsMedium(list.get(i), list.get(i+1), list.get(i+2))){
                answer++;
            }
        }

        System.out.println(answer);
    }

    private static boolean secondIsMedium(int one, int two, int three){
        return (one < two && two < three) || (one > two && two > three);
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i<n; i++){
            list.add(sc.nextInt());
        }

        int answer =0;
        for (int i = 0; i < n-2; i++){
            if (secondIsMedium(list.get(i), list.get(i+1), list.get(i+2))){
                answer++;
            }
        }

        System.out.println(answer);
    }

    private static boolean secondIsMedium(int one, int two, int three){
        return (one < two && two < three) || (one > two && two > three);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i<n; i++){
            list.add(sc.nextInt());
        }

        int answer =0;
        for (int i = 0; i < n-2; i++){
            if (secondIsMedium(list.get(i), list.get(i+1), list.get(i+2))){
                answer++;
            }
        }

        System.out.println(answer);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i<n; i++){
            list.add(sc.nextInt());
        }

        int answer =0;
        for (int i = 0; i < n-2; i++){
            if (secondIsMedium(list.get(i), list.get(i+1), list.get(i+2))){
                answer++;
            }
        }

        System.out.println(answer);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc List<Integer> list = new ArrayList<>(); list new ArrayList<>() for (int i = 0; i<n; i++){
            list.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            list.add(sc.nextInt());
        } {
            list.add(sc.nextInt());
        } list.add(sc.nextInt()) list.add list sc.nextInt() sc.nextInt sc int answer =0; answer 0 for (int i = 0; i < n-2; i++){
            if (secondIsMedium(list.get(i), list.get(i+1), list.get(i+2))){
                answer++;
            }
        } int i = 0; int i = 0; i 0 i < n-2 i n-2 n 2 i++ i++ i {
            if (secondIsMedium(list.get(i), list.get(i+1), list.get(i+2))){
                answer++;
            }
        } {
            if (secondIsMedium(list.get(i), list.get(i+1), list.get(i+2))){
                answer++;
            }
        } if (secondIsMedium(list.get(i), list.get(i+1), list.get(i+2))){
                answer++;
            } secondIsMedium(list.get(i), list.get(i+1), list.get(i+2)) secondIsMedium list.get(i) list.get list i list.get(i+1) list.get list i+1 i 1 list.get(i+2) list.get list i+2 i 2 {
                answer++;
            } answer++ answer System.out.println(answer) System.out.println System.out System System.out answer String[] args args private static boolean secondIsMedium(int one, int two, int three){
        return (one < two && two < three) || (one > two && two > three);
    } secondIsMedium {
        return (one < two && two < three) || (one > two && two > three);
    } return (one < two && two < three) || (one > two && two > three); (one < two && two < three) || (one > two && two > three) (one < two && two < three) one < two one two two < three two three (one > two && two > three) one > two one two two > three two three int one one int two two int three three public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i<n; i++){
            list.add(sc.nextInt());
        }

        int answer =0;
        for (int i = 0; i < n-2; i++){
            if (secondIsMedium(list.get(i), list.get(i+1), list.get(i+2))){
                answer++;
            }
        }

        System.out.println(answer);
    }

    private static boolean secondIsMedium(int one, int two, int three){
        return (one < two && two < three) || (one > two && two > three);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i<n; i++){
            list.add(sc.nextInt());
        }

        int answer =0;
        for (int i = 0; i < n-2; i++){
            if (secondIsMedium(list.get(i), list.get(i+1), list.get(i+2))){
                answer++;
            }
        }

        System.out.println(answer);
    }

    private static boolean secondIsMedium(int one, int two, int three){
        return (one < two && two < three) || (one > two && two > three);
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i<n; i++){
            list.add(sc.nextInt());
        }

        int answer =0;
        for (int i = 0; i < n-2; i++){
            if (secondIsMedium(list.get(i), list.get(i+1), list.get(i+2))){
                answer++;
            }
        }

        System.out.println(answer);
    }

    private static boolean secondIsMedium(int one, int two, int three){
        return (one < two && two < three) || (one > two && two > three);
    }
}