//package india;

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

public class C {

    public static void main(String[] args) {
        CIO io = new CIO();
        try {
            Csolver solver = new Csolver(io);
        } finally {
            io.close();
        }
    }

}

class Csolver {

    int n;
    int[] t;
    int count;
    HashSet<Swap> viableSwaps;

    public Csolver(CIO io) {
        n = io.nextInt();
        t = new int[n];
        for (int i=0; i<n; i++) {
            t[i] = io.nextInt();
        }

        List<Integer> streaks = new ArrayList<>();
        for (int i=1; i<n; i++) {
            if (i%2 == 0 && t[i] >= t[i-1]) {
                int bah = Math.max(0, i-2);
                streaks.add(bah);
            } else if (i%2 != 0 && t[i] <= t[i-1]) {
                int bah = Math.max(0, i-2);
                streaks.add(bah);
            }
            if (streaks.size() > 8) {
                io.println("0");
                return;
            }
        }
        viableSwaps = new HashSet<>();
        if (streaks.size() == 1) {
            int start = streaks.get(0);
            for (int i=start; i<n && i<=start+4; i++) {
                for (int j=0; j<n; j++) {
                    swap(i,j);
                    if (verifyNicenessAround(i, j)) addViableSwap(i,j);
                    swap(i,j);
                }
            }
        } else {
            for (int s : streaks) {
                doShit(s, streaks);
            }
            //doShit(streaks.get(0), streaks.get(1));
            //doShit(streaks.get(1), streaks.get(0));
        }
        io.println(viableSwaps.size());
    }

    void doShit(int start, List<Integer> others) {
        for (int i=start; i<n && i<=start+6; i++) {
            for (int j=0; j<n; j++) {
                swap(i,j);
                boolean allOkOthers = true;
                for (int other : others) {
                    if (!verifyNicenessAround(other)) allOkOthers = false;
                }
                if (verifyNicenessAround(i, j) && allOkOthers) addViableSwap(i,j);
                swap(i,j);
            }
        }
    }

    void doShit(int start, int other) {
        for (int i=start; i<n && i<=start+6; i++) {
            for (int j=0; j<n; j++) {
                swap(i,j);
                if (verifyNicenessAround(i, j) && verifyNicenessAround(other)) addViableSwap(i,j);
                swap(i,j);
            }
        }
    }

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

    boolean verifyNicenessAround(int i, int j) {
        return (verifyNicenessAround(i) && verifyNicenessAround(j));
    }

    boolean verifyNicenessAround(int a) {
        int startRange = Math.max(0, a-4);
        int endRange = Math.min(n-1, startRange+8);
        for (int i=startRange+1; i<=endRange; i++) {
            if (i%2 == 0 && t[i] >= t[i-1]) {
                return false;
            } else if (i%2 != 0 && t[i] <= t[i-1]) {
                return false;
            }
        }
        return true;
    }

    void addViableSwap(int i, int j) {
        viableSwaps.add(new Swap(i,j));
    }

}

class Swap {
    int i;
    int j;

    public Swap(int i, int j) {
        this.i = Math.min(i,j);
        this.j = Math.max(i,j);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj.getClass() != this.getClass()) return false;
        Swap other = (Swap) obj;
        if (other.i != this.i) return false;
        if (other.j != this.j) return false;
        return true;
    }

    @Override
    public int hashCode() {
        return i*10000008+j;
    }

}

class CIO extends PrintWriter {
    private InputStreamReader r;
    private static final int BUFSIZE = 1 << 15;
    private char[] buf;
    private int bufc;
    private int bufi;
    private StringBuilder sb;

    public CIO() {
            super(new BufferedOutputStream(System.out));
            r = new InputStreamReader(System.in);

            buf = new char[BUFSIZE];
            bufc = 0;
            bufi = 0;
            sb = new StringBuilder();
    }

    private void fillBuf() throws IOException {
            bufi = 0;
            bufc = 0;
            while(bufc == 0) {
                    bufc = r.read(buf, 0, BUFSIZE);
                    if(bufc == -1) {
                            bufc = 0;
                            return;
                    }
            }
    }

    private boolean pumpBuf() throws IOException {
            if(bufi == bufc) {
                    fillBuf();
            }
            return bufc != 0;
    }

    private boolean isDelimiter(char c) {
            return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
    }

    private void eatDelimiters() throws IOException {
            while(true) {
                    if(bufi == bufc) {
                            fillBuf();
                            if(bufc == 0) throw new RuntimeException("IO: Out of input.");
                    }

                    if(!isDelimiter(buf[bufi])) break;
                    ++bufi;
            }
    }

    public String next() {
            try {
                    sb.setLength(0);

                    eatDelimiters();
                    int start = bufi;

                    while(true) {
                            if(bufi == bufc) {
                                    sb.append(buf, start, bufi - start);
                                    fillBuf();
                                    start = 0;
                                    if(bufc == 0) break;
                            }

                            if(isDelimiter(buf[bufi])) break;
                            ++bufi;
                    }

                    sb.append(buf, start, bufi - start);

                    return sb.toString();
            } catch(IOException e) {
                    throw new RuntimeException("IO.next: Caught IOException.");
            }
    }

    public int nextInt() {
            try {
                    int ret = 0;

                    eatDelimiters();

                    boolean positive = true;
                    if(buf[bufi] == '-') {
                            ++bufi;
                            if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
                            positive = false;
                    }

                    boolean first = true;
                    while(true) {
                            if(!pumpBuf()) break;
                            if(isDelimiter(buf[bufi])) {
                                    if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
                                    break;
                            }
                            first = false;

                            if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                                    if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
                                    ret *= 10;
                                    ret -= (int)(buf[bufi] - '0');
                                    if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
                            } else {
                                    throw new RuntimeException("IO.nextInt: Invalid int.");
                            }

                            ++bufi;
                    }

                    if(positive) {
                            if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
                            ret = -ret;
                    }

                    return ret;
            } catch(IOException e) {
                    throw new RuntimeException("IO.nextInt: Caught IOException.");
            }
    }

    public long nextLong() {
            try {
                    long ret = 0;

                    eatDelimiters();

                    boolean positive = true;
                    if(buf[bufi] == '-') {
                            ++bufi;
                            if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
                            positive = false;
                    }

                    boolean first = true;
                    while(true) {
                            if(!pumpBuf()) break;
                            if(isDelimiter(buf[bufi])) {
                                    if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
                                    break;
                            }
                            first = false;

                            if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                                    if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
                                    ret *= 10;
                                    ret -= (long)(buf[bufi] - '0');
                                    if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
                            } else {
                                    throw new RuntimeException("IO.nextLong: Invalid long.");
                            }

                            ++bufi;
                    }

                    if(positive) {
                            if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
                            ret = -ret;
                    }

                    return ret;
            } catch(IOException e) {
                    throw new RuntimeException("IO.nextLong: Caught IOException.");
            }
    }

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

}


//package india;

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

public class C {

    public static void main(String[] args) {
        CIO io = new CIO();
        try {
            Csolver solver = new Csolver(io);
        } finally {
            io.close();
        }
    }

}

