#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 1e9 + 7;
const long long maxe = 1e9 + 7;
const long long INF = 1e9 + 7;
const double PI = acos(-1);
int dx[4] = {0, 0, 1, -1};
int dy[4] = {-1, 1, 0, 0};
int num;
int al[150005];
vector<int> vv;
set<pair<int, int> > sp;
bool rr(int gg) {
  if (gg == 0) return true;
  if (gg == num) return true;
  if (gg % 2 == 0) {
    return al[gg] > al[gg + 1];
  } else
    return al[gg] < al[gg + 1];
}
int main() {
  cin >> num;
  int zz = 0;
  for (int i = 1; i <= num; i++) {
    cin >> al[i];
  }
  for (int i = 1; i <= num - 1; i++) {
    if (i % 2 == 1) {
      if (al[i] >= al[i + 1]) {
        vv.push_back(i);
      }
    } else if (al[i] <= al[i + 1])
      vv.push_back(i);
  }
  sort((vv).begin(), (vv).end());
  if (((int)(vv).size()) > 4) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < ((int)(vv).size()); i++) {
    for (int k = 0; k < 2; k++) {
      int ff = vv[i] + k;
      if (ff > num) continue;
      for (int j = 1; j <= num; j++) {
        if (j == ff) continue;
        swap(al[j], al[ff]);
        int ok = 1;
        if (!rr(j) || !rr(j - 1)) ok = 0;
        if (!rr(ff) || !rr(ff - 1)) ok = 0;
        for (int z = 0; z < ((int)(vv).size()); z++) {
          int hh = vv[z];
          if (!rr(hh) || !rr(hh - 1)) ok = 0;
        }
        if (ok) sp.insert(make_pair(min(j, ff), max(j, ff)));
        swap(al[j], al[ff]);
      }
    }
  }
  cout << ((int)(sp).size()) << endl;
  return 0;
}
