#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
bool get_bad(const vector<int>& v, int i) {
  assert(i + 1 < v.size());
  if (i & 1) {
    return (v[i] <= v[i + 1]);
  } else {
    return (v[i] >= v[i + 1]);
  }
}
int solve_smart(int n, vector<int> v) {
  vector<bool> is_bad(n, false);
  set<int> bad_ind;
  for (int i = 0; i < n - 1; i++) {
    is_bad[i] = get_bad(v, i);
  }
  int real_bad = 0;
  for (int i = 0; i < n; i++) {
    if (is_bad[i]) {
      bad_ind.insert(i);
      real_bad++;
      if (i > 0) bad_ind.insert(i - 1);
      if (i + 1 < n) bad_ind.insert(i + 1);
    }
  }
  if (bad_ind.size() > 10) {
    return 0;
  }
  vector<pair<int, int>> result;
  for (int i = 0; i < n; i++) {
    for (int j : bad_ind) {
      if (i != j) {
        int balance = n - real_bad;
        swap(v[i], v[j]);
        vector<int> candidates = {i - 1, i, i + 1, j - 1, j, j + 1};
        sort(candidates.begin(), candidates.end());
        candidates.erase(unique(candidates.begin(), candidates.end()),
                         candidates.end());
        for (int k : candidates) {
          if (k >= 0 && k < n - 1) {
            int update = int(is_bad[k]) - get_bad(v, k);
            balance += update;
          }
        }
        swap(v[i], v[j]);
        if (balance == n) {
          if (i < j)
            result.push_back({i, j});
          else
            result.push_back({j, i});
        }
      }
    }
  }
  sort(result.begin(), result.end());
  result.erase(unique(result.begin(), result.end()), result.end());
  return result.size();
}
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  cout << solve_smart(n, v) << endl;
  return 0;
}
