#include <bits/stdc++.h>
using namespace std;
int t[150005];
int cnt;
vector<int> prob;
int isprob[150005];
int main() {
  int n;
  int swapPROB, swapGUEST;
  int ans = 0;
  int valid;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
  t[0] = 1000000;
  if (n % 2 == 1)
    t[n + 1] = 1000000;
  else
    t[n + 1] = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 1 && (t[i] >= t[i + 1] || t[i] >= t[i - 1]))
      prob.push_back(i), isprob[i]++;
    if (i % 2 == 0 && (t[i] <= t[i + 1] || t[i] <= t[i - 1]))
      prob.push_back(i), isprob[i]++;
  }
  if (prob.size() > 8) {
    printf("0");
    return 0;
  }
  for (int i = 0; i < prob.size(); i++) {
    for (int j = 1; j <= n; j++) {
      if (j == prob[i]) continue;
      if (isprob[j] && j > prob[i]) continue;
      valid = 1;
      swapPROB = t[j];
      swapGUEST = t[prob[i]];
      t[prob[i]] = swapPROB;
      t[j] = swapGUEST;
      for (int k = 0; k < prob.size(); k++) {
        for (int x = max(1, prob[k] - 5); x <= min(n, prob[k] + 5); x++) {
          if (x % 2 == 1 && (t[x] >= t[x + 1] || t[x] >= t[x - 1])) {
            valid = 0;
            break;
          } else if (x % 2 == 0 && (t[x] <= t[x + 1] || t[x] <= t[x - 1])) {
            valid = 0;
            break;
          }
        }
      }
      for (int k = max(1, j - 5); k <= min(n, j + 5); k++) {
        if (k % 2 == 1 && (t[k] >= t[k + 1] || t[k] >= t[k - 1])) {
          valid = 0;
          break;
        } else if (k % 2 == 0 && (t[k] <= t[k + 1] || t[k] <= t[k - 1])) {
          valid = 0;
          break;
        }
      }
      if (valid == 1) ans++;
      t[prob[i]] = swapGUEST;
      t[j] = swapPROB;
    }
  }
  printf("%d", ans);
}
