#include <bits/stdc++.h>
const int maxn = 15e4 + 5;
int n;
int a[maxn], cnt;
inline bool check(int i) {
  if (i == 0 || i == n + 1) return true;
  if (i & 1) {
    if (!(a[i - 1] > a[i] && a[i] < a[i + 1])) return false;
  } else {
    if (!(a[i - 1] < a[i] && a[i] > a[i + 1])) return false;
  }
  return true;
}
int ans = 0;
int calc(int P, int i) {
  if (P + 1 == i) return check(P - 1) + check(P) + check(i) + check(i + 1);
  if (P + 1 == i - 1)
    return check(P - 1) + check(P) + check(P + 1) + check(i) + check(i + 1);
  else
    return check(P) + check(P - 1) + check(P + 1) + check(i - 1) +
           check(i + 1) + check(i);
}
inline void dd(int P, int i) {
  if (P > i) std::swap(P, i);
  int cnt1 = calc(P, i);
  std::swap(a[P], a[i]);
  if (check(P) && check(P - 1) && check(P + 1) && check(i - 1) &&
      check(i + 1) && check(i)) {
    int cnt2 = calc(P, i);
    int delta = cnt2 - cnt1;
    if (cnt == delta) {
      ans++;
    }
  }
  std::swap(a[P], a[i]);
}
int solve() {
  int pos[maxn];
  a[0] = maxn;
  if (n % 2 == 1)
    a[n + 1] = maxn;
  else
    a[n + 1] = 0;
  for (int i = 1; i <= n; i++)
    if (!check(i)) pos[++cnt] = i;
  if (cnt > 100) return 0;
  for (int i = 1; i <= n; i++) {
    bool flag = false;
    for (int j = 1; j <= cnt; j++)
      if (i == pos[j]) {
        flag = true;
        break;
      }
    if (flag) continue;
    for (int j = 1; j <= cnt; j++) dd(i, pos[j]);
  }
  ans *= 2;
  for (int i = 1; i <= cnt; i++)
    for (int j = 1; j <= cnt; j++)
      if (i != j) dd(pos[i], pos[j]);
  return ans / 2;
}
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) a[i] = read();
  printf("%d", solve());
}
