#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> x(n - 1);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n - 1; ++i) {
    if (i & 1)
      x[i] = (a[i + 1] < a[i]);
    else
      x[i] = (a[i + 1] > a[i]);
  }
  set<int> bad;
  for (int i = 0; i < x.size(); ++i)
    if (!x[i]) {
      bad.insert(i);
      bad.insert(i + 1);
    }
  if (bad.size() > 8) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for (auto i : bad)
    for (int j = 0; j < n; ++j) {
      if (j < i && bad.find(j) != bad.end()) continue;
      swap(a[i], a[j]);
      bool fail = 0;
      for (int u = max(0, j - 1); u < min(j + 1, n - 1); ++u) {
        if ((u & 1) && a[u + 1] >= a[u]) fail = 1;
        if (!(u & 1) && a[u + 1] <= a[u]) fail = 1;
      }
      for (int u = max(0, i - 1); u < min(i + 1, n - 1); ++u) {
        if ((u & 1) && a[u + 1] >= a[u]) fail = 1;
        if (!(u & 1) && a[u + 1] <= a[u]) fail = 1;
      }
      for (auto y : bad) {
        if (y == n - 1) continue;
        if ((y & 1) && a[y + 1] >= a[y]) fail = 1;
        if (!(y & 1) && a[y + 1] <= a[y]) fail = 1;
      }
      if (!fail) ++ans;
      swap(a[i], a[j]);
    }
  cout << ans << endl;
  return 0;
}
