#include <bits/stdc++.h>
using namespace std;
long long modpow(long long base, long long exponent, long long modulus) {
  if (base == 0 && exponent == 0) return 0;
  long long result = 1;
  while (exponent > 0) {
    if (exponent % 2 == 1) result = (result * base) % modulus;
    exponent = exponent >> 1;
    base = (base * base) % modulus;
  }
  return result;
}
int N;
int arr[200110];
int pos = -1;
int pref[200110], suff[200110];
int bad[200110];
inline void ReadInput(void) {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &arr[i]);
    if (pos == -1 and i > 1) {
      if (i & 1) {
        if (arr[i] >= arr[i - 1]) pos = i;
      } else {
        if (arr[i] <= arr[i - 1]) pos = i;
      }
    }
  }
}
bool check(int x) {
  if (x == 1) {
    if (arr[1] < arr[2])
      return true;
    else
      return false;
  } else if (x == N) {
    if (x & 1) {
      if (arr[x] < arr[x - 1])
        return true;
      else
        return false;
    } else {
      if (arr[x] > arr[x - 1])
        return true;
      else
        return false;
    }
  } else {
    if (x & 1) {
      if (arr[x] < arr[x + 1] and arr[x] < arr[x - 1])
        return true;
      else
        return false;
    } else {
      if (arr[x] > arr[x + 1] and arr[x] > arr[x - 1])
        return true;
      else
        return false;
    }
  }
}
bool check(int a, int b) {
  if (a > b) return true;
  if (bad[b] - bad[a - 1])
    return false;
  else
    return true;
}
inline void solve(void) {
  pref[0] = pref[1] = true;
  for (int i = 2; i <= N; i++) {
    pref[i] = pref[i - 1];
    bad[i] = bad[i - 1];
    if (i & 1) {
      if (arr[i] >= arr[i - 1]) pref[i] = 0, bad[i]++;
    } else {
      if (arr[i] <= arr[i - 1]) pref[i] = 0, bad[i]++;
    }
  }
  suff[N + 1] = suff[N] = 1;
  for (int i = N - 1; i >= 1; i--) {
    suff[i] = suff[i + 1];
    if (i & 1) {
      if (arr[i] >= arr[i + 1]) suff[i] = 0;
    } else {
      if (arr[i] <= arr[i + 1]) suff[i] = 0;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    if (i == pos) continue;
    swap(arr[i], arr[pos]);
    if (check(i) and check(pos) and pref[min(i, pos) - 1] and
        suff[max(pos, i) + 1] and check(min(i, pos) + 2, max(i, pos) - 2))
      ans++;
    swap(arr[i], arr[pos]);
    if (i == pos - 1) continue;
    pos--;
    swap(arr[i], arr[pos]);
    if (check(i) and check(pos) and pref[min(i, pos) - 1] and
        suff[max(pos, i) + 1] and check(min(i, pos) + 2, max(i, pos) - 2))
      ans++;
    swap(arr[i], arr[pos]);
    pos++;
  }
  cout << ans << endl;
}
inline void Refresh(void) {}
int main() {
  ReadInput();
  solve();
  return 0;
}
