import java.io.*; import java.util.*; /** * @author Aydar Gizatullin a.k.a. lightning95, aydar.gizatullin@gmail.com * Created on 17.02.17. */ public class Main { int[][] dp; int[] a; int md = 1_000_000_007; int[][] factkn; int rec(int k, int pos) { if (pos == a.length) return 1; if (dp[k][pos] != -1) return dp[k][pos]; int res = 0; int last = pos; int n = a.length; for (; last + 1 < n; ) if (a[last] < a[last + 1]) ++last; else break; for (int i = Math.min(last - pos + 1, k); i >= 1; --i) { long cur = 1L * factkn[k - i][k] * rec(i, pos + i) % md; res += cur; res %= md; } return dp[k][pos] = res; } private void solve() { int n = rw.nextInt(); a = new int[n]; dp = new int[n + 1][n]; for (int i = 0; i < n; ++i) { a[i] = rw.nextInt(); Arrays.fill(dp[i + 1], -1); } factkn = new int[n + 1][n + 1]; for (int i = 0; i <= n; ++i) { factkn[i][i] = 1; for (int j = i + 1; j <= n; ++j) factkn[i][j] = (int) (1L * factkn[i][j - 1] * j % md); } int ans = 1; for (int i = 0; i + 1 < n; i++) if (a[i] < a[i + 1]) { ans += rec(i + 2, i + 2) % md; ans %= md; } else break; rw.println(ans); } private RW rw; private String FILE_NAME = "file"; public static void main(String[] args) { new Main().run(); } private void run() { rw = new RW(FILE_NAME + ".in", FILE_NAME + ".out"); solve(); rw.close(); } private class RW { private StringTokenizer st; private PrintWriter out; private BufferedReader br; private boolean eof; RW(String inputFile, String outputFile) { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); File f = new File(inputFile); if (f.exists() && f.canRead()) { try { br = new BufferedReader(new FileReader(inputFile)); out = new PrintWriter(new FileWriter(outputFile)); } catch (IOException e) { e.printStackTrace(); } } } private String nextLine() { String s = ""; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } private String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { eof = true; return "-1"; } } return st.nextToken(); } private long nextLong() { return Long.parseLong(next()); } private int nextInt() { return Integer.parseInt(next()); } private void println() { out.println(); } private void println(Object o) { out.println(o); } private void print(Object o) { out.print(o); } private void close() { try { br.close(); } catch (IOException e) { e.printStackTrace(); } out.close(); } } }