#include #define all(a) (a).begin(), (a).end() #define sz(a) (int)(a).size() #define pb push_back using namespace std; typedef long long ll; typedef pair pii; typedef double ld; const int mod = 1e9 + 7; void add(int& a, int b) { a += b; if (a >= mod) { a -= mod; } } void mul(int& a, int b) { ll c = ll(a) * ll(b); if (c >= mod) { c %= mod; } a = c; } int binpow(int a, int n) { int ans = 1; while (n) { if (n & 1) { mul(ans, a); } n >>= 1; mul(a, a); } return ans; } const int nmax = 1250; int dp[nmax][nmax]; int a[nmax]; int fact[nmax]; int rfact[nmax]; int get(int j, int k) { int ans = fact[j]; mul(ans, rfact[j - k]); return ans; } int main() { //ifstream cin("input.txt"); //freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); fact[0] = rfact[0] = 1; for (int i = 1; i < nmax; ++i) { fact[i] = fact[i - 1]; mul(fact[i], i); rfact[i] = binpow(fact[i], mod - 2); } int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { if (a[i] > a[i - 1]) { dp[i][i] = 1; } else { break; } } for (int i = 1; i <= n; ++i) { for (int k = 1; i - k >= 1; ++k) { if (k > 1 && a[i - k + 1] > a[i - k + 2]) { break; } for (int j = k; j <= i - k; ++j) { int val = dp[i - k][j]; mul(val, get(j, k)); add(dp[i][k], val); } } } int ans = 0; for (int k = 1; k <= n; ++k) { add(ans, dp[n][k]); } cout << ans << "\n"; }