#include <bits/stdc++.h>
using namespace std;
const int maxn = 150000;
int a[maxn];
int n;
bool now[maxn];
vector<pair<int, int> > ans;
bool check(int i) {
  if (i % 2 == 0) {
    if (i > 0)
      if (a[i] >= a[i - 1]) return false;
    if (i < n - 1)
      if (a[i] >= a[i + 1]) return false;
    return true;
  } else {
    if (i > 0)
      if (a[i] <= a[i - 1]) return false;
    if (i < n - 1)
      if (a[i] <= a[i + 1]) return false;
    return true;
  }
}
int main() {
  ::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> bad;
  for (int i = 0; i < n; ++i) cin >> a[i];
  int sum = 0;
  for (int i = 0; i < n; ++i) now[i] = check(i), sum += now[i];
  for (int i = 0; i < n; ++i) {
    if ((now[i] == false) || (i < n - 1 && now[i + 1] == false) ||
        (i > 0 && now[i - 1] == false))
      bad.push_back(i);
  }
  if (bad.size() > 10) {
    cout << 0;
    return 0;
  }
  for (auto x : bad) {
    for (int i = 0; i < n; ++i) {
      vector<int> checker;
      for (int j = max(i - 2, 0); j < n && j <= i + 2; ++j)
        checker.push_back(j);
      for (int j = max(x - 2, 0); j < n && j <= x + 2; ++j)
        checker.push_back(j);
      sort(checker.begin(), checker.end());
      checker.resize(unique(checker.begin(), checker.end()) - checker.begin());
      for (auto x : checker) sum -= check(x);
      swap(a[i], a[x]);
      for (auto x : checker) sum += check(x);
      if (sum == n) ans.push_back({min(i, x), max(i, x)});
      for (auto x : checker) sum -= check(x);
      swap(a[i], a[x]);
      for (auto x : checker) sum += check(x);
    }
  }
  sort(ans.begin(), ans.end());
  ans.resize(unique(ans.begin(), ans.end()) - ans.begin());
  cout << ans.size() << endl;
  return 0;
}
