#include #include #include using namespace std; int main() { int n, t[3], ans = 0; cin >> n; vector a(n); for (auto& e : a) cin >> e; for (int i = 0; i < n - 2; i++) { t[0] = a[i]; t[1] = a[i + 1]; t[2] = a[i + 2]; sort(t, t + 3); if ((a[i + 1] == t[0] || a[i + 1] == t[2]) && t[0] != t[1] && t[1] != t[2]) { ans++; } } cout << ans << endl; }