class Csolver {

    int n;
    int[] t;
    int count;
    HashSet<Swap> viableSwaps;

    public Csolver(CIO io) {
        n = io.nextInt();
        t = new int[n];
        for (int i=0; i<n; i++) {
            t[i] = io.nextInt();
        }

        List<Integer> streaks = new ArrayList<>();
        for (int i=1; i<n; i++) {
            if (i%2 == 0 && t[i] >= t[i-1]) {
                streaks.add(Math.max(0, i-2));
            } else if (i%2 != 0 && t[i] <= t[i-1]) {
                streaks.add(Math.max(0, i-2));
            }
            if (streaks.size() > 2) {
                io.println("0");
                return;
            }
        }
        viableSwaps = new HashSet<>();
        if (streaks.size() == 1) {
            int start = streaks.get(0);
            for (int i=start; i<n && i<=start+4; i++) {
                for (int j=0; j<n; j++) {
                    swap(i,j);
                    if (verifyNicenessAround(i, j)) addViableSwap(i,j);
                    swap(i,j);
                }
            }
        } else {
            doShit(streaks.get(0), streaks.get(1));
            doShit(streaks.get(1), streaks.get(0));
        }
        io.println(viableSwaps.size());
    }

    void doShit(int start, int other) {
        for (int i=start; i<n && i<=start+4; i++) {
            for (int j=0; j<n; j++) {
                swap(i,j);
                if (verifyNicenessAround(i, j) && verifyNicenessAround(other)) addViableSwap(i,j);
                swap(i,j);
            }
        }
    }

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

    boolean verifyNicenessAround(int i, int j) {
        return (verifyNicenessAround(i) && verifyNicenessAround(j));
    }

    boolean verifyNicenessAround(int a) {
        int startRange = Math.max(0, a-4);
        int endRange = Math.min(n-1, startRange+8);
        for (int i=startRange+1; i<=endRange; i++) {
            if (i%2 == 0 && t[i] >= t[i-1]) {
                return false;
            } else if (i%2 != 0 && t[i] <= t[i-1]) {
                return false;
            }
        }
        return true;
    }

    void addViableSwap(int i, int j) {
        viableSwaps.add(new Swap(i,j));
    }

}

class Swap {
    int i;
    int j;

    public Swap(int i, int j) {
        this.i = Math.min(i,j);
        this.j = Math.max(i,j);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj.getClass() != this.getClass()) return false;
        Swap other = (Swap) obj;
        if (other.i != this.i) return false;
        if (other.j != this.j) return false;
        return true;
    }

    @Override
    public int hashCode() {
        return i*10000008+j;
    }

}

class CIO extends PrintWriter {
    private InputStreamReader r;
    private static final int BUFSIZE = 1 << 15;
    private char[] buf;
    private int bufc;
    private int bufi;
    private StringBuilder sb;

    public CIO() {
            super(new BufferedOutputStream(System.out));
            r = new InputStreamReader(System.in);

            buf = new char[BUFSIZE];
            bufc = 0;
            bufi = 0;
            sb = new StringBuilder();
    }

    private void fillBuf() throws IOException {
            bufi = 0;
            bufc = 0;
            while(bufc == 0) {
                    bufc = r.read(buf, 0, BUFSIZE);
                    if(bufc == -1) {
                            bufc = 0;
                            return;
                    }
            }
    }

    private boolean pumpBuf() throws IOException {
            if(bufi == bufc) {
                    fillBuf();
            }
            return bufc != 0;
    }

    private boolean isDelimiter(char c) {
            return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
    }

    private void eatDelimiters() throws IOException {
            while(true) {
                    if(bufi == bufc) {
                            fillBuf();
                            if(bufc == 0) throw new RuntimeException("IO: Out of input.");
                    }

                    if(!isDelimiter(buf[bufi])) break;
                    ++bufi;
            }
    }

    public String next() {
            try {
                    sb.setLength(0);

                    eatDelimiters();
                    int start = bufi;

                    while(true) {
                            if(bufi == bufc) {
                                    sb.append(buf, start, bufi - start);
                                    fillBuf();
                                    start = 0;
                                    if(bufc == 0) break;
                            }

                            if(isDelimiter(buf[bufi])) break;
                            ++bufi;
                    }

                    sb.append(buf, start, bufi - start);

                    return sb.toString();
            } catch(IOException e) {
                    throw new RuntimeException("IO.next: Caught IOException.");
            }
    }

    public int nextInt() {
            try {
                    int ret = 0;

                    eatDelimiters();

                    boolean positive = true;
                    if(buf[bufi] == '-') {
                            ++bufi;
                            if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
                            positive = false;
                    }

                    boolean first = true;
                    while(true) {
                            if(!pumpBuf()) break;
                            if(isDelimiter(buf[bufi])) {
                                    if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
                                    break;
                            }
                            first = false;

                            if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                                    if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
                                    ret *= 10;
                                    ret -= (int)(buf[bufi] - '0');
                                    if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
                            } else {
                                    throw new RuntimeException("IO.nextInt: Invalid int.");
                            }

                            ++bufi;
                    }

                    if(positive) {
                            if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
                            ret = -ret;
                    }

                    return ret;
            } catch(IOException e) {
                    throw new RuntimeException("IO.nextInt: Caught IOException.");
            }
    }

    public long nextLong() {
            try {
                    long ret = 0;

                    eatDelimiters();

                    boolean positive = true;
                    if(buf[bufi] == '-') {
                            ++bufi;
                            if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
                            positive = false;
                    }

                    boolean first = true;
                    while(true) {
                            if(!pumpBuf()) break;
                            if(isDelimiter(buf[bufi])) {
                                    if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
                                    break;
                            }
                            first = false;

                            if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                                    if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
                                    ret *= 10;
                                    ret -= (long)(buf[bufi] - '0');
                                    if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
                            } else {
                                    throw new RuntimeException("IO.nextLong: Invalid long.");
                            }

                            ++bufi;
                    }

                    if(positive) {
                            if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
                            ret = -ret;
                    }

                    return ret;
            } catch(IOException e) {
                    throw new RuntimeException("IO.nextLong: Caught IOException.");
            }
    }

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

}


//package india;

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

public class C {

    public static void main(String[] args) {
        CIO io = new CIO();
        try {
            Csolver solver = new Csolver(io);
        } finally {
            io.close();
        }
    }

}

class Csolver {

    int n;
    int[] t;
    int count;
    HashSet<Swap> viableSwaps;

