import java.io.*; import java.util.*; public class Main { static FastScanner in; static int n; static final int MOD = 1000000007; public static void main(String[] args) throws IOException { // System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream("nocross.out")), true)); in = new FastScanner(System.in); // in = new FastScanner("nocross.in"); // in = new FastScanner("input.txt"); n = in.nextInt(); int[] m = new int[n]; for (int i = 0; i < n; i++) { m[i] = in.nextInt(); } long f[] = new long[1201]; f[1] = 1; f[2] = 2; for (int i = 3; i <= 1200; i++) { f[i] = 2; for (int j = 2; j <= i - 1; j++) { f[i] += f[i - j] * j; f[i] = f[i] % MOD; } } long ans = 1; int cur = 1; for (int i = 0; i < n - 1; i++) { if (m[i] > m[i + 1]) { break; } cur++; } ans *= f[cur]; ans = ans % MOD; System.out.println(ans); } } class FastScanner { BufferedReader br; StringTokenizer tokenizer; FastScanner(String fileName) throws FileNotFoundException { this(new FileInputStream(new File(fileName))); } FastScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } String nextLine() throws IOException { tokenizer = null; return br.readLine(); } String next() throws IOException { if (tokenizer == null || !tokenizer.hasMoreTokens()) { String line = br.readLine(); if (line == null) { return null; } tokenizer = new StringTokenizer(line); } return tokenizer.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } char nextChar() throws IOException { return next().charAt(0); } }