import java.util.Arrays; import java.util.Scanner; public class Yuki116 { public Yuki116() { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = scanner.nextInt(); } int count = 0; for (int i = 0; i < N - 2; i++) { int[] B = new int[3]; for (int j = 0; j < 3; j++) { B[j] = A[i + j]; } Arrays.sort(B); if (B[0] < B[1] && B[1] < B[2]) { if (B[1] == A[i] || B[1] == A[i + 2]) { count++; } } } System.out.println(count); } public static void main(String[] args) { Yuki116 hoge = new Yuki116(); } }