#include <bits/stdc++.h>
using namespace std;
const int maxn = 150005;
int a[maxn], n;
set<pair<int, int> > S;
bool judge(int x) {
  if (x < 0 || x >= n) return 1;
  if (x % 2 == 0) {
    if (x - 1 >= 0 && a[x] >= a[x - 1]) return 0;
    if (x + 1 < n && a[x] >= a[x + 1]) return 0;
  } else {
    if (x - 1 >= 0 && a[x] <= a[x - 1]) return 0;
    if (x + 1 < n && a[x] <= a[x + 1]) return 0;
  }
  return 1;
}
bool v[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (!judge(i)) {
      v[i] = 1;
      cnt++;
    }
  if (cnt > 6) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < n; i++)
    if (v[i]) {
      for (int j = 0; j < n; j++) {
        swap(a[i], a[j]);
        int b[6] = {i, i + 1, i - 1, j, j - 1, j + 1}, m = 6;
        sort(b, b + 6);
        m = unique(b, b + 6) - b;
        if (judge(i) && judge(i + 1) && judge(i - 1) && judge(j) &&
            judge(j - 1) && judge(j + 1)) {
          int tmp = 0;
          for (int k = 0; k < m; k++)
            if (b[k] >= 0 && b[k] < n) {
              if (v[b[k]]) tmp++;
            }
          if (tmp == cnt) S.insert(pair<int, int>(min(i, j), max(i, j)));
        }
        swap(a[i], a[j]);
      }
    }
  printf("%d\n", S.size());
  return 0;
}