    public Csolver(CIO io) {
        n = io.nextInt();
        t = new int[n];
        for (int i=0; i<n; i++) {
            t[i] = io.nextInt();
        }

        List<Integer> streaks = new ArrayList<>();
        for (int i=1; i<n; i++) {
            if (i%2 == 0 && t[i] >= t[i-1]) {
                int bah = Math.max(0, i-2);
                streaks.add(bah);
            } else if (i%2 != 0 && t[i] <= t[i-1]) {
                int bah = Math.max(0, i-2);
                streaks.add(bah);
            }
            if (streaks.size() > 8) {
                io.println("0");
                return;
            }
        }
        viableSwaps = new HashSet<>();
        if (streaks.size() == 1) {
            int start = streaks.get(0);
            for (int i=start; i<n && i<=start+4; i++) {
                for (int j=0; j<n; j++) {
                    swap(i,j);
                    if (verifyNicenessAround(i, j)) addViableSwap(i,j);
                    swap(i,j);
                }
            }
        } else {
            for (int i=streaks.size()-1; i>=1; i--) {
                int a = streaks.get(i);
                int b = streaks.get(i-1);
                if (b-a > 1) continue;
                if ((t[b] > t[a] && t[a] > t[a-1])
                    || (t[b] < t[a] && t[a] < t[a-1])) {
                        streaks.remove(i);
                }
            }
            for (int s : streaks) {
                doShit(s, streaks);
            }
            //doShit(streaks.get(0), streaks.get(1));
            //doShit(streaks.get(1), streaks.get(0));
        }
        io.println(viableSwaps.size());
    }

    void doShit(int start, List<Integer> others) {
        for (int i=start; i<n && i<=start+6; i++) {
            for (int j=0; j<n; j++) {
                swap(i,j);
                boolean allOkOthers = true;
                for (int other : others) {
                    if (!verifyNicenessAround(other)) allOkOthers = false;
                }
                if (verifyNicenessAround(i, j) && allOkOthers) addViableSwap(i,j);
                swap(i,j);
            }
        }
    }

    void doShit(int start, int other) {
        for (int i=start; i<n && i<=start+6; i++) {
            for (int j=0; j<n; j++) {
                swap(i,j);
                if (verifyNicenessAround(i, j) && verifyNicenessAround(other)) addViableSwap(i,j);
                swap(i,j);
            }
        }
    }

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

    boolean verifyNicenessAround(int i, int j) {
        return (verifyNicenessAround(i) && verifyNicenessAround(j));
    }

    boolean verifyNicenessAround(int a) {
        int startRange = Math.max(0, a-4);
        int endRange = Math.min(n-1, startRange+8);
        for (int i=startRange+1; i<=endRange; i++) {
            if (i%2 == 0 && t[i] >= t[i-1]) {
                return false;
            } else if (i%2 != 0 && t[i] <= t[i-1]) {
                return false;
            }
        }
        return true;
    }

    void addViableSwap(int i, int j) {
        viableSwaps.add(new Swap(i,j));
    }

}

class Swap {
    int i;
    int j;

    public Swap(int i, int j) {
        this.i = Math.min(i,j);
        this.j = Math.max(i,j);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj.getClass() != this.getClass()) return false;
        Swap other = (Swap) obj;
        if (other.i != this.i) return false;
        if (other.j != this.j) return false;
        return true;
    }

    @Override
    public int hashCode() {
        return i*10000008+j;
    }

}

class CIO extends PrintWriter {
    private InputStreamReader r;
    private static final int BUFSIZE = 1 << 15;
    private char[] buf;
    private int bufc;
    private int bufi;
    private StringBuilder sb;

    public CIO() {
            super(new BufferedOutputStream(System.out));
            r = new InputStreamReader(System.in);

            buf = new char[BUFSIZE];
            bufc = 0;
            bufi = 0;
            sb = new StringBuilder();
    }

    private void fillBuf() throws IOException {
            bufi = 0;
            bufc = 0;
            while(bufc == 0) {
                    bufc = r.read(buf, 0, BUFSIZE);
                    if(bufc == -1) {
                            bufc = 0;
                            return;
                    }
            }
    }

    private boolean pumpBuf() throws IOException {
            if(bufi == bufc) {
                    fillBuf();
            }
            return bufc != 0;
    }

    private boolean isDelimiter(char c) {
            return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
    }

    private void eatDelimiters() throws IOException {
            while(true) {
                    if(bufi == bufc) {
                            fillBuf();
                            if(bufc == 0) throw new RuntimeException("IO: Out of input.");
                    }

                    if(!isDelimiter(buf[bufi])) break;
                    ++bufi;
            }
    }

    public String next() {
            try {
                    sb.setLength(0);

                    eatDelimiters();
                    int start = bufi;

                    while(true) {
                            if(bufi == bufc) {
                                    sb.append(buf, start, bufi - start);
                                    fillBuf();
                                    start = 0;
                                    if(bufc == 0) break;
                            }

                            if(isDelimiter(buf[bufi])) break;
                            ++bufi;
                    }

                    sb.append(buf, start, bufi - start);

                    return sb.toString();
            } catch(IOException e) {
                    throw new RuntimeException("IO.next: Caught IOException.");
            }
    }

    public int nextInt() {
            try {
                    int ret = 0;

                    eatDelimiters();

                    boolean positive = true;
                    if(buf[bufi] == '-') {
                            ++bufi;
                            if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
                            positive = false;
                    }

                    boolean first = true;
                    while(true) {
                            if(!pumpBuf()) break;
                            if(isDelimiter(buf[bufi])) {
                                    if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
                                    break;
                            }
                            first = false;

                            if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                                    if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
                                    ret *= 10;
                                    ret -= (int)(buf[bufi] - '0');
                                    if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
                            } else {
                                    throw new RuntimeException("IO.nextInt: Invalid int.");
                            }

                            ++bufi;
                    }

                    if(positive) {
                            if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
                            ret = -ret;
                    }

                    return ret;
            } catch(IOException e) {
                    throw new RuntimeException("IO.nextInt: Caught IOException.");
            }
    }

    public long nextLong() {
            try {
                    long ret = 0;

                    eatDelimiters();

                    boolean positive = true;
                    if(buf[bufi] == '-') {
                            ++bufi;
                            if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
                            positive = false;
                    }

                    boolean first = true;
                    while(true) {
                            if(!pumpBuf()) break;
                            if(isDelimiter(buf[bufi])) {
                                    if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
                                    break;
                            }
                            first = false;

                            if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                                    if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
                                    ret *= 10;
                                    ret -= (long)(buf[bufi] - '0');
                                    if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
                            } else {
                                    throw new RuntimeException("IO.nextLong: Invalid long.");
                            }

                            ++bufi;
                    }

                    if(positive) {
                            if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
                            ret = -ret;
                    }

                    return ret;
            } catch(IOException e) {
                    throw new RuntimeException("IO.nextLong: Caught IOException.");
            }
    }

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

}


//package india;

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

public class C {

    public static void main(String[] args) {
        CIO io = new CIO();
        try {
            Csolver solver = new Csolver(io);
        } finally {
            io.close();
        }
    }

}

class Csolver {

    int n;
    int[] t;
    int count;
    HashSet<Swap> viableSwaps;

