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.
/*
Keep solving problems. 
*/
import java.util.*;
import java.io.*;

public class IndiaHacks2016C {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    int[] arr;
    int n;

    void solve() throws IOException {
        n = nextInt();
        arr = nextIntArr(n);
        Set<Integer> list = new HashSet<>();
        for(int i = 0; i < n; i++) {
            if(!check(i)) {
                list.add(i);
                if(i + 1 < n) {
                    list.add(i + 1);
                }
            }
        }

        if(list.size() > 10) {
            out(0);
            return;
        }

        Set<Long> hs = new HashSet<>();

        for(int v : list) {
            for(int i = 0; i < n; i++) {
                if(v == i) {
                    continue;
                }
                swap(v, i);

                boolean tmp = true;
                for (int j : list) {
                    for(int k = -1; k <= 1; k++) {
                        tmp &= check(j + k);
                    }

                    if(!tmp) {
                        break;
                    }
                }
                for(int k = -1; k <= 1; k++) {
                    tmp &= check(i + k);
                }
                if (tmp) {
                    long l1 = Math.min(v, i);
                    long l2 = Math.max(v, i);
                    hs.add(MOD * l1 + l2);
                }
                swap(v, i);
            }
        }
        out(hs.size());
    }
    void swap(int i1, int i2) {
        int tmp = arr[i1];
        arr[i1] = arr[i2];
        arr[i2] = tmp;
    }
    boolean check(int idx) {
        if(idx < 0 || idx >= n) {
            return true;
        }
        if(idx == 0) {
            return arr[idx] < arr[idx + 1];
        }
        else if(idx == n - 1) {
            if(idx % 2 == 0) {
                return arr[idx] < arr[idx - 1];
            }
            else {
                return arr[idx] > arr[idx - 1];
            }
        }
        else {
            if (idx % 2 == 0) {
                return arr[idx] < arr[idx - 1] && arr[idx] < arr[idx + 1];
            } else {
                return arr[idx] > arr[idx - 1] && arr[idx] > arr[idx + 1];
            }
        }
    }
    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public IndiaHacks2016C() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new IndiaHacks2016C();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

