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

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

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

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

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

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

        private boolean checkNearest(int pos) {
            for (int i = -2; i <= 2; i++) {
                if (!checkPosition(pos + i)) {
                    return false;
                }
            }
            return true;
        }

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

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

    }

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

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

        public abstract void removeAt(int index);

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

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

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

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

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

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

    }

    static abstract class IntAbstractStream implements IntStream {

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

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

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

    }

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

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

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

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

            IntIntPair pair = (IntIntPair) o;

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

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

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

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

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

    }

    static interface IntReversableCollection extends IntCollection {
    }

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

    }

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

        public boolean advance();

        public boolean isValid();

    }

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

    }

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

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

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

    }

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

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

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

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

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

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

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

        }

    }

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

        public IntArrayList() {
            this(3);
        }

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

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

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

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

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

        public int size() {
            return size;
        }

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

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

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

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

    }

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

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

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

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

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

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

    }
}


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

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

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

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

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

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

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

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

    }

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

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

        public abstract void removeAt(int index);

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

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

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

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

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

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

    }

    static abstract class IntAbstractStream implements IntStream {

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

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

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

    }

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

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

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

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

            IntIntPair pair = (IntIntPair) o;

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

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

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

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

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

    }

    static interface IntReversableCollection extends IntCollection {
    }

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

    }

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

        public boolean advance();

        public boolean isValid();

    }

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

    }

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

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

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

    }

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

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

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

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

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

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

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

        }

    }

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

        public IntArrayList() {
            this(3);
        }

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

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

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

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

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

        public int size() {
            return size;
        }

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

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

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

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

    }

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

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

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

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

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

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

    }
}


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

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

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

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

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

        private boolean checkAllPositions(IntList positions) {
            for (int position : positions) {
                for (int i = -1; i <= 1; i++) {
                    if (!checkPosition(position + i)) {
                        return false;
                    }
                }
            }
            return true;
        }

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

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

    }

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

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

        public abstract void removeAt(int index);

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

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

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

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

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

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

    }

    static abstract class IntAbstractStream implements IntStream {

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

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

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

    }

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

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

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

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

            IntIntPair pair = (IntIntPair) o;

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

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

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

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

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

    }

    static interface IntReversableCollection extends IntCollection {
    }

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

    }

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

        public boolean advance();

        public boolean isValid();

    }

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

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

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

    }

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

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

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

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

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

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

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

        }

    }

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

        public IntArrayList() {
            this(3);
        }

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

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

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

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

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

        public int size() {
            return size;
        }

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

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

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

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

    }

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

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

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

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

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

    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static int MOD = 1000000007;

    // After writing solution, quick scan for:
    //   array out of bounds
    //   special cases e.g. n=1?
    //
    // Big numbers arithmetic bugs:
    //   int overflow
    //   sorting, or taking max, after MOD
    void solve() throws IOException {
        int n = ri();
        int[] t = ril(n);
        // even index up, odd index down

        int numbad = 0;
        for (int i = 0; i < n-1; i++) {
            if (i % 2 == 0 && t[i] >= t[i+1] || i % 2 == 1 && t[i] <= t[i+1]) numbad++;
        }

        long ans = 0;
        for (int i = 0; i < n-1; i++) {
            if (i % 2 == 0 && t[i] >= t[i+1] || i % 2 == 1 && t[i] <= t[i+1]) {
                for (int j = 0; j < n; j++) {
                    // try swapping t[i] with t[j]
                    Set<Integer> set = new HashSet<>();
                    set.add(i-1);
                    set.add(i);
                    set.add(i+1);
                    set.add(j-1);
                    set.add(j);
                    set.add(j+1);
                    int before = 0;
                    for (int x : set) if (!ok(t, x)) before++;
                    swap(t, i, j);
                    int after = 0;
                    for (int x : set) if (!ok(t, x)) after++;
                    int delta = after - before;
                    if (numbad + delta == 0) {
                        ans++;
                    }
                    swap(t, i, j);
                }
                for (int j = 0; j < n; j++) {
                    if (j == i) continue;
                    // try swapping t[i] with t[j]
                    Set<Integer> set = new HashSet<>();
                    set.add(i);
                    set.add(i+1);
                    set.add(i+2);
                    set.add(j-1);
                    set.add(j);
                    set.add(j+1);
                    int before = 0;
                    for (int x : set) if (!ok(t, x)) before++;
                    swap(t, i+1, j);
                    int after = 0;
                    for (int x : set) if (!ok(t, x)) after++;
                    int delta = after - before;
                    if (numbad + delta == 0) {
                        ans++;
                    }
                    swap(t, i+1, j);
                }
                break;
            }
        }
        pw.println(ans);
    }

    boolean ok(int[] t, int i) {
        if (i >= t.length-1 || i < 0) return true;
        if (i % 2 == 0) return t[i] < t[i+1];
        return t[i] > t[i+1];
    }

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

    // Template code below

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        Main m = new Main();
        m.solve();
        m.close();
    }

    void close() throws IOException {
        pw.flush();
        pw.close();
        br.close();
    }

    int ri() throws IOException {
        return Integer.parseInt(br.readLine().trim());
    }

    long rl() throws IOException {
        return Long.parseLong(br.readLine().trim());
    }

    int[] ril(int n) throws IOException {
        int[] nums = new int[n];
        int c = 0;
        for (int i = 0; i < n; i++) {
            int sign = 1;
            c = br.read();
            int x = 0;
            if (c == '-') {
                sign = -1;
                c = br.read();
            }
            while (c >= '0' && c <= '9') {
                x = x * 10 + c - '0';
                c = br.read();
            }
            nums[i] = x * sign;
        }
        while (c != '\n' && c != -1) c = br.read();
        return nums;
    }

    long[] rll(int n) throws IOException {
        long[] nums = new long[n];
        int c = 0;
        for (int i = 0; i < n; i++) {
            int sign = 1;
            c = br.read();
            long x = 0;
            if (c == '-') {
                sign = -1;
                c = br.read();
            }
            while (c >= '0' && c <= '9') {
                x = x * 10 + c - '0';
                c = br.read();
            }
            nums[i] = x * sign;
        }
        while (c != '\n' && c != -1) c = br.read();
        return nums;
    }

    int[] rkil() throws IOException {
        int sign = 1;
        int c = br.read();
        int x = 0;
        if (c == '-') {
            sign = -1;
            c = br.read();
        }
        while (c >= '0' && c <= '9') {
            x = x * 10 + c - '0';
            c = br.read();
        }
        return ril(x);
    }

    long[] rkll() throws IOException {
        int sign = 1;
        int c = br.read();
        int x = 0;
        if (c == '-') {
            sign = -1;
            c = br.read();
        }
        while (c >= '0' && c <= '9') {
            x = x * 10 + c - '0';
            c = br.read();
        }
        return rll(x);
    }

    char[] rs() throws IOException {
        return br.readLine().toCharArray();
    }

    void sort(int[] A) {
        Random r = new Random();
        for (int i = A.length-1; i > 0; i--) {
            int j = r.nextInt(i+1);
            int temp = A[i];
            A[i] = A[j];
            A[j] = temp;
        }
        Arrays.sort(A);
    }
}


