#include <bits/stdc++.h>
#define INF (ll)(1e18 + 7)
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

using namespace std;
using ll = long long;
using cd = complex<double>;
using ul = unsigned long;

void f_io () { ios_base :: sync_with_stdio (false); cin.tie (nullptr);
 cout.tie (nullptr);
}

const ll MAX = 9e6 + 5;
const int MOD = 1;

ll gc (ll a, ll b) {
	if (!a || !b) {
		return max (a, b);
	}
	ll r = a % b;
	while (r) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int mult (int a, int b) {
	return ((a % MOD)  * 1LL * (b % MOD)) % MOD;
}

int pw (int a, int b) {
	int r = 1;
	while (b) {
		if (b & 1) {
			r = mult (a, r);
		}
		b >>= 1;
		a = mult (a, a);
	}
	return r;
}

ll cnt (vector<int> &a, vector<int> &b) {
	int bp = 0;
	ll d = 0;
	for (int i = 0; i < a.size (); i++) {
		while (bp < b.size () && b[bp] < a[i]) {
			bp++;
		}
		d += bp;
	}
	return d;
}

int main () {
	int n;
	cin >> n;
	vector<int> pp[n];
	int ar[n];
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
	}
	int p = 0, ma = 0;
	map<int ,int> mp;
	//even Q wins
	set<int> se;
	for (int i = 1; i < n - 1; i++) {
		if (ar[i - 1] < ar[i] && ar[i + 1] < ar[i]) {
			int d = i - p;
			p = i;
			pp[d].pb (i);
			ma = max (d, ma);
			mp[d]++;
			se.insert (d);
		}
		else if (ar[i - 1] > ar[i] && ar[i + 1] > ar[i]) {
			int d = i - p;
			pp[d].pb (p);
			mp[d]++;
			p = i;
			ma = max (d, ma);
			se.insert (d);
		}
	}
	if (ar[n - 2] < ar[n - 1])  {
		ma = max (n - 1 - p, ma);
		pp[n - 1 - p].pb (n - 1);
		mp[n - 1 - p]++;
		se.insert (n - 1 - p);
	}
	else {
		int d = n - 1 - p;
		ma = max (ma, d);
		pp[d].pb (p);
		mp[d]++;
		se.insert (d);
	}
	int cc = mp[ma];
	if (cc > 2)  {
		cout << "0\n";
	}
	else if (cc == 2) {
		if (pp[ma][0] != pp[ma][1]) {
			cout << "0\n";
		}
		else if ((pp[ma][0] == 0 || pp[ma][0] == n - 1) && (pp[ma][1] == 0 || pp[ma][1] == n - 1)) {
			cout << "0\n";
		}
		else{
			cout << ((ma & 1) ? "0\n" : "1\n");
		}
	}
	else {
		int x = pp[ma][0];
		if (x == 0 || x == n - 1) {
			cout << "0\n";
		}
		else {
			cout << "0\n";
		}
	}
}
