#include using namespace std; const int N = 1210; const int mod = 1e9 + 7ll; long long P[N][N]; long long dp[N][N]; int pass[N][N]; int right_most[N]; int A[N]; int n; int search(int idx, int len) { if (idx == n) { return 1; } if (pass[idx][len]) { return dp[idx][len]; } long long &d = dp[idx][len]; d = 0; pass[idx][len] = 1; for (int i = 0 ; idx+i <= right_most[idx] and i+1 <= len ; ++i) { long long val = (idx > 0 ? P[len][i+1] : 1); val = (val * search(idx+i+1, i+1)) % mod; d = (d + val) % mod; } return d; } int main(void) { cin.sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0 ; i < n ; ++i) { cin >> A[i]; } for (int i = 1 ; i <= n ; ++i) { P[i][0] = 1ll; for (int j = 1 ; j <= i ; ++j) { P[i][j] = (P[i][j-1] * (i-j+1)) % mod; } } for (int i = n-1 ; i >= 0 ; --i) { if (i+1 < n and A[i] < A[i+1]) { right_most[i] = right_most[i+1]; } else { right_most[i] = i; } } cout << search(0, n) << endl; return 0; }