import java.util.*;

class Main{
    static int[] nums = new int[3];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        
        int cnt = 0;
        for(int i = 0; i < num; i++){
            next();
            nums[0] = sc.nextInt();
            if(i > 1){
                if(nums[1] == median3()){
                    ++cnt;
                }
            }
        }
        System.out.println(cnt);
    }

    public static int median3(){
        int[] tmpArr = {nums[0], nums[1], nums[2]};
        Arrays.sort(tmpArr);
        return tmpArr[1];
    }

    public static void next(){
        nums[2] = nums[1];
        nums[1] = nums[0];
    }
} import java.util.*; util.* java class Main{
    static int[] nums = new int[3];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        
        int cnt = 0;
        for(int i = 0; i < num; i++){
            next();
            nums[0] = sc.nextInt();
            if(i > 1){
                if(nums[1] == median3()){
                    ++cnt;
                }
            }
        }
        System.out.println(cnt);
    }

    public static int median3(){
        int[] tmpArr = {nums[0], nums[1], nums[2]};
        Arrays.sort(tmpArr);
        return tmpArr[1];
    }

    public static void next(){
        nums[2] = nums[1];
        nums[1] = nums[0];
    }
} Main static int[] nums = new int[3]; nums new int[3] 3 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        
        int cnt = 0;
        for(int i = 0; i < num; i++){
            next();
            nums[0] = sc.nextInt();
            if(i > 1){
                if(nums[1] == median3()){
                    ++cnt;
                }
            }
        }
        System.out.println(cnt);
    } main {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        
        int cnt = 0;
        for(int i = 0; i < num; i++){
            next();
            nums[0] = sc.nextInt();
            if(i > 1){
                if(nums[1] == median3()){
                    ++cnt;
                }
            }
        }
        System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc int cnt = 0; cnt 0 for(int i = 0; i < num; i++){
            next();
            nums[0] = sc.nextInt();
            if(i > 1){
                if(nums[1] == median3()){
                    ++cnt;
                }
            }
        } int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
            next();
            nums[0] = sc.nextInt();
            if(i > 1){
                if(nums[1] == median3()){
                    ++cnt;
                }
            }
        } {
            next();
            nums[0] = sc.nextInt();
            if(i > 1){
                if(nums[1] == median3()){
                    ++cnt;
                }
            }
        } next() next nums[0] = sc.nextInt() nums[0] nums 0 sc.nextInt() sc.nextInt sc if(i > 1){
                if(nums[1] == median3()){
                    ++cnt;
                }
            } i > 1 i 1 {
                if(nums[1] == median3()){
                    ++cnt;
                }
            } if(nums[1] == median3()){
                    ++cnt;
                } nums[1] == median3() nums[1] nums 1 median3() median3 {
                    ++cnt;
                } ++cnt cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public static int median3(){
        int[] tmpArr = {nums[0], nums[1], nums[2]};
        Arrays.sort(tmpArr);
        return tmpArr[1];
    } median3 {
        int[] tmpArr = {nums[0], nums[1], nums[2]};
        Arrays.sort(tmpArr);
        return tmpArr[1];
    } int[] tmpArr = {nums[0], nums[1], nums[2]}; tmpArr {nums[0], nums[1], nums[2]} nums[0] nums 0 nums[1] nums 1 nums[2] nums 2 Arrays.sort(tmpArr) Arrays.sort Arrays tmpArr return tmpArr[1]; tmpArr[1] tmpArr 1 public static void next(){
        nums[2] = nums[1];
        nums[1] = nums[0];
    } next {
        nums[2] = nums[1];
        nums[1] = nums[0];
    } nums[2] = nums[1] nums[2] nums 2 nums[1] nums 1 nums[1] = nums[0] nums[1] nums 1 nums[0] nums 0
import java.util.*;

class Main{
    static int[] nums = new int[3];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        
        int cnt = 0;
        for(int i = 0; i < num; i++){
            next();
            nums[0] = sc.nextInt();
            if(i > 1){
                if(nums[1] == median3()){
                    ++cnt;
                }
            }
        }
        System.out.println(cnt);
    }

    public static int median3(){
        int[] tmpArr = {nums[0], nums[1], nums[2]};
        Arrays.sort(tmpArr);
        return tmpArr[1];
    }

    public static void next(){
        nums[2] = nums[1];
        nums[1] = nums[0];
    }
}
