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.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class TaskC {
    StringTokenizer st;
    BufferedReader in;
    PrintWriter out;

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

    String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String str = in.readLine();
            if (str == null) return null;
            else st = new StringTokenizer(str);
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private void close() {
        out.close();
    }

    private long checkSimple(int n) {
        int ret = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                int tmp;
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
                if (check(0, n) == 0) ret++;
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
        return ret;
    }

    int[] a;

    private void solve() throws IOException {
        int n = nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        out.println(slv(n));
    }

    public long slv(int n) throws IOException {
        int fails = check(0, n, true);
        switch (fails) {
            case 0: {
                throw new IOException();
            }
            case 1: {
                int bad1 = failed.get(0);
                int bad2 = bad1 + 1;
                int ans = 0;
                if (trySwp(bad1, bad2, false)) ans++;
                for (int i = 0; i < n; i++) {
                    if (i == bad1 || i == bad2) continue;
                    if (trySwp(i, bad1, false)) ans++;
                    if (trySwp(i, bad2, false)) ans++;
                }
                return ans;
            }
            case 2: {
                int bad1 = failed.get(0);
                int bad2 = bad1 + 1;
                int bad3 = failed.get(1);
                int bad4 = bad3 + 1;
                int ans = 0;
                if (bad2 == bad3) {
                    if (trySwp(bad1, bad2, false)) ans++;
                    if (trySwp(bad1, bad4, false)) ans++;
                    if (trySwp(bad3, bad4, false)) ans++;
                    for (int i = 0; i < n; i++) {
                        if (i == bad1 || i == bad2 || i == bad4) continue;
                        if (trySwp(i, bad2, false)) ans++;
                    }
                } else {
                    if (trySwp(bad1, bad3, false)) ans++;
                    if (trySwp(bad1, bad4, false)) ans++;
                    if (trySwp(bad2, bad3, false)) ans++;
                    if (trySwp(bad2, bad4, false)) ans++;
                }
                return ans;
            }
            case 3: {
                Set<Integer> bads = new HashSet<>();
                for (Integer cur : failed) {
                    bads.add(cur);
                    bads.add(cur + 1);
                }
                ArrayList<Integer> bs = new ArrayList<Integer>(bads);
                int ans = 0;
                for (int i = 0; i < bs.size(); i++) {
                    for (int j = i + 1; j < bs.size(); j++) {
                        if (trySwp(bs.get(i), bs.get(j), true)) ans++;
                    }
                }
                return ans;
            }
            case 4: {
                if (trySwp(failed.get(1), failed.get(3), false)) return 1;
                return 0;
            }
            default:
                return 0;
        }

    }

    boolean trySwp(int i, int j, boolean fullCheck) {
        if (Math.max(i, j) >= a.length) return false;
        boolean result = true;
        int tmp;
        tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
        if (fullCheck) {
            if (check(0, a.length) != 0) result = false;
        }
        if (check(i - 10, i + 10) != 0) result = false;
        if (check(j - 10, j + 10) != 0) result = false;
        tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
        return result;
    }

    ArrayList<Integer> failed;

    private int check(int start, int end) {
        return check(start, end, false);
    }

    private int check(int start, int end, boolean calcF) {
        int fails = 0;
        if (calcF) {
            failed = new ArrayList<Integer>();
        }
        int s = Math.max(start, 0);
        int e = Math.min(end, a.length);
        for (int i = s; i < e - 1; i++) {
            if ((i % 2 == 0) && (a[i] >= a[i + 1])
                    || (i % 2 != 0) && (a[i] <= a[i + 1])) {
                fails++;
                if (calcF) {
                    failed.add(i);
                }
            }
        }
        return fails;
    }

    private void open() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
    }

}