#include <bits/stdc++.h>
using namespace std;
const int MAXN = 160000, INF = 1000000;
int A[MAXN], h[MAXN], b[MAXN], N, ans;
bool chk(int i) {
  if (i & 1)
    return A[i - 1] > A[i] && A[i] < A[i + 1];
  else
    return A[i - 1] < A[i] && A[i] > A[i + 1];
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", A + i);
  }
  A[0] = INF;
  A[N + 1] = (N & 1) ? INF : 0;
  int c = 0;
  for (int i = 1; i <= N; ++i) {
    if (i & 1) {
      if (A[i] >= A[i + 1]) {
        if (h[i - 1]) {
          b[c - 1] = i;
        } else {
          h[i] = 1;
          b[c++] = i;
        }
      }
    } else {
      if (A[i] <= A[i + 1]) {
        if (h[i - 1]) {
          b[c - 1] = i;
        } else {
          h[i] = 1;
          b[c++] = i;
        }
      }
    }
  }
  if (c > 2) {
    printf("0\n");
    return 0;
  }
  if (c == 1) {
    for (int i = 1; i <= N; ++i) {
      if (i != b[0]) {
        swap(A[b[0]], A[i]);
        if (chk(b[0]) && chk(i)) ans++;
        swap(A[b[0]], A[i]);
      }
    }
    if (h[b[0]] && b[0] < N) {
      b[0]++;
      for (int i = 1; i <= N; ++i) {
        if (i != b[0] && i != b[0] - 1) {
          swap(A[b[0]], A[i]);
          if (chk(b[0]) && chk(i)) ans++;
          swap(A[b[0]], A[i]);
        }
      }
    }
  } else {
    for (int i = max(1, b[0] - 1); i <= min(N, b[0] + 1); ++i)
      for (int j = max(1, b[1] - 1); j <= min(N, b[1] + 1); ++j) {
        if (i < j) {
          swap(A[i], A[j]);
          if (chk(b[0]) && chk(b[1])) ans++;
          swap(A[i], A[j]);
        }
      }
  }
  printf("%d\n", ans);
  return 0;
}
