#include #define rep(i, ss, ee) for (int i = ss; i < ee; ++i) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, ans = 0; cin >> N; vector v(N), tmp(3); rep(i, 0, N) { cin >> v[i]; } rep(i, 0, N - 2) { if (v[i] != v[i + 1] && v[i] != v[i + 2] && v[i + 1] != v[i + 2]) { tmp[0] = v[i], tmp[1] = v[i + 1], tmp[2] = v[i + 2]; sort(tmp.begin(), tmp.end()); if (tmp[1] != v[i + 1]) ans++; } } cout << ans << endl; getchar(); }