#include using namespace std; typedef long long LL; const int N = 1205; const int Q = 1e9 + 7; int n , a[N] , P[N][N]; bool v[N][N]; int f[N][N]; inline void add(int &A , int B) { A += B; if (A >= Q) { A -= Q; } } void work() { scanf("%d" , &n); for (int i = 1 ; i <= n; ++ i) { scanf("%d" , &a[i]); } for (int i = 1 ; i <= n ; ++ i) { v[i][i] = 1; P[i][i] = i; for (int j = i + 1 ; j <= n ; ++ j) { v[i][j] = v[i][j - 1] & (a[j - 1] < a[j]); P[i][j] = (LL)P[i][j - 1] * j % Q; } } for (int i = 1 ; i <= n ; ++ i) f[i][i] = v[1][i]; for (int i = 0 ; i <= n ; ++ i) { for (int j = 1 ; j <= n ; ++ j) { if (!f[i][j]) continue; for (int k = 1 ; k <= j && i + k <= n ; ++ k) { if (!v[i + 1][i + k]) break; add(f[i + k][k] , (LL)f[i][j] * P[j - k + 1][j] % Q); } } } int res = 0; for (int i = 1 ; i <= n ; ++ i) add(res , f[n][i]); cout << res << endl; } int main() { int T; T = 1; while (T --) { work(); } }