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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        List<Integer> nums = new ArrayList<>();
        for(int i = 0;i < n;i++) {
            nums.add(sc.nextInt());
        }
        int r = 0;
        for(int i = 1;i < n - 1;i++){
            int p1 = nums.get(i - 1);
            int p2 = nums.get(i);
            int p3 = nums.get(i + 1);
            if(p1 > p2 && p2 > p3){
                r++;
            }else if(p3 > p2 && p2 > p1){
                r++;
            }
        }
        System.out.println(r);
    }
} 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 sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        List<Integer> nums = new ArrayList<>();
        for(int i = 0;i < n;i++) {
            nums.add(sc.nextInt());
        }
        int r = 0;
        for(int i = 1;i < n - 1;i++){
            int p1 = nums.get(i - 1);
            int p2 = nums.get(i);
            int p3 = nums.get(i + 1);
            if(p1 > p2 && p2 > p3){
                r++;
            }else if(p3 > p2 && p2 > p1){
                r++;
            }
        }
        System.out.println(r);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        List<Integer> nums = new ArrayList<>();
        for(int i = 0;i < n;i++) {
            nums.add(sc.nextInt());
        }
        int r = 0;
        for(int i = 1;i < n - 1;i++){
            int p1 = nums.get(i - 1);
            int p2 = nums.get(i);
            int p3 = nums.get(i + 1);
            if(p1 > p2 && p2 > p3){
                r++;
            }else if(p3 > p2 && p2 > p1){
                r++;
            }
        }
        System.out.println(r);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        List<Integer> nums = new ArrayList<>();
        for(int i = 0;i < n;i++) {
            nums.add(sc.nextInt());
        }
        int r = 0;
        for(int i = 1;i < n - 1;i++){
            int p1 = nums.get(i - 1);
            int p2 = nums.get(i);
            int p3 = nums.get(i + 1);
            if(p1 > p2 && p2 > p3){
                r++;
            }else if(p3 > p2 && p2 > p1){
                r++;
            }
        }
        System.out.println(r);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.nextLine()); n Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc List<Integer> nums = new ArrayList<>(); nums new ArrayList<>() for(int i = 0;i < n;i++) {
            nums.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            nums.add(sc.nextInt());
        } {
            nums.add(sc.nextInt());
        } nums.add(sc.nextInt()) nums.add nums sc.nextInt() sc.nextInt sc int r = 0; r 0 for(int i = 1;i < n - 1;i++){
            int p1 = nums.get(i - 1);
            int p2 = nums.get(i);
            int p3 = nums.get(i + 1);
            if(p1 > p2 && p2 > p3){
                r++;
            }else if(p3 > p2 && p2 > p1){
                r++;
            }
        } int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
            int p1 = nums.get(i - 1);
            int p2 = nums.get(i);
            int p3 = nums.get(i + 1);
            if(p1 > p2 && p2 > p3){
                r++;
            }else if(p3 > p2 && p2 > p1){
                r++;
            }
        } {
            int p1 = nums.get(i - 1);
            int p2 = nums.get(i);
            int p3 = nums.get(i + 1);
            if(p1 > p2 && p2 > p3){
                r++;
            }else if(p3 > p2 && p2 > p1){
                r++;
            }
        } int p1 = nums.get(i - 1); p1 nums.get(i - 1) nums.get nums i - 1 i 1 int p2 = nums.get(i); p2 nums.get(i) nums.get nums i int p3 = nums.get(i + 1); p3 nums.get(i + 1) nums.get nums i + 1 i 1 if(p1 > p2 && p2 > p3){
                r++;
            }else if(p3 > p2 && p2 > p1){
                r++;
            } p1 > p2 && p2 > p3 p1 > p2 p1 p2 p2 > p3 p2 p3 {
                r++;
            } r++ r if(p3 > p2 && p2 > p1){
                r++;
            } p3 > p2 && p2 > p1 p3 > p2 p3 p2 p2 > p1 p2 p1 {
                r++;
            } r++ r System.out.println(r) System.out.println System.out System System.out r String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        List<Integer> nums = new ArrayList<>();
        for(int i = 0;i < n;i++) {
            nums.add(sc.nextInt());
        }
        int r = 0;
        for(int i = 1;i < n - 1;i++){
            int p1 = nums.get(i - 1);
            int p2 = nums.get(i);
            int p3 = nums.get(i + 1);
            if(p1 > p2 && p2 > p3){
                r++;
            }else if(p3 > p2 && p2 > p1){
                r++;
            }
        }
        System.out.println(r);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        List<Integer> nums = new ArrayList<>();
        for(int i = 0;i < n;i++) {
            nums.add(sc.nextInt());
        }
        int r = 0;
        for(int i = 1;i < n - 1;i++){
            int p1 = nums.get(i - 1);
            int p2 = nums.get(i);
            int p3 = nums.get(i + 1);
            if(p1 > p2 && p2 > p3){
                r++;
            }else if(p3 > p2 && p2 > p1){
                r++;
            }
        }
        System.out.println(r);
    }
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        List<Integer> nums = new ArrayList<>();
        for(int i = 0;i < n;i++) {
            nums.add(sc.nextInt());
        }
        int r = 0;
        for(int i = 1;i < n - 1;i++){
            int p1 = nums.get(i - 1);
            int p2 = nums.get(i);
            int p3 = nums.get(i + 1);
            if(p1 > p2 && p2 > p3){
                r++;
            }else if(p3 > p2 && p2 > p1){
                r++;
            }
        }
        System.out.println(r);
    }
}