#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
inline bool mina(A &first, B second) {
  return (first > second) ? (first = second, 1) : 0;
}
template <class A, class B>
inline bool maxa(A &first, B second) {
  return (first < second) ? (first = second, 1) : 0;
}
const int MAXN = 150005;
int N;
int in[MAXN];
bool good(int a, int b) {
  swap(in[a], in[b]);
  bool bad = false;
  for (int(i) = 0; (i) < (N - 1); ++(i)) {
    if (i % 2 == 0) {
      if (in[i] >= in[i + 1]) {
        bad = true;
        break;
      }
    } else {
      if (in[i] <= in[i + 1]) {
        bad = true;
        break;
      }
    }
  }
  swap(in[a], in[b]);
  return !bad;
}
bool check2(int p) {
  if (p < 0 || p >= N) return true;
  if (p % 2 == 0) {
    if (p + 1 < N && in[p] >= in[p + 1]) return false;
    if (p - 1 >= 0 && in[p] >= in[p - 1]) return false;
  } else {
    if (p + 1 < N && in[p] <= in[p + 1]) return false;
    if (p - 1 >= 0 && in[p] <= in[p - 1]) return false;
  }
  return true;
}
bool check_local(int a, int b) {
  swap(in[a], in[b]);
  bool g1 = true;
  for (int i = -1; i <= 1; i++) {
    g1 &= check2(a + i);
    g1 &= check2(b + i);
  }
  swap(in[a], in[b]);
  return g1;
}
int main() {
  scanf("%d", &N);
  for (int(i) = 0; (i) < (N); ++(i)) {
    scanf("%d", &in[i]);
  }
  set<int> bad;
  int num_bad_local = 0;
  int xx = -1;
  for (int(i) = 0; (i) < (N - 1); ++(i)) {
    if (i % 2 == 0) {
      if (in[i] >= in[i + 1]) {
        bad.insert(i);
        bad.insert(i + 1);
        num_bad_local++;
        xx = i;
        i++;
      }
    } else {
      if (in[i] <= in[i + 1]) {
        bad.insert(i);
        bad.insert(i + 1);
        num_bad_local++;
        xx = i;
        i++;
      }
    }
  }
  if (((int)(bad).size()) > 10) {
    printf("0\n");
    return 0;
  }
  set<pair<int, int> > ans;
  for (int first : bad) {
    for (int second : bad) {
      if (first < second) {
        if (good(first, second)) {
          ans.insert(pair<int, int>(first, second));
        }
      }
    }
  }
  if (num_bad_local == 1) {
    for (int(g) = 0; (g) < (N); ++(g)) {
      if (g != xx && g != xx + 1) {
        if (check_local(g, xx)) {
          int a = g;
          int b = xx;
          if (a > b) swap(a, b);
          ans.insert(pair<int, int>(a, b));
        }
        if (check_local(g, xx + 1)) {
          int a = g;
          int b = xx + 1;
          if (a > b) swap(a, b);
          ans.insert(pair<int, int>(a, b));
        }
      }
    }
  }
  cout << ((int)(ans).size()) << endl;
  return 0;
}
