#include <bits/stdc++.h>
using namespace std;
const int N = 150010, oo = 0x3f3f3f3f;
int a[N];
int n;
bool noice(int i) {
  if (i & 1) return a[i] < a[i - 1] and a[i] < a[i + 1];
  return a[i] > a[i - 1] and a[i] > a[i + 1];
}
vector<pair<int, int> > test;
void add(int i, int j) {
  if (i == j) return;
  if (j < i) swap(i, j);
  test.emplace_back(i, j);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  a[0] = oo;
  if (n & 1)
    a[n + 1] = oo;
  else
    a[n + 1] = -oo;
  vector<int> fail;
  for (int i = 1; i < n; i++) {
    if (i & 1) {
      if (a[i] >= a[i + 1]) fail.push_back(i);
    } else {
      if (a[i] <= a[i + 1]) fail.push_back(i);
    }
  }
  int ans = 0;
  if (fail.size() <= 5) {
    for (int i = 0; i < fail.size(); i++) {
      add(fail[i], fail[i] + 1);
      for (int j = i + 1; j < fail.size(); j++) {
        add(fail[i], fail[j]);
        add(fail[i] + 1, fail[j]);
        add(fail[i], fail[j] + 1);
        add(fail[i] + 1, fail[j] + 1);
      }
      for (int j = 1; j <= n; j++) {
        add(fail[i], j);
        add(fail[i] + 1, j);
      }
    }
  } else {
    printf("0\n");
    return 0;
  }
  sort(test.begin(), test.end());
  test.erase(unique(test.begin(), test.end()), test.end());
  for (auto p : test) {
    int i = p.first, j = p.second;
    swap(a[i], a[j]);
    bool ok = noice(i) and noice(j);
    for (int k : fail) ok = ok and noice(k);
    if (ok) {
      ans++;
      fprintf(stderr, "%d %d\n", i, j);
    }
    swap(a[i], a[j]);
  }
  printf("%d\n", ans);
  return 0;
}
