// package codeforces.other2016.indiahacks2016;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Set;

/**
 * Created by hama_du on 2016/03/19.
 */
public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n ; i++) {
            a[i] = in.nextInt();
        }

        Set<Long> okSet = new HashSet<>();
        for (int f = 0 ; f <= 1 ; f++) {
            boolean[] wrong = new boolean[n];
            int ct = 0;
            for (int i = 0; i < n-1; i++) {
                if (a[i] < a[i+1] && i % 2 == f) {
                } else if (a[i] > a[i+1] && i % 2 == 1-f) {
                } else {
                    wrong[i] = wrong[i+1] = true;
                    ct++;
                }
            }
            if (ct <= 4) {
                for (int i = 0; i < n; i++) {
                    if (wrong[i]) {
                        for (int j = 0; j < n; j++) {
                            if (i == j) {
                                continue;
                            }
                            swap(a, i, j);
                            if (confirm(a)) {
                                int ii = Math.min(i, j);
                                int jj = Math.max(i, j);
                                okSet.add(ii*100000000L+jj);
                            }
                            swap(a, i, j);
                        }
                    }
                }
            }
        }
        out.println(okSet.size());
        out.flush();
    }

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

    private static boolean confirm(int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            if (a[i] == a[i+1]) {
                return false;
            }
        }
        boolean less = true;
        for (int i = 0 ; i < a.length-1 ; i++) {
            if (less) {
                if (a[i] >= a[i+1]) {
                    return false;
                }
            } else {
                if (a[i] <= a[i+1]) {
                    return false;
                }
            }
            less = !less;
        }
        return true;
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int next() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            if ('a' <= c && c <= 'z') {
                return (char) c;
            }
            if ('A' <= c && c <= 'Z') {
                return (char) c;
            }
            throw new InputMismatchException();
        }

        public String nextToken() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c-'0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c-'0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }
}


import java.io.*;
import java.util.*;

public class C653 {
    static int[] d;

    public static void swap(int a, int b){
        int t = d[a];
        d[a] = d[b];
        d[b] = t;
    }

    public static boolean check(int i){
        if(i==0){
            return d[i]<d[i+1];
        }else if(i==d.length-1){
            if(d.length%2==1){
                return d[i]<d[i-1];
            }else{
                return d[i]>d[i-1];
            }
        }else{
            if(i%2==0){
                return d[i]<d[i+1] && d[i]<d[i-1];
            }else return d[i]>d[i+1] && d[i]>d[i-1];
        }
    }

    public static void main(String[] args)throws Exception{
        IO.init(System.in);

        int n = IO.nextInt();
        d = new int[n];HashSet<String> reg = new HashSet<>();
        for(int i=0;i<n;++i)d[i] = IO.nextInt();
        boolean []rr = new boolean[n];
        ArrayList<Integer> bad = new ArrayList<>();
        int badCount=0;
        for(int i=0;i<n;++i){
            if(!check(i)){
//                IO.println("bad is "+i);
                badCount++;
                rr[i] = true;
                bad.add(i);
            }
        }
//        IO.println("badcount = "+badCount);
        if(badCount>6){IO.println(0);return;}
        int ans=0;

        for(int j=0;j<n;++j){
            for(int k=0;k<n;++k){
                if(reg.contains(j+"/"+k)||reg.contains(k+"/"+j)){
//                    IO.println("contained P");
                    continue;
                }
                if(j!=k && (rr[j] || rr[k] || (j>0 && rr[j-1]) || (j==n-1 && rr[j-1]) ||
                        (k>0 && rr[k-1]) || (k==n-1 && rr[k-1])
                        )){
                    swap(j, k);

                    boolean one = check(j);
                    if(one && !check(k))one = false;
                    if(one)for(int xx:bad){

                        if(!check(xx)){one = false;break;}
                    }
                    if(one){
//                        IO.println(Arrays.toString(d));
//                        IO.println("index j = "+j+" k = "+k+" are good");
                        ans++;
                    }
                    swap(j, k);
                    reg.add(j+"/"+k);
                }
            }
        }
        IO.println(ans);
    }

    static class IO {
        static BufferedReader reader;
        static StringTokenizer tokenizer;

        static void init(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input) );
            tokenizer = new StringTokenizer("");
        }

        static String next() throws IOException {
            while ( ! tokenizer.hasMoreTokens() ) {
                tokenizer = new StringTokenizer(reader.readLine() );
            }
            return tokenizer.nextToken();
        }

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

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

        static void print(Object ... o){
            for(int i=0;i<o.length;++i){
                System.out.print(o[i]);
            }
        }

        static void println(Object ... o){
            for(int i=0;i<o.length;++i){
                System.out.print(o[i]);
            }
            System.out.println();
        }
    }
}


import java.io.*;
import java.util.*;

public class C653 {
    static int[] d;

    public static void swap(int a, int b){
        int t = d[a];
        d[a] = d[b];
        d[b] = t;
    }

    public static boolean check(int i){
        if(i==0){
            return d[i]<d[i+1];
        }else if(i==d.length-1){
            if(d.length%2==1){
                return d[i]<d[i-1];
            }else{
                return d[i]>d[i-1];
            }
        }else{
            if(i%2==0){
                return d[i]<d[i+1] && d[i]<d[i-1];
            }else return d[i]>d[i+1] && d[i]>d[i-1];
        }
    }
    public static boolean[][] reg;
    public static void main(String[] args)throws Exception{
        IO.init(System.in);

        int n = IO.nextInt();
        d = new int[n];reg = new boolean[n][n];
        for(int i=0;i<n;++i)d[i] = IO.nextInt();
        boolean []rr = new boolean[n];
        ArrayList<Integer> bad = new ArrayList<>();
        int badCount=0;
        for(int i=0;i<n;++i){
            if(!check(i)){
//                IO.println("bad is "+i);
                badCount++;
                rr[i] = true;
                bad.add(i);
            }
        }
//        IO.println("badcount = "+badCount);
        if(badCount>6){IO.println(0);return;}
        int ans=0;

        for(int j=0;j<n;++j){
            for(int k=0;k<n;++k){
                if(reg[j][k])continue;
                if(j!=k && (rr[j] || rr[k] || (j>0 && rr[j-1]) || (j==n-1 && rr[j-1]) ||
                        (k>0 && rr[k-1]) || (k==n-1 && rr[k-1])
                        )){
                    swap(j, k);

                    boolean one = check(j);
                    if(one && !check(k))one = false;
                    if(one)for(int xx:bad){

                        if(!check(xx)){one = false;break;}
                    }
                    if(one){
//                        IO.println(Arrays.toString(d));
//                        IO.println("index j = "+j+" k = "+k+" are good");
                        ans++;
                    }
                    swap(j, k);
                    reg[k][j] = true;
                    reg[j][k] = true;
                }
            }
        }
        IO.println(ans);
    }

    static class IO {
        static BufferedReader reader;
        static StringTokenizer tokenizer;

