#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long LINF = 1e18;
const int INF = 1e9;
const double EPS = 1e-8;
int a[150005], n;
bool check(int l, int r) {
  if (l <= 0) {
    l = 1;
  }
  if (r >= n) {
    r = n - 1;
  }
  for (int i = l; i <= r; i++) {
    if (i & 1) {
      if (a[i] >= a[i + 1]) {
        return false;
      }
    } else {
      if (a[i] <= a[i + 1]) {
        return false;
      }
    }
  }
  return true;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> vv;
  for (int i = 1; i <= n - 1; i++) {
    if (i & 1) {
      if (a[i] >= a[i + 1]) {
        vv.push_back(i);
        i++;
      }
    } else {
      if (a[i] <= a[i + 1]) {
        vv.push_back(i);
        i++;
      }
    }
  }
  if ((int)vv.size() <= 2) {
    int ans = 0;
    set<pair<int, int> > se;
    if ((int)vv.size() == 1) {
      for (int i = vv[0] - 2; i <= vv[0] + 2; i++) {
        for (int j = 1; j <= n; j++) {
          if (i == j || i <= 0 || i > n) {
            continue;
          }
          swap(a[i], a[j]);
          if (check(i - 10, i + 10) && check(j - 10, j + 10)) {
            se.insert(make_pair(min(i, j), max(i, j)));
            ans++;
          }
          swap(a[i], a[j]);
        }
      }
    } else {
      for (int i = vv[0] - 2; i <= vv[0] + 2; i++) {
        for (int j = vv[1] - 2; j <= vv[1] + 2; j++) {
          if (i == j || i <= 0 || i > n || j <= 0 || j > n) {
            continue;
          }
          swap(a[i], a[j]);
          if (check(i - 10, i + 10) && check(j - 10, j + 10)) {
            se.insert(make_pair(min(i, j), max(i, j)));
          }
          swap(a[i], a[j]);
        }
      }
    }
    cout << (int)se.size() << endl;
  } else {
    cout << "0" << endl;
  }
}
