#include #define ll long ll MOD = 1000000000 + 7; ll dp[1300][1300]; int m[1300]; int main(){ int n; scanf("%d",&n); for(int m_i = 1; m_i <= n; m_i++) scanf("%d",&m[m_i]); int i = 1; while (i <= n && (i == 1 || m[i] > m[i-1])){ dp[i][i] = 1; i++; } for (int i = 1;i < n;i++){ for (int j = 1;j<=n;j++){ if (dp[i][j] == 0) continue; ll v = (j*dp[i][j])%MOD; for (int nj = 1;nj+i<=n && nj <= j && (nj == 1 || m[i+nj]>m[i+nj-1]);nj++){ dp[i+nj][nj] = (dp[i+nj][nj]+v)%MOD; v = (v * (j-nj))%MOD; } } } ll sol = 0; for (int i=1;i <= n;i++){ sol = (sol + dp[n][i])%MOD; } printf("%ld",sol); }