import java.util.ArrayList;
import java.util.Collections;
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 = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int ans = 0;
        for (int i = 0; i < n - 2; i++) {
            List<Integer> list = new ArrayList<>();
            int tmp = 0;
            for (int j = 0; j < 3; j++) {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            }
            Collections.sort(list);
            if(list.get(1) == tmp) ans++;
        }
        System.out.println(ans);
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections 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 = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int ans = 0;
        for (int i = 0; i < n - 2; i++) {
            List<Integer> list = new ArrayList<>();
            int tmp = 0;
            for (int j = 0; j < 3; j++) {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            }
            Collections.sort(list);
            if(list.get(1) == tmp) ans++;
        }
        System.out.println(ans);
    }
} 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 ans = 0;
        for (int i = 0; i < n - 2; i++) {
            List<Integer> list = new ArrayList<>();
            int tmp = 0;
            for (int j = 0; j < 3; j++) {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            }
            Collections.sort(list);
            if(list.get(1) == tmp) ans++;
        }
        System.out.println(ans);
    } 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 ans = 0;
        for (int i = 0; i < n - 2; i++) {
            List<Integer> list = new ArrayList<>();
            int tmp = 0;
            for (int j = 0; j < 3; j++) {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            }
            Collections.sort(list);
            if(list.get(1) == tmp) ans++;
        }
        System.out.println(ans);
    } 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 ans = 0; ans 0 for (int i = 0; i < n - 2; i++) {
            List<Integer> list = new ArrayList<>();
            int tmp = 0;
            for (int j = 0; j < 3; j++) {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            }
            Collections.sort(list);
            if(list.get(1) == tmp) ans++;
        } int i = 0; int i = 0; i 0 i < n - 2 i n - 2 n 2 i++ i++ i {
            List<Integer> list = new ArrayList<>();
            int tmp = 0;
            for (int j = 0; j < 3; j++) {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            }
            Collections.sort(list);
            if(list.get(1) == tmp) ans++;
        } {
            List<Integer> list = new ArrayList<>();
            int tmp = 0;
            for (int j = 0; j < 3; j++) {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            }
            Collections.sort(list);
            if(list.get(1) == tmp) ans++;
        } List<Integer> list = new ArrayList<>(); list new ArrayList<>() int tmp = 0; tmp 0 for (int j = 0; j < 3; j++) {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            } int j = 0; int j = 0; j 0 j < 3 j 3 j++ j++ j {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            } {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            } list.add(p[i + j]) list.add list p[i + j] p i + j i j if(j == 1) {
                    tmp = p[i + j];
                } j == 1 j 1 {
                    tmp = p[i + j];
                } tmp = p[i + j] tmp p[i + j] p i + j i j Collections.sort(list) Collections.sort Collections list if(list.get(1) == tmp) ans++; list.get(1) == tmp list.get(1) list.get list 1 tmp ans++ ans System.out.println(ans) System.out.println System.out System System.out ans 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 ans = 0;
        for (int i = 0; i < n - 2; i++) {
            List<Integer> list = new ArrayList<>();
            int tmp = 0;
            for (int j = 0; j < 3; j++) {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            }
            Collections.sort(list);
            if(list.get(1) == tmp) ans++;
        }
        System.out.println(ans);
    }
} 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 ans = 0;
        for (int i = 0; i < n - 2; i++) {
            List<Integer> list = new ArrayList<>();
            int tmp = 0;
            for (int j = 0; j < 3; j++) {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            }
            Collections.sort(list);
            if(list.get(1) == tmp) ans++;
        }
        System.out.println(ans);
    }
} Main
import java.util.ArrayList;
import java.util.Collections;
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 = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int ans = 0;
        for (int i = 0; i < n - 2; i++) {
            List<Integer> list = new ArrayList<>();
            int tmp = 0;
            for (int j = 0; j < 3; j++) {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            }
            Collections.sort(list);
            if(list.get(1) == tmp) ans++;
        }
        System.out.println(ans);
    }
}
