import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Integer> integers = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            integers.add(Integer.valueOf(scanner.nextInt()));
        }
        int result = 0;
        for(int i = 0; i < integers.size() - 2; i++){
            int p1 = integers.get(i);
            int p2 = integers.get(i+1);
            int p3 = integers.get(i+2);
            if(p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1)
                result++;
        }
        System.out.println(result);
    }
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Integer> integers = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            integers.add(Integer.valueOf(scanner.nextInt()));
        }
        int result = 0;
        for(int i = 0; i < integers.size() - 2; i++){
            int p1 = integers.get(i);
            int p2 = integers.get(i+1);
            int p3 = integers.get(i+2);
            if(p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1)
                result++;
        }
        System.out.println(result);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Integer> integers = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            integers.add(Integer.valueOf(scanner.nextInt()));
        }
        int result = 0;
        for(int i = 0; i < integers.size() - 2; i++){
            int p1 = integers.get(i);
            int p2 = integers.get(i+1);
            int p3 = integers.get(i+2);
            if(p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1)
                result++;
        }
        System.out.println(result);
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Integer> integers = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            integers.add(Integer.valueOf(scanner.nextInt()));
        }
        int result = 0;
        for(int i = 0; i < integers.size() - 2; i++){
            int p1 = integers.get(i);
            int p2 = integers.get(i+1);
            int p3 = integers.get(i+2);
            if(p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1)
                result++;
        }
        System.out.println(result);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner List<Integer> integers = new ArrayList<>(); integers new ArrayList<>() for(int i = 0; i < n; i++) {
            integers.add(Integer.valueOf(scanner.nextInt()));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            integers.add(Integer.valueOf(scanner.nextInt()));
        } {
            integers.add(Integer.valueOf(scanner.nextInt()));
        } integers.add(Integer.valueOf(scanner.nextInt())) integers.add integers Integer.valueOf(scanner.nextInt()) Integer.valueOf Integer scanner.nextInt() scanner.nextInt scanner int result = 0; result 0 for(int i = 0; i < integers.size() - 2; i++){
            int p1 = integers.get(i);
            int p2 = integers.get(i+1);
            int p3 = integers.get(i+2);
            if(p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1)
                result++;
        } int i = 0; int i = 0; i 0 i < integers.size() - 2 i integers.size() - 2 integers.size() integers.size integers 2 i++ i++ i {
            int p1 = integers.get(i);
            int p2 = integers.get(i+1);
            int p3 = integers.get(i+2);
            if(p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1)
                result++;
        } {
            int p1 = integers.get(i);
            int p2 = integers.get(i+1);
            int p3 = integers.get(i+2);
            if(p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1)
                result++;
        } int p1 = integers.get(i); p1 integers.get(i) integers.get integers i int p2 = integers.get(i+1); p2 integers.get(i+1) integers.get integers i+1 i 1 int p3 = integers.get(i+2); p3 integers.get(i+2) integers.get integers i+2 i 2 if(p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1)
                result++; p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1 p1 < p2 && p2 < p3 p1 < p2 p1 p2 p2 < p3 p2 p3 p3 < p2 && p2 < p1 p3 < p2 p3 p2 p2 < p1 p2 p1 result++ result System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Integer> integers = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            integers.add(Integer.valueOf(scanner.nextInt()));
        }
        int result = 0;
        for(int i = 0; i < integers.size() - 2; i++){
            int p1 = integers.get(i);
            int p2 = integers.get(i+1);
            int p3 = integers.get(i+2);
            if(p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1)
                result++;
        }
        System.out.println(result);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Integer> integers = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            integers.add(Integer.valueOf(scanner.nextInt()));
        }
        int result = 0;
        for(int i = 0; i < integers.size() - 2; i++){
            int p1 = integers.get(i);
            int p2 = integers.get(i+1);
            int p3 = integers.get(i+2);
            if(p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1)
                result++;
        }
        System.out.println(result);
    }
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Integer> integers = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            integers.add(Integer.valueOf(scanner.nextInt()));
        }
        int result = 0;
        for(int i = 0; i < integers.size() - 2; i++){
            int p1 = integers.get(i);
            int p2 = integers.get(i+1);
            int p3 = integers.get(i+2);
            if(p1 < p2 && p2 < p3 || p3 < p2 && p2 < p1)
                result++;
        }
        System.out.println(result);
    }
}