/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*--------------------------------------------------------------------------------------*/

signed main() { EmiliaMyWife
	int n;
	cin >> n;
	vector<int> arr(n), l(n), r(n), cnt(n + 1);
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	for(int i = 0, cur = 0; i < n; i++) {
		if(i && arr[i - 1] > arr[i])
			cur = 0;
		cur++;
		l[i] = cur;
		cnt[l[i]]++;
	}
	for(int i = n - 1, cur = 0; ~i; i--) {
		if(i < n - 1 && arr[i] < arr[i + 1])
			cur = 0;
		cur++;
		r[i] = cur;
		cnt[r[i]]++;
	}
	int ans = 0;
	for(int i = 0; i < n; i++) {
		if(l[i] == 1 || r[i] == 1)
			continue;
		ans++;
		if(l[i] > r[i]) {
			ans--;
			/*
			if(cnt[l[i]] > 1)
				ans--;
			else {
				if(l[i] % 2 == 0)
					ans--;
				else if(l[i] - 1 >= r[i])
					ans--;
			}
			*/
		}
		if(l[i] < r[i]) {
			ans--;
			/*
			if(cnt[r[i]] > 1) 
				ans--;
			else {
				if(r[i] % 2 == 0)
					ans--;
				else if(r[i] - 1 >= l[i])
					ans--;
			}
			*/
		}
		if(l[i] == r[i]) {
			if(cnt[l[i]] > 2)
				ans--;
			else {
				if(r[i] % 2 == 0)
					ans--;
			}
		}
	}
	cout << ans << '\n';
}
