#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000001;
const int MOD = 1000000007;
int a[155009];
int n;
inline bool check(int pos) {
  if (pos <= 0 || pos >= n) return true;
  if (pos % 2 == 0 && a[pos] <= a[pos + 1]) return false;
  if (pos % 2 == 1 && a[pos] >= a[pos + 1]) return false;
  return true;
}
vector<int> ch;
int ans = 0;
bool try_swap(int pos1, int pos2) {
  swap(a[pos1], a[pos2]);
  bool ok = true;
  for (int i = (0); i <= ((int)((ch).size()) - 1); ++i) ok &= check(ch[i]);
  for (int dx = (-2); dx <= (2); ++dx)
    ok &= check(pos1 + dx), ok &= check(pos2 + dx);
  ans += ok;
  swap(a[pos1], a[pos2]);
}
bool bad[155009];
int main() {
  cin >> n;
  for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]);
  vector<int> inx;
  for (int i = (1); i <= (n - 1); ++i)
    if (i % 2 == 1 && a[i] >= a[i + 1] || i % 2 == 0 && a[i] <= a[i + 1]) {
      ch.push_back(i);
      inx.push_back(i);
      inx.push_back(i + 1);
    }
  sort(inx.begin(), inx.end());
  inx.resize(unique(inx.begin(), inx.end()) - inx.begin());
  for (int i = (0); i <= ((int)((inx).size()) - 1); ++i) bad[inx[i]] = true;
  if ((int)((inx).size()) >= 8) {
    cout << "0" << endl;
    return 0;
  }
  for (int i1 = (0); i1 <= ((int)((inx).size()) - 1); ++i1)
    for (int i2 = (i1 + 1); i2 <= ((int)((inx).size()) - 1); ++i2) {
      int pos1 = inx[i1];
      int pos2 = inx[i2];
      try_swap(pos1, pos2);
    }
  for (int i1 = (0); i1 <= ((int)((inx).size()) - 1); ++i1)
    for (int i2 = (1); i2 <= (n); ++i2)
      if (!bad[i2]) {
        int pos1 = inx[i1];
        int pos2 = i2;
        try_swap(pos1, pos2);
      }
  cout << ans << endl;
}
