n = gets.to_i a = gets.split.map(&:to_i) ans = 0 (n-2).times{|i| mid = a[i+1] th = a[i..i+2].sort ans += 1 if th.uniq.size==3 && th[1]!=mid } p ans