#!/usr/bin/env python3 #fileencoding: utf-8 N = int(input()) A = [int(i) for i in input().strip().split(" ")] def is_kad(a,b,c): l = sorted([a,b,c]) if (l[1] == a or l[1] == c) and (a != b and b != c and c != a): return True return False count = 0 for i in range(N-2): if is_kad(A[i],A[i+1],A[i+2]): count += 1 print(count)