#include <bits/stdc++.h>
using namespace std;
template <typename T, typename S>
inline bool upmin(T& a, const S& b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
inline bool upmax(T& a, const S& b) {
  return a < b ? a = b, 1 : 0;
}
template <typename N, typename PN>
inline N flo(N a, PN b) {
  return a >= 0 ? a / b : -((-a - 1) / b) - 1;
}
template <typename N, typename PN>
inline N cei(N a, PN b) {
  return a > 0 ? (a - 1) / b + 1 : -(-a / b);
}
template <typename N>
N gcd(N a, N b) {
  return b ? gcd(b, a % b) : a;
}
inline void gn(long long& x) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= sg;
}
inline void gn(int& x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(unsigned long long& x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(double& x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gn(long double& x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline long long sqr(long long a) { return a * a; }
inline double sqrf(double a) { return a * a; }
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
int mo = 1000000007;
int qp(int a, long long b) {
  int n = 1;
  do {
    if (b & 1) n = 1ll * n * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return n;
}
int n;
int a[555555];
int no[555555];
int ntot = 0;
int ch(int i) {
  if (i <= 0 || i >= n) return 1;
  if (i & 1) return a[i] < a[i + 1];
  return a[i] > a[i + 1];
}
int tr[555555];
map<pair<int, int>, bool> ma;
void gao(int i, int j) {
  if (i > j) swap(i, j);
  int bo = 1;
  swap(a[i], a[j]);
  for (int k = (1), _ed = (ntot + 1); k < _ed; k++)
    if (!ch(no[k])) bo = 0;
  if (!ch(i - 1)) bo = 0;
  if (!ch(j - 1)) bo = 0;
  if (!ch(i)) bo = 0;
  if (!ch(j)) bo = 0;
  swap(a[i], a[j]);
  if (bo) ma[make_pair(i, j)] = 1;
}
int main() {
  gn(n);
  for (int i = (1), _ed = (n + 1); i < _ed; i++) gn(a[i]);
  for (int i = (1), _ed = (n); i < _ed; i++)
    if (!ch(i)) no[++ntot] = i;
  if (ntot > 5) {
    printf("0\n");
    return 0;
  }
  for (int i = (1), _ed = (ntot + 1); i < _ed; i++)
    tr[no[i]] = tr[no[i] + 1] = 1;
  for (int i = (1), _ed = (n + 1); i < _ed; i++)
    if (tr[i]) {
      for (int j = 1; j <= n; j++)
        if (j != i) gao(i, j);
    }
  printf("%d\n", ((int)(ma).size()));
  return 0;
}
