#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = int(1e9);
const int MAX = 150007;
int n, good, a[MAX], val[MAX];
vector<int> bad;
set<pair<int, int> > res;
bool valid(int x) {
  if (x == 1) {
    if (a[x] >= a[x + 1]) return false;
    return true;
  } else if (x == n) {
    if ((n - 1) % 2 == 0) {
      if (a[n - 1] <= a[n]) return false;
    } else {
      if (a[n - 1] >= a[n]) return false;
    }
  } else if (x % 2 == 0) {
    if (a[x] <= a[x + 1] || a[x] <= a[x - 1]) return false;
  } else {
    if (a[x] >= a[x + 1] || a[x] >= a[x - 1]) return false;
  }
  return true;
}
void update(int x) {
  if (x < 1 || x > n) {
    return;
  }
  good -= val[x];
  val[x] = valid(x);
  good += val[x];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    val[i] = valid(i);
    if (!val[i]) {
      bad.push_back(i);
    }
    good += val[i];
  }
  if (bad.size() > 15) {
    cout << "0\n";
    return 0;
  }
  for (int x : bad) {
    for (int i = 1; i <= n; i++) {
      if (x != i) {
        swap(a[x], a[i]);
        update(x - 1), update(x), update(x + 1), update(i), update(i - 1),
            update(i + 1);
        if (good == n) {
          res.insert(make_pair(min(i, x), max(i, x)));
        }
        swap(a[x], a[i]);
        update(x - 1), update(x), update(x + 1), update(i), update(i - 1),
            update(i + 1);
      }
    }
  }
  cout << res.size() << "\n";
  return 0;
}
