#include <bits/stdc++.h>
using namespace std;
const int N = 15e4 + 10, inf = 0x3f3f3f3f;
int t[N], wr[N];
bool w[N];
bool check(int x) {
  return (x % 2 && t[x] < t[x - 1] && t[x] < t[x + 1]) ||
         (x % 2 == 0 && t[x] > t[x - 1] && t[x] > t[x + 1]);
}
int main() {
  int n, cnt = 0, ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
  t[0] = inf, t[n + 2 - (n % 2)] = inf;
  for (int i = 1; i <= n; i++)
    if (!check(i)) {
      wr[++cnt] = i;
      w[i] = 1;
    }
  if (cnt > 6) {
    printf("0");
    return 0;
  }
  for (int i = 1; i <= cnt; i++) {
    for (int j = 1; j <= n; j++) {
      if (w[j] && j <= wr[i]) continue;
      swap(t[wr[i]], t[j]);
      bool flag = check(j);
      for (int k = 1; k <= cnt; k++) flag &= check(wr[k]);
      swap(t[wr[i]], t[j]);
      ans += flag;
    }
  }
  printf("%d", ans);
  return 0;
}
