using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { const int MOD = 1000000007; static int[] Fs = new int[1201]; static int Mul(int a, int b) { return (int)(((long)a * b) % MOD); } static int Subtract(int a, int b) { int result = (a - b) % MOD; if (result < 0) { result += MOD; } return result; } static int PowerMod(int a, int b) { int res = 1; for (; b > 0; b /= 2) { if (b % 2 == 1) { res = Mul(res, a); } a = Mul(a, a); } return res; } static int InverseMod(int a) { return PowerMod(a, MOD - 2); } static int C(int n, int k) { int nf = Fs[n]; int nkf = Fs[Subtract(n, k)]; return Mul(nf, InverseMod(nkf)); } static bool IsSorted(int start, int length, int[] next_sorted) { return next_sorted[start] >= length; } static int Solve(int[] arr, int start, int v_size, int n, int[] next_sorted, int[,] mem, int[,] Cs) { if (mem[start, v_size] != -1) { return mem[start, v_size]; } if (v_size == 1) return 1; int total = 0; if (start + v_size == n && IsSorted(start, v_size, next_sorted)) { total += 1; } else if (start + v_size < n && IsSorted(start, v_size, next_sorted)) { for (int i = 1; i <= v_size; i++) { var result = Solve(arr, start + v_size, i, n, next_sorted, mem, Cs); if (Cs[v_size, i] == -1) Cs[v_size, i] = C(v_size, i); total += Mul(Cs[v_size, i], result); total %= MOD; } } total %= MOD; mem[start, v_size] = total; return total; } static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); string[] m_temp = Console.ReadLine().Split(' '); int[] m = Array.ConvertAll(m_temp,Int32.Parse); int[] next_sorted = new int[n]; next_sorted[n - 1] = 1; for (int i = n - 2; i >= 0; i--) { next_sorted[i] = m[i] < m[i+1] ? 1 + next_sorted[i+1] : 1; } int [,] mem = new int[n+1, n+1]; for (int i = 0; i < n+1; i++) { for (int j = 0; j < n+1; j++) { mem[i,j] = -1; } } int [,] Cs = new int[n+1, n+1]; for (int i = 0; i < n+1; i++) { for (int j = 0; j < n+1; j++) { Cs[i,j] = -1; } } Fs[0] = Fs[1] = 1; for (int i = 2; i <= 1200; i++) { Fs[i] = Mul(Fs[i-1], i); } int total = 0; for (int i = 1; i <= n; i++) { total += Solve(m, 0, i, n, next_sorted, mem, Cs); total %= MOD; } Console.WriteLine(total); } }