#include <bits/stdc++.h>
using namespace std;
struct T {
  int x, y;
};
T t = {1, 2};
const int ma = 2 * 131072;
int n, ans;
vector<long long> a;
map<pair<int, int>, int> kk;
bool ok1(int nu) {
  if (nu % 2 == 0) {
    if (nu && a[nu - 1] <= a[nu]) return false;
    if (nu + 1 < n && a[nu + 1] <= a[nu]) return false;
  }
  if (nu % 2) {
    if (nu && a[nu - 1] >= a[nu]) return false;
    if (nu + 1 < n && a[nu + 1] >= a[nu]) return false;
  }
  return true;
}
int main() {
  iostream::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  a.resize(n);
  for (long long i = 0; i < int(n); i++) cin >> a[i];
  vector<int> nu, nu2;
  for (int i = 1; i < n; i += 2) {
    if (a[i] <= a[i - 1] || (i + 1 < n && a[i] <= a[i + 1])) nu.push_back(i);
  }
  for (int i = 0; i < n; i += 2) {
    if ((i && a[i] >= a[i - 1]) || (i + 1 < n && a[i] >= a[i + 1]))
      nu2.push_back(i);
  }
  if ((int)nu.size() > 8 || (int)nu2.size() > 8) {
    cout << 0;
    return 0;
  }
  int k = nu[0];
  bool ok;
  for (int i = k - 1; i < min(k + 2, n); i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      swap(a[i], a[j]);
      ok = true;
      for (long long i = 0; i < int((int)nu.size()); i++) {
        if (!ok1(nu[i])) ok = false;
      }
      for (long long i = 0; i < int((int)nu2.size()); i++) {
        if (!ok1(nu2[i])) ok = false;
      }
      if (!ok1(i) || !ok1(j)) ok = false;
      if (ok) {
        if (!kk[make_pair(i, j)]) ans++;
        kk[make_pair(i, j)] = kk[make_pair(j, i)] = 1;
      }
      swap(a[i], a[j]);
    }
  }
  cout << ans;
  return 0;
}
