#include <bits/stdc++.h>
using namespace std;
const long long INF = 1.e18 + 2;
const long long mod = 1000006;
const int MAXN = 200005;
using namespace std;
int n, dif;
vector<int> seq;
bool ctrl[MAXN];
bool ver(int ind1, int ind2) {
  set<int> myS;
  if (ind1 % 2) {
    if (seq[ind1] > seq[ind1 - 1]) {
      if (ctrl[ind1]) myS.insert(ind1);
      if (ctrl[ind1 - 1]) myS.insert(ind1 - 1);
    } else
      return false;
    if (ind1 < seq.size() - 1 && seq[ind1] > seq[ind1 + 1]) {
      if (ctrl[ind1]) myS.insert(ind1);
      if (ctrl[ind1 + 1]) myS.insert(ind1 + 1);
    } else if (ind1 < seq.size() - 1)
      return false;
  } else {
    if (ind1 > 0 && seq[ind1] < seq[ind1 - 1]) {
      if (ctrl[ind1]) myS.insert(ind1);
      if (ctrl[ind1 - 1]) myS.insert(ind1 - 1);
    } else if (ind1 > 0)
      return false;
    if (ind1 < seq.size() - 1 && seq[ind1] < seq[ind1 + 1]) {
      if (ctrl[ind1]) myS.insert(ind1);
      if (ctrl[ind1 + 1]) myS.insert(ind1 + 1);
    } else if (ind1 < seq.size() - 1)
      return false;
  }
  if (ind2 % 2) {
    if (seq[ind2] > seq[ind2 - 1]) {
      if (ctrl[ind2]) myS.insert(ind2);
      if (ctrl[ind2 - 1]) myS.insert(ind2 - 1);
    } else
      return false;
    if (ind2 < seq.size() - 1 && seq[ind2] > seq[ind2 + 1]) {
      if (ctrl[ind2]) myS.insert(ind2);
      if (ctrl[ind2 + 1]) myS.insert(ind2 + 1);
    } else if (ind2 < seq.size() - 1)
      return false;
  } else {
    if (ind2 > 0 && seq[ind2] < seq[ind2 - 1]) {
      if (ctrl[ind2]) myS.insert(ind2);
      if (ctrl[ind2 - 1]) myS.insert(ind2 - 1);
    } else if (ind2 > 0)
      return false;
    if (ind2 < seq.size() - 1 && seq[ind2] < seq[ind2 + 1]) {
      if (ctrl[ind2]) myS.insert(ind2);
      if (ctrl[ind2 + 1]) myS.insert(ind2 + 1);
    } else if (ind2 < seq.size() - 1)
      return false;
  }
  return myS.size() == dif;
}
int f(int ind) {
  int acm = 0;
  for (int i = 0; i < seq.size(); i++) {
    if (i == ind) continue;
    int aux = seq[ind];
    seq[ind] = seq[i];
    seq[i] = aux;
    if (ver(ind, i)) {
      acm++;
      if (!ctrl[i]) acm++;
    }
    aux = seq[ind];
    seq[ind] = seq[i];
    seq[i] = aux;
  }
  return acm;
}
int main() {
  cin >> n;
  seq = vector<int>(n);
  for (int x, i = 0; i < n; i++) {
    scanf("%d", &seq[i]);
  }
  memset(ctrl, false, sizeof(ctrl));
  int acm = 0;
  for (int i = 0; i < seq.size() - 1; i++) {
    if (i % 2 && seq[i] <= seq[i + 1]) {
      if (!ctrl[i]) {
        ctrl[i] = true;
        acm++;
      }
      if (!ctrl[i + 1]) {
        ctrl[i + 1] = true;
        acm++;
      }
    } else if (!(i % 2) && seq[i] >= seq[i + 1]) {
      if (!ctrl[i]) {
        ctrl[i] = true;
        acm++;
      }
      if (!ctrl[i + 1]) {
        ctrl[i + 1] = true;
        acm++;
      }
    }
  }
  if (acm > 6) return cout << "0" << endl, 0;
  int res = 0;
  dif = acm;
  for (int i = 0; i < seq.size(); i++) {
    if (ctrl[i]) res += f(i);
  }
  cout << res / 2 << endl;
  return 0;
}
