#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++) #define np(v) next_permutation(v.begin(), v.end()) #define pll pair < long long, long long> #define all(a) a.begin(), a.end() #define ull unsigned long long #define pii pair < int, int > #define sz(a) (int)a.size() #define sqr(x) ((x) * (x)) #define y1 stupid_cmath #define vi vector #define pb push_back #define mp make_pair #define ll long long #define f first #define s second const int inf = (int)1e9; const int mod = inf + 7; const double eps = 1e-9; const double pi = acos(-1.0); const int N = 10000; int n; int a[2000]; int dp[2000][2000]; int d[2000][2000]; int f[10000], revf[10000]; char is[2000][2000]; inline int binpow(int a,int n){ int res = 1; while(n){ if(n & 1) res = (res * 1ll * a) % mod; n >>= 1; a = (a * 1ll * a) % mod; } return res; } inline void solve(){ cin >> n; for(int i = 1; i <= n; ++i){ cin >> a[i]; } dp[1][n] = 1; f[0] = 1; revf[0] = 1; for(int i = 1; i <= n; ++i){ f[i] = (f[i - 1] * 1ll * i) % mod; revf[i] = binpow(f[i], mod - 2); is[i][i] = 1; for(int j = i + 1; j <= n; ++j){ is[i][j] = (is[i][j - 1] & (a[j - 1] <= a[j])); } } for(int i = 1; i <= n; ++i){ for(int j = i; j <= n; ++j){ d[i][j] = f[j] * 1ll * revf[j - i] % mod; } } for(int i = 1; i <= n; ++i){ for(int j = 1; i + j - 1 <= n; ++j){ if(!is[i][i + j - 1]) continue; for(int k = j; k <= n; ++k){ if(i > 1){ dp[i + j][j] = (dp[i + j][j] + (dp[i][k] * 1ll * d[j][k]) % mod); if(dp[i + j][j] >= mod) dp[i + j][j] -= mod; }else{ dp[i + j][j] = (dp[i + j][j] + dp[i][k]) % mod; if(dp[i + j][j] >= mod) dp[i + j][j] -= mod; } } } } int ans = 0; for(int i = 1; i <= n; ++i){ ans = (ans + dp[n + 1][i]); if(ans >= mod) ans -= mod; } cout << ans << endl; } int main(){ ios_base::sync_with_stdio(0), cin.tie(0); int T; // cin >> T; T = 1; while(T--){ solve(); } }