#include <bits/stdc++.h>
using namespace std;
int n;
int wrongs[888];
int wc = 0;
int d[888888];
int ans = 0;
bool check_edge(int x) {
  if (x + 1 >= n) return 1;
  if (x % 2 == 0) {
    return d[x] < d[x + 1];
  } else {
    return d[x] > d[x + 1];
  }
}
bool check(int x, int y) {
  if (x > 0 && !check_edge(x - 1)) return 0;
  if (!check_edge(x)) return 0;
  if (y > 0 && !check_edge(y - 1)) return 0;
  if (!check_edge(y)) return 0;
  for (int i = 0; i < wc; i++) {
    if (!check_edge(wrongs[i])) return 0;
  }
  return 1;
}
void change(int x, int y) {
  for (int i = 0; i < n; i++) {
    if (i == x) continue;
    if (i == y) continue;
    swap(d[i], d[x]);
    ans += check(i, x);
    swap(d[i], d[x]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &d[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    if (i % 2 == 0) {
      if (d[i] >= d[i + 1]) {
        if (wc >= 8 / 2) {
          printf("0\n");
          return 0;
        }
        wrongs[wc++] = i;
      }
    } else {
      if (d[i] <= d[i + 1]) {
        if (wc >= 8 / 2) {
          printf("0\n");
          return 0;
        }
        wrongs[wc++] = i;
      }
    }
  }
  change(wrongs[0], -1);
  change(wrongs[0] + 1, wrongs[0]);
  printf("%d\n", ans);
}
