#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
#pragma GCC optimize("03")
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n + 2);
  v[0] = 2e5;
  v[n + 1] = 2e5;
  if ((n + 1) & 1) v[n + 1] = 0;
  vector<int> cant(n + 2);
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    if (i & 1) {
      if (v[i] >= v[i - 1]) {
        sum++;
        cant[i - 1]++;
        cant[i]++;
      }
    } else {
      if (v[i] <= v[i - 1]) {
        sum++;
        cant[i - 1]++;
        cant[i]++;
      }
    }
  }
  if (sum > 4) {
    cout << (0) << '\n';
    return 0;
  }
  vector<int> p1;
  vector<int> p2;
  for (int i = 1; i <= n; i++)
    if (sum == cant[i]) p1.push_back(i);
  for (int i = 1; i <= n; i++)
    if (cant[i] && cant[i] != sum) p2.push_back(i);
  long long res = 0;
  for (auto y : p1) {
    for (int i = 1; i <= n; i++) {
      if (i == y) continue;
      if (cant[i] == sum && i < y) continue;
      swap(v[i], v[y]);
      bool ok = 1;
      if (i & 1)
        ok &= (v[i] < (min(v[i - 1], v[i + 1])));
      else
        ok &= (v[i] > (max(v[i - 1], v[i + 1])));
      if (y & 1)
        ok &= (v[y] < (min(v[y - 1], v[y + 1])));
      else
        ok &= (v[y] > (max(v[y - 1], v[y + 1])));
      res += ok;
      swap(v[i], v[y]);
    }
  }
  for (auto y1 : p2) {
    for (auto y2 : p2) {
      if (y1 >= y2) continue;
      swap(v[y1], v[y2]);
      int sum = 0;
      for (int i = 1; i <= n; i++) {
        if (i & 1) {
          if (v[i] >= v[i - 1]) {
            sum++;
            cant[i - 1]++;
            cant[i]++;
          }
        } else {
          if (v[i] <= v[i - 1]) {
            sum++;
            cant[i - 1]++;
            cant[i]++;
          }
        }
      }
      res += (sum == 0);
      swap(v[y1], v[y2]);
    }
  }
  cout << (res) << '\n';
  return 0;
}