        static void init(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input) );
            tokenizer = new StringTokenizer("");
        }

        static String next() throws IOException {
            while ( ! tokenizer.hasMoreTokens() ) {
                tokenizer = new StringTokenizer(reader.readLine() );
            }
            return tokenizer.nextToken();
        }

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

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

        static void print(Object ... o){
            for(int i=0;i<o.length;++i){
                System.out.print(o[i]);
            }
        }

        static void println(Object ... o){
            for(int i=0;i<o.length;++i){
                System.out.print(o[i]);
            }
            System.out.println();
        }
    }
}


import java.io.*;
import java.util.*;

public class C653 {
    static int[] d;

    public static void swap(int a, int b){
        int t = d[a];
        d[a] = d[b];
        d[b] = t;
    }
    static class Point{
        int i, j;
        Point(int i, int j){
            this.i = i;
            this.j = j;
        }

        @Override
        public boolean equals(Object o){
            Point other = (Point)o;
            if(this.i == other.i && this.j == other.j)return true;
            if(this.i == other.j && this.j == other.i)return true;
            return false;
        }

        @Override
        public int hashCode() {
            int hash = 667;
            hash = 67 * hash + this.i + this.j;
            return hash;
        }
    }

    public static boolean check(int i){
        if(i==0){
            return d[i]<d[i+1];
        }else if(i==d.length-1){
            if(d.length%2==1){
                return d[i]<d[i-1];
            }else{
                return d[i]>d[i-1];
            }
        }else{
            if(i%2==0){
                return d[i]<d[i+1] && d[i]<d[i-1];
            }else return d[i]>d[i+1] && d[i]>d[i-1];
        }
    }

    public static void main(String[] args)throws Exception{
        IO.init(System.in);

        int n = IO.nextInt();
        d = new int[n];HashSet<Point> reg = new HashSet<>();
        for(int i=0;i<n;++i)d[i] = IO.nextInt();
        boolean []rr = new boolean[n];
        ArrayList<Integer> bad = new ArrayList<>();
        int badCount=0;
        for(int i=0;i<n;++i){
            if(!check(i)){
//                IO.println("bad is "+i);
                badCount++;
                rr[i] = true;
                bad.add(i);
            }
        }
//        IO.println("badcount = "+badCount);
        if(badCount>6){IO.println(0);return;}
        int ans=0;

        for(int j=0;j<n;++j){
            for(int k=0;k<n;++k){
                Point p = new Point(j, k);
                if(reg.contains(p))continue;
                if(j!=k && (rr[j] || rr[k] || (j>0 && rr[j-1]) || (j==n-1 && rr[j-1]) ||
                        (k>0 && rr[k-1]) || (k==n-1 && rr[k-1])
                        )){
                    swap(j, k);

                    boolean one = check(j);
                    if(one && !check(k))one = false;
                    if(one)for(int xx:bad){

                        if(!check(xx)){one = false;break;}
                    }
                    if(one){
//                        IO.println(Arrays.toString(d));
//                        IO.println("index j = "+j+" k = "+k+" are good");
                        ans++;
                    }
                    swap(j, k);
                    reg.add(p);
                }
            }
        }
        IO.println(ans);
    }

    static class IO {
        static BufferedReader reader;
        static StringTokenizer tokenizer;

        static void init(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input) );
            tokenizer = new StringTokenizer("");
        }

        static String next() throws IOException {
            while ( ! tokenizer.hasMoreTokens() ) {
                tokenizer = new StringTokenizer(reader.readLine() );
            }
            return tokenizer.nextToken();
        }

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

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

        static void print(Object ... o){
            for(int i=0;i<o.length;++i){
                System.out.print(o[i]);
            }
        }

        static void println(Object ... o){
            for(int i=0;i<o.length;++i){
                System.out.print(o[i]);
            }
            System.out.println();
        }
    }
}


import java.io.*;
import java.util.*;

public class C653 {
    static int[] d;

    public static void swap(int a, int b){
        int t = d[a];
        d[a] = d[b];
        d[b] = t;
    }
    static class Point{
        int i, j;
        Point(int i, int j){
            this.i = i;
            this.j = j;
        }

        @Override
        public boolean equals(Object o){
            Point other = (Point)o;
            if(this.i == other.i && this.j == other.j)return true;
            if(this.i == other.j && this.j == other.i)return true;
            return false;
        }

        @Override
        public int hashCode() {
            int hash = 667;
            hash = 67 * hash + this.i + this.j;
            return hash;
        }
    }
    public static boolean check(int i){
        if(i==0){
            return d[i]<d[i+1];
        }else if(i==d.length-1){
            if(d.length%2==1){
                return d[i]<d[i-1];
            }else{
                return d[i]>d[i-1];
            }
        }else{
            if(i%2==0){
                return d[i]<d[i+1] && d[i]<d[i-1];
            }else return d[i]>d[i+1] && d[i]>d[i-1];
        }
    }
    public static boolean[][] reg;
    public static void main(String[] args)throws Exception{
        IO.init(System.in);

        int n = IO.nextInt();
        d = new int[n];reg = new boolean[n][n];
        for(int i=0;i<n;++i)d[i] = IO.nextInt();

        ArrayList<Integer> bad = new ArrayList<>();
        HashSet<Point> reg = new HashSet<>();
        int badCount=0;
        for(int i=0;i<n;++i){
            if(!check(i)){
//                IO.println("bad is "+i);
                badCount++;
                bad.add(i);
            }
        }
//        IO.println("badcount = "+badCount);
        if(badCount>6){IO.println(0);return;}
        int ans=0;
        for(int i=0;i<bad.size();++i){
            int b = bad.get(i);
            for(int j=0;j<n;++j){
                Point p = new Point(b, j);
                if(reg.contains(p))continue;
                swap(b, j);
//                IO.println("Swapped "+b+", "+j+" : "+Arrays.toString(d));
                boolean one = check(j);
                if(one)for(int xx:bad){
                     if(!check(xx)){one = false;break;}
                }
                if(one){
//                    IO.println("Fixed (i, j) "+i+", "+j+" : "+Arrays.toString(d));
                    ans++;
                }
                swap(b, j);
//                IO.println("Reverse Swapped "+b+", "+j+" : "+Arrays.toString(d));
                reg.add(p);
            }
        }
        IO.println(ans);
    }

    static class IO {
        static BufferedReader reader;
        static StringTokenizer tokenizer;

        static void init(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input) );
            tokenizer = new StringTokenizer("");
        }

        static String next() throws IOException {
            while ( ! tokenizer.hasMoreTokens() ) {
                tokenizer = new StringTokenizer(reader.readLine() );
            }
            return tokenizer.nextToken();
        }

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

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

        static void print(Object ... o){
            for(int i=0;i<o.length;++i){
                System.out.print(o[i]);
            }
        }

        static void println(Object ... o){
            for(int i=0;i<o.length;++i){
                System.out.print(o[i]);
            }
            System.out.println();
        }
    }
}


import java.io.*;
import java.util.*;

public class C653 {
    static int[] d;

    public static void swap(int a, int b){
        int t = d[a];
        d[a] = d[b];
        d[b] = t;
    }
    static class Point{
        int i, j;
        Point(int i, int j){
            this.i = i;
            this.j = j;
        }

