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.
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static int MOD = 1000000007;

    // After writing solution, quick scan for:
    //   array out of bounds
    //   special cases e.g. n=1?
    //
    // Big numbers arithmetic bugs:
    //   int overflow
    //   sorting, or taking max, after MOD
    void solve() throws IOException {
        int n = ri();
        int[] t = ril(n);
        // even index up, odd index down

        int numbad = 0;
        for (int i = 0; i < n-1; i++) {
            if (i % 2 == 0 && t[i] >= t[i+1] || i % 2 == 1 && t[i] <= t[i+1]) numbad++;
        }

        long ans = 0;
        for (int i = 0; i < n-1; i++) {
            if (i % 2 == 0 && t[i] >= t[i+1] || i % 2 == 1 && t[i] <= t[i+1]) {
                for (int j = 0; j < n; j++) {
                    // try swapping t[i] with t[j]
                    Set<Integer> set = new HashSet<>();
                    set.add(i-1);
                    set.add(i);
                    set.add(i+1);
                    set.add(j-1);
                    set.add(j);
                    set.add(j+1);
                    int before = 0;
                    for (int x : set) if (!ok(t, x)) before++;
                    swap(t, i, j);
                    int after = 0;
                    for (int x : set) if (!ok(t, x)) after++;
                    int delta = after - before;
                    if (numbad + delta == 0) {
                        ans++;
                    }
                    swap(t, i, j);
                }
                for (int j = 0; j < n; j++) {
                    if (j == i) continue;
                    // try swapping t[i] with t[j]
                    Set<Integer> set = new HashSet<>();
                    set.add(i);
                    set.add(i+1);
                    set.add(i+2);
                    set.add(j-1);
                    set.add(j);
                    set.add(j+1);
                    int before = 0;
                    for (int x : set) if (!ok(t, x)) before++;
                    swap(t, i+1, j);
                    int after = 0;
                    for (int x : set) if (!ok(t, x)) after++;
                    int delta = after - before;
                    if (numbad + delta == 0) {
                        ans++;
                    }
                    swap(t, i+1, j);
                }
                break;
            }
        }
        pw.println(ans);
    }

    boolean ok(int[] t, int i) {
        if (i >= t.length-1 || i < 0) return true;
        if (i % 2 == 0) return t[i] < t[i+1];
        return t[i] > t[i+1];
    }

    void swap(int[] t, int i, int j) {
        int temp = t[i];
        t[i] = t[j];
        t[j] = temp;
    }

    // Template code below

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        Main m = new Main();
        m.solve();
        m.close();
    }

    void close() throws IOException {
        pw.flush();
        pw.close();
        br.close();
    }

    int ri() throws IOException {
        return Integer.parseInt(br.readLine().trim());
    }

    long rl() throws IOException {
        return Long.parseLong(br.readLine().trim());
    }

    int[] ril(int n) throws IOException {
        int[] nums = new int[n];
        int c = 0;
        for (int i = 0; i < n; i++) {
            int sign = 1;
            c = br.read();
            int x = 0;
            if (c == '-') {
                sign = -1;
                c = br.read();
            }
            while (c >= '0' && c <= '9') {
                x = x * 10 + c - '0';
                c = br.read();
            }
            nums[i] = x * sign;
        }
        while (c != '\n' && c != -1) c = br.read();
        return nums;
    }

    long[] rll(int n) throws IOException {
        long[] nums = new long[n];
        int c = 0;
        for (int i = 0; i < n; i++) {
            int sign = 1;
            c = br.read();
            long x = 0;
            if (c == '-') {
                sign = -1;
                c = br.read();
            }
            while (c >= '0' && c <= '9') {
                x = x * 10 + c - '0';
                c = br.read();
            }
            nums[i] = x * sign;
        }
        while (c != '\n' && c != -1) c = br.read();
        return nums;
    }

    int[] rkil() throws IOException {
        int sign = 1;
        int c = br.read();
        int x = 0;
        if (c == '-') {
            sign = -1;
            c = br.read();
        }
        while (c >= '0' && c <= '9') {
            x = x * 10 + c - '0';
            c = br.read();
        }
        return ril(x);
    }

    long[] rkll() throws IOException {
        int sign = 1;
        int c = br.read();
        int x = 0;
        if (c == '-') {
            sign = -1;
            c = br.read();
        }
        while (c >= '0' && c <= '9') {
            x = x * 10 + c - '0';
            c = br.read();
        }
        return rll(x);
    }

    char[] rs() throws IOException {
        return br.readLine().toCharArray();
    }

    void sort(int[] A) {
        Random r = new Random();
        for (int i = A.length-1; i > 0; i--) {
            int j = r.nextInt(i+1);
            int temp = A[i];
            A[i] = A[j];
            A[j] = temp;
        }
        Arrays.sort(A);
    }
}