#include #define MAX_N 1210 using namespace std; #define ll long long #define ull unsigned long long #define ii pair #define iii pair #define fi first #define se second #define mp make_pair #define pb push_back #define ep emplace_back #define sz(a) (int) a.size() #define cl(a) a.clear() #define vi vector #define vii vector #define LOWBIT(x) ( (x) & -(x) ) #define FOR(x,a,b) for (int x=a;x<=b;x++) #define FOD(x,a,b) for (int x=a;x>=b;x--) #define REP(x,a,b) for (int x=a;xb;x--) const int MAX = 1e5 + 10; const int MAXN = 1e4 + 10; const ll MOD = 1e9 + 7; const int inf = 1e9; const double pi = acos(-1.0); const double eps = 1e-6; int dx[] = {0 , -1 , 0 , 1}; int dy[] = {1 , 0 , -1 , 0}; ll F[MAX_N]; int a[MAX_N]; ll invF[MAX_N]; int n; ll dp[MAX_N][MAX_N]; bool mark[MAX_N][MAX_N]; ll Pow(ll x , ll n) { if (n == 1) return x; ll tmp = Pow(x , n / 2); (tmp *= tmp) %= MOD; if (n % 2) (tmp *= x) %= MOD; return tmp; } ll inv_F(ll x) { ll tmp = Pow(x , MOD - 2); return tmp; } int main() { ios::sync_with_stdio(false); cin.tie(0); //freopen("input.txt", "r" , stdin); scanf("%d" , &n); FOR(i , 1 , n) scanf("%d" , &a[i]); F[0] = 1LL; invF[0] = 1LL; FOR(i , 1 , n) { F[i] = (F[i - 1] * (ll) i) % MOD; invF[i] = inv_F(F[i]); } //cout << (F[3] * invF[2]) % MOD; FOR(i , 1 , n) mark[i][i] = true; REP(i , 1 , n) FOR(j , i + 1 , n) if (a[j] > a[j - 1]) mark[i][j] = mark[i][j - 1]; else mark[i][j] = false; FOR(i , 1 , n) FOR(j , 1 , i) { if (!mark[i - j + 1][i]) continue; if (i == j) dp[i][j] = 1LL; else FOR(k , j , i - j) { ll V = (((dp[i - j][k] * F[k]) % MOD) * invF[k - j]) % MOD; (dp[i][j] += V) %= MOD; } } ll res = 0LL; /*FOR(i , 1 , n) { FOR(j , 1 , n) cout << dp[i][j] << ' '; cout << endl; }*/ FOR(i , 1 , n) (res += dp[n][i]) %= MOD; cout << res; return 0; }