#include using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge range(c i, c j) { return rge{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge d) { for (auto it = d.b; it != d.e; ++it) *this << ", \0[" + 3 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(x) "[" << #x ": " << (x) << "] " const int nax=1207; const long long mod=1000*1000*1000+7; int n; int tab[nax]; int tak[nax][nax]; long long war[nax][nax]; long long dp[nax][nax]; long long wyn; inline void dod(long long &a, long long b) { a+=b; if (a>=mod) a-=mod; if (a>=mod) a%=mod; } int main() { scanf("%d", &n); for (int i=1; i<=n; i++) scanf("%d", &tab[i]); for (int i=1; i<=n; i++) { tak[i][i]=1; for (int j=i+1; j<=n; j++) tak[i][j]=tak[i][j-1]*(tab[j]>tab[j-1]); } for (int i=1; i<=n; i++) { war[i][0]=1; for (int j=1; j<=i; j++) war[i][j]=(war[i][j-1]*(i-j+1))%mod; } for (int i=1; i<=n; i++) if (tak[i][n]) dp[i][n]=1; for (int i=n; i>0; i--) { for (int j=i; j<=n; j++) { if (!dp[i][j]) continue; int d=j-i+1; for (int l=i-d; l>0 && tak[l][i-1]; l--) dod(dp[l][i-1], dp[i][j]*war[i-l][d]); } } for (int i=1; i<=n; i++) dod(wyn, dp[1][i]); printf("%lld\n", wyn); return 0; }