#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
void setmin(T& a, T val) {
  if (a > val) a = val;
}
template <class T>
void setmax(T& a, T val) {
  if (a < val) a = val;
}
void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
const int maxn = 200010;
int n;
int a[maxn];
map<pair<int, int>, int> tb;
int f[maxn];
int g[maxn];
int tot;
int check(int idx) {
  if (idx & 1) {
    if (a[idx] <= a[idx - 1]) {
      return 0;
    }
    if (idx < n - 1 && a[idx] <= a[idx + 1]) {
      return 0;
    }
  } else {
    if (idx && a[idx] >= a[idx - 1]) {
      return 0;
    }
    if (idx < n - 1 && a[idx] >= a[idx + 1]) {
      return 0;
    }
  }
  return 1;
}
long long work(int idx) {
  if (idx < 0 || idx >= n) return 0;
  if (f[idx]) return 0;
  f[idx] = 1;
  long long res = 0;
  for (int i = (0); i < (n); i++) {
    if (i != idx && !tb.count(make_pair(i, idx))) {
      tb[make_pair(i, idx)];
      tb[make_pair(idx, i)];
      swap(a[i], a[idx]);
      int flag = 1;
      if (!check(i)) flag = 0;
      if (i && !check(i - 1)) flag = 0;
      if (i < n - 1 && !check(i + 1)) flag = 0;
      if (!check(idx)) flag = 0;
      if (idx && !check(idx - 1)) flag = 0;
      if (idx < n - 1 && !check(idx + 1)) flag = 0;
      int r = 0;
      vector<int> v;
      v.push_back(i);
      if (i) v.push_back(i - 1);
      if (i < n - 1) v.push_back(i + 1);
      v.push_back(idx);
      if (idx) v.push_back(idx - 1);
      if (idx < n - 1) v.push_back(idx + 1);
      sort((v).begin(), (v).end());
      (v).erase(unique((v).begin(), (v).end()), (v).end());
      for (int j = (0); j < (int((v).size())); j++) {
        int u = v[j];
        if (g[u]) r++;
      }
      if (flag && r == tot) {
        res++;
      }
      swap(a[i], a[idx]);
    }
  }
  return res;
}
void solve() {
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) scanf("%d", a + i);
  int idx1 = -1, idx2 = -1;
  for (int i = 0; i < n - 1; i += 2) {
    if (a[i] >= a[i + 1]) {
      idx1 = i;
      g[i] = 1;
      tot++;
    }
  }
  for (int i = 1; i < n - 1; i += 2) {
    if (a[i] <= a[i + 1]) {
      idx2 = i;
      g[i] = 1;
      tot++;
    }
  }
  long long ans = work(idx1 - 1) + work(idx1) + work(idx1 + 1);
  ans += work(idx2 - 1) + work(idx2) + work(idx2 + 1);
  printf("%I64d\n", ans);
}
int main() {
  solve();
  return 0;
}
