import java.math.BigInteger;
import java.util.Scanner;

public class L {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n;
		n = in.nextInt();
		int[] a = new int [n + 5];
		for (int i = 1; i <= n; i++) {
			a[i] = in.nextInt();
		}
		Gao solve = new Gao(n, a);
		solve.gao();
	}
}


class Gao {
	static final int INF = 100000000;
	static final int N = 1005;
	int n;
	int []a;
	BigInteger f[][] = new BigInteger[N + 5][N + 5];
	BigInteger sum[][] = new BigInteger[N + 5][N + 5];
	int g[][] = new int[N + 5][N + 5];
	int pre[] = new int[N + 5];
	int prest[] = new int[N + 5];
	
	Gao(int n, int [] a) {
		this.n = n;
		this.a = a;
	}
	
	void calcpre() {
		for (int i = 1; i <= n; i++) {
			int j = i;
			while (j > 1 && a[j - 1] < a[j]) j--;
			prest[i] = j;
			int k = j - 1;
			while (k > 0 && a[k] > a[i]) k--;
			if (k <= 0 || k < prest[prest[i] - 1]) {
				pre[i] = -INF;
			} else {
				pre[i] = k - (i - prest[i]);
				if (pre[i] <= 0)
					pre[i] = -INF;
			}
		}
	}
	
	boolean isBegin(int i) {
		return prest[i] == i;
	}
	
	void calcg() {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= i; j++) {
				if (i == j) {
					g[i][j] = -INF;
				} else if (!isBegin(i - j + 1)) {
					g[i][j] = -INF;
				} else if (!isBegin(i)) {
					g[i][j] = Math.min(g[i - 1][j - 1], pre[i]);
				} else {
					g[i][j] = pre[i];
				}
			}
		}
	}
	
	void calcf() {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j < i; j++) {
				if (i - j + 1 < prest[i]) {
					f[i][j] = BigInteger.ZERO;
				} else if (isBegin(i - j + 1)) {
					int rhs = i - j + 1 - prest[i - j], lhs = Math.max(j, i - j + 1 - g[i][j]);
					if (lhs <= rhs)
						f[i][j] = sum[i - j][rhs].subtract(sum[i - j][lhs - 1]);
					else
						f[i][j] = BigInteger.ZERO;
				} else {
					int lhs = j, rhs = i - j + 1 - prest[i];
					if (lhs <= rhs)
						f[i][j] = sum[i - j][rhs].subtract(sum[i - j][lhs - 1]);
					else
						f[i][j] = BigInteger.ZERO;
				}
			}
			if (prest[i] == 1) {
				f[i][i] = BigInteger.ONE;
			} else {
				f[i][i] = BigInteger.ZERO;
			}
			sum[i][0] = BigInteger.ZERO;
			for (int j = 1; j <= i; j++)
				sum[i][j] = sum[i][j - 1].add(f[i][j]);
		}
	}
	
	void gao() {
		calcpre();
		calcg();
		calcf();
		BigInteger ans = BigInteger.ZERO;
		for (int i = 1; i <= n; i++)
			ans = ans.add(f[n][i]);
		System.out.print(ans);
	}
}

