#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 2;
const int maxlog = 20;
const int mod = 1e9 + 7;
const int sq = 350;
int a[maxn];
vector<int> v;
bool an[maxn];
int n;
map<pair<int, int>, bool> m;
bool check(int pl) {
  if (pl == 0 || pl >= n) return true;
  if (pl % 2 == 1 && a[pl] < a[pl + 1]) return true;
  if (pl % 2 == 0 && a[pl] > a[pl + 1]) return true;
  return false;
}
int solve() {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < v.size(); j++) {
      int pl1 = i, pl2 = v[j];
      if (pl1 == pl2) continue;
      swap(a[pl1], a[pl2]);
      bool tof = true;
      for (int k = 0; k < v.size(); k++) {
        int p = v[k];
        if (!check(p)) tof = false;
      }
      if (tof && check(pl1 + 1) && check(pl1) && check(pl1 - 1))
        m[make_pair(min(pl1, pl2), max(pl1, pl2))] = true;
      swap(a[pl1], a[pl2]);
    }
  }
  return m.size();
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    if (i % 2 == 1 && a[i] >= a[i + 1])
      an[i] = true, an[i + 1] = true, an[i - 1] = true;
    else if (a[i] <= a[i + 1] && i % 2 == 0)
      an[i] = true, an[i + 1] = true, an[i - 1] = true;
  }
  for (int i = 1; i <= n; i++)
    if (an[i]) v.push_back(i);
  if (v.size() > 10)
    cout << 0;
  else
    cout << solve();
  return 0;
}
