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.*;
import java.util.stream.*;
import java.util.function.*;

import static java.lang.StrictMath.*;
import static java.util.stream.Collectors.*;

public class TaskC {

    private static final String INPUT_FILE = "input.txt";
    
    private static final String ONLINE_JUDGE = "ONLINE_JUDGE";

    public static void main(String[] args) {
        boolean oj = System.getProperty(ONLINE_JUDGE) != null;

        try {
            InputReader reader = new InputReader(oj ? System.in : new FileInputStream(INPUT_FILE));
            PrintWriter writer = new PrintWriter(System.out);
            new Solver(reader).run(writer);
            writer.close();
        }
        catch (IOException e) {
            new RuntimeException(e);
        }
    }
}

class Solver {

    public Solver(InputReader reader) throws IOException {
        n = reader.nextInt(); 
        a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = reader.nextInt();
        }
    }

    public void run(PrintWriter writer) {
        v = new boolean[n]; 
        int cnt = 0;
        p = new TreeSet<>();
        for (int i = 0; i < n-1; ++i) {
            if ((i%2 == 0) ? (a[i] >= a[i+1]) : (a[i] <= a[i+1])) {
                ++cnt;
                p.add(i);
                p.add(i+1);
            }
        }
        if (cnt > 4) {
            writer.println(0);
            return;
        } 
        else {
            pairs = new HashSet<Long>();
            for (int position: p) {
                for (int i = 0; i < n; ++i) {
                    if (i != position) {
                        change(position, i);
                    }
                }
            }
            writer.println(pairs.size());
        }
    }

    private void change(int i, int j) {
        swap(i, j);
        boolean ok = valid(i-1) && valid(i) && valid(i+1) && valid(j-1) && valid(j) && valid(j+1);
        if (ok) 
            for (int x: p) {
                if (!valid(x-1) || !valid(x) || !valid(x+1)) {
                    ok = false;
                    break;
                }
            }
        swap(i, j);
        if (ok) {
            if (i < j) {
                int t = i;
                i = j;
                j = t;
            }
            pairs.add((long)i*n + j);
        }
    }

    private boolean valid(int position) {
        if (position < 0 || position >= n-1) {
            return true;
        }
        else {
            return position%2 == 0 ? a[position] < a[position+1] : a[position] > a[position+1];
        }
    }

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

    private Set<Integer> p;
    private Set<Long> pairs;
    private int n;
    private int[] a;
    private boolean[] v;
}

class InputReader {
 	
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 1<<15);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double parseDouble() {
        return Double.parseDouble(next());
    }

}
