#include <bits/stdc++.h>
using namespace std;
int inf = 1e9;
const int N = 1.6e5 + 10;
int a[N] = {0}, n, cnt, ans;
bool fr[N] = {0};
bool vis[N] = {0};
vector<int> v;
bool fun() {
  bool flag = 0;
  for (int i = 2; i <= n; i++) {
    if (i & 1) {
      if (a[i] >= a[i - 1]) flag = 1;
    } else {
      if (a[i] <= a[i - 1]) flag = 1;
    }
  }
  return flag;
}
void solve(int idx, int val) {
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (fr[i]) continue;
    if (idx & 1) {
      if (a[i] < val) {
        if (i % 2 == 0) {
          a[n + 1] = 0;
          a[0] = 1e9;
          if (val > a[i + 1] && val > a[i - 1] && a[i] < a[idx - 1] &&
              a[i] < a[idx + 1])
            cnt++;
        } else {
          a[0] = 1e9;
          a[n + 1] = 1e9;
          if (val < a[i - 1] && val < a[i + 1] && a[i] < a[idx + 1] &&
              a[i] < a[idx - 1])
            cnt++;
        }
      }
    } else {
      if (a[i] > val) {
        if (i % 2 == 0) {
          a[n + 1] = 0;
          a[0] = 0;
          if (val > a[i - 1] && val > a[i + 1] && a[i] > a[idx - 1] &&
              a[i] > a[idx + 1]) {
            cnt++;
          }
        } else {
          a[n + 1] = 1e9;
          a[0] = 1e9;
          if (val < a[i - 1] && val < a[i + 1] && a[i] > a[idx + 1] &&
              a[i] > a[idx - 1])
            cnt++;
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int fl = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    bool p = 0;
    if (i % 2 == 0) {
      if (a[i] <= a[i + 1]) v.push_back(i), p = 1;
    } else if (a[i] >= a[i + 1] && i & 1)
      v.push_back(i), p = 1;
    if (p)
      if (v.size() >= 2)
        if (v[v.size() - 1] == v[v.size() - 2] + 1) {
          v.pop_back();
          v.pop_back();
          v.push_back(i);
          vis[i] = 1;
        }
  }
  if (v.size() > 2) return cout << "0", 0;
  if (v.size() == 2) {
    swap(a[v[0]], a[v[1]]);
    if (!fun()) ans++;
    swap(a[v[0]], a[v[1]]);
    swap(a[v[0]], a[v[1] + 1]);
    if (!fun()) ans++;
    swap(a[v[0]], a[v[1] + 1]);
    swap(a[v[0] + 1], a[v[1]]);
    if (!fun()) ans++;
    swap(a[v[0] + 1], a[v[1]]);
    swap(a[v[0] + 1], a[v[1] + 1]);
    if (!fun()) ans++;
    swap(a[v[0] + 1], a[v[1] + 1]);
  } else {
    solve(v[0], a[v[0]]);
    ans += cnt;
    fr[v[0]] = 1;
    if (!vis[v[0]]) {
      solve(v[0] + 1, a[v[0] + 1]);
      ans += cnt;
      fr[v[0] + 1] = 1;
    }
    swap(a[v[0]], a[v[0] + 1]);
    if (!fun()) ans++;
    swap(a[v[0]], a[v[0] + 1]);
    if (v[0] != 1) {
      swap(a[v[0]], a[v[0] - 1]);
      if (!fun()) ans++;
      swap(a[v[0]], a[v[0] - 1]);
    }
  }
  cout << ans;
}
