#include using namespace std; long long int MOD = 1000000007; int n; int arr[1200]; long long int dp[1200][1200]; long long int fact[1200], inv[1200]; int sorted[1200][1200]; long long int pow(long long int base, long long int exp) { if(exp == 0) return 1; long long int half = pow(base, exp / 2); if(exp % 2 == 1) return half * half % MOD * base % MOD; return half * half % MOD; } long long int solve(int cur, int hi) { if(~dp[cur][hi]) return dp[cur][hi]; if(cur == n) return dp[cur][hi] = 1; dp[cur][hi] = 0; for(int i = cur + 1; i <= min(cur + hi, n); i++) if(sorted[cur][i - 1]) dp[cur][hi] = (dp[cur][hi] + fact[hi] * inv[hi - i + cur] % MOD * solve(i, i - cur) % MOD) % MOD; return dp[cur][hi]; } int main(){ fill(*dp, *dp + 1200 * 1200, -1); scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", arr + i); fact[0] = inv[0] = 1; for(int i = 1; i <= n; i++) { fact[i] = (i * fact[i - 1]) % MOD; inv [i] = pow(fact[i], MOD - 2); } for(int i = 0; i < n; i++) { sorted[i][i] = 1; for(int j = i + 1; j < n; j++) sorted[i][j] = arr[j] > arr[j - 1] && sorted[i][j - 1]; } long long int ans = 0; for(int i = 1; i <= n; i++) if(sorted[0][i - 1]) ans = (ans + solve(i, i)) % MOD; printf("%lld\n", ans); return 0; }