
import java.util.Scanner;

/**
 * @author author
 *
 */
public class Main {

  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());

    int[] numbers = new int[n];
    for (int i = 0; i < n; i++) {
      numbers[i] = Integer.parseInt(sc.next());
    }

    int count = 0;
    for (int i = 2; i < numbers.length; i++) {
      if (numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2]
          || numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i]) {
        count++;
      }
    }
    System.out.println(count);
  }

} import java.util.Scanner; Scanner java.util public class Main {

  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());

    int[] numbers = new int[n];
    for (int i = 0; i < n; i++) {
      numbers[i] = Integer.parseInt(sc.next());
    }

    int count = 0;
    for (int i = 2; i < numbers.length; i++) {
      if (numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2]
          || numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i]) {
        count++;
      }
    }
    System.out.println(count);
  }

} Main /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());

    int[] numbers = new int[n];
    for (int i = 0; i < n; i++) {
      numbers[i] = Integer.parseInt(sc.next());
    }

    int count = 0;
    for (int i = 2; i < numbers.length; i++) {
      if (numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2]
          || numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i]) {
        count++;
      }
    }
    System.out.println(count);
  } main {

    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());

    int[] numbers = new int[n];
    for (int i = 0; i < n; i++) {
      numbers[i] = Integer.parseInt(sc.next());
    }

    int count = 0;
    for (int i = 2; i < numbers.length; i++) {
      if (numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2]
          || numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i]) {
        count++;
      }
    }
    System.out.println(count);
  } 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[] numbers = new int[n]; numbers new int[n] n for (int i = 0; i < n; i++) {
      numbers[i] = Integer.parseInt(sc.next());
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      numbers[i] = Integer.parseInt(sc.next());
    } {
      numbers[i] = Integer.parseInt(sc.next());
    } numbers[i] = Integer.parseInt(sc.next()) numbers[i] numbers i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int count = 0; count 0 for (int i = 2; i < numbers.length; i++) {
      if (numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2]
          || numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i]) {
        count++;
      }
    } int i = 2; int i = 2; i 2 i < numbers.length i numbers.length numbers numbers.length i++ i++ i {
      if (numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2]
          || numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i]) {
        count++;
      }
    } {
      if (numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2]
          || numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i]) {
        count++;
      }
    } if (numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2]
          || numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i]) {
        count++;
      } numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2]
          || numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i] numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2] numbers[i] > numbers[i - 1] numbers[i] numbers i numbers[i - 1] numbers i - 1 i 1 numbers[i - 1] > numbers[i - 2] numbers[i - 1] numbers i - 1 i 1 numbers[i - 2] numbers i - 2 i 2 numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i] numbers[i - 2] > numbers[i - 1] numbers[i - 2] numbers i - 2 i 2 numbers[i - 1] numbers i - 1 i 1 numbers[i - 1] > numbers[i] numbers[i - 1] numbers i - 1 i 1 numbers[i] numbers i {
        count++;
      } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());

    int[] numbers = new int[n];
    for (int i = 0; i < n; i++) {
      numbers[i] = Integer.parseInt(sc.next());
    }

    int count = 0;
    for (int i = 2; i < numbers.length; i++) {
      if (numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2]
          || numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i]) {
        count++;
      }
    }
    System.out.println(count);
  }

} public class Main {

  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());

    int[] numbers = new int[n];
    for (int i = 0; i < n; i++) {
      numbers[i] = Integer.parseInt(sc.next());
    }

    int count = 0;
    for (int i = 2; i < numbers.length; i++) {
      if (numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2]
          || numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i]) {
        count++;
      }
    }
    System.out.println(count);
  }

} Main

import java.util.Scanner;

/**
 * @author author
 *
 */
public class Main {

  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());

    int[] numbers = new int[n];
    for (int i = 0; i < n; i++) {
      numbers[i] = Integer.parseInt(sc.next());
    }

    int count = 0;
    for (int i = 2; i < numbers.length; i++) {
      if (numbers[i] > numbers[i - 1] && numbers[i - 1] > numbers[i - 2]
          || numbers[i - 2] > numbers[i - 1] && numbers[i - 1] > numbers[i]) {
        count++;
      }
    }
    System.out.println(count);
  }

}
