using namespace std;
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <queue>
#include <deque>
#include <unordered_set>
#include <cstring>  
#include <set>  


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long T, maxi = 0, m = 0;
    cin >> T;
    map <long long, long long> s;
    vector<long long>p(T);
    for (long long i = 0; i < T; i++) {
        cin >> p[i];
    }
    for (long long l = 0, r = 0, i = 0; i < T - 1; i++) {
        while (i + 1 < T and p[i] < p[i + 1]) {
            l++;
            i++;
        }
        while (i + 1 < T and p[i] > p[i + 1]) {
            r++;
            i++;
        }
        if (l == r and l != 0) {
            s[l+1]++;
            maxi = max(maxi, l+1);
        }
        else {
            m = max(m, max(l + 1, r + 1));
        }
        i--;
        l = 0;
        r = 0;
    }
    if (maxi > m and maxi % 2 == 1 and s[maxi] == 1) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }

    return 0;

}