import java.util.*;

public class Main {
  public static void main(String[] args) {
    int i, number_n, count = 0;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    int[] number_array = new int[number_n];
    for(i = 0; i < number_n; i++) number_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number_n - 2; i++) {
      if((number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) || (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2])) {
        count++;
      }
    }
    System.out.println(count);
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    int i, number_n, count = 0;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    int[] number_array = new int[number_n];
    for(i = 0; i < number_n; i++) number_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number_n - 2; i++) {
      if((number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) || (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2])) {
        count++;
      }
    }
    System.out.println(count);
  }
} Main public static void main(String[] args) {
    int i, number_n, count = 0;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    int[] number_array = new int[number_n];
    for(i = 0; i < number_n; i++) number_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number_n - 2; i++) {
      if((number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) || (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2])) {
        count++;
      }
    }
    System.out.println(count);
  } main {
    int i, number_n, count = 0;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    int[] number_array = new int[number_n];
    for(i = 0; i < number_n; i++) number_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number_n - 2; i++) {
      if((number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) || (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2])) {
        count++;
      }
    }
    System.out.println(count);
  } int i i number_n number_n count = 0; count 0 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) number_n = Integer.parseInt(sc.next()) number_n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] number_array = new int[number_n]; number_array new int[number_n] number_n for(i = 0; i < number_n; i++) number_array[i] = Integer.parseInt(sc.next()); i = 0; i = 0 i 0 i < number_n i number_n i++ i++ i number_array[i] = Integer.parseInt(sc.next()); number_array[i] = Integer.parseInt(sc.next()) number_array[i] number_array i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for(i = 0; i < number_n - 2; i++) {
      if((number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) || (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2])) {
        count++;
      }
    } i = 0; i = 0 i 0 i < number_n - 2 i number_n - 2 number_n 2 i++ i++ i {
      if((number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) || (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2])) {
        count++;
      }
    } {
      if((number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) || (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2])) {
        count++;
      }
    } if((number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) || (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2])) {
        count++;
      } (number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) || (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2]) (number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) number_array[i] < number_array[i+1] number_array[i] number_array i number_array[i+1] number_array i+1 i 1 number_array[i+1] < number_array[i+2] number_array[i+1] number_array i+1 i 1 number_array[i+2] number_array i+2 i 2 (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2]) number_array[i] > number_array[i+1] number_array[i] number_array i number_array[i+1] number_array i+1 i 1 number_array[i+1] > number_array[i+2] number_array[i+1] number_array i+1 i 1 number_array[i+2] number_array i+2 i 2 {
        count++;
      } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
  public static void main(String[] args) {
    int i, number_n, count = 0;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    int[] number_array = new int[number_n];
    for(i = 0; i < number_n; i++) number_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number_n - 2; i++) {
      if((number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) || (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2])) {
        count++;
      }
    }
    System.out.println(count);
  }
} public class Main {
  public static void main(String[] args) {
    int i, number_n, count = 0;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    int[] number_array = new int[number_n];
    for(i = 0; i < number_n; i++) number_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number_n - 2; i++) {
      if((number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) || (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2])) {
        count++;
      }
    }
    System.out.println(count);
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    int i, number_n, count = 0;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    int[] number_array = new int[number_n];
    for(i = 0; i < number_n; i++) number_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number_n - 2; i++) {
      if((number_array[i] < number_array[i+1] && number_array[i+1] < number_array[i+2]) || (number_array[i] > number_array[i+1] && number_array[i+1] > number_array[i+2])) {
        count++;
      }
    }
    System.out.println(count);
  }
}
