#include #include #include using namespace std; int main() { int n; cin >> n; vector v; int count{0}; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; v.push_back(tmp); } for (int j = 0; j < (n - 2); ++j) { if (v.at(j) != v.at(j+1) && v.at(j+1) != v.at(j+2) && v.at(j+2) != v.at(j)) { auto p = minmax_element(v.begin(), v.begin() + 2); if (v.at(j + 1) == *p.first || v.at(j + 1) == *p.second) count++; } } cout << count << endl; return 0; }