#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int a[100005];
struct node
{
    int flag;
    int id;
    int num;
};
vector<node> que;
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n;i++)
        scanf("%d", &a[i]);
    if(a[1]<a[2])
        a[0] = 0;
    else
        a[0] = 999999999;
    if(a[n-1]<a[n])
        a[n + 1] = 999999999;
    else
        a[n + 1] = 0;
    que.push_back((node){1, 1});
    for (int i = 2; i < n;i++)
    {
        if(a[i-1]<a[i])
        {
            while(a[i-1]<a[i] && a[i]<a[i+1])
                i++;
            if(i<=n)
                que.push_back((node){0, i, 0});
        }
        else
        {
            while(a[i-1]>a[i] && a[i]>a[i+1])
                i++;
            if(i<=n)
                que.push_back((node){1, i, 0});
        }
    }
    que.push_back((node){1, n});
    for (int i = 1; i < que.size();i++)
        que[i].num = que[i].id - que[i - 1].id;
    //for (int i = 1; i < que.size();i++)
    //    printf("%d %d %d\n", i, que[i].id, que[i].num);
    int longest = 0;
    for (int i = 1; i < que.size();i++)
        if(longest<que[i].num)
            longest = que[i].num;
    int cnt = 0;
    for (int i = 1; i < que.size();i++)
        if(longest==que[i].num)
            cnt++;
    if(cnt==1 || cnt>2)
    {
        printf("0");
        return 0;
    }
    for (int i = 1; i < que.size();i++)
        if(longest==que[i].num && que[i+1].num==longest && que[i].flag==0)
        {
            if(longest%2==0)
                printf("1");
            else
                printf("0");
            return 0;
        }
    printf("0");
    return 0;
}