#include #include #include #include using namespace std; #define sol 1200 #define MOD 1000000007 int a[sol]; int64_t rep[sol+1][sol+1]; int64_t f[sol+1][sol+1]; int64_t temp[sol+1]; void answer(){ int64_t p = 1LL; temp[0] = 1; for (int v = 1 ; v <= sol ; ++v){ temp[v] = p = (p*v) % MOD; } } int64_t result(int a1 , int b1){ if (rep[a1][b1] >= 0){ return rep[a1][b1]; } if (a1 < b1){ return 0; } if (b1 == 0){ rep[a1][b1] = 1LL; } else{ rep[a1][b1] = (result(a1-1 , b1) + result(a1-1 , b1-1)) % MOD; } return rep[a1][b1]; } int main() { int a1; scanf("%d",&a1); for (int v = 0 ; v < a1 ; ++v){ scanf("%d",&a[v]); } memset(f , 0 , sizeof(f)); memset(rep , -1 , sizeof(rep)); answer(); f[a1][0] = 1; for (int v = a1-1 ; v >= 0; --v){ int x = 0,k = -1; for (int u = v ; u < a1 ; ++u){ if (a[u] <= k){ break; } k = a[u]; ++x; } for (int u = 1 ; u <= x ; ++u){ for (int b = 0 ; b <= u ; ++b){ int64_t y = result(u , b); int64_t z = (((temp[b]*y) % MOD)*f[v+u][b]) % MOD; f[v][u] = (f[v][u]+z) % MOD; }}} int64_t t = 0LL; for (int v = 1 ; v <= a1 ; ++v){ t = (t+f[0][v])%MOD; } printf("%" PRId64 "\n", t); return 0; }