#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
int n, A[150000 + 5];
vector<int> B;
bool err[150000 + 5];
bool check(int x) {
  int v = A[x];
  if (x & 1) {
    if (x < n && v >= A[x + 1]) return 0;
    if (x > 1 && v >= A[x - 1]) return 0;
  } else {
    if (x < n && v <= A[x + 1]) return 0;
    if (x > 1 && v <= A[x - 1]) return 0;
  }
  return 1;
}
bool judge() {
  for (int i = 0; i < B.size(); i++) {
    int a = B[i];
    if (!check(a)) return 0;
  }
  return 1;
}
int sum = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (int i = 1; i <= n; i++) {
    if (!check(i)) B.push_back(i), err[i] = 1;
  }
  if (B.size() > 10) {
    puts("0");
    return 0;
  }
  for (int i = 0; i < B.size(); i++) {
    for (int j = 1; j <= n; j++) {
      int a = B[i], b = j;
      if ((b > a || (!err[b]))) {
        swap(A[a], A[b]);
        int flag = check(a) && check(b);
        if (judge() == 0) {
          flag = 0;
        }
        if (flag) sum++;
        swap(A[a], A[b]);
      }
    }
  }
  cout << sum << endl;
  return 0;
}
