#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  long long int n;
  cin >> n;
  long long int ip[n + 2];
  for (long long int i = 1; i < n + 1; i++) cin >> ip[i];
  ip[0] = LONG_LONG_MAX;
  if (n & 1)
    ip[n + 1] = LONG_LONG_MAX;
  else
    ip[n + 1] = 0;
  vector<long long int> jt;
  for (long long int i = 1; i < n + 1; i++) {
    if (i & 1) {
      if (min(ip[i - 1], ip[i + 1]) <= ip[i]) jt.push_back(i);
    } else {
      if (max(ip[i - 1], ip[i + 1]) >= ip[i]) jt.push_back(i);
    }
  }
  if (jt.size() > 6)
    return cout << "0", 0;
  else {
    long long int ans = 0;
    map<pair<long long int, long long int>, bool> m;
    for (auto j : jt) {
      for (long long int i = 1; i < n + 1; i++) {
        bool f = 0;
        set<long long int> s;
        if (i == j) continue;
        swap(ip[i], ip[j]);
        for (long long int l = j - 1; l < j + 2; l++) {
          if (!l || l == n + 1) continue;
          if (l & 1) {
            if (min(ip[l - 1], ip[l + 1]) > ip[l]) {
              for (long long int q = 0; q < jt.size(); q++)
                if (l == jt[q]) s.insert(l);
            } else
              f = 1;
          } else {
            if (max(ip[l - 1], ip[l + 1]) < ip[l]) {
              for (long long int q = 0; q < jt.size(); q++)
                if (l == jt[q]) s.insert(l);
            } else
              f = 1;
          }
        }
        for (long long int l = i - 1; l < i + 2; l++) {
          if (!l || l == n + 1) continue;
          if (l & 1) {
            if (min(ip[l - 1], ip[l + 1]) > ip[l]) {
              for (long long int q = 0; q < jt.size(); q++)
                if (l == jt[q]) s.insert(l);
            } else
              f = 1;
          } else {
            if (max(ip[l - 1], ip[l + 1]) < ip[l]) {
              for (long long int q = 0; q < jt.size(); q++)
                if (l == jt[q]) s.insert(l);
            } else
              f = 1;
          }
        }
        if (!f && s.size() == jt.size() && m.find({i, j}) == m.end())
          ans++, m[{i, j}] = m[{j, i}] = 1;
        swap(ip[i], ip[j]);
      }
    }
    cout << ans;
  }
}
