#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160000")
using namespace std;
int n, t[160000];
set<std::pair<int, int> > vis;
bool check(int a, int b) {
  if (a > b) swap(a, b);
  if (a < 1 || b > n) return 0;
  if (a == b) return 0;
  if (vis.find(std::pair<int, int>(a, b)) != vis.end()) return 0;
  vis.insert(std::pair<int, int>(a, b));
  swap(t[a], t[b]);
  bool ret = 1;
  for (int i = 1; i <= (int)n - 1; i++) {
    if (i % 2 == 1 && t[i] >= t[i + 1]) ret = 0;
    if (i % 2 == 0 && t[i] <= t[i + 1]) ret = 0;
  }
  swap(t[a], t[b]);
  return ret;
}
int main() {
  cin >> n;
  for (int i = 1; i <= (int)n; i++) cin >> t[i];
  t[0] = 100000000;
  t[n + 1] = -100000000;
  if (n % 2 == 1) t[n + 1] = -t[n + 1];
  vector<int> bad;
  for (int i = 1; i <= (int)n - 1; i++) {
    if (i % 2 == 1 && t[i] >= t[i + 1]) bad.push_back(i);
    if (i % 2 == 0 && t[i] <= t[i + 1]) bad.push_back(i);
  }
  if (bad.size() > 4) {
    cout << 0;
    return 0;
  }
  if (bad.size() == 4) {
    if (check(bad[1], bad[3]))
      cout << 1;
    else
      cout << 0;
    return 0;
  }
  if (bad.size() == 3) {
    int answer = 0;
    if (check(bad[0], bad[2])) answer++;
    if (check(bad[0], bad[2] + 1)) answer++;
    if (check(bad[0] + 1, bad[2])) answer++;
    if (check(bad[1], bad[2])) answer++;
    if (check(bad[1] + 1, bad[2])) answer++;
    if (check(bad[1], bad[2] + 1)) answer++;
    if (check(bad[0], bad[1])) answer++;
    if (check(bad[0], bad[1] + 1)) answer++;
    if (check(bad[0] + 1, bad[1])) answer++;
    if (check(bad[0] + 1, bad[1] + 1)) answer++;
    if (check(bad[1] + 1, bad[2] + 1)) answer++;
    if (check(bad[0] + 1, bad[2] + 1)) answer++;
    cout << answer;
    return 0;
  }
  if (bad.size() == 2) {
    if (bad[0] != bad[1] - 1) {
      int answer = 0;
      if (check(bad[0], bad[1])) answer++;
      if (check(bad[0] + 1, bad[1])) answer++;
      if (check(bad[0], bad[1] + 1)) answer++;
      if (check(bad[0] + 1, bad[1] + 1)) answer++;
      cout << answer;
      return 0;
    }
    int answer = 0;
    if (check(bad[0], bad[1] + 1)) answer++;
    if (check(bad[0], bad[1])) answer++;
    if (check(bad[0] + 1, bad[1] + 1)) answer++;
    for (int i = 1; i <= (int)n; i++) {
      if (i >= bad[0] && i <= bad[1] + 1) continue;
      int now = t[i];
      int toswap = t[bad[1]];
      if (i % 2 == 1 && (toswap >= t[i - 1] || toswap >= t[i + 1])) continue;
      if (i % 2 == 0 && (toswap <= t[i - 1] || toswap <= t[i + 1])) continue;
      if (bad[1] % 2 == 0 && (now <= t[bad[0]] || now <= t[bad[1] + 1]))
        continue;
      if (bad[1] % 2 == 1 && (now >= t[bad[0]] || now >= t[bad[1] + 1]))
        continue;
      answer++;
    }
    cout << answer;
    return 0;
  }
  int answer = 0;
  if (check(bad[0] - 1, bad[0])) answer++;
  if (check(bad[0] - 1, bad[0] + 1)) answer++;
  if (check(bad[0] - 1, bad[0] + 2)) answer++;
  if (check(bad[0], bad[0] + 1)) answer++;
  if (check(bad[0], bad[0] + 2)) answer++;
  if (check(bad[0] + 1, bad[0] + 2)) answer++;
  for (int i = 1; i <= (int)n; i++) {
    if (i >= bad[0] - 1 && i <= bad[0] + 2) continue;
    int now = t[i];
    int toswap = t[bad[0]];
    if (i % 2 == 1 && (toswap >= t[i - 1] || toswap >= t[i + 1])) continue;
    if (i % 2 == 0 && (toswap <= t[i - 1] || toswap <= t[i + 1])) continue;
    if (bad[0] % 2 == 0 && (now <= t[bad[0] - 1] || now <= t[bad[0] + 1]))
      continue;
    if (bad[0] % 2 == 1 && (now >= t[bad[0] - 1] || now >= t[bad[0] + 1]))
      continue;
    answer++;
  }
  for (int i = 1; i <= (int)n; i++) {
    if (i >= bad[0] - 1 && i <= bad[0] + 2) continue;
    int now = t[i];
    int toswap = t[bad[0] + 1];
    if (i % 2 == 1 && (toswap >= t[i - 1] || toswap >= t[i + 1])) continue;
    if (i % 2 == 0 && (toswap <= t[i - 1] || toswap <= t[i + 1])) continue;
    if ((bad[0] + 1) % 2 == 0 && (now <= t[bad[0]] || now <= t[bad[0] + 2]))
      continue;
    if ((bad[0] + 1) % 2 == 1 && (now >= t[bad[0]] || now >= t[bad[0] + 2]))
      continue;
    answer++;
  }
  cout << answer;
  return 0;
}
