import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { // static boolean[][] sorted; static final long mod = 1000000000 + 7; static long[][] waysDP; static long[][] DP; public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] m = new int[n]; for (int m_i = 0; m_i < n; m_i++) { m[m_i] = in.nextInt(); } // your code goes here merge(m); } public static void merge(int[] m) throws Exception { waysDP = new long[m.length + 1][m.length + 1]; for (int i = 0; i < waysDP.length; i++) { for (int j = 0; j < waysDP[0].length; j++) { waysDP[i][j] = -1; } } DP = new long[m.length][m.length + 1]; for (int i = 0; i < DP.length; i++) { for (int j = 0; j < DP[0].length; j++) { DP[i][j] = -1; } } long ways = F(m, 0, 0); System.out.println(ways); } public static long G(int[] m, int index, int prevSize, int currSize) throws Exception { long total = (ways(prevSize, currSize) % mod * F(m, index, currSize) % mod) % mod; return total; } public static long F(int[] m, int index, int prevSize) throws Exception { if (index == m.length) { return 1; } if (DP[index][prevSize] != -1) { return DP[index][prevSize]; } int prev = -1; int j = index; long total = 0; int length = prevSize == 0 ? m.length : prevSize; for (int i = 1; i <= length && i + index <= m.length; i++) { if (m[j] >= prev) { if (prevSize == 0) { total = (total % mod + F(m, i + index, i) % mod) % mod; } else { total = (total % mod + G(m, i + index, length, i) % mod) % mod; } prev = m[j]; j++; } else { break; } } DP[index][prevSize] = total; return total; } public static long ways(int prevSize, int currSize) throws Exception { if (currSize > prevSize) { throw new Exception("damn it"); } if (prevSize == 1 && currSize == 1) { return 1; } if (currSize == 1) { return prevSize; } if (waysDP[prevSize][currSize] != -1) { return waysDP[prevSize][currSize]; } long total = 0; if (prevSize > currSize) { total = ways(prevSize - 1, currSize) % mod; } long temp = ((long) currSize % mod * ways(prevSize - 1, currSize - 1) % mod) % mod; total = (total % mod + temp % mod) % mod; waysDP[prevSize][currSize] = total; return total; } // public static boolean[][] sorted(int[] m) { // boolean[][] sorted = new boolean[m.length][m.length]; // for (int i = 0; i < m.length; i++) { // int prev = 0; // for (int j = i; j < m.length; j++) { // if (m[j] >= prev) { // sorted[i][j] = true; // prev = m[j]; // } else { // break; // } // } // } // return sorted; // } }