#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int a[N], n, res;
vector<int> id;
bool f(int i) {
  if (i & 1) {
    if ((i > 1 && a[i] >= a[i - 1]) || (i < n && a[i] >= a[i + 1])) return 1;
  } else {
    if ((i > 1 && a[i] <= a[i - 1]) || (i < n && a[i] <= a[i + 1])) return 1;
  }
  return 0;
}
signed main() {
  ios::sync_with_stdio(0), cin.tie(0);
  for (int i = 1 && cin >> n; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i)
    if (f(i)) id.push_back(i);
  if (id.size() <= 10) {
    for (auto& i : id) {
      for (int j = 1; j <= n; ++j) {
        bool F = 1;
        if (j > i || !f(j)) {
          swap(a[i], a[j]);
          F = !f(j);
          if (f)
            for (auto& z : id)
              if (f(z)) {
                F = 0;
                break;
              }
          res += F, swap(a[i], a[j]);
        }
      }
    }
  }
  cout << res;
  return 0;
}