    public Csolver(CIO io) {
        n = io.nextInt();
        t = new int[n];
        for (int i=0; i<n; i++) {
            t[i] = io.nextInt();
        }

        List<Integer> streaks = new ArrayList<>();
        for (int i=1; i<n; i++) {
            if (i%2 == 0 && t[i] >= t[i-1]) {
                int bah = Math.max(0, i);
                streaks.add(bah);
            } else if (i%2 != 0 && t[i] <= t[i-1]) {
                int bah = Math.max(0, i);
                streaks.add(bah);
            }
            if (streaks.size() > 8) {
                io.println("0");
                return;
            }
        }
        viableSwaps = new HashSet<>();
        for (int i=streaks.size()-1; i>=1; i--) {
            int a = streaks.get(i);
            int b = streaks.get(i-1);
            if (b-a > 1) continue;
            if ((t[a] > t[a-1] && t[a-1] > t[a-2])
                || (t[a] < t[a-1] && t[a-1] < t[a-2])) {
                    streaks.remove(i);
            }
        }
        for (int s : streaks) {
            doShit(s, streaks);
        }
        //doShit(streaks.get(0), streaks.get(1));
        //doShit(streaks.get(1), streaks.get(0));
        io.println(viableSwaps.size());
    }

    void doShit(int start, List<Integer> others) {
        start = Math.max(0, start-2);
        for (int i=start; i<n && i<=start+6; i++) {
            for (int j=0; j<n; j++) {
                swap(i,j);
                boolean allOkOthers = true;
                for (int other : others) {
                    if (!verifyNicenessAround(other)) allOkOthers = false;
                }
                if (verifyNicenessAround(i, j) && allOkOthers) addViableSwap(i,j);
                swap(i,j);
            }
        }
    }

    void doShit(int start, int other) {
        for (int i=start; i<n && i<=start+6; i++) {
            for (int j=0; j<n; j++) {
                swap(i,j);
                if (verifyNicenessAround(i, j) && verifyNicenessAround(other)) addViableSwap(i,j);
                swap(i,j);
            }
        }
    }

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

    boolean verifyNicenessAround(int i, int j) {
        return (verifyNicenessAround(i) && verifyNicenessAround(j));
    }

    boolean verifyNicenessAround(int a) {
        int startRange = Math.max(0, a-4);
        int endRange = Math.min(n-1, startRange+8);
        for (int i=startRange+1; i<=endRange; i++) {
            if (i%2 == 0 && t[i] >= t[i-1]) {
                return false;
            } else if (i%2 != 0 && t[i] <= t[i-1]) {
                return false;
            }
        }
        return true;
    }

    void addViableSwap(int i, int j) {
        viableSwaps.add(new Swap(i,j));
    }

}

class Swap {
    int i;
    int j;

    public Swap(int i, int j) {
        this.i = Math.min(i,j);
        this.j = Math.max(i,j);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj.getClass() != this.getClass()) return false;
        Swap other = (Swap) obj;
        if (other.i != this.i) return false;
        if (other.j != this.j) return false;
        return true;
    }

    @Override
    public int hashCode() {
        return i*10000008+j;
    }

}

class CIO extends PrintWriter {
    private InputStreamReader r;
    private static final int BUFSIZE = 1 << 15;
    private char[] buf;
    private int bufc;
    private int bufi;
    private StringBuilder sb;

    public CIO() {
            super(new BufferedOutputStream(System.out));
            r = new InputStreamReader(System.in);

            buf = new char[BUFSIZE];
            bufc = 0;
            bufi = 0;
            sb = new StringBuilder();
    }

    private void fillBuf() throws IOException {
            bufi = 0;
            bufc = 0;
            while(bufc == 0) {
                    bufc = r.read(buf, 0, BUFSIZE);
                    if(bufc == -1) {
                            bufc = 0;
                            return;
                    }
            }
    }

    private boolean pumpBuf() throws IOException {
            if(bufi == bufc) {
                    fillBuf();
            }
            return bufc != 0;
    }

    private boolean isDelimiter(char c) {
            return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
    }

    private void eatDelimiters() throws IOException {
            while(true) {
                    if(bufi == bufc) {
                            fillBuf();
                            if(bufc == 0) throw new RuntimeException("IO: Out of input.");
                    }

                    if(!isDelimiter(buf[bufi])) break;
                    ++bufi;
            }
    }

    public String next() {
            try {
                    sb.setLength(0);

                    eatDelimiters();
                    int start = bufi;

                    while(true) {
                            if(bufi == bufc) {
                                    sb.append(buf, start, bufi - start);
                                    fillBuf();
                                    start = 0;
                                    if(bufc == 0) break;
                            }

                            if(isDelimiter(buf[bufi])) break;
                            ++bufi;
                    }

                    sb.append(buf, start, bufi - start);

                    return sb.toString();
            } catch(IOException e) {
                    throw new RuntimeException("IO.next: Caught IOException.");
            }
    }

    public int nextInt() {
            try {
                    int ret = 0;

                    eatDelimiters();

                    boolean positive = true;
                    if(buf[bufi] == '-') {
                            ++bufi;
                            if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
                            positive = false;
                    }

                    boolean first = true;
                    while(true) {
                            if(!pumpBuf()) break;
                            if(isDelimiter(buf[bufi])) {
                                    if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
                                    break;
                            }
                            first = false;

                            if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                                    if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
                                    ret *= 10;
                                    ret -= (int)(buf[bufi] - '0');
                                    if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
                            } else {
                                    throw new RuntimeException("IO.nextInt: Invalid int.");
                            }

                            ++bufi;
                    }

                    if(positive) {
                            if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
                            ret = -ret;
                    }

                    return ret;
            } catch(IOException e) {
                    throw new RuntimeException("IO.nextInt: Caught IOException.");
            }
    }

    public long nextLong() {
            try {
                    long ret = 0;

                    eatDelimiters();

                    boolean positive = true;
                    if(buf[bufi] == '-') {
                            ++bufi;
                            if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
                            positive = false;
                    }

                    boolean first = true;
                    while(true) {
                            if(!pumpBuf()) break;
                            if(isDelimiter(buf[bufi])) {
                                    if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
                                    break;
                            }
                            first = false;

                            if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                                    if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
                                    ret *= 10;
                                    ret -= (long)(buf[bufi] - '0');
                                    if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
                            } else {
                                    throw new RuntimeException("IO.nextLong: Invalid long.");
                            }

                            ++bufi;
                    }

                    if(positive) {
                            if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
                            ret = -ret;
                    }

                    return ret;
            } catch(IOException e) {
                    throw new RuntimeException("IO.nextLong: Caught IOException.");
            }
    }

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

}


//package india;

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

public class C {

    public static void main(String[] args) {
        CIO io = new CIO();
        try {
            Csolver solver = new Csolver(io);
        } finally {
            io.close();
        }
    }

}

class Csolver {

    int n;
    int[] t;
    int count;
    HashSet<Swap> viableSwaps;

