#include <bits/stdc++.h>
 
#define debug(...) fprintf(stderr ,__VA_ARGS__)
#define __FILE(x)\
	freopen(#x".in" ,"r" ,stdin);\
	freopen(#x".out" ,"w" ,stdout)
#define LL long long
 
const int MX = 1e5 + 23;
const LL MOD = 998244353;
 
int read(){
	char k = getchar(); int x = 0;
	while(k < '0' || k > '9') k = getchar();
	while(k >= '0' && k <= '9') x = x * 10 + k - '0' ,k = getchar();
	return x;
}
 
int n ,p[MX];
 
int main(){
	n = read();
	for(int i = 1 ; i <= n ; ++i) p[i] = read();
	p[0] = p[n + 1] = n + 1;
 
	int longest = 1 ,ok = 0;
	for(int i = 2 ,l ,r ; i < n ; ++i){
		if(p[i] > p[i - 1] && p[i] > p[i + 1]){
			l = r = i;
			while(p[l - 1] < p[l]) --l;
			while(p[r] > p[r + 1]) ++r;
			if(i - l == r - i && i - l + 1 >= longest){
				if(longest == r - i + 1){
					ok = 0;
					continue;
				}
				longest = i - l + 1;
				ok = longest & 1;
			}
			else if(std::max(i - l + 1 ,r - i + 1) >= longest){
				longest = std::max(i - l + 1 ,r - i + 1);
				ok = 0;
			}
		}
	}
	int mx = 0;
	for(int i = 1 ; p[i] < p[i - 1] ; ++i) ++mx;
	if(mx >= longest) ok = 0;
	
	mx = 0;
	for(int i = n ; p[i] < p[i + 1] ; --i) ++mx;
	if(mx >= longest) ok = 0;
	
	printf("%d\n" ,ok);
	return 0;
}