#include <bits/stdc++.h>   using namespace std;   int n, a[150005];   vector<int> v;   set<pair<int, int> > ans;   int compute() {     int problem = 0;     for (int i = 1; i <= n; i = i + 2) {       if (a[i] >= a[i + 1]) {         problem++;       }     }     for (int i = 2; i <= n; i = i + 2) {       if (a[i] <= a[i + 1]) {         problem++;       }     }     return problem;   }   vector<int> findproblems() {     vector<int> q;     for (int i = 1; i <= n; i = i + 2) {       if (a[i] >= a[i + 1]) {         q.push_back(i);         if (i >= 1 && i <= n) {           q.push_back(i + 1);         }       }     }     for (int i = 2; i <= n; i = i + 2) {       if (a[i] <= a[i + 1]) {         q.push_back(i);         if (i >= 1 && i <= n) {           q.push_back(i + 1);         }       }     }     sort(q.begin(), q.end());     return q;   }   void swap(int i, int j) {     int tempa = a[i];     a[i] = a[j];     a[j] = tempa;   }   int check(int e) {     if (e % 2 == 0) {       if (a[e] > a[e - 1] && a[e] > a[e + 1]) {         return 0;       }       return 1;     }     if (a[e] < a[e - 1] && a[e] < a[e + 1]) {       return 0;     }     return 1;   }   int threeandfour(int i, int j, vector<int> q) {     swap(i, j);     int flag = 0;     for (int i = 0; i < q.size(); i++) {       flag += check(q[i]);     }     flag += check(i);     flag += check(j);     swap(i, j);     return flag;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     a[0] = 150005;     if (n % 2 == 0) {       a[n + 1] = -10;     } else {       a[n + 1] = 150005;     }     int problem = compute();     if (problem > 4) {       cout <<  0  << endl;     } else {       v = findproblems();       for (int i = 0; i < v.size(); i++) {         for (int j = 1; j <= n; j++) {           if (threeandfour(v[i], j, v) == 0) {             ans.insert(make_pair(v[i], j));             ans.insert(make_pair(j, v[i]));           }         }       }       cout << ans.size() / 2 << endl;     }     return 0;   }   