				//package indiahacksfinal;

				import java.io.*;
				import java.util.*;
				public class q1twmp {
					static HashSet<LongLongPair> hs=new HashSet<LongLongPair>();
					public static void main(String[] args) throws Exception
					{
						InputReader in=new InputReader(System.in);
						PrintWriter pw=new PrintWriter(System.out);
						int n=in.nextInt();
						int[] a=new int[n];
						for(int i=0;i<n;i++)
						{
							a[i]=in.nextInt();
						}
						//System.out.println(ispos(a));
						int count=0;
						HashSet<Integer> bad=new HashSet<Integer>();
						boolean[] temp=new boolean[n];
						for(int i=0;i<n;i++)
						{
							if(i%2==0)
							{
								if(i<n-1 && a[i]>=a[i+1])
								{
									bad.add(i);
									//bad.add(i+1);
									temp[i]=true;
									count++;
								}
								if(i>0 && a[i]>=a[i-1])
								{
									bad.add(i);
								}
							}
							else
							{
								if(i<n-1 && a[i]<=a[i+1])
								{
									bad.add(i);
									//bad.add(i+1);
									temp[i]=true;
									count++;
								}
								if(i>0 && a[i]<=a[i-1])
								{
									bad.add(i);
								}
							}
						}

						if(count>4)
						{
							pw.println(0);
						}
						else
						{
							ArrayList<Integer> tt=new ArrayList<Integer>();
							for(int w:bad)
							{
								tt.add(w);
							}
							int ans=0;
							for(int w:bad)
							{
								function(w,a,temp,tt);
								//System.out.println(bad.get(i)+" "+ans);
							}
							pw.println(hs.size());
						}

						pw.close();
					}
					public static int function(int i,int[] a,boolean[] t,ArrayList<Integer> bad)
					{
						int count=0;
						int n=a.length;
						for(int k=0;k<n;k++)
						{
							if(k!=i)
							{
								int temp=a[k];
								a[k]=a[i];
								a[i]=temp;
								boolean aa=true;
								for(int m=0;m<bad.size();m++)
								{
									if(!ispos(a,bad.get(m)))
									{
										aa=false;
									}
								}
								if(!ispos(a,i))
								{
									aa=false;
								}
								if(!ispos(a,k))
								{
									aa=false;
								}
								if(aa)
								{

									LongLongPair  p1=new LongLongPair (i,k);
									LongLongPair  p2=new LongLongPair (k,i);
									if(hs.contains(p1))
									{

									}
									else if(hs.contains(p2))
									{

									}
									else
									{
										hs.add(p1);
									}
								}
								temp=a[k];
								a[k]=a[i];
								a[i]=temp;
							}
						}
						return count;
					}
					public static boolean ispos(int[] a,int j)
					{
						int n=a.length;
						if(j>=n-1)
						{
							return true;
						}
						int i=j;
							if(i%2==0)
							{
								if(a[i]>=a[i+1])
								{
									return false;
								}
							}
							else
							{
								if(a[i]<=a[i+1])
								{
									return false;
								}
							}

						return true;
					}
					 static class LongLongPair implements Comparable<LongLongPair> {
						    public final long first;
						    public final long second;

						    public LongLongPair(long first, long 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;
						        }

						        LongLongPair pair = (LongLongPair) o;

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

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

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

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

						}

					 static class InputReader {

						private InputStream stream;
						private byte[] buf = new byte[8192];
						private int curChar;
						private int snumChars;
						private SpaceCharFilter filter;

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

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

						public int nextInt() {
							int c = snext();
							while (isSpaceChar(c))
								c = snext();
							int sgn = 1;
							if (c == '-') {
								sgn = -1;
								c = snext();
							}

							int res = 0;

							do {
								if (c < '0' || c > '9')
									throw new InputMismatchException();
								res *= 10;
								res += c - '0';
								c = snext();
							} while (!isSpaceChar(c));

							return res * sgn;
						}

						public long nextLong() {
							int c = snext();
							while (isSpaceChar(c))
								c = snext();
							int sgn = 1;
							if (c == '-') {
								sgn = -1;
								c = snext();
							}

							long res = 0;

							do {
								if (c < '0' || c > '9')
									throw new InputMismatchException();
								res *= 10;
								res += c - '0';
								c = snext();
							} while (!isSpaceChar(c));

							return res * sgn;
						}

						public String readString() {
							int c = snext();
							while (isSpaceChar(c))
								c = snext();
							StringBuilder res = new StringBuilder();
							do {
								res.appendCodePoint(c);
								c = snext();
							} while (!isSpaceChar(c));
							return res.toString();
						}

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

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

				}


//package indiahacksfinal;

import java.io.*;
import java.util.*;
public class q1 {
	static HashSet<LongLongPair> hs=new HashSet<LongLongPair>();
	public static void main(String[] args) throws Exception
	{
		InputReader in=new InputReader(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=in.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++)
		{
			a[i]=in.nextInt();
		}
		//System.out.println(ispos(a));
		int count=0;
		HashSet<Integer> bad=new HashSet<Integer>();
		boolean[] temp=new boolean[n];
		for(int i=0;i<n-1;i++)
		{
			if(i%2==0)
			{
				if(a[i]>=a[i+1])
				{
					bad.add(i);
					bad.add(i+1);
					temp[i]=true;
					count++;
				}
			}
			else
			{
				if(a[i]<=a[i+1])
				{
					bad.add(i);
					bad.add(i+1);
					temp[i]=true;
					count++;
				}
			}
		}
		if(count>4)
		{
			pw.println(0);
		}
		else
		{
			ArrayList<Integer> tt=new ArrayList<Integer>();
			for(int w:bad)
			{
				tt.add(w);
			}
			int ans=0;
			for(int w:bad)
			{
				function(w,a,temp,tt);
				//System.out.println(bad.get(i)+" "+ans);
			}
			pw.println(hs.size());
		}

		pw.close();
	}
	public static int function(int i,int[] a,boolean[] t,ArrayList<Integer> bad)
	{
		int count=0;
		int n=a.length;
		for(int k=0;k<n;k++)
		{
			if(k!=i)
			{
				int temp=a[k];
				a[k]=a[i];
				a[i]=temp;
				boolean aa=true;
				for(int m=0;m<bad.size();m++)
				{
					if(!ispos(a,bad.get(m)))
					{
						aa=false;
					}
				}
				if(!ispos(a,i))
				{
					aa=false;
				}
				if(!ispos(a,k))
				{
					aa=false;
				}
				if(aa)
				{

					LongLongPair  p1=new LongLongPair (i,k);
					LongLongPair  p2=new LongLongPair (k,i);
					if(hs.contains(p1))
					{

					}
					else if(hs.contains(p2))
					{

					}
					else
					{
						hs.add(p1);
					}
				}
				temp=a[k];
				a[k]=a[i];
				a[i]=temp;
			}
		}
		return count;
	}
	public static boolean ispos(int[] a,int j)
	{
		int n=a.length;
		if(j>=n-1)
		{
			return true;
		}
		int i=j;
			if(i%2==0)
			{
				if(a[i]>=a[i+1])
				{
					return false;
				}
			}
			else
			{
				if(a[i]<=a[i+1])
				{
					return false;
				}
			}

		return true;
	}
	 static class LongLongPair implements Comparable<LongLongPair> {
		    public final long first;
		    public final long second;

		    public LongLongPair(long first, long 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;
		        }

		        LongLongPair pair = (LongLongPair) o;

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

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

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

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

		}

	 static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar;
		private int snumChars;
		private SpaceCharFilter filter;

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

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

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}

			int res = 0;

			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));

			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}

			long res = 0;

			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));

			return res * sgn;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

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

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

}


			//	package indiahacksfinal;

				import java.io.*;
				import java.util.*;
				public class q1twmp {
					static HashSet<LongLongPair> hs=new HashSet<LongLongPair>();
					public static void main(String[] args) throws Exception
					{
						InputReader in=new InputReader(System.in);
						PrintWriter pw=new PrintWriter(System.out);
						int n=in.nextInt();
						int[] a=new int[n];
						for(int i=0;i<n;i++)
						{
							a[i]=in.nextInt();
						}
						//System.out.println(ispos(a));
						int count=0;
						HashSet<Integer> bad=new HashSet<Integer>();
						boolean[] temp=new boolean[n];
						for(int i=0;i<n;i++)
						{
							if(i%2==0)
							{
								if(i<n-1 && a[i]>=a[i+1])
								{
									bad.add(i);
									//bad.add(i+1);
									temp[i]=true;
									count++;
								}
								if(i>0 && a[i]>=a[i-1])
								{
									bad.add(i);
								}
							}
							else
							{
								if(i<n-1 && a[i]<=a[i+1])
								{
									bad.add(i);
									//bad.add(i+1);
									temp[i]=true;
									count++;
								}
								if(i>0 && a[i]<=a[i-1])
								{
									bad.add(i);
								}
							}
						}

						if(count>4)
						{
							pw.println(0);
						}
						else
						{
							ArrayList<Integer> tt=new ArrayList<Integer>();
							for(int w:bad)
							{
								tt.add(w);
							}
							int ans=0;
							for(int w:bad)
							{
								function(w,a,temp,tt);
								//System.out.println(bad.get(i)+" "+ans);
							}
							pw.println(hs.size());
						}

						pw.close();
					}
					public static int function(int i,int[] a,boolean[] t,ArrayList<Integer> bad)
					{
						int count=0;
						int n=a.length;
						for(int k=0;k<n;k++)
						{
							if(k!=i)
							{
								int temp=a[k];
								a[k]=a[i];
								a[i]=temp;
								boolean aa=true;
								for(int m=0;m<bad.size();m++)
								{
									if(!ispos(a,bad.get(m)))
									{
										aa=false;
									}
								}
								if(!ispos(a,i))
								{
									aa=false;
								}
								if(!ispos(a,k))
								{
									aa=false;
								}
								if(aa)
								{

									LongLongPair  p1=new LongLongPair (i,k);
									LongLongPair  p2=new LongLongPair (k,i);
									if(hs.contains(p1))
									{

									}
									else if(hs.contains(p2))
									{

									}
									else
									{
										hs.add(p1);
									}
								}
								temp=a[k];
								a[k]=a[i];
								a[i]=temp;
							}
						}
						return count;
					}
					public static boolean ispos(int[] a,int j)
					{
						int n=a.length;

						int i=j;
							if(i%2==0)
							{
								if(i<n-1 && a[i]>=a[i+1])
								{
									return false;
								}
								if(i>0 && a[i]>=a[i-1])
								{
									return false;
								}
							}
							else
							{
								if(i<n-1 && a[i]<=a[i+1])
								{
									return false;
								}
								if(i>0 && a[i]<=a[i-1])
								{
									return false;
								}
							}

						return true;
					}
					 static class LongLongPair implements Comparable<LongLongPair> {
						    public final long first;
						    public final long second;

						    public LongLongPair(long first, long 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;
						        }

						        LongLongPair pair = (LongLongPair) o;

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

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

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

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

						}

					 static class InputReader {

						private InputStream stream;
						private byte[] buf = new byte[8192];
						private int curChar;
						private int snumChars;
						private SpaceCharFilter filter;

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

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

						public int nextInt() {
							int c = snext();
							while (isSpaceChar(c))
								c = snext();
							int sgn = 1;
							if (c == '-') {
								sgn = -1;
								c = snext();
							}

							int res = 0;

							do {
								if (c < '0' || c > '9')
									throw new InputMismatchException();
								res *= 10;
								res += c - '0';
								c = snext();
							} while (!isSpaceChar(c));

							return res * sgn;
						}

						public long nextLong() {
							int c = snext();
							while (isSpaceChar(c))
								c = snext();
							int sgn = 1;
							if (c == '-') {
								sgn = -1;
								c = snext();
							}

							long res = 0;

							do {
								if (c < '0' || c > '9')
									throw new InputMismatchException();
								res *= 10;
								res += c - '0';
								c = snext();
							} while (!isSpaceChar(c));

							return res * sgn;
						}

						public String readString() {
							int c = snext();
							while (isSpaceChar(c))
								c = snext();
							StringBuilder res = new StringBuilder();
							do {
								res.appendCodePoint(c);
								c = snext();
							} while (!isSpaceChar(c));
							return res.toString();
						}

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

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

				}


			//	package indiahacksfinal;

				import java.io.*;
				import java.util.*;
				public class q1 {
					static HashSet<LongLongPair> hs=new HashSet<LongLongPair>();
					public static void main(String[] args) throws Exception
					{
						InputReader in=new InputReader(System.in);
						PrintWriter pw=new PrintWriter(System.out);
						int n=in.nextInt();
						int[] a=new int[n];
						for(int i=0;i<n;i++)
						{
							a[i]=in.nextInt();
						}
						//System.out.println(ispos(a));
						int count=0;
						HashSet<Integer> bad=new HashSet<Integer>();
						boolean[] temp=new boolean[n];
						for(int i=0;i<n-1;i++)
						{
							if(i%2==0)
							{
								if(a[i]>=a[i+1])
								{
									bad.add(i);
									//bad.add(i+1);
									temp[i]=true;
									count++;
								}
								if(i>0 && a[i]<=a[i-1])
								{
									bad.add(i);
								}
							}
							else
							{
								if(a[i]<=a[i+1])
								{
									bad.add(i);
									//bad.add(i+1);
									temp[i]=true;
									count++;
								}
								if(i>0 && a[i]>=a[i-1])
								{
									bad.add(i);
								}
							}
						}
						if(count>4)
						{
							pw.println(0);
						}
						else
						{
							ArrayList<Integer> tt=new ArrayList<Integer>();
							for(int w:bad)
							{
								tt.add(w);
							}
							int ans=0;
							for(int w:bad)
							{
								function(w,a,temp,tt);
								//System.out.println(bad.get(i)+" "+ans);
							}
							pw.println(hs.size());
						}

						pw.close();
					}
					public static int function(int i,int[] a,boolean[] t,ArrayList<Integer> bad)
					{
						int count=0;
						int n=a.length;
						for(int k=0;k<n;k++)
						{
							if(k!=i)
							{
								int temp=a[k];
								a[k]=a[i];
								a[i]=temp;
								boolean aa=true;
								for(int m=0;m<bad.size();m++)
								{
									if(!ispos(a,bad.get(m)))
									{
										aa=false;
									}
								}
								if(!ispos(a,i))
								{
									aa=false;
								}
								if(!ispos(a,k))
								{
									aa=false;
								}
								if(aa)
								{

									LongLongPair  p1=new LongLongPair (i,k);
									LongLongPair  p2=new LongLongPair (k,i);
									if(hs.contains(p1))
									{

									}
									else if(hs.contains(p2))
									{

									}
									else
									{
										hs.add(p1);
									}
								}
								temp=a[k];
								a[k]=a[i];
								a[i]=temp;
							}
						}
						return count;
					}
					public static boolean ispos(int[] a,int j)
					{
						int n=a.length;
						if(j>=n-1)
						{
							return true;
						}
						int i=j;
							if(i%2==0)
							{
								if(a[i]>=a[i+1])
								{
									return false;
								}
							}
							else
							{
								if(a[i]<=a[i+1])
								{
									return false;
								}
							}

						return true;
					}
					 static class LongLongPair implements Comparable<LongLongPair> {
						    public final long first;
						    public final long second;

						    public LongLongPair(long first, long 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;
						        }

						        LongLongPair pair = (LongLongPair) o;

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

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

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

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

						}

					 static class InputReader {

						private InputStream stream;
						private byte[] buf = new byte[8192];
						private int curChar;
						private int snumChars;
						private SpaceCharFilter filter;

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

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

						public int nextInt() {
							int c = snext();
							while (isSpaceChar(c))
								c = snext();
							int sgn = 1;
							if (c == '-') {
								sgn = -1;
								c = snext();
							}

							int res = 0;

							do {
								if (c < '0' || c > '9')
									throw new InputMismatchException();
								res *= 10;
								res += c - '0';
								c = snext();
							} while (!isSpaceChar(c));

							return res * sgn;
						}

						public long nextLong() {
							int c = snext();
							while (isSpaceChar(c))
								c = snext();
							int sgn = 1;
							if (c == '-') {
								sgn = -1;
								c = snext();
							}

							long res = 0;

							do {
								if (c < '0' || c > '9')
									throw new InputMismatchException();
								res *= 10;
								res += c - '0';
								c = snext();
							} while (!isSpaceChar(c));

							return res * sgn;
						}

						public String readString() {
							int c = snext();
							while (isSpaceChar(c))
								c = snext();
							StringBuilder res = new StringBuilder();
							do {
								res.appendCodePoint(c);
								c = snext();
							} while (!isSpaceChar(c));
							return res.toString();
						}

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

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

				}


//package indiahacksfinal;

import java.io.*;
import java.util.*;
public class q1 {
	static HashSet<LongLongPair> hs=new HashSet<LongLongPair>();
	public static void main(String[] args) throws Exception
	{
		InputReader in=new InputReader(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=in.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++)
		{
			a[i]=in.nextInt();
		}
		//System.out.println(ispos(a));
		int count=0;
		HashSet<Integer> bad=new HashSet<Integer>();
		boolean[] temp=new boolean[n];
		for(int i=0;i<n-1;i++)
		{
			if(i%2==0)
			{
				if(a[i]>=a[i+1])
				{
					bad.add(i);
					bad.add(i+1);
					temp[i]=true;
					count++;
				}
			}
			else
			{
				if(a[i]<=a[i+1])
				{
					bad.add(i);
					bad.add(i+1);
					temp[i]=true;
					count++;
				}
			}
		}
		if(count>4)
		{
			pw.println(0);
		}
		else
		{
			int ans=0;
			for(int w:bad)
			{
				function(w,a,temp);
				//System.out.println(bad.get(i)+" "+ans);
			}
			pw.println(hs.size());
		}

		pw.close();
	}
	public static int function(int i,int[] a,boolean[] t)
	{
		int count=0;
		int n=a.length;
		for(int k=0;k<n;k++)
		{
			if(k!=i)
			{
				int temp=a[k];
				a[k]=a[i];
				a[i]=temp;
				if(ispos(a))
				{

					LongLongPair  p1=new LongLongPair (i,k);
					LongLongPair  p2=new LongLongPair (k,i);
					if(hs.contains(p1))
					{

					}
					else if(hs.contains(p2))
					{

					}
					else
					{
						hs.add(p1);
					}
				}
				temp=a[k];
				a[k]=a[i];
				a[i]=temp;
			}
		}
		return count;
	}
	public static boolean ispos(int[] a)
	{
		int n=a.length;
		for(int i=0;i<n-1;i++)
		{
			if(i%2==0)
			{
				if(a[i]>=a[i+1])
				{
					return false;
				}
			}
			else
			{
				if(a[i]<=a[i+1])
				{
					return false;
				}
			}
		}
		return true;
	}
	 static class LongLongPair implements Comparable<LongLongPair> {
		    public final long first;
		    public final long second;

		    public LongLongPair(long first, long 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;
		        }

		        LongLongPair pair = (LongLongPair) o;

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

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

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

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

		}

	 static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar;
		private int snumChars;
		private SpaceCharFilter filter;

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

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

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}

			int res = 0;

			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));

			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}

			long res = 0;

			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));

			return res * sgn;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

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

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

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	static int MOD = 1000 * 1000 * 1000 + 7;

	public static void shuffleArray(int[] arr) {
		int n = arr.length;
		Random rnd = new Random();
		for (int i = 0; i < n; ++i) {
			int tmp = arr[i];
			int randomPos = i + rnd.nextInt(n - i);
			arr[i] = arr[randomPos];
			arr[randomPos] = tmp;
		}
	}

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

	static class Pair {
		int x;
		int y;

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

	private static void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] tab = new int[n];
		for (int i = 0; i < n; i++) {
			tab[i] = in.nextInt();
		}
		int res = 0;
		ArrayList<Integer> bad = new ArrayList<Integer>();
		TreeSet<Integer> set = new TreeSet<Integer>();

		for (int i = 0; i < n - 1; i++) {
			if (i % 2 == 0 && tab[i] >= tab[i + 1]) {
				bad.add(i);
				set.add(i);
				set.add(i + 1);
				continue;
			}
			if (i % 2 == 1 && tab[i] <= tab[i + 1]) {
				bad.add(i);
				set.add(i);
				set.add(i + 1);
				continue;
			}
		}

		if (bad.size() > 4) {
			out.print(0);
			return;
		}
		Integer[] cand = new Integer[set.size()];
		cand = set.toArray(cand);
		for (int i = 0; i < cand.length; i++) {
			for (int j = i + 1; j < cand.length; j++) {
				int iNum = cand[i];
				int jNum = cand[j];
				int tmp1 = tab[iNum];
				int tmp2 = tab[jNum];
				tab[iNum] = tmp2;
				tab[jNum] = tmp1;
				boolean isOk = checkIfOk(tab);
				tab[iNum] = tmp1;
				tab[jNum] = tmp2;
				if (isOk) {
					res++;
				}
			}
		}

		if (bad.size() >= 3 || (bad.size() == 2 && bad.get(1) - bad.get(0) > 1)) {
			out.println(res);
			return;
		}

		for (int i = 0; i < cand.length; i++) {
			int iNum = cand[i];
			for (int k = 0; k < tab.length; k++) {
				if (k == iNum || set.contains(k)) {
					continue;
				}
				if (isGood(k, iNum, tab)) {
					res++;
				}
			}
		}
		out.print(res);
		return;

	}

	private static boolean isGood(int k, int iNum, int[] tab) {
		int tmp1 = tab[k];
		int tmp2 = tab[iNum];
		tab[k] = tmp2;
		tab[iNum] = tmp1;
		boolean ok = checkOk(k, tab);
		ok &= checkOk(iNum, tab);
		tab[k] = tmp1;
		tab[iNum] = tmp2;
		if (!ok) {
			return false;
		} else {
			return true;
		}
	}

	private static boolean checkOk(int k, int[] tab) {
		if (k % 2 == 0) {
			if (k < tab.length - 1 && tab[k] >= tab[k + 1]) {
				return false;
			}
			if (k > 0 && tab[k - 1] <= tab[k]) {
				return false;
			}
		}
		if (k % 2 == 1) {
			if (k < tab.length - 1 && tab[k + 1] >= tab[k]) {
				return false;
			}
			if (k > 0 && tab[k - 1] >= tab[k]) {
				return false;
			}
		}
		return true;
	}

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

	/*
	 *
	 */
	// --------------------------------------------------------
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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

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

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

		public String nextLine() {
			String str = "";
			try {
				str = reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}

			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	static int MOD = 1000 * 1000 * 1000 + 7;

	public static void shuffleArray(int[] arr) {
		int n = arr.length;
		Random rnd = new Random();
		for (int i = 0; i < n; ++i) {
			int tmp = arr[i];
			int randomPos = i + rnd.nextInt(n - i);
			arr[i] = arr[randomPos];
			arr[randomPos] = tmp;
		}
	}

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

	static class Pair {
		int x;
		int y;

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

	static boolean isOK(int i, int[] tab) {
		if (i == tab.length - 1) {
			return true;
		}
		if (i % 2 == 0 && tab[i] >= tab[i + 1]) {
			return false;
		}
		if (i % 2 == 1 && tab[i] <= tab[i + 1]) {
			return false;
		}
		return true;
	}

	private static void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] tab = new int[n];
		for (int i = 0; i < n; i++) {
			tab[i] = in.nextInt();
		}
		int res = 0;
		TreeSet<Integer> set = new TreeSet<Integer>();

		for (int i = 0; i < n - 1; i++) {
			if (!isOK(i, tab)) {
				set.add(i);
				set.add(i + 1);
			}
			if (set.size() > 6) {
				out.print(0);
				return;
			}
		}

		Integer[] cand = new Integer[set.size()];
		cand = set.toArray(cand);

		for (int e : cand) {
			for (int i = 0; i < n; i++) {
				if (i < e && set.contains(i)) {
					continue;
				}
				int tmp1 = tab[i];
				int tmp2 = tab[e];
				tab[i] = tmp2;
				tab[e] = tmp1;
				if (isArrayOk(i, tab, cand)) {
					res++;
				}
				tab[i] = tmp1;
				tab[e] = tmp2;
			}

		}

		out.print(res);
	}

	private static boolean isArrayOk(int i, int[] tab, Integer[] cand) {
		if (!isOK(i, tab)) {
			return false;
		}
		for (int e : cand) {
			if (!isOK(e, tab)) {
				return false;
			}
		}
		return true;

	}/*
		*
		*/
	// --------------------------------------------------------

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

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

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

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

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

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

		public String nextLine() {
			String str = "";
			try {
				str = reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}

			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	static int MOD = 1000 * 1000 * 1000 + 7;

	public static void shuffleArray(int[] arr) {
		int n = arr.length;
		Random rnd = new Random();
		for (int i = 0; i < n; ++i) {
			int tmp = arr[i];
			int randomPos = i + rnd.nextInt(n - i);
			arr[i] = arr[randomPos];
			arr[randomPos] = tmp;
		}
	}

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

	static class Pair {
		int x;
		int y;

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

	private static void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] tab = new int[n];
		for (int i = 0; i < n; i++) {
			tab[i] = in.nextInt();
		}
		int res = 0;
		ArrayList<Integer> bad = new ArrayList<Integer>();
		TreeSet<Integer> set = new TreeSet<Integer>();

		for (int i = 0; i < n - 1; i++) {
			if (i % 2 == 0 && tab[i] >= tab[i + 1]) {
				bad.add(i);
				set.add(i);
				set.add(i + 1);
				continue;
			}
			if (i % 2 == 1 && tab[i] <= tab[i + 1]) {
				bad.add(i);
				set.add(i);
				set.add(i + 1);
				continue;
			}
		}

		if (bad.size() > 4) {
			out.print(0);
			return;
		}
		Integer[] cand = new Integer[set.size()];
		cand = set.toArray(cand);
		for (int i = 0; i < cand.length; i++) {
			for (int j = i + 1; j < cand.length; j++) {
				int iNum = cand[i];
				int jNum = cand[j];
				int tmp1 = tab[iNum];
				int tmp2 = tab[jNum];
				tab[iNum] = tmp2;
				tab[jNum] = tmp1;
				boolean isOk = checkIfOk(tab);
				tab[iNum] = tmp1;
				tab[jNum] = tmp2;
				if (isOk) {
					res++;
				}
			}
		}

		if (bad.size() >= 3 || (bad.size() == 2 && bad.get(1) - bad.get(0) > 1)) {
			out.print(res);
			return;
		}

		for (int i = 0; i < cand.length; i++) {
			int iNum = cand[i];
			for (int k = 0; k < tab.length; k++) {
				if (k == iNum || set.contains(k)) {
					continue;
				}
				if (isGood(k, iNum, tab)) {
					res++;
				}
			}
		}
		out.print(res);
		return;

	}

	private static boolean isGood(int k, int iNum, int[] tab) {
		int tmp1 = tab[k];
		int tmp2 = tab[iNum];
		tab[k] = tmp2;
		tab[iNum] = tmp1;
		boolean ok = checkOk(k, tab);
		ok &= checkOk(iNum, tab);
		tab[k] = tmp1;
		tab[iNum] = tmp2;
		if (!ok) {
			return false;
		} else {
			return true;
		}
	}

	private static boolean checkOk(int k, int[] tab) {
		if (k % 2 == 0) {
			if (k < tab.length - 1 && tab[k] >= tab[k + 1]) {
				return false;
			}
			if (k > 0 && tab[k - 1] <= tab[k]) {
				return false;
			}
		}
		if (k % 2 == 1) {
			if (k < tab.length - 1 && tab[k + 1] >= tab[k]) {
				return false;
			}
			if (k > 0 && tab[k - 1] >= tab[k]) {
				return false;
			}
		}
		return true;
	}

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

	/*
	 *
	 */
	// --------------------------------------------------------
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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

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

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

		public String nextLine() {
			String str = "";
			try {
				str = reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}

			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	static int MOD = 1000 * 1000 * 1000 + 7;

	public static void shuffleArray(int[] arr) {
		int n = arr.length;
		Random rnd = new Random();
		for (int i = 0; i < n; ++i) {
			int tmp = arr[i];
			int randomPos = i + rnd.nextInt(n - i);
			arr[i] = arr[randomPos];
			arr[randomPos] = tmp;
		}
	}

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

	static class Pair {
		int x;
		int y;

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

	static boolean isOK(int i, int[] tab) {
		if (i % 2 == 0 && tab[i] >= tab[i + 1]) {
			return false;
		}
		if (i % 2 == 1 && tab[i] <= tab[i + 1]) {
			return false;
		}
		return true;
	}

	private static void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] tab = new int[n];
		for (int i = 0; i < n; i++) {
			tab[i] = in.nextInt();
		}
		int res = 0;
		TreeSet<Integer> set = new TreeSet<Integer>();

		for (int i = 0; i < n - 1; i++) {
			if (!isOK(i, tab)) {
				set.add(i);
				set.add(i + 1);
			}
			if (set.size() > 6) {
				out.print(0);
				return;
			}
		}

		Integer[] cand = new Integer[set.size()];
		cand = set.toArray(cand);

		for (int e : cand) {
			for (int i = 0; i < n; i++) {
				if (i < e && set.contains(i)) {
					continue;
				}
				int tmp1 = tab[i];
				int tmp2 = tab[e];
				tab[i] = tmp2;
				tab[e] = tmp1;
				if (isArrayOk(i, tab, cand)) {
					res++;
				}
				tab[i] = tmp1;
				tab[e] = tmp2;
			}

		}

		out.print(res);
	}

	private static boolean isArrayOk(int i, int[] tab, Integer[] cand) {
		if (!isOK2(i, tab)) {
			return false;
		}
		for (int e : cand) {
			if (!isOK2(e, tab)) {
				return false;
			}
		}
		return true;

	}

	private static boolean isOK2(int i, int[] tab) {
		if (i % 2 == 0) {
			if (i < tab.length - 1 && tab[i + 1] <= tab[i]) {
				return false;
			}
			if (i > 0 && tab[i - 1] <= tab[i]) {
				return false;
			}
		}
		if (i % 2 == 1) {
			if (i < tab.length - 1 && tab[i + 1] >= tab[i]) {
				return false;
			}
			if (i > 0 && tab[i - 1] >= tab[i]) {
				return false;
			}
		}
		return true;
	}

	/*
		*
		*/
	// --------------------------------------------------------

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

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

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

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

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

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

		public String nextLine() {
			String str = "";
			try {
				str = reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}

			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	static int MOD = 1000 * 1000 * 1000 + 7;

	public static void shuffleArray(int[] arr) {
		int n = arr.length;
		Random rnd = new Random();
		for (int i = 0; i < n; ++i) {
			int tmp = arr[i];
			int randomPos = i + rnd.nextInt(n - i);
			arr[i] = arr[randomPos];
			arr[randomPos] = tmp;
		}
	}

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

	static class Pair {
		int x;
		int y;

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

	static boolean isOK(int i, int[] tab) {
		if (i % 2 == 0 && tab[i] >= tab[i + 1]) {
			return false;
		}
		if (i % 2 == 1 && tab[i] <= tab[i + 1]) {
			return false;
		}
		return true;
	}

	private static void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] tab = new int[n];
		for (int i = 0; i < n; i++) {
			tab[i] = in.nextInt();
		}
		int res = 0;
		TreeSet<Integer> set = new TreeSet<Integer>();

		for (int i = 0; i < n - 1; i++) {
			if (!isOK(i, tab)) {
				set.add(i);
				set.add(i + 1);
			}
			if (set.size() > 6) {
				out.print(0);
				return;
			}
		}

		Integer[] cand = new Integer[set.size()];
		cand = set.toArray(cand);

		for (int e : cand) {
			for (int i = 0; i < n; i++) {
				if (i < e && set.contains(i)) {
					continue;
				}
				int tmp1 = tab[i];
				int tmp2 = tab[e];
				tab[i] = tmp2;
				tab[e] = tmp1;
				if (isArrayOk(tab)) {
					res++;
				}
				tab[i] = tmp1;
				tab[e] = tmp2;
			}

		}

		out.print(res);
	}

	private static boolean isArrayOk(int[] tab) {
		for (int i = 0; i < tab.length - 1; i++) {
			if (!isOK(i, tab)) {
				return false;
			}
		}
		return true;
	}

	/*
	 *
	 */
	// --------------------------------------------------------
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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

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

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

		public String nextLine() {
			String str = "";
			try {
				str = reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}

			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	static int MOD = 1000 * 1000 * 1000 + 7;

	public static void shuffleArray(int[] arr) {
		int n = arr.length;
		Random rnd = new Random();
		for (int i = 0; i < n; ++i) {
			int tmp = arr[i];
			int randomPos = i + rnd.nextInt(n - i);
			arr[i] = arr[randomPos];
			arr[randomPos] = tmp;
		}
	}

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

	static class Pair {
		int x;
		int y;

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

	private static void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] tab = new int[n];
		for (int i = 0; i < n; i++) {
			tab[i] = in.nextInt();
		}
		int res = 0;
		ArrayList<Integer> bad = new ArrayList<Integer>();
		TreeSet<Integer> set = new TreeSet<Integer>();

		for (int i = 0; i < n - 1; i++) {
			if (i % 2 == 0 && tab[i] >= tab[i + 1]) {
				bad.add(i);
				set.add(i);
				set.add(i + 1);
				continue;
			}
			if (i % 2 == 1 && tab[i] <= tab[i + 1]) {
				bad.add(i);
				set.add(i);
				set.add(i + 1);
				continue;
			}
		}

		if (bad.size() > 4) {
			out.print(0);
			return;
		}
		Integer[] cand = new Integer[set.size()];
		cand = set.toArray(cand);
		for (int i = 0; i < cand.length; i++) {
			for (int j = i + 1; j < cand.length; j++) {
				int iNum = cand[i];
				int jNum = cand[j];
				int tmp1 = tab[iNum];
				int tmp2 = tab[jNum];
				tab[iNum] = tmp2;
				tab[jNum] = tmp1;
				boolean isOk = checkIfOk(tab);
				tab[iNum] = tmp1;
				tab[jNum] = tmp2;
				if (isOk) {
					res++;
				}
			}
		}

		if (bad.size() >= 3 || (bad.size() == 2 && bad.get(1) - bad.get(0) > 1)) {
			out.println(res);
			return;
		}

		if (cand.length == 3) {
			int tmp = cand[1];
			cand = new Integer[1];
			cand[0] = tmp;
		}
		for (int i = 0; i < cand.length; i++) {
			int iNum = cand[i];
			for (int k = 0; k < tab.length; k++) {
				if (k == iNum || set.contains(k)) {
					continue;
				}
				if (isGood(k, iNum, tab)) {
					res++;
				}
			}
		}
		out.print(res);
		return;

	}

	private static boolean isGood(int k, int iNum, int[] tab) {
		int tmp1 = tab[k];
		int tmp2 = tab[iNum];
		tab[k] = tmp2;
		tab[iNum] = tmp1;
		boolean ok = checkOk(k, tab);
		ok &= checkOk(iNum, tab);
		tab[k] = tmp1;
		tab[iNum] = tmp2;
		if (!ok) {
			return false;
		} else {
			return true;
		}
	}

	private static boolean checkOk(int k, int[] tab) {
		if (k % 2 == 0) {
			if (k < tab.length - 1 && tab[k] >= tab[k + 1]) {
				return false;
			}
			if (k > 0 && tab[k - 1] <= tab[k]) {
				return false;
			}
		}
		if (k % 2 == 1) {
			if (k < tab.length - 1 && tab[k + 1] >= tab[k]) {
				return false;
			}
			if (k > 0 && tab[k - 1] >= tab[k]) {
				return false;
			}
		}
		return true;
	}

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

	/*
	 *
	 */
	// --------------------------------------------------------
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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

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

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

		public String nextLine() {
			String str = "";
			try {
				str = reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}

			return str;
		}
	}

}


