#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1.01E5;
int A[MAXN];
int n, ans, mx, cnts = 1;

int main(void) {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> n;
	for (int i = 1;i <= n; ++i)
		cin >> A[i];
	for (int i = 2, cur = 1;i <= n; ++i) {
		if ((A[i] > A[i - 1]) == (A[i + 1] > A[i]) && i != n)
			++cur;
		else {
			if (cur < mx) {
				cur = 1;
				continue;
			}
			if (cur == mx)
				++cnts;
			else
				mx = cur, cnts = 1;
			cur = 1;
		}
	}
	
	if (cnts != 2)
		return puts("0") * 0;
	
	for (int i = 2;i < n; ++i)
		if (A[i] > A[i - 1] && A[i] > A[i + 1]) {
			int lp = i - 1, rp = i + 1;;
			while (lp > 1 && A[lp - 1] < A[lp])
				--lp;
			while (rp < n && A[rp] > A[rp + 1])
				++rp;
			if ((i - lp) != (rp - i) || ((i - lp) & 1) || i - lp != mx)
				continue;
			++ans;
		}
		
	cout << ans << '\n';
	
	return 0;
}