The life goes up and down, just like nice sequences. Sequence t1, t2, ..., tn is called nice if the following two conditions are satisfied: 

  * ti < ti + 1 for each odd i < n; 
  * ti > ti + 1 for each even i < n. 



For example, sequences (2, 8), (1, 5, 1) and (2, 5, 1, 100, 99, 120) are nice, while (1, 1), (1, 2, 3) and (2, 5, 3, 2) are not.

Bear Limak has a sequence of positive integers t1, t2, ..., tn. This sequence is not nice now and Limak wants to fix it by a single swap. He is going to choose two indices i < j and swap elements ti and tj in order to get a nice sequence. Count the number of ways to do so. Two ways are considered different if indices of elements chosen for a swap are different.

Input

The first line of the input contains one integer n (2 ≤ n ≤ 150 000) — the length of the sequence.

The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 150 000) — the initial sequence. It's guaranteed that the given sequence is not nice.

Output

Print the number of ways to swap two elements exactly once in order to get a nice sequence.

Examples

Input

5
2 8 4 7 7


Output

2


Input

4
200 150 100 50


Output

1


Input

10
3 2 1 4 1 4 1 4 1 4


Output

8


Input

9
1 2 3 4 5 6 7 8 9


Output

0

Note

In the first sample, there are two ways to get a nice sequence with one swap: 

  1. Swap t2 = 8 with t4 = 7. 
  2. Swap t1 = 2 with t5 = 7. 



