#include using namespace std; #define For(i,l,r) for (int i = l; i <= r; ++i) #define Cor(i,l,r) for (int i = l; i >= r; --i) #define UPD(a,b) { a = (a + b) % MD; } const int MD = 1000000007; int iPow(int x, int y) { int ret = 1; for (int j = y; j; j >>= 1) { if (j & 1) ret = (long long)ret * x % MD; x = (long long)x * x % MD; } return ret; } int factor[1212], ifactor[1212]; int C(int x, int y) { return (long long)factor[x] * ifactor[y] % MD * ifactor[x - y] % MD; } int dp[1212][1212]; int A[1212], p[1212]; int n; int main() { cin >> n; For(i,1,n) scanf("%d", &A[i]); //n = 1200; //For(i,1,n) A[i] = i; factor[0] = 1; For(i,1,n) factor[i] = (long long)factor[i - 1] * i % MD; ifactor[n] = iPow(factor[n], MD - 2); Cor(i,n,1) ifactor[i - 1] = (long long)ifactor[i] * i % MD; p[1] = 0; For(i,2,n) { if (A[i - 1] > A[i]) p[i] = i - 1; else p[i] = p[i - 1]; } memset(dp, 0, sizeof dp); int ans = 0; For(i,1,n) dp[0][i] = ifactor[i]; For(i,0,n - 1) Cor(j,n,1) if (dp[i][j]) { if (i + j <= n && p[i + j] <= i) UPD(dp[i + j][j], (long long)dp[i][j] * factor[j] % MD); if (i > 0) { For(k,1,j - 1) { if (i + k <= n && p[i + k] <= i) { UPD(dp[i + k][k], (long long)dp[i][j] * factor[j] % MD * ifactor[j - k] % MD); } } } } For(i,1,n) UPD(ans, dp[n][i]); cout << ans << endl; return 0; }