
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = in.nextInt();
        }
        int way = 0;
        for (int i = 0; i < n - 2; i++) {
            if ((arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2])) {
                way++;
            }
        }
        System.out.println(way);
    }

} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = in.nextInt();
        }
        int way = 0;
        for (int i = 0; i < n - 2; i++) {
            if ((arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2])) {
                way++;
            }
        }
        System.out.println(way);
    }

} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = in.nextInt();
        }
        int way = 0;
        for (int i = 0; i < n - 2; i++) {
            if ((arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2])) {
                way++;
            }
        }
        System.out.println(way);
    } main {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = in.nextInt();
        }
        int way = 0;
        for (int i = 0; i < n - 2; i++) {
            if ((arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2])) {
                way++;
            }
        }
        System.out.println(way);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int[] arr = new int[n]; arr new int[n] n for (int i = 0; i < arr.length; i++) {
            arr[i] = in.nextInt();
        } int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i {
            arr[i] = in.nextInt();
        } {
            arr[i] = in.nextInt();
        } arr[i] = in.nextInt() arr[i] arr i in.nextInt() in.nextInt in int way = 0; way 0 for (int i = 0; i < n - 2; i++) {
            if ((arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2])) {
                way++;
            }
        } int i = 0; int i = 0; i 0 i < n - 2 i n - 2 n 2 i++ i++ i {
            if ((arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2])) {
                way++;
            }
        } {
            if ((arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2])) {
                way++;
            }
        } if ((arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2])) {
                way++;
            } (arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2]) (arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) arr[i] > arr[i + 1] arr[i] arr i arr[i + 1] arr i + 1 i 1 arr[i + 1] > arr[i + 2] arr[i + 1] arr i + 1 i 1 arr[i + 2] arr i + 2 i 2 (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2]) arr[i] < arr[i + 1] arr[i] arr i arr[i + 1] arr i + 1 i 1 arr[i + 1] < arr[i + 2] arr[i + 1] arr i + 1 i 1 arr[i + 2] arr i + 2 i 2 {
                way++;
            } way++ way System.out.println(way) System.out.println System.out System System.out way String[] args args public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = in.nextInt();
        }
        int way = 0;
        for (int i = 0; i < n - 2; i++) {
            if ((arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2])) {
                way++;
            }
        }
        System.out.println(way);
    }

} public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = in.nextInt();
        }
        int way = 0;
        for (int i = 0; i < n - 2; i++) {
            if ((arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2])) {
                way++;
            }
        }
        System.out.println(way);
    }

} Main

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = in.nextInt();
        }
        int way = 0;
        for (int i = 0; i < n - 2; i++) {
            if ((arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) || (arr[i] < arr[i + 1] && arr[i + 1] < arr[i + 2])) {
                way++;
            }
        }
        System.out.println(way);
    }

}