In the second sample, there is only one way — Limak should swap t1 = 200 with t4 = 50.
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T mod_v(T num) {
  if (num >= 0)
    return num % 1000000007;
  else
    return (num % 1000000007 + 1000000007) % 1000000007;
}
template <class T>
inline T gcd(T a, T b) {
  a = abs(a);
  b = abs(b);
  while (b) b ^= a ^= b ^= a %= b;
  return a;
}
template <class T>
T fast_pow(T n, T p) {
  if (p == 0) return 1;
  if (p % 2) {
    T g = mod_v(mod_v(n) * mod_v(fast_pow(n, p - 1)));
    return g;
  } else {
    T g = fast_pow(n, p / 2);
    g = mod_v(mod_v(g) * mod_v(g));
    return g;
  }
}
template <class T>
inline T modInverse(T n) {
  return fast_pow(n, 1000000007 - 2);
}
template <class T>
inline void debug(string S1, T S2, string S3) {
  cout << S1 << S2 << S3;
}
bool equalTo(double a, double b) {
  if (fabs(a - b) <= 1e-9)
    return true;
  else
    return false;
}
bool notEqual(double a, double b) {
  if (fabs(a - b) > 1e-9)
    return true;
  else
    return false;
}
bool lessThan(double a, double b) {
  if (a + 1e-9 < b)
    return true;
  else
    return false;
}
bool lessThanEqual(double a, double b) {
  if (a < b + 1e-9)
    return true;
  else
    return false;
}
bool greaterThan(double a, double b) {
  if (a > b + 1e-9)
    return true;
  else
    return false;
}
bool greaterThanEqual(double a, double b) {
  if (a + 1e-9 > b)
    return true;
  else
    return false;
}
template <class T>
inline int in(register T& num) {
  register char c = 0;
  num = 0;
  bool n = false;
  while (c < 33) c = getchar();
  while (c > 33) {
    if (c == '-')
      n = true;
    else
      num = num * 10 + c - '0';
    c = getchar();
  }
  num = n ? -num : num;
  return 1;
}
int kp[150004];
int mark[150004];
int n;
int main() {
  in(n);
  for (int i = 1; i <= n; i++) in(kp[i]);
  vector<int> pp1;
  vector<int> pp2;
  int cnt = 0;
  for (int i = 2; i < n; i++) {
    if (i % 2) {
      if (kp[i] >= kp[i + 1] && kp[i] >= kp[i - 1]) {
        pp1.push_back(i);
        mark[i] = 1;
        mark[i + 1] = 1;
        mark[i - 1] = 1;
      }
    } else {
      if (kp[i] <= kp[i + 1] && kp[i] <= kp[i - 1]) {
        pp2.push_back(i);
        mark[i] = 1;
        mark[i + 1] = 1;
        mark[i - 1] = 1;
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (mark[i]) continue;
    if (i % 2) {
      if (kp[i] >= kp[i + 1]) {
        pp1.push_back(i);
      }
    } else {
      if (kp[i] <= kp[i + 1]) {
        pp2.push_back(i);
      }
    }
  }
  bool ok;
  if (((int)pp1.size()) + ((int)pp2.size()) > 2) {
    printf("0\n");
    return 0;
  } else if (((int)pp1.size()) + ((int)pp2.size()) == 2) {
    if (((int)pp1.size()) == 2) {
      pp2.push_back(pp1.back());
      pp1.pop_back();
    } else if (((int)pp2.size()) == 2) {
      pp1.push_back(pp2.back());
      pp2.pop_back();
    }
    swap(kp[pp1[0]], kp[pp2[0]]);
    ok = true;
    for (int i = 1; i < n && ok; i++) {
      if (i % 2) {
        if (kp[i] >= kp[i + 1]) {
          ok = false;
        }
      } else {
        if (kp[i] <= kp[i + 1]) {
          ok = false;
        }
      }
    }
    swap(kp[pp1[0]], kp[pp2[0]]);
    if (ok) cnt++;
    if (pp1[0] + 1 < n && pp2[0] + 1 <= n) {
      pp1[0]++;
      pp2[0]++;
      swap(kp[pp1[0]], kp[pp2[0]]);
      ok = true;
      for (int i = 1; i < n && ok; i++) {
        if (i % 2) {
          if (kp[i] >= kp[i + 1]) {
            ok = false;
          }
        } else {
          if (kp[i] <= kp[i + 1]) {
            ok = false;
          }
        }
      }
      swap(kp[pp1[0]], kp[pp2[0]]);
      if (ok) cnt++;
      pp1[0]--;
      pp2[0]--;
    }
    if (pp1[0] + 1 < n && pp2[0] + 1 <= n) {
      pp1[0]--;
      pp2[0]--;
      swap(kp[pp1[0]], kp[pp2[0]]);
      ok = true;
      for (int i = 1; i < n && ok; i++) {
        if (i % 2) {
          if (kp[i] >= kp[i + 1]) {
            ok = false;
          }
        } else {
          if (kp[i] <= kp[i + 1]) {
            ok = false;
          }
        }
      }
      swap(kp[pp1[0]], kp[pp2[0]]);
      if (ok) cnt++;
      pp1[0]++;
      pp2[0]++;
    }
    if (pp2[0] + 1 <= n) {
      swap(kp[pp1[0]], kp[pp2[0] + 1]);
      ok = true;
      for (int i = 1; i < n && ok; i++) {
        if (i % 2) {
          if (kp[i] >= kp[i + 1]) {
            ok = false;
          }
        } else {
          if (kp[i] <= kp[i + 1]) {
            ok = false;
          }
        }
      }
      swap(kp[pp1[0]], kp[pp2[0] + 1]);
      if (ok) cnt++;
    }
    if (pp2[0] - 1 >= 1) {
      swap(kp[pp1[0]], kp[pp2[0] - 1]);
      ok = true;
      for (int i = 1; i < n && ok; i++) {
        if (i % 2) {
          if (kp[i] >= kp[i + 1]) {
            ok = false;
          }
        } else {
          if (kp[i] <= kp[i + 1]) {
            ok = false;
          }
        }
      }
      swap(kp[pp1[0]], kp[pp2[0] - 1]);
      if (ok) cnt++;
    }
    swap(pp1[0], pp2[0]);
    if (pp2[0] + 1 <= n) {
      swap(kp[pp1[0]], kp[pp2[0] + 1]);
      ok = true;
      for (int i = 1; i < n && ok; i++) {
        if (i % 2) {
          if (kp[i] >= kp[i + 1]) {
            ok = false;
          }
        } else {
          if (kp[i] <= kp[i + 1]) {
            ok = false;
          }
        }
      }
      swap(kp[pp1[0]], kp[pp2[0] + 1]);
      if (ok) cnt++;
    }
    if (pp2[0] - 1 >= 1) {
      swap(kp[pp1[0]], kp[pp2[0] - 1]);
      ok = true;
      for (int i = 1; i < n && ok; i++) {
        if (i % 2) {
          if (kp[i] >= kp[i + 1]) {
            ok = false;
          }
        } else {
          if (kp[i] <= kp[i + 1]) {
            ok = false;
          }
        }
      }
      swap(kp[pp1[0]], kp[pp2[0] - 1]);
      if (ok) cnt++;
    }
  } else {
    if (((int)pp2.size()) == 1) {
      pp1.push_back(pp2[0]);
    }
    for (int i = 1; i <= n; i++) {
      if (pp1[0] == i) continue;
      swap(kp[i], kp[pp1[0]]);
      int c = 0;
      if (i - 1 > 0) {
        if (i % 2) {
          c += (kp[i] < kp[i - 1]);
        } else {
          c += (kp[i] > kp[i - 1]);
        }
      } else
        c++;
      if (i + 1 <= n) {
        if (i % 2) {
          c += (kp[i] < kp[i + 1]);
        } else
          c += (kp[i] > kp[i + 1]);
      } else
        c++;
      if (pp1[0] - 1 > 0) {
        if (pp1[0] % 2)
          c += (kp[pp1[0]] < kp[pp1[0] - 1]);
        else
          c += (kp[pp1[0]] > kp[pp1[0] - 1]);
      } else
        c++;
      if (pp1[0] + 1 <= n) {
        if (pp1[0] % 2)
          c += (kp[pp1[0]] < kp[pp1[0] + 1]);
        else
          c += (kp[pp1[0]] > kp[pp1[0] + 1]);
      } else
        c++;
      cnt += (c == 4);
      swap(kp[i], kp[pp1[0]]);
    }
    int x = pp1[0];
    if (x + 1 <= n && !mark[x] && !((int)pp2.size())) {
      pp1[0] = x + 1;
      cerr << "pp1[0]"
           << " is " << pp1[0] << "\n";
      for (int i = 1; i <= n; i++) {
        if (pp1[0] == i) continue;
        if (i == x) continue;
        swap(kp[i], kp[pp1[0]]);
        int c = 0;
        if (i - 1 > 0) {
          if (i % 2) {
            c += (kp[i] < kp[i - 1]);
          } else {
            c += (kp[i] > kp[i - 1]);
          }
        } else
          c++;
        if (i + 1 <= n) {
          if (i % 2) {
            c += (kp[i] < kp[i + 1]);
          } else
            c += (kp[i] > kp[i + 1]);
        } else
          c++;
        if (pp1[0] - 1 > 0) {
          if (pp1[0] % 2)
            c += (kp[pp1[0]] < kp[pp1[0] - 1]);
          else
            c += (kp[pp1[0]] > kp[pp1[0] - 1]);
        } else
          c++;
        if (pp1[0] + 1 <= n) {
          if (pp1[0] % 2)
            c += (kp[pp1[0]] < kp[pp1[0] + 1]);
          else
            c += (kp[pp1[0]] > kp[pp1[0] + 1]);
        } else
          c++;
        cnt += (c == 4);
        swap(kp[i], kp[pp1[0]]);
      }
    } else if (x - 1 > 0 && !mark[x]) {
      pp1[0] = x - 1;
      for (int i = 1; i <= n; i++) {
        if (pp1[0] == i) continue;
        if (i == x) continue;
        if (i == x + 1) continue;
        swap(kp[i], kp[pp1[0]]);
        int c = 0;
        if (i - 1 > 0) {
          if (i % 2) {
            c += (kp[i] < kp[i - 1]);
          } else {
            c += (kp[i] > kp[i - 1]);
          }
        } else
          c++;
        if (i + 1 <= n) {
          if (i % 2) {
            c += (kp[i] < kp[i + 1]);
          } else
            c += (kp[i] > kp[i + 1]);
        } else
          c++;
        if (pp1[0] - 1 > 0) {
          if (pp1[0] % 2)
            c += (kp[pp1[0]] < kp[pp1[0] - 1]);
          else
            c += (kp[pp1[0]] > kp[pp1[0] - 1]);
        } else
          c++;
        if (pp1[0] + 1 <= n) {
          if (pp1[0] % 2)
            c += (kp[pp1[0]] < kp[pp1[0] + 1]);
          else
            c += (kp[pp1[0]] > kp[pp1[0] + 1]);
        } else
          c++;
        cnt += (c == 4);
        swap(kp[i], kp[pp1[0]]);
      }
    }
  }
  cout << cnt;
  return 0;
}
