#include <bits/stdc++.h>
using namespace std;
const int N = 1500009;
int t[N], n;
bool ok(int i) {
  if (i < 1 || i >= n) return 1;
  if ((i & 1) && t[i] >= t[i + 1]) return 0;
  if (!(i & 1) && t[i] <= t[i + 1]) return 0;
  return 1;
}
vector<int> bd;
bool check(int a, int b) {
  bool flag = 1;
  swap(t[a], t[b]);
  for (int i = 0; i < bd.size(); i++)
    if (!ok(bd[i])) flag = 0;
  if (!ok(a) || !ok(a - 1) || !ok(b) || !ok(b - 1)) flag = 0;
  swap(t[a], t[b]);
  return flag;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
  for (int i = 1; i < n; i++)
    if (!ok(i)) bd.push_back(i);
  if (bd.size() > 4) {
    printf("0\n");
    return 0;
  }
  int x = bd[0];
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (check(i, x)) ans++;
  for (int i = 1; i <= n; i++)
    if (check(i, x + 1)) ans++;
  if (check(x, x + 1)) ans--;
  printf("%d\n", ans);
  return 0;
}
