#include #define For(i, a, b) for(int i = a; i < b; i++) #define rep(i, n) For(i, 0, n) #define rFor(i, a, b) for(int i = a; i >= b; i--) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() using namespace std; using lint = long long; using ld = long double; int INF = 2000000000; lint LINF = 1000000000000000000; int main() { int n; cin >> n; vector a(n); rep(i, n) { cin >> a[i]; } auto ok = [](int x, int y, int z) -> bool { vector v = {x, y, z}; sort(ALL(v)); if (v[0] == v[1] || v[1] == v[2]) { return false; } if (x == v[1] || z == v[1]) { return true; } else { return false; } }; int ans = 0; rep(i, n) { if (i + 2 < n) { if (ok(a[i], a[i + 1], a[i + 2])) { ans++; } } } cout << ans << endl; }