/*
Keep solving problems.
*/
import java.util.*;
import java.io.*;

public class IndiaHacks2016C {

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

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

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

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

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

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

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

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


/*
Keep solving problems.
*/
import java.util.*;
import java.io.*;

public class IndiaHacks2016C {

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

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

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

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

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

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

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


/*
Keep solving problems.
*/
import java.util.*;
import java.io.*;

public class IndiaHacks2016C {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    int[] arr;
    int n;
    class Node implements Comparable<Node> {
        int i;
        int j;
        public Node(int i, int j) {
            this.i = i;
            this.j = j;
        }

        @Override
        public int compareTo(Node o) {
            if(i != o.i) {
                return Integer.compare(i, o.i);
            }
            return Integer.compare(j, o.j);
        }

        @Override
        public int hashCode() {
            int v = 31;
            v = 37 * v + i;
            v = 37 * v + j;
            return v;
        }

        @Override
        public boolean equals(Object obj) {
            if(!(obj instanceof Node)) {
                return false;
            }
            Node nd = (Node) obj;
            return nd.i == this.i && nd.j == this.j;
        }
    }
    void solve() throws IOException {
        n = nextInt();
        arr = nextIntArr(n);
        Set<Integer> list = new HashSet<>();
        for(int i = 0; i < n; i++) {
            if(!check(i)) {
                list.add(i);
                if(i + 1 < n) {
                    list.add(i + 1);
                }
            }
        }

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

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

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

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

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


/*
Keep solving problems.
*/
import java.util.*;
import java.io.*;

public class IndiaHacks2016C {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    int[] arr;
    int n;
    class Node implements Comparable<Node> {
        int i;
        int j;
        public Node(int i, int j) {
            this.i = i;
            this.j = j;
        }

        @Override
        public int compareTo(Node o) {
            if(i != o.i) {
                return Integer.compare(i, o.i);
            }
            return Integer.compare(j, o.j);
        }

        @Override
        public int hashCode() {
            int v = 31;
            v = 37 * v + i;
            v = 37 * v + j;
            return v;
        }

        @Override
        public boolean equals(Object obj) {
            if(!(obj instanceof Node)) {
                return false;
            }
            Node nd = (Node) obj;
            return nd.i == this.i && nd.j == this.j;
        }
    }
    void solve() throws IOException {
        n = nextInt();
        arr = nextIntArr(n);
        Set<Integer> list = new HashSet<>();
        for(int i = 0; i < n; i++) {
            if(!check(i)) {
                list.add(i);
                if(i + 1 < n) {
                    list.add(i + 1);
                }
            }
        }

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

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

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

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

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


/*
Keep solving problems.
*/
import java.util.*;
import java.io.*;

public class IndiaHacks2016C {

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

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

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

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

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

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

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

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


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

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

    static class TaskC {
        private int[] t;
        private int[] diff;
        private int n;
        private HashSet<Long> answers;

        private boolean subCheck(int i) {
            boolean a = true;
            if (i < 0 || i >= n) return true;
            if (i % 2 == 0) {
                a = a && ((i - 1 < 0) || t[i - 1] > t[i]);
                a = a && ((i + 1 >= n) || t[i + 1] > t[i]);
            } else {
                a = a && ((i - 1 < 0) || t[i - 1] < t[i]);
                a = a && ((i + 1 >= n) || t[i + 1] < t[i]);
            }
            return a;
        }

        private boolean checkSwap(int i, int j) {
            boolean a = true;

            if (i == j || i < 0 || i >= n || j < 0 || j >= n) return false;

            int lastI = t[i];
            int lastJ = t[j];

            t[i] = lastJ;
            t[j] = lastI;

            a = subCheck(i) && subCheck(j) && subCheck(i - 1) && subCheck(i + 1) && subCheck(j - 1) && subCheck(j + 1);

            if (a) {
                putAnswer(Math.min(i, j), Math.max(i, j));
            }
            t[i] = lastI;
            t[j] = lastJ;

            return a;
        }

        void putAnswer(long i, long j) {
            answers.add(i * (long) n + j);
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            this.n = in.nextInt();
            this.t = new int[n];
            this.diff = new int[n - 1];
            ArrayList<Integer> issues = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                t[i] = in.nextInt();
                if (i >= 1) {
                    diff[i - 1] = t[i] - t[i - 1];
                    if (!((i % 2 == 0 && diff[i - 1] < 0) || (i % 2 == 1 && diff[i - 1] > 0))) {
                        issues.add(i);
                    }
                }
            }

            this.answers = new HashSet<>();

            if (issues.size() == 1) {
                int issue = issues.get(0);
                for (int i = 0; i < n; i++) {
                    checkSwap(i, issue);
                    checkSwap(i, issue - 1);
                }
                checkSwap(issue - 1, issue);
            } else if (issues.size() == 2) {
                int a = issues.get(0);
                int b = issues.get(1);
                if (b == a + 1) {
                    for (int i = 0; i < n; i++) {
                        checkSwap(i, a);
                    }
                } else {
                    checkSwap(b, a);
                    checkSwap(b, a + 1);
                    checkSwap(b, a - 1);

                    checkSwap(b - 1, a);
                    checkSwap(b - 1, a + 1);
                    checkSwap(b - 1, a - 1);

                    checkSwap(b + 1, a);
                    checkSwap(b + 1, a + 1);
                    checkSwap(b + 1, a - 1);
                }
            } else if (issues.size() == 3) {
                int a = issues.get(0);
                int b = issues.get(1);
                int c = issues.get(2);

                if (b == a + 1 || c == b + 1) {
                    int aa = a, ab = b, ac = c;
                    if (c == b + 1) {
                        aa = b;
                        ab = c;
                        ac = a;
                    }
                    checkSwap(aa, ac);
                    checkSwap(aa, ac + 1);
                    checkSwap(aa, ac - 1);
                } else {
                    // pass
                }
            } else if (issues.size() == 4) {
                int a = issues.get(0);
                int b = issues.get(1);
                int c = issues.get(2);
                int d = issues.get(3);
                if (b == a + 1 && d == c + 1) {
                    checkSwap(a, c);
                } else {
                    // pass
                }
            }

            out.println(answers.size());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.Set;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskC {
        Scanner in;
        PrintWriter out;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            this.in = in;
            this.out = out;
            run();
        }

        void run() {
            int n = in.nextInt();
            int[] is = in.nextIntArray(n);
            int cnt = 0;
            int x = -1;
            int y = -1;
            Set<Integer> xs = new HashSet<>();
            for (int i = 0; i + 1 < n; i++) {
                if (i % 2 == 0 && !(is[i + 1] > is[i]) || i % 2 == 1 && !(is[i + 1] < is[i])) {
                    cnt++;
                    if (x == -1) x = i;
                    else y = i;
                    xs.add(i);
                    if (i + 1 < n) xs.add(i + 1);
                }
            }
            int res = 0;
            if (cnt == 2 && x == y - 1) {
                res = check(n, is, y);
                Algo.swap(is, x, x + 2);
                if (fit(is, x) && fit(is, x + 2)) res++;
            } else if (cnt == 1) {
                res = check(n, is, x) + check(n, is, x + 1);
                Algo.swap(is, x, x + 1);
                if (fit(is, x) && fit(is, x + 1)) res--;
            } else if (cnt <= 4) {
                for (int i : xs) {
                    for (int j : xs)
                        if (i < j) {
                            Algo.swap(is, i, j);
                            boolean f = true;
                            for (int u : xs) if (!fit(is, u)) f = false;
                            if (f) res++;
                            Algo.swap(is, i, j);
                        }
                }
            }
            out.println(res);
        }

        private int check(int n, int[] is, int x) {
            int res = 0;
            for (int i = 0; i < n; i++)
                if (x != i) {
                    Algo.swap(is, i, x);
                    if (fit(is, i) && fit(is, x)) res++;
                    Algo.swap(is, i, x);
                }
            return res;
        }

        private boolean fit(int[] is, int i) {
            return (i == 0 || (i % 2 == 0 && is[i] < is[i - 1] || i % 2 == 1 && is[i] > is[i - 1])) &&
                    (i == is.length - 1 || (i % 2 == 0 && is[i] < is[i + 1] || i % 2 == 1 && is[i] > is[i + 1]));
        }

    }

    static class Algo {
        public static void swap(int[] is, int i, int j) {
            int t = is[i];
            is[i] = is[j];
            is[j] = t;
        }

    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            eat("");
        }

        private void eat(String s) {
            st = new StringTokenizer(s);
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!st.hasMoreTokens()) {
                String s = nextLine();
                if (s == null)
                    return false;
                eat(s);
            }
            return true;
        }

        public String next() {
            hasNext();
            return st.nextToken();
        }

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

        public int[] nextIntArray(int n) {
            int[] is = new int[n];
            for (int i = 0; i < n; i++) {
                is[i] = nextInt();
            }
            return is;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class TaskC {
        Scanner in;
        PrintWriter out;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            this.in = in;
            this.out = out;
            run();
        }

        void run() {
            int n = in.nextInt();
            int[] is = in.nextIntArray(n);
            int cnt = 0;
            int x = -1;
            int y = -1;
            for (int i = 0; i + 1 < n; i++) {
                if (i % 2 == 0 && !(is[i + 1] > is[i]) || i % 2 == 1 && !(is[i + 1] < is[i])) {
                    cnt++;
                    if (x == -1) x = i;
                    else y = i;
                }
            }
            if (cnt > 2) {
                out.println(0);
                return;
            }
            int res = 0;
            if (cnt == 2) {
                if (x == y - 1) {
                    res = check(n, is, y);
                    Algo.swap(is, x, x + 2);
                    if (fit(is, x) && fit(is, x + 2)) res++;
                } else {
                    int[] ls = new int[]{x, x + 1, y, y + 1};
                    Set<PII> set = new HashSet<>();
                    for (int i : ls) {
                        for (int j : ls)
                            if (i < j) {
                                Algo.swap(is, i, j);
                                if (fit(is, x) && fit(is, x + 1) && fit(is, y) && fit(is, y + 1)) {
                                    set.add(new PII(i, j));
                                }
                                Algo.swap(is, i, j);
                            }
                    }
                    res = set.size();
                }
            } else {
                res = check(n, is, x) + check(n, is, x + 1);
                Algo.swap(is, x, x + 1);
                if (fit(is, x) && fit(is, x + 1)) res--;
            }
            out.println(res);
        }

        private int check(int n, int[] is, int x) {
            int res = 0;
            for (int i = 0; i < n; i++)
                if (x != i) {
                    Algo.swap(is, i, x);
                    if (fit(is, i) && fit(is, x)) res++;
                    Algo.swap(is, i, x);
                }
            return res;
        }

        private boolean fit(int[] is, int i) {
            return (i == 0 || (i % 2 == 0 && is[i] < is[i - 1] || i % 2 == 1 && is[i] > is[i - 1])) &&
                    (i == is.length - 1 || (i % 2 == 0 && is[i] < is[i + 1] || i % 2 == 1 && is[i] > is[i + 1]));
        }

    }

    static class Algo {
        public static void swap(int[] is, int i, int j) {
            int t = is[i];
            is[i] = is[j];
            is[j] = t;
        }

    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            eat("");
        }

        private void eat(String s) {
            st = new StringTokenizer(s);
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!st.hasMoreTokens()) {
                String s = nextLine();
                if (s == null)
                    return false;
                eat(s);
            }
            return true;
        }

        public String next() {
            hasNext();
            return st.nextToken();
        }

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

        public int[] nextIntArray(int n) {
            int[] is = new int[n];
            for (int i = 0; i < n; i++) {
                is[i] = nextInt();
            }
            return is;
        }

    }

    static class PII implements Comparable<PII> {
        public int x;
        public int y;

        public PII(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public int compareTo(PII o) {
            if (x != o.x) return x - o.x;
            return y - o.y;
        }

        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof PII)) return false;

            PII pii = (PII) o;

            if (x != pii.x) return false;
            if (y != pii.y) return false;

            return true;
        }