    public Csolver(CIO io) {
        n = io.nextInt();
        t = new int[n];
        for (int i=0; i<n; i++) {
            t[i] = io.nextInt();
        }

        List<Integer> streaks = new ArrayList<>();
        for (int i=1; i<n; i++) {
            if (i%2 == 0 && t[i] >= t[i-1]) {
                int bah = Math.max(0, i-2);
                streaks.add(bah);
            } else if (i%2 != 0 && t[i] <= t[i-1]) {
                int bah = Math.max(0, i-2);
                streaks.add(bah);
            }
            if (streaks.size() > 8) {
                io.println("0");
                return;
            }
        }
        viableSwaps = new HashSet<>();
        if (streaks.size() == 1) {
            int start = streaks.get(0);
            for (int i=start; i<n && i<=start+4; i++) {
                for (int j=0; j<n; j++) {
                    swap(i,j);
                    if (verifyNicenessAround(i, j)) addViableSwap(i,j);
                    swap(i,j);
                }
            }
        } else {
            for (int i=streaks.size(); i>=1; i--) {
                int a = streaks.get(i);
                int b = streaks.get(i-1);
                if (b-a > 1) continue;
                if ((t[b] > t[a] && t[a] > t[a-1])
                    || (t[b] < t[a] && t[a] < t[a-1])) {
                        streaks.remove(i);
                }
            }
            for (int s : streaks) {
                doShit(s, streaks);
            }
            //doShit(streaks.get(0), streaks.get(1));
            //doShit(streaks.get(1), streaks.get(0));
        }
        io.println(viableSwaps.size());
    }

    void doShit(int start, List<Integer> others) {
        for (int i=start; i<n && i<=start+6; i++) {
            for (int j=0; j<n; j++) {
                swap(i,j);
                boolean allOkOthers = true;
                for (int other : others) {
                    if (!verifyNicenessAround(other)) allOkOthers = false;
                }
                if (verifyNicenessAround(i, j) && allOkOthers) addViableSwap(i,j);
                swap(i,j);
            }
        }
    }

    void doShit(int start, int other) {
        for (int i=start; i<n && i<=start+6; i++) {
            for (int j=0; j<n; j++) {
                swap(i,j);
                if (verifyNicenessAround(i, j) && verifyNicenessAround(other)) addViableSwap(i,j);
                swap(i,j);
            }
        }
    }

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

    boolean verifyNicenessAround(int i, int j) {
        return (verifyNicenessAround(i) && verifyNicenessAround(j));
    }

    boolean verifyNicenessAround(int a) {
        int startRange = Math.max(0, a-4);
        int endRange = Math.min(n-1, startRange+8);
        for (int i=startRange+1; i<=endRange; i++) {
            if (i%2 == 0 && t[i] >= t[i-1]) {
                return false;
            } else if (i%2 != 0 && t[i] <= t[i-1]) {
                return false;
            }
        }
        return true;
    }

    void addViableSwap(int i, int j) {
        viableSwaps.add(new Swap(i,j));
    }

}

class Swap {
    int i;
    int j;

    public Swap(int i, int j) {
        this.i = Math.min(i,j);
        this.j = Math.max(i,j);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj.getClass() != this.getClass()) return false;
        Swap other = (Swap) obj;
        if (other.i != this.i) return false;
        if (other.j != this.j) return false;
        return true;
    }

    @Override
    public int hashCode() {
        return i*10000008+j;
    }

}

class CIO extends PrintWriter {
    private InputStreamReader r;
    private static final int BUFSIZE = 1 << 15;
    private char[] buf;
    private int bufc;
    private int bufi;
    private StringBuilder sb;

    public CIO() {
            super(new BufferedOutputStream(System.out));
            r = new InputStreamReader(System.in);

            buf = new char[BUFSIZE];
            bufc = 0;
            bufi = 0;
            sb = new StringBuilder();
    }

    private void fillBuf() throws IOException {
            bufi = 0;
            bufc = 0;
            while(bufc == 0) {
                    bufc = r.read(buf, 0, BUFSIZE);
                    if(bufc == -1) {
                            bufc = 0;
                            return;
                    }
            }
    }

    private boolean pumpBuf() throws IOException {
            if(bufi == bufc) {
                    fillBuf();
            }
            return bufc != 0;
    }

    private boolean isDelimiter(char c) {
            return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
    }

    private void eatDelimiters() throws IOException {
            while(true) {
                    if(bufi == bufc) {
                            fillBuf();
                            if(bufc == 0) throw new RuntimeException("IO: Out of input.");
                    }

                    if(!isDelimiter(buf[bufi])) break;
                    ++bufi;
            }
    }

    public String next() {
            try {
                    sb.setLength(0);

                    eatDelimiters();
                    int start = bufi;

                    while(true) {
                            if(bufi == bufc) {
                                    sb.append(buf, start, bufi - start);
                                    fillBuf();
                                    start = 0;
                                    if(bufc == 0) break;
                            }

                            if(isDelimiter(buf[bufi])) break;
                            ++bufi;
                    }

                    sb.append(buf, start, bufi - start);

                    return sb.toString();
            } catch(IOException e) {
                    throw new RuntimeException("IO.next: Caught IOException.");
            }
    }

    public int nextInt() {
            try {
                    int ret = 0;

                    eatDelimiters();

                    boolean positive = true;
                    if(buf[bufi] == '-') {
                            ++bufi;
                            if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
                            positive = false;
                    }

                    boolean first = true;
                    while(true) {
                            if(!pumpBuf()) break;
                            if(isDelimiter(buf[bufi])) {
                                    if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
                                    break;
                            }
                            first = false;

                            if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                                    if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
                                    ret *= 10;
                                    ret -= (int)(buf[bufi] - '0');
                                    if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
                            } else {
                                    throw new RuntimeException("IO.nextInt: Invalid int.");
                            }

                            ++bufi;
                    }

                    if(positive) {
                            if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
                            ret = -ret;
                    }

                    return ret;
            } catch(IOException e) {
                    throw new RuntimeException("IO.nextInt: Caught IOException.");
            }
    }

    public long nextLong() {
            try {
                    long ret = 0;

                    eatDelimiters();

                    boolean positive = true;
                    if(buf[bufi] == '-') {
                            ++bufi;
                            if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
                            positive = false;
                    }

                    boolean first = true;
                    while(true) {
                            if(!pumpBuf()) break;
                            if(isDelimiter(buf[bufi])) {
                                    if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
                                    break;
                            }
                            first = false;

                            if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                                    if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
                                    ret *= 10;
                                    ret -= (long)(buf[bufi] - '0');
                                    if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
                            } else {
                                    throw new RuntimeException("IO.nextLong: Invalid long.");
                            }

                            ++bufi;
                    }

                    if(positive) {
                            if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
                            ret = -ret;
                    }

                    return ret;
            } catch(IOException e) {
                    throw new RuntimeException("IO.nextLong: Caught IOException.");
            }
    }

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

}


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

