#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T>
inline void gmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
  if (b < a) a = b;
}
using namespace std;
const int N = 2e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647,
          ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567,
          ms127 = 2139062143;
const double PI = acos(-1.0), eps = 1e-8;
void fre() {
  freopen("/Users/luras/Desktop/in.txt", "r", stdin);
  freopen("/Users/luras/Desktop/out.txt", "w", stdout);
}
const int INF = 1e9;
int casenum, casei;
int n, t[N], ans, s, val[N];
set<pair<int, int> > ret;
vector<int> pos;
bool valid(int x) {
  if (x % 2 == 0) {
    return (x == n - 1 || t[x] < t[x + 1]) && (x == 0 || t[x] < t[x - 1]);
  } else {
    return (x == n - 1 || t[x] > t[x + 1]) && (x == 0 || t[x] > t[x - 1]);
  }
}
void upd(int x) {
  if (x < 0 || x >= n) return;
  s -= val[x];
  val[x] = valid(x);
  s += val[x];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &t[i]);
  for (int i = 0; i < n; i++) {
    val[i] = valid(i);
    if (!val[i]) pos.push_back(i);
    s += val[i];
  }
  if (pos.size() >= 7) {
    puts("0");
    return 0;
  }
  for (auto u : pos) {
    for (int v = 0; v < n; v++) {
      swap(t[u], t[v]);
      upd(u - 1);
      upd(u);
      upd(u + 1);
      upd(v - 1);
      upd(v);
      upd(v + 1);
      if (s == n) ret.insert(make_pair(min(u, v), max(u, v)));
      swap(t[u], t[v]);
      upd(u - 1);
      upd(u);
      upd(u + 1);
      upd(v - 1);
      upd(v);
      upd(v + 1);
    }
  }
  printf("%d\n", ret.size());
}