        public int hashCode() {
            int result = x;
            result = 31 * result + y;
            return result;
        }

        public String toString() {
            return "(" + x + ", " + y + ")";
        }

    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;

public class C {
	static int n, nums[];

	static boolean valid(int pos) {
		if (pos > n)
			return true;
		if (pos % 2 == 0) {
			if (pos < n && nums[pos] <= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] >= nums[pos])
				return false;
		} else {
			if (pos < n && nums[pos] >= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] <= nums[pos])
				return false;
		}
		return true;
	}

	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(bf.readLine());
		String l[] = bf.readLine().split(" ");
		nums = new int[n + 1];
		for (int i = 0; i < n; i++) {
			nums[i + 1] = Integer.parseInt(l[i]);
		}
		int x = 0;
		int pos[] = new int[3];
		for (int i = 1; i < nums.length - 1; i++) {
			if (i % 2 == 0) {
				if (nums[i] <= nums[i + 1]) {
					if (x >= 3) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			} else {
				if (nums[i] >= nums[i + 1]) {
					if (x >= 3) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			}
		}
		int ans = 0;
		if (x == 1) {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
			pos[0]++;
			for (int i = 1; i < nums.length; i++) {
				if (i == pos[0] - 1)
					continue;
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
		} else if (x == 2) {
			HashSet<String> res = new HashSet<String>();

			for (int i = 1; i < nums.length; i++) {
				for (int j = 0; j < 2; j++) {
					swap(pos[j], i);
					pos[2] = i;
					if (valid(pos)) {
						add(i, pos[j], res);
					}
					swap(pos[j], i);
					swap(pos[j] + 1, i);
					pos[2] = i;
					if (valid(pos)) {
						add(i, pos[j] + 1, res);
					}
					swap(pos[j] + 1, i);
				}
			}
			if(n==149997)System.out.println("HERE123");
			ans = res.size();
		} else {
			if(n==149997)System.out.println("HERE");
			HashSet<String> res = new HashSet<String>();
			for (int i = 0; i < pos.length; i++) {
				for (int k = 0; k < pos.length; k++) {
					swap(pos[i], pos[k]);
					if (valid(pos)) {
						add(pos[i], pos[k], res);
					}
					swap(pos[i], pos[k]);

					swap(pos[i] + 1, pos[k]);
					if (valid(pos)) {
						add(pos[i] + 1, pos[k], res);

					}
					swap(pos[i] + 1, pos[k]);

					swap(pos[i] + 1, pos[k] + 1);
					if (valid(pos)) {
						add(pos[i] + 1, pos[k] + 1, res);

					}
					swap(pos[i] + 1, pos[k] + 1);

					swap(pos[i], pos[k] + 1);
					if (valid(pos)) {
						add(pos[i], pos[k] + 1, res);
					}
					swap(pos[i], pos[k] + 1);

				}
			}
			ans = res.size();
		}
		System.out.println(ans);
	}

	private static void add(int i, int j, HashSet<String> res) {
		if (i > j){
			int tmp = i;
			i = j;
			j = tmp;
		}
		res.add(i + " " + j);

	}

	private static boolean valid(int[] pos) {
		if (valid(pos[0] + 1) && valid(pos[1] + 1) && valid(pos[2] + 1))
			return valid(pos[0]) && valid(pos[1]) && valid(pos[2]);
		return false;
	}

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

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeMap;

public class C {
	static int n, nums[];

	static boolean valid(int pos) {
		if (pos % 2 == 0) {
			if (pos < n && nums[pos] <= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] >= nums[pos])
				return false;
		} else {
			if (pos < n && nums[pos] >= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] <= nums[pos])
				return false;
		}
		return true;
	}

	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(bf.readLine());
		String l[] = bf.readLine().split(" ");
		nums = new int[n + 1];
		for (int i = 0; i < n; i++) {
			nums[i + 1] = Integer.parseInt(l[i]);
		}
		int x = 0;
		int pos[] = new int[2];
		for (int i = 1; i < nums.length - 1; i++) {
			if (i % 2 == 0) {
				if (nums[i] <= nums[i + 1]) {
					if (x == 2) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			} else {
				if (nums[i] >= nums[i + 1]) {
					if (x == 2) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			}
		}
		int ans = 0;
		if (x == 1) {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
			pos[0]++;
			for (int i = 1; i < nums.length; i++) {
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
		} else {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[1], i);
				if (valid(i) && valid(pos[1])) {
					if (valid(pos[0]))
						ans++;
				}
				swap(pos[1], i);
			}
			for (int i = 1; i < nums.length; i++) {
				if (i == pos[1])
					continue;
				swap(pos[0], i);
				if (valid(i) && valid(pos[0])) {
					if (valid(pos[1]))
						ans++;
				}
				swap(pos[0], i);
			}
		}
		System.out.println(ans);
	}

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

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeMap;

public class C {
	static int n, nums[];

	static boolean valid(int pos) {
		if (pos % 2 == 0) {
			if (pos < n && nums[pos] <= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] >= nums[pos])
				return false;
		} else {
			if (pos < n && nums[pos] >= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] <= nums[pos])
				return false;
		}
		return true;
	}

	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(bf.readLine());
		String l[] = bf.readLine().split(" ");
		nums = new int[n + 1];
		for (int i = 0; i < n; i++) {
			nums[i + 1] = Integer.parseInt(l[i]);
		}
		int x = 0;
		int pos[] = new int[2];
		for (int i = 1; i < nums.length - 1; i++) {
			if (i % 2 == 0) {
				if (nums[i] <= nums[i + 1]) {
					if (x == 2) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			} else {
				if (nums[i] >= nums[i + 1]) {
					if (x == 2) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			}
		}
		int ans = 0;
		if (x == 1) {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
			pos[0]++;
			for (int i = 1; i < nums.length; i++) {
				if (i == pos[0] - 1)
					continue;
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
		} else {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[1], i);
				if (valid(i) && valid(pos[1])) {
					if (valid(pos[0]))
						ans++;
				}
				swap(pos[1], i);
			}
			if (pos[0] + 1 != pos[1]) {
				pos[1]++;
				for (int i = 1; i < nums.length; i++) {
					if (i == pos[1] - 1)
						continue;
					swap(pos[1], i);
					if (valid(i) && valid(pos[1])) {
						if (valid(pos[0]))
							ans++;
					}
					swap(pos[1], i);
				}
				pos[1]--;
			}
			for (int i = 1; i < nums.length; i++) {
				if (i == pos[1] || i == pos[1] + 1)
					continue;
				swap(pos[0], i);
				if (valid(i) && valid(pos[0])) {
					if (valid(pos[1]))
						ans++;
				}
				swap(pos[0], i);
			}
			if (pos[0] + 1 != pos[1]) {
				pos[0]++;
				for (int i = 1; i < nums.length; i++) {
					if (i == pos[1] || i == pos[1] + 1 || i == pos[0] - 1)
						continue;
					swap(pos[0], i);
					if (valid(i) && valid(pos[0])) {
						if (valid(pos[1]))
							ans++;
					}
					swap(pos[0], i);
				}
			}
		}
		System.out.println(ans);
	}

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

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.TreeMap;

public class C {
	static int n, nums[];

