#include <bits/stdc++.h>
using namespace std;
const int N = 151234;
int v[N], n;
vector<int> e;
unordered_map<long long, bool> mp;
inline bool chk(int i) {
  if ((i & 1) != 0 && (i == n || v[i] < v[i + 1])) return true;
  if ((i & 1) == 0 && (i == n || v[i] > v[i + 1])) return true;
  return false;
}
inline void get(int x, int y) {
  swap(v[x], v[y]);
  for (int i = 0; i < e.size(); ++i) {
    if (!chk(e[i])) {
      swap(v[x], v[y]);
      return;
    }
  }
  for (int i = max(x - 1, 1); i <= min(x + 1, n); ++i) {
    if (!chk(i)) {
      swap(v[x], v[y]);
      return;
    }
  }
  for (int i = max(y - 1, 1); i <= min(y + 1, n); ++i) {
    if (!chk(i)) {
      swap(v[x], v[y]);
      return;
    }
  }
  if (x > y) swap(x, y);
  mp[1LL * 1e9 * x + y]++;
  swap(v[x], v[y]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &v[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (!chk(i)) e.push_back(i);
  }
  int sz = e.size();
  int pv = e[0];
  if (sz >= 5) {
    puts("0");
    return 0;
  }
  for (int i = max(pv - 1, 1); i <= min(pv + 1, n); ++i) {
    for (int j = 1; j <= n; ++j) {
      get(i, j);
    }
  }
  cout << mp.size();
}
