
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        int cnt = 0;
        for (int i = 0; i < n; i++) ar[i] = sc.nextInt();
        for (int i = 0; i < n - 2; i++) {
            if (ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2] || ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2]) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        int cnt = 0;
        for (int i = 0; i < n; i++) ar[i] = sc.nextInt();
        for (int i = 0; i < n - 2; i++) {
            if (ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2] || ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2]) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
} Main void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        int cnt = 0;
        for (int i = 0; i < n; i++) ar[i] = sc.nextInt();
        for (int i = 0; i < n - 2; i++) {
            if (ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2] || ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2]) {
                cnt++;
            }
        }
        System.out.println(cnt);
    } run {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        int cnt = 0;
        for (int i = 0; i < n; i++) ar[i] = sc.nextInt();
        for (int i = 0; i < n - 2; i++) {
            if (ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2] || ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2]) {
                cnt++;
            }
        }
        System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] ar = new int[n]; ar new int[n] n int cnt = 0; cnt 0 for (int i = 0; i < n; i++) ar[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i ar[i] = sc.nextInt(); ar[i] = sc.nextInt() ar[i] ar i sc.nextInt() sc.nextInt sc for (int i = 0; i < n - 2; i++) {
            if (ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2] || ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2]) {
                cnt++;
            }
        } int i = 0; int i = 0; i 0 i < n - 2 i n - 2 n 2 i++ i++ i {
            if (ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2] || ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2]) {
                cnt++;
            }
        } {
            if (ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2] || ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2]) {
                cnt++;
            }
        } if (ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2] || ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2]) {
                cnt++;
            } ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2] || ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2] ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2] ar[i] < ar[i + 1] ar[i] ar i ar[i + 1] ar i + 1 i 1 ar[i + 1] < ar[i + 2] ar[i + 1] ar i + 1 i 1 ar[i + 2] ar i + 2 i 2 ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2] ar[i] > ar[i + 1] ar[i] ar i ar[i + 1] ar i + 1 i 1 ar[i + 1] > ar[i + 2] ar[i + 1] ar i + 1 i 1 ar[i + 2] ar i + 2 i 2 {
                cnt++;
            } cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    } debug {
        System.err.println(Arrays.deepToString(os));
    } System.err.println(Arrays.deepToString(os)) System.err.println System.err System System.err Arrays.deepToString(os) Arrays.deepToString Arrays os Object... os os public static void main(String[] args) {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        int cnt = 0;
        for (int i = 0; i < n; i++) ar[i] = sc.nextInt();
        for (int i = 0; i < n - 2; i++) {
            if (ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2] || ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2]) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
} Main

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        int cnt = 0;
        for (int i = 0; i < n; i++) ar[i] = sc.nextInt();
        for (int i = 0; i < n - 2; i++) {
            if (ar[i] < ar[i + 1] && ar[i + 1] < ar[i + 2] || ar[i] > ar[i + 1] && ar[i + 1] > ar[i + 2]) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}
