#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int n;
int a[maxn];
vector<int> tmp;
long long ans = 0;
set<pair<int, int> > S;
bool check() {
  for (int i = 0; i < tmp.size(); i++) {
    for (int j = -1; j <= 1; j++) {
      if (tmp[i] + j == 0) continue;
      if (tmp[i] + j == n + 1) continue;
      int pos = (tmp[i] + j);
      if (pos % 2 == 1) {
        if (a[pos] >= a[pos + 1]) return false;
        if (a[pos] >= a[pos - 1]) return false;
      } else {
        if (a[pos] <= a[pos + 1]) return false;
        if (a[pos] <= a[pos - 1]) return false;
      }
    }
  }
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  a[0] = 1e9;
  if (n % 2 == 1)
    a[n + 1] = 1e9;
  else
    a[n + 1] = -1;
  for (int i = 1; i <= n; i++) {
    if (i & 1) {
      bool ok = true;
      if (i + 1 <= n && a[i] >= a[i + 1]) ok = false;
      if (i - 1 >= 1 && a[i] >= a[i - 1]) ok = false;
      if (ok == false) tmp.push_back(i);
    } else {
      bool ok = true;
      if (i + 1 <= n && a[i] <= a[i + 1]) ok = false;
      if (i - 1 >= 1 && a[i] <= a[i - 1]) ok = false;
      if (ok == false) tmp.push_back(i);
    }
  }
  if (tmp.size() > 30) return puts("0"), 0;
  for (int i = 0; i < tmp.size(); i++) {
    for (int j = 1; j <= n; j++) {
      if (tmp[i] == j) continue;
      swap(a[tmp[i]], a[j]);
      bool ok = check();
      if (j % 2 == 1) {
        if (a[j] >= a[j + 1] || a[j] >= a[j - 1]) ok = false;
      }
      if (j % 2 == 0) {
        if (a[j] <= a[j + 1] || a[j] <= a[j - 1]) ok = false;
      }
      if (ok) {
        pair<int, int> SS = make_pair(min(tmp[i], j), max(tmp[i], j));
        if (!S.count(SS)) {
          S.insert(SS);
          ans++;
        }
      }
      swap(a[tmp[i]], a[j]);
    }
  }
  cout << ans << endl;
}
