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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Arthur Gazizov  [2oo7] - Kazan FU
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        private boolean check(int[] a, int p1) {
            if (p1 > 0 && p1 < a.length - 1) {
                if (p1 % 2 == 0) {
                    if (a[p1 - 1] <= a[p1] || a[p1] >= a[p1 + 1]) {
                        return false;
                    }
                } else {
                    if (a[p1 - 1] >= a[p1] || a[p1] <= a[p1 + 1]) {
                        return false;
                    }
                }
            } else {
                if (p1 == 0) {
                    if (a[p1] >= a[p1 + 1]) {
                        return false;
                    }
                } else {
                    int prev = p1 - 1;
                    if (prev % 2 == 0) {
                        if (a[prev] >= a[p1]) {
                            return false;
                        }
                    } else {
                        if (a[prev] <= a[p1]) {
                            return false;
                        }
                    }
                }
            }
            if (a[0] >= a[1]) {
                return false;
            }
            return true;
        }

        public void solve(int testNumber, FastScanner in, FastPrinter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);
            int count = 0;
            Set<Integer> problems = new HashSet<>();
            Set<Pair<Integer, Integer>> pr = new HashSet<>();
            for (int i = 0; i < n - 1; i++) {
                if (i % 2 == 0) {
                    if (a[i] >= a[i + 1]) {
                        count++;
                        pr.add(new Pair<>(i, i + 1));
                        problems.add(i);
                        problems.add(i + 1);
                    }
                } else {
                    if (a[i] <= a[i + 1]) {
                        count++;
                        pr.add(new Pair<>(i, i + 1));
                        problems.add(i);
                        problems.add(i + 1);
                    }
                }
            }
            //out.println("count:: " + count);
            Set<Pair<Integer, Integer>> used = new HashSet<>();

            if (pr.size() > 4) {
                out.print(0);
            } else {
                for (int p1 : problems) {
                    for (int p2 = 0; p2 < n; p2++) {
                        if (p2 == p1) {
                            continue;
                        }
                        Set<Pair<Integer, Integer>> clone = new HashSet<>(pr);
                        int temp = a[p1];
                        a[p1] = a[p2];
                        a[p2] = temp;
                        boolean ok = check(a, p1) && check(a, p2);

                        if (ok) {

                            clone.remove(new Pair<>(p1 - 1, p1));
                            clone.remove(new Pair<>(p1, p1 + 1));
                            clone.remove(new Pair<>(p2, p2 + 1));
                            clone.remove(new Pair<>(p2 - 1, p2));
                            if (clone.size() != 0) {
                                ok = false;
                            }
                        }
                        if (ok) {
                            used.add(new Pair<>(Integer.min(p1, p2), Integer.max(p1, p2)));
                        }
                        temp = a[p1];
                        a[p1] = a[p2];
                        a[p2] = temp;
                    }
                }
                out.print(used.size());
            }
        }

    }

    static class FastScanner extends BufferedReader {
        boolean isEOF;

        public FastScanner(InputStream is) {
            super(new InputStreamReader(is));
        }

        public FastScanner(InputStreamReader inputStreamReader) {
            super(inputStreamReader);
        }

        public int read() {
            try {
                int ret = super.read();
                if (isEOF && ret < 0) {
                    throw new InputMismatchException();
                }
                isEOF = ret == -1;
                return ret;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        public static boolean isWhiteSpace(int c) {
            return c >= -1 && c <= 32;
        }

        public int nextInt() {
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int ret = 0;
            while (!isWhiteSpace(c)) {
                if (c < '0' || c > '9') {
                    throw new NumberFormatException("digit expected " + (char) c
                            + " found");
                }
                ret = ret * 10 + c - '0';
                c = read();
            }
            return ret * sgn;
        }

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

        public String readLine() {
            try {
                return super.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

    }

    static interface Indexable {
    }

    static class FastPrinter extends PrintWriter {
        public FastPrinter(Writer writer) {
            super(writer);
        }

        public FastPrinter(OutputStream out) {
            super(out);
        }

        public void close() {
            super.close();
        }

    }

    static interface Identified {
    }

    static class Pair<U, V> implements Comparable<Pair<U, V>>, Identified, Indexable, Cloneable {
        private static int counter = 0;
        public final U first;
        public final V second;
        public final int id;

        public Pair(U first, V second) {
            this.first = first;
            this.second = second;
            this.id = counter++;
        }

        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Pair pair = (Pair) o;

            return !(first != null ? !first.equals(pair.first) : pair.first != null) && !(second != null ? !second.equals(pair.second) : pair.second != null);

        }


        protected Pair<U, V> clone() throws CloneNotSupportedException {
            return new Pair<>(this.first, this.second);
        }

        public int hashCode() {
            int result = first != null ? first.hashCode() : 0;
            result = 31 * result + (second != null ? second.hashCode() : 0);
            return result;
        }

        public String toString() {
            return "(" + first + "," + second + ")";
        }

        public int compareTo(Pair<U, V> o) {
            int value = ((Comparable<U>) first).compareTo(o.first);
            if (value != 0)
                return value;
            return ((Comparable<V>) second).compareTo(o.second);
        }

    }
}
