#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
struct segtree{
const ll inf = 1e18;
int k;
vector<ll> mx;
segtree(int n){
k = 1;
while(k <= n) k*=2; k*=2;
mx.assign(k, -inf);
}
void upd(int in, ll x){
in+=k/2;
mx[in] = x, in/=2;
while(in > 0){
mx[in] = max(mx[2*in], mx[2*in+1]);
in/=2;
}
}
ll smx(int l, int r, int nd, int a, int b){
if(b < l || a > r) return -inf;
if(a >= l && b <= r) return mx[nd];
int c = (a+b)/2;
return max(smx(l, r, 2*nd, a, c), smx(l, r, 2*nd+1, c+1, b));
}
ll smx(int l, int r){
return smx(l, r, 1, 0, k/2-1);
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<int> v(n);
for(int &x: v) cin >> x;
vector<int> pref(n, 0), suff(n, 0);
for(int i = 0; i < n; i++){
if(i != 0 && v[i] > v[i-1]){
pref[i] = pref[i-1]+1;
}
else pref[i] = 1;
}
for(int i = n-1; i >= 0; i--){
if(i != n-1 && v[i] > v[i+1]){
suff[i] = suff[i+1]+1;
}
else suff[i] = 1;
}
vector<int> pref1(n, 0), suff1(n, 0);
for(int i = 0; i < n; i++){
if(i != 0 && v[i] < v[i-1]) pref1[i] = pref1[i-1]+1;
else pref1[i] = 1;
}
for(int i = n-1; i >= 0; i--){
if(i != n-1 && v[i] < v[i+1]) suff1[i] = suff1[i+1]+1;
else suff1[i] = 1;
}
segtree seg(n);
for(int i = 0; i < n; i++){
seg.upd(i, max(suff1[i], pref1[i]));
}
int ans = 0;
for(int i = 1; i < n-1; i++){
if(v[i] < v[i+1] || v[i] < v[i-1]) continue;
int a = i-pref[i], b = i+suff[i];
int mx = max(pref[i], suff[i]);
if(a >= 0 && seg.smx(0, a) >= mx || suff1[a] >= mx){
continue;
}
if(b < n && seg.smx(b, n-1) >= mx || pref1[b] >= mx){
continue;
}
a = pref[i], b = suff[i];
if(a < b) swap(a, b);
if(a == b && a%2 == 1){
ans++;
continue;
}
}
/*
a
*/
cout << ans << "\n";
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgZiBmaXJzdAojZGVmaW5lIHNjIHNlY29uZAp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBpbnQgbGw7CnR5cGVkZWYgc3RyaW5nIHN0cjsKc3RydWN0IHNlZ3RyZWV7CiAgICBjb25zdCBsbCBpbmYgPSAxZTE4OwogICAgaW50IGs7CiAgICB2ZWN0b3I8bGw+IG14OwogICAgc2VndHJlZShpbnQgbil7CiAgICAgICAgayA9IDE7CiAgICAgICAgd2hpbGUoayA8PSBuKSBrKj0yOyBrKj0yOwogICAgICAgIG14LmFzc2lnbihrLCAtaW5mKTsKICAgIH0KICAgIHZvaWQgdXBkKGludCBpbiwgbGwgeCl7CiAgICAgICAgaW4rPWsvMjsKICAgICAgICBteFtpbl0gPSB4LCBpbi89MjsKICAgICAgICB3aGlsZShpbiA+IDApewogICAgICAgICAgICBteFtpbl0gPSBtYXgobXhbMippbl0sIG14WzIqaW4rMV0pOwogICAgICAgICAgICBpbi89MjsKICAgICAgICB9CiAgICB9CiAgICBsbCBzbXgoaW50IGwsIGludCByLCBpbnQgbmQsIGludCBhLCBpbnQgYil7CiAgICAgICAgaWYoYiA8IGwgfHwgYSA+IHIpIHJldHVybiAtaW5mOwogICAgICAgIGlmKGEgPj0gbCAmJiBiIDw9IHIpIHJldHVybiBteFtuZF07CiAgICAgICAgaW50IGMgPSAoYStiKS8yOwogICAgICAgIHJldHVybiBtYXgoc214KGwsIHIsIDIqbmQsIGEsIGMpLCBzbXgobCwgciwgMipuZCsxLCBjKzEsIGIpKTsKICAgIH0KICAgIGxsIHNteChpbnQgbCwgaW50IHIpewogICAgICAgIHJldHVybiBzbXgobCwgciwgMSwgMCwgay8yLTEpOwogICAgfQp9OwppbnQgbWFpbigpewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbi50aWUoMCk7CiAgICBpbnQgbjsgY2luID4+IG47CiAgICB2ZWN0b3I8aW50PiB2KG4pOwogICAgZm9yKGludCAmeDogdikgY2luID4+IHg7CiAgICB2ZWN0b3I8aW50PiBwcmVmKG4sIDApLCBzdWZmKG4sIDApOwogICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKyl7CiAgICAgICAgaWYoaSAhPSAwICYmIHZbaV0gPiB2W2ktMV0pewogICAgICAgICAgICBwcmVmW2ldID0gcHJlZltpLTFdKzE7CiAgICAgICAgfQogICAgICAgIGVsc2UgcHJlZltpXSA9IDE7CiAgICB9CiAgICBmb3IoaW50IGkgPSBuLTE7IGkgPj0gMDsgaS0tKXsKICAgICAgICBpZihpICE9IG4tMSAmJiB2W2ldID4gdltpKzFdKXsKICAgICAgICAgICAgc3VmZltpXSA9IHN1ZmZbaSsxXSsxOwogICAgICAgIH0KICAgICAgICBlbHNlIHN1ZmZbaV0gPSAxOwogICAgfQogICAgdmVjdG9yPGludD4gcHJlZjEobiwgMCksIHN1ZmYxKG4sIDApOyAKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgIGlmKGkgIT0gMCAmJiB2W2ldIDwgdltpLTFdKSBwcmVmMVtpXSA9IHByZWYxW2ktMV0rMTsKICAgICAgICBlbHNlIHByZWYxW2ldID0gMTsKICAgIH0KICAgIGZvcihpbnQgaSA9IG4tMTsgaSA+PSAwOyBpLS0pewogICAgICAgIGlmKGkgIT0gbi0xICYmIHZbaV0gPCB2W2krMV0pIHN1ZmYxW2ldID0gc3VmZjFbaSsxXSsxOwogICAgICAgIGVsc2Ugc3VmZjFbaV0gPSAxOwogICAgfQogICAgc2VndHJlZSBzZWcobik7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKXsKICAgICAgICBzZWcudXBkKGksIG1heChzdWZmMVtpXSwgcHJlZjFbaV0pKTsKICAgIH0KICAgIGludCBhbnMgPSAwOwogICAgZm9yKGludCBpID0gMTsgaSA8IG4tMTsgaSsrKXsKICAgICAgICBpZih2W2ldIDwgdltpKzFdIHx8IHZbaV0gPCB2W2ktMV0pIGNvbnRpbnVlOwogICAgICAgIGludCBhID0gaS1wcmVmW2ldLCBiID0gaStzdWZmW2ldOwogICAgICAgIGludCBteCA9IG1heChwcmVmW2ldLCBzdWZmW2ldKTsKICAgICAgICBpZihhID49IDAgJiYgc2VnLnNteCgwLCBhKSA+PSBteCB8fCBzdWZmMVthXSA+PSBteCl7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBpZihiIDwgbiAmJiBzZWcuc214KGIsIG4tMSkgPj0gbXggfHwgcHJlZjFbYl0gPj0gbXgpewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgYSA9IHByZWZbaV0sIGIgPSBzdWZmW2ldOwogICAgICAgIGlmKGEgPCBiKSBzd2FwKGEsIGIpOwogICAgICAgIGlmKGEgPT0gYiAmJiBhJTIgPT0gMSl7CiAgICAgICAgICAgIGFucysrOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICB9CiAgICAvKgogICAgYQogICAgKi8KICAgIGNvdXQgPDwgYW5zIDw8ICJcbiI7Cn0=