#include <bits/stdc++.h>
using namespace std;
vector<int> v;
vector<int>::iterator it;
int n, ans;
int arr[150010] = {0};
bool vld(int p) {
  bool vv = 1;
  if (arr[p] <= arr[p - 1]) vv = 0;
  if (p < n && arr[p] <= arr[p + 1]) vv = 0;
  return vv;
}
void swp(int i1, int i2) {
  int temp = arr[i1];
  arr[i1] = arr[i2];
  arr[i2] = temp;
}
bool nice() {
  it = next(begin(v), 1);
  while (it != end(v)) {
    if (vld(*it) == false) return false;
    it++;
  }
  return true;
}
int main() {
  cin >> n;
  for (int i = 1, j = 2; i <= n; i++) {
    cin >> arr[i];
    if (i == n || i == j + 1) {
      if (vld(j) == 0) v.push_back(j);
      j = j + 2;
    }
  }
  int b, bi, a;
  if (v.size() > 3)
    ans = 0;
  else {
    a = arr[v[0]];
    bi = (arr[v[0] - 1] > arr[v[0] + 1]) ? v[0] - 1 : v[0] + 1;
    b = arr[bi];
    for (int p = 2; p <= n; p += 2) {
      if (arr[p] > b && arr[p - 1] < a && (p == n || arr[p + 1] < a)) {
        swp(v[0], p);
        if (nice() == 1) ans++;
        swp(v[0], p);
      }
      if (arr[p] < a) {
        if (arr[v[0]] == arr[v[0] - 1] && b > a) continue;
        if (arr[v[0]] == arr[v[0] + 1] && b > a) continue;
        if (arr[v[0]] < arr[v[0] - 1] && arr[v[0]] < arr[v[0] + 1]) continue;
        swp(bi, p);
        if (nice() == 1) ans++;
        swp(bi, p);
      }
    }
    for (int np = 1; np <= n; np = np + 2) {
      if (arr[np] > b) {
        swp(v[0], np);
        if (nice() == 1) ans++;
        swp(v[0], np);
      }
      if (arr[np] < a && (np - 1 == 0 || arr[np - 1] > b) &&
          (np == n || arr[np + 1] > b)) {
        if (arr[v[0]] == arr[v[0] - 1] && b > a) continue;
        if (arr[v[0]] == arr[v[0] + 1] && b > a) continue;
        if (arr[v[0]] < arr[v[0] - 1] && arr[v[0]] < arr[v[0] + 1]) continue;
        swp(bi, np);
        if (nice() == 1) ans++;
        swp(bi, np);
      }
    }
    swp(bi, v[0]);
    if (nice() == 1 && vld(v[0])) ans++;
    swp(bi, v[0]);
  }
  cout << ans << '\n';
  return 0;
}
