#include using namespace std; typedef long long ll; const int maxn = (int) 1205; const int mod = (int) 1e9 + 7; int n, a[maxn], C[maxn][maxn], ok[maxn][maxn]; ll f[maxn][maxn], fac[maxn], res; int main() { //freopen("test.txt", "r", stdin); ios_base::sync_with_stdio(0); cin.tie(0); C[0][0] = 1; fac[0] = 1; for (int i = 1; i < maxn; i ++) { C[i][0] = 1; fac[i] = fac[i - 1] * i % mod; for (int j = 1; j <= i; j ++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod; } cin >> n; //n = 1000; for (int i = 1; i <= n; i ++) { cin >> a[i]; //a[i] = i; ok[i][i] = 1; for (int j = i - 1; j >= 1; j --) { ok[j][i] = (ok[j][i - 1] & (a[i - 1] < a[i])); } } for (int i = n; i >= 1; i --) { for (int j = i; j <= n; j ++) if(ok[i][j]) { if(j == n) f[i][j] = 1; int len = j - i + 1; for (int k = j + 1; k <= min(n, j + len); k ++) { int x = k - j; f[i][j] += ((f[j + 1][k] * C[len][x]) % mod * fac[x]) % mod; } f[i][j] %= mod; } } for (int i = 1; i <= n; i ++) res = (res + f[1][i]) % mod; cout << res << endl; }