#include <bits/stdc++.h>
using namespace std;
int data[150000 + 10];
int n;
struct Node {
  int x, y;
  Node(int x, int y) {
    if (x > y) {
      swap(x, y);
    }
    this->x = x;
    this->y = y;
  }
  bool operator<(const Node& other) const {
    if (x != other.x) {
      return x < other.x;
    }
    return y < other.y;
  }
};
set<Node> sett;
set<int> bad_edge;
bool isOk(int s[2]) {
  int ans = 0;
  for (set<int>::iterator it = bad_edge.begin(); it != bad_edge.end(); it++) {
    if (s[0] == *it || s[0] - 1 == *it || s[0] + 1 == *it || s[1] == *it ||
        s[1] - 1 == *it || s[1] + 1 == *it) {
      ans++;
    }
  }
  return ans == bad_edge.size();
}
int main() {
  int i, j, s[2];
  while (scanf("%d", &n) != EOF) {
    for (i = 0; i < n; i++) {
      scanf("%d", &data[i]);
    }
    bad_edge.clear();
    for (i = 0; i < n - 1; i++) {
      if (i & 1) {
        if (data[i] <= data[i + 1]) {
          bad_edge.insert(i);
          bad_edge.insert(i + 1);
        }
      } else {
        if (data[i] >= data[i + 1]) {
          bad_edge.insert(i);
          bad_edge.insert(i + 1);
        }
      }
      if (bad_edge.size() > 6) {
        break;
      }
    }
    if (i < n - 1) {
      puts("0");
    } else {
      sett.clear();
      for (set<int>::iterator it = bad_edge.begin(); it != bad_edge.end();
           it++) {
        for (j = 0; j < n; j++) {
          s[0] = *it;
          s[1] = j;
          swap(data[s[0]], data[s[1]]);
          if (s[0] & 1) {
            if (s[0] >= 1 && data[s[0]] <= data[s[0] - 1] ||
                s[0] < n - 1 && data[s[0]] <= data[s[0] + 1]) {
            } else {
              if (j & 1) {
                if (j >= 1 && data[j] <= data[j - 1] ||
                    j < n - 1 && data[j] <= data[j + 1]) {
                  swap(data[s[0]], data[s[1]]);
                  continue;
                }
                if (isOk(s)) {
                  sett.insert(Node(s[0], j));
                }
              } else {
                if (j >= 1 && data[j] >= data[j - 1] ||
                    j < n - 1 && data[j] >= data[j + 1]) {
                  swap(data[s[0]], data[s[1]]);
                  continue;
                }
                if (isOk(s)) {
                  sett.insert(Node(s[0], j));
                }
              }
            }
            swap(data[s[0]], data[s[1]]);
            continue;
          }
          if (s[0] >= 1 && data[s[0]] >= data[s[0] - 1] ||
              s[0] < n - 1 && data[s[0]] >= data[s[0] + 1]) {
          } else {
            if (j & 1) {
              if (j >= 1 && data[j] <= data[j - 1] ||
                  j < n - 1 && data[j] <= data[j + 1]) {
                swap(data[s[0]], data[s[1]]);
                continue;
              }
              if (isOk(s)) {
                sett.insert(Node(s[0], j));
              }
            } else {
              if (j >= 1 && data[j] >= data[j - 1] ||
                  j < n - 1 && data[j] >= data[j + 1]) {
                swap(data[s[0]], data[s[1]]);
                continue;
              }
              if (isOk(s)) {
                sett.insert(Node(s[0], j));
              }
            }
          }
          swap(data[s[0]], data[s[1]]);
        }
      }
      printf("%d\n", (int)sett.size());
    }
  }
}
