import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; public class Solution { private static String inputFilename = "src/input.txt"; private static String outputFilename = "src/output.txt"; private BufferedReader in; private StringTokenizer line; private PrintWriter out; private boolean isDebug; public Solution(boolean isDebug) { this.isDebug = isDebug; } private int[] a; private long[] fac = new long[1300]; { fac[0] = 1; for (int i = 1; i < fac.length; i++) { fac[i] = mult(fac[i - 1], i); } } private long[][] cnk0 = new long[1213][1213]; { for (int i = 1; i < cnk0.length; i++) { cnk0[i][0] = 1; cnk0[i][i] = 1; for (int j = 1; j < i; j++) { cnk0[i][j] = (cnk0[i - 1][j - 1] + cnk0[i - 1][j]) % mm; } } } private long cnk(int n, int k) { return cnk0[n][k]; // return mult(fac[n], pow(mult(fac[k], fac[n - k]), mm - 2)); } private long[][] cache; private long calcRes(int i, int cnt) { if (i >= a.length) { return 1; } if (cache[i][cnt] >= 0) { return cache[i][cnt]; } long res = 0; for (int newCnt = 1; newCnt <= cnt; newCnt++) { if (newCnt > 1 && (i + newCnt - 1 >= a.length || a[i + newCnt - 2] > a[i + newCnt - 1])) { break; } res += mult(mult(fac[newCnt], cnk(cnt, newCnt)), calcRes(i + newCnt, newCnt)); } res %= mm; cache[i][cnt] = res; return res; } public void solve() throws IOException { cache = new long[1213][1213]; for (long[] c : cache) { for (int i = 0; i < c.length; i++) { c[i] = -1; } } int n = nextInt(); a = nextIntArray(n); long res = 0; for (int newCnt = 1; newCnt <= n; newCnt++) { if (newCnt > 1 && a[newCnt - 2] > a[newCnt - 1]) { break; } res = (res + calcRes(newCnt, newCnt)) % mm; } out.println(res); } private static class Pii { private int key; private int value; public Pii(int key, int value) { this.key = key; this.value = value; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pii pii = (Pii) o; if (key != pii.key) return false; return value == pii.value; } @Override public int hashCode() { int result = key; result = 31 * result + value; return result; } @Override public String toString() { return "Pii{" + "key=" + key + ", value=" + value + '}'; } } private static final int mm = 1000000007; private long mult(long a, long b) { return a * b % mm; } private long pow(long a, long n) { if (n == 0) return 1; long t = pow(a, n / 2); t = mult(t, t); if (n % 2 != 0) { t = mult(t, a); } return t; } public static void main(String[] args) throws IOException { new Solution(Arrays.asList(args).contains("DEBUG_MODE")).run(args); } public void run(String[] args) throws IOException { if (isDebug) { in = new BufferedReader(new InputStreamReader(new FileInputStream(inputFilename))); // in = new BufferedReader(new InputStreamReader(System.in)); } else { in = new BufferedReader(new InputStreamReader(System.in)); } out = new PrintWriter(System.out); // out = new PrintWriter(outputFilename); // int t = nextInt(); int t = 1; for (int i = 0; i < t; i++) { // out.print("Case #" + (i + 1) + ": "); solve(); } in.close(); out.flush(); out.close(); } private int[] nextIntArray(int n) throws IOException { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = nextInt(); } return res; } private long[] nextLongArray(int n) throws IOException { long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = nextInt(); } return res; } private int nextInt() throws IOException { return Integer.parseInt(nextToken()); } private long nextLong() throws IOException { return Long.parseLong(nextToken()); } private double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } private String nextToken() throws IOException { while (line == null || !line.hasMoreTokens()) { line = new StringTokenizer(in.readLine()); } return line.nextToken(); } }