	static boolean valid(int pos) {
		if (pos % 2 == 0) {
			if (pos < n && nums[pos] <= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] >= nums[pos])
				return false;
		} else {
			if (pos < n && nums[pos] >= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] <= nums[pos])
				return false;
		}
		return true;
	}

	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(bf.readLine());
		String l[] = bf.readLine().split(" ");
		nums = new int[n + 1];
		for (int i = 0; i < n; i++) {
			nums[i + 1] = Integer.parseInt(l[i]);
		}
		int x = 0;
		int pos[] = new int[3];
		for (int i = 1; i < nums.length - 1; i++) {
			if (i % 2 == 0) {
				if (nums[i] <= nums[i + 1]) {
					if (x == 3) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			} else {
				if (nums[i] >= nums[i + 1]) {
					if (x == 2) {
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			}
		}
		int ans = 0;
		if (x == 1) {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
			pos[0]++;
			for (int i = 1; i < nums.length; i++) {
				if (i == pos[0] - 1)
					continue;
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
		} else if (x == 2) {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[1], i);
				if (valid(i) && valid(pos[1])) {
					if (valid(pos[0]))
						ans++;
				}
				swap(pos[1], i);
			}
			if (pos[0] + 1 != pos[1]) {
				pos[1]++;
				for (int i = 1; i < nums.length; i++) {
					if (i == pos[1] - 1)
						continue;
					swap(pos[1], i);
					if (valid(i) && valid(pos[1])) {
						if (valid(pos[0]))
							ans++;
					}
					swap(pos[1], i);
				}
				pos[1]--;
			}
			for (int i = 1; i < nums.length; i++) {
				if (i == pos[1] || i == pos[1] + 1)
					continue;
				swap(pos[0], i);
				if (valid(i) && valid(pos[0])) {
					if (valid(pos[1]))
						ans++;
				}
				swap(pos[0], i);
			}
			if (pos[0] + 1 != pos[1]) {
				pos[0]++;
				for (int i = 1; i < nums.length; i++) {
					if (i == pos[1] || i == pos[1] + 1 || i == pos[0] - 1)
						continue;
					swap(pos[0], i);
					if (valid(i) && valid(pos[0])) {
						if (valid(pos[1]))
							ans++;
					}
					swap(pos[0], i);
				}
			}
		} else {
			HashSet<String> res = new HashSet<String>();
			for (int i = 0; i < pos.length; i++) {
				for (int k = i + 1; k < pos.length; k++) {
					swap(pos[i], pos[k]);
					if (valid(pos)) {
						add(pos[i], pos[k], res);
					}
					swap(pos[i], pos[k]);

					swap(pos[i] + 1, pos[k]);
					if (valid(pos)) {
						add(pos[i] + 1, pos[k], res);

					}
					swap(pos[i] + 1, pos[k]);

					swap(pos[i] + 1, pos[k] + 1);
					if (valid(pos)) {
						add(pos[i] + 1, pos[k] + 1, res);

					}
					swap(pos[i] + 1, pos[k] + 1);

					swap(pos[i], pos[k] + 1);
					if (valid(pos)) {
						add(pos[i], pos[k] + 1, res);
					}
					swap(pos[i], pos[k] + 1);

				}
			}
			ans = res.size();
		}
		System.out.println(ans);
	}

	private static void add(int i, int j, HashSet<String> res) {
		if (i > j)
			add(j, i, res);
		res.add(i + " " + j);

	}

	private static boolean valid(int[] pos) {
		if (valid(pos[0] + 1) && valid(pos[1] + 1) && valid(pos[2] + 1))
			return valid(pos[0]) && valid(pos[1]) && valid(pos[2]);
		return false;
	}

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

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;

public class C {
	static int n, nums[];

	static boolean valid(int pos) {
		if (pos > n)
			return true;
		if (pos % 2 == 0) {
			if (pos < n && nums[pos] <= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] >= nums[pos])
				return false;
		} else {
			if (pos < n && nums[pos] >= nums[pos + 1])
				return false;
			if (pos > 1 && nums[pos - 1] <= nums[pos])
				return false;
		}
		return true;
	}

	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(bf.readLine());
		String l[] = bf.readLine().split(" ");
		nums = new int[n + 1];
		for (int i = 0; i < n; i++) {
			nums[i + 1] = Integer.parseInt(l[i]);
		}
		int x = 0;
		int pos[] = new int[3];
		for (int i = 1; i < nums.length - 1; i++) {
			if (i % 2 == 0) {
				if (nums[i] <= nums[i + 1]) {
					if (x >= 3) {
						if(n==149997)System.out.println("HERE0");
						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			} else {
				if (nums[i] >= nums[i + 1]) {
					if (x >= 3) {
						if(n==149997)System.out.println("HERE13");

						System.out.println(0);
						return;
					}
					pos[x++] = i;
				}
			}
		}
		int ans = 0;
		if (x == 1) {
			for (int i = 1; i < nums.length; i++) {
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
			pos[0]++;
			for (int i = 1; i < nums.length; i++) {
				if (i == pos[0] - 1)
					continue;
				swap(pos[0], i);
				if (valid(i) && valid(pos[0]))
					ans++;
				swap(pos[0], i);
			}
			if(n==149997)System.out.println("HERE");
		} else if (x == 2) {
			HashSet<String> res = new HashSet<String>();

			for (int i = 1; i < nums.length; i++) {
				for (int j = 0; j < 2; j++) {
					swap(pos[j], i);
					pos[2] = i;
					if (valid(pos)) {
						add(i, pos[j], res);
					}
					swap(pos[j], i);
					swap(pos[j] + 1, i);
					pos[2] = i;
					if (valid(pos)) {
						add(i, pos[j] + 1, res);
					}
					swap(pos[j] + 1, i);
				}
			}
			ans = res.size();
		} else {
			HashSet<String> res = new HashSet<String>();
			for (int i = 0; i < pos.length; i++) {
				for (int k = 0; k < pos.length; k++) {
					swap(pos[i], pos[k]);
					if (valid(pos)) {
						add(pos[i], pos[k], res);
					}
					swap(pos[i], pos[k]);

					swap(pos[i] + 1, pos[k]);
					if (valid(pos)) {
						add(pos[i] + 1, pos[k], res);

					}
					swap(pos[i] + 1, pos[k]);

					swap(pos[i] + 1, pos[k] + 1);
					if (valid(pos)) {
						add(pos[i] + 1, pos[k] + 1, res);

					}
					swap(pos[i] + 1, pos[k] + 1);

					swap(pos[i], pos[k] + 1);
					if (valid(pos)) {
						add(pos[i], pos[k] + 1, res);
					}
					swap(pos[i], pos[k] + 1);

				}
			}
			ans = res.size();
		}
		System.out.println(ans);
	}

	private static void add(int i, int j, HashSet<String> res) {
		if (i > j){
			int tmp = i;
			i = j;
			j = tmp;
		}
		res.add(i + " " + j);

	}

	private static boolean valid(int[] pos) {
		if (valid(pos[0] + 1) && valid(pos[1] + 1) && valid(pos[2] + 1))
			return valid(pos[0]) && valid(pos[1]) && valid(pos[2]);
		return false;
	}

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

}