#include #define pb push_back #define mp make_pair #define f first #define s second using namespace std; typedef pair pii; typedef long long ll; const int M = 1205, MOD = 1e9 + 7; int dp[M][M], C[M][M], F[M], P[M]; int n; int m[M], a[M]; void init() { C[0][0] = 1, F[0] = 1; for(int i = 1; i < M; i++) for(int j = 1; j <= i; j++) C[i][j] = (C[i][j] + C[i - 1][j] + C[i - 1][j - 1]) % MOD; for(int i = 1; i < M; i++) F[i] = (1LL * i * F[i - 1]) % MOD; } int calc(int i, int len) { if(i == n + 1)return 1; if(dp[i][len] != -1) return dp[i][len]; int ans = 0; for(int j = 0; i + j <= n && j < len; j++) { if(j > 0 && a[i + j] != a[i + j - 1])break; ans = (ans + 1LL * ((1LL * F[j + 1] * C[len + 1][j + 2]) % MOD) * calc(i + j + 1, j + 1)) % MOD; } return dp[i][len] = ans; } int main() { init(); scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &m[i]); int comp = 0; a[0] = 0; int cur = 1; while(cur <= n) { if(m[cur] > m[cur - 1]) a[cur++] = comp; else a[cur++] = ++comp; } memset(dp, -1, sizeof dp); int ans = 0; for(int i = 1; i <= n && a[i] == a[i - 1]; i++) ans = (ans + calc(i + 1, i)) % MOD; cout << ans; return 0; }