#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long double PI = 3.1415926535897932384626433832795028841;
bool TST = 0;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
void Show(int *QQ, int N) {
  if (not TST) {
    return;
  }
  for (int x = 0; x < N; x++) {
    cout << QQ[x];
    if (x != N - 1) {
      cout << ',';
    }
  }
  cout << '\n';
}
void ShowLL(long long *QQ, int N) {
  if (not TST) {
    return;
  }
  for (int x = 0; x < N; x++) {
    cout << QQ[x];
    if (x != N - 1) {
      cout << ',';
    }
  }
  cout << '\n';
}
int n, T[150002];
int D[150002];
int EC[150002];
set<pair<int, int> > U;
int RR(int a, int b) {
  if (a >= b) {
    return 0;
  }
  return EC[((b - 1) + 1)] - EC[((a - 1) + 1)];
}
bool BackCheck(int i) {
  if (i == 0) {
    return 1;
  }
  if ((i - 1) % 2 == 1) {
    return D[i - 1] > D[i];
  }
  return D[i - 1] < D[i];
}
bool FrontCheck(int i) {
  if (i == n - 1) {
    return 1;
  }
  if (i % 2 == 1) {
    return D[i] > D[i + 1];
  }
  return D[i] < D[i + 1];
}
bool Errors(int i) { return (not BackCheck(i)) or (not FrontCheck(i)); }
void MARK(int x, int y) {
  int a = min(x, y);
  int b = max(x, y);
  U.insert(pair<int, int>(a, b));
}
bool USED(int x, int y) {
  int a = min(x, y);
  int b = max(x, y);
  if (U.find(pair<int, int>(a, b)) != U.end()) {
    return true;
  }
  return false;
}
int swapCheck(int i) {
  for (int x = 0; x < n; x++) {
    D[x] = T[x];
  }
  int ways = 0;
  for (int x = 0; x < n; x++) {
    if (x == i) {
      continue;
    }
    if (USED(x, i)) {
      continue;
    }
    MARK(x, i);
    swap(D[x], D[i]);
    if (Errors(i) or Errors(x)) {
      swap(D[x], D[i]);
      continue;
    }
    int t1 = min(x, i);
    int t2 = max(x, i);
    int b1 = RR(0, t1 - 1);
    int b2 = RR(t1 + 1, t2 - 1);
    int b3 = RR(t2 + 1, n - 1);
    if (b1 + b2 + b3 > 0) {
      swap(D[x], D[i]);
      continue;
    }
    ways++;
    swap(D[x], D[i]);
  }
  return ways;
}
int main() {
  scanf("%i", &n);
  for (int x = 0; x < n; x++) {
    scanf("%i", &T[x]);
  }
  EC[0] = 0;
  for (int x = 0; x < n; x++) {
    int errors = 0;
    if (x % 2 == 0 and T[x] >= T[x + 1]) {
      errors++;
    }
    if (x % 2 == 1 and T[x] <= T[x + 1]) {
      errors++;
    }
    EC[x + 1] = EC[x] + errors;
  }
  if (EC[n - 1] > 4) {
    printf("0\n");
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0 and T[i] >= T[i + 1]) {
      ans += swapCheck(i);
      ans += swapCheck(i + 1);
      i++;
    }
    if (i % 2 == 1 and T[i] <= T[i + 1]) {
      ans += swapCheck(i);
      ans += swapCheck(i + 1);
      i++;
    }
  }
  printf("%i\n", ans);
}
