import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int counter = 0;
        for (int i = 0; i < p.length - 2; i++) {
            int min = p[i];
            int max = p[i];
            for (int j = i; j < i + 3; j++) {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            }
            if (p[i + 1] != min && p[i + 1] != max) {
                counter++;
            }
        }
        System.out.println(counter);
        sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int counter = 0;
        for (int i = 0; i < p.length - 2; i++) {
            int min = p[i];
            int max = p[i];
            for (int j = i; j < i + 3; j++) {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            }
            if (p[i + 1] != min && p[i + 1] != max) {
                counter++;
            }
        }
        System.out.println(counter);
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int counter = 0;
        for (int i = 0; i < p.length - 2; i++) {
            int min = p[i];
            int max = p[i];
            for (int j = i; j < i + 3; j++) {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            }
            if (p[i + 1] != min && p[i + 1] != max) {
                counter++;
            }
        }
        System.out.println(counter);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int counter = 0;
        for (int i = 0; i < p.length - 2; i++) {
            int min = p[i];
            int max = p[i];
            for (int j = i; j < i + 3; j++) {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            }
            if (p[i + 1] != min && p[i + 1] != max) {
                counter++;
            }
        }
        System.out.println(counter);
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] p = new int[n]; p new int[n] n for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < p.length i p.length p p.length i++ i++ i {
            p[i] = sc.nextInt();
        } {
            p[i] = sc.nextInt();
        } p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc int counter = 0; counter 0 for (int i = 0; i < p.length - 2; i++) {
            int min = p[i];
            int max = p[i];
            for (int j = i; j < i + 3; j++) {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            }
            if (p[i + 1] != min && p[i + 1] != max) {
                counter++;
            }
        } int i = 0; int i = 0; i 0 i < p.length - 2 i p.length - 2 p.length p p.length 2 i++ i++ i {
            int min = p[i];
            int max = p[i];
            for (int j = i; j < i + 3; j++) {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            }
            if (p[i + 1] != min && p[i + 1] != max) {
                counter++;
            }
        } {
            int min = p[i];
            int max = p[i];
            for (int j = i; j < i + 3; j++) {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            }
            if (p[i + 1] != min && p[i + 1] != max) {
                counter++;
            }
        } int min = p[i]; min p[i] p i int max = p[i]; max p[i] p i for (int j = i; j < i + 3; j++) {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            } int j = i; int j = i; j i j < i + 3 j i + 3 i 3 j++ j++ j {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            } {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            } min = Math.min(min, p[j]) min Math.min(min, p[j]) Math.min Math min p[j] p j max = Math.max(max, p[j]) max Math.max(max, p[j]) Math.max Math max p[j] p j if (p[i + 1] != min && p[i + 1] != max) {
                counter++;
            } p[i + 1] != min && p[i + 1] != max p[i + 1] != min p[i + 1] p i + 1 i 1 min p[i + 1] != max p[i + 1] p i + 1 i 1 max {
                counter++;
            } counter++ counter System.out.println(counter) System.out.println System.out System System.out counter sc.close() sc.close sc String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int counter = 0;
        for (int i = 0; i < p.length - 2; i++) {
            int min = p[i];
            int max = p[i];
            for (int j = i; j < i + 3; j++) {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            }
            if (p[i + 1] != min && p[i + 1] != max) {
                counter++;
            }
        }
        System.out.println(counter);
        sc.close();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int counter = 0;
        for (int i = 0; i < p.length - 2; i++) {
            int min = p[i];
            int max = p[i];
            for (int j = i; j < i + 3; j++) {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            }
            if (p[i + 1] != min && p[i + 1] != max) {
                counter++;
            }
        }
        System.out.println(counter);
        sc.close();
    }
} Main
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int counter = 0;
        for (int i = 0; i < p.length - 2; i++) {
            int min = p[i];
            int max = p[i];
            for (int j = i; j < i + 3; j++) {
                min = Math.min(min, p[j]);
                max = Math.max(max, p[j]);
            }
            if (p[i + 1] != min && p[i + 1] != max) {
                counter++;
            }
        }
        System.out.println(counter);
        sc.close();
    }
}