#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n;
int a[MAXN];
vector<int> v[MAXN];
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i ++)
        scanf("%d", a + i);
    for (int i = 1, j = 2; i <= n; i = j, j = i + 1)
    {
        while (j <= n && a[j] > a[j - 1]) j++;
        if (j - i > 1) v[j - i].push_back(j - 1);
    }
    for (int i = n, j = n - 1; i > 0; i = j, j = i - 1)
    {
        while (j > 0 && a[j] > a[j + 1]) j--;
        if (i - j > 1) v[i - j].push_back(j + 1);
    }
    int x = n;
    while (v[x].empty()) x--;
    if (v[x].size() >= 3 || (v[x].size() == 2 && v[x][0] != v[x][1]))
    {
        printf("0\n");
        return 0;
    }
    if (v[x].size() == 2)
    {
        if (x & 1) printf("1\n");
        else printf("0\n");
        return 0;
    }
    if (x >= 6)
    {
        printf("0\n");
        return 0;
    }
    if (x <= 3)
    {
        printf("0\n");
        return 0;
    }
    bool flag = false;
    for (int i = 3; i < x; i ++)
        if (!v[i].empty())
        {
            flag = true;
            break;
        }
    if (flag) printf("0\n");
    else printf("1\n");
    return 0;
}