#include #define pb push_back typedef long long ll; const int N = 1200 + 10; const int MOD = 1e9 + 7; inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;} inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);} using namespace std; int n, a[N]; bool check[N][N]; ll dp[N][N], f[N], inv_f[N];; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } f[0] = 1; inv_f[0] = inv(1); for (int i = 1; i <= n; i++) { f[i] = (f[i - 1] * i) % MOD; inv_f[i] = inv(f[i]); } for (int i = 1; i <= n; i++) check[i][i] = 1; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (a[j] > a[j - 1]) { check[i][j] = check[i][j - 1]; } else { check[i][j] = 0; } } } memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { if (check[i - j + 1][i] == 0) { continue; } if (i == j) { dp[i][j] = 1; } else { for (int k = j; k <= i - j; k++) { ll val = (((dp[i - j][k] * f[k]) % MOD) * inv_f[k - j]) % MOD; dp[i][j] = (dp[i][j] + val) % MOD; } } } } ll res = 0; for (int i = 1; i <= n; i++) { res = (res + dp[n][i]) % MOD; } cout << res; return 0; }