#include using namespace std; const int mod = (int) (1e9 + 7); void add (int &a, int b) { a += b; if (a >= mod) a -= mod; } void mult (int &a, int b) { a = a * 1ll * b % mod; } int n; int c[1333][1333]; int fact[1333]; int dp[1333][1333]; int good[1333][1333]; int mas[1333]; void load () { cin >> n; for (int i = 0; i < n; i++) { cin >> mas[i]; } } int check (int l, int r) { auto &res = good[l][r]; if (res != -1) return res; res = 1; if (l == r) return res; res = check (l + 1, r); res &= mas[l] < mas[l + 1]; return res; } void pre () { memset (dp, 0xff, sizeof (dp)); memset (good, 0xff, sizeof (good)); for (int i = 0; i < 1333; i++) { c[i][0] = 1; for (int j = 1; j <= i; j++) { c[i][j] = c[i - 1][j - 1]; add (c[i][j], c[i - 1][j]); } } fact[0] = 1; for (int i = 1; i < 1333; i++) { fact[i] = fact[i - 1]; mult (fact[i], i); } } int go (int pos, int last) { auto &res = dp[pos][last]; if (res != -1) return res; if (pos == n) return res = 1; res = 0; for (int i = min (last, n - pos); i >= 1; i--) { if (!check (pos, pos + i - 1)) continue; int v = go (pos + i, i); mult (v, c[last][i]); mult (v, fact[i]); add (res, v); } return res; } void solve () { int ans = 0; for (int i = n; i > 0; i--) { if (!check (0, i - 1)) continue; int v = go (i, i); add (ans, v); clog << ans << endl; } cout << ans << endl; } int main() { pre (); load (); solve (); return 0; }