#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define int long long
#define reg register
#define For(i,a,b) for(reg int i=a;i<=b;++i) 
#define Down(i,a,b) for(reg int i=a;i>=b;--i) 
inline int max(int x,int y){return x>y?x:y;}
inline int min(int x,int y){return x<y?x:y;}
inline void swap(int &x,int &y){int t=x; x=y; y=t; return ;}
inline int gcd(int n,int m){return m?gcd(m,n%m):n;}
inline int lcm(int x,int y){return x/gcd(x,y)*y;}
namespace yspm{
    inline int read(){
        int res=0,f=1; char k;
        while(!isdigit(k=getchar())) if(k=='-') f=-1;
        while(isdigit(k)) res=res*10+k-'0',k=getchar();
        return res*f;
    }
    const int N=1e5+10;
    int len[N],cnt,n,mx,a[N],t[N],ton[N];
    signed main(){
        n=read(); For(i,1,n) a[i]=read();
        if(n==2) puts("0"),exit(0);
        int fl=a[1]<a[2],lst=1;
        for(reg int i=3;i<=n;++i){
            if(a[i]<a[i-1]&&fl) len[++cnt]=i-lst,lst=i-1,t[cnt]=fl,fl=0;
            else if(a[i]>a[i-1]&&!fl) len[++cnt]=i-lst,lst=i-1,t[cnt]=fl,fl=1;
        } 
        len[++cnt]=n-lst+1,t[cnt]=fl;
        for(reg int i=1;i<=cnt;++i) mx=max(mx,len[i]),ton[len[i]]++;
        if(ton[mx]^2) puts("0"),exit(0);
        for(reg int i=1;i<=cnt;++i) if(len[i]==mx){
            if(len[i+1]==mx){
                if(!t[i]||len[i]%2==0) puts("0");
                else puts("1"); exit(0);
            }else puts("0"),exit(0);
        }
       return 0;
    }
}
signed main(){return yspm::main();}