#include <bits/stdc++.h>
using namespace std;
const long long N = 6e5 + 2;
const long long mod = 1e9 + 7;
long long n;
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    if (i & 1) {
      if (i > 0 && a[i] <= a[i - 1])
        v.push_back(i);
      else if (i < n - 1 && a[i] <= a[i + 1])
        v.push_back(i);
    } else {
      if (i > 0 && a[i] >= a[i - 1])
        v.push_back(i);
      else if (i < n - 1 && a[i] >= a[i + 1])
        v.push_back(i);
    }
  }
  if (v.size() > 6) {
    cout << 0;
    return 0;
  }
  set<pair<long long, long long> > s;
  for (long long i = 0; i < v.size(); i++) {
    for (long long j = 0; j < n; j++) {
      if (j == v[i]) continue;
      swap(a[v[i]], a[j]);
      bool flag = 0;
      for (long long k = 0; k < v.size(); k++) {
        long long i = v[k];
        if (i & 1) {
          if (i > 0 && a[i] <= a[i - 1])
            flag = 1;
          else if (i < n - 1 && a[i] <= a[i + 1])
            flag = 1;
        } else {
          if (i > 0 && a[i] >= a[i - 1])
            flag = 1;
          else if (i < n - 1 && a[i] >= a[i + 1])
            flag = 1;
        }
      }
      if (j & 1) {
        if (j > 0 && a[j] <= a[j - 1])
          flag = 1;
        else if (j < n - 1 && a[j] <= a[j + 1])
          flag = 1;
      } else {
        if (j > 0 && a[j] >= a[j - 1])
          flag = 1;
        else if (j < n - 1 && a[j] >= a[j + 1])
          flag = 1;
      }
      swap(a[v[i]], a[j]);
      if (!flag) {
        s.insert({min(v[i], j), max(v[i], j)});
      }
    }
  }
  cout << s.size();
  return 0;
}
