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.
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.text.*;

/**
 *
 * @author zulkan
 */
public class cf653c {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);

    public static String getString() {
        try {
            return br.readLine();
        } catch (Exception e) {
        }
        return "";
    }

    public static Integer getInt() {
        try {
            return Integer.parseInt(br.readLine());
        } catch (Exception e) {
        }
        return 0;
    }

    public static Integer[] getIntArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            Integer temp2[] = new Integer[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = Integer.parseInt(temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static Long[] getLongArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            Long temp2[] = new Long[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = Long.parseLong(temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static String[] getStringArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            String temp2[] = new String[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = (temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static void print(Object a) {
        out.print(a);
    }

    public static void println(Object a) {
        out.println(a);
    }

    public static void printf(String s, Object... a) {
        out.printf(s, a);
    }

    public static int nextInt() {
        return sc.nextInt();
    }

    public static double nextDouble() {
        return sc.nextDouble();
    }

    public static void main(String[] ar) {
        cf653c c = new cf653c();
        c.solve();
        out.flush();
    }

    public void solve() {
        int n = getInt();
        Integer xx[] = getIntArr();

        HashSet<Integer> salah = new HashSet<>();
        for (int i = 1; i < n; i++) {
            if (i % 2 == 1 && xx[i - 1] >= xx[i]) {
                salah.add(i - 1);
                salah.add(i);

                //println("SALAH DI1 " + (i - 1));
            } else if (i % 2 == 0 && xx[i - 1] <= xx[i]) {
                salah.add(i - 1);
                salah.add(i);

                //println("SALAH DI2 " + (i - 1));
            }
        }
        //println(salah);
        if (salah.size() > 6) {
            println(0);
            return;
        }
        HashSet<List<Integer>> res = new HashSet<>();
        for (int pos : salah) {
            int va = xx[pos];
            for (int j = 0; j < n; j++) {
                if (pos != j) {
                    int vb = xx[j];

                    xx[pos] += xx[j];
                    xx[j] = xx[pos] - xx[j];
                    xx[pos] = xx[pos] - xx[j];

                    //println(pos + " " + j);
                    boolean valid = true;
                    if (j % 2 == 0) {
                        if (j + 1 < n) {
                            valid &= xx[j] < xx[j + 1];
                           // println(1 + " " + valid);
                        }
                        if (j - 1 >= 0) {
                            valid &= xx[j] < xx[j - 1];
                           // println(2 + " " + valid);

                        }
                    } else {
                        if (j + 1 < n) {
                            valid &= xx[j] > xx[j + 1];
                           // println(3 + " " + valid);

                        }
                        if (j - 1 >= 0) {
                            valid &= xx[j] > xx[j - 1];
                           // println(4 + " " + valid);

                        }
                    }
                    for(int pos2 : salah) {
                    if (pos2 % 2 == 0) {
                        if (pos2 + 1 < n) {
                            valid &= xx[pos2] < xx[pos2 + 1];
                           // println(5 + " " + valid);

                        }
                        if (pos2 - 1 >= 0) {
                            valid &= xx[pos2] < xx[pos2 - 1];
                           // println(6 + " " + valid);

                        }
                    } else {
                        if (pos2 + 1 < n) {
                            valid &= xx[pos2] > xx[pos2 + 1];
                          //  println(7 + " " + valid);

                        }
                        if (pos2 - 1 >= 0) {
                            valid &= xx[pos2] > xx[pos2 - 1];
                           // println(8 + " " + valid);

                        }
                    }
                    }
                    
                    if (valid) {
                        //println("TUKER " + va + " " + vb + "(" + pos + "," + j + ")");
                        res.add(Arrays.asList(Math.min(pos, j), Math.max(pos, j)));
                    }
                    xx[pos] += xx[j];
                    xx[j] = xx[pos] - xx[j];
                    xx[pos] = xx[pos] - xx[j];

                }
            }
        }
        //println(res);
        println(res.size());
    }

}