        @Override
        public boolean equals(Object o){
            Point other = (Point)o;
            if(this.i == other.i && this.j == other.j)return true;
            if(this.i == other.j && this.j == other.i)return true;
            return false;
        }

        @Override
        public int hashCode() {
            int hash = 667;
            hash = 67 * hash + this.i + this.j;
            return hash;
        }
    }
    public static boolean check(int i){
        if(i==0){
            return d[i]<d[i+1];
        }else if(i==d.length-1){
            if(d.length%2==1){
                return d[i]<d[i-1];
            }else{
                return d[i]>d[i-1];
            }
        }else{
            if(i%2==0){
                return d[i]<d[i+1] && d[i]<d[i-1];
            }else return d[i]>d[i+1] && d[i]>d[i-1];
        }
    }
    public static void main(String[] args)throws Exception{
        IO.init(System.in);

        int n = IO.nextInt();
        d = new int[n];
        for(int i=0;i<n;++i)d[i] = IO.nextInt();

        ArrayList<Integer> bad = new ArrayList<>();
        HashSet<Point> reg = new HashSet<>();
        int badCount=0;
        for(int i=0;i<n;++i){
            if(!check(i)){
//                IO.println("bad is "+i);
                badCount++;
                bad.add(i);
            }
        }
//        IO.println("badcount = "+badCount);
        if(badCount>6){IO.println(0);return;}
        int ans=0;
        for(int i=0;i<bad.size();++i){
            int b = bad.get(i);
            for(int j=0;j<n;++j){
                Point p = new Point(b, j);
                if(reg.contains(p))continue;
                swap(b, j);
//                IO.println("Swapped "+b+", "+j+" : "+Arrays.toString(d));
                boolean one = check(j);
                if(one)for(int xx:bad){
                     if(!check(xx)){one = false;break;}
                }
                if(one){
//                    IO.println("Fixed (i, j) "+i+", "+j+" : "+Arrays.toString(d));
                    ans++;
                }
                swap(b, j);
//                IO.println("Reverse Swapped "+b+", "+j+" : "+Arrays.toString(d));
                reg.add(p);
            }
        }
        IO.println(ans);
    }

    static class IO {
        static BufferedReader reader;
        static StringTokenizer tokenizer;

