#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } int ans = 0; for(int i = 0; i <= n - 3; i++) { int x = a[i]; int y = a[i + 1]; int z = a[i + 2]; cerr << x << " " << y << " " << z << endl; if(x == y || y == z || z == x) continue; int mi = min(x, min(y, z)); int mx = max(x, max(y, z)); if(mi == y || mx == y) ans++; } cout << ans << endl; return 0; }