#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <random>
#include <map>
#include <unordered_map>
#include <numeric>
#include <fstream>
#include <chrono>

using namespace std;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define x first
#define y second
#define int long long
#define ll long long

void solve() {
    int n;
    cin >> n;
    vector<int> lt(n), rt(n), a(n);
    for (int i{}; i < n; ++i) {
        cin >> a[i];
    }
    lt[0] = 0;
    for (int i{1}; i < n; ++i) {
        if (a[i] > a[i - 1]) lt[i] = lt[i - 1] + 1;
        else lt[i] = 0;
    }
    rt[n - 1] = 0;
    for (int i{n - 2}; i >= 0; --i) {
        if (a[i] > a[i + 1]) rt[i] = rt[i + 1] + 1;
    }
    multiset<int> all;
    all.insert(rt[0] + 1);
    all.insert(lt[n - 1] + 1);
    for (int i{1}; i < n - 1; ++i) {
        if (a[i] > a[i - 1] && a[i] > a[i + 1]) {
            all.insert(lt[i] + 1);
            all.insert(rt[i] + 1);
        }
    }
    all.insert(rt[0] + 1);
    all.insert(lt[n - 1] + 1);
    int ans = 0;
    for (int i{1}; i < n - 1; ++i) {
        if (a[i] < a[i - 1] || a[i] < a[i + 1]) continue;
        all.erase(all.find(lt[i] + 1));
        all.erase(all.find(rt[i] + 1));
        int t = max(lt[i] + 1, rt[i] + 1);
        if (*all.rbegin() >= t) {
            all.insert(lt[i] + 1);
            all.insert(rt[i] + 1);
            continue;
        } 
        
        if (lt[i] + 1 == t && rt[i] + 1 == t && t % 2 == 1) {
            ans++;
            all.insert(lt[i] + 1);
            all.insert(rt[i] + 1);
            continue;
        } 
        
        if (t % 2 == 0) {
            all.insert(lt[i] + 1);
            all.insert(rt[i] + 1);
            continue;
        }
        
        if ((t ^ (lt[i] + 1) ^ (rt[i] + 1)) == t - 1) {
//            ans++;
            all.insert(lt[i] + 1);
            all.insert(rt[i] + 1);
            continue;
        }
    }
    cout << ans;
}

int32_t main() {
    cin.tie(NULL);
    cout.tie(NULL);
    ios::sync_with_stdio(false);
    cout.precision(100);
    
    int t;
    t = 1;
    for (int i{}; i < t; ++i) solve();
    
    return 0;
}
