import java.util.*; 

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 c=0;c<n;c++){
    		p[c]=sc.nextInt();
    	}
  		int ans=0;
    	for(int d=0;d<n-2;d++){
        	if(p[d]<p[d+1]&&p[d+1]<p[d+2]){
            	ans++;
            }else if(p[d+2]<p[d+1]&&p[d+1]<p[d]){
            	ans++;
            }
        }

    	System.out.println(ans);
    }
} import java.util.*; util.* java 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 c=0;c<n;c++){
    		p[c]=sc.nextInt();
    	}
  		int ans=0;
    	for(int d=0;d<n-2;d++){
        	if(p[d]<p[d+1]&&p[d+1]<p[d+2]){
            	ans++;
            }else if(p[d+2]<p[d+1]&&p[d+1]<p[d]){
            	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 c=0;c<n;c++){
    		p[c]=sc.nextInt();
    	}
  		int ans=0;
    	for(int d=0;d<n-2;d++){
        	if(p[d]<p[d+1]&&p[d+1]<p[d+2]){
            	ans++;
            }else if(p[d+2]<p[d+1]&&p[d+1]<p[d]){
            	ans++;
            }
        }

    	System.out.println(ans);
    } main {
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

  		int[] p=new int[n];
		for(int c=0;c<n;c++){
    		p[c]=sc.nextInt();
    	}
  		int ans=0;
    	for(int d=0;d<n-2;d++){
        	if(p[d]<p[d+1]&&p[d+1]<p[d+2]){
            	ans++;
            }else if(p[d+2]<p[d+1]&&p[d+1]<p[d]){
            	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 c=0;c<n;c++){
    		p[c]=sc.nextInt();
    	} int c=0; int c=0; c 0 c<n c n c++ c++ c {
    		p[c]=sc.nextInt();
    	} {
    		p[c]=sc.nextInt();
    	} p[c]=sc.nextInt() p[c] p c sc.nextInt() sc.nextInt sc int ans=0; ans 0 for(int d=0;d<n-2;d++){
        	if(p[d]<p[d+1]&&p[d+1]<p[d+2]){
            	ans++;
            }else if(p[d+2]<p[d+1]&&p[d+1]<p[d]){
            	ans++;
            }
        } int d=0; int d=0; d 0 d<n-2 d n-2 n 2 d++ d++ d {
        	if(p[d]<p[d+1]&&p[d+1]<p[d+2]){
            	ans++;
            }else if(p[d+2]<p[d+1]&&p[d+1]<p[d]){
            	ans++;
            }
        } {
        	if(p[d]<p[d+1]&&p[d+1]<p[d+2]){
            	ans++;
            }else if(p[d+2]<p[d+1]&&p[d+1]<p[d]){
            	ans++;
            }
        } if(p[d]<p[d+1]&&p[d+1]<p[d+2]){
            	ans++;
            }else if(p[d+2]<p[d+1]&&p[d+1]<p[d]){
            	ans++;
            } p[d]<p[d+1]&&p[d+1]<p[d+2] p[d]<p[d+1] p[d] p d p[d+1] p d+1 d 1 p[d+1]<p[d+2] p[d+1] p d+1 d 1 p[d+2] p d+2 d 2 {
            	ans++;
            } ans++ ans if(p[d+2]<p[d+1]&&p[d+1]<p[d]){
            	ans++;
            } p[d+2]<p[d+1]&&p[d+1]<p[d] p[d+2]<p[d+1] p[d+2] p d+2 d 2 p[d+1] p d+1 d 1 p[d+1]<p[d] p[d+1] p d+1 d 1 p[d] p d {
            	ans++;
            } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.*; 

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 c=0;c<n;c++){
    		p[c]=sc.nextInt();
    	}
  		int ans=0;
    	for(int d=0;d<n-2;d++){
        	if(p[d]<p[d+1]&&p[d+1]<p[d+2]){
            	ans++;
            }else if(p[d+2]<p[d+1]&&p[d+1]<p[d]){
            	ans++;
            }
        }

    	System.out.println(ans);
    }
}