#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;


int n;
int a[maxn];
std::vector<pair<int,int>> v;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    int maxx = 0;
    for(int i = 1;i <= n; ++i)  cin >> a[i];
    for(int l = 1,r = 2;l <= n; l = r,r = r + 1)
    {
        while(r + 1 <= n && (a[r + 1] - a[r]) * (a[r] - a[l]) > 0) ++r;
        if(r - l + 1 >= maxx)
        {
            if(r - l + 1 > maxx)
            {
                maxx = r - l + 1;
                v.clear();
                v.push_back({l,r});
            }
            else
                v.push_back({l,r});
        }
    }
    if(v.size() != 2)
    {
        cout << 0 << endl;
        return 0;
    }
    int l1 = v[0].first,r1 = v[0].second;
    int l2 = v[1].first,r2 = v[1].second;
    if(r1 == l2 && (r1 - l1) % 2 == 0 && a[r1] > a[l1] && a[l2] > a[r2])
    {
        cout << 1 << endl;
        return 0;
    }
    cout << 0 << endl;
    return 0;
}