#include <bits/stdc++.h>
using namespace std;
set<int> ind;
int v[150005], sum, n;
bool seq[150005];
void upd(int i) {
  if (i == 0 || i == n + 1) return;
  sum -= seq[i];
  if (i & 1) {
    if (v[i - 1] > v[i] && v[i] < v[i + 1])
      seq[i] = 1;
    else
      seq[i] = 0;
  } else {
    if (v[i - 1] < v[i] && v[i] > v[i + 1])
      seq[i] = 1;
    else
      seq[i] = 0;
  }
  sum += seq[i];
}
int main() {
  int i, j;
  int m, t, k, l;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> v[i];
  v[0] = 0;
  if (n & 1)
    v[n + 1] = 151000;
  else
    v[n + 1] = 0;
  memset(seq, 1, sizeof(seq));
  sum = n;
  for (i = 1; i <= n; i++) {
    if (i & 1) {
      if (v[i - 1] <= v[i] || v[i] >= v[i + 1]) {
        seq[i] = 0;
        sum--;
        ind.insert(i);
      }
    } else {
      if (v[i - 1] >= v[i] || v[i] <= v[i + 1]) {
        seq[i] = 0;
        sum--;
        ind.insert(i);
      }
    }
  }
  if (ind.size() >= 8) {
    cout << 0 << "\n";
    return 0;
  }
  set<pair<int, int>> resp;
  for (int x : ind) {
    for (i = 1; i <= n; i++) {
      swap(v[i], v[x]);
      upd(i - 1);
      upd(i);
      upd(i + 1);
      upd(x - 1);
      upd(x);
      upd(x + 1);
      if (sum == n - 1) resp.insert(make_pair(min(i, x), max(i, x)));
      swap(v[i], v[x]);
      upd(i - 1);
      upd(i);
      upd(i + 1);
      upd(x - 1);
      upd(x);
      upd(x + 1);
    }
  }
  cout << resp.size() << "\n";
  return 0;
}
