#include <bits/stdc++.h>
using namespace std;
void fre() {
  freopen("c://test//input.in", "r", stdin);
  freopen("c://test//output.out", "w", stdout);
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
const int N = 15e4 + 10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int a[N];
int b[N];
int n, m;
bool check(int p) {
  if (p & 1) {
    if (p > 1 && a[p - 1] <= a[p]) return 0;
    if (p < n && a[p + 1] <= a[p]) return 0;
  } else {
    if (p > 1 && a[p - 1] >= a[p]) return 0;
    if (p < n && a[p + 1] >= a[p]) return 0;
  }
  return 1;
}
set<pair<int, int> > sot;
bool tryit(int x, int y) {
  swap(a[x], a[y]);
  if (check(x) && check(y) && !sot.count(make_pair(x, y))) {
    sot.insert(make_pair(x, y));
    sot.insert(make_pair(y, x));
    swap(a[x], a[y]);
    return 1;
  } else {
    swap(a[x], a[y]);
    return 0;
  }
}
bool Tryit(int x, int y) {
  if (check(x) && check(y) && !sot.count(make_pair(x, y))) {
    sot.insert(make_pair(x, y));
    sot.insert(make_pair(y, x));
    return 1;
  } else
    return 0;
}
int ANS;
void BF() {
  for (int i = 0; i <= 1; ++i) {
    for (int j = 0; j <= 1; ++j) {
      for (int u = 1; u <= m; ++u) {
        for (int v = 1; v <= m; ++v) {
          int p1 = b[u] + i;
          int p2 = b[v] + j;
          swap(a[p1], a[p2]);
          bool flag = 1;
          for (int k = 1; k <= m; ++k) {
            if (!check(b[k]) || !check(b[k] + 1)) {
              flag = 0;
              break;
            }
          }
          if (flag && !sot.count(make_pair(p1, p2))) {
            ++ANS;
            sot.insert(make_pair(p1, p2));
            sot.insert(make_pair(p2, p1));
          }
          swap(a[p1], a[p2]);
        }
      }
    }
  }
}
long long solve() {
  if (m > 6) return 0;
  if (m == 1) {
    long long ret = 0;
    for (int i = 1; i <= n; ++i) {
      if (tryit(b[1], i)) ++ret;
      if (tryit(b[1] + 1, i)) ++ret;
    }
    return ret;
  } else if (m == 2) {
    long long ret = 0;
    for (int i = 1; i <= n; ++i) {
      swap(a[b[1]], a[i]);
      if (Tryit(b[1], i) && check(b[1]) && check(b[2]) && check(b[1] + 1) &&
          check(b[2] + 1))
        ++ret;
      swap(a[b[1]], a[i]);
      swap(a[b[1] + 1], a[i]);
      if (Tryit(b[1] + 1, i) && check(b[1]) && check(b[2]) && check(b[1] + 1) &&
          check(b[2] + 1))
        ++ret;
      swap(a[b[1] + 1], a[i]);
      swap(a[b[2]], a[i]);
      if (Tryit(b[2], i) && check(b[1]) && check(b[2]) && check(b[1] + 1) &&
          check(b[2] + 1))
        ++ret;
      swap(a[b[2]], a[i]);
      swap(a[b[2] + 1], a[i]);
      if (Tryit(b[2] + 1, i) && check(b[1]) && check(b[2]) && check(b[1] + 1) &&
          check(b[2] + 1))
        ++ret;
      swap(a[b[2] + 1], a[i]);
    }
    return ret;
  } else {
    ANS = 0;
    BF();
    return ANS;
  }
}
void check() {}
int main() {
  while (~scanf("%d", &n)) {
    sot.clear();
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    m = 0;
    for (int i = 1; i < n; ++i) {
      if (i & 1) {
        if (a[i] >= a[i + 1]) b[++m] = i;
      } else {
        if (a[i] <= a[i + 1]) b[++m] = i;
      }
    }
    printf("%lld\n", solve());
  }
  return 0;
}
