#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define ll long long
int n,ans,tot,a[N],f[N],g[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	f[1]=1,f[2]=2;
	for(int i=3;i<=n;i++){
		if (1LL*(a[i-1]-a[i-2])*(a[i]-a[i-1])>0)f[i]=f[i-1]+1;
		else f[i]=2;
	}
	for(int i=1;i<=n;i++)ans=max(ans,f[i]);
	if (ans%2==0){
		printf("0");
		return 0;
	}
	g[n]=1,g[n-1]=2;
	for(int i=n-2;i;i--){
		if (1LL*(a[i+1]-a[i+2])*(a[i]-a[i+1])>0)g[i]=g[i+1]+1;
		else g[i]=2;
	}
	for(int i=1;i<=n;i++)
		if ((f[i]==ans)&&(g[i]==ans)&&(a[i]>a[i-1])&&(a[i]>a[i+1])){
			int flag=0;
			for(int j=1;j<=n;j++)
				if ((j!=i)&&(j!=i+f[i]-1)&&(f[j]==ans))flag=1;
			if (!flag)printf("1");
			else printf("0");
			return 0;
		}
	printf("0");
}