        static void init(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input) );
            tokenizer = new StringTokenizer("");
        }

        static String next() throws IOException {
            while ( ! tokenizer.hasMoreTokens() ) {
                tokenizer = new StringTokenizer(reader.readLine() );
            }
            return tokenizer.nextToken();
        }

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

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

        static void print(Object ... o){
            for(int i=0;i<o.length;++i){
                System.out.print(o[i]);
            }
        }

        static void println(Object ... o){
            for(int i=0;i<o.length;++i){
                System.out.print(o[i]);
            }
            System.out.println();
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Artem Gilmudinov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        HashSet<Long> cache = new HashSet<>();

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            int[] t = new int[n];
            for (int i = 0; i < n; i++) {
                t[i] = in.readInt();
            }
            int[] b = new int[n];
            System.arraycopy(t, 0, b, 0, n);
            ArrayList<Integer> pos = new ArrayList<>();
            for (int i = 0; i < n - 1; i++) {
                if (!check(i, t)) {
                    pos.add(i);
                }
            }
            if (pos.size() > 4) {
                out.println(0);
                return;
            }
            for (int p : pos) {
                for (int j = Math.max(0, p - 2); j < Math.min(p + 2, n); j++) {
                    for (int z = 0; z < n; z++) {
                        addToCacheIfOk(z, j, b, pos);
                    }
                }
            }
            out.println(cache.size());
        }

        public void addToCacheIfOk(int i, int j, int[] b, ArrayList<Integer> pos) {
            if (i == j) {
                return;
            }
            if (check(i, j, b, pos)) {
                if (i > j) {
                    int temp = i;
                    i = j;
                    j = temp;
                }
                long hash = (((long) i) << 32) | (j);
                cache.add(hash);
            }
        }

        public boolean check(int i, int[] b) {
            if (i < 0) {
                return true;
            }
            if (i >= b.length - 1) {
                return true;
            }
            if (i % 2 != 0) {
                if (b[i] <= b[i + 1]) {
                    return false;
                }
            } else {
                if (b[i] >= b[i + 1]) {
                    return false;
                }
            }
            return true;
        }

        public boolean check(int i, int j, int[] b, ArrayList<Integer> pos) {
            swap(i, j, b);
            boolean res = check(i, b) && check(j, b) && check(i - 1, b) && check(j - 1, b);
            for (int p : pos) {
                res &= check(p, b);
            }
            swap(i, j, b);
            return res;
        }

        public void swap(int i, int j, int[] a) {
            int temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Artem Gilmudinov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        HashSet<Long> cache = new HashSet<>();

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            int[] t = new int[n];
            for (int i = 0; i < n; i++) {
                t[i] = in.readInt();
            }
            int[] b = new int[n];
            System.arraycopy(t, 0, b, 0, n);
            ArrayList<Integer> pos = new ArrayList<>();
            for (int i = 0; i < n - 1; i++) {
                if (!check(i, t)) {
                    pos.add(i);
                }
            }
            if (pos.size() >= 3) {
                out.println(0);
                return;
            }
            for (int p : pos) {
                for (int j = Math.max(0, p - 2); j < Math.min(p + 2, n); j++) {
                    for (int z = 0; z < n; z++) {
                        addToCacheIfOk(z, j, b, pos);
                    }
                }
            }
            out.println(cache.size());
        }

        public void addToCacheIfOk(int i, int j, int[] b, ArrayList<Integer> pos) {
            if (i == j) {
                return;
            }
            if (check(i, j, b, pos)) {
                if (i > j) {
                    int temp = i;
                    i = j;
                    j = temp;
                }
                long hash = (((long) i) << 32) | (j);
                cache.add(hash);
            }
        }

        public boolean check(int i, int[] b) {
            if (i < 0) {
                return true;
            }
            if (i >= b.length - 1) {
                return true;
            }
            if (i % 2 != 0) {
                if (b[i] <= b[i + 1]) {
                    return false;
                }
            } else {
                if (b[i] >= b[i + 1]) {
                    return false;
                }
            }
            return true;
        }

        public boolean check(int i, int j, int[] b, ArrayList<Integer> pos) {
            swap(i, j, b);
            boolean res = check(i, b) && check(j, b) && check(i - 1, b) && check(j - 1, b);
            for (int p : pos) {
                res &= check(p, b);
            }
            swap(i, j, b);
            return res;
        }

        public void swap(int i, int j, int[] a) {
            int temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Artem Gilmudinov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        HashSet<Long> cache = new HashSet<>();

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            int[] t = new int[n];
            for (int i = 0; i < n; i++) {
                t[i] = in.readInt();
            }
            int[] b = new int[n];
            System.arraycopy(t, 0, b, 0, n);
            ArrayList<Integer> pos = new ArrayList<>();
            for (int i = 0; i < n - 1; i++) {
                if (!check(i, t)) {
                    pos.add(i);
                }
            }
            if (pos.size() > 3) {
                out.println(0);
                return;
            }
            for (int p : pos) {
                for (int j = Math.max(0, p - 2); j < Math.min(p + 2, n); j++) {
                    for (int z = 0; z < n; z++) {
                        addToCacheIfOk(z, j, b, pos);
                    }
                }
            }
            out.println(cache.size());
        }

        public void addToCacheIfOk(int i, int j, int[] b, ArrayList<Integer> pos) {
            if (i == j) {
                return;
            }
            if (check(i, j, b, pos)) {
                if (i > j) {
                    int temp = i;
                    i = j;
                    j = temp;
                }
                long hash = (((long) i) << 32) | (j);
                cache.add(hash);
            }
        }

        public boolean check(int i, int[] b) {
            if (i < 0) {
                return true;
            }
            if (i >= b.length - 1) {
                return true;
            }
            if (i % 2 != 0) {
                if (b[i] <= b[i + 1]) {
                    return false;
                }
            } else {
                if (b[i] >= b[i + 1]) {
                    return false;
                }
            }
            return true;
        }

        public boolean check(int i, int j, int[] b, ArrayList<Integer> pos) {
            swap(i, j, b);
            boolean res = check(i, b) && check(j, b) && check(i - 1, b) && check(j - 1, b);
            for (int p : pos) {
                res &= check(p, b);
            }
            swap(i, j, b);
            return res;
        }

        public void swap(int i, int j, int[] a) {
            int temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Artem Gilmudinov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        HashSet<Long> cache = new HashSet<>();

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            int[] t = new int[n];
            for (int i = 0; i < n; i++) {
                t[i] = in.readInt();
            }
            int[] b = new int[n];
            System.arraycopy(t, 0, b, 0, n);
            ArrayList<Integer> pos = new ArrayList<>();
            for (int i = 0; i < n - 1; i++) {
                if (!check(i, t)) {
                    pos.add(i);
                }
            }
            if (pos.size() > 10) {
                out.println(0);
                return;
            }
            for (int p : pos) {
                for (int j = Math.max(0, p - 2); j < Math.min(p + 2, n); j++) {
                    for (int z = 0; z < n; z++) {
                        addToCacheIfOk(z, j, b, pos);
                    }
                }
            }
            out.println(cache.size());
        }

        public void addToCacheIfOk(int i, int j, int[] b, ArrayList<Integer> pos) {
            if (i == j) {
                return;
            }
            if (check(i, j, b, pos)) {
                if (i > j) {
                    int temp = i;
                    i = j;
                    j = temp;
                }
                long hash = (((long) i) << 32) | (j);
                cache.add(hash);
            }
        }

        public boolean check(int i, int[] b) {
            if (i < 0) {
                return true;
            }
            if (i >= b.length - 1) {
                return true;
            }
            if (i % 2 != 0) {
                if (b[i] <= b[i + 1]) {
                    return false;
                }
            } else {
                if (b[i] >= b[i + 1]) {
                    return false;
                }
            }
            return true;
        }

        public boolean check(int i, int j, int[] b, ArrayList<Integer> pos) {
            swap(i, j, b);
            boolean res = check(i, b) && check(j, b) && check(i - 1, b) && check(j - 1, b);
            for (int p : pos) {
                res &= check(p, b);
            }
            swap(i, j, b);
            return res;
        }

        public void swap(int i, int j, int[] a) {
            int temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {new Main();}

	public Main() throws Exception {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
//		BufferedReader f = new BufferedReader(new FileReader("testdata.out"));

		int n = Integer.parseInt(f.readLine());
		int[] a = new int[n];
		String[] split = f.readLine().split(" ");
		for(int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(split[i]);
		}

		boolean[] bad = new boolean[n + 1];
		for(int i = 0; i < n - 1; i++) {
			if(i % 2 == 0) {
				if(a[i] >= a[i + 1]) {
					bad[i] = bad[i + 1] = true;
				}
			} else {
				if(a[i] <= a[i + 1]) {
					bad[i] = bad[i + 1] = true;
				}
			}
		}

		int broken = 0;
		for(int i = 0; i < n; i++) {
			if(bad[i]) broken++;
		}

		if(broken > 9) {
			System.out.println(0);
			return;
		}

		int[] b = new int[broken];
		int idx = 0;
		for(int i = 0; i < n; i++) {
			if(bad[i]) {
				b[idx++] = i;
			}
		}

		HashSet<Integer>[] mark = new HashSet[n];
		for(int i = 0; i < n; i++) {
			mark[i] = new HashSet<>();
		}

		int res = 0;
		for(int fix = 0; fix < broken; fix++) {
			//try and swap b[fix] with a[i] and see if it fixes it
			for(int i = 0; i < n; i++) {
				swap(a, b[fix], i);
				boolean worked = true;

				ArrayList<Integer> list = new ArrayList<>();
				for(int j = 0; j < broken; j++) {
					list.add(b[j]);
				}
				if(!list.contains(i)) {
					list.add(i);
				}

				for(int j = 0; j < list.size(); j++) {
					int pos = list.get(j);
					if(pos - 1 >= 0) {
						if((pos - 1) % 2 == 0) {
							//move up
							if(a[pos - 1] >= a[pos]) {
								worked = false;
							}
						} else {
							//move down
							if(a[pos - 1] <= a[pos]) {
								worked = false;
							}
						}
					}

					if(pos + 1 < n) {
						if(pos % 2 == 0) {
							//move up
							if(a[pos] >= a[pos + 1]) {
								worked = false;
							}
						} else {
							//move down
							if(a[pos] <= a[pos + 1]) {
								worked = false;
							}
						}
					}

				}

				if(worked) {
					if(!mark[b[fix]].contains(i)) {
						mark[b[fix]].add(i);
						mark[i].add(b[fix]);
						res++;
					}
				}

				swap(a, b[fix], i);
			}
		}

		System.out.println(res);
	}

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


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    private NotMyScanner in;
    private PrintWriter out;
//    private Timer timer = new Timer();

    Set<Integer> set = new TreeSet<>();

    int get(int[] a, int i) {
        if (!set.add(i)) {
            return 0;
        }
        if (i < 0) {
            return 0;
        }
        if (i % 2 == 0) {
            if (a[i] >= a[i + 1]) {
                return 1;
            }
        } else {
            if (a[i] <= a[i + 1]) {
                return 1;
            }
        }
        return 0;
    }

    private void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n + 1];
        a[n] = (n % 2 == 0 ? 0 : 222_222);
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        int bad = 0;
        int lb = 0;
        for (int i = 0; i < n; i++) {
            if (get(a, i) == 1) {
                bad++;
                lb = i;
            }
        }

        int ans = 0;
        for (int i = lb; i < Math.min(n, lb + 2); i++) {
            for (int j = 0; j < n; j++) {
                if (i == lb + 1 && j == lb || i == j) {
                    continue;
                }

                set.clear();
                bad -= get(a, j - 1);
                bad -= get(a, j);
                bad -= get(a, i - 1);
                bad -= get(a, i);

                int t = a[i];
                a[i] = a[j];
                a[j] = t;

                set.clear();
                bad += get(a, j - 1);
                bad += get(a, j);
                bad += get(a, i - 1);
                bad += get(a, i);

                if (bad == 0) {
//                    out.println(i + " " + j);
                    ans++;
                }

                set.clear();
                bad -= get(a, j - 1);
                bad -= get(a, j);
                bad -= get(a, i - 1);
                bad -= get(a, i);

                t = a[i];
                a[i] = a[j];
                a[j] = t;

                set.clear();
                bad += get(a, j - 1);
                bad += get(a, j);
                bad += get(a, i - 1);
                bad += get(a, i);
            }
        }

        out.println(ans);
    }

    private void run() throws IOException {
        in = new NotMyScanner();
        out = new PrintWriter(System.out, false);
        solve();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}

