#include #ifndef LOCAL #define cerr dolor_sit_amet #endif #define mp make_pair #define sz(x) ((int)((x).size())) #define X first #define Y second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair < int , int > ipair; typedef pair < ll , ll > lpair; const int IINF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const double DINF = numeric_limits::infinity(); const ll MOD = 1000000007; const double EPS = 1e-9; const int DX[] = { 1, 0, -1, 0, 1, -1, 1, -1}; const int DY[] = { 0, 1, 0, -1, 1, -1, -1, 1}; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; } double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; } // ========================================================================= // const int N = 1234; int n; int a[N]; int d[N][N]; int ank[N][N]; int main() { ios::sync_with_stdio(false); for (int i = 0; i < N; ++i) { ank[i][0] = 1; for (int j = 1; j <= i; ++j) ank[i][j] = (ank[i][j-1] * (i - j + 1LL)) % MOD; } cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; int ans = 0; for (int l = 0; l < n; ++l) { for (int r = l + 1; r <= n; ++r) { if (r != l + 1 && a[r-1] < a[r-2]) break; if (l == 0) d[l][r] = 1; else for (int p = l - (r - l); p >= 0; --p) d[l][r] = (d[l][r] + 1LL * d[p][l] * ank[l-p][r-l]) % MOD; } ans = (ans + d[l][n]) % MOD; } cout << ans << "\n"; return 0; }