import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] a = new int[N]; for(int i = 0; i < N; i++) { a[i] = sc.nextInt(); } int ans = 0; for(int i = 0; i < N - 2; i++) { if(a[i] != a[i + 1] && a[i] != a[i + 2] && a[i + 1] != a[i + 2]) { int max = Math.max(a[i], Math.max(a[i + 1], a[i + 2])); int min = Math.min(a[i], Math.min(a[i + 1], a[i + 2])); if(a[i + 1] == max || a[i + 1] == min) ans++; } } System.out.println(ans); } }