#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;
int n,num[maxn],l[maxn],r[maxn],maxlen,ctt;
int main(){
	cin>>n;
	for(int i=1;i<=n;++i) cin>>num[i];
    bool juge1=true,juge2=true;
	for(int i=1;i<=n;++i){
    	l[i]=1;
    	if(i>1&&num[i]>num[i-1]) l[i]=l[i-1]+1;
    	if(l[i]>maxlen){
    		maxlen=l[i];
    		ctt=1;
		}
		else if(l[i]==maxlen) ctt++;
	    if(l[i]!=1) juge1=false;
	}
	for(int i=n;i>=1;--i){
		r[i]=1;
		if(i<n&&num[i]>num[i+1]) r[i]=r[i+1]+1;
		if(maxlen<r[i]){
			maxlen=r[i];
			ctt=1;
		}
		else if(r[i]==maxlen) ctt++;
		if(r[i]!=1) juge2=false;
	}/* 
	for(int i=1;i<=n;++i) cout<<l[i]<<' ';
    cout<<"\n";
	for(int i=1;i<=n;++i) cout<<r[i]<<' ';
	cout<<"\n";
	cout<<maxlen<<' '<<ctt<<"\n";*/ 
	if(juge1||juge2){
		cout<<0;
		return 0;
	}
	if(ctt>=3){
		cout<<0;
		return 0;
	}
	else if(ctt==2){
		for(int i=1;i<=n;++i){
			if(l[i]==maxlen&&r[i]==maxlen){
				if(l[i]%2==0) cout<<0;
				else cout<<1;
				return 0;
			}
		}
		cout<<0;
		return 0;
	}
	else{/*
		if(maxlen%2==0){
			cout<<0;
			return 0;
		}
		for(int i=1;i<=n;++i){
			if((l[i]==maxlen||r[i]==maxlen)&&l[i]>1&&r[i]>1){
				int maxnum=max(l[i],r[i]);
				int minnum=min(l[i],r[i]);
				if(minnum>maxnum-1) cout<<1;
				else cout<<0;
				return 0;
			}
		}*/
		cout<<0;
		return 0;
	}
	
}