#include using namespace std; const int N = 1210; const int M = 1e9 + 7; long long f[N][N], gt[N], C[N][N]; int n, a[N]; int main() { //freopen("in.txt", "r", stdin); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; gt[0] = 1; for(int i = 1; i <= n; i++) { gt[i] = (gt[i-1]*i) % M; } for(int i = 0; i <= n; i++) C[0][i] = 1; for(int j = 1; j <= n; j++) for(int i = 1; i <= j; i++) C[i][j] = (C[i-1][j-1] + C[i][j-1]) % M; for(int i = 1; i <= n; i++) { for(int j = 1; j <= i; j++) { if (j == 1 || (j > 1 && a[i-j+1] < a[i-j+2])) { if (i == j) f[i][i] = 1; else for(int jj = j; jj <= i-j; jj++) f[i][j] = (f[i][j] + ((f[i-j][jj] * C[j][jj]) % M) * gt[j]) % M; } else break; } } long long res = 0; for(int j = 1; j <= n; j++) res = (res + f[n][j]) % M; cout << res; }