class NotMyScanner {

    private final BufferedReader br;
    private StringTokenizer st;
    private String last;

    public NotMyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public NotMyScanner(String path) throws IOException {
        br = new BufferedReader(new FileReader(path));
    }

    public NotMyScanner(String path, String decoder) throws IOException {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(path), decoder));
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        last = null;
        return st.nextToken();
    }

    String nextLine() throws IOException {
        st = null;
        return (last == null) ? br.readLine() : last;
    }

    boolean hasNext() {
        if (st != null && st.hasMoreElements())
            return true;

        try {
            while (st == null || !st.hasMoreElements()) {
                last = br.readLine();
                st = new StringTokenizer(last);
            }
        } catch (Exception e) {
            return false;
        }

        return true;
    }

    String[] nextStrings(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = next();
        return arr;
    }

    String[] nextLines(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLine();
        return arr;
    }

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

    int[] nextInts(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    Integer[] nextIntegers(int n) throws IOException {
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    int[][] next2Ints(int n, int m) throws IOException {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextInt();
        return arr;
    }

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

    long[] nextLongs(int n) throws IOException {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLong();
        return arr;
    }

    long[][] next2Longs(int n, int m) throws IOException {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextLong();
        return arr;
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next().replace(',', '.'));
    }

    double[] nextDoubles(int size) throws IOException {
        double[] arr = new double[size];
        for (int i = 0; i < size; i++)
            arr[i] = nextDouble();
        return arr;
    }

    boolean nextBool() throws IOException {
        String s = next();
        if (s.equalsIgnoreCase("true") || s.equals("1"))
            return true;

        if (s.equalsIgnoreCase("false") || s.equals("0"))
            return false;

        throw new IOException("Boolean expected, String found!");
    }
}


import java.io.*;
import java.util.*;

public final class bear_and_up_down
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long inf=Long.MAX_VALUE;
	static Map<Integer,Integer> m1=new HashMap<>();

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();int[] a=new int[n+2];a[0]=Integer.MAX_VALUE;a[n+1]=n%2==0 ? 0 : Integer.MAX_VALUE;

		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextInt();
		}

		//System.out.println("hello");

		for(int i=1;i<=n;i++)
		{
			if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
			{
				m1.put(i,1);
			}

			if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
			{
				m1.put(i,1);
			}
		}

		if(m1.size()>6)
		{
			out.println(0);
		}
		else
		{

			long res=0;List<Integer> list=new ArrayList<Integer>();

			for(int i=1;i<=n;i++)
			{
				if(list.size()>=1 && list.size()<=6)
				{
					for(int x:list)
					{
						int temp=a[i];a[i]=a[x];a[x]=temp;boolean now=true;

						for(int y:m1.keySet())
						{
							if(Math.abs(y-i)>1 && Math.abs(y-x)>1)
							{
								now=false;break;
							}
						}

						for(int j=Math.max(x-1,1);j<=Math.min(n,x+1);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								now=false;break;
							}
						}

						for(int j=Math.max(i-1,1);j<=Math.min(i+1,n);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								now=false;break;
							}
						}

						res+=(now ? 1 : 0);temp=a[i];a[i]=a[x];a[x]=temp;
					}
				}

				if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
				{
					list.add(i);
				}

				if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
				{
					list.add(i);
				}
			}

			list.clear();

			for(int i=n;i>=1;i--)
			{
				if(list.size()>=1 && list.size()<=6 && m1.get(i)==null)
				{
					for(int x:list)
					{
						int temp=a[i];a[i]=a[x];a[x]=temp;boolean now=true;

						for(int y:m1.keySet())
						{
							if(Math.abs(y-i)>1 && Math.abs(y-x)>1)
							{
								now=false;break;
							}
						}

						for(int j=Math.max(x-1,1);j<=Math.min(n,x+1);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}
						}

						for(int j=Math.max(i-1,1);j<=Math.min(i+1,n);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}
						}

					//	out.println(i+" "+x+" "+list);

						res+=(now ? 1 : 0);temp=a[i];a[i]=a[x];a[x]=temp;
					}
				}

				if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
				{
					list.add(i);
				}

				if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
				{
					list.add(i);
				}
			}

			out.println(res);
		}

		out.close();

    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

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

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

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


import java.io.*;
import java.util.*;

public final class bear_and_up_down
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long inf=Long.MAX_VALUE;
	static Map<Integer,Integer> m1=new HashMap<>();

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();int[] a=new int[n+2];a[0]=Integer.MAX_VALUE;a[n+1]=n%2==0 ? 0 : Integer.MAX_VALUE;

		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextInt();
		}

		//System.out.println("hello");

		for(int i=1;i<=n;i++)
		{
			if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
			{
				m1.put(i,1);
			}

			if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
			{
				m1.put(i,1);
			}
		}

		//out.println(m1);

		if(m1.size()>6)
		{
			out.println(0);
		}
		else
		{

			long res=0;List<Integer> list=new ArrayList<Integer>();

			for(int i=1;i<=n;i++)
			{
				if(list.size()>=1 && list.size()<=3)
				{
					for(int x:list)
					{
						int temp=a[i];a[i]=a[x];a[x]=temp;boolean now=true;

						for(int y:m1.keySet())
						{
							if(Math.abs(y-i)>1 && Math.abs(y-x)>1)
							{
								now=false;break;
							}
						}

						for(int j=Math.max(x-1,1);j<=Math.min(n,x+1);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								now=false;break;
							}
						}

						for(int j=Math.max(i-1,1);j<=Math.min(i+1,n);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								now=false;break;
							}
						}

						//out.println(i+" "+x+" "+now);

						res+=(now ? 1 : 0);temp=a[i];a[i]=a[x];a[x]=temp;
					}
				}

				if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
				{
					list.add(i);
				}

				if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
				{
					list.add(i);
				}
			}

			list.clear();

			for(int i=n;i>=1;i--)
			{
				if(list.size()>=1 && list.size()<=3 && m1.get(i)==null)
				{
					for(int x:list)
					{
						int temp=a[i];a[i]=a[x];a[x]=temp;boolean now=true;

						for(int y:m1.keySet())
						{
							if(Math.abs(y-i)>1 && Math.abs(y-x)>1)
							{
								now=false;break;
							}
						}

						for(int j=Math.max(x-1,1);j<=Math.min(n,x+1);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}
						}

						for(int j=Math.max(i-1,1);j<=Math.min(i+1,n);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}
						}

						//out.println(i+" "+x+" "+now);

						res+=(now ? 1 : 0);temp=a[i];a[i]=a[x];a[x]=temp;
					}
				}

				if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
				{
					list.add(i);
				}

				if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
				{
					list.add(i);
				}
			}

			out.println(res);
		}

		out.close();

    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

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

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

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


