#include <bits/stdc++.h>
using namespace std;
int n, A[200010];
int ok(int p) {
  if (p >= n || p <= 0) return 1;
  if (p & 1)
    return A[p] < A[p + 1];
  else
    return A[p] > A[p + 1];
}
int q[200010], cnt_q;
struct node {
  int x, y;
  bool operator<(const node &b) const { return x != b.x ? x < b.x : y < b.y; }
} T[5000000];
int check(int x, int y) {
  swap(A[x], A[y]);
  if (!ok(x)) return swap(A[x], A[y]), 0;
  if (!ok(x - 1)) return swap(A[x], A[y]), 0;
  if (!ok(y)) return swap(A[x], A[y]), 0;
  if (!ok(y - 1)) return swap(A[x], A[y]), 0;
  for (int i = 1; i <= cnt_q; ++i) {
    if (!ok(q[i])) return swap(A[x], A[y]), 0;
  }
  swap(A[x], A[y]);
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &A[i]);
  for (int i = 1; i < n; ++i)
    if (!ok(i)) {
      q[++cnt_q] = i;
    }
  if (cnt_q > 5) {
    printf("0\n");
    return 0;
  }
  int cnt_T = 0;
  for (int c = 1; c <= cnt_q; ++c) {
    for (int i = 1; i <= n; ++i)
      if (i != q[c]) {
        T[++cnt_T] = (node){min(i, q[c]), max(i, q[c])};
      }
    for (int i = 1; i <= n; ++i)
      if (i != q[c] + 1) {
        T[++cnt_T] = (node){min(i, q[c] + 1), max(i, q[c] + 1)};
      }
  }
  sort(T + 1, T + cnt_T + 1);
  int ans = 0;
  for (int i = 1; i <= cnt_T; ++i)
    if (i == 1 || T[i].x != T[i - 1].x || T[i].y != T[i - 1].y)
      ans += check(T[i].x, T[i].y);
  printf("%d\n", ans);
  return 0;
}
