#include <bits/stdc++.h>
using namespace std;
vector<long> items;
bool canPlace(long index, long value) {
  if (index & 0x01) {
    return (value > items[index - 1] && value > items[index + 1]);
  } else {
    if (index) {
      return value < items[index - 1] && value < items[index + 1];
    } else {
      return value < items[index + 1];
    }
  }
  return 0;
}
set<long> changes;
bool test(int index) {
  if (!canPlace(index, items[index])) {
    return false;
  }
  for (long i : changes) {
    if (!canPlace(i - 1, items[i - 1])) {
      return false;
    }
    if (!canPlace(i, items[i])) {
      return false;
    }
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  items.resize(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> items[i];
  }
  if (n & 1) {
    items[n] = 1000000;
  } else {
    items[n] = -1000000;
  }
  for (int i = 1; i < n; i += 2) {
    if (items[i - 1] >= items[i]) {
      changes.insert(i);
    }
  }
  for (int i = 2; i < n; i += 2) {
    if (items[i - 1] <= items[i]) {
      changes.insert(i);
    }
  }
  if (changes.size() > 5) {
    cout << 0;
  } else {
    set<long long> res;
    for (long i : changes) {
      int a = items[i - 1];
      for (int j = 0; j < n; j++) {
        int b = items[j];
        items[j] = a;
        items[i - 1] = b;
        if (test(j)) {
          long k = i - 1;
          long l = j;
          if (k > l) {
            k ^= l;
            l ^= k;
            k ^= l;
          }
          long long r = k;
          r <<= 32;
          r |= l;
          res.insert(r);
        }
        items[i - 1] = a;
        items[j] = b;
      }
      a = items[i];
      for (int j = 0; j < n; j++) {
        int b = items[j];
        items[j] = a;
        items[i] = b;
        if (test(j)) {
          long k = i;
          long l = j;
          if (k > l) {
            k ^= l;
            l ^= k;
            k ^= l;
          }
          long long r = k;
          r <<= 32;
          r |= l;
          res.insert(r);
        }
        items[i] = a;
        items[j] = b;
      }
    }
    cout << res.size();
  }
  return 0;
}
