#include #include #include typedef long long ll; int main(void) { std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(8); int n; std::cin >> n; int a[n]; for (int i = 0; i < n; ++i) std::cin >> a[i]; int ans = 0; for (int i = 1; i < n-1; ++i) { if ((a[i] < a[i-1] && a[i-1] < a[i+1]) || (a[i+1] < a[i-1] && a[i-1] < a[i]) || (a[i] < a[i+1] && a[i+1] < a[i-1]) || (a[i-1] < a[i+1] && a[i+1] < a[i])) ans++; } std::cout << ans << std::endl; return 0; }