public class b {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		solve(in, out);
		out.close();
	}

	static private boolean valid(int[] a) {
		for(int i = 0; i + 1 < a.length; i++) {
			if(i % 2 == 0 && a[i] >= a[i + 1]) {
				return false;
			} else if(i % 2 == 1 && a[i] <= a[i + 1]) {
				return false;
			}
		}
		return true;
	}

	static private void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		int[] bottom = new int[(n + 1) / 2];
		int[] upper = new int[n / 2];
		for(int i = 0; i < n; i += 2) {
			bottom[i / 2] = 200000;
			if(i + 1 < n) {
				bottom[i / 2] = a[i + 1];
			}
			if(i != 0 && a[i - 1] < bottom[i / 2]) {
				bottom[i / 2] = a[i - 1];
			}
			//out.print(bottom[i / 2] + " ");
		}
		//out.println();
		for(int i = 1; i < n; i += 2) {
			upper[i / 2] = a[i - 1];
			if(i + 1 < n && a[i + 1] > upper[i / 2]) {
				upper[i / 2] = a[i + 1];
			}
			//out.print(upper[i / 2] + " ");
		}
		//out.println();
		int l = 0, r = n - 1;
		while(l < n) {
			if(l % 2 == 0 && a[l] >= a[l + 1]) {
				break;
			} else if(l % 2 == 1 && a[l] <= a[l + 1]) {
				break;
			}
			l++;
		}
		while(r > 0) {
			r--;
			if(r % 2 == 0 && a[r] >= a[r + 1]) {
				break;
			} else if(r % 2 == 1 && a[r] <= a[r + 1]) {
				break;
			}
		}
		int ans = 0;
		int lul = 10;
		//out.println("got (" + l + ", " + r + ")");
		if(l == r) {
			if(l % 2 == 0) {
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				l++;
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
			} else {
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
				l++;
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
			}
			l--;
		} else if(l + 1 == r) {
			lul = 1;
			l++;
			if(r % 2 == 0) {
				for(int i = 0; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
				for(int i = 1; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
			} else {
				for(int i = 0; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
				for(int i = 1; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
			}
		}
		for(int i = -lul; i <= lul; i++) {
			for(int j = -lul; j <= lul; j++) {
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				if(i + l < 0 || j + r < 0 || l + i >= r + j || l + i >= n || r + j >= n) {
					continue;
				}
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				int t = a[l + i];
				a[l + i] = a[r + j];
				a[r + j] = t;
				if(valid(a)) {
					ans++;
				}
				a[r + j] = a[l + i];
				a[l + i] = t;
			}
		}
		out.println(ans);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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


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

public class b {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		solve(in, out);
		out.close();
	}

	static private boolean valid(int[] a) {
		for(int i = 0; i + 1 < a.length; i++) {
			if(i % 2 == 0 && a[i] >= a[i + 1]) {
				return false;
			} else if(i % 2 == 1 && a[i] <= a[i + 1]) {
				return false;
			}
		}
		return true;
	}

	static private void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		int[] bottom = new int[(n + 1) / 2];
		int[] upper = new int[n / 2];
		for(int i = 0; i < n; i += 2) {
			bottom[i / 2] = 200000;
			if(i + 1 < n) {
				bottom[i / 2] = a[i + 1];
			}
			if(i != 0 && a[i - 1] < bottom[i / 2]) {
				bottom[i / 2] = a[i - 1];
			}
			//out.print(bottom[i / 2] + " ");
		}
		//out.println();
		for(int i = 1; i < n; i += 2) {
			upper[i / 2] = a[i - 1];
			if(i + 1 < n && a[i + 1] > upper[i / 2]) {
				upper[i / 2] = a[i + 1];
			}
			//out.print(upper[i / 2] + " ");
		}
		//out.println();
		int l = 0, r = n - 1;
		while(l < n) {
			if(l % 2 == 0 && a[l] >= a[l + 1]) {
				break;
			} else if(l % 2 == 1 && a[l] <= a[l + 1]) {
				break;
			}
			l++;
		}
		while(r > 0) {
			r--;
			if(r % 2 == 0 && a[r] >= a[r + 1]) {
				break;
			} else if(r % 2 == 1 && a[r] <= a[r + 1]) {
				break;
			}
		}
		int ans = 0;
		int lul = 10;
		//out.println("got (" + l + ", " + r + ")");
		if(l == r) {
			if(l % 2 == 0) {
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				l++;
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
			} else {
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
				l++;
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
			}
			l--;
		} else if(l + 1 == r) {
			l++;
			if(r % 2 == 0) {
				for(int i = 0; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
				for(int i = 1; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
			} else {
				for(int i = 0; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
				for(int i = 1; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
			}
			l--;
			ans = 0;
		}
		for(int i = -lul; i <= lul; i++) {
			for(int j = -lul; j <= lul; j++) {
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				if(i + l < 0 || j + r < 0 || l + i >= r + j || l + i >= n || r + j >= n) {
					continue;
				}
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				int t = a[l + i];
				a[l + i] = a[r + j];
				a[r + j] = t;
				if(valid(a)) {
					ans++;
				}
				a[r + j] = a[l + i];
				a[l + i] = t;
			}
		}
		out.println(ans);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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


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

public class b {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		solve(in, out);
		out.close();
	}

	static private boolean valid(int[] a) {
		for(int i = 0; i + 1 < a.length; i++) {
			if(i % 2 == 0 && a[i] >= a[i + 1]) {
				return false;
			} else if(i % 2 == 1 && a[i] <= a[i + 1]) {
				return false;
			}
		}
		return true;
	}

	static private void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		int[] bottom = new int[(n + 1) / 2];
		int[] upper = new int[n / 2];
		for(int i = 0; i < n; i += 2) {
			bottom[i / 2] = 200000;
			if(i + 1 < n) {
				bottom[i / 2] = a[i + 1];
			}
			if(i != 0 && a[i - 1] < bottom[i / 2]) {
				bottom[i / 2] = a[i - 1];
			}
			//out.print(bottom[i / 2] + " ");
		}
		//out.println();
		for(int i = 1; i < n; i += 2) {
			upper[i / 2] = a[i - 1];
			if(i + 1 < n && a[i + 1] > upper[i / 2]) {
				upper[i / 2] = a[i + 1];
			}
			//out.print(upper[i / 2] + " ");
		}
		//out.println();
		int l = 0, r = n - 1;
		while(l < n) {
			if(l % 2 == 0 && a[l] >= a[l + 1]) {
				break;
			} else if(l % 2 == 1 && a[l] <= a[l + 1]) {
				break;
			}
			l++;
		}
		while(r > 0) {
			r--;
			if(r % 2 == 0 && a[r] >= a[r + 1]) {
				break;
			} else if(r % 2 == 1 && a[r] <= a[r + 1]) {
				break;
			}
		}
		int ans = 0;
		//out.println("got (" + l + ", " + r + ")");
		if(l == r) {
			if(l % 2 == 0) {
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - 1 <= i && i <= r + 1)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - 1 <= i && i <= r + 1)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				l++;
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - 1 <= i && i <= r + 1)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - 1 <= i && i <= r + 1)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
			} else {
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - 1 <= i && i <= r + 1)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - 1 <= i && i <= r + 1)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
				l++;
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - 1 <= i && i <= r + 1)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - 1 <= i && i <= r + 1)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
			}
			l--;
		}
		for(int i = -1; i < 2; i++) {
			for(int j = -1; j < 2; j++) {
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				if(i + l < 0 || j + r < 0 || l + i >= r + j || l + i >= n || r + j >= n) {
					continue;
				}
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				int t = a[l + i];
				a[l + i] = a[r + j];
				a[r + j] = t;
				if(valid(a)) {
					ans++;
				}
				a[r + j] = a[l + i];
				a[l + i] = t;
			}
		}
		out.println(ans);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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


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

