#include <bits/stdc++.h>
using namespace std;
int n;
int a[222222];
vector<int> sp;
set<pair<int, int> > used;
int ans;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n - 1; ++i) {
    if (i % 2 == 0 && a[i] >= a[i + 1]) {
      sp.push_back(i);
    }
    if (i % 2 == 1 && a[i] <= a[i + 1]) {
      sp.push_back(i);
    }
  }
  if ((int)(sp).size() > 5) {
    cout << "0\n";
    return 0;
  }
  for (int idx = 0; idx < (int)(sp).size(); ++idx) {
    for (int sh = -2; sh <= 2; ++sh) {
      int pos1 = sp[idx] + sh;
      if (pos1 >= 0 && pos1 < n) {
        for (int jdx = idx; jdx < (int)(sp).size(); ++jdx) {
          for (int sh2 = -2; sh2 <= 2; ++sh2) {
            int pos2 = sp[jdx] + sh2;
            if (pos2 >= 0 && pos2 < n && pos2 > pos1 &&
                !used.count(make_pair(pos1, pos2))) {
              used.insert(make_pair(pos1, pos2));
              swap(a[pos1], a[pos2]);
              bool ok = 1;
              for (int i = 0; i < n - 1; ++i) {
                if (i % 2 == 0 && a[i] >= a[i + 1]) {
                  ok = 0;
                  break;
                }
                if (i % 2 == 1 && a[i] <= a[i + 1]) {
                  ok = 0;
                  break;
                }
              }
              if (ok) {
                ++ans;
              }
              swap(a[pos1], a[pos2]);
            }
          }
        }
      }
    }
  }
  if ((int)(sp).size() <= 2 && sp.back() - sp[0] <= 2) {
    for (int idx = sp[0] - 2; idx <= sp.back() + 2; ++idx) {
      if (idx < 0 || idx >= n) continue;
      for (int i = 0; i < n; ++i) {
        if (i != idx && !used.count(make_pair(min(idx, i), max(idx, i)))) {
          used.insert(make_pair(min(idx, i), max(idx, i)));
          swap(a[idx], a[i]);
          bool ok = 1;
          for (int pos = min(idx, i) - 5; pos <= min(idx, i) + 5; ++pos) {
            if (pos >= 0 && pos + 1 < n && pos % 2 == 0 && a[pos] >= a[pos + 1])
              ok = 0;
            if (pos >= 0 && pos + 1 < n && pos % 2 == 1 && a[pos] <= a[pos + 1])
              ok = 0;
          }
          for (int pos = max(idx, i) - 5; pos <= max(idx, i) + 5; ++pos) {
            if (pos >= 0 && pos + 1 < n && pos % 2 == 0 && a[pos] >= a[pos + 1])
              ok = 0;
            if (pos >= 0 && pos + 1 < n && pos % 2 == 1 && a[pos] <= a[pos + 1])
              ok = 0;
          }
          if (ok) {
            ++ans;
          }
          swap(a[idx], a[i]);
        }
      }
    }
  }
  cout << ans << endl;
}
