#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define endl "\n"
typedef long double ld;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    vector<pair<int, int>> up;
    vector<pair<int, int>> down;
    pair<int, int> now = {0, 0};
    for (int i = 0; i < n; i++) {
        if (i == n - 1 || A[i] > A[i + 1]) {
            now.first += 1;
            now.second = i;
            if (up.empty() || now.first == up[0].first) {
                up.pb(now);
            } else {
                if (now.first > up[0].first) {
                    up = {};
                    up.pb(now);
                }
            }
            now.first = 0;
            now.second = 0;
        } else {
            now.first++;
        }
    }
    for (int i = n - 1; i > -1; i--) {
        if (i == 0 || A[i] > A[i - 1]) {
            now.first += 1;
            now.second = i;
            if (down.empty() || now.first == down[0].first) {
                down.pb(now);
            } else {
                if (now.first > down[0].first) {
                    down = {};
                    down.pb(now);
                }
            }
            now.first = 0;
            now.second = 0;
        } else {
            now.first++;
        }
    }
    if (down.size() == 1 && up.size() == 1 && down[0] == up[0] && down[0].first % 2 == 1) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}
