#include using namespace std; #define forn(i, n) for (int i = 0; i < n; i++) #define re return #define fi first #define mp make_pair #define se second #define sz(a) (int)a.size() typedef long long ll; const ll mod = 1e9 + 7; ll n, dp[1201][1201]; vector a; int main() { iostream::sync_with_stdio(0); //freopen("a.in", "r", stdin); //freopen("class.in", "r", stdin); //freopen("class.out", "w", stdout); cin >> n; a.resize(n); forn (i, n) { cin >> a[i]; } forn (i, n) { if (i && a[i] < a[i - 1]) break; dp[i][i + 1] = 1; } for (int i = 0; i < n; i++) { int qq = 0; if (i + 1 < n) { for (ll j = 1; j <= n; j++) { dp[i][j] = ((dp[i][j]%mod) * j) % mod; if (dp[i][j]) qq = j; } } for (int k = 1; i + k < n; k++) { if (k > 1 && a[i + k] < a[i + k - 1]) break; int c = i + k; for (int j = k; j <= qq; j++) { dp[c][k] += dp[i][j]; dp[i][j] = (dp[i][j] * ll(j - k)) % mod; } } } ll sum = 0; forn (i, n + 1) sum += dp[n - 1][i] % mod; cout << sum % mod; }