import java.io.*;
import java.util.*;

public final class bear_and_up_down
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long inf=Long.MAX_VALUE;
	static Map<Integer,Integer> m1=new HashMap<>();

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();int[] a=new int[n+2];a[0]=Integer.MAX_VALUE;a[n+1]=n%2==0 ? 0 : Integer.MAX_VALUE;

		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextInt();
		}

		//System.out.println("hello");

		for(int i=1;i<=n;i++)
		{
			if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
			{
				m1.put(i,1);
			}

			if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
			{
				m1.put(i,1);
			}
		}

		if(m1.size()>6)
		{
			out.println(0);
		}
		else
		{

			long res=0;List<Integer> list=new ArrayList<Integer>();

			for(int i=1;i<=n;i++)
			{
				if(list.size()>=1 && list.size()<=6)
				{
					for(int x:list)
					{
						int temp=a[i];a[i]=a[x];a[x]=temp;boolean now=true;

						for(int y:m1.keySet())
						{
							if(Math.abs(y-i)>1 && Math.abs(y-x)>1)
							{
								now=false;break;
							}
						}

						for(int j=Math.max(x-1,1);j<=Math.min(n,x+1);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								now=false;break;
							}
						}

						for(int j=Math.max(i-1,1);j<=Math.min(i+1,n);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								now=false;break;
							}
						}

						res+=(now ? 1 : 0);temp=a[i];a[i]=a[x];a[x]=temp;
					}
				}

				if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
				{
					list.add(i);
				}

				if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
				{
					list.add(i);
				}
			}

			list.clear();

			for(int i=n;i>=1;i--)
			{
				if(list.size()>=1 && list.size()<=6 && m1.get(i)==null)
				{
					for(int x:list)
					{
						int temp=a[i];a[i]=a[x];a[x]=temp;boolean now=true;

						for(int y:m1.keySet())
						{
							if(Math.abs(y-i)>1 && Math.abs(y-x)>1)
							{
								now=false;break;
							}
						}

						for(int j=Math.max(x-1,1);j<=Math.min(n,x+1);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}
						}

						for(int j=Math.max(i-1,1);j<=Math.min(i+1,n);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}
						}

						out.println(i+" "+x+" "+list);

						res+=(now ? 1 : 0);temp=a[i];a[i]=a[x];a[x]=temp;
					}
				}

				if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
				{
					list.add(i);
				}

				if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
				{
					list.add(i);
				}
			}

			out.println(res);
		}

		out.close();

    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

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

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

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


import java.io.*;
import java.util.*;

public final class bear_and_up_down
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long inf=Long.MAX_VALUE;
	static Map<Integer,Integer> m1=new HashMap<>();

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();int[] a=new int[n+2];a[0]=Integer.MAX_VALUE;a[n+1]=n%2==0 ? 0 : Integer.MAX_VALUE;

		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextInt();
		}

		//System.out.println("hello");

		for(int i=1;i<=n;i++)
		{
			if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
			{
				m1.put(i,1);
			}

			if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
			{
				m1.put(i,1);
			}
		}

		if(m1.size()>6)
		{
			out.println(0);
		}
		else
		{

			long res=0;List<Integer> list=new ArrayList<Integer>();

			for(int i=1;i<=n;i++)
			{
				if(list.size()>=1 && list.size()<=5)
				{
					for(int x:list)
					{
						int temp=a[i];a[i]=a[x];a[x]=temp;boolean now=true;

						for(int y:m1.keySet())
						{
							if(Math.abs(y-i)>1 && Math.abs(y-x)>1)
							{
								now=false;break;
							}
						}

						for(int j=Math.max(x-1,1);j<=Math.min(n,x+1);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								now=false;break;
							}
						}

						for(int j=Math.max(i-1,1);j<=Math.min(i+1,n);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								now=false;break;
							}
						}

						//out.println(i+" "+x+" "+now);

						res+=(now ? 1 : 0);temp=a[i];a[i]=a[x];a[x]=temp;
					}
				}

				if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
				{
					list.add(i);
				}

				if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
				{
					list.add(i);
				}
			}

			list.clear();

			for(int i=n;i>=1;i--)
			{
				if(list.size()>=1 && list.size()<=5 && m1.get(i)==null)
				{
					for(int x:list)
					{
						int temp=a[i];a[i]=a[x];a[x]=temp;boolean now=true;

						for(int y:m1.keySet())
						{
							if(Math.abs(y-i)>1 && Math.abs(y-x)>1)
							{
								now=false;break;
							}
						}

						for(int j=Math.max(x-1,1);j<=Math.min(n,x+1);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}
						}

						for(int j=Math.max(i-1,1);j<=Math.min(i+1,n);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}
						}

						//out.println(i+" "+x+" "+now);

						res+=(now ? 1 : 0);temp=a[i];a[i]=a[x];a[x]=temp;
					}
				}

				if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
				{
					list.add(i);
				}

				if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
				{
					list.add(i);
				}
			}

			out.println(res);
		}

		out.close();

    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

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

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

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


import java.io.*;
import java.util.*;

public final class bear_and_up_down
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long inf=Long.MAX_VALUE;
	static Map<Integer,Integer> m1=new HashMap<>();

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();int[] a=new int[n+2];a[0]=Integer.MAX_VALUE;a[n+1]=n%2==0 ? 0 : Integer.MAX_VALUE;

		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextInt();
		}

		for(int i=1;i<=n;i++)
		{
			if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
			{
				m1.put(i,1);
			}

			if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
			{
				m1.put(i,1);
			}
		}

		//out.println(m1);

		if(m1.size()>6)
		{
			out.println(0);
		}
		else
		{

			long res=0;List<Integer> list=new ArrayList<Integer>();TreeSet<Pair> ts=new TreeSet<>();

			for(int i=1;i<=n;i++)
			{
				if(list.size()>=1 && list.size()<=3)
				{
					for(int x:list)
					{
						int temp=a[i];a[i]=a[x];a[x]=temp;boolean now=true;

						for(int y:m1.keySet())
						{
							if(Math.abs(y-i)>1 && Math.abs(y-x)>1)
							{
								now=false;break;
							}
						}

						for(int j=Math.max(x-1,1);j<=Math.min(n,x+1);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								now=false;break;
							}
						}

						for(int j=Math.max(i-1,1);j<=Math.min(i+1,n);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								now=false;break;
							}
						}

						//out.println(i+" "+x+" "+now);

						res+=(now ? 1 : 0);temp=a[i];a[i]=a[x];a[x]=temp;
					}
				}

				if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
				{
					list.add(i);
				}

				if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
				{
					list.add(i);
				}
			}

			list.clear();

			for(int i=n;i>=1;i--)
			{
				if(list.size()>=1 && list.size()<=3 && m1.get(i)==null)
				{
					for(int x:list)
					{
						int temp=a[i];a[i]=a[x];a[x]=temp;boolean now=true;

						for(int y:m1.keySet())
						{
							if(Math.abs(y-i)>1 && Math.abs(y-x)>1)
							{
								now=false;break;
							}
						}

						for(int j=Math.max(x-1,1);j<=Math.min(n,x+1);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}
						}

						for(int j=Math.max(i-1,1);j<=Math.min(i+1,n);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}
						}

						//out.println(i+" "+x+" "+now);

						res+=(now ? 1 : 0);temp=a[i];a[i]=a[x];a[x]=temp;
					}
				}

				if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
				{
					list.add(i);
				}

				if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
				{
					list.add(i);
				}
			}

			out.println(res);
		}

		out.close();

    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

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

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

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


