import java.util.*;
public class Main {

    public static void main(String[] args) {
     
        Scanner entrada=new Scanner(System.in);
        int k=entrada.nextInt();
        int x[]=new int[k];
        int x2[]=new int[3];
        int count=0;
        int count2=0;
        for (int i = 0; i < k; i++) {
            x[i]=entrada.nextInt();
        }
      
        for (int i = 0; i < k-2; i++) {
            for (int j = 0; j < 3; j++) {
            
           x2[j]=x[j+count];
          
        }
        count++;  
     Arrays.sort(x2);
         
       if(x[count]==x2[1]){
           count2++;
       
       }
       
       }
  System.out.println(count2);
    }
    
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
     
        Scanner entrada=new Scanner(System.in);
        int k=entrada.nextInt();
        int x[]=new int[k];
        int x2[]=new int[3];
        int count=0;
        int count2=0;
        for (int i = 0; i < k; i++) {
            x[i]=entrada.nextInt();
        }
      
        for (int i = 0; i < k-2; i++) {
            for (int j = 0; j < 3; j++) {
            
           x2[j]=x[j+count];
          
        }
        count++;  
     Arrays.sort(x2);
         
       if(x[count]==x2[1]){
           count2++;
       
       }
       
       }
  System.out.println(count2);
    }
    
} Main public static void main(String[] args) {
     
        Scanner entrada=new Scanner(System.in);
        int k=entrada.nextInt();
        int x[]=new int[k];
        int x2[]=new int[3];
        int count=0;
        int count2=0;
        for (int i = 0; i < k; i++) {
            x[i]=entrada.nextInt();
        }
      
        for (int i = 0; i < k-2; i++) {
            for (int j = 0; j < 3; j++) {
            
           x2[j]=x[j+count];
          
        }
        count++;  
     Arrays.sort(x2);
         
       if(x[count]==x2[1]){
           count2++;
       
       }
       
       }
  System.out.println(count2);
    } main {
     
        Scanner entrada=new Scanner(System.in);
        int k=entrada.nextInt();
        int x[]=new int[k];
        int x2[]=new int[3];
        int count=0;
        int count2=0;
        for (int i = 0; i < k; i++) {
            x[i]=entrada.nextInt();
        }
      
        for (int i = 0; i < k-2; i++) {
            for (int j = 0; j < 3; j++) {
            
           x2[j]=x[j+count];
          
        }
        count++;  
     Arrays.sort(x2);
         
       if(x[count]==x2[1]){
           count2++;
       
       }
       
       }
  System.out.println(count2);
    } Scanner entrada=new Scanner(System.in); entrada new Scanner(System.in) int k=entrada.nextInt(); k entrada.nextInt() entrada.nextInt entrada int x[]=new int[k]; x new int[k] k int x2[]=new int[3]; x2 new int[3] 3 int count=0; count 0 int count2=0; count2 0 for (int i = 0; i < k; i++) {
            x[i]=entrada.nextInt();
        } int i = 0; int i = 0; i 0 i < k i k i++ i++ i {
            x[i]=entrada.nextInt();
        } {
            x[i]=entrada.nextInt();
        } x[i]=entrada.nextInt() x[i] x i entrada.nextInt() entrada.nextInt entrada for (int i = 0; i < k-2; i++) {
            for (int j = 0; j < 3; j++) {
            
           x2[j]=x[j+count];
          
        }
        count++;  
     Arrays.sort(x2);
         
       if(x[count]==x2[1]){
           count2++;
       
       }
       
       } int i = 0; int i = 0; i 0 i < k-2 i k-2 k 2 i++ i++ i {
            for (int j = 0; j < 3; j++) {
            
           x2[j]=x[j+count];
          
        }
        count++;  
     Arrays.sort(x2);
         
       if(x[count]==x2[1]){
           count2++;
       
       }
       
       } {
            for (int j = 0; j < 3; j++) {
            
           x2[j]=x[j+count];
          
        }
        count++;  
     Arrays.sort(x2);
         
       if(x[count]==x2[1]){
           count2++;
       
       }
       
       } for (int j = 0; j < 3; j++) {
            
           x2[j]=x[j+count];
          
        } int j = 0; int j = 0; j 0 j < 3 j 3 j++ j++ j {
            
           x2[j]=x[j+count];
          
        } {
            
           x2[j]=x[j+count];
          
        } x2[j]=x[j+count] x2[j] x2 j x[j+count] x j+count j count count++ count Arrays.sort(x2) Arrays.sort Arrays x2 if(x[count]==x2[1]){
           count2++;
       
       } x[count]==x2[1] x[count] x count x2[1] x2 1 {
           count2++;
       
       } count2++ count2 System.out.println(count2) System.out.println System.out System System.out count2 String[] args args public class Main {

    public static void main(String[] args) {
     
        Scanner entrada=new Scanner(System.in);
        int k=entrada.nextInt();
        int x[]=new int[k];
        int x2[]=new int[3];
        int count=0;
        int count2=0;
        for (int i = 0; i < k; i++) {
            x[i]=entrada.nextInt();
        }
      
        for (int i = 0; i < k-2; i++) {
            for (int j = 0; j < 3; j++) {
            
           x2[j]=x[j+count];
          
        }
        count++;  
     Arrays.sort(x2);
         
       if(x[count]==x2[1]){
           count2++;
       
       }
       
       }
  System.out.println(count2);
    }
    
} public class Main {

    public static void main(String[] args) {
     
        Scanner entrada=new Scanner(System.in);
        int k=entrada.nextInt();
        int x[]=new int[k];
        int x2[]=new int[3];
        int count=0;
        int count2=0;
        for (int i = 0; i < k; i++) {
            x[i]=entrada.nextInt();
        }
      
        for (int i = 0; i < k-2; i++) {
            for (int j = 0; j < 3; j++) {
            
           x2[j]=x[j+count];
          
        }
        count++;  
     Arrays.sort(x2);
         
       if(x[count]==x2[1]){
           count2++;
       
       }
       
       }
  System.out.println(count2);
    }
    
} Main
import java.util.*;
public class Main {

    public static void main(String[] args) {
     
        Scanner entrada=new Scanner(System.in);
        int k=entrada.nextInt();
        int x[]=new int[k];
        int x2[]=new int[3];
        int count=0;
        int count2=0;
        for (int i = 0; i < k; i++) {
            x[i]=entrada.nextInt();
        }
      
        for (int i = 0; i < k-2; i++) {
            for (int j = 0; j < 3; j++) {
            
           x2[j]=x[j+count];
          
        }
        count++;  
     Arrays.sort(x2);
         
       if(x[count]==x2[1]){
           count2++;
       
       }
       
       }
  System.out.println(count2);
    }
    
}
