#include <bits/stdc++.h>
using namespace std;
vector<int> arr;
set<int> indices;
bool valid(int ind1, int ind2) {
  for (int i = max(0, ind1 - 10); i + 1 < min(ind1 + 10, (int)arr.size());
       i++) {
    if (i % 2 == 0 && arr[i] >= arr[i + 1]) return 0;
    if (i % 2 == 1 && arr[i] <= arr[i + 1]) return 0;
  }
  for (int i = max(0, ind2 - 10); i + 1 < min(ind2 + 10, (int)arr.size());
       i++) {
    if (i % 2 == 0 && arr[i] >= arr[i + 1]) return 0;
    if (i % 2 == 1 && arr[i] <= arr[i + 1]) return 0;
  }
  for (int ind : indices) {
    for (int i = max(0, ind - 10); i + 1 < min(ind + 10, (int)arr.size());
         i++) {
      if (i % 2 == 0 && arr[i] >= arr[i + 1]) return 0;
      if (i % 2 == 1 && arr[i] <= arr[i + 1]) return 0;
    }
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  arr = vector<int>(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  int errors = 0;
  for (int i = 0; i + 1 < n && errors <= 2; i++) {
    if (i % 2 == 0 && arr[i] >= arr[i + 1]) {
      errors++, i++;
      for (int j = max(0, i - 2); j < min(i + 3, (int)arr.size()); j++)
        indices.insert(j);
    } else if (i % 2 == 1 && arr[i] <= arr[i + 1]) {
      errors++, i++;
      for (int j = max(0, i - 2); j < min(i + 3, (int)arr.size()); j++)
        indices.insert(j);
    }
  }
  if (errors > 2) {
    cout << 0;
    return 0;
  }
  set<pair<int, int> > ans;
  for (int ind : indices) {
    for (int i = 0; i < n; i++) {
      if (i == ind) continue;
      swap(arr[ind], arr[i]);
      if (valid(i, ind)) {
        ans.insert({min(i, ind), max(i, ind)});
      }
      swap(arr[ind], arr[i]);
    }
  }
  cout << ans.size() << endl;
  return 0;
}
