// Probleme.cpp : Defines the entry point for the console application. // #include #define ll long long #define MOD 1000000007 using namespace std; int n, mus[1202]; int dp[1202][1202]; int aranj[1202][1202]; int main() { cin >> n; dp[0][0] = 1; for (int i = 0; i <= n; i++) aranj[i][0] = 1; for (int k = 1; k <= n; k++) { aranj[k][k] = 1LL * aranj[k - 1][k - 1] * k % MOD; for (int i = k + 1; i <= n; i++) aranj[i][k] = 1LL * aranj[i - 1][k - 1] * i % MOD; } for (int i = 1; i <= n; i++) { cin >> mus[i]; int j = i; do { j--; for (int lg = i - j; lg <= j; lg++) dp[i][i - j] = (dp[i][i - j] + 1LL * dp[j][lg] * aranj[lg][i - j] % MOD) % MOD; } while (j >= 1 && mus[j] <= mus[j + 1]); if (j == 0) dp[i][i] = 1; } ll rez = 0; for(int lg = 1; lg <= n; lg ++) rez = (rez + dp[n][lg]) % MOD; cout << rez; return 0; }