#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1.5e5 + 10;
int n;
int arr[MAXN];
vector<int> record;
bool ok(int p) {
  if (p <= 0 || p >= n) return 1;
  if (p & 1)
    return arr[p] < arr[p + 1];
  else
    return arr[p] > arr[p + 1];
}
bool check(int a, int b) {
  bool flag = 1;
  swap(arr[a], arr[b]);
  for (int i = 0; i < record.size(); i++)
    if (!ok(record[i])) flag = 0;
  if (!ok(a) || !ok(a - 1) || !ok(b) || !ok(b - 1)) flag = 0;
  swap(arr[a], arr[b]);
  return flag;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", arr + i);
  for (int i = 1; i < n; i++) {
    if (!ok(i)) record.push_back(i);
  }
  if (record.size() > 4) {
    printf("0\n");
  } else {
    int x = record[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;
}
