#include <bits/stdc++.h>
using namespace std;
int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0));
using Int = long long;
int maxpos(const vector<int> &X) {
    int pos = -1;
    int val = INT_MIN;
    for (int i = 0; i < X.size(); i++) {
        if (val < X[i]) {
            pos = i;
            val = X[i];
        } else if (val == X[i]) {
            pos = -1;
        }
    }
    return pos;
}
int main() {
    int N; cin >> N;
    vector<int> P(N); for (auto &p : P) cin >> p, p--;
    vector<int> L(N), R(N);
    for (int i = 1; i < N; i++) {
        if (P[i - 1] < P[i]) {
            L[i] = L[i - 1] + 1;
        } else {
            L[i] = 0;
        }
    }
    for (int i = N - 2; i >= 0; i--) {
        if (P[i] > P[i + 1]) {
            R[i] = R[i + 1] + 1;
        } else {
            R[i] = 0;
        }
    }
    int maxL = maxpos(L);
    int maxR = maxpos(R);
    if (maxL != -1 && maxR != -1 && maxL == maxR && L[maxL] == R[maxR] && L[maxL] % 2 == 0) {
        cout << 1 << '\n';
    } else {
        cout << 0 << '\n';
    }
    return 0;
}