#include <bits/stdc++.h>
using namespace std;
const int inf = (int)2 * 1e9;
const int MOD = (int)1e9 + 7;
const int p = 239;
const int MAX_N = 10;
const long double pi = 3.1415926535897932384626;
const long double eps = 1e-6;
int f(int x, int y, int* a, int n) {
  int ans = 0;
  bool b = true;
  int c = a[x];
  a[x] = a[y];
  a[y] = c;
  for (int i = 1; i < n; i++)
    if (i % 2 == 0 && a[i] >= a[i - 1] || i % 2 == 1 && a[i] <= a[i - 1]) {
      b = false;
      break;
    }
  c = a[x];
  a[x] = a[y];
  a[y] = c;
  if (b)
    return 1;
  else
    return 0;
}
bool ok(int x, int y, int* a, int n) {
  bool b = true;
  int c = a[x];
  a[x] = a[y];
  a[y] = c;
  if (x % 2 == 0) {
    if (y % 2 == 0) {
      if (x > 0 && a[x] >= a[x - 1]) b = false;
      if (x < n - 1 && a[x] >= a[x + 1]) b = false;
      if (y > 0 && a[y] >= a[y - 1]) b = false;
      if (y < n - 1 && a[y] >= a[y + 1]) b = false;
    } else {
      if (x > 0 && a[x] >= a[x - 1]) b = false;
      if (x < n - 1 && a[x] >= a[x + 1]) b = false;
      if (y > 0 && a[y] <= a[y - 1]) b = false;
      if (y < n - 1 && a[y] <= a[y + 1]) b = false;
    }
  } else {
    if (y % 2 == 0) {
      if (x > 0 && a[x] <= a[x - 1]) b = false;
      if (x < n - 1 && a[x] <= a[x + 1]) b = false;
      if (y > 0 && a[y] >= a[y - 1]) b = false;
      if (y < n - 1 && a[y] >= a[y + 1]) b = false;
    } else {
      if (x > 0 && a[x] <= a[x - 1]) b = false;
      if (x < n - 1 && a[x] <= a[x + 1]) b = false;
      if (y > 0 && a[y] <= a[y - 1]) b = false;
      if (y < n - 1 && a[y] <= a[y + 1]) b = false;
    }
  }
  c = a[x];
  a[x] = a[y];
  a[y] = c;
  return b;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  vector<pair<int, int> > v, v1;
  v.push_back(make_pair(0, 0));
  for (int i = 1; i < n; i++)
    if (i % 2 == 0 && a[i] >= a[i - 1] || i % 2 == 1 && a[i] <= a[i - 1])
      v[v.size() - 1].second = i;
    else
      v.push_back(make_pair(i, i));
  for (int i = 0; i < v.size(); i++)
    if (v[i].first != v[i].second) v1.push_back(v[i]);
  if (v1.size() > 2) {
    cout << 0;
    return 0;
  }
  if (v1.size() == 2) {
    if (v1[0].second - v1[0].first + 1 > 3 ||
        v1[1].second - v1[1].first + 1 > 3) {
      cout << 0;
      return 0;
    }
    if (v1[0].second - v1[0].first + 1 == 3 &&
        v1[1].second - v1[1].first + 1 == 3) {
      cout << f(v1[0].first + 1, v1[1].first + 1, a, n);
      return 0;
    }
    if (v1[0].second - v1[0].first + 1 == 3 &&
        v1[1].second - v1[1].first + 1 == 2) {
      cout << f(v1[0].first + 1, v1[1].first, a, n) +
                  f(v1[0].first + 1, v1[1].first + 1, a, n);
      return 0;
    }
    if (v1[0].second - v1[0].first + 1 == 2 &&
        v1[1].second - v1[1].first + 1 == 3) {
      cout << f(v1[0].first, v1[1].first + 1, a, n) +
                  f(v1[0].first + 1, v1[1].first + 1, a, n);
      return 0;
    }
    if (v1[0].second - v1[0].first + 1 == 2 &&
        v1[1].second - v1[1].first + 1 == 2) {
      cout << f(v1[0].first, v1[1].first, a, n) +
                  f(v1[0].first, v1[1].first + 1, a, n) +
                  f(v1[0].first + 1, v1[1].first, a, n) +
                  f(v1[0].first + 1, v1[1].first + 1, a, n);
      return 0;
    }
  }
  if (v1[0].second - v1[0].first + 1 >= 6) {
    cout << 0;
    return 0;
  }
  if (v1[0].second - v1[0].first + 1 == 3) {
    int ans = 0;
    int x = v1[0].first + 1;
    for (int i = 0; i < n; i++)
      if (ok(x, i, a, n)) ans++;
    cout << ans;
    return 0;
  }
  if (v1[0].second - v1[0].first + 1 == 2) {
    int ans = 0, x;
    x = v1[0].first;
    for (int i = 0; i < n; i++)
      if (ok(x, i, a, n)) {
        ans++;
      }
    x++;
    for (int i = 0; i < n; i++)
      if ((i != x - 1) && ok(x, i, a, n)) {
        ans++;
      }
    cout << ans;
    return 0;
  }
  int ans = 0;
  for (int i = v1[0].first; i <= v1[0].second; i++)
    for (int j = i; j <= v1[0].second; j++) ans += f(i, j, a, n);
  cout << ans;
  return 0;
}