public class b {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		solve(in, out);
		out.close();
	}

	static private boolean valid(int[] a) {
		for(int i = 0; i + 1 < a.length; i++) {
			if(i % 2 == 0 && a[i] >= a[i + 1]) {
				return false;
			} else if(i % 2 == 1 && a[i] <= a[i + 1]) {
				return false;
			}
		}
		return true;
	}

	static private void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		int[] bottom = new int[(n + 1) / 2];
		int[] upper = new int[n / 2];
		for(int i = 0; i < n; i += 2) {
			bottom[i / 2] = 200000;
			if(i + 1 < n) {
				bottom[i / 2] = a[i + 1];
			}
			if(i != 0 && a[i - 1] < bottom[i / 2]) {
				bottom[i / 2] = a[i - 1];
			}
			//out.print(bottom[i / 2] + " ");
		}
		//out.println();
		for(int i = 1; i < n; i += 2) {
			upper[i / 2] = a[i - 1];
			if(i + 1 < n && a[i + 1] > upper[i / 2]) {
				upper[i / 2] = a[i + 1];
			}
			//out.print(upper[i / 2] + " ");
		}
		//out.println();
		int l = 0, r = n - 1;
		while(l < n) {
			if(l % 2 == 0 && a[l] >= a[l + 1]) {
				break;
			} else if(l % 2 == 1 && a[l] <= a[l + 1]) {
				break;
			}
			l++;
		}
		while(r > 0) {
			r--;
			if(r % 2 == 0 && a[r] >= a[r + 1]) {
				break;
			} else if(r % 2 == 1 && a[r] <= a[r + 1]) {
				break;
			}
		}
		int ans = 0;
		int lul = 10;
		//out.println("got (" + l + ", " + r + ")");
		if(l == r) {
			if(l % 2 == 0) {
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				l++;
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
			} else {
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
				l++;
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
			}
			l--;
		}
		for(int i = -lul; i <= lul; i++) {
			for(int j = -lul; j <= lul; j++) {
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				if(i + l < 0 || j + r < 0 || l + i >= r + j || l + i >= n || r + j >= n) {
					continue;
				}
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				int t = a[l + i];
				a[l + i] = a[r + j];
				a[r + j] = t;
				if(valid(a)) {
					ans++;
				}
				a[r + j] = a[l + i];
				a[l + i] = t;
			}
		}
		out.println(ans);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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


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

