#include # define F first # define S second # define mp make_pair # define pii pair # define ll long long # define pb push_back # define sz(a) (int)(a.size()) # define y1 NOT # define left NEEDED # define right THINGS const int Mod = (int)1e9 + 7; const int MX = 1073741822; const ll MXLL = 4611686018427387903; const int Sz = 1210; using namespace std; inline void Read_rap () { ios_base :: sync_with_stdio(0); cin.tie(0); } int n; int a[Sz]; ll C[Sz][Sz]; ll f[Sz]; ll dp[Sz][Sz]; bool g[Sz][Sz]; inline void Precalc () { for (int i = 1;i <= n;i ++) { C[i][0] = C[i][i] = 1; for (int j = 1;j < i;j ++) C[i][j] = (C[i-1][j - 1] + C[i-1][j]) % Mod; } f[0] = 1; for (int i = 1;i <= n;i ++) f[i] = (f[i - 1] * 1ll * i) % Mod; } int main() { Read_rap (); cin >> n; for (int i = 1;i <= n;i ++) cin >> a[i]; Precalc(); for (int i = 1;i <= n;i ++) { g[i][i] = 1; for (int j = i+1;j <= n;j ++) { if (a[j - 1] < a[j]) g[i][j] = 1; else break; } } for (int i = 1;i <= n;i ++) if (g[1][i]) dp[i][i] = 1; for (int i = 1;i <= n;i ++) { for (int j = i;j <= n;j ++) { if (!g[i][j]) break; int len = j - i + 1; for (int k = j + 1;k <= min (n, j + len);k ++) { if (!g[j + 1][k]) break; int len2 = k - j; dp[k][len2] = (dp[k][len2] + ((dp[j][len] * C[len][len2]) % Mod) * f[len2]) % Mod; } } } ll ans = 0; for (int i = 1;i <= n;i ++) ans = (ans + dp[n][i]) % Mod; cout << ans; return 0; } // Coded by Z...