import java.util.*; public class ArrayMergingAlgo { final static int MOD = 1000000007; static int[] ar; static long[][] C = new long[1201][1201], result; static long[] factorial = new long[1201]; public static void main(String[] args) { factorial[0] = 1; for (int i = 0; i < 1201; i++) { Arrays.fill(C[i], -1); if (i == 0) continue; factorial[i] = (factorial[i - 1] * i) % MOD; } Scanner in = new Scanner(System.in); int n = in.nextInt(); ar = new int[n]; for (int i = 0; i < n; i++) ar[i] = in.nextInt(); int startLength = increasingLength(0); long res = 0; result = new long[n + 1][n + 1]; for (int i = 1; i <= startLength; i++) { res += count(0, i); res %= MOD; } System.out.println(res); } static long count(int offset, int startLength) { if (result[offset][startLength] > 0) return result[offset][startLength]; if (ar.length <= offset + 1) { return 1; } offset += startLength; if (offset == ar.length) return 1; long res = 0; int nextLength = Math.min(increasingLength(offset), startLength); for (int i = 1; i <= nextLength; i++) { long permutation = (factorial[i] * combination(startLength, i)) % MOD; res += (permutation * count(offset, i)) % MOD; res %= MOD; } result[offset - startLength][startLength] = res; return res; } static int increasingLength(int offset) { int count = 1; for (int i = offset + 1; i < ar.length; i++) { if (ar[i] < ar[i - 1]) break; count++; } return count; } static long combination(int n, int k) { if (n < k) return 0; if (k == 0 || k == n) return 1; if (C[n][k] >= 0) return C[n][k]; C[n][k] = combination(n - 1, k - 1) + combination(n - 1, k); C[n][k] %= MOD; return C[n][k]; } }