public class b {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		solve(in, out);
		out.close();
	}

	static private boolean valid(int[] a) {
		for(int i = 0; i + 1 < a.length; i++) {
			if(i % 2 == 0 && a[i] >= a[i + 1]) {
				return false;
			} else if(i % 2 == 1 && a[i] <= a[i + 1]) {
				return false;
			}
		}
		return true;
	}

	static private void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		int[] bottom = new int[(n + 1) / 2];
		int[] upper = new int[n / 2];
		for(int i = 0; i < n; i += 2) {
			bottom[i / 2] = 200000;
			if(i + 1 < n) {
				bottom[i / 2] = a[i + 1];
			}
			if(i != 0 && a[i - 1] < bottom[i / 2]) {
				bottom[i / 2] = a[i - 1];
			}
			//out.print(bottom[i / 2] + " ");
		}
		//out.println();
		for(int i = 1; i < n; i += 2) {
			upper[i / 2] = a[i - 1];
			if(i + 1 < n && a[i + 1] > upper[i / 2]) {
				upper[i / 2] = a[i + 1];
			}
			//out.print(upper[i / 2] + " ");
		}
		//out.println();
		int l = 0, r = n - 1;
		while(l < n) {
			if(l % 2 == 0 && a[l] >= a[l + 1]) {
				break;
			} else if(l % 2 == 1 && a[l] <= a[l + 1]) {
				break;
			}
			l++;
		}
		while(r > 0) {
			r--;
			if(r % 2 == 0 && a[r] >= a[r + 1]) {
				break;
			} else if(r % 2 == 1 && a[r] <= a[r + 1]) {
				break;
			}
		}
		int ans = 0;
		int lul = 10;
		//out.println("got (" + l + ", " + r + ")");
		if(l == r) {
			if(l % 2 == 0) {
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				l++;
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
			} else {
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
				l++;
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
			}
			l--;
		} else if(l + 1 == r) {
			lul = 0;
			if(r % 2 == 0) {
				for(int i = 0; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] < bottom[l / 2] && a[r] < bottom[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
				for(int i = 1; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] < bottom[l / 2] && a[r] > upper[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
			} else {
				for(int i = 0; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] > upper[l / 2] && a[r] < bottom[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
				for(int i = 1; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] > upper[l / 2] && a[r] > upper[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
			}
		}
		for(int i = -lul; i <= lul; i++) {
			for(int j = -lul; j <= lul; j++) {
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				if(i + l < 0 || j + r < 0 || l + i >= r + j || l + i >= n || r + j >= n) {
					continue;
				}
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				int t = a[l + i];
				a[l + i] = a[r + j];
				a[r + j] = t;
				if(valid(a)) {
					ans++;
				}
				a[r + j] = a[l + i];
				a[l + i] = t;
			}
		}
		out.println(ans);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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


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

public class b {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		solve(in, out);
		out.close();
	}

	static private boolean valid(int[] a) {
		for(int i = 0; i + 1 < a.length; i++) {
			if(i % 2 == 0 && a[i] >= a[i + 1]) {
				return false;
			} else if(i % 2 == 1 && a[i] <= a[i + 1]) {
				return false;
			}
		}
		return true;
	}

	static private void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		int[] bottom = new int[(n + 1) / 2];
		int[] upper = new int[n / 2];
		for(int i = 0; i < n; i += 2) {
			bottom[i / 2] = 200000;
			if(i + 1 < n) {
				bottom[i / 2] = a[i + 1];
			}
			if(i != 0 && a[i - 1] < bottom[i / 2]) {
				bottom[i / 2] = a[i - 1];
			}
			//out.print(bottom[i / 2] + " ");
		}
		//out.println();
		for(int i = 1; i < n; i += 2) {
			upper[i / 2] = a[i - 1];
			if(i + 1 < n && a[i + 1] > upper[i / 2]) {
				upper[i / 2] = a[i + 1];
			}
			//out.print(upper[i / 2] + " ");
		}
		//out.println();
		int l = 0, r = n - 1;
		while(l < n) {
			if(l % 2 == 0 && a[l] >= a[l + 1]) {
				break;
			} else if(l % 2 == 1 && a[l] <= a[l + 1]) {
				break;
			}
			l++;
		}
		while(r > 0) {
			r--;
			if(r % 2 == 0 && a[r] >= a[r + 1]) {
				break;
			} else if(r % 2 == 1 && a[r] <= a[r + 1]) {
				break;
			}
		}
		int ans = 0;
		int lul = 10;
		//out.println("got (" + l + ", " + r + ")");
		if(l == r) {
			if(l % 2 == 0) {
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				l++;
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
			} else {
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
				l++;
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
			}
			l--;
		} else if(l + 1 == r) {
			lul = 0;
			if(r % 2 == 0) {
				for(int i = 0; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
				for(int i = 1; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
			} else {
				for(int i = 0; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
				for(int i = 1; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
			}
		}
		for(int i = -lul; i <= lul; i++) {
			for(int j = -lul; j <= lul; j++) {
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				if(i + l < 0 || j + r < 0 || l + i >= r + j || l + i >= n || r + j >= n) {
					continue;
				}
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				int t = a[l + i];
				a[l + i] = a[r + j];
				a[r + j] = t;
				if(valid(a)) {
					ans++;
				}
				a[r + j] = a[l + i];
				a[l + i] = t;
			}
		}
		out.println(ans);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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


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

public class b {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		solve(in, out);
		out.close();
	}

	static private boolean valid(int[] a) {
		for(int i = 0; i + 1 < a.length; i++) {
			if(i % 2 == 0 && a[i] >= a[i + 1]) {
				return false;
			} else if(i % 2 == 1 && a[i] <= a[i + 1]) {
				return false;
			}
		}
		return true;
	}

	static private void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		int[] bottom = new int[(n + 1) / 2];
		int[] upper = new int[n / 2];
		for(int i = 0; i < n; i += 2) {
			bottom[i / 2] = 200000;
			if(i + 1 < n) {
				bottom[i / 2] = a[i + 1];
			}
			if(i != 0 && a[i - 1] < bottom[i / 2]) {
				bottom[i / 2] = a[i - 1];
			}
			//out.print(bottom[i / 2] + " ");
		}
		//out.println();
		for(int i = 1; i < n; i += 2) {
			upper[i / 2] = a[i - 1];
			if(i + 1 < n && a[i + 1] > upper[i / 2]) {
				upper[i / 2] = a[i + 1];
			}
			//out.print(upper[i / 2] + " ");
		}
		//out.println();
		int l = 0, r = n - 1;
		while(l < n) {
			if(l % 2 == 0 && a[l] >= a[l + 1]) {
				break;
			} else if(l % 2 == 1 && a[l] <= a[l + 1]) {
				break;
			}
			l++;
		}
		while(r > 0) {
			r--;
			if(r % 2 == 0 && a[r] >= a[r + 1]) {
				break;
			} else if(r % 2 == 1 && a[r] <= a[r + 1]) {
				break;
			}
		}
		int ans = 0;
		int lul = 10;
		//out.println("got (" + l + ", " + r + ")");
		if(l == r) {
			if(l % 2 == 0) {
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				l++;
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
			} else {
				if(l < n) {
					//out.println("is upper, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] > upper[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
				l++;
				if(l < n) {
					//out.println("is bottom, " + bottom[l / 2]);
					for(int i = 0; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] < bottom[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
					for(int i = 1; i < n; i += 2) {
						if((r - lul <= i && i <= r + lul)) continue;
						if(a[i] < bottom[l / 2] && a[l] > upper[i / 2]) {
							//out.println("found answer swapping (" + l + ", " + i + ")");
							ans++;
						}
					}
				}
				//out.println(ans);
			}
			l--;
		} else if(l + 1 == r) {
			lul = 0;
			l++;
			if(r % 2 == 0) {
				for(int i = 0; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] < bottom[l / 2] && a[r] < bottom[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
				for(int i = 1; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] < bottom[l / 2] && a[r] > upper[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
			} else {
				for(int i = 0; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] > upper[l / 2] && a[r] < bottom[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
				for(int i = 1; i < n; i += 2) {
					if((r - lul <= i && i <= r + lul)) continue;
					if(a[i] > upper[l / 2] && a[r] > upper[i / 2]) {
						//out.println("found answer swapping (" + l + ", " + i + ")");
						ans++;
					}
				}
			}
			out.println(ans);
			return;
		}
		for(int i = -lul; i <= lul; i++) {
			for(int j = -lul; j <= lul; j++) {
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				if(i + l < 0 || j + r < 0 || l + i >= r + j || l + i >= n || r + j >= n) {
					continue;
				}
				//out.println("testing (" + (i + l) + ", " + (j + r) + ")");
				int t = a[l + i];
				a[l + i] = a[r + j];
				a[r + j] = t;
				if(valid(a)) {
					ans++;
				}
				a[r + j] = a[l + i];
				a[l + i] = t;
			}
		}
		out.println(ans);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class C_IndiaHack_2016 {

    public static long MOD = 1000000007;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int[] data = new int[n];
        for (int i = 0; i < n; i++) {
            data[i] = in.nextInt();
        }

        int c = 0;

        ArrayList<Integer> list = new ArrayList();
        for (int i = 0; i < n - 1; i++) {
            if (!check(i, data)) {

                list.add(i);
            }

        }
        if (list.size() > 4) {
            out.println(0);
        } else if (list.size() > 2) {
            int result = 0;
            for (int i = 0; i < list.size(); i++) {
                for (int j = i + 1; j < list.size(); j++) {
                    int x = list.get(i);
                    int y = list.get(j);
                    for (int k = -1; k < 2; k++) {
                        for (int h = -1; h < 2; h++) {
                            boolean ok = true;
                            for(int v : list){
                                ok &= check(v, data);
                            }
                            if (ok && check(x + i, data) && check(y + j, data) && check(x + i - 1, data) && check(y + j - 1, data)) {
                                result++;
                            }
                        }
                    }
                }
            }
            out.println(result);
        } else if (list.size() == 2) {
            int x = list.get(0);
            int y = list.get(1);
            int result = 0;
            for (int i = -1; i < 2; i++) {
                for (int j = -1; j < 2; j++) {
                    swap(x + i, y + j, data);

                    if (check(x, data) && check(y, data) && check(x + i, data) && check(y + j, data) && check(x + i - 1, data) && check(y + j - 1, data)) {
                        result++;
                    }
                    swap(x + i, y + j, data);
                }
            }
            out.println(result);

        } else {
            int x = list.get(0);
            int result = 0;
            for (int i = 0; i < n - 1; i++) {
                swap(x, i, data);
                if (check(i, data) && check(x, data) && check(i - 1, data) && check(x - 1, data)) {
                    //System.out.println(i + " " + x);
                    result++;
                }
                swap(x, i, data);
                swap(x + 1, i, data);
                if (check(i, data) && check(x, data) && check(x + 1, data) && check(i - 1, data)) {
                    //System.out.println(i + " " + x);
                    result++;
                }
                swap(x + 1, i, data);

            }
            out.println(result);
        }
        out.close();
    }

    static void swap(int x, int y, int[] data) {
        if (x < 0 || y < 0 || x >= data.length || y >= data.length) {
            return;
        }
        int tmp = data[x];
        data[x] = data[y];
        data[y] = tmp;
    }

    static boolean check(int index, int[] data) {
        if (index + 1 >= data.length || index < 0) {
            return true;
        }
        if (index % 2 == 0) {
            return data[index] < data[index + 1];
        } else {
            return data[index] > data[index + 1];
        }
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return x - o.x;
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

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

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}