//package india;

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

public class C {

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

}

class Csolver {

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

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

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

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

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

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

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

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

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

}

class Swap {
    int i;
    int j;

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

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

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

}

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

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

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

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

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

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

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

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

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

                    eatDelimiters();
                    int start = bufi;

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

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

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

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

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

                    eatDelimiters();

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

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

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

                            ++bufi;
                    }

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

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

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

                    eatDelimiters();

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

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

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

                            ++bufi;
                    }

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

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

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

}


//package india;

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

public class C {

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

}

class Csolver {

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

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

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

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

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

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

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

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

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

}

class Swap {
    int i;
    int j;

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

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

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

}

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

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

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

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

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

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

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

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

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

                    eatDelimiters();
                    int start = bufi;

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

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

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

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

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

                    eatDelimiters();

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

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

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

                            ++bufi;
                    }

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

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

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

                    eatDelimiters();

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

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

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

                            ++bufi;
                    }

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

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

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

}


//package india;

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

public class C {

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

}

class Csolver {

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

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

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

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

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

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

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

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

}

class Swap {
    int i;
    int j;

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

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

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

}

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

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

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

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

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

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

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

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

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

                    eatDelimiters();
                    int start = bufi;

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

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

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

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

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

                    eatDelimiters();

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

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

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

                            ++bufi;
                    }

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

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

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

                    eatDelimiters();

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

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

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

                            ++bufi;
                    }

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

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

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

}


//package india;

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

public class C {

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

}

class Csolver {

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

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

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

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

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

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

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

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

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

}

class Swap {
    int i;
    int j;

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

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

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

}

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

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

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

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

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

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

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

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

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

                    eatDelimiters();
                    int start = bufi;

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

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

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

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

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

                    eatDelimiters();

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

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

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

                            ++bufi;
                    }

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

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

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

                    eatDelimiters();

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

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

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

                            ++bufi;
                    }

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

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

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

}