#include using namespace std; const int N = 1205; const int mod = 1e9 + 7; int n, a[N], ok[N][N], f[N][N]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = n; i >= 1; --i) cin >> a[i]; for (int i = 1; i <= n; ++i) { ok[i][i] = 1; for (int j = i + 1; j <= n; ++j) { ok[i][j] = ok[i][j - 1]; if (a[j] > a[j - 1]) ok[i][j] = 0; } } for (int i = 1; i <= n; ++i) { if (ok[1][i]) f[i][i] = 1; for (int j = 1; j < i; ++j) { if (!ok[i - j + 1][i]) break; int prd = 1, cur = i - j; for (int k = 1; k <= min(j, cur); ++k) { if (!ok[cur - k + 1][cur]) break; prd = 1LL * prd * (j - k + 1) % mod; f[i][j] = (f[i][j] + 1LL * f[cur][k] * prd) % mod; } } } int res = 0; for (int i = 1; i <= n; ++i) res = (res + f[n][i]) % mod; cout << res; }