import java.io.*;
import java.util.*;

public final class bear_and_up_down
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long inf=Long.MAX_VALUE;
	static Map<Integer,Integer> m1=new HashMap<>();

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();int[] a=new int[n+2];a[0]=Integer.MAX_VALUE;a[n+1]=n%2==0 ? 0 : Integer.MAX_VALUE;

		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextInt();
		}

		//System.out.println("hello");

		for(int i=1;i<=n;i++)
		{
			if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
			{
				m1.put(i,1);
			}

			if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
			{
				m1.put(i,1);
			}
		}

		//out.println(m1);

		if(m1.size()>6)
		{
			out.println(0);
		}
		else
		{

			long res=0;List<Integer> list=new ArrayList<Integer>();TreeSet<Pair> ts=new TreeSet<>();

			for(int i=1;i<=n;i++)
			{
				if(list.size()>=1 && list.size()<=3)
				{
					for(int x:list)
					{
						int temp=a[i];a[i]=a[x];a[x]=temp;boolean now=true;

						for(int y:m1.keySet())
						{
							if(Math.abs(y-i)>1 && Math.abs(y-x)>1)
							{
								now=false;break;
							}
						}

						for(int j=Math.max(x-1,1);j<=Math.min(n,x+1);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								now=false;break;
							}
						}

						for(int j=Math.max(i-1,1);j<=Math.min(i+1,n);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								now=false;break;
							}
						}

						//out.println(i+" "+x+" "+now);

						res+=(now ? 1 : 0);temp=a[i];a[i]=a[x];a[x]=temp;
					}
				}

				if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
				{
					list.add(i);
				}

				if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
				{
					list.add(i);
				}
			}

			list.clear();

			for(int i=n;i>=1;i--)
			{
				if(list.size()>=1 && list.size()<=3 && m1.get(i)==null)
				{
					for(int x:list)
					{
						int temp=a[i];a[i]=a[x];a[x]=temp;boolean now=true;

						for(int y:m1.keySet())
						{
							if(Math.abs(y-i)>1 && Math.abs(y-x)>1)
							{
								now=false;break;
							}
						}

						for(int j=Math.max(x-1,1);j<=Math.min(n,x+1);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}
						}

						for(int j=Math.max(i-1,1);j<=Math.min(i+1,n);j++)
						{
							if(j%2==1 && (a[j]>=a[j-1] || a[j]>=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}

							if(j%2==0 && (a[j]<=a[j-1] || a[j]<=a[j+1]))
							{
								//out.println(i+" "+x+" "+j);

								now=false;break;
							}
						}

						//out.println(i+" "+x+" "+now);

						res+=(now ? 1 : 0);temp=a[i];a[i]=a[x];a[x]=temp;
					}
				}

				if(i%2==1 && (a[i]>=a[i-1] || a[i]>=a[i+1]))
				{
					list.add(i);
				}

				if(i%2==0 && (a[i]<=a[i-1] || a[i]<=a[i+1]))
				{
					list.add(i);
				}
			}

			out.println(res);
		}

		out.close();

    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

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

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

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


import java.io.*;
import java.util.*;

public class C_new {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

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

		List<Integer> bad = new ArrayList<>();

		int[] arrBad = new int[n - 1];
		int totBad = 0;

		for (int i = 0; i < n - 1; i++) {
			if ((i % 2 == 0 && a[i] >= a[i + 1])
					|| (i % 2 == 1 && a[i] <= a[i + 1])) {
				bad.add(i);
				totBad++;
				arrBad[i] = 1;
			}
		}

		if (bad.size() > 4) {
			out.println(0);
			return;
		}

		HashSet<Long> set = new HashSet<>();

		int ret = 0;

		for (int i1 = 0; i1 < bad.size(); i1++) {
			for (int ii = 0; ii < 2; ii++) {

				int x = bad.get(i1) + ii;

				for (int y = 0; y < n; y++) {

					if (x == y) {
						continue;
					}

					int low = Math.min(x, y);
					int high = Math.max(x, y);

					long hash = (long)low * n + high;
					if (set.contains(hash)) {
						continue;
					}
					set.add(hash);

					int tmp = a[low];
					a[low] = a[high];
					a[high] = tmp;

					int nowBad = totBad;

					if (low != 0) {
						int i = low - 1;
						int here;
						if ((i % 2 == 0 && a[i] >= a[i + 1])
								|| (i % 2 == 1 && a[i] <= a[i + 1]))
							here = 1;
						else
							here = 0;
						nowBad += here - arrBad[i];
					}

					if (low != n - 1) {
						int i = low;
						int here;
						if ((i % 2 == 0 && a[i] >= a[i + 1])
								|| (i % 2 == 1 && a[i] <= a[i + 1]))
							here = 1;
						else
							here = 0;
						nowBad += here - arrBad[i];
					}

					if (high != low + 1) {
						int i = high - 1;
						int here;
						if ((i % 2 == 0 && a[i] >= a[i + 1])
								|| (i % 2 == 1 && a[i] <= a[i + 1]))
							here = 1;
						else
							here = 0;
						nowBad += here - arrBad[i];
					}

					if (high != n - 1) {
						int i = high;
						int here;
						if ((i % 2 == 0 && a[i] >= a[i + 1])
								|| (i % 2 == 1 && a[i] <= a[i + 1]))
							here = 1;
						else
							here = 0;
						nowBad += here - arrBad[i];
					}

					if (nowBad == 0) {
						ret++;
					}

					tmp = a[x];
					a[x] = a[y];
					a[y] = tmp;

				}
			}
		}

