import java.io.File; import java.io.FileNotFoundException; import java.util.*; public class PE { static int[] temp; static int n; static int maxBucket; static long[][] dp; static final int MOD = 1000000007; static long[][] permutation; public static void main(String[] args) throws FileNotFoundException { // Scanner scanner = new Scanner(new File("test.txt")); Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] m = new int[n]; dp = new long[n+1][n+1]; //[start][bucket] permutation = new long[n+1][n+1]; maxBucket = 1; for (int i = 0 ; i < n ; i++){ m[i] = scanner.nextInt(); } for (int i = 1 ; i < n; i++){ if (m[i] > m[i-1]) maxBucket++; else break; } for (int i = 0 ; i m.length) return 0; if (dp[start][bucket] > 0) return dp[start][bucket]; long result = 0; int curMaxChar =1; for (int i = start+bucket+1 ; i < Math.min(m.length,start+bucket+1 + bucket); i++){ if (m[i] > m[i-1]) curMaxChar++; else break; } for (int i = 1 ; i <=curMaxChar ; i++){ result += compute(m,start+bucket,i)*permutation(bucket,i)%MOD; } if (result == 0 && start == 0){ dp[start][bucket] = 1; }else { if (result == 0) result = 1; dp[start][bucket] = result%MOD; } return dp[start][bucket]; } public static long permutation(int n, int k){ if (permutation[n][k] > 0) return permutation[n][k]; long result = 1; for (int i = n-k+1; i <= n; i++){ result = (result*i)%MOD; } permutation[n][k] = result; return result; } }