#include using namespace std; typedef long long ll; const int N = 1201, mod = 1e9 + 7; int n, c[N][N], last[N], a[N], ans; ll d[N][N], fact[N]; int main() { cin >> n; //n = 1200; for(int i = 0;i <= n; ++ i){ if(i)fact[i] = (fact[i - 1] * i) % mod; else fact[i] = 1; c[i][0] = 1; c[i][i] = 1; for(int j = 1;j < i; ++ j){ c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; c[i][j] %= mod; } } last[0] = 1; for(int i = 1;i <= n; ++ i){ cin >> a[i]; // a[i] = ((i % 2) ^ 1) + 1; last[i] = last[i - 1]; if(a[i] < a[i - 1])last[i] = i; } for(int i = 1;i <= n; ++ i)d[0][i] = 1; for(int i = 1;i <= n; ++ i){ if(last[i] == 1)d[i][i] = 1; for(int j = 1;j < i && i - last[i] >= j - 1; ++ j){ for(int k = j;k <= i - j; ++ k){ d[i][j] += (((d[i - j][k] * c[k][j]) % mod) * fact[j]) % mod; d[i][j] %= mod; } } } for(int i = 1;i <= n; ++ i){ ans += d[n][i]; ans %= mod; } cout << ans; return 0; }