#include using namespace std; const int MAXN = 1205; const long long MOD = 1000000007; int n; int m[ MAXN ]; long long dp[ MAXN ][ MAXN ]; bool sorted[ MAXN ][ MAXN ]; long long v[ MAXN ][ MAXN ]; long long memo( int i, int j ) { // |V| = i // |M| = j if (i == n - j + 1) { if (sorted[j][n]) dp[i][j] = 1; else dp[i][j] = 0; } if (n - j + 1 < i || !sorted[j][j + i - 1]) dp[i][j] = 0; if (dp[i][j] != -1) return dp[i][j]; long long sum = 0; for (int k = 1; k <= i; k++) sum = (sum + (v[i][k] * memo(k, j + i)) % MOD) % MOD; dp[i][j] = sum; return dp[i][j]; } int main(){ cin >> n; for (int i = 1; i <= n; i++) cin >> m[ i ]; // variations // i! // v[i][j] = --------- // (i - j)! for (int i = 1; i <= n; i++) { long long x = 1; for (int j = 0; j <= i; j++) { v[i][j] = x; x = (x * (i - j)) % MOD; } } // sorted segments for (int i = 1; i <= n; i++) { sorted[i][i] = true; for (int j = i + 1; j <= n; j++) sorted[i][j] = sorted[i][j - 1] && (m[j] > m[j - 1]); } // initialize dp matrix for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dp[i][j] = -1; long long answer = 0; for (int i = 1; i <= n; i++) answer = (answer + memo(i, 1)) % MOD; cout << answer << endl; return 0; }