#include <map>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstddef>
#include <cstring>
#include <iostream>
#include <algorithm>
#define pii pair<int, int>
#define mp make_pair
#define int long long
using namespace std;
 
inline int read() {
	int x = 0, w = 1;char ch = getchar();
	while (ch > '9' || ch < '0') { if (ch == '-')w = -1;ch = getchar(); }
	while (ch >= '0' && ch <= '9')x = x * 10 + ch - '0', ch = getchar();
	return x * w;
}
inline void write(int x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
 
const int maxn = 1e6 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f3f3f3f;
 
inline int min(int x, int y) { return x < y ? x : y; }
inline int max(int x, int y) { return x > y ? x : y; }

int n, tot, cnt, t, maxh, p[maxn], tmp[maxn], ans[maxn];

signed main(void) {
	n = read();
	for (int i = 1;i <= n;i++) p[i] = read();
	if (p[1] < p[2]) t = 1; else t = 0; tmp[++tot] = 1;
	for (int i = 2;i <= n;i++) {
		if (t == 0) {
			if (p[i] < p[i - 1]) tmp[tot]++;
			else t = 1, tmp[++tot] = 2; 
		} else {
			if (p[i] > p[i - 1]) tmp[tot]++;
			else t = 0, tmp[++tot] = 2;
		}
	}
	for (int i = 1;i <= tot;i++) maxh = max(maxh, tmp[i]);
	for (int i = 1;i <= tot;i++) 
		if (tmp[i] == maxh) ans[++cnt] = i;
	if ((cnt != 2) || (ans[2] - ans[1] != 1)) puts("0");
	else if (!((p[1] < p[2]) ^ (ans[1] % 2 == 0))) puts("0");
	else if (maxh % 2 == 0) puts("0");
	else puts("1");
    return 0;
}