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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.Set;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author shu_mj @ http://shu-mj.com
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        Scanner in;
        PrintWriter out;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            this.in = in;
            this.out = out;
            run();
        }

        void run() {
            int n = in.nextInt();
            int[] is = in.nextIntArray(n);
            int cnt = 0;
            int x = -1;
            int y = -1;
            Set<Integer> xs = new HashSet<>();
            for (int i = 0; i + 1 < n; i++) {
                if (i % 2 == 0 && !(is[i + 1] > is[i]) || i % 2 == 1 && !(is[i + 1] < is[i])) {
                    cnt++;
                    if (x == -1) x = i;
                    else y = i;
                    xs.add(i);
                    if (i + 1 < n) xs.add(i + 1);
                }
            }
            int res = 0;
            if (cnt == 2 && x == y - 1) {
                res = check(n, is, y);
                Algo.swap(is, x, x + 2);
                if (fit(is, x) && fit(is, x + 2)) res++;
            } else if (cnt == 1) {
                res = check(n, is, x) + check(n, is, x + 1);
                Algo.swap(is, x, x + 1);
                if (fit(is, x) && fit(is, x + 1)) res--;
            } else if (cnt <= 4) {
                for (int i : xs) {
                    for (int j : xs)
                        if (i < j) {
                            Algo.swap(is, i, j);
                            boolean f = true;
                            for (int u : xs) if (!fit(is, u)) f = false;
                            if (f) res++;
                            Algo.swap(is, i, j);
                        }
                }
            }
            out.println(res);
        }

        private int check(int n, int[] is, int x) {
            int res = 0;
            for (int i = 0; i < n; i++)
                if (x != i) {
                    Algo.swap(is, i, x);
                    if (fit(is, i) && fit(is, x)) res++;
                    Algo.swap(is, i, x);
                }
            return res;
        }

        private boolean fit(int[] is, int i) {
            return (i == 0 || (i % 2 == 0 && is[i] < is[i - 1] || i % 2 == 1 && is[i] > is[i - 1])) &&
                    (i == is.length - 1 || (i % 2 == 0 && is[i] < is[i + 1] || i % 2 == 1 && is[i] > is[i + 1]));
        }

    }

    static class Algo {
        public static void swap(int[] is, int i, int j) {
            int t = is[i];
            is[i] = is[j];
            is[j] = t;
        }

    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            eat("");
        }

        private void eat(String s) {
            st = new StringTokenizer(s);
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!st.hasMoreTokens()) {
                String s = nextLine();
                if (s == null)
                    return false;
                eat(s);
            }
            return true;
        }

        public String next() {
            hasNext();
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int n) {
            int[] is = new int[n];
            for (int i = 0; i < n; i++) {
                is[i] = nextInt();
            }
            return is;
        }

    }
}

