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 = Integer.parseInt(sc.next());
        int cnt = 0;
        List<Integer> sortAry = new ArrayList<>();
        int[] ary = new int[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i+2 < n; i++) {
            sortAry.add(ary[i]);
            sortAry.add(ary[i+1]);
            sortAry.add(ary[i+2]);
            Collections.sort(sortAry);
            if (ary[i+1] == sortAry.get(1)) {
                cnt++;
            }
            sortAry.clear();
        }
        System.out.println(cnt);
    }
} 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 = Integer.parseInt(sc.next());
        int cnt = 0;
        List<Integer> sortAry = new ArrayList<>();
        int[] ary = new int[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i+2 < n; i++) {
            sortAry.add(ary[i]);
            sortAry.add(ary[i+1]);
            sortAry.add(ary[i+2]);
            Collections.sort(sortAry);
            if (ary[i+1] == sortAry.get(1)) {
                cnt++;
            }
            sortAry.clear();
        }
        System.out.println(cnt);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int cnt = 0;
        List<Integer> sortAry = new ArrayList<>();
        int[] ary = new int[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i+2 < n; i++) {
            sortAry.add(ary[i]);
            sortAry.add(ary[i+1]);
            sortAry.add(ary[i+2]);
            Collections.sort(sortAry);
            if (ary[i+1] == sortAry.get(1)) {
                cnt++;
            }
            sortAry.clear();
        }
        System.out.println(cnt);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int cnt = 0;
        List<Integer> sortAry = new ArrayList<>();
        int[] ary = new int[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i+2 < n; i++) {
            sortAry.add(ary[i]);
            sortAry.add(ary[i+1]);
            sortAry.add(ary[i+2]);
            Collections.sort(sortAry);
            if (ary[i+1] == sortAry.get(1)) {
                cnt++;
            }
            sortAry.clear();
        }
        System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int cnt = 0; cnt 0 List<Integer> sortAry = new ArrayList<>(); sortAry new ArrayList<>() int[] ary = new int[n]; ary new int[n] n for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            ary[i] = Integer.parseInt(sc.next());
        } {
            ary[i] = Integer.parseInt(sc.next());
        } ary[i] = Integer.parseInt(sc.next()) ary[i] ary i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for (int i = 0; i+2 < n; i++) {
            sortAry.add(ary[i]);
            sortAry.add(ary[i+1]);
            sortAry.add(ary[i+2]);
            Collections.sort(sortAry);
            if (ary[i+1] == sortAry.get(1)) {
                cnt++;
            }
            sortAry.clear();
        } int i = 0; int i = 0; i 0 i+2 < n i+2 i 2 n i++ i++ i {
            sortAry.add(ary[i]);
            sortAry.add(ary[i+1]);
            sortAry.add(ary[i+2]);
            Collections.sort(sortAry);
            if (ary[i+1] == sortAry.get(1)) {
                cnt++;
            }
            sortAry.clear();
        } {
            sortAry.add(ary[i]);
            sortAry.add(ary[i+1]);
            sortAry.add(ary[i+2]);
            Collections.sort(sortAry);
            if (ary[i+1] == sortAry.get(1)) {
                cnt++;
            }
            sortAry.clear();
        } sortAry.add(ary[i]) sortAry.add sortAry ary[i] ary i sortAry.add(ary[i+1]) sortAry.add sortAry ary[i+1] ary i+1 i 1 sortAry.add(ary[i+2]) sortAry.add sortAry ary[i+2] ary i+2 i 2 Collections.sort(sortAry) Collections.sort Collections sortAry if (ary[i+1] == sortAry.get(1)) {
                cnt++;
            } ary[i+1] == sortAry.get(1) ary[i+1] ary i+1 i 1 sortAry.get(1) sortAry.get sortAry 1 {
                cnt++;
            } cnt++ cnt sortAry.clear() sortAry.clear sortAry System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int cnt = 0;
        List<Integer> sortAry = new ArrayList<>();
        int[] ary = new int[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i+2 < n; i++) {
            sortAry.add(ary[i]);
            sortAry.add(ary[i+1]);
            sortAry.add(ary[i+2]);
            Collections.sort(sortAry);
            if (ary[i+1] == sortAry.get(1)) {
                cnt++;
            }
            sortAry.clear();
        }
        System.out.println(cnt);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int cnt = 0;
        List<Integer> sortAry = new ArrayList<>();
        int[] ary = new int[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i+2 < n; i++) {
            sortAry.add(ary[i]);
            sortAry.add(ary[i+1]);
            sortAry.add(ary[i+2]);
            Collections.sort(sortAry);
            if (ary[i+1] == sortAry.get(1)) {
                cnt++;
            }
            sortAry.clear();
        }
        System.out.println(cnt);
    }
} 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 = Integer.parseInt(sc.next());
        int cnt = 0;
        List<Integer> sortAry = new ArrayList<>();
        int[] ary = new int[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i+2 < n; i++) {
            sortAry.add(ary[i]);
            sortAry.add(ary[i+1]);
            sortAry.add(ary[i+2]);
            Collections.sort(sortAry);
            if (ary[i+1] == sortAry.get(1)) {
                cnt++;
            }
            sortAry.clear();
        }
        System.out.println(cnt);
    }
}