#include using namespace std; typedef long long ll; const int MAX = 1201; const int MOD = 1e9 + 7; int n, a[MAX]; ll gt[MAX], inv[MAX], f[MAX][MAX], res; ll lt(ll a, int b){ ll res = 1; while (b){ if (b & 1) res = (res * a) % MOD; b >>= 1; a = (a * a) % MOD; } return res; } int main(){ //freopen("in.txt", "r", stdin); scanf("%d", &n); gt[0] = inv[0] = 1; for (int i = 1; i <= n; ++i){ scanf("%d", a + i); gt[i] = (gt[i - 1] * i) % MOD; inv[i] = lt(gt[i], MOD - 2); } reverse(a + 1, a + 1 + n); for (int i = 1; i <= n; ++i) for (int j = 1; j <= i && (j == 1 || a[i - j + 1] > a[i - j + 2]); ++j) if (j == i) f[i][j] = 1; else{ for (int k = 1; k <= j && j + k <= i; ++k) f[i][j] = (f[i][j] + f[i - j][k] * inv[j - k]) % MOD; f[i][j] = (f[i][j] * gt[j]) % MOD; } for (int i = 1; i <= n; ++i) res = (res + f[n][i]) % MOD; printf("%lld", res); return 0; }