import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] ar = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < N-2; i++) {
            int max = Math.max(Math.max(ar[i], ar[i+1]), ar[i+2]);
            int min = Math.min(Math.min(ar[i], ar[i+1]), ar[i+2]);
            if (ar[i+1] != max && ar[i+1] != min) {
                count++;
            }
        }
        System.out.println(count);
    }
} import java.util.*; util.* java public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] ar = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < N-2; i++) {
            int max = Math.max(Math.max(ar[i], ar[i+1]), ar[i+2]);
            int min = Math.min(Math.min(ar[i], ar[i+1]), ar[i+2]);
            if (ar[i+1] != max && ar[i+1] != min) {
                count++;
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] ar = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < N-2; i++) {
            int max = Math.max(Math.max(ar[i], ar[i+1]), ar[i+2]);
            int min = Math.min(Math.min(ar[i], ar[i+1]), ar[i+2]);
            if (ar[i+1] != max && ar[i+1] != min) {
                count++;
            }
        }
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] ar = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < N-2; i++) {
            int max = Math.max(Math.max(ar[i], ar[i+1]), ar[i+2]);
            int min = Math.min(Math.min(ar[i], ar[i+1]), ar[i+2]);
            if (ar[i+1] != max && ar[i+1] != min) {
                count++;
            }
        }
        System.out.println(count);
    } 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 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] = sc.nextInt() ar[i] ar i sc.nextInt() sc.nextInt sc int count = 0; count 0 for (int i = 0; i < N-2; i++) {
            int max = Math.max(Math.max(ar[i], ar[i+1]), ar[i+2]);
            int min = Math.min(Math.min(ar[i], ar[i+1]), ar[i+2]);
            if (ar[i+1] != max && ar[i+1] != min) {
                count++;
            }
        } int i = 0; int i = 0; i 0 i < N-2 i N-2 N 2 i++ i++ i {
            int max = Math.max(Math.max(ar[i], ar[i+1]), ar[i+2]);
            int min = Math.min(Math.min(ar[i], ar[i+1]), ar[i+2]);
            if (ar[i+1] != max && ar[i+1] != min) {
                count++;
            }
        } {
            int max = Math.max(Math.max(ar[i], ar[i+1]), ar[i+2]);
            int min = Math.min(Math.min(ar[i], ar[i+1]), ar[i+2]);
            if (ar[i+1] != max && ar[i+1] != min) {
                count++;
            }
        } int max = Math.max(Math.max(ar[i], ar[i+1]), ar[i+2]); max Math.max(Math.max(ar[i], ar[i+1]), ar[i+2]) Math.max Math Math.max(ar[i], ar[i+1]) Math.max Math ar[i] ar i ar[i+1] ar i+1 i 1 ar[i+2] ar i+2 i 2 int min = Math.min(Math.min(ar[i], ar[i+1]), ar[i+2]); min Math.min(Math.min(ar[i], ar[i+1]), ar[i+2]) Math.min Math Math.min(ar[i], ar[i+1]) Math.min Math ar[i] ar i ar[i+1] ar i+1 i 1 ar[i+2] ar i+2 i 2 if (ar[i+1] != max && ar[i+1] != min) {
                count++;
            } ar[i+1] != max && ar[i+1] != min ar[i+1] != max ar[i+1] ar i+1 i 1 max ar[i+1] != min ar[i+1] ar i+1 i 1 min {
                count++;
            } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] ar = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < N-2; i++) {
            int max = Math.max(Math.max(ar[i], ar[i+1]), ar[i+2]);
            int min = Math.min(Math.min(ar[i], ar[i+1]), ar[i+2]);
            if (ar[i+1] != max && ar[i+1] != min) {
                count++;
            }
        }
        System.out.println(count);
    }
} public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] ar = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < N-2; i++) {
            int max = Math.max(Math.max(ar[i], ar[i+1]), ar[i+2]);
            int min = Math.min(Math.min(ar[i], ar[i+1]), ar[i+2]);
            if (ar[i+1] != max && ar[i+1] != min) {
                count++;
            }
        }
        System.out.println(count);
    }
} Main
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] ar = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < N-2; i++) {
            int max = Math.max(Math.max(ar[i], ar[i+1]), ar[i+2]);
            int min = Math.min(Math.min(ar[i], ar[i+1]), ar[i+2]);
            if (ar[i+1] != max && ar[i+1] != min) {
                count++;
            }
        }
        System.out.println(count);
    }
}