n = io.read() a = {} scan = string.gmatch(io.read(),"%d+") for i = 1, n do a[i] = scan()-0 end result = 0 for i = 1 , n - 2 do local v1 = a[i] local v2 = a[i+1] local v3 = a[i+2] if v1 ~= v3 and v1 ~= v2 and v2 ~= v3 then local max, min = nil, nil if v1 < v3 then max, min = v3, v1 else max, min = v1, v3 end if v2 < min or v2 > max then result = result + 1 end end end print(result)