#include #define PB push_back #define MP make_pair #define F first #define S second #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #ifdef _DEBUG_ #define debug(...) printf(__VA_ARGS__) #else #define debug(...) (void)0 #endif using namespace std; typedef long long ll; typedef pair PII; typedef vector VI; const int MOD = 1e9 + 7; inline int add(int x, int y) { x += y; if(x >= MOD) x -= MOD; return x; } inline int mul(int x, int y) { return 1ll * x * y % MOD; } const int MAXN = 1234; int dp[MAXN][MAXN]; int a[MAXN]; int main() { int n; scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &a[i]); for(int i = 0; i <= n; i++) dp[n][i] = 1; for(int i = n - 1; i >= 1; i--) { for(int j = 1; j <= i; j++) { int res = 0, t = j; for(int k = 1; k <= j && i + k <= n; k++) { res = add(res, mul(dp[i + k][k], t)); if(a[i + k] < a[i + k - 1]) break; t = mul(t, j - k); } dp[i][j] = res; debug("dp[%d][%d] = %d\n", i, j, dp[i][j]); } } int ans = 0; for(int j = 1; j <= n; j++) { ans = add(ans, dp[j][j]); if(a[j] < a[j - 1]) break; } printf("%d\n", ans); return 0; }