#include using namespace std; #define MOD 1000000007 long long fact[1201], inv[1201], dp[1200][1201]; long long power(long long a, int b) { long long val = a; long long out = 1; while (b) { if (b & 1) { out *= val; out %= MOD; } b >>= 1; val *= val; val %= MOD; } return out; } long long inverse(long long a) { return power(a, MOD - 2); } long long perm(long long a, long long b) { return (inv[a - b] * fact[a]) % MOD; } int main(){ int n; scanf("%d", &n); int arr[n]; for (int i = 0; i < n; i++) scanf("%d", &arr[i]); fact[0] = 1; for (int i = 1; i <= 1200; i++){ fact[i] = (fact[i - 1] * i) % MOD; } inv[1200] = inverse(fact[1200]); for (int i = 1199; i >= 0; i--){ inv[i] = (inv[i + 1] * (i + 1)) % MOD; } for (int i = n - 1; i >= 0; i--){ int maxlen = 1; while (i + maxlen < n && arr[i + maxlen] > arr[i + maxlen - 1]) maxlen++; if (i + maxlen == n){ dp[i][maxlen] = 1; maxlen--; } for (int j = 1; j <= maxlen; j++){ for (int k = 1; k <= j; k++){ dp[i][j] += (dp[i + j][k] * perm(j, k)) % MOD; dp[i][j] %= MOD; } } } /*for (int i = 0; i < n; i++){ for (int j = 1; j <= n; j++){ printf("%lld ", dp[i][j]); } printf("\n"); }*/ long long ans = 0; for (int i = 1; i <= n; i++){ ans += dp[0][i]; ans %= MOD; } printf("%lld\n", ans); return 0; }