#include #include #include #include #include #include #include #include #include using namespace std; #define pb push_back #define mp make_pair #define MAX 300009 #define LEN 1002 #define mod 1000000007 #define ll long long #define pii pair #define ss second #define ff first ll fact[1201], inv_fact[1201],dp[1250][1250],n,M[1250]; ll powi(ll base, ll exp, ll m) { ll res = 1; while (exp) { if (exp % 2) { res *= base; res %= m; } base *= base; base %= m; exp >>= 1; } return res%m; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); fact[0] = 1; ll i,l,j; cin >> n; for (i = 1; i <= n; i++) cin >> M[i]; for (i = 1; i <= 1200; i++) { fact[i] = fact[i - 1] * i; if (fact[i] >= mod) fact[i] = fact[i] % mod; } for (i = 0; i <= 1200; i++) { inv_fact[i] = powi(fact[i], mod - 2, mod); } dp[n + 1][0] = 1; for (i = n; i > 0; i--) { for (l = 1; l <= n - i + 1; l++) { bool sorted = true; for (j = i+1; j <= i + l - 1; j++) { if (M[j] < M[j - 1]) { sorted = false; break; } } if (sorted) { for (j = 0; j <= l; j++) { ll temp = (fact[l] * inv_fact[l - j]) % mod; dp[i][l] += (dp[i + l][j] * temp) % mod; if (dp[i][l] >= mod) dp[i][l] = dp[i][l] % mod; } } } } ll ans = 0; for (i = 0; i <= n; i++) { ans += dp[1][i]; if (ans >= mod) ans = ans%mod; } cout << (ans)%mod << "\n"; if (ans<0) return 0; }