#pragma comment(linker, "/STACK:216000000") #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; const ll MAX = numeric_limits::max(); const ll MIN = numeric_limits::min(); const double PI = 3.1415926535; const ll MOD = 1000000007; template ostream& operator<<(ostream& out, vector& v) { for (int i = 0; i < v.size(); ++i) out << v[i] << " "; out << endl; return out; } template istream& operator>>(istream& in, vector& v) { for (int i = 0; i < v.size(); ++i) in >> v[i]; return in; } template T lexical_cast(string& s) { stringstream ss(s); T t; ss >> t; return t; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll ceil(ll a, ll b) { if (a % b) return a / b + 1; return a / b; } int main() { ios_base::sync_with_stdio(false); #ifdef DEBUG ifstream cin{ "input.txt" }; ofstream cout{ "output.txt" }; #endif int n; cin >> n; vector m(n); cin >> m; vector> A(n + 1, vector(n + 1, 1)); for (int k = 1; k <= n; ++k) { for (int j = 1; j <= k; ++j) { A[k][j] = (A[k][j - 1] * (k - j + 1)) % MOD; } } vector> d(n + 1, vector(n + 1, -1)); for (int i = 1; i <= n && (i == 1 || m[i - 2] < m[i - 1]); ++i) { d[i][i] = 1; } for (int i = 1; i <= n; ++i) { // i for (int k = 1; k <= i; ++k) { // if (d[i][k] == -1) continue; for (int j = 1; j <= k && i + j <= n && (j == 1 || m[i + j - 1] > m[i + j - 2]); ++j) { if (d[i + j][j] == -1) d[i + j][j] = 0; d[i + j][j] = (d[i + j][j] + d[i][k] * A[k][j]) % MOD; } } } ll ans = 0; for (int i = 1; i <= n; ++i) { if (d[n][i] != -1) { ans = (ans + d[n][i]) % MOD; } } cout << ans; }