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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arrayList.add(scanner.nextInt());
        }
        int cnt = 0;
        for (int i = 1; i < n-1; i++) {
            if(arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1)) cnt++;
        }
        System.out.println(cnt);
    }
} import java.util.ArrayList; ArrayList 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();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arrayList.add(scanner.nextInt());
        }
        int cnt = 0;
        for (int i = 1; i < n-1; i++) {
            if(arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1)) cnt++;
        }
        System.out.println(cnt);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arrayList.add(scanner.nextInt());
        }
        int cnt = 0;
        for (int i = 1; i < n-1; i++) {
            if(arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1)) cnt++;
        }
        System.out.println(cnt);
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arrayList.add(scanner.nextInt());
        }
        int cnt = 0;
        for (int i = 1; i < n-1; i++) {
            if(arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1)) cnt++;
        }
        System.out.println(cnt);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner ArrayList<Integer> arrayList = new ArrayList<>(); arrayList new ArrayList<>() for (int i = 0; i < n; i++) {
            arrayList.add(scanner.nextInt());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            arrayList.add(scanner.nextInt());
        } {
            arrayList.add(scanner.nextInt());
        } arrayList.add(scanner.nextInt()) arrayList.add arrayList scanner.nextInt() scanner.nextInt scanner int cnt = 0; cnt 0 for (int i = 1; i < n-1; i++) {
            if(arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1)) cnt++;
        } int i = 1; int i = 1; i 1 i < n-1 i n-1 n 1 i++ i++ i {
            if(arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1)) cnt++;
        } {
            if(arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1)) cnt++;
        } if(arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1)) cnt++; arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1) arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) arrayList.get(i-1) < arrayList.get(i) arrayList.get(i-1) arrayList.get arrayList i-1 i 1 arrayList.get(i) arrayList.get arrayList i arrayList.get(i) < arrayList.get(i+1) arrayList.get(i) arrayList.get arrayList i arrayList.get(i+1) arrayList.get arrayList i+1 i 1 arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1) arrayList.get(i+1) < arrayList.get(i) arrayList.get(i+1) arrayList.get arrayList i+1 i 1 arrayList.get(i) arrayList.get arrayList i arrayList.get(i) < arrayList.get(i-1) arrayList.get(i) arrayList.get arrayList i arrayList.get(i-1) arrayList.get arrayList i-1 i 1 cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arrayList.add(scanner.nextInt());
        }
        int cnt = 0;
        for (int i = 1; i < n-1; i++) {
            if(arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1)) cnt++;
        }
        System.out.println(cnt);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arrayList.add(scanner.nextInt());
        }
        int cnt = 0;
        for (int i = 1; i < n-1; i++) {
            if(arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1)) cnt++;
        }
        System.out.println(cnt);
    }
} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            arrayList.add(scanner.nextInt());
        }
        int cnt = 0;
        for (int i = 1; i < n-1; i++) {
            if(arrayList.get(i-1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i+1) ||
                arrayList.get(i+1) < arrayList.get(i) && arrayList.get(i) < arrayList.get(i-1)) cnt++;
        }
        System.out.println(cnt);
    }
}
