#include <bits/stdc++.h>
using namespace std;
const int N = 150010;
int n, a[N];
vector<int> pos;
set<pair<int, int> > S;
bool check(int pos) {
  if (pos >= n || pos < 1) return true;
  if ((pos & 1) && a[pos] < a[pos + 1]) return true;
  if (!(pos & 1) && a[pos] > a[pos + 1]) return true;
  return false;
}
bool change(int x, int y) {
  swap(a[x], a[y]);
  bool succes = true;
  for (int i = 0; i < pos.size(); i++)
    if (!check(pos[i])) succes = false;
  if (!check(x - 1) || !check(x) || !check(y - 1) || !check(y)) succes = false;
  swap(a[x], a[y]);
  return succes;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++)
    if (!check(i)) {
      pos.push_back(i);
      if (i + 1 <= n) pos.push_back(i + 1), i++;
    }
  if (pos.size() > 4) {
    cout << 0 << endl;
    return 0;
  }
  int cnt = 0;
  for (int i = 0; i < pos.size(); i++)
    for (int j = 1; j <= n; j++) {
      if (S.count({pos[i], j}) || S.count({j, pos[i]})) continue;
      S.insert({pos[i], j});
      S.insert({j, pos[i]});
      if (change(pos[i], j)) cnt++;
    }
  cout << cnt << endl;
  return 0;
}