		out.println(ret);
	}

	C_new() 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 C_new();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

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

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

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


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.HashSet;
import java.io.OutputStreamWriter;
import java.util.NoSuchElementException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.Set;
import java.io.IOException;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        private int n;
        private int[] a;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.readInt();
            a = IOUtils.readIntArray(in, n);
            IntList badPositions = getBadPositions();
            if (badPositions.size() > 6) {
                out.print(0);
                return;
            }
            Set<IntIntPair> ans = new HashSet<>();
            for (int badPosition : badPositions) {
                for (int i = 0; i < a.length; i++) {
                    if (i == badPosition) {
                        continue;
                    }
                    swap(badPosition, i);
                    if (checkAllPositions(badPositions)) {
                        ans.add(IntIntPair.makePair(Math.min(badPosition, i), Math.max(badPosition, i)));
                    }
                    swap(badPosition, i);
                }
            }
            out.print(ans.size());
        }

        private IntList getBadPositions() {
            IntList badPositions = new IntArrayList();
            for (int i = 0; i < a.length; i++) {
                if (!checkPosition(i)) {
                    badPositions.add(i);
                }
            }
            return badPositions;
        }

        private boolean checkAllPositions(IntList positions) {
            return positions.allOf(this::checkPosition);
        }

        private boolean checkPosition(int pos) {
            if (pos % 2 == 0) {
                if (pos > 0) {
                    if (a[pos - 1] <= a[pos]) {
                        return false;
                    }
                }
                if (pos < n - 1) {
                    if (a[pos + 1] <= a[pos]) {
                        return false;
                    }
                }
            } else {
                if (pos > 0) {
                    if (a[pos - 1] >= a[pos]) {
                        return false;
                    }
                }
                if (pos < n - 1) {
                    if (a[pos + 1] >= a[pos]) {
                        return false;
                    }
                }
            }
            return true;
        }

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

    }

    static interface IntList extends IntReversableCollection {
        public abstract int get(int index);

        public abstract void addAt(int index, int value);

        public abstract void removeAt(int index);

        default public IntIterator intIterator() {
            return new IntIterator() {
                private int at;
                private boolean removed;

                public int value() {
                    if (removed) {
                        throw new IllegalStateException();
                    }
                    return get(at);
                }

                public boolean advance() {
                    at++;
                    removed = false;
                    return isValid();
                }

                public boolean isValid() {
                    return !removed && at < size();
                }

                public void remove() {
                    removeAt(at);
                    at--;
                    removed = true;
                }
            };
        }

        default public void add(int value) {
            addAt(size(), value);
        }

    }

    static abstract class IntAbstractStream implements IntStream {

        public String toString() {
            StringBuilder builder = new StringBuilder();
            boolean first = true;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                if (first) {
                    first = false;
                } else {
                    builder.append(' ');
                }
                builder.append(it.value());
            }
            return builder.toString();
        }

        public boolean equals(Object o) {
            if (!(o instanceof IntStream)) {
                return false;
            }
            IntStream c = (IntStream) o;
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                if (it.value() != jt.value()) {
                    return false;
                }
                it.advance();
                jt.advance();
            }
            return !it.isValid() && !jt.isValid();
        }

        public int hashCode() {
            int result = 0;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                result *= 31;
                result += it.value();
            }
            return result;
        }

    }

    static class IntIntPair implements Comparable<IntIntPair> {
        public final int first;
        public final int second;

        public static IntIntPair makePair(int first, int second) {
            return new IntIntPair(first, second);
        }

        public IntIntPair(int first, int second) {
            this.first = first;
            this.second = second;
        }

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

            IntIntPair pair = (IntIntPair) o;

            return first == pair.first && second == pair.second;
        }

        public int hashCode() {
            int result = first;
            result = 31 * result + second;
            return result;
        }

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

        @SuppressWarnings({"unchecked"})
        public int compareTo(IntIntPair o) {
            int value = Integer.compare(first, o.first);
            if (value != 0) {
                return value;
            }
            return Integer.compare(second, o.second);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

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

        public void print(int i) {
            writer.print(i);
        }

    }

    static interface IntReversableCollection extends IntCollection {
    }

    static class IOUtils {
        public static int[] readIntArray(InputReader in, int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++) {
                array[i] = in.readInt();
            }
            return array;
        }

    }

    static interface IntIterator {
        public int value() throws NoSuchElementException;

        public boolean advance();

        public boolean isValid();

    }

    static interface IntFilter {
        public boolean accept(int value);

    }

    static interface IntCollection extends IntStream {
        public int size();

        default public void add(int value) {
            throw new UnsupportedOperationException();
        }

        default public IntCollection addAll(IntStream values) {
            for (IntIterator it = values.intIterator(); it.isValid(); it.advance()) {
                add(it.value());
            }
            return this;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class IntArrayList extends IntAbstractStream implements IntList {
        private int size;
        private int[] data;

        public IntArrayList() {
            this(3);
        }

        public IntArrayList(int capacity) {
            data = new int[capacity];
        }

        public IntArrayList(IntCollection c) {
            this(c.size());
            addAll(c);
        }

        public IntArrayList(IntStream c) {
            this();
            if (c instanceof IntCollection) {
                ensureCapacity(((IntCollection) c).size());
            }
            addAll(c);
        }

        public IntArrayList(IntArrayList c) {
            size = c.size();
            data = c.data.clone();
        }

        public IntArrayList(int[] arr) {
            size = arr.length;
            data = arr.clone();
        }

        public int size() {
            return size;
        }

        public int get(int at) {
            if (at >= size) {
                throw new IndexOutOfBoundsException("at = " + at + ", size = " + size);
            }
            return data[at];
        }

        private void ensureCapacity(int capacity) {
            if (data.length >= capacity) {
                return;
            }
            capacity = Math.max(2 * data.length, capacity);
            data = Arrays.copyOf(data, capacity);
        }

        public void addAt(int index, int value) {
            ensureCapacity(size + 1);
            if (index > size || index < 0) {
                throw new IndexOutOfBoundsException("at = " + index + ", size = " + size);
            }
            if (index != size) {
                System.arraycopy(data, index, data, index + 1, size - index);
            }
            data[index] = value;
            size++;
        }

        public void removeAt(int index) {
            if (index >= size || index < 0) {
                throw new IndexOutOfBoundsException("at = " + index + ", size = " + size);
            }
            if (index != size - 1) {
                System.arraycopy(data, index + 1, data, index, size - index - 1);
            }
            size--;
        }

    }

    static interface IntStream extends Iterable<Integer>, Comparable<IntStream> {
        public IntIterator intIterator();

        default public Iterator<Integer> iterator() {
            return new Iterator<Integer>() {
                private IntIterator it = intIterator();

                public boolean hasNext() {
                    return it.isValid();
                }

                public Integer next() {
                    int result = it.value();
                    it.advance();
                    return result;
                }
            };
        }

        default public int compareTo(IntStream c) {
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                int i = it.value();
                int j = jt.value();
                if (i < j) {
                    return -1;
                } else if (i > j) {
                    return 1;
                }
                it.advance();
                jt.advance();
            }
            if (it.isValid()) {
                return 1;
            }
            if (jt.isValid()) {
                return -1;
            }
            return 0;
        }

        default public boolean allOf(IntFilter f) {
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                if (!f.accept(it.value())) {
                    return false;
                }
            }
            return true;
        }

    }
}