#include #include #include #include #include #include #include #include #include #include using namespace std; const int maxN = 1210, modP = 1e9 + 7, oo = 23041997; #define foru(i, l, r) for (int i = l; i <= r; ++i) #define ford(i, r, l) for (int i = r; i >= l; --i) #define repu(i, r) for (int i = 0; i < r; ++i) #define ll long long #define F first #define S second #define mp make_pair int f[maxN][maxN], fact[maxN], c[maxN][maxN], n, a[maxN], res; int dp(int i, int j) { if (f[i][j] != -1) return f[i][j]; if (i > n) return 1; f[i][j] = 0; foru(t, i, n) { if (t != i && a[t] < a[t - 1]) break; if (t - i + 1 > j) break; int tmp = dp(t + 1, t - i + 1); if (i != 1) { tmp = (1ll * tmp * c[j][t - i + 1]) % modP; tmp = (1ll * tmp * fact[t - i + 1]) % modP; } f[i][j] = (f[i][j] + tmp) % modP; } return f[i][j]; } void init() { foru(i, 1, n) c[i][0] = 1, c[0][i] = 0; c[0][0] = 1; foru(i, 1, n) foru(j, 1, i) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % modP; fact[0] = 1; foru(i, 1, n) fact[i] = (1ll * fact[i - 1] * i) % modP; } int main() { cin >> n; init(); foru(i, 1, n) cin >> a[i]; memset(f, 255, sizeof(f)); res = dp(1, n); cout << res << endl; }