#include using namespace std; const int N = 1210, md = 1e9 + 7; int n, a[N]; int f[N][N], ft[N], inv[N]; int rev(int a) { int res = 1; for (int i = 0; (1ll << i) <= md - 2; ++i) { if ((md-2) & (1ll << i)) res = 1ll * res * a % md; a = 1ll * a * a % md; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; ft[0] = inv[0] = 1; for (int i = 1; i < N; ++i) ft[i] = 1ll * ft[i-1] * i % md, inv[i] = rev(ft[i]); for (int i = 1; i <= n; ++i) if (a[i] > a[i-1]) f[i][i] = 1; else break; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= i / 2; ++j) { if (j > 1 && a[i-j+1] > a[i-j+2]) break; for (int k = j; k <= i - j; ++k) f[i][j] = (f[i][j] + 1ll * (1ll * f[i - j][k] * inv[k - j] % md) * ft[k] % md) % md; //cerr << i << ' ' << j << ' ' << f[i][j] << endl; } } int ans = 0; for (int i = 1; i <= n; ++i) ans = (ans + f[n][i]) % md; cout << ans << endl; }