#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
const int N = 150005;
int n, a[N], ok[N];
int cnt(int i, int j) {
  int ans = 0;
  set<int> pos{i - 1, i, i + 1, j - 1, j, j + 1};
  for (auto x : pos) {
    if (x < 0 || x > n - 1 || !(x & 1)) {
      continue;
    }
    ans += a[x] > max(a[x - 1], a[x + 1]);
  }
  return ans;
}
int sm, nd;
bool check(int i, int j) {
  int curr = sm - cnt(i, j);
  swap(a[i], a[j]);
  curr += cnt(i, j);
  swap(a[i], a[j]);
  return curr == nd;
}
int solve(int i) {
  int ans = 0;
  for (int j = 0; j < n; ++j) {
    if (i != j && check(i, j)) {
      ++ans;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int cnt = 0;
  for (int i = 1; i < n; i += 2) {
    ok[i] = a[i] > max(a[i - 1], a[i + 1]);
    cnt += !ok[i], sm += ok[i], ++nd;
  }
  if (cnt > 4) {
    cout << 0 << '\n';
    return 0;
  }
  set<int> pos;
  for (int i = 1; i < n; i += 2) {
    if (!ok[i]) {
      pos.insert(i - 1);
      pos.insert(i);
      if (i != n - 1) pos.insert(i + 1);
    }
  }
  int ans = 0;
  for (auto x : pos) {
    ans += solve(x);
  }
  for (auto x : pos) {
    for (auto y : pos) {
      if (x < y && check(x, y)